@@ -1434,13 +1434,15 @@ class GoblinAmbusher(Goblin):
1434
1434
1435
1435
def test_issubclass(cls: Type[Goblin]) -> None:
1436
1436
if issubclass(cls, GoblinAmbusher):
1437
+ reveal_type(cls) # E: Revealed type is 'Type[__main__.GoblinAmbusher]'
1437
1438
cls.level
1438
1439
cls.job
1439
1440
ga = cls()
1440
1441
ga.level = 15
1441
1442
ga.job
1442
1443
ga.job = "Warrior" # E: Cannot assign to class variable "job" via instance
1443
1444
else:
1445
+ reveal_type(cls) # E: Revealed type is 'Type[__main__.Goblin]'
1444
1446
cls.level
1445
1447
cls.job # E: Type[Goblin] has no attribute "job"
1446
1448
g = cls()
@@ -1452,52 +1454,29 @@ def test_issubclass(cls: Type[Goblin]) -> None:
1452
1454
1453
1455
1454
1456
[case testIssubclassDeepHierarchy]
1455
- from typing import Type, ClassVar
1457
+ from typing import Type
1456
1458
1457
1459
class Mob:
1458
1460
pass
1459
1461
1460
1462
class Goblin(Mob):
1461
- level: int
1463
+ pass
1462
1464
1463
1465
class GoblinAmbusher(Goblin):
1464
- job: ClassVar[str] = 'Ranger'
1466
+ pass
1465
1467
1466
1468
def test_issubclass(cls: Type[Mob]) -> None:
1467
1469
if issubclass(cls, Goblin):
1468
- cls.level
1469
- cls.job # E: Type[Goblin] has no attribute "job"
1470
- g = cls()
1471
- g.level = 15
1472
- g.job # E: "Goblin" has no attribute "job"
1470
+ reveal_type(cls) # E: Revealed type is 'Type[__main__.Goblin]'
1473
1471
if issubclass(cls, GoblinAmbusher):
1474
- cls.level
1475
- cls.job
1476
- g = cls()
1477
- g.level = 15
1478
- g.job
1479
- g.job = 'Warrior' # E: Cannot assign to class variable "job" via instance
1472
+ reveal_type(cls) # E: Revealed type is 'Type[__main__.GoblinAmbusher]'
1480
1473
else:
1481
- cls.job # E: Type[Mob] has no attribute "job"
1482
- cls.level # E: Type[Mob] has no attribute "level"
1483
- m = cls()
1484
- m.level = 15 # E: "Mob" has no attribute "level"
1485
- m.job # E: "Mob" has no attribute "job"
1474
+ reveal_type(cls) # E: Revealed type is 'Type[__main__.Mob]'
1486
1475
if issubclass(cls, GoblinAmbusher):
1487
- cls.job
1488
- cls.level
1489
- ga = cls()
1490
- ga.level = 15
1491
- ga.job
1492
- ga.job = 'Warrior' # E: Cannot assign to class variable "job" via instance
1476
+ reveal_type(cls) # E: Revealed type is 'Type[__main__.GoblinAmbusher]'
1493
1477
1494
1478
if issubclass(cls, GoblinAmbusher):
1495
- cls.level
1496
- cls.job
1497
- ga = cls()
1498
- ga.level = 15
1499
- ga.job
1500
- ga.job = "Warrior" # E: Cannot assign to class variable "job" via instance
1479
+ reveal_type(cls) # E: Revealed type is 'Type[__main__.GoblinAmbusher]'
1501
1480
1502
1481
[builtins fixtures/isinstancelist.pyi]
1503
1482
@@ -1509,50 +1488,25 @@ class Mob:
1509
1488
pass
1510
1489
1511
1490
class Goblin(Mob):
1512
- level: int
1491
+ pass
1513
1492
1514
1493
class GoblinAmbusher(Goblin):
1515
- job: ClassVar[str] = 'Ranger'
1494
+ pass
1516
1495
1517
1496
class GoblinDigger(Goblin):
1518
- job: ClassVar[str] = 'Thief'
1497
+ pass
1519
1498
1520
1499
def test_issubclass(cls: Type[Mob]) -> None:
1521
1500
if issubclass(cls, (Goblin, GoblinAmbusher)):
1522
- cls.level
1523
- cls.job # E: Type[Goblin] has no attribute "job"
1524
- g = cls()
1525
- g.level = 15
1526
- g.job # E: "Goblin" has no attribute "job"
1501
+ reveal_type(cls) # E: Revealed type is 'Type[__main__.Goblin]'
1527
1502
if issubclass(cls, GoblinAmbusher):
1528
- cls.level
1529
1503
reveal_type(cls) # E: Revealed type is 'Type[__main__.GoblinAmbusher]'
1530
- cls.job
1531
- ga = cls()
1532
- ga.level = 15
1533
- ga.job
1534
- ga.job = "Warrior" # E: Cannot assign to class variable "job" via instance
1535
1504
else:
1536
- cls.job # E: Type[Mob] has no attribute "job"
1537
- cls.level # E: Type[Mob] has no attribute "level"
1538
- m = cls()
1539
- m.level = 15 # E: "Mob" has no attribute "level"
1540
- m.job # E: "Mob" has no attribute "job"
1505
+ reveal_type(cls) # E: Revealed type is 'Type[__main__.Mob]'
1541
1506
if issubclass(cls, GoblinAmbusher):
1542
- cls.job
1543
- cls.level
1544
- ga = cls()
1545
- ga.level = 15
1546
- ga.job
1547
- ga.job = "Warrior" # E: Cannot assign to class variable "job" via instance
1548
-
1507
+ reveal_type(cls) # E: Revealed type is 'Type[__main__.GoblinAmbusher]'
1549
1508
if issubclass(cls, (GoblinDigger, GoblinAmbusher)):
1550
- cls.level
1551
- cls.job
1552
- g = cls()
1553
- g.level = 15
1554
- g.job
1555
- g.job = "Warrior" # E: Cannot assign to class variable "job" via instance
1509
+ reveal_type(cls) # E: Revealed type is 'Union[Type[__main__.GoblinDigger], Type[__main__.GoblinAmbusher]]'
1556
1510
1557
1511
[builtins fixtures/isinstancelist.pyi]
1558
1512
@@ -1565,11 +1519,14 @@ class MyIntList(List[int]): pass
1565
1519
1566
1520
def f(cls: Type[object]) -> None:
1567
1521
if issubclass(cls, MyList):
1522
+ reveal_type(cls) # E: Revealed type is 'Type[__main__.MyList]'
1568
1523
cls()[0]
1569
1524
else:
1525
+ reveal_type(cls) # E: Revealed type is 'Type[builtins.object]'
1570
1526
cls()[0] # E: Value of type "object" is not indexable
1571
1527
1572
1528
if issubclass(cls, MyIntList):
1529
+ reveal_type(cls) # E: Revealed type is 'Type[__main__.MyIntList]'
1573
1530
cls()[0] + 1
1574
1531
1575
1532
[builtins fixtures/isinstancelist.pyi]
0 commit comments