IntEnum objects are Unhashable in Python 3

Bug #1177857 reported by Matthew Lefavor
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
flufl.enum
Won't Fix
Undecided
Unassigned

Bug Description

I am running Python 3.3. When I create an IntEnum, the IntEnumValue members are not hashable. I do not have this problem with Python 2.7, or with regular enums.

Consider this example interactive session with Python3:

>>> import flufl.enum
>>> MyEnum = flufl.enum.Enum("MyEnum", "a b c d")
>>> hash(MyEnum.a)
268880433
>>> MyIntEnum = flufl.enum.IntEnum("MyIntEnum", "a b c d")
>>> hash(MyIntEnum.a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'IntEnumValue'

Running the same code in Python 2 will not cause an error.

This is an issue because it prevents IntEnum objects from being used as dictionary keys. In particular, the dictionary problem makes code like the following crash when it shouldn't (because it appears some internal code is trying to look up the value in a dictionary):

>>> MyIntEnum(MyIntEnum.a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/flufl/enum/_enum.py", line 120, in __call__
    return cls.__getitem__(args[0])
  File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/flufl/enum/_enum.py", line 102, in __getitem__
    attr = cls._enums.get(item)
TypeError: unhashable type: 'IntEnumValue'

description: updated
description: updated
Barry Warsaw (barry)
Changed in flufl.enum:
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.