Resolution of disallowed `Type[Type[T]]` and casting to a blank `Type`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
(A clear and concise description of what the bug is.)
Mypy is inferring types that are illegal to create or annotate, like Type[Type[T]], which causes errors during linting checks.
The only ways to resolve it are either # type: ignore, which seems counter-intuitive when writing type safe code, or doing a typing.cast(typing.Type) which defeats the purpose of the generic typehint
To Reproduce
Playground link
Expected Behavior
I'd expect Type[Type[T]] to coalesce into the legal generic Type[T]
Actual Behavior
Mypy sees the expected type as Type[Type[T]], causing an error when not casting or ignoring.
Your Environment
- Mypy version used: 0.991 (compiled: yes)
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): setup.cfg from project this was first noticed in - Python version used: 3.10
The template asks for a link to the affected repository, if it's open source. This can be found in the EnforceTypes repo
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 reproduction using Python 3.10 and mypy 0.991, then trace how nested Type expressions are analyzed. The issue names no mypy source file or test; done means the example accepts the intended Type[T] relationship without requiring type: ignore or a blank typing.cast.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100