[Python-Dev] PEP 435: initial values must be specified? Yes

Ethan Furman ethan at stoneleaf.us
Mon May 6 02:03:52 CEST 2013

On 05/05/2013 04:14 PM, Tim Delaney wrote:
> 1. That the dictionary returned from <enum metaclass>.__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 _enum_names 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 _enum_names (or at least, not directly).
> My preferred way would probably be a note that the dictionary returned from the enum metaclass __prepare__ implements an
> enum_names() or maybe __enum_names__() 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.


More information about the Python-Dev mailing list