mypy should error about missing type vars in explicit type aliases
Open
Nobody has claimed this yet.
feature
topic-type-alias
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Explicit type aliases don't allow no-args for generics, but don't error about it either.
To Reproduce
from typing import Generic, TypeVar
from typing_extensions import TypeAlias
T = TypeVar("T")
class Y(Generic[T]): ...
Alias2a = Y
reveal_type(Alias2a) # N: Revealed type is "def [T] () -> __main__.Y[T`1]"
Alias2b: TypeAlias = Y
reveal_type(Alias2b) # N: Revealed type is "def () -> __main__.Y[Any]"
Expected Behavior
An error when defining Alias2b.
Actual Behavior
No error when defining Alias2b.
Your Environment
Checked on mypy playground.
- Mypy version used: v1.14
- Mypy command-line flags:
--disallow-any-generics - Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.12
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
Run the supplied Python 3.12 reproduction with --disallow-any-generics and compare the Alias2a and Alias2b reveal_type results. Done means defining Alias2b as an explicit generic type alias reports an error for missing type variables, while the reported Alias2a behavior remains understood.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100