[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library (original) (raw)

Barry Warsaw barry at python.org
Thu Apr 25 21:20:10 CEST 2013


On Apr 23, 2013, at 10:53 AM, R. David Murray wrote:

Ah. I'd be looking for a bug every time I saw isinstance(value, myEnumClass). A better class name for values and an API for getting that class from the EnumClass would be nice, though. (So that you could write "isinstance(value, MyEnumClass.ValueClass)", say.)

I think if we did this, the attribute should be the same name as the one used to customize the value factory. Okay, this is horrible, but you could use

isinstance(value, MyEnumClass.__value_factory__)

The only thing stopping you from doing this right now is that when value_factory is not given, a default is used which is not available on that attribute. That's easily corrected though.

  1. really, to be consistent with the documentation, this should be item_factory since the attributes of the enum class are called "items", while items have an underlying value (e.g. A.b.value).

  2. A better name than either item_factory or value_factory is welcome, though I guess that will spawn another bikeshedding, soul-destroying centi-thread. ;)

  3. I'd like to make the implementation names consistent with the documentation in the next version of flufl.enum.

-Barry



More information about the Python-Dev mailing list