[Python-Dev] PEP-435 reference implementation

Barry Warsaw barry at python.org
Wed May 1 17:44:32 CEST 2013

On Apr 30, 2013, at 10:50 PM, Ethan Furman wrote:

>The way I had subclassing working originally was for the subclass to create
>it's own versions of the superclass' enum items -- they weren't the same
>object, but they were equal:
>--> class Color(Enum):
>...     red = 1
>...     green = 2
>...     blue = 3
>--> class MoreColor(Color):
>...     cyan = 4
>...     magenta = 5
>...     yellow = 6
>--> Color.red is MoreColor.red
>--> Color.red == MoreColor.red
>If you switched from `is` to `==` would this work for you?

Not really, because in practice you don't compare one enum against another
explicitly.  You have a value in a variable and you're comparing against a
literal enum.  So `is` is still the more natural spelling.

My point is, if you want enums to behave more class-like because you're using
the class syntax, then you shouldn't explicitly break this one class-like
behavior just to protect some users from themselves.  There doesn't even seem
to be an easy way to override the default behavior if you really wanted to do


More information about the Python-Dev mailing list