Wrong Signature for Enum with Specific Dataclass Mixin Scenario
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 5.1k
- Forks
- 2.1k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 82
Beschreibung
Note: I was thinking about putting this on pyright but it said standard library problems are more suited here, so I'll give it a shot.
I was trying to code an enum with a dataclass mixin where each value is overridden through the first string variable for easier referencing (rather than a dict from str to enum).
from dataclasses import dataclass
from enum import Enum, auto
@dataclass(frozen=True)
class SampleMixin:
a_string: str
a_number: int
class SampleEnum(SampleMixin, Enum):
def __new__(cls, value: str, *_):
obj = object.__new__(cls)
obj._value_ = value
return obj
foo = "foo", 1
bar = "bar", 2
class SampleEnum2(Enum):
foo = auto()
bar = auto()
baz = SampleEnum("foo")
qux = SampleEnum2("foo")
baz still gets SampleEnum.foo right, but the function signature is incorrectly identified. Ideally, it should be closer to SampleEnum2's function signature.
I'm open to workarounds at the meantime. The code runs correctly, it's just that the inferred signature I got was wrong.
Code sample in pyright playground.
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 Python-Reproduktion und dem verknüpften pyright playground und vergleiche die abgeleiteten Signaturen für SampleEnum und SampleEnum2. Verfolge die relevanten Typing-Definitionen für enum und dataclass aus der Standardbibliothek in typeshed und bestätige den Abschluss, sobald der dataclass-mixin-Fall die beabsichtigte enum-Konstruktor-Signatur erzeugt, ohne das Laufzeitverhalten zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- developer-experience
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 55/100