@@ -1423,31 +1423,40 @@ def f(x: Union[int, A], a: Type[A]) -> None:
1423
1423
[builtins fixtures/isinstancelist.pyi]
1424
1424
1425
1425
1426
+ [case testIssubclassUnreachable]
1427
+ from typing import Type, Sequence, Union
1428
+ x: Type[str]
1429
+ if issubclass(x, int):
1430
+ reveal_type(x) # unreachable block
1431
+
1432
+
1433
+ class X: pass
1434
+ class Y(X): pass
1435
+ class Z(X): pass
1436
+
1437
+ a: Union[Type[Y], Type[Z]]
1438
+ if issubclass(a, X):
1439
+ reveal_type(a) # E: Revealed type is 'Union[Type[__main__.Y], Type[__main__.Z]]'
1440
+ else:
1441
+ reveal_type(a) # unreachable block
1442
+
1443
+ [builtins fixtures/isinstancelist.pyi]
1444
+
1445
+
1426
1446
[case testIssubclass]
1427
- from typing import Type, ClassVar
1447
+ from typing import Type
1428
1448
1429
1449
class Goblin:
1430
- level: int
1450
+ pass
1431
1451
1432
1452
class GoblinAmbusher(Goblin):
1433
- job: ClassVar[str] = 'Ranger'
1453
+ pass
1434
1454
1435
1455
def test_issubclass(cls: Type[Goblin]) -> None:
1436
1456
if issubclass(cls, GoblinAmbusher):
1437
1457
reveal_type(cls) # E: Revealed type is 'Type[__main__.GoblinAmbusher]'
1438
- cls.level
1439
- cls.job
1440
- ga = cls()
1441
- ga.level = 15
1442
- ga.job
1443
- ga.job = "Warrior" # E: Cannot assign to class variable "job" via instance
1444
1458
else:
1445
1459
reveal_type(cls) # E: Revealed type is 'Type[__main__.Goblin]'
1446
- cls.level
1447
- cls.job # E: Type[Goblin] has no attribute "job"
1448
- g = cls()
1449
- g.level = 15
1450
- g.job # E: "Goblin" has no attribute "job"
1451
1460
1452
1461
1453
1462
[builtins fixtures/isinstancelist.pyi]
@@ -1482,7 +1491,7 @@ def test_issubclass(cls: Type[Mob]) -> None:
1482
1491
1483
1492
1484
1493
[case testIssubclassTuple]
1485
- from typing import Type, ClassVar
1494
+ from typing import Type
1486
1495
1487
1496
class Mob:
1488
1497
pass
0 commit comments