You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wrong Signature for Enum with Specific Dataclass Mixin Scenario #15908
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).
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.
I looked into this a bit.
The runtime behaviour is correct, and the mismatch seems to be in how the typechecker pick the call signature for this pattern.
the dataclass init is used tob uild members at class definition time.
EnumMeta.call is used to look up for existing members at call sites. Type checkers appear to conflate the two and show the dataclass construction signature where the enum lookup signature should be shown instead.
You can workaround it by manual mixin instead of '@DataClass'; 'SampleEnum["foo"]' for name lookup; or
"class SampleEnum(str, Enum)" if the lookup key is always a string.
Activity
lul-cas commentedon Jun 19, 2026
I looked into this a bit.
The runtime behaviour is correct, and the mismatch seems to be in how the typechecker pick the call signature for this pattern.
the dataclass init is used tob uild members at class definition time.
EnumMeta.call is used to look up for existing members at call sites. Type checkers appear to conflate the two and show the dataclass construction signature where the enum lookup signature should be shown instead.
You can workaround it by manual mixin instead of '@DataClass'; 'SampleEnum["foo"]' for name lookup; or
"class SampleEnum(str, Enum)" if the lookup key is always a string.