[Python-Dev] PEP 435: initial values must be specified? Yes (original) (raw)
Ethan Furman ethan at stoneleaf.us
Mon May 6 02:03:52 CEST 2013
- Previous message: [Python-Dev] PEP 435: initial values must be specified? Yes
- Next message: [Python-Dev] PEP 435: initial values must be specified? Yes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 05/05/2013 04:14 PM, Tim Delaney wrote:
1. That the dictionary returned from .prepare provide a way to obtain the enum instance names once it's been populated (e.g. once it's been passed as the classdict to new). The reference implementation provides a enumnames list attribute. The enum names need to be available to a metaclass subclass before calling the base metaclass new.
[...]
My preferred solution is 1 (for the reason mentioned above) but it does not require exposing the metaclass publically (that's obtainable via type(Enum)). It does require a way to get the enum names before calling the base metaclass new, but that does not necessarily imply that I'm advocating exposing enumnames (or at least, not directly).
My preferred way would probably be a note that the dictionary returned from the enum metaclass prepare implements an enumnames() or maybe enumnames() method which returns an iterator over the enum instance names in definition order. The way this is implemented by the dictionary would be an implementation detail.
I like having an enum_names() that returns a list or tuple of (name, value) pairs in definition order.
--
Ethan
- Previous message: [Python-Dev] PEP 435: initial values must be specified? Yes
- Next message: [Python-Dev] PEP 435: initial values must be specified? Yes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]