I would like to create a new Enum (IntEnum) class based on two existing ones. There is a working solution for this, like so:
from enum import unique, IntEnum
from itertools import chain
from collections import OrderedDict
@unique
class FirstEnumClass(IntEnum):
a = 1
b = 2
@unique
class SecondEnumClass(IntEnum):
c = 3
d = 4
# here a combined class is created:
CombinedEnumClass = unique(IntEnum('CombinedEnumClass', OrderedDict([(i.name, i.value) for i in chain(FirstEnumClass, SecondEnumClass)])))
My question: is there a fancy way to achieve this, so that there is a proper class definition? Like overriding some of the metaclass methods, or so? I would like something like this, so that docstring can also be given:
@unique
class CombinedEnumClass(IntEnum):
""" docstring """
# magic needed here
Any idea? Thanks!