Skip to content

Type variables of a nested generic function are confused with type variables of surrounding generic function #1335

Closed
@rwbarton

Description

@rwbarton
from typing import TypeVar
T = TypeVar('T')
U = TypeVar('U')

def outer(x: T) -> T:
    def inner(y: U) -> T: ...
    return inner(1)    # error: Incompatible return value type: expected T`-1, got builtins.int*

I should be able to pass inner a value of any type and get back a T to return from outer. But internally the type variables U and T of inner have the same id (-1) so effectively mypy thinks inner has a type like (U) -> U.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions