Skip to content

Commit 0cc21d9

Browse files
Use "type arguments" instead of "type parameters" for bare generics (#20494)
gh-20493 --------- Co-authored-by: Shantanu Jain <[email protected]>
1 parent e7f4619 commit 0cc21d9

File tree

11 files changed

+75
-78
lines changed

11 files changed

+75
-78
lines changed

docs/source/error_code_list2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Example:
3232
3333
# mypy: disallow-any-generics
3434
35-
# Error: Missing type parameters for generic type "list" [type-arg]
35+
# Error: Missing type arguments for generic type "list" [type-arg]
3636
def remove_dups(items: list) -> list:
3737
...
3838

mypy/message_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def with_additional_msg(self, info: str) -> ErrorMessage:
176176
"Access to generic instance variables via class is ambiguous"
177177
)
178178
GENERIC_CLASS_VAR_ACCESS: Final = "Access to generic class variables is ambiguous"
179-
BARE_GENERIC: Final = "Missing type parameters for generic type {}"
179+
BARE_GENERIC: Final = "Missing type arguments for generic type {}"
180180
IMPLICIT_GENERIC_ANY_BUILTIN: Final = (
181181
'Implicit generic "Any". Use "{}" and specify generic parameters'
182182
)

test-data/unit/check-columns.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,10 @@ class D(A):
263263
[case testColumnMissingTypeParameters]
264264
# flags: --disallow-any-generics
265265
from typing import List, Callable
266-
def f(x: List) -> None: pass # E:10: Missing type parameters for generic type "List"
267-
def g(x: list) -> None: pass # E:10: Missing type parameters for generic type "list"
266+
def f(x: List) -> None: pass # E:10: Missing type arguments for generic type "List"
267+
def g(x: list) -> None: pass # E:10: Missing type arguments for generic type "list"
268268
if int():
269-
c: Callable # E:8: Missing type parameters for generic type "Callable"
269+
c: Callable # E:8: Missing type arguments for generic type "Callable"
270270
[builtins fixtures/list.pyi]
271271

272272
[case testColumnIncompatibleDefault]

test-data/unit/check-errorcodes.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,11 @@ a.x = '' # E: Incompatible types in assignment (expression has type "str", vari
357357
[case testErrorCodeMissingTypeArg]
358358
# flags: --disallow-any-generics
359359
from typing import List, TypeVar
360-
x: List # E: Missing type parameters for generic type "List" [type-arg]
361-
y: list # E: Missing type parameters for generic type "list" [type-arg]
360+
x: List # E: Missing type arguments for generic type "List" [type-arg]
361+
y: list # E: Missing type arguments for generic type "list" [type-arg]
362362
T = TypeVar('T')
363363
L = List[List[T]]
364-
z: L # E: Missing type parameters for generic type "L" [type-arg]
364+
z: L # E: Missing type arguments for generic type "L" [type-arg]
365365
[builtins fixtures/list.pyi]
366366

367367
[case testErrorCodeUnionAttribute]

test-data/unit/check-flags.test

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,8 +1540,8 @@ from queue import Queue
15401540
x: Future[str]
15411541
y: Queue[int]
15421542

1543-
p: Future # E: Missing type parameters for generic type "Future"
1544-
q: Queue # E: Missing type parameters for generic type "Queue"
1543+
p: Future # E: Missing type arguments for generic type "Future"
1544+
q: Queue # E: Missing type arguments for generic type "Queue"
15451545
[file asyncio/__init__.pyi]
15461546
from asyncio.futures import Future as Future
15471547
[file asyncio/futures.pyi]
@@ -1558,25 +1558,25 @@ class Queue(Generic[_T]): ...
15581558
[case testDisallowAnyGenericsBuiltinTuple]
15591559
# flags: --disallow-any-generics
15601560
s = tuple([1, 2, 3])
1561-
def f(t: tuple) -> None: pass # E: Missing type parameters for generic type "tuple"
1561+
def f(t: tuple) -> None: pass # E: Missing type arguments for generic type "tuple"
15621562
[builtins fixtures/tuple.pyi]
15631563

