You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test-data/unit/check-classes.test
+37-37Lines changed: 37 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -104,7 +104,7 @@ import typing
104
104
class A:
105
105
def f(self): pass
106
106
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")
108
108
109
109
110
110
[case testOverrideAttributeWithMethod]
@@ -145,7 +145,7 @@ class Base:
145
145
pass
146
146
147
147
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")
149
149
150
150
[case testOverridePartialAttributeWithMethod]
151
151
# This was crashing: https://github.com/python/mypy/issues/11686.
@@ -740,13 +740,13 @@ class A:
740
740
f3: Callable[[str], None]
741
741
742
742
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")
744
744
745
745
@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")
747
747
748
748
@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")
@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")
774
774
def f(self) -> Callable[[object], None]: pass
775
775
@func.setter
776
776
def f(self, x: object) -> None: pass
@@ -812,18 +812,18 @@ class A:
812
812
f4: Union[Callable[[str], str], str]
813
813
814
814
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")
816
816
pass
817
817
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")
819
819
pass
820
820
821
821
@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")
823
823
pass
824
824
825
825
@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")
827
827
pass
828
828
[builtins fixtures/classmethod.pyi]
829
829
@@ -1095,9 +1095,9 @@ class A:
1095
1095
if int():
1096
1096
h = f
1097
1097
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")
1099
1099
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")
1101
1101
[out]
1102
1102
1103
1103
@@ -1206,7 +1206,7 @@ import typing
1206
1206
class A:
1207
1207
def f(self): pass
1208
1208
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")
@@ -3119,12 +3119,12 @@ b.bad = 'a' # E: Incompatible types in assignment (expression has type "str", v
3119
3119
from typing import Any
3120
3120
3121
3121
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__"
3123
3123
t = Test()
3124
3124
t.crash = 'test' # E: "Test" has no attribute "crash"
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
3359
3359
reveal_type(B.a) # N: Revealed type is "def () -> __main__.A"
3360
3360
reveal_type(B().a) # N: Revealed type is "def () -> __main__.A"
3361
3361
reveal_type(B().a()) # N: Revealed type is "__main__.A"
@@ -4439,7 +4439,7 @@ class A:
4439
4439
def a(self) -> None: pass
4440
4440
b = 1
4441
4441
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")
4443
4443
def b(self) -> None: pass # E: Signature of "b" incompatible with supertype "A" \
4444
4444
# N: Superclass: \
4445
4445
# N: int \
@@ -4483,7 +4483,7 @@ class C(B):
4483
4483
def m(self, a: str) -> None: pass
4484
4484
n = m
4485
4485
[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")
4487
4487
4488
4488
[case testInstanceMethodOverwriteTypevar]
4489
4489
from typing import Generic, TypeVar
@@ -4527,7 +4527,7 @@ class C(B):
4527
4527
n = m
4528
4528
[builtins fixtures/classmethod.pyi]
4529
4529
[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")
4531
4531
4532
4532
[case testClassSpec]
4533
4533
from typing import Callable
@@ -4545,7 +4545,7 @@ class B(A):
4545
4545
def c(self, a: str) -> int: pass
4546
4546
b = c
4547
4547
[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")
4549
4549
4550
4550
[case testClassStaticMethod]
4551
4551
class A():
@@ -4557,7 +4557,7 @@ class B(A):
4557
4557
a = b
4558
4558
[builtins fixtures/staticmethod.pyi]
4559
4559
[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")
4561
4561
4562
4562
[case testClassStaticMethodIndirect]
4563
4563
class A():
@@ -4570,7 +4570,7 @@ class B(A):
4570
4570
c = b
4571
4571
[builtins fixtures/staticmethod.pyi]
4572
4572
[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")
4574
4574
4575
4575
[case testClassStaticMethodSubclassing]
4576
4576
class A:
@@ -5053,9 +5053,9 @@ reveal_type(A.g4) # N: Revealed type is "def () -> def () -> __main__.A"
5053
5053
class B(metaclass=M):
5054
5054
def foo(self): pass
5055
5055
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"
5059
5059
reveal_type(B.g4) # N: Revealed type is "def () -> def () -> __main__.B"
5060
5060
5061
5061
# 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]"
5068
5068
reveal_type(ta.g4) # N: Revealed type is "def () -> Type[__main__.A]"
5069
5069
5070
5070
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"
5074
5074
reveal_type(x.g4) # N: Revealed type is "def () -> __main__.M"
5075
5075
5076
5076
def r(ta: Type[TA], tta: TTA) -> None:
@@ -7823,7 +7823,7 @@ class Foo:
7823
7823
def meth1(self, a: str) -> str: ... # E: Name "meth1" already defined on line 5
7824
7824
7825
7825
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")
7827
7827
7828
7828
class Bar:
7829
7829
from mod1 import foo # E: Unsupported class scoped import
0 commit comments