Skip to content

Commit d4d893c

Browse files
update tests to follow new error / printing syntax
1 parent 4dfccc6 commit d4d893c

36 files changed

+318
-318
lines changed

test-data/unit/check-assert-type-fail.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ def f(si: arr.array[int]):
3030
[case testAssertTypeFailCallableArgKind]
3131
from typing import assert_type, Callable
3232
def myfunc(arg: int) -> None: pass
33-
assert_type(myfunc, Callable[[int], None]) # E: Expression is of type "Callable[[Arg(int, 'arg')], None]", not "Callable[[int], None]"
33+
assert_type(myfunc, Callable[[int], None]) # E: Expression is of type "(arg: int) -> None", not "(int) -> None"

test-data/unit/check-callable.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ x = 5 # type: Union[int, Callable[[], str]]
155155
if callable(x) and x() == 'test':
156156
x()
157157
else:
158-
x + 5 # E: Unsupported left operand type for + ("Callable[[], str]") \
159-
# N: Left operand is of type "Union[int, Callable[[], str]]"
158+
x + 5 # E: Unsupported left operand type for + ("() -> str") \
159+
# N: Left operand is of type "Union[int, () -> str]"
160160

161161
[builtins fixtures/callable.pyi]
162162

@@ -605,14 +605,14 @@ class Call(Protocol):
605605
def __call__(self, x: int, *args: Any, **kwargs: Any) -> None: ...
606606

607607
def f1() -> None: ...
608-
a1: Call = f1 # E: Incompatible types in assignment (expression has type "Callable[[], None]", variable has type "Call") \
609-
# N: "Call.__call__" has type "Callable[[Arg(int, 'x'), VarArg(Any), KwArg(Any)], None]"
608+
a1: Call = f1 # E: Incompatible types in assignment (expression has type "() -> None", variable has type "Call") \
609+
# N: "Call.__call__" has type "(x: int, Any, Any) -> None"
610610
def f2(x: str) -> None: ...
611-
a2: Call = f2 # E: Incompatible types in assignment (expression has type "Callable[[str], None]", variable has type "Call") \
612-
# N: "Call.__call__" has type "Callable[[Arg(int, 'x'), VarArg(Any), KwArg(Any)], None]"
611+
a2: Call = f2 # E: Incompatible types in assignment (expression has type "(str) -> None", variable has type "Call") \
612+
# N: "Call.__call__" has type "(x: int, Any, Any) -> None"
613613
def f3(y: int) -> None: ...
614-
a3: Call = f3 # E: Incompatible types in assignment (expression has type "Callable[[int], None]", variable has type "Call") \
615-
# N: "Call.__call__" has type "Callable[[Arg(int, 'x'), VarArg(Any), KwArg(Any)], None]"
614+
a3: Call = f3 # E: Incompatible types in assignment (expression has type "(int) -> None", variable has type "Call") \
615+
# N: "Call.__call__" has type "(x: int, Any, Any) -> None"
616616
def f4(x: int) -> None: ...
617617
a4: Call = f4
618618

test-data/unit/check-classes.test

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ import typing
104104
class A:
105105
def f(self): pass
106106
A().f = None # E: Cannot assign to a method \
107-
# E: Incompatible types in assignment (expression has type "None", variable has type "Callable[[], Any]")
107+
# E: Incompatible types in assignment (expression has type "None", variable has type "() -> Any")
108108

109109

110110
[case testOverrideAttributeWithMethod]
@@ -145,7 +145,7 @@ class Base:
145145
pass
146146

147147
class Derived(Base):
148-
__hash__ = 1 # E: Incompatible types in assignment (expression has type "int", base class "Base" defined the type as "Callable[[Base], int]")
148+
__hash__ = 1 # E: Incompatible types in assignment (expression has type "int", base class "Base" defined the type as "(Base) -> int")
149149

