@@ -1527,3 +1527,75 @@ def bar(arg: Type[X]):
1527
1527
foo(X)
1528
1528
[builtins fixtures/tuple.py]
1529
1529
[out]
1530
+
1531
+ [case testTypeUsingTypeCClassMethod]
1532
+ from typing import Type
1533
+ class User:
1534
+ @classmethod
1535
+ def foo(cls) -> int: pass
1536
+ def bar(self) -> int: pass
1537
+ def process(cls: Type[User]):
1538
+ reveal_type(cls.foo()) # E: Revealed type is 'builtins.int'
1539
+ obj = cls()
1540
+ reveal_type(cls.bar(obj)) # E: Revealed type is 'builtins.int'
1541
+ cls.mro() # Defined in class type
1542
+ cls.error # E: Type[User] has no attribute "error"
1543
+ [builtins fixtures/classmethod.py]
1544
+ [out]
1545
+ main: note: In function "process":
1546
+
1547
+ [case testTypeUsingTypeCClassMethodUnion]
1548
+ # Ideally this would work, but not worth the effort; just don't crash
1549
+ from typing import Type, Union
1550
+ class User:
1551
+ @classmethod
1552
+ def foo(cls) -> int: pass
1553
+ def bar(self) -> int: pass
1554
+ class ProUser(User): pass
1555
+ class BasicUser(User): pass
1556
+ def process(cls: Type[Union[BasicUser, ProUser]]):
1557
+ cls.foo() # E: Type[Union[BasicUser, ProUser]] has no attribute "foo"
1558
+ obj = cls()
1559
+ cls.bar(obj) # E: Type[Union[BasicUser, ProUser]] has no attribute "bar"
1560
+ cls.mro() # Defined in class type
1561
+ cls.error # E: Type[Union[BasicUser, ProUser]] has no attribute "error"
1562
+ [builtins fixtures/classmethod.py]
1563
+ [out]
1564
+ main: note: In function "process":
1565
+
1566
+ [case testTypeUsingTypeCClassMethodFromTypeVar]
1567
+ from typing import Type, TypeVar
1568
+ class User:
1569
+ @classmethod
1570
+ def foo(cls) -> int: pass
1571
+ def bar(self) -> int: pass
1572
+ U = TypeVar('U', bound=User)
1573
+ def process(cls: Type[U]):
1574
+ reveal_type(cls.foo()) # E: Revealed type is 'builtins.int'
1575
+ obj = cls()
1576
+ reveal_type(cls.bar(obj)) # E: Revealed type is 'builtins.int'
1577
+ cls.mro() # Defined in class type
1578
+ cls.error # E: Type[U] has no attribute "error"
1579
+ [builtins fixtures/classmethod.py]
1580
+ [out]
1581
+ main: note: In function "process":
1582
+
1583
+ [case testTypeUsingTypeCClassMethodFromTypeVarUnionBound]
1584
+ # Ideally this would work, but not worth the effort; just don't crash
1585
+ from typing import Type, TypeVar, Union
1586
+ class User:
1587
+ @classmethod
1588
+ def foo(cls) -> int: pass
1589
+ def bar(self) -> int: pass
1590
+ class ProUser(User): pass
1591
+ class BasicUser(User): pass
1592
+ U = TypeVar('U', bound=Union[ProUser, BasicUser])
1593
+ def process(cls: Type[U]):
1594
+ cls.foo() # E: Type[U] has no attribute "foo"
1595
+ obj = cls()
1596
+ cls.bar(obj) # E: Type[U] has no attribute "bar"
1597
+ cls.mro() # Defined in class type
1598
+ cls.error # E: Type[U] has no attribute "error"
1599
+ [builtins fixtures/classmethod.py]
1600
+ [out]
1601
+ main: note: In function "process":
0 commit comments