How can I define a Python enum class that somehow derives from int, has a custom starting value, and adds custom attributes? I know how to derive from int using enum.IntEnum and set the starting value,
Goo = enum.IntEnum("Goo", "MOO FOO LOO", start = 42)
and how to add custom attributes to the base enum type,
class Goo(enum.Enum):
MOO = (42, "forty-two")
FOO = (43, "forty-three")
LOO = (44, "forty-four")
def __init__(self, value, alias):
self._value = value #self.value gives AttributeError, as expected, grrr...
self.alias = alias
but how do I do all three? I've tried all manner of __new__() too,
class Goo(int, enum.Enum):
MOO = (42, "forty-two")
FOO = (43, "forty-three")
LOO = (44, "forty-four")
def __new__(cls, value, alias):
self = super().__new__(cls, value)
self.alias = alias
return self
mostly with odd errors,
TypeError: int() takes at most 2 arguments (3 given)
in this case. Thanks.
Jim