Skip to content

Commit

Permalink
Merge pull request #37 from tulioz/hash
Browse files Browse the repository at this point in the history
__hash__ is not inherited from parent class when __eq__ is overridden, define new __hash__ to account for this
  • Loading branch information
Adam DePue committed Feb 14, 2016
2 parents 8b52fd9 + cc67055 commit 4e1ae04
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name='richenum',
version='1.1.1',
version='1.1.2',
description='Enum library for python.',
long_description=(
open('README.rst').read() + '\n\n' +
Expand Down
7 changes: 7 additions & 0 deletions src/richenum/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ def __eq__(self, other):
else:
return False

def __hash__(self):
"""
__hash__ is not inherited from base class when __eq__
is overridden
"""
return hash(self.canonical_name + str(self.index))


def _setup_members(cls_attrs, cls_parents, member_cls):
members = []
Expand Down
3 changes: 3 additions & 0 deletions tests/richenum/test_ordered_rich_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,6 @@ def test_unicode_handling(self):
self.assertEqual(str(poop_oatmeal), "Oatmeal💩")
if not PY3:
self.assertEqual(unicode(poop_oatmeal), u"Oatmeal💩")

def test_enum_hashable(self):
self.assertTrue(hash(coffee))
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27,py33,py34,pypy
envlist = py27,py33,py34,py35,pypy
[testenv]
deps =
nose
Expand Down

0 comments on commit 4e1ae04

Please sign in to comment.