Skip to content

Commit 6a787bf

Browse files
authored
Conformance tests for Callables (#1731)
Added new conformance test to go along with the recently-accepted new sections in the "Callables" chapter of the typing spec.
1 parent b2d9173 commit 6a787bf

13 files changed

+1071
-66
lines changed
Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
Incorrectly treats "*args: T, **kwargs: T" as "..." when T is specialized to Any.
4+
Does not treat "*args: Any, **kargs: Any" as "..." when separated by keyword parameter.
5+
"""
26
output = """
3-
callables_annotation.py:13: error: Too few arguments [call-arg]
4-
callables_annotation.py:14: error: Argument 2 has incompatible type "int"; expected "str" [arg-type]
5-
callables_annotation.py:15: error: Too many arguments [call-arg]
6-
callables_annotation.py:17: error: Unexpected keyword argument "a" [call-arg]
7-
callables_annotation.py:17: error: Unexpected keyword argument "b" [call-arg]
8-
callables_annotation.py:23: error: Too many arguments [call-arg]
9-
callables_annotation.py:40: error: Please use "Callable[[<parameters>], <return type>]" or "Callable" [misc]
10-
callables_annotation.py:41: error: The first argument to Callable must be a list of types, parameter specification, or "..." [valid-type]
11-
callables_annotation.py:41: note: See https://mypy.readthedocs.io/en/stable/kinds_of_types.html#callable-types-and-lambdas
12-
callables_annotation.py:42: error: Bracketed expression "[...]" is not valid as a type [valid-type]
13-
callables_annotation.py:42: note: Did you mean "List[...]"?
14-
callables_annotation.py:43: error: Please use "Callable[[<parameters>], <return type>]" or "Callable" [misc]
15-
callables_annotation.py:44: error: Unexpected "..." [misc]
7+
callables_annotation.py:25: error: Too few arguments [call-arg]
8+
callables_annotation.py:26: error: Argument 2 has incompatible type "int"; expected "str" [arg-type]
9+
callables_annotation.py:27: error: Too many arguments [call-arg]
10+
callables_annotation.py:29: error: Unexpected keyword argument "a" [call-arg]
11+
callables_annotation.py:29: error: Unexpected keyword argument "b" [call-arg]
12+
callables_annotation.py:35: error: Too many arguments [call-arg]
13+
callables_annotation.py:55: error: Please use "Callable[[<parameters>], <return type>]" or "Callable" [misc]
14+
callables_annotation.py:56: error: The first argument to Callable must be a list of types, parameter specification, or "..." [valid-type]
15+
callables_annotation.py:56: note: See https://mypy.readthedocs.io/en/stable/kinds_of_types.html#callable-types-and-lambdas
16+
callables_annotation.py:57: error: Bracketed expression "[...]" is not valid as a type [valid-type]
17+
callables_annotation.py:57: note: Did you mean "List[...]"?
18+
callables_annotation.py:58: error: Please use "Callable[[<parameters>], <return type>]" or "Callable" [misc]
19+
callables_annotation.py:59: error: Unexpected "..." [misc]
20+
callables_annotation.py:91: error: Incompatible types in assignment (expression has type "Callable[[], str]", variable has type "Callable[[int, VarArg(Any), KwArg(Any)], str]") [assignment]
21+
callables_annotation.py:93: error: Incompatible types in assignment (expression has type "Callable[[NamedArg(int, 'a')], str]", variable has type "Callable[[int, VarArg(Any), KwArg(Any)], str]") [assignment]
22+
callables_annotation.py:136: error: Expression is of type "Proto3", not "Callable[..., None]" [assert-type]
23+
callables_annotation.py:139: error: Incompatible types in assignment (expression has type "Proto7", variable has type "Proto6") [assignment]
24+
callables_annotation.py:139: note: Following member(s) of "Proto7" have conflicts:
25+
callables_annotation.py:139: note: Expected:
26+
callables_annotation.py:139: note: def __call__(self, int, /, *args: Any, k: str, **kwargs: Any) -> None
27+
callables_annotation.py:139: note: Got:
28+
callables_annotation.py:139: note: def __call__(self, float, /, b: int, *, k: str, m: str) -> None
29+
callables_annotation.py:152: error: Incompatible types in assignment (expression has type "Callable[[], str]", variable has type "Callable[[int, VarArg(Any), KwArg(Any)], str]") [assignment]
30+
callables_annotation.py:167: error: Incompatible types in assignment (expression has type "Callable[[int, str], str]", variable has type "Callable[[str, VarArg(Any), KwArg(Any)], str]") [assignment]
31+
callables_annotation.py:169: error: Incompatible types in assignment (expression has type "Callable[[int, str], str]", variable has type "Callable[[str, VarArg(Any), KwArg(Any)], str]") [assignment]
1632
"""
17-
conformance_automated = "Pass"
33+
conformance_automated = "Fail"
1834
errors_diff = """
35+
Line 134: Expected 1 errors
36+
Line 139: Unexpected errors ['callables_annotation.py:139: error: Incompatible types in assignment (expression has type "Proto7", variable has type "Proto6") [assignment]']
1937
"""
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
conformant = "Pass"
2+
errors_diff = """
3+
"""
4+
output = """
5+
callables_subtyping.py:26: error: Incompatible types in assignment (expression has type "Callable[[int], int]", variable has type "Callable[[float], float]") [assignment]
6+
callables_subtyping.py:29: error: Incompatible types in assignment (expression has type "Callable[[float], float]", variable has type "Callable[[int], int]") [assignment]
7+
callables_subtyping.py:51: error: Incompatible types in assignment (expression has type "PosOnly2", variable has type "Standard2") [assignment]
8+
callables_subtyping.py:52: error: Incompatible types in assignment (expression has type "KwOnly2", variable has type "Standard2") [assignment]
9+
callables_subtyping.py:52: note: Following member(s) of "KwOnly2" have conflicts:
10+
callables_subtyping.py:52: note: Expected:
11+
callables_subtyping.py:52: note: def __call__(self, a: int, b: int) -> None
12+
callables_subtyping.py:52: note: Got:
13+
callables_subtyping.py:52: note: def __call__(self, *, b: int, a: int) -> None
14+
callables_subtyping.py:55: error: Incompatible types in assignment (expression has type "KwOnly2", variable has type "PosOnly2") [assignment]
15+
callables_subtyping.py:55: note: Following member(s) of "KwOnly2" have conflicts:
16+
callables_subtyping.py:55: note: Expected:
17+
callables_subtyping.py:55: note: def __call__(self, int, int, /) -> None
18+
callables_subtyping.py:55: note: Got:
19+
callables_subtyping.py:55: note: def __call__(self, *, b: int, a: int) -> None
20+
callables_subtyping.py:58: error: Incompatible types in assignment (expression has type "PosOnly2", variable has type "KwOnly2") [assignment]
21+
callables_subtyping.py:58: note: Following member(s) of "PosOnly2" have conflicts:
22+
callables_subtyping.py:58: note: Expected:
23+
callables_subtyping.py:58: note: def __call__(self, *, b: int, a: int) -> None
24+
callables_subtyping.py:58: note: Got:
25+
callables_subtyping.py:58: note: def __call__(self, int, int, /) -> None
26+
callables_subtyping.py:82: error: Incompatible types in assignment (expression has type "NoArgs3", variable has type "IntArgs3") [assignment]
27+
callables_subtyping.py:82: note: Following member(s) of "NoArgs3" have conflicts:
28+
callables_subtyping.py:82: note: Expected:
29+
callables_subtyping.py:82: note: def __call__(self, *args: int) -> None
30+
callables_subtyping.py:82: note: Got:
31+
callables_subtyping.py:82: note: def __call__(self) -> None
32+
callables_subtyping.py:85: error: Incompatible types in assignment (expression has type "NoArgs3", variable has type "FloatArgs3") [assignment]
33+
callables_subtyping.py:85: note: Following member(s) of "NoArgs3" have conflicts:
34+
callables_subtyping.py:85: note: Expected:
35+
callables_subtyping.py:85: note: def __call__(self, *args: float) -> None
36+
callables_subtyping.py:85: note: Got:
37+
callables_subtyping.py:85: note: def __call__(self) -> None
38+
callables_subtyping.py:86: error: Incompatible types in assignment (expression has type "IntArgs3", variable has type "FloatArgs3") [assignment]
39+
callables_subtyping.py:86: note: Following member(s) of "IntArgs3" have conflicts:
40+
callables_subtyping.py:86: note: Expected:
41+
callables_subtyping.py:86: note: def __call__(self, *args: float) -> None
42+
callables_subtyping.py:86: note: Got:
43+
callables_subtyping.py:86: note: def __call__(self, *args: int) -> None
44+
callables_subtyping.py:116: error: Incompatible types in assignment (expression has type "IntArgs4", variable has type "PosOnly4") [assignment]
45+
callables_subtyping.py:116: note: Following member(s) of "IntArgs4" have conflicts:
46+
callables_subtyping.py:116: note: Expected:
47+
callables_subtyping.py:116: note: def __call__(self, int, str, /) -> None
48+
callables_subtyping.py:116: note: Got:
49+
callables_subtyping.py:116: note: def __call__(self, *args: int) -> None
50+
callables_subtyping.py:119: error: Incompatible types in assignment (expression has type "StrArgs4", variable has type "IntStrArgs4") [assignment]
51+
callables_subtyping.py:119: note: Following member(s) of "StrArgs4" have conflicts:
52+
callables_subtyping.py:119: note: Expected:
53+
callables_subtyping.py:119: note: def __call__(self, *args: int | str) -> None
54+
callables_subtyping.py:119: note: Got:
55+
callables_subtyping.py:119: note: def __call__(self, int, /, *args: str) -> None
56+
callables_subtyping.py:120: error: Incompatible types in assignment (expression has type "IntArgs4", variable has type "IntStrArgs4") [assignment]
57+
callables_subtyping.py:120: note: Following member(s) of "IntArgs4" have conflicts:
58+
callables_subtyping.py:120: note: Expected:
59+
callables_subtyping.py:120: note: def __call__(self, *args: int | str) -> None
60+
callables_subtyping.py:120: note: Got:
61+
callables_subtyping.py:120: note: def __call__(self, *args: int) -> None
62+
callables_subtyping.py:122: error: Incompatible types in assignment (expression has type "IntArgs4", variable has type "StrArgs4") [assignment]
63+
callables_subtyping.py:122: note: Following member(s) of "IntArgs4" have conflicts:
64+
callables_subtyping.py:122: note: Expected:
65+
callables_subtyping.py:122: note: def __call__(self, int, /, *args: str) -> None
66+
callables_subtyping.py:122: note: Got:
67+
callables_subtyping.py:122: note: def __call__(self, *args: int) -> None
68+
callables_subtyping.py:124: error: Incompatible types in assignment (expression has type "StrArgs4", variable has type "IntArgs4") [assignment]
69+
callables_subtyping.py:124: note: Following member(s) of "StrArgs4" have conflicts:
70+
callables_subtyping.py:124: note: Expected:
71+
callables_subtyping.py:124: note: def __call__(self, *args: int) -> None
72+
callables_subtyping.py:124: note: Got:
73+
callables_subtyping.py:124: note: def __call__(self, int, /, *args: str) -> None
74+
callables_subtyping.py:125: error: Incompatible types in assignment (expression has type "IntStrArgs4", variable has type "Standard4") [assignment]
75+
callables_subtyping.py:126: error: Incompatible types in assignment (expression has type "StrArgs4", variable has type "Standard4") [assignment]
76+
callables_subtyping.py:151: error: Incompatible types in assignment (expression has type "NoKwargs5", variable has type "IntKwargs5") [assignment]
77+
callables_subtyping.py:151: note: Following member(s) of "NoKwargs5" have conflicts:
78+
callables_subtyping.py:151: note: Expected:
79+
callables_subtyping.py:151: note: def __call__(self, **kwargs: int) -> None
80+
callables_subtyping.py:151: note: Got:
81+
callables_subtyping.py:151: note: def __call__(self) -> None
82+
callables_subtyping.py:154: error: Incompatible types in assignment (expression has type "NoKwargs5", variable has type "FloatKwargs5") [assignment]
83+
callables_subtyping.py:154: note: Following member(s) of "NoKwargs5" have conflicts:
84+
callables_subtyping.py:154: note: Expected:
85+
callables_subtyping.py:154: note: def __call__(self, **kwargs: float) -> None
86+
callables_subtyping.py:154: note: Got:
87+
callables_subtyping.py:154: note: def __call__(self) -> None
88+
callables_subtyping.py:155: error: Incompatible types in assignment (expression has type "IntKwargs5", variable has type "FloatKwargs5") [assignment]
89+
callables_subtyping.py:155: note: Following member(s) of "IntKwargs5" have conflicts:
90+
callables_subtyping.py:155: note: Expected:
91+
callables_subtyping.py:155: note: def __call__(self, **kwargs: float) -> None
92+
callables_subtyping.py:155: note: Got:
93+
callables_subtyping.py:155: note: def __call__(self, **kwargs: int) -> None
94+
callables_subtyping.py:187: error: Incompatible types in assignment (expression has type "IntKwargs6", variable has type "KwOnly6") [assignment]
95+
callables_subtyping.py:187: note: Following member(s) of "IntKwargs6" have conflicts:
96+
callables_subtyping.py:187: note: Expected:
97+
callables_subtyping.py:187: note: def __call__(self, *, a: int, b: str) -> None
98+
callables_subtyping.py:187: note: Got:
99+
callables_subtyping.py:187: note: def __call__(self, **kwargs: int) -> None
100+
callables_subtyping.py:190: error: Incompatible types in assignment (expression has type "StrKwargs6", variable has type "IntStrKwargs6") [assignment]
101+
callables_subtyping.py:190: note: Following member(s) of "StrKwargs6" have conflicts:
102+
callables_subtyping.py:190: note: Expected:
103+
callables_subtyping.py:190: note: def __call__(self, **kwargs: int | str) -> None
104+
callables_subtyping.py:190: note: Got:
105+
callables_subtyping.py:190: note: def __call__(self, *, a: int, **kwargs: str) -> None
106+
callables_subtyping.py:191: error: Incompatible types in assignment (expression has type "IntKwargs6", variable has type "IntStrKwargs6") [assignment]
107+
callables_subtyping.py:191: note: Following member(s) of "IntKwargs6" have conflicts:
108+
callables_subtyping.py:191: note: Expected:
109+
callables_subtyping.py:191: note: def __call__(self, **kwargs: int | str) -> None
110+
callables_subtyping.py:191: note: Got:
111+
callables_subtyping.py:191: note: def __call__(self, **kwargs: int) -> None
112+
callables_subtyping.py:193: error: Incompatible types in assignment (expression has type "IntKwargs6", variable has type "StrKwargs6") [assignment]
113+
callables_subtyping.py:193: note: Following member(s) of "IntKwargs6" have conflicts:
114+
callables_subtyping.py:193: note: Expected:
115+
callables_subtyping.py:193: note: def __call__(self, *, a: int, **kwargs: str) -> None
116+
callables_subtyping.py:193: note: Got:
117+
callables_subtyping.py:193: note: def __call__(self, **kwargs: int) -> None
118+
callables_subtyping.py:195: error: Incompatible types in assignment (expression has type "StrKwargs6", variable has type "IntKwargs6") [assignment]
119+
callables_subtyping.py:195: note: Following member(s) of "StrKwargs6" have conflicts:
120+
callables_subtyping.py:195: note: Expected:
121+
callables_subtyping.py:195: note: def __call__(self, **kwargs: int) -> None
122+
callables_subtyping.py:195: note: Got:
123+
callables_subtyping.py:195: note: def __call__(self, *, a: int, **kwargs: str) -> None
124+
callables_subtyping.py:196: error: Incompatible types in assignment (expression has type "IntStrKwargs6", variable has type "Standard6") [assignment]
125+
callables_subtyping.py:196: note: Following member(s) of "IntStrKwargs6" have conflicts:
126+
callables_subtyping.py:196: note: Expected:
127+
callables_subtyping.py:196: note: def __call__(self, a: int, b: str) -> None
128+
callables_subtyping.py:196: note: Got:
129+
callables_subtyping.py:196: note: def __call__(self, **kwargs: int | str) -> None
130+
callables_subtyping.py:197: error: Incompatible types in assignment (expression has type "StrKwargs6", variable has type "Standard6") [assignment]
131+
callables_subtyping.py:197: note: Following member(s) of "StrKwargs6" have conflicts:
132+
callables_subtyping.py:197: note: Expected:
133+
callables_subtyping.py:197: note: def __call__(self, a: int, b: str) -> None
134+
callables_subtyping.py:197: note: Got:
135+
callables_subtyping.py:197: note: def __call__(self, *, a: int, **kwargs: str) -> None
136+
callables_subtyping.py:236: error: Incompatible types in assignment (expression has type "NoDefaultArg8", variable has type "DefaultArg8") [assignment]
137+
callables_subtyping.py:236: note: Following member(s) of "NoDefaultArg8" have conflicts:
138+
callables_subtyping.py:236: note: Expected:
139+
callables_subtyping.py:236: note: def __call__(self, x: int = ...) -> None
140+
callables_subtyping.py:236: note: Got:
141+
callables_subtyping.py:236: note: def __call__(self, x: int) -> None
142+
callables_subtyping.py:237: error: Incompatible types in assignment (expression has type "NoX8", variable has type "DefaultArg8") [assignment]
143+
callables_subtyping.py:237: note: Following member(s) of "NoX8" have conflicts:
144+
callables_subtyping.py:237: note: Expected:
145+
callables_subtyping.py:237: note: def __call__(self, x: int = ...) -> None
146+
callables_subtyping.py:237: note: Got:
147+
callables_subtyping.py:237: note: def __call__(self) -> None
148+
callables_subtyping.py:240: error: Incompatible types in assignment (expression has type "NoX8", variable has type "NoDefaultArg8") [assignment]
149+
callables_subtyping.py:240: note: Following member(s) of "NoX8" have conflicts:
150+
callables_subtyping.py:240: note: Expected:
151+
callables_subtyping.py:240: note: def __call__(self, x: int) -> None
152+
callables_subtyping.py:240: note: Got:
153+
callables_subtyping.py:240: note: def __call__(self) -> None
154+
callables_subtyping.py:243: error: Incompatible types in assignment (expression has type "NoDefaultArg8", variable has type "NoX8") [assignment]
155+
callables_subtyping.py:243: note: Following member(s) of "NoDefaultArg8" have conflicts:
156+
callables_subtyping.py:243: note: Expected:
157+
callables_subtyping.py:243: note: def __call__(self) -> None
158+
callables_subtyping.py:243: note: Got:
159+
callables_subtyping.py:243: note: def __call__(self, x: int) -> None
160+
callables_subtyping.py:273: error: Incompatible types in assignment (expression has type "Overloaded9", variable has type "FloatArg9") [assignment]
161+
callables_subtyping.py:273: note: Following member(s) of "Overloaded9" have conflicts:
162+
callables_subtyping.py:273: note: Expected:
163+
callables_subtyping.py:273: note: def __call__(self, x: float) -> float
164+
callables_subtyping.py:273: note: Got:
165+
callables_subtyping.py:273: note: @overload
166+
callables_subtyping.py:273: note: def __call__(self, x: int) -> int
167+
callables_subtyping.py:273: note: @overload
168+
callables_subtyping.py:273: note: def __call__(self, x: str) -> str
169+
callables_subtyping.py:297: error: Incompatible types in assignment (expression has type "StrArg10", variable has type "Overloaded10") [assignment]
170+
callables_subtyping.py:297: note: Following member(s) of "StrArg10" have conflicts:
171+
callables_subtyping.py:297: note: Expected:
172+
callables_subtyping.py:297: note: @overload
173+
callables_subtyping.py:297: note: def __call__(self, x: int, y: str) -> float
174+
callables_subtyping.py:297: note: @overload
175+
callables_subtyping.py:297: note: def __call__(self, x: str) -> complex
176+
callables_subtyping.py:297: note: Got:
177+
callables_subtyping.py:297: note: def __call__(self, x: str) -> complex
178+
"""
179+
conformance_automated = "Pass"

0 commit comments

Comments
 (0)