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

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]>
  • Loading branch information
achbj and claude committed Apr 23, 2026
commit 5a11fee2aa9ac5c75b69046bba4768d2920249df
2 changes: 1 addition & 1 deletion mypy/message_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def with_additional_msg(self, info: str) -> ErrorMessage:
"Function is missing a type annotation", codes.NO_UNTYPED_DEF
)
ONLY_CLASS_APPLICATION: Final = ErrorMessage(
"Type application is only supported for generic classes"
"Type application is only supported for generic classes and type aliases"
)
RETURN_TYPE_EXPECTED: Final = ErrorMessage(
"Function is missing a return type annotation", codes.NO_UNTYPED_DEF
Expand Down
10 changes: 5 additions & 5 deletions test-data/unit/check-generics.test
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ from typing import TypeVar
T = TypeVar('T')
def f(x: T) -> T: pass

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


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

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

[case testAliasesInClassBodyNormalVsSubscripted]

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

xx = CA[str] + 1 # E: Type application is only supported for generic classes
yy = TA[str]() # E: Type application is only supported for generic classes
zz = UA[str].x # E: Type application is only supported for generic classes
xx = CA[str] + 1 # E: Type application is only supported for generic classes and type aliases
yy = TA[str]() # E: Type application is only supported for generic classes and type aliases
zz = UA[str].x # E: Type application is only supported for generic classes and type aliases
[builtins fixtures/tuple.pyi]
[typing fixtures/typing-medium.pyi]
[out]
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class B(Generic[P]): ...
Other = B[P]

T = TypeVar('T', bound=Alias[..., Any])
Alias[..., Any] # E: Type application is only supported for generic classes
Alias[..., Any] # E: Type application is only supported for generic classes and type aliases
B[...]
Other[...]
[builtins fixtures/paramspec.pyi]
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-typevar-tuple.test
Original file line number Diff line number Diff line change
Expand Up @@ -2763,6 +2763,6 @@ T = TypeVar('T')

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

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