15641564
[case testDisallowAnyGenericsBuiltinList]
15651565
# flags: --disallow-any-generics
15661566
l = list([1, 2, 3])
1567-
def f(t: list) -> None: pass # E: Missing type parameters for generic type "list"
1567+
def f(t: list) -> None: pass # E: Missing type arguments for generic type "list"
15681568
[builtins fixtures/list.pyi]
15691569

15701570
[case testDisallowAnyGenericsBuiltinSet]
15711571
# flags: --disallow-any-generics
15721572
l = set({1, 2, 3})
1573-
def f(s: set) -> None: pass # E: Missing type parameters for generic type "set"
1573+
def f(s: set) -> None: pass # E: Missing type arguments for generic type "set"
15741574
[builtins fixtures/set.pyi]
15751575

15761576
[case testDisallowAnyGenericsBuiltinDict]
15771577
# flags: --disallow-any-generics
15781578
l = dict([('a', 1)])
1579-
def f(d: dict) -> None: pass # E: Missing type parameters for generic type "dict"
1579+
def f(d: dict) -> None: pass # E: Missing type arguments for generic type "dict"
15801580
[builtins fixtures/dict.pyi]
15811581

15821582
[case testCheckDefaultAllowAnyGeneric]
@@ -1607,9 +1607,8 @@ from typing import TypeVar, Callable
16071607
T = TypeVar('T')
16081608
C = Callable[[], T]
16091609

1610-
def f(c: C): # E: Missing type parameters for generic type "C"
1610+
def f(c: C): # E: Missing type arguments for generic type "C"
16111611
pass
1612-
[out]
16131612

16141613
[case testStrictAnyGeneric]
16151614
# flags: --strict
@@ -1620,9 +1619,8 @@ T = TypeVar('T')
16201619
class A(Generic[T]):
16211620
pass
16221621

1623-
def f(c: A) -> None: # E: Missing type parameters for generic type "A"
1622+
def f(c: A) -> None: # E: Missing type arguments for generic type "A"
16241623
pass
1625-
[out]
16261624

16271625
[case testStrictInConfigAnyGeneric]
16281626
# flags: --config-file tmp/mypy.ini
@@ -1633,12 +1631,11 @@ T = TypeVar('T')
16331631
class A(Generic[T]):
16341632
pass
16351633

1636-
def f(c: A) -> None: # E: Missing type parameters for generic type "A"
1634+
def f(c: A) -> None: # E: Missing type arguments for generic type "A"
16371635
pass
16381636
[file mypy.ini]
16391637
\[mypy]
16401638
strict = True
1641-
[out]
16421639

16431640

16441641
[case testStrictInConfigAnyGenericPyProjectTOML]
@@ -1650,15 +1647,13 @@ T = TypeVar('T')
16501647
class A(Generic[T]):
16511648
pass
16521649

1653-
def f(c: A) -> None: # E: Missing type parameters for generic type "A"
1650+
def f(c: A) -> None: # E: Missing type arguments for generic type "A"
16541651
pass
16551652

16561653
[file pyproject.toml]
16571654
\[tool.mypy]
16581655
strict = true
16591656

1660-
[out]
1661-
16621657

16631658
[case testStrictFalseInConfigAnyGeneric]
16641659
# flags: --config-file tmp/mypy.ini
@@ -1856,8 +1851,8 @@ main:2: error: Module "other_module_2" does not explicitly export attribute "a"
18561851
from typing import List
18571852

18581853
A = List # OK
1859-
B = List[A] # E:10: Missing type parameters for generic type "A"
1860-
x: A # E:4: Missing type parameters for generic type "A"
1854+
B = List[A] # E:10: Missing type arguments for generic type "A"
1855+
x: A # E:4: Missing type arguments for generic type "A"
18611856
[builtins fixtures/list.pyi]
18621857

18631858
[case testDisallowAnyExplicitDefSignature]
@@ -1982,20 +1977,20 @@ N = TypedDict('N', {'x': str, 'y': List}) # no error
19821977
# flags: --disallow-any-generics
19831978
from typing import Tuple
19841979

