Generic TypeAlias does not infer types
Open
Nobody has claimed this yet.
bug
topic-type-alias
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Inferred types for a generic TypedAlias do not work even if they work for the original Generic.
To Reproduce
from collections.abc import Set
from typing import Iterable, TypeAlias, TypeVar
_T_co = TypeVar("_T_co", covariant=True)
class orderedset(Set[_T_co]):
def __init__(self, __iterable: Iterable[_T_co] = ()) -> None:
...
oset: TypeAlias = orderedset[_T_co]
orderedset((1., 2., 3.)) # orderedset[float]
oset((1., 2., 3.)) # Missing type parameters for generic type "oset" [type-arg] mypy(error)
Expected Behavior
I expect that both lines above infer the same type.
Your Environment
- Mypy version used: 0.982
- Python version used: 3.10.6
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 supplied Python reproduction and compare inference for orderedset((1., 2., 3.)) with the TypeAlias form oset((1., 2., 3.)). Trace the type-checking path for generic TypeAlias calls; done means both expressions infer the same type without the missing-type-parameters error, with a regression test covering the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100