150150
[case testOverridePartialAttributeWithMethod]
151151
# This was crashing: https://github.com/python/mypy/issues/11686.
@@ -740,13 +740,13 @@ class A:
740740
f3: Callable[[str], None]
741741

742742
class B(A):
743-
def f1(self, x: object) -> None: pass # E: Covariant override of a mutable attribute (base class "A" defined the type as "Callable[[str], None]", override has type "Callable[[object], None]")
743+
def f1(self, x: object) -> None: pass # E: Covariant override of a mutable attribute (base class "A" defined the type as "(str) -> None", override has type "(object) -> None")
744744

745745
@classmethod
746-
def f2(cls, x: object) -> None: pass # E: Covariant override of a mutable attribute (base class "A" defined the type as "Callable[[str], None]", override has type "Callable[[object], None]")
746+
def f2(cls, x: object) -> None: pass # E: Covariant override of a mutable attribute (base class "A" defined the type as "(str) -> None", override has type "(object) -> None")
747747

748748
@staticmethod
749-
def f3(x: object) -> None: pass # E: Covariant override of a mutable attribute (base class "A" defined the type as "Callable[[str], None]", override has type "Callable[[object], None]")
749+
def f3(x: object) -> None: pass # E: Covariant override of a mutable attribute (base class "A" defined the type as "(str) -> None", override has type "(object) -> None")
750750
[builtins fixtures/classmethod.pyi]
751751

752752
[case testOverrideCallableAttributeWithSettableProperty]
@@ -770,7 +770,7 @@ class A:
770770
f: Callable[[str], None]
771771

772772
class B(A):
773-
@property # E: Covariant override of a mutable attribute (base class "A" defined the type as "Callable[[str], None]", override has type "Callable[[object], None]")
773+
@property # E: Covariant override of a mutable attribute (base class "A" defined the type as "(str) -> None", override has type "(object) -> None")
774774
def f(self) -> Callable[[object], None]: pass
775775
@func.setter
776776
def f(self, x: object) -> None: pass
@@ -812,18 +812,18 @@ class A:
812812
f4: Union[Callable[[str], str], str]
813813

