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

Guido van Rossum guido at python.org
Sat Apr 13 04:14:56 CEST 2013


On Fri, Apr 12, 2013 at 7:07 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On 13/04/13 05:33, Barry Warsaw wrote:
>>
>> 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
>>> there.
>>
>>
>> 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 would expect the same behaviour from enums that I get in Python 3 from
> non-enums. That is, if enums X.a and X.b happen to both be ints, or both
> strings, then comparisons should succeed, but if they are different types, I
> should get a TypeError.
>
> The above applies to related enums. If they are unrelated (e.g. Colours.red
> < Insects.ant) then I think TypeError is appropriate.

That's exactly what I'm trying to propose too, but Steven has the
better words. :-)

--
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list