[Python-ideas] Yet another enum proposal :)
Ethan Furman
ethan at stoneleaf.us
Sat Feb 23 02:12:49 CET 2013
On 02/22/2013 04:38 PM, Bruce Leban wrote:
>
> On Fri, Feb 22, 2013 at 3:57 PM, Bruce Leban <bruce at leapyear.org <mailto: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.
Yeah, I can easily see this issue keeping an enum implementation out of the stdlib; perhaps an acceptable breakage
would be to have enum instances not be hashable?
--
~Ethan~
More information about the Python-ideas
mailing list