Skip to content

Fix error message for type application on non-generic expressions#21295

Open
achbj wants to merge 1 commit intopython:masterfrom
achbj:fix-20927-error-message-type-application
Open

Fix error message for type application on non-generic expressions#21295
achbj wants to merge 1 commit intopython:masterfrom
achbj:fix-20927-error-message-type-application

Conversation

@achbj
Copy link
Copy Markdown

@achbj achbj commented Apr 23, 2026

Summary

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.

The original error message was misleading because it stated that type application is only supported for generic classes, but type aliases also support type application (e.g., type TA[T] = list[T]; v: TA[int] works correctly).

Changes

  • Updated ONLY_CLASS_APPLICATION error message in mypy/message_registry.py from "Type application is only supported for generic classes" to "Type application is only supported for generic classes and type aliases"
  • Updated corresponding test expectations in:
    • test-data/unit/check-generics.test
    • test-data/unit/check-parameter-specification.test
    • test-data/unit/check-typevar-tuple.test

Test plan

  • Ran pytest mypy/test/testcheck.py::TypeCheckSuite::check-generics.test - all 194 tests passed
  • Ran pytest mypy/test/testcheck.py::TypeCheckSuite::check-parameter-specification.test - tests passed
  • Ran pytest mypy/test/testcheck.py::TypeCheckSuite::check-typevar-tuple.test - tests passed
  • Manually verified the fix with a test file

🤖 Generated with Claude Code

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 python#20927.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@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]

@achbj achbj marked this pull request as ready for review April 23, 2026 09:41
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.

1 participant