[Python-ideas] PEP XXX - Competitor with PEP 435: Adding an enum type to the Python standard library

Paul Moore p.f.moore at gmail.com
Mon Mar 11 17:55:28 CET 2013


On 11 March 2013 16:18, Ethan Furman <ethan at stoneleaf.us> wrote:
> First, I offer my apologies to all who are still battle-weary from the last
> flurry of enum threads.
[...]
> This new PEP proposes an enum module that handles all those use cases, and
> makes it possible to handle others as well.

One thing that is not discussed in the PEP (at least from my quick
reading of it) is the issue of transitivity of equality (untested
code, sorry, but I believe this is the intention of the PEP):

>>> class E1(Enum):
...   example = 1

>>> class E2(Enum):
...   example = 1

>>> E1.example == 1
True
>>> E2.example == 1
True
>>> E1.example == E2.example
False
>>> E1.example == 1 == E2.example
True
>>> E1.example == E2.example == 1
False

Personally, I find this behaviour unacceptable. The lack of a good way
of dealing with this issue (I don't particularly like the "just use
int()" or special value property approaches either) seems to be key to
why people are failing to agree on an implementation...

At the very least, there should be a section in the PEP addressing the
discussion over this.

The motivation section isn't particularly strong, either. There's
nothing there that would persuade me to use enums. In general, the
proposal seems geared mainly at people who *already* want to use
enums, but for some reason aren't comfortable with using a 3rd party
package. But maybe that just implies that I'm not part of the target
audience for the feature, in which case fine (I don't have to use it,
obviously...)

Paul.



More information about the Python-ideas mailing list