Skip to content

Commit 4e1ae04

Browse files
author
Adam DePue
committed
Merge pull request #37 from tulioz/hash
__hash__ is not inherited from parent class when __eq__ is overridden, define new __hash__ to account for this
2 parents 8b52fd9 + cc67055 commit 4e1ae04

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
setup(
1515
name='richenum',
16-
version='1.1.1',
16+
version='1.1.2',
1717
description='Enum library for python.',
1818
long_description=(
1919
open('README.rst').read() + '\n\n' +

src/richenum/enums.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ def __eq__(self, other):
164164
else:
165165
return False
166166

167+
def __hash__(self):
168+
"""
169+
__hash__ is not inherited from base class when __eq__
170+
is overridden
171+
"""
172+
return hash(self.canonical_name + str(self.index))
173+
167174

168175
def _setup_members(cls_attrs, cls_parents, member_cls):
169176
members = []

tests/richenum/test_ordered_rich_enums.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,6 @@ def test_unicode_handling(self):
122122
self.assertEqual(str(poop_oatmeal), "Oatmeal💩")
123123
if not PY3:
124124
self.assertEqual(unicode(poop_oatmeal), u"Oatmeal💩")
125+
126+
def test_enum_hashable(self):
127+
self.assertTrue(hash(coffee))

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py27,py33,py34,pypy
2+
envlist = py27,py33,py34,py35,pypy
33
[testenv]
44
deps =
55
nose

0 commit comments

Comments
 (0)