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.
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
enumwith a dataclass mixin where each value is overridden through the first string variable for easier referencing (rather than a dict fromstrtoenum).bazstill getsSampleEnum.fooright, but the function signature is incorrectly identified. Ideally, it should be closer toSampleEnum2'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.