A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2013-May/125815.html below:

[Python-Dev] PEP-435 reference implementation

[Python-Dev] PEP-435 reference implementation [Python-Dev] PEP-435 reference implementationBarry 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
>False
>
>--> Color.red == MoreColor.red
>True
>
>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
it.

-Barry
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4