814814
class B(A):
815-
def f1(self, x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[Callable[[str], str], str]", override has type "Callable[[str], str]")
815+
def f1(self, x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[(str) -> str, str]", override has type "(str) -> str")
816816
pass
817817

818-
def f2(self, x: object) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[Callable[[str], str], str]", override has type "Callable[[object], str]")
818+
def f2(self, x: object) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[(str) -> str, str]", override has type "(object) -> str")
819819
pass
820820

821821
@classmethod
822-
def f3(cls, x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[Callable[[str], str], str]", override has type "Callable[[str], str]")
822+
def f3(cls, x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[(str) -> str, str]", override has type "(str) -> str")
823823
pass
824824

825825
@staticmethod
826-
def f4(x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[Callable[[str], str], str]", override has type "Callable[[str], str]")
826+
def f4(x: str) -> str: # E: Covariant override of a mutable attribute (base class "A" defined the type as "Union[(str) -> str, str]", override has type "(str) -> str")
827827
pass
828828
[builtins fixtures/classmethod.pyi]
829829

@@ -1095,9 +1095,9 @@ class A:
10951095
if int():
10961096
h = f
10971097
g = h
1098-
ff = f # type: Callable[[B], None] # E: Incompatible types in assignment (expression has type "Callable[[A], None]", variable has type "Callable[[B], None]")
1098+
ff = f # type: Callable[[B], None] # E: Incompatible types in assignment (expression has type "(A) -> None", variable has type "(B) -> None")
10991099
if int():
1100-
g = ff # E: Incompatible types in assignment (expression has type "Callable[[B], None]", variable has type "Callable[[A], None]")
1100+
g = ff # E: Incompatible types in assignment (expression has type "(B) -> None", variable has type "(A) -> None")
11011101
[out]
11021102

11031103

@@ -1206,7 +1206,7 @@ import typing
12061206
class A:
12071207
def f(self): pass
12081208
A.f = None # E: Cannot assign to a method \
1209-
# E: Incompatible types in assignment (expression has type "None", variable has type "Callable[[A], Any]")
1209+
# E: Incompatible types in assignment (expression has type "None", variable has type "(A) -> Any")
12101210

12111211
[case testAssignToNestedClassViaClass]
12121212
import typing
@@ -2345,8 +2345,8 @@ class B:
23452345
class C:
23462346
def __radd__(self, other, oops) -> int: ...
23472347
[out]
2348-
tmp/foo.pyi:3: error: Invalid signature "Callable[[B], A]"
2349-
tmp/foo.pyi:5: error: Invalid signature "Callable[[C, Any, Any], int]"
2348+
tmp/foo.pyi:3: error: Invalid signature "(B) -> A"
2349+
tmp/foo.pyi:5: error: Invalid signature "(C, Any, Any) -> int"
23502350

23512351
[case testReverseOperatorOrderingCase1]
23522352
class A:
@@ -2934,8 +2934,8 @@ class C:
29342934
class D:
29352935
def __getattribute__(self, x: str) -> None: pass
29362936
[out]
2937-
main:4: error: Invalid signature "Callable[[B, A], B]" for "__getattribute__"
2938-
main:6: error: Invalid signature "Callable[[C, str, str], C]" for "__getattribute__"
2937+
main:4: error: Invalid signature "(B, A) -> B" for "__getattribute__"
2938+
main:6: error: Invalid signature "(C, str, str) -> C" for "__getattribute__"
29392939

29402940
[case testGetattr]
29412941
a: A
@@ -3004,7 +3004,7 @@ class C:
30043004

30053005
def do(cd: Callable[..., Any]) -> None: ...
30063006

3007-
do(C()) # E: Argument 1 to "do" has incompatible type "C"; expected "Callable[..., Any]"
3007+
do(C()) # E: Argument 1 to "do" has incompatible type "C"; expected "(..., Any)"
30083008

30093009
[case testGetattrWithCallableTypeVar]
30103010
from typing import Callable, Any, TypeVar
@@ -3040,8 +3040,8 @@ class C:
30403040
class D:
30413041
def __getattr__(self, x: str) -> None: pass
30423042
[out]
3043-
main:4: error: Invalid signature "Callable[[B, A], B]" for "__getattr__"
3044-
main:6: error: Invalid signature "Callable[[C, str, str], C]" for "__getattr__"
3043+
main:4: error: Invalid signature "(B, A) -> B" for "__getattr__"
3044+
main:6: error: Invalid signature "(C, str, str) -> C" for "__getattr__"
30453045

30463046
[case testSetattr]
30473047
from typing import Union, Any
@@ -3119,12 +3119,12 @@ b.bad = 'a' # E: Incompatible types in assignment (expression has type "str", v
31193119
from typing import Any
31203120

31213121
class Test:
3122-
def __setattr__() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument? # E: Invalid signature "Callable[[], None]" for "__setattr__"
3122+
def __setattr__() -> None: ... # E: Method must have at least one argument. Did you forget the "self" argument? # E: Invalid signature "() -> None" for "__setattr__"
31233123
t = Test()
31243124
t.crash = 'test' # E: "Test" has no attribute "crash"
31253125

31263126
class A:
3127-
def __setattr__(self): ... # E: Invalid signature "Callable[[A], Any]" for "__setattr__"
3127+
def __setattr__(self): ... # E: Invalid signature "(A) -> Any" for "__setattr__"
31283128
a = A()
31293129
a.test = 4 # E: "A" has no attribute "test"
31303130

@@ -3134,7 +3134,7 @@ b = B()
31343134
b.integer = 5
31353135

31363136
class C:
3137-
def __setattr__(self, name: int, value: int) -> None: ... # E: Invalid signature "Callable[[C, int, int], None]" for "__setattr__"
3137+
def __setattr__(self, name: int, value: int) -> None: ... # E: Invalid signature "(C, int, int) -> None" for "__setattr__"
31383138
c = C()
31393139
c.check = 13
31403140

@@ -3355,7 +3355,7 @@ class B:
33553355
a = A
33563356
bad = lambda: 42
33573357

3358-
B().bad() # E: Attribute function "bad" with type "Callable[[], int]" does not accept self argument
3358+
B().bad() # E: Attribute function "bad" with type "() -> int" does not accept self argument
33593359
reveal_type(B.a) # N: Revealed type is "def () -> __main__.A"
33603360
reveal_type(B().a) # N: Revealed type is "def () -> __main__.A"
33613361
reveal_type(B().a()) # N: Revealed type is "__main__.A"
@@ -4439,7 +4439,7 @@ class A:
44394439
def a(self) -> None: pass
44404440
b = 1
44414441
class B(A):
4442-
a = 1 # E: Incompatible types in assignment (expression has type "int", base class "A" defined the type as "Callable[[A], None]")
4442+
a = 1 # E: Incompatible types in assignment (expression has type "int", base class "A" defined the type as "(A) -> None")
44434443
def b(self) -> None: pass # E: Signature of "b" incompatible with supertype "A" \
44444444
# N: Superclass: \
44454445
# N: int \
@@ -4483,7 +4483,7 @@ class C(B):
44834483
def m(self, a: str) -> None: pass
44844484
n = m
44854485
[out]
4486-
main:5: error: Incompatible types in assignment (expression has type "Callable[[str], None]", base class "B" defined the type as "Callable[[int], None]")
4486+
main:5: error: Incompatible types in assignment (expression has type "(str) -> None", base class "B" defined the type as "(int) -> None")
44874487

44884488
[case testInstanceMethodOverwriteTypevar]
44894489
from typing import Generic, TypeVar
@@ -4527,7 +4527,7 @@ class C(B):
45274527
n = m
45284528
[builtins fixtures/classmethod.pyi]
45294529
[out]
4530-
main:7: error: Incompatible types in assignment (expression has type "Callable[[str], None]", base class "B" defined the type as "Callable[[int], None]")
4530+
main:7: error: Incompatible types in assignment (expression has type "(str) -> None", base class "B" defined the type as "(int) -> None")
45314531

45324532
[case testClassSpec]
45334533
from typing import Callable
@@ -4545,7 +4545,7 @@ class B(A):
45454545
def c(self, a: str) -> int: pass
45464546
b = c
45474547
[out]
4548-
main:6: error: Incompatible types in assignment (expression has type "Callable[[str], int]", base class "A" defined the type as "Callable[[int], int]")
4548+
main:6: error: Incompatible types in assignment (expression has type "(str) -> int", base class "A" defined the type as "(int) -> int")
45494549

45504550
[case testClassStaticMethod]
45514551
class A():
@@ -4557,7 +4557,7 @@ class B(A):
45574557
a = b
45584558
[builtins fixtures/staticmethod.pyi]
45594559
[out]
4560-
main:7: error: Incompatible types in assignment (expression has type "Callable[[str], None]", base class "A" defined the type as "Callable[[int], None]")
4560+
main:7: error: Incompatible types in assignment (expression has type "(str) -> None", base class "A" defined the type as "(int) -> None")
45614561

45624562
[case testClassStaticMethodIndirect]
45634563
class A():
@@ -4570,7 +4570,7 @@ class B(A):
45704570
c = b
45714571
[builtins fixtures/staticmethod.pyi]
45724572
[out]
4573-
main:8: error: Incompatible types in assignment (expression has type "Callable[[str], None]", base class "A" defined the type as "Callable[[int], None]")
4573+
main:8: error: Incompatible types in assignment (expression has type "(str) -> None", base class "A" defined the type as "(int) -> None")
45744574

45754575
[case testClassStaticMethodSubclassing]
45764576
class A:
@@ -5053,9 +5053,9 @@ reveal_type(A.g4) # N: Revealed type is "def () -> def () -> __main__.A"
50535053
class B(metaclass=M):
50545054
def foo(self): pass
50555055

5056-
B.g1 # E: Invalid self argument "Type[B]" to attribute function "g1" with type "Callable[[Type[A]], A]"
5057-
B.g2 # E: Invalid self argument "Type[B]" to attribute function "g2" with type "Callable[[Type[TA]], TA]"
5058-
B.g3 # E: Invalid self argument "Type[B]" to attribute function "g3" with type "Callable[[TTA], TTA]"
5056+
B.g1 # E: Invalid self argument "Type[B]" to attribute function "g1" with type "(Type[A]) -> A"
5057+
B.g2 # E: Invalid self argument "Type[B]" to attribute function "g2" with type "(Type[TA]) -> TA"
5058+
B.g3 # E: Invalid self argument "Type[B]" to attribute function "g3" with type "(TTA) -> TTA"
50595059
reveal_type(B.g4) # N: Revealed type is "def () -> def () -> __main__.B"
50605060

50615061
# 4 examples of unsoundness - instantiation, classmethod, staticmethod and ClassVar:
@@ -5068,9 +5068,9 @@ reveal_type(ta.g3) # N: Revealed type is "def () -> Type[__main__.A]"
50685068
reveal_type(ta.g4) # N: Revealed type is "def () -> Type[__main__.A]"
50695069

50705070
x: M = ta
5071-
x.g1 # E: Invalid self argument "M" to attribute function "g1" with type "Callable[[Type[A]], A]"
5072-
x.g2 # E: Invalid self argument "M" to attribute function "g2" with type "Callable[[Type[TA]], TA]"
5073-
x.g3 # E: Invalid self argument "M" to attribute function "g3" with type "Callable[[TTA], TTA]"
5071+
x.g1 # E: Invalid self argument "M" to attribute function "g1" with type "(Type[A]) -> A"
5072+
x.g2 # E: Invalid self argument "M" to attribute function "g2" with type "(Type[TA]) -> TA"
5073+
x.g3 # E: Invalid self argument "M" to attribute function "g3" with type "(TTA) -> TTA"
50745074
reveal_type(x.g4) # N: Revealed type is "def () -> __main__.M"
50755075

50765076
def r(ta: Type[TA], tta: TTA) -> None:
@@ -7823,7 +7823,7 @@ class Foo:
78237823
def meth1(self, a: str) -> str: ... # E: Name "meth1" already defined on line 5
78247824

78257825
def meth2(self, a: str) -> str: ...
7826-
from mod1 import meth2 # E: Incompatible import of "meth2" (imported name has type "Callable[[int], int]", local name has type "Callable[[Foo, str], str]")
7826+
from mod1 import meth2 # E: Incompatible import of "meth2" (imported name has type "(int) -> int", local name has type "(Foo, str) -> str")
78277827

78287828
class Bar:
78297829
from mod1 import foo # E: Unsupported class scoped import

test-data/unit/check-custom-plugin.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ from mypy_extensions import DefaultArg
330330
from m import Signal
331331
s: Signal[[int, DefaultArg(str, 'x')]] = Signal()
332332
reveal_type(s) # N: Revealed type is "m.Signal[def (builtins.int, x: builtins.str =)]"
333-
s.x # E: "Signal[Callable[[int, str], None]]" has no attribute "x"
333+
s.x # E: "Signal[(int, str) -> None]" has no attribute "x"
334334
ss: Signal[int, str] # E: Invalid "Signal" type (expected "Signal[[t, ...]]")
335335
[file m.py]
336336
from typing import TypeVar, Generic, Callable

0 commit comments

Comments
 (0)