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

Barry Warsaw barry at python.org
Fri Apr 12 21:33:02 CEST 2013

On Apr 12, 2013, at 11:21 AM, Russell E. Owen wrote:

>I, too, would strongly prefer to see ordering within an enum. I use 
>home-made enums heavily in my code and find ordering comparisons useful 

This was all hashed out in gory detail on python-ideas.  I feel strongly that
base EnumValues should be unordered, especially because the underlying values
can be of any type.  What would you expect to happen in this case:

    class X(Enum):
        a = 1
        b = 'hi'

    if X.a < myvalue < X.b:
        # whaa?

I think for most use cases, IntEnums will fit the bill for those who want
ordered comparisons, and it's also easy to subclass EnumValues to specialize
the behavior (in fact, this is how IntEnums are implemented).

So if you really want ordered-comparisons-with-untyped-enum-values, you can
have them. :)


More information about the Python-Dev mailing list