Skip to content

Commit 4bf8cc3

Browse files
committed
chore: update tests
1 parent 4d108e2 commit 4bf8cc3

10 files changed

+418
-42
lines changed

test-data/unit/check-abstract.test

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,13 @@ class I(metaclass=ABCMeta):
442442
def g(self, x): pass
443443
class A(I):
444444
def f(self, x): pass
445-
def g(self, x, y) -> None: pass \
446-
# E: Signature of "g" incompatible with supertype "I"
445+
def g(self, x, y) -> None: pass # Fail
447446
[out]
447+
main:10: error: Signature of "g" incompatible with supertype "I"
448+
main:10: note: Superclass:
449+
main:10: note: def g(x: Any) -> Any
450+
main:10: note: Subclass:
451+
main:10: note: def g(self, x: Any, y: Any) -> None
448452

449453
[case testAbstractClassWithAllDynamicTypes2]
450454
from abc import abstractmethod, ABCMeta

test-data/unit/check-classes.test

Lines changed: 80 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,15 @@ class B(A):
310310
def g(self, x: A) -> A: pass # Fail
311311
[out]
312312
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
313317
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
314322

315323
[case testMethodOverridingAcrossDeepInheritanceHierarchy1]
316324
import typing
@@ -403,10 +411,16 @@ class B(A):
403411
@int_to_none
404412
def f(self) -> int: pass
405413
@str_to_int
406-
def g(self) -> str: pass # E: Signature of "g" incompatible with supertype "A"
414+
def g(self) -> str: pass # Fail
407415
@int_to_none
408416
@str_to_int
409417
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
410424

411425
[case testOverrideDecorated]
412426
from typing import Callable
@@ -423,9 +437,15 @@ class A:
423437

424438
class B(A):
425439
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
427441
@str_to_int
428442
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
429449

430450
[case testOverrideWithDecoratorReturningAny]
431451
def dec(f): pass
@@ -1236,7 +1256,7 @@ class A:
12361256
def g(self) -> None: pass
12371257

12381258
class B(A):
1239-
def f(self) -> None: pass # E: Signature of "f" incompatible with supertype "A"
1259+
def f(self) -> None: pass # Fail
12401260

