You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from typing import Generic, Callable, TypeVar, Iterator
T = TypeVar('T')
class Box(Generic[T]):
@classmethod
def wrap(cls, generator: Callable[[], T]) -> 'Box[T]':
pass
class IteratorBox(Box[Iterator[T]],
Generic[T]):
pass
def g() -> int:
return 0
r = IteratorBox.wrap(g)
b: IteratorBox = IteratorBox
reveal_type(b.wrap)
reveal_type(IteratorBox.wrap)
reveal_type(IteratorBox.wrap(g))
output of mypy is
as type "IteratorBox[Any]")
test.py:24: error: Revealed type is 'def (generator: def () -> typing.Iterator*[Any]) -> test.Box[typing.Iter
ator*[Any]]'
test.py:25: error: Revealed type is 'def [T] (generator: def () -> T`1) -> test.Box[T`1]'
test.py:26: error: Revealed type is 'test.Box[builtins.int*]'
I was expecting that mypy will find type mismatch to call IteratorBox.wrap(g), which it didn't.
And reveal_type(IteratorBox.wrap) just return the type of the method in base class.
This is a known issue, see #3645, but I don't want to close this because I want to collect all the use cases for type variables in class methods, so that we can understand what is actually desired and test our solution properly.
Activity
ilevkivskyi commentedon Sep 24, 2018
This is a known issue, see #3645, but I don't want to close this because I want to collect all the use cases for type variables in class methods, so that we can understand what is actually desired and test our solution properly.
oraluben commentedon Sep 24, 2018
Thanks for your reply! I have tried the PR and found a code may get wrong checking result. If it's ok to put my repro in the PR?
Fix member access on generic classes (#6418)