@@ -1829,3 +1829,83 @@ reveal_type(C.f) # E: Revealed type is 'def () -> builtins.int*'
1829
1829
reveal_type(C.f()) # E: Revealed type is 'builtins.int*'
1830
1830
[builtins fixtures/classmethod.pyi]
1831
1831
[out]
1832
+
1833
+ [case testClassMethodOfGenericClassMultipleInheritance]
1834
+ from typing import TypeVar, Generic
1835
+ t = TypeVar('t')
1836
+ class A(Generic[t]):
1837
+ @classmethod
1838
+ def f(cls) -> t: ...
1839
+ class B(A[str]): pass
1840
+ class C(A[int]): pass
1841
+ reveal_type(B.f) # E: Revealed type is 'def () -> builtins.str*'
1842
+ reveal_type(B.f()) # E: Revealed type is 'builtins.str*'
1843
+ reveal_type(C.f) # E: Revealed type is 'def () -> builtins.int*'
1844
+ reveal_type(C.f()) # E: Revealed type is 'builtins.int*'
1845
+ [builtins fixtures/classmethod.pyi]
1846
+ [out]
1847
+
1848
+ [case testClassMethodOfGenericClassMultipleLevelInheritance]
1849
+ from typing import TypeVar, Generic
1850
+ t = TypeVar('t')
1851
+ class A(Generic[t]):
1852
+ @classmethod
1853
+ def f(cls) -> t: ...
1854
+ class B(A[str]): pass
1855
+ class C(B): pass
1856
+ class D(C): pass
1857
+ class E(D): pass
1858
+ reveal_type(C.f) # E: Revealed type is 'def () -> builtins.str*'
1859
+ reveal_type(C.f()) # E: Revealed type is 'builtins.str*'
1860
+ reveal_type(D.f) # E: Revealed type is 'def () -> builtins.str*'
1861
+ reveal_type(D.f()) # E: Revealed type is 'builtins.str*'
1862
+ reveal_type(E.f) # E: Revealed type is 'def () -> builtins.str*'
1863
+ reveal_type(E.f()) # E: Revealed type is 'builtins.str*'
1864
+ [builtins fixtures/classmethod.pyi]
1865
+ [out]
1866
+
1867
+ [case testClassMethodOfMultipleGenericClass]
1868
+ from typing import TypeVar, Generic
1869
+ t = TypeVar('t')
1870
+ class A(Generic[t]):
1871
+ @classmethod
1872
+ def f(cls) -> t: ...
1873
+ class B(Generic[t]):
1874
+ @classmethod
1875
+ def f(cls) -> t: ...
1876
+ class C(A[str], B[int]): pass
1877
+ class D(A[int], B[str]): pass
1878
+ reveal_type(C.f) # E: Revealed type is 'def () -> builtins.str'
1879
+ reveal_type(C.f()) # E: Revealed type is 'builtins.str'
1880
+ reveal_type(D.f) # E: Revealed type is 'def () -> builtins.int'
1881
+ reveal_type(D.f()) # E: Revealed type is 'builtins.int'
1882
+ [builtins fixtures/classmethod.pyi]
1883
+ [out]
1884
+
1885
+ [case testClassMethodOfGenericClassOverriding]
1886
+ from typing import Generic, TypeVar
1887
+ t = TypeVar('t')
1888
+ class A(Generic[t]):
1889
+ @classmethod
1890
+ def f(cls) -> t: pass
1891
+ class B(A[str]):
1892
+ @classmethod
1893
+ def f(cls) -> str: pass
1894
+ class C(A[str]):
1895
+ @classmethod
1896
+ def f(cls) -> int: pass # E: Return type of "f" incompatible with supertype "A"
1897
+ [builtins fixtures/classmethod.pyi]
1898
+ [out]
1899
+
1900
+ [case testClassMethodOfGenericClassWithBindingAnotherTypeVariable]
1901
+ from typing import Generic, TypeVar
1902
+ t = TypeVar('t')
1903
+ s = TypeVar('s')
1904
+ class A(Generic[t]):
1905
+ @classmethod
1906
+ def f(cls) -> t: pass
1907
+ class B(A[s]): pass
1908
+ reveal_type(A.f()) # E: Revealed type is '<nothing>'
1909
+ reveal_type(B.f()) # E: Revealed type is '<nothing>'
1910
+ [builtins fixtures/classmethod.pyi]
1911
+ [out]
0 commit comments