Example:
from typing import *
TypeT = TypeVar("TypeT", bound=type)
class Base:
field: str = "Hey"
class C1:
def method(self, other: type) -> str:
if issubclass(other, Base):
# reveal_type(other) == Type[Base]
return other.field
return "Hi"
class C2(Generic[TypeT]):
def method(self, other: TypeT) -> str:
if issubclass(other, Base):
# reveal_type(other) == TypeT`1
return other.field # mypy error: "TypeT" has no attribute "field"
return "Hi"
Actual behavior as of 0.740 included in the comments above. Expected behavior would be to not raise an error on the penultimate line.
Looks like an issue in checker.py (the logic around issubclass() is pretty ad-hoc there). One needs to add an elif for type variables in find_isinstance_check() there.
This might potentially need also an adjustment in meet.py either in narrow_declared_type() or in is_overlapping_types() or in meet_types().
@ilevkivskyi I'd like to take this
I'd like to take this
OK, go ahead.