Skip to content

Commit ed50208

Browse files
authored
Update TypeAlias error messages to remove colon (#16831)
Small update to adjust the error messages following the suggestion in #16825 (comment).
1 parent 7a746c4 commit ed50208

7 files changed

+26
-27
lines changed

mypy/typeanal.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,17 +1995,17 @@ def instantiate_type_alias(
19951995
if node.tvar_tuple_index is not None:
19961996
msg = (
19971997
"Bad number of arguments for type alias,"
1998-
f" expected: at least {min_tv_count}, given: {act_len}"
1998+
f" expected at least {min_tv_count}, given {act_len}"
19991999
)
20002000
elif min_tv_count != max_tv_count:
20012001
msg = (
20022002
"Bad number of arguments for type alias,"
2003-
f" expected between {min_tv_count} and {max_tv_count}, given: {act_len}"
2003+
f" expected between {min_tv_count} and {max_tv_count}, given {act_len}"
20042004
)
20052005
else:
20062006
msg = (
20072007
"Bad number of arguments for type alias,"
2008-
f" expected: {min_tv_count}, given: {act_len}"
2008+
f" expected {min_tv_count}, given {act_len}"
20092009
)
20102010
fail(msg, ctx, code=codes.TYPE_ARG)
20112011
args = []

test-data/unit/check-generics.test

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ main:11:5: error: "Node" expects 2 type arguments, but 3 given
630630
main:15:10: error: "list" expects 1 type argument, but 2 given
631631
main:16:19: error: "list" expects 1 type argument, but 2 given
632632
main:17:25: error: "Node" expects 2 type arguments, but 1 given
633-
main:19:5: error: Bad number of arguments for type alias, expected: 1, given: 2
633+
main:19:5: error: Bad number of arguments for type alias, expected 1, given 2
634634
main:22:13: note: Revealed type is "__main__.Node[builtins.int, builtins.str]"
635635
main:24:13: note: Revealed type is "__main__.Node[__main__.Node[builtins.int, builtins.int], builtins.list[builtins.int]]"
636636
main:26:5: error: Type variable "__main__.T" is invalid as target for type alias
@@ -944,7 +944,7 @@ Transform = Callable[[T, int], Tuple[T, R]]
944944

945945
[case testGenericTypeAliasesImportingWithoutTypeVarError]
946946
from a import Alias
947-
x: Alias[int, str] # E: Bad number of arguments for type alias, expected: 1, given: 2
947+
x: Alias[int, str] # E: Bad number of arguments for type alias, expected 1, given 2
948948
reveal_type(x) # N: Revealed type is "builtins.list[builtins.list[Any]]"
949949

950950
[file a.py]
@@ -953,7 +953,6 @@ T = TypeVar('T')
953953

954954
Alias = List[List[T]]
955955
[builtins fixtures/list.pyi]
956-
[out]
957956

958957
[case testGenericAliasWithTypeVarsFromDifferentModules]
959958
from mod import Alias, TypeVar
@@ -1000,8 +999,8 @@ reveal_type(x) # N: Revealed type is "Union[builtins.int, None]"
1000999
reveal_type(y) # N: Revealed type is "builtins.int"
10011000

10021001
U[int] # E: Type application targets a non-generic function or class
1003-
O[int] # E: Bad number of arguments for type alias, expected: 0, given: 1 # E: Type application is only supported for generic classes
1004-
[out]
1002+
O[int] # E: Bad number of arguments for type alias, expected 0, given 1 \
1003+
# E: Type application is only supported for generic classes
10051004

10061005
[case testAliasesInClassBodyNormalVsSubscripted]
10071006

test-data/unit/check-parameter-specification.test

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,9 +1506,10 @@ def g(x: A[P]) -> None: ... # E: Invalid location for ParamSpec "P" \
15061506
# N: You can use ParamSpec as the first argument to Callable, e.g., 'Callable[P, int]'
15071507

15081508
C = Callable[P, T]
1509-
x: C[int] # E: Bad number of arguments for type alias, expected: 2, given: 1
1509+
x: C[int] # E: Bad number of arguments for type alias, expected 2, given 1
15101510
y: C[int, str] # E: Can only replace ParamSpec with a parameter types list or another ParamSpec, got "int"
1511-
z: C[int, str, bytes] # E: Bad number of arguments for type alias, expected: 2, given: 3
1511+
z: C[int, str, bytes] # E: Bad number of arguments for type alias, expected 2, given 3
1512+
15121513
[builtins fixtures/paramspec.pyi]
15131514

15141515
[case testTrivialParametersHandledCorrectly]

test-data/unit/check-type-aliases.test

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,9 @@ c: C
330330
t: T
331331
reveal_type(c) # N: Revealed type is "def (*Any, **Any) -> Any"
332332
reveal_type(t) # N: Revealed type is "builtins.tuple[Any, ...]"
333-
bad: C[int] # E: Bad number of arguments for type alias, expected: 0, given: 1
334-
also_bad: T[int] # E: Bad number of arguments for type alias, expected: 0, given: 1
333+
bad: C[int] # E: Bad number of arguments for type alias, expected 0, given 1
334+
also_bad: T[int] # E: Bad number of arguments for type alias, expected 0, given 1
335335
[builtins fixtures/tuple.pyi]
336-
[out]
337336

338337
[case testAliasRefOnClass]
339338
from typing import Generic, TypeVar, Type

test-data/unit/check-typevar-defaults.test

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def func_a1(
255255
a: TA1,
256256
b: TA1[float],
257257
c: TA1[float, float],
258-
d: TA1[float, float, float], # E: Bad number of arguments for type alias, expected between 0 and 2, given: 3
258+
d: TA1[float, float, float], # E: Bad number of arguments for type alias, expected between 0 and 2, given 3
259259
) -> None:
260260
reveal_type(a) # N: Revealed type is "builtins.dict[builtins.int, builtins.str]"
261261
reveal_type(b) # N: Revealed type is "builtins.dict[builtins.float, builtins.str]"
@@ -269,7 +269,7 @@ def func_a2(
269269
b: TA2[float],
270270
c: TA2[float, float],
271271
d: TA2[float, float, float],
272-
e: TA2[float, float, float, float], # E: Bad number of arguments for type alias, expected between 1 and 3, given: 4
272+
e: TA2[float, float, float, float], # E: Bad number of arguments for type alias, expected between 1 and 3, given 4
273273
) -> None:
274274
reveal_type(a) # N: Revealed type is "Tuple[Any, builtins.int, builtins.str]"
275275
reveal_type(b) # N: Revealed type is "Tuple[builtins.float, builtins.int, builtins.str]"
@@ -284,7 +284,7 @@ def func_a3(
284284
b: TA3[float],
285285
c: TA3[float, float],
286286
d: TA3[float, float, float],
287-
e: TA3[float, float, float, float], # E: Bad number of arguments for type alias, expected between 1 and 3, given: 4
287+
e: TA3[float, float, float, float], # E: Bad number of arguments for type alias, expected between 1 and 3, given 4
288288
) -> None:
289289
reveal_type(a) # N: Revealed type is "Union[builtins.dict[Any, builtins.int], builtins.list[builtins.str]]"
290290
reveal_type(b) # N: Revealed type is "Union[builtins.dict[builtins.float, builtins.int], builtins.list[builtins.str]]"
@@ -296,10 +296,10 @@ TA4 = Tuple[T1, T4, T2]
296296

297297
def func_a4(
298298
a: TA4, # E: Missing type parameters for generic type "TA4"
299-
b: TA4[float], # E: Bad number of arguments for type alias, expected between 2 and 3, given: 1
299+
b: TA4[float], # E: Bad number of arguments for type alias, expected between 2 and 3, given 1
300300
c: TA4[float, float],
301301
d: TA4[float, float, float],
302-
e: TA4[float, float, float, float], # E: Bad number of arguments for type alias, expected between 2 and 3, given: 4
302+
e: TA4[float, float, float, float], # E: Bad number of arguments for type alias, expected between 2 and 3, given 4
303303
) -> None:
304304
reveal_type(a) # N: Revealed type is "Tuple[Any, Any, builtins.int]"
305305
reveal_type(b) # N: Revealed type is "Tuple[Any, Any, builtins.int]"
@@ -323,7 +323,7 @@ def func_b1(
323323
a: TB1,
324324
b: TB1[[float]],
325325
c: TB1[[float], [float]],
326-
d: TB1[[float], [float], [float]], # E: Bad number of arguments for type alias, expected between 0 and 2, given: 3
326+
d: TB1[[float], [float], [float]], # E: Bad number of arguments for type alias, expected between 0 and 2, given 3
327327
) -> None:
328328
reveal_type(a) # N: Revealed type is "__main__.ClassB1[[builtins.int, builtins.str], [*Any, **Any]]"
329329
reveal_type(b) # N: Revealed type is "__main__.ClassB1[[builtins.float], [*Any, **Any]]"
@@ -337,7 +337,7 @@ def func_b2(
337337
a: TB2, # E: Missing type parameters for generic type "TB2"
338338
b: TB2[[float]],
339339
c: TB2[[float], [float]],
340-
d: TB2[[float], [float], [float]], # E: Bad number of arguments for type alias, expected between 1 and 2, given: 3
340+
d: TB2[[float], [float], [float]], # E: Bad number of arguments for type alias, expected between 1 and 2, given 3
341341
) -> None:
342342
reveal_type(a) # N: Revealed type is "__main__.ClassB2[Any, [builtins.int, builtins.str]]"
343343
reveal_type(b) # N: Revealed type is "__main__.ClassB2[[builtins.float], [builtins.int, builtins.str]]"

test-data/unit/check-typevar-tuple.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,15 @@ Ts = TypeVarTuple("Ts")
769769
class G(Generic[Unpack[Ts]]): ...
770770

771771
A = List[Tuple[T, Unpack[Ts], S]]
772-
x: A[int] # E: Bad number of arguments for type alias, expected: at least 2, given: 1
772+
x: A[int] # E: Bad number of arguments for type alias, expected at least 2, given 1
773773
reveal_type(x) # N: Revealed type is "builtins.list[Tuple[Any, Unpack[builtins.tuple[Any, ...]], Any]]"
774774

775775
B = Callable[[T, S, Unpack[Ts]], int]
776-
y: B[int] # E: Bad number of arguments for type alias, expected: at least 2, given: 1
776+
y: B[int] # E: Bad number of arguments for type alias, expected at least 2, given 1
777777
reveal_type(y) # N: Revealed type is "def (Any, Any, *Any) -> builtins.int"
778778

779779
C = G[T, Unpack[Ts], S]
780-
z: C[int] # E: Bad number of arguments for type alias, expected: at least 2, given: 1
780+
z: C[int] # E: Bad number of arguments for type alias, expected at least 2, given 1
781781
reveal_type(z) # N: Revealed type is "__main__.G[Any, Unpack[builtins.tuple[Any, ...]], Any]"
782782
[builtins fixtures/tuple.pyi]
783783

test-data/unit/fine-grained.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4032,7 +4032,7 @@ def f(x: a.A[str]):
40324032
[builtins fixtures/dict.pyi]
40334033
[out]
40344034
==
4035-
b.py:2: error: Bad number of arguments for type alias, expected: 2, given: 1
4035+
b.py:2: error: Bad number of arguments for type alias, expected 2, given 1
40364036

40374037
[case testAliasFineAdded]
40384038
import b
@@ -5542,7 +5542,7 @@ main:9: error: Function "a.T" is not valid as a type
55425542
main:9: note: Perhaps you need "Callable[...]" or a callback protocol?
55435543
main:12: error: Function "a.T" is not valid as a type
55445544
main:12: note: Perhaps you need "Callable[...]" or a callback protocol?
5545-
main:12: error: Bad number of arguments for type alias, expected: 0, given: 1
5545+
main:12: error: Bad number of arguments for type alias, expected 0, given 1
55465546

55475547
[case testChangeTypeVarToModule]
55485548

@@ -5576,7 +5576,7 @@ main:9: error: Module "T" is not valid as a type
55765576
main:9: note: Perhaps you meant to use a protocol matching the module structure?
55775577
main:12: error: Module "T" is not valid as a type
55785578
main:12: note: Perhaps you meant to use a protocol matching the module structure?
5579-
main:12: error: Bad number of arguments for type alias, expected: 0, given: 1
5579+
main:12: error: Bad number of arguments for type alias, expected 0, given 1
55805580

55815581
[case testChangeClassToModule]
55825582

@@ -5628,7 +5628,7 @@ T = int
56285628
==
56295629
main:5: error: Free type variable expected in Generic[...]
56305630
main:9: error: "C" expects no type arguments, but 1 given
5631-
main:12: error: Bad number of arguments for type alias, expected: 0, given: 1
5631+
main:12: error: Bad number of arguments for type alias, expected 0, given 1
56325632

56335633
[case testChangeTypeAliasToModule]
56345634

0 commit comments

Comments
 (0)