1985-
def f(s: Tuple) -> None: pass # E: Missing type parameters for generic type "Tuple"
1986-
def g(s) -> Tuple: # E: Missing type parameters for generic type "Tuple"
1980+
def f(s: Tuple) -> None: pass # E: Missing type arguments for generic type "Tuple"
1981+
def g(s) -> Tuple: # E: Missing type arguments for generic type "Tuple"
19871982
return 'a', 'b'
19881983
def h(s) -> Tuple[str, str]: # no error
19891984
return 'a', 'b'
1990-
x: Tuple = () # E: Missing type parameters for generic type "Tuple"
1985+
x: Tuple = () # E: Missing type arguments for generic type "Tuple"
19911986
[builtins fixtures/tuple.pyi]
19921987

19931988
[case testDisallowAnyGenericsTupleWithNoTypeParamsGeneric]
19941989
# flags: --disallow-any-generics
19951990
from typing import Tuple, List
19961991

1997-
def f(s: Tuple) -> None: pass # E: Missing type parameters for generic type "Tuple"
1998-
def g(s: List[Tuple]) -> None: pass # E: Missing type parameters for generic type "Tuple"
1992+
def f(s: Tuple) -> None: pass # E: Missing type arguments for generic type "Tuple"
1993+
def g(s: List[Tuple]) -> None: pass # E: Missing type arguments for generic type "Tuple"
19991994
def h(s: List[Tuple[str, str]]) -> None: pass # no error
20001995
[builtins fixtures/list.pyi]
20011996

@@ -2004,19 +1999,19 @@ def h(s: List[Tuple[str, str]]) -> None: pass # no error
20041999
from typing import Type, Any
20052000

20062001
def f(s: Type[Any]) -> None: pass # no error
2007-
def g(s) -> Type: # E: Missing type parameters for generic type "Type"
2002+
def g(s) -> Type: # E: Missing type arguments for generic type "Type"
20082003
return s
20092004
def h(s) -> Type[str]: # no error
20102005
return s
2011-
x: Type = g(0) # E: Missing type parameters for generic type "Type"
2006+
x: Type = g(0) # E: Missing type arguments for generic type "Type"
20122007

20132008
[case testDisallowAnyGenericsAliasGenericType]
20142009
# flags: --disallow-any-generics
20152010
from typing import List
20162011

20172012
L = List # no error
20182013

2019-
def f(l: L) -> None: pass # E: Missing type parameters for generic type "L"
2014+
def f(l: L) -> None: pass # E: Missing type arguments for generic type "L"
20202015
def g(l: L[str]) -> None: pass # no error
20212016
[builtins fixtures/list.pyi]
20222017

@@ -2027,47 +2022,47 @@ from typing import TypeVar, Tuple
20272022
T = TypeVar('T')
20282023
A = Tuple[T, str, T]
20292024

2030-
def f(s: A) -> None: pass # E: Missing type parameters for generic type "A"
2031-
def g(s) -> A: # E: Missing type parameters for generic type "A"
2025+
def f(s: A) -> None: pass # E: Missing type arguments for generic type "A"
2026+
def g(s) -> A: # E: Missing type arguments for generic type "A"
20322027
return 'a', 'b', 1
20332028
def h(s) -> A[str]: # no error
20342029
return 'a', 'b', 'c'
2035-
x: A = ('a', 'b', 1) # E: Missing type parameters for generic type "A"
2030+
x: A = ('a', 'b', 1) # E: Missing type arguments for generic type "A"
20362031
[builtins fixtures/tuple.pyi]
20372032

20382033
[case testDisallowAnyGenericsPlainList]
20392034
# flags: --disallow-any-generics
20402035
from typing import List
20412036

