[Python-ideas] Yet another enum proposal :)
Bruce Leban
bruce at leapyear.org
Sat Feb 23 01:38:45 CET 2013
On Fri, Feb 22, 2013 at 3:57 PM, Bruce Leban <bruce at leapyear.org> wrote:
> To avoid this problem ensure that hash(enum) != hash(int(enum)) [or
> whatever the base type of the enum is].
>
Never mind. That's a bad idea. As others pointed out, if two objects
compare equal, they have to have the same hash value. This weird behavior
is a side effect of having non-transitive equality (a == b, b == c but a !=
c) and objects like dicts are not designed to work with objects with
non-transitive equality. Not having transitivity when it's expected leads
to weird behavior. For example, if you have non-transitive inequality (a <
b < c < a, as is the case in PHP, for example) then sorting may not work
and some sorting code can even get into infinite loops.
--- Bruce
Latest blot post: Alice's Puzzle Page http://www.vroospeak.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130222/f9efaa42/attachment.html>
More information about the Python-ideas
mailing list