Skip to content

fix: mention type aliases in "Type application" error message#21122

Open
nuglifeleoji wants to merge 1 commit intopython:masterfrom
nuglifeleoji:fix/type-application-message
Open

fix: mention type aliases in "Type application" error message#21122
nuglifeleoji wants to merge 1 commit intopython:masterfrom
nuglifeleoji:fix/type-application-message

Conversation

@nuglifeleoji
Copy link
Copy Markdown
Contributor

Fixes #20927.

The error message raised when type arguments are applied to a non-class expression (e.g. a generic function):

error: Type application is only supported for generic classes

is inaccurate because PEP 695 type aliases (type TA[T] = list[T]) also support type application (TA[int]). Updated to:

error: Type application is only supported for generic classes and type aliases

Updated mypy/message_registry.py (ONLY_CLASS_APPLICATION) and all matching test fixtures.

Made with Cursor

The error fired when calling e.g. func[int]() on a generic function said:
  Type application is only supported for generic classes
but PEP 695 type aliases (type TA[T] = ...) also support type application,
making the message inaccurate.  Updated to:
  Type application is only supported for generic classes and type aliases

Updated the message in message_registry.py and all matching test fixtures.

Closes python#20927

Made-with: Cursor
@github-actions
Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/commands/menu.py:63: error: Type application is only supported for generic classes  [misc]
+ tanjun/commands/menu.py:63: error: Type application is only supported for generic classes and type aliases  [misc]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using type application with a function call gets a wrong error message

1 participant