File tree Expand file tree Collapse file tree 2 files changed +13
-13
lines changed Expand file tree Collapse file tree 2 files changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -3730,6 +3730,9 @@ def find_isinstance_check(self, node: Expression
37303730 if literal (expr ) == LITERAL_TYPE :
37313731 vartype = get_proper_type (type_map [expr ])
37323732 type = get_isinstance_type (node .args [1 ], type_map )
3733+ if (isinstance (vartype , TypeVarType )):
3734+ vartype = vartype .upper_bound
3735+ vartype = get_proper_type (vartype )
37333736 if isinstance (vartype , UnionType ):
37343737 union_list = []
37353738 for t in get_proper_types (vartype .items ):
@@ -3745,8 +3748,6 @@ def find_isinstance_check(self, node: Expression
37453748 elif (isinstance (vartype , Instance ) and
37463749 vartype .type .fullname () == 'builtins.type' ):
37473750 vartype = self .named_type ('builtins.object' )
3748- elif (isinstance (vartype , TypeVarType )):
3749- vartype = vartype .upper_bound
37503751 else :
37513752 # Any other object whose type we don't know precisely
37523753 # for example, Any or a custom metaclass.
Original file line number Diff line number Diff line change @@ -6518,22 +6518,21 @@ from typing import TypeVar, Generic
65186518
65196519TypeT = TypeVar("TypeT", bound=type)
65206520
6521- class IntBase :
6521+ class Base :
65226522 field: int = 42
65236523
6524- class IntFoo(Generic[TypeT]):
6525- def method(self, other: TypeT) -> int:
6526- if issubclass(other, IntBase):
6524+ class C1:
6525+ def method(self, other: type) -> int:
6526+ if issubclass(other, Base):
6527+ reveal_type(other) # N: Revealed type is 'Type[__main__.Base]'
65276528 return other.field
65286529 return 0
65296530
6530- class StrBase:
6531- field: str = "hello"
6532-
6533- class StrFoo(Generic[TypeT]):
6534- def method(self, other: TypeT) -> str:
6535- if issubclass(other, StrBase):
6531+ class C2(Generic[TypeT]):
6532+ def method(self, other: TypeT) -> int:
6533+ if issubclass(other, Base):
6534+ reveal_type(other) # N: Revealed type is 'Type[__main__.Base]'
65366535 return other.field
6537- return "hi"
6536+ return 0
65386537
65396538[builtins fixtures/isinstancelist.pyi]
You can’t perform that action at this time.
0 commit comments