[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

Ethan Furman ethan at stoneleaf.us
Fri Apr 12 17:36:11 CEST 2013


On 04/12/2013 07:51 AM, Barry Warsaw wrote:
> On Apr 12, 2013, at 10:23 AM, R. David Murray wrote:
>
>> I think either the iteration order should be undefined (like a set
>> or dict), or the comparison operations should work.  I'd prefer
>> the latter, because of the use case I outlined.
>
> Order (both iteration and comparison) is officially undefined for Enums but
> defined for IntEnums.

Huh??

 From the PEP
============
The ``Enum`` class supports iteration.  Iteration is defined as the
sorted order of the item values::

     >>> class FiveColors(Enum):
     ...     pink = 4
     ...     cyan = 5
     ...     green = 2
     ...     blue = 3
     ...     red = 1
     >>> [v.name for v in FiveColors]
     ['red', 'green', 'blue', 'pink', 'cyan']

--
~Ethan~


More information about the Python-Dev mailing list