2042-
def f(l: List) -> None: pass # E: Missing type parameters for generic type "List"
2037+
def f(l: List) -> None: pass # E: Missing type arguments for generic type "List"
20432038
def g(l: List[str]) -> None: pass
2044-
def h(l: List[List]) -> None: pass # E: Missing type parameters for generic type "List"
2045-
def i(l: List[List[List[List]]]) -> None: pass # E: Missing type parameters for generic type "List"
2046-
def j() -> List: pass # E: Missing type parameters for generic type "List"
2039+
def h(l: List[List]) -> None: pass # E: Missing type arguments for generic type "List"
2040+
def i(l: List[List[List[List]]]) -> None: pass # E: Missing type arguments for generic type "List"
2041+
def j() -> List: pass # E: Missing type arguments for generic type "List"
20472042

20482043
x = [] # E: Need type annotation for "x" (hint: "x: list[<type>] = ...")
2049-
y: List = [] # E: Missing type parameters for generic type "List"
2044+
y: List = [] # E: Missing type arguments for generic type "List"
20502045
[builtins fixtures/list.pyi]
20512046

20522047
[case testDisallowAnyGenericsPlainDict]
20532048
# flags: --disallow-any-generics
20542049
from typing import List, Dict
20552050

2056-
def f(d: Dict) -> None: pass # E: Missing type parameters for generic type "Dict"
2057-
def g(d: Dict[str, Dict]) -> None: pass # E: Missing type parameters for generic type "Dict"
2058-
def h(d: List[Dict]) -> None: pass # E: Missing type parameters for generic type "Dict"
2051+
def f(d: Dict) -> None: pass # E: Missing type arguments for generic type "Dict"
2052+
def g(d: Dict[str, Dict]) -> None: pass # E: Missing type arguments for generic type "Dict"
2053+
def h(d: List[Dict]) -> None: pass # E: Missing type arguments for generic type "Dict"
20592054

2060-
d: Dict = {} # E: Missing type parameters for generic type "Dict"
2055+
d: Dict = {} # E: Missing type arguments for generic type "Dict"
20612056
[builtins fixtures/dict.pyi]
20622057

20632058
[case testDisallowAnyGenericsPlainSet]
20642059
# flags: --disallow-any-generics
20652060
from typing import Set
20662061

2067-
def f(s: Set) -> None: pass # E: Missing type parameters for generic type "Set"
2068-
def g(s: Set[Set]) -> None: pass # E: Missing type parameters for generic type "Set"
2062+
def f(s: Set) -> None: pass # E: Missing type arguments for generic type "Set"
2063+
def g(s: Set[Set]) -> None: pass # E: Missing type arguments for generic type "Set"
20692064

2070-
s: Set = set() # E: Missing type parameters for generic type "Set"
2065+
s: Set = set() # E: Missing type arguments for generic type "Set"
20712066
[builtins fixtures/set.pyi]
20722067

20732068
[case testDisallowAnyGenericsCustomGenericClass]
@@ -2077,11 +2072,11 @@ from typing import Generic, TypeVar, Any
20772072
T = TypeVar('T')
20782073
class G(Generic[T]): pass
20792074

2080-
def f() -> G: # E: Missing type parameters for generic type "G"
2075+
def f() -> G: # E: Missing type arguments for generic type "G"
20812076
return G()
20822077

20832078
x: G[Any] = G() # no error
2084-
y: G = x # E: Missing type parameters for generic type "G"
2079+
y: G = x # E: Missing type arguments for generic type "G"
20852080

20862081
[case testDisallowAnyGenericsForAliasesInRuntimeContext]
20872082
# flags: --disallow-any-generics
@@ -2093,8 +2088,8 @@ class G(Generic[T]):
20932088
def foo(cls) -> T: ...
20942089

20952090
A = G[Tuple[T, T]]
2096-
A() # E: Missing type parameters for generic type "A"
2097-
A.foo() # E: Missing type parameters for generic type "A"
2091+
A() # E: Missing type arguments for generic type "A"
2092+
A.foo() # E: Missing type arguments for generic type "A"
20982093

20992094
B = G
21002095
B()
@@ -2498,8 +2493,9 @@ from typing import TypeVar, Generic, List, Union
24982493

24992494
class C(Generic[T]): ...
25002495

