Ethan Furman wrote:

> > 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

Thanks for that info.

Per the example in 
https://docs.python.org/3/library/enum.html#when-to-use-new-vs-init, it looks 
like I can properly set the `_value_` property in the `__new__` method of the 
`Enum` subclass without needing to subclass `EnumMeta`. Am I understanding that 
correctly?
_______________________________________________
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/CERSFF3I4IAFXFSWOEA45EGKMVXTKOU4/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to