Closed
Description
from typing import TypeVar, Generic
T = TypeVar('T')
class A(Generic[T]):
@classmethod
def func(cls) -> T:
pass
class B(A['B']):
pass
def except_b(b: B):
pass
except_b(B.func())
is a valid python3 code, but mypy warns that
file:20: error: Argument 1 to "except_b" has incompatible type "T"; expected "B"
but the resolved pseudo-code of class B should be
class B(A['B']):
@classmethod
def func(cls) -> 'B':
pass
if I replace it, mypy doesn't complain anymore.
I'm might have overlook some specificities of @classmethod
but I think that func
is also bind to class B
thus should be type checking.