This is a combination of @dataclass
and enum.Enum
, inspired by https://blog.glyph.im/2025/01/active-enum.html . I didn't like that the syntax required making two classes, and naively combining @dataclass
on an enum.Enum
doesn't work (and is documented as such in the standard library docs).
The key insight is that all dataclass fields must be typed, and all enum members should not be typed, so we can unambiguously write something like this:
@dataenum
class SomeNumber:
result: int