On 10/21/2019 10:33 PM, Steve Jorgensen wrote:
class ChoiceEnum(Enum): def __init__(self, src=None, label=None): super().__init__()
if isinstance(src, Label): value = None label = str(src) else: value = src
self._value_ = self.name if value is None else value self.label = label or _label_from_name(self.name)
Experimenting is good! However, you'll want to either build your own metaclass and/or prepared dict, or do some work on your `__new__`/`__init__` methods for building enum members. Currently, you are reassigning `_value_` in `__init__`, which leaves some internal structures not matching the Enum. --> class Food(ChoiceEnum): ... APPLE = () ... ICED_TEA = () ... --> Food['APPLE'] <Food.APPLE: 'APPLE'> --> Food.APPLE <Food.APPLE: 'APPLE'> --> Food('APPLE') Traceback (most recent call last): ... ValueError: 'APPLE' is not a valid Food -- ~Ethan~