Resolution of disallowed `Type[Type[T]]` and casting to a blank `Type`
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
(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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der verknüpften mypy-play-Reproduktion unter Verwendung von Python 3.10 und mypy 0.991 und verfolge dann, wie verschachtelte Type-Ausdrücke analysiert werden. Das Issue nennt keine mypy-Quelldatei und keinen Test; abgeschlossen ist die Arbeit, wenn das Beispiel die beabsichtigte Type[T]-Beziehung akzeptiert, ohne type: ignore oder einen leeren typing.cast zu erfordern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100