from enum import Enum ALL = "all" class ExtEnum(Enum): @classmethod def by_name(cls, name): return next(i for i in cls if i.name == name) @classmethod def values(cls, with_all: bool = False): values = [i.value for i in cls] if with_all: values.append(ALL) return values def extend_enum(*inherit_enum): """Extend enum with exiting ones. Supports numerous inheritance Sensitive to inheritance order (for the similar names the value be the last one appeared). """ def wrapper(add_enum): _inherit = [] for i in inherit_enum: for v in list(i): _inherit.append(v) return ExtEnum(add_enum.__name__, {i.name: i.value for i in (_inherit + list(add_enum))}) return wrapper