Generic type alias with `Annotated` of a union: Type application is only supported for generic classes
Open
Nobody has claimed this yet.
topic-type-alias
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
from typing import Annotated, TypeVar
T = TypeVar('T')
A = Annotated[T | object, '']
A[int] # error: Type application is only supported for generic classes [misc]
https://mypy-play.net/?mypy=latest&python=3.12&gist=ed5366ef19a62c9620df139b05adcce9
I expect this to work the same as:
from typing import TypeVar
T = TypeVar('T')
A = list[T | object, '']
A[int] # ok
Looks like Annotated annotation makes mypy to mess with finding type var definition.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked mypy-play reproducer using Python 3.12 and the latest mypy. Compare the Annotated union alias with the stated working generic alias case, then confirm that applying A[int] no longer reports the type-application error while preserving the expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100