MyIntEnum.ONE should be passable to functions expecting Literal[1] arguments
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
This is related but distinct from #19576, #16327, and #17162. It's also not specific to IntEnums, but I use them in the example for clarity. StrEnums as well as enums based on (int, Enum), or (str, Enum), etc.
To Reproduce
import enum
from typing import Literal
type One = Literal[1]
type Two = Literal[2]
type Three = Literal[3]
def option(arg: One | Two | Three) -> None:
...
class MyEnum(enum.IntEnum):
ONE = 1
TWO = 2
THREE = 3
option(MyEnum.TWO) # error: Argument 1 to "option" has incompatible type "Literal[MyEnum.TWO]"; expected "Literal[1, 2, 3]" [arg-type]
Expected Behavior
No error reported.
Actual Behavior
The error in the comment in the example is a false positive. This code works fine at runtime.
Your Environment
- Mypy version used: master as of 0d791b29b7ba4e5a9b04c0b6bdba11faf4a186a2
- Python version used: 3.13
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
Führe zunächst das bereitgestellte Python-3.13-Beispiel gegen mypy master aus und verfolge die Verarbeitung von Literal-Argumenten, die MyEnum.TWO betreffen. Die Korrektur ist abgeschlossen, wenn das Beispiel keinen Fehler wegen eines inkompatiblen Arguments mehr meldet und dabei das im Issue beschriebene verwandte enum- und Literal-Verhalten beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100