Literal infers tuple literal as Union of the items though this syntax is forbidden by PEP 586
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
The section Illegal parameters for Literal at type check time describes that tuple literals inside Literal are forbidden:
Tuples containing valid literal types like
Literal[(1, "foo", "bar")]. The user could always express this type asTuple[Literal[1], Literal["foo"], Literal["bar"]]instead. Also, tuples are likely to be confused with theLiteral[1, 2, 3]shortcut.
Nevertheless mypy seems to be taking this shortcut since it doesn't flag the following code:
from typing_extensions import Literal
a : Literal[(1, 2)] = 1
Python 3.7, mypy 0.740, typing-extensions 3.7.4.
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 damit, das gemeldete Python-Snippet mit Literal[(1, 2)] zu reproduzieren, und bestätige, ob mypy es akzeptiert. Finde den Pfad für die Literal-Typprüfung und die vorhandenen Tests dazu; als erledigt gilt die Aufgabe, wenn Tupel-Literale in Literal gemäß PEP 586 abgelehnt werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100