12411261
@classmethod
12421262
def g(cls) -> None: pass
@@ -1245,6 +1265,13 @@ class C(A):
12451265
@staticmethod
12461266
def f() -> None: pass
12471267
[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
12481275

12491276
-- Properties
12501277
-- ----------
@@ -1808,12 +1835,20 @@ from typing import overload
18081835
class A:
18091836
def __add__(self, x: int) -> int: pass
18101837
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
18131839
def __add__(self, x: int) -> int: pass
18141840
@overload
18151841
def __add__(self, x: str) -> str: pass
18161842
[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
18171852

18181853
[case testOperatorMethodOverrideWideningArgumentType]
18191854
import typing
@@ -1912,13 +1947,27 @@ class A:
19121947
@overload
19131948
def __add__(self, x: str) -> 'A': pass
19141949
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
19171951
def __add__(self, x: int) -> A: pass
19181952
@overload
19191953
def __add__(self, x: str) -> A: pass
19201954
@overload
19211955
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
19221971

19231972
[case testOverloadedOperatorMethodOverrideWithSwitchedItemOrder]
19241973
from foo import *
@@ -3664,14 +3713,28 @@ class Super:
36643713
def foo(self, a: C) -> C: pass
36653714

36663715
class Sub(Super):
3667-
@overload # E: Signature of "foo" incompatible with supertype "Super"
3716+
@overload # Fail
36683717
def foo(self, a: A) -> A: pass
36693718
@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
36713720
@overload
36723721
def foo(self, a: C) -> C: pass
36733722
[builtins fixtures/classmethod.pyi]
36743723
[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
36753738

36763739
[case testTypeTypeOverlapsWithObjectAndType]
36773740
from foo import *
@@ -4086,14 +4149,21 @@ class A:
40864149
def c() -> None: pass
40874150

40884151
class B(A):
4089-
def a(self) -> None: pass # E: Signature of "a" incompatible with supertype "A"
4152+
def a(self) -> None: pass # Fail
40904153

40914154
@classmethod
40924155
def b(cls) -> None: pass
40934156

40944157
@staticmethod
40954158
def c() -> None: pass
40964159
[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
40974167

40984168
[case testTempNode]
40994169
class A():

test-data/unit/check-columns.test

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,11 @@ class B(A):
268268
class C(A):
269269
def f(self, x: int) -> int: pass # E:5: Return type "int" of "f" incompatible with return type "None" in supertype "A"
270270
class D(A):
271-
def f(self) -> None: pass # E:5: Signature of "f" incompatible with supertype "A"
271+
def f(self) -> None: pass # E:5: Signature of "f" incompatible with supertype "A" \
272+
# N:5: Superclass: \
273+
# N:5: def f(self, x: int) -> None \
274+
# N:5: Subclass: \
275+
# N:5: def f(self) -> None
272276

273277
[case testColumnMissingTypeParameters]
274278
# flags: --disallow-any-generics

test-data/unit/check-dynamic-typing.test

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,18 +725,28 @@ import typing
725725
class B:
726726
def f(self, x, y): pass
727727
class A(B):
728-
def f(self, x: 'A') -> None: # E: Signature of "f" incompatible with supertype "B"
728+
def f(self, x: 'A') -> None: # Fail
729729
pass
730730
[out]
731+
main:5: error: Signature of "f" incompatible with supertype "B"
732+
main:5: note: Superclass:
733+
main:5: note: def f(x: Any, y: Any) -> Any
734+
main:5: note: Subclass:
735+
main:5: note: def f(self, x: A) -> None
731736

732737
[case testInvalidOverrideArgumentCountWithImplicitSignature3]
733738
import typing
734739
class B:
735740
def f(self, x: A) -> None: pass
736741
class A(B):
737-
def f(self, x, y) -> None: # E: Signature of "f" incompatible with supertype "B"
742+
def f(self, x, y) -> None: # Fail
738743
x()
739744
[out]
745+
main:5: error: Signature of "f" incompatible with supertype "B"
746+
main:5: note: Superclass:
747+
main:5: note: def f(self, x: A) -> None
748+
main:5: note: Subclass:
749+
main:5: note: def f(self, x: Any, y: Any) -> None
740750

741751
[case testInvalidOverrideWithImplicitSignatureAndClassMethod1]
742752
class B:

test-data/unit/check-errorcodes.test

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ class B(A):
277277
def f(self) -> str: # E: Return type "str" of "f" incompatible with return type "int" in supertype "A" [override]
278278
return ''
279279
class C(A):
280-
def f(self, x: int) -> int: # E: Signature of "f" incompatible with supertype "A" [override]
280+
def f(self, x: int) -> int: # E: Signature of "f" incompatible with supertype "A" [override] \
281+
# N: Superclass: \
282+
# N: def f(self) -> int \
283+
# N: Subclass: \
284+
# N: def f(self, x: int) -> int
281285
return 0
282286
class D:
283287
def f(self, x: int) -> int:

test-data/unit/check-functions.test

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ class B(A):
3737
def f(self, *, b: str, a: int) -> None: pass
3838

3939
class C(A):
40-
def f(self, *, b: int, a: str) -> None: pass # E: Signature of "f" incompatible with supertype "A"
40+
def f(self, *, b: int, a: str) -> None: pass # Fail
41+
[out]
42+
main:10: error: Signature of "f" incompatible with supertype "A"
43+
main:10: note: Superclass:
44+
main:10: note: def f(self, *, a: int, b: str) -> None
45+
main:10: note: Subclass:
46+
main:10: note: def f(self, *, b: int, a: str) -> None
4147

4248
[case testPositionalOverridingArgumentNameInsensitivity]
4349
import typing
@@ -62,8 +68,13 @@ class A(object):
6268
def f(self, a: int, b: str) -> None: pass
6369

6470
class B(A):
65-
def f(self, b: int, a: str) -> None: pass # E: Signature of "f" incompatible with supertype "A"
66-
71+
def f(self, b: int, a: str) -> None: pass # Fail
72+
[out]
73+
main:7: error: Signature of "f" incompatible with supertype "A"
74+
main:7: note: Superclass:
75+
main:7: note: def f(self, a: int, b: str) -> None
76+
main:7: note: Subclass:
77+
main:7: note: def f(self, b: int, a: str) -> None
6778

6879
[case testSubtypingFunctionTypes]
6980
from typing import Callable

test-data/unit/check-generic-subtyping.test

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,14 @@ class A:
270270
class B(A):
271271
def f(self, x: List[S], y: List[T]) -> None: pass
272272
class C(A):
273-
def f(self, x: List[T], y: List[T]) -> None: pass # E: Signature of "f" incompatible with supertype "A"
273+
def f(self, x: List[T], y: List[T]) -> None: pass # Fail
274274
[builtins fixtures/list.pyi]
275275
[out]
276+
main:11: error: Signature of "f" incompatible with supertype "A"
277+
main:11: note: Superclass:
278+
main:11: note: def [T, S] f(self, x: List[T], y: List[S]) -> None
279+
main:11: note: Subclass:
280+
main:11: note: def [T] f(self, x: List[T], y: List[T]) -> None
276281

277282
[case testOverrideGenericMethodInNonGenericClassGeneralize]
278283
from typing import TypeVar
@@ -294,7 +299,10 @@ main:12: error: Argument 2 of "f" is incompatible with supertype "A"; supertype
294299
main:12: note: This violates the Liskov substitution principle
295300
main:12: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
296301
main:14: error: Signature of "f" incompatible with supertype "A"
297-
302+
main:14: note: Superclass:
303+
main:14: note: def [S] f(self, x: int, y: S) -> None
304+
main:14: note: Subclass:
305+
main:14: note: def [T1 <: str, S] f(self, x: T1, y: S) -> None
298306

299307
-- Inheritance from generic types with implicit dynamic supertype
300308
-- --------------------------------------------------------------

0 commit comments

Comments
 (0)