-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrong
Description
from typing import *
T = TypeVar('T', bound='A')
class X: ...
class Y(X): ...
class A(Iterable[X]):
def __iter__(self) -> Iterator[X]: ...
class B(A, Iterable[Y]):
def __iter__(self) -> Iterator[Y]: ...
b = B()
for x in b:
reveal_type(x) # 'Y*'
y = list(b)
reveal_type(y) # 'builtins.list[X*]'
The first reveal_type is correct.
The second is wrong: it should be builtins.list[Y*]. Somehow the presence of A in the bases of B causes this mistake.
In addition, even a workaround doesn't work:
z = List[Y](b) # Argument 1 to "list" has incompatible type "B"; expected Iterable[Y]
reveal_type(z) # 'builtins.list[Y*]'
The revealed type is now correct, but the constructor doesn't pass the type check.
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong