Skip to content

Commit

Permalink
Merge pull request #294 from havelock/master
Browse files Browse the repository at this point in the history
Added Choice.__hash__()
  • Loading branch information
kvesteri committed Nov 5, 2017
2 parents a9389f4 + 8a68c4b commit 96057c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sqlalchemy_utils/types/choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def __eq__(self, other):
return self.code == other.code
return other == self.code

def __hash__(self):
return hash(self.code)

def __ne__(self, other):
return not (self == other)

Expand Down
3 changes: 3 additions & 0 deletions tests/types/test_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def test_non_equality_operator(self):
assert Choice(1, 1) != 2
assert not (Choice(1, 1) != 1)

def test_hash(self):
assert hash(Choice(1, 1)) == hash(1)


class TestChoiceType(object):

Expand Down

0 comments on commit 96057c0

Please sign in to comment.