@@ -310,7 +310,15 @@ class B(A):
310
310
def g(self, x: A) -> A: pass # Fail
311
311
[out]
312
312
main:6: error: Signature of "f" incompatible with supertype "A"
313
+ main:6: note: Superclass:
314
+ main:6: note: def f(self, x: A) -> None
315
+ main:6: note: Subclass:
316
+ main:6: note: def f(self, x: A, y: A) -> None
313
317
main:7: error: Signature of "g" incompatible with supertype "A"
318
+ main:7: note: Superclass:
319
+ main:7: note: def g(self, x: A, y: B) -> A
320
+ main:7: note: Subclass:
321
+ main:7: note: def g(self, x: A) -> A
314
322
315
323
[case testMethodOverridingAcrossDeepInheritanceHierarchy1]
316
324
import typing
@@ -403,10 +411,16 @@ class B(A):
403
411
@int_to_none
404
412
def f(self) -> int: pass
405
413
@str_to_int
406
- def g(self) -> str: pass # E: Signature of "g" incompatible with supertype "A"
414
+ def g(self) -> str: pass # Fail
407
415
@int_to_none
408
416
@str_to_int
409
417
def h(self) -> str: pass
418
+ [out]
419
+ main:15: error: Signature of "g" incompatible with supertype "A"
420
+ main:15: note: Superclass:
421
+ main:15: note: def g(self) -> str
422
+ main:15: note: Subclass:
423
+ main:15: note: def g(*Any, **Any) -> int
410
424
411
425
[case testOverrideDecorated]
412
426
from typing import Callable
@@ -423,9 +437,15 @@ class A:
423
437
424
438
class B(A):
425
439
def f(self) -> int: pass
426
- def g(self) -> str: pass # E: Signature of "g" incompatible with supertype "A"
440
+ def g(self) -> str: pass # Fail
427
441
@str_to_int
428
442
def h(self) -> str: pass
443
+ [out]
444
+ main:15: error: Signature of "g" incompatible with supertype "A"
445
+ main:15: note: Superclass:
446
+ main:15: note: def g(*Any, **Any) -> int
447
+ main:15: note: Subclass:
448
+ main:15: note: def g(self) -> str
429
449
430
450
[case testOverrideWithDecoratorReturningAny]
431
451
def dec(f): pass
@@ -1236,7 +1256,7 @@ class A:
1236
1256
def g(self) -> None: pass
1237
1257
1238
1258
class B(A):
1239
- def f(self) -> None: pass # E: Signature of "f" incompatible with supertype "A"
1259
+ def f(self) -> None: pass # Fail
1240
1260
1241
1261
@classmethod
1242
1262
def g(cls) -> None: pass
@@ -1245,6 +1265,13 @@ class C(A):
1245
1265
@staticmethod
1246
1266
def f() -> None: pass
1247
1267
[builtins fixtures/classmethod.pyi]
1268
+ [out]
1269
+ main:8: error: Signature of "f" incompatible with supertype "A"
1270
+ main:8: note: Superclass:
1271
+ main:8: note: @classmethod
1272
+ main:8: note: def f(cls) -> None
1273
+ main:8: note: Subclass:
1274
+ main:8: note: def f(self) -> None
1248
1275
1249
1276
-- Properties
1250
1277
-- ----------
@@ -1808,12 +1835,20 @@ from typing import overload
1808
1835
class A:
1809
1836
def __add__(self, x: int) -> int: pass
1810
1837
class B(A):
1811
- @overload # E: Signature of "__add__" incompatible with supertype "A" \
1812
- # N: Overloaded operator methods can't have wider argument types in overrides
1838
+ @overload # Fail
1813
1839
def __add__(self, x: int) -> int: pass
1814
1840
@overload
1815
1841
def __add__(self, x: str) -> str: pass
1816
1842
[out]
1843
+ tmp/foo.pyi:5: error: Signature of "__add__" incompatible with supertype "A"
1844
+ tmp/foo.pyi:5: note: Superclass:
1845
+ tmp/foo.pyi:5: note: def __add__(self, int) -> int
1846
+ tmp/foo.pyi:5: note: Subclass:
1847
+ tmp/foo.pyi:5: note: @overload
1848
+ tmp/foo.pyi:5: note: def __add__(self, int) -> int
1849
+ tmp/foo.pyi:5: note: @overload
1850
+ tmp/foo.pyi:5: note: def __add__(self, str) -> str
1851
+ tmp/foo.pyi:5: note: Overloaded operator methods cannot have wider argument types in overrides
1817
1852
1818
1853
[case testOperatorMethodOverrideWideningArgumentType]
1819
1854
import typing
@@ -1912,13 +1947,27 @@ class A:
1912
1947
@overload
1913
1948
def __add__(self, x: str) -> 'A': pass
1914
1949
class B(A):
1915
- @overload # E: Signature of "__add__" incompatible with supertype "A" \
1916
- # N: Overloaded operator methods can't have wider argument types in overrides
1950
+ @overload # Fail
1917
1951
def __add__(self, x: int) -> A: pass
1918
1952
@overload
1919
1953
def __add__(self, x: str) -> A: pass
1920
1954
@overload
1921
1955
def __add__(self, x: type) -> A: pass
1956
+ [out]
1957
+ tmp/foo.pyi:8: error: Signature of "__add__" incompatible with supertype "A"
1958
+ tmp/foo.pyi:8: note: Superclass:
1959
+ tmp/foo.pyi:8: note: @overload
1960
+ tmp/foo.pyi:8: note: def __add__(self, int) -> A
1961
+ tmp/foo.pyi:8: note: @overload
1962
+ tmp/foo.pyi:8: note: def __add__(self, str) -> A
1963
+ tmp/foo.pyi:8: note: Subclass:
1964
+ tmp/foo.pyi:8: note: @overload
1965
+ tmp/foo.pyi:8: note: def __add__(self, int) -> A
1966
+ tmp/foo.pyi:8: note: @overload
1967
+ tmp/foo.pyi:8: note: def __add__(self, str) -> A
1968
+ tmp/foo.pyi:8: note: @overload
1969
+ tmp/foo.pyi:8: note: def __add__(self, type) -> A
1970
+ tmp/foo.pyi:8: note: Overloaded operator methods cannot have wider argument types in overrides
1922
1971
1923
1972
[case testOverloadedOperatorMethodOverrideWithSwitchedItemOrder]
1924
1973
from foo import *
@@ -3664,14 +3713,28 @@ class Super:
3664
3713
def foo(self, a: C) -> C: pass
3665
3714
3666
3715
class Sub(Super):
3667
- @overload # E: Signature of "foo" incompatible with supertype "Super"
3716
+ @overload # Fail
3668
3717
def foo(self, a: A) -> A: pass
3669
3718
@overload
3670
- def foo(self, a: B) -> C: pass # E: Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader
3719
+ def foo(self, a: B) -> C: pass # Fail
3671
3720
@overload
3672
3721
def foo(self, a: C) -> C: pass
3673
3722
[builtins fixtures/classmethod.pyi]
3674
3723
[out]
3724
+ tmp/foo.pyi:16: error: Signature of "foo" incompatible with supertype "Super"
3725
+ tmp/foo.pyi:16: note: Superclass:
3726
+ tmp/foo.pyi:16: note: @overload
3727
+ tmp/foo.pyi:16: note: def foo(self, a: A) -> A
3728
+ tmp/foo.pyi:16: note: @overload
3729
+ tmp/foo.pyi:16: note: def foo(self, a: C) -> C
3730
+ tmp/foo.pyi:16: note: Subclass:
3731
+ tmp/foo.pyi:16: note: @overload
3732
+ tmp/foo.pyi:16: note: def foo(self, a: A) -> A
3733
+ tmp/foo.pyi:16: note: @overload
3734
+ tmp/foo.pyi:16: note: def foo(self, a: B) -> C
3735
+ tmp/foo.pyi:16: note: @overload
3736
+ tmp/foo.pyi:16: note: def foo(self, a: C) -> C
3737
+ tmp/foo.pyi:19: error: Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader
3675
3738
3676
3739
[case testTypeTypeOverlapsWithObjectAndType]
3677
3740
from foo import *
@@ -4086,14 +4149,21 @@ class A:
4086
4149
def c() -> None: pass
4087
4150
4088
4151
class B(A):
4089
- def a(self) -> None: pass # E: Signature of "a" incompatible with supertype "A"
4152
+ def a(self) -> None: pass # Fail
4090
4153
4091
4154
@classmethod
4092
4155
def b(cls) -> None: pass
4093
4156
4094
4157
@staticmethod
4095
4158
def c() -> None: pass
4096
4159
[builtins fixtures/classmethod.pyi]
4160
+ [out]
4161
+ main:11: error: Signature of "a" incompatible with supertype "A"
4162
+ main:11: note: Superclass:
4163
+ main:11: note: @staticmethod
4164
+ main:11: note: def a() -> None
4165
+ main:11: note: Subclass:
4166
+ main:11: note: def a(self) -> None
4097
4167
4098
4168
[case testTempNode]
4099
4169
class A():
0 commit comments