[Python-Dev] [Python-checkins] peps: Pre-alpha draft for PEP 435 (enum). The name is not important at the moment, as

Barry Warsaw barry at python.org
Mon Feb 25 21:32:47 CET 2013

On Feb 25, 2013, at 10:25 AM, Ethan Furman wrote:

>Hey, I think I just had a light-bulb moment: have the enum implement
>__index__ -- that will solve my use-case of using them for list indices.

They don't currently, but I think it's reasonable, given that they already
support __int__.


>Dumb question, but are flufl.enums ordered?  That's also an important use

Kind of.  Ordered comparisons are explicitly not supported, but iteration over
the Enum is guaranteed to be returned in int-value order.

One thing I've been thinking about is allowing you to override the EnumValue
class that the metaclass uses.  In that case, if you really wanted ordered
comparisons, you could override __lt__() and friends in a custom enum-value
class.  I haven't quite worked out in my mind how that would look, but I have
a bug to track the feature request:


Heck, that might even allow you to implement int-derived enum values if you
really wanted them <wink>.


More information about the Python-Dev mailing list