2501-
A = Union[C, List] # E: Missing type parameters for generic type "C" \
2502-
# E: Missing type parameters for generic type "List"
2496+
A = Union[C, List] # E: Missing type arguments for generic type "C" \
2497+
# E: Missing type arguments for generic type "List"
2498+
25032499
[builtins fixtures/list.pyi]
25042500

25052501
[case testNestedGenericInAliasAllow]

test-data/unit/check-inline-config.test

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# mypy: disallow-any-generics, no-warn-no-return
66

77
from typing import List, Optional
8-
def foo() -> Optional[List]: # E: Missing type parameters for generic type "List"
8+
def foo() -> Optional[List]: # E: Missing type arguments for generic type "List"
99
20
1010

1111
[builtins fixtures/list.pyi]
@@ -16,7 +16,7 @@ def foo() -> Optional[List]: # E: Missing type parameters for generic type "Lis
1616
# mypy: no-warn-no-return
1717

1818
from typing import List, Optional
19-
def foo() -> Optional[List]: # E: Missing type parameters for generic type "List"
19+
def foo() -> Optional[List]: # E: Missing type arguments for generic type "List"
2020
20
2121

2222
[builtins fixtures/list.pyi]
@@ -26,7 +26,7 @@ def foo() -> Optional[List]: # E: Missing type parameters for generic type "Lis
2626
# mypy: disallow-any-generics=true, warn-no-return=0
2727

2828
from typing import List, Optional
29-
def foo() -> Optional[List]: # E: Missing type parameters for generic type "List"
29+
def foo() -> Optional[List]: # E: Missing type arguments for generic type "List"
3030
20
3131

3232
[builtins fixtures/list.pyi]
@@ -37,7 +37,7 @@ def foo() -> Optional[List]: # E: Missing type parameters for generic type "Lis
3737
# mypy: disallow-any-generics = true, warn-no-return = 0
3838

3939
from typing import List, Optional
40-
def foo() -> Optional[List]: # E: Missing type parameters for generic type "List"
40+
def foo() -> Optional[List]: # E: Missing type arguments for generic type "List"
4141
20
4242

4343
[builtins fixtures/list.pyi]
@@ -48,7 +48,7 @@ def foo() -> Optional[List]: # E: Missing type parameters for generic type "Lis
4848

4949
from typing import List
5050

51-
def foo(FOO: bool, BAR: bool) -> List: # E: Missing type parameters for generic type "List"
51+
def foo(FOO: bool, BAR: bool) -> List: # E: Missing type arguments for generic type "List"
5252
if FOO or BAR:
5353
1+'lol'
5454
return []
@@ -100,7 +100,7 @@ from typing import List, Optional
100100
def foo() -> Optional[List]:
101101
20
102102
[out]
103-
tmp/a.py:4: error: Missing type parameters for generic type "List"
103+
tmp/a.py:4: error: Missing type arguments for generic type "List"
104104
[out2]
105105
[out3]
106106
tmp/a.py:2: error: Missing return statement
@@ -123,7 +123,7 @@ def foo() -> Optional[List]:
123123

124124
[out]
125125
[out2]
126-
tmp/a.py:4: error: Missing type parameters for generic type "List"
126+
tmp/a.py:4: error: Missing type arguments for generic type "List"
127127

128128
[builtins fixtures/list.pyi]
129129

test-data/unit/check-typeddict.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3040,8 +3040,9 @@ reveal_type(ad) # N: Revealed type is "TypedDict('__main__.TD', {'key': builtin
30403040
Alias[str](key=0, value=0) # E: Incompatible types (expression has type "int", TypedDict item "value" has type "list[str]")
30413041

30423042
# Generic aliases are *always* filled with Any, so this is different from TD(...) call.
3043-
Alias(key=0, value=0) # E: Missing type parameters for generic type "Alias" \
3043+
Alias(key=0, value=0) # E: Missing type arguments for generic type "Alias" \
30443044
# E: Incompatible types (expression has type "int", TypedDict item "value" has type "list[Any]")
3045+
30453046
[builtins fixtures/dict.pyi]
30463047
[typing fixtures/typing-typeddict.pyi]
30473048

0 commit comments

Comments
 (0)