Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a11fee

Browse files
achbjclaude
andcommitted
Fix error message for type application on non-generic expressions
Update the error message "Type application is only supported for generic classes" to also mention type aliases, since type application is also valid for generic type aliases. Fixes #20927. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 2b136f0 commit 5a11fee

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

mypy/message_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def with_additional_msg(self, info: str) -> ErrorMessage:
121121
"Function is missing a type annotation", codes.NO_UNTYPED_DEF
122122
)
123123
ONLY_CLASS_APPLICATION: Final = ErrorMessage(
124-
"Type application is only supported for generic classes"
124+
"Type application is only supported for generic classes and type aliases"
125125
)
126126
RETURN_TYPE_EXPECTED: Final = ErrorMessage(
127127
"Function is missing a return type annotation", codes.NO_UNTYPED_DEF

test-data/unit/check-generics.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ from typing import TypeVar
426426
T = TypeVar('T')
427427
def f(x: T) -> T: pass
428428

429-
y = f[int] # E: Type application is only supported for generic classes
429+
y = f[int] # E: Type application is only supported for generic classes and type aliases
430430
[out]
431431

432432

@@ -1004,7 +1004,7 @@ reveal_type(y) # N: Revealed type is "builtins.int"
10041004

10051005
U[int] # E: Bad number of arguments for type alias, expected 0, given 1
10061006
O[int] # E: Bad number of arguments for type alias, expected 0, given 1 \
1007-
# E: Type application is only supported for generic classes
1007+
# E: Type application is only supported for generic classes and type aliases
10081008

10091009
[case testAliasesInClassBodyNormalVsSubscripted]
10101010

@@ -1072,9 +1072,9 @@ reveal_type(ts) # N: Revealed type is "Any"
10721072
us = UA.x # E: "<typing special form>" has no attribute "x"
10731073
reveal_type(us) # N: Revealed type is "Any"
10741074

1075-
xx = CA[str] + 1 # E: Type application is only supported for generic classes
1076-
yy = TA[str]() # E: Type application is only supported for generic classes
1077-
zz = UA[str].x # E: Type application is only supported for generic classes
1075+
xx = CA[str] + 1 # E: Type application is only supported for generic classes and type aliases
1076+
yy = TA[str]() # E: Type application is only supported for generic classes and type aliases
1077+
zz = UA[str].x # E: Type application is only supported for generic classes and type aliases
10781078
[builtins fixtures/tuple.pyi]
10791079
[typing fixtures/typing-medium.pyi]
10801080
[out]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class B(Generic[P]): ...
9292
Other = B[P]
9393

9494
T = TypeVar('T', bound=Alias[..., Any])
95-
Alias[..., Any] # E: Type application is only supported for generic classes
95+
Alias[..., Any] # E: Type application is only supported for generic classes and type aliases
9696
B[...]
9797
Other[...]
9898
[builtins fixtures/paramspec.pyi]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2763,6 +2763,6 @@ T = TypeVar('T')
27632763

27642764
def func(d: Callable[[Unpack[Ts]], T]) -> T: ...
27652765

2766-
y = func[1, int] # E: Type application is only supported for generic classes \
2766+
y = func[1, int] # E: Type application is only supported for generic classes and type aliases \
27672767
# E: Invalid type: try using Literal[1] instead?
27682768
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)