Skip to content

Type inference problem in generic function #603

Closed
@JukkaL

Description

@JukkaL

Mypy complains about the following code:

from typing import TypeVar, List
T = TypeVar('T')
def f(a: T) -> None:
    l = []  # type: List[T]   # Error, even though this should be fine

The reason for the error seems to be that the type variable type T in List[T] is erased so that it won't conflict with the type variables used for inferring the type of the list expression. Both type variables should be able to coexist during type inference.

Metadata

Metadata

Assignees

Labels

bugmypy got something wrong

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions