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~
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/WOWC756XL7NB5GNR6SKOEPLR63CYMXJJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to