Skip to content

Commit

Permalink
Merge branch 'fix-comparison-to-None'
Browse files Browse the repository at this point in the history
  • Loading branch information
antocuni committed Feb 5, 2018
2 parents 7a084a3 + 7caaf1e commit 72a6d00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 2 additions & 6 deletions capnpy/struct_.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,8 @@ def __hash__(self):
return hash(self._key())

def _equals(self, other):
mykey = self._key()
if isinstance(other, tuple):
otherkey = other
else:
otherkey = other._key()
return mykey == otherkey
# by doing this, we ensure that we compare equals to tuples
return other == self._key()

# this is already defined in blob.py: however, it seems if we do not
# redeclare it here, Cython won't use it
Expand Down
7 changes: 7 additions & 0 deletions capnpy/testing/compiler/test_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ def test_key_on_struct(self):
#
assert p1 == (1, 2)
assert p3 == (3, 4)
assert (1, 2) == p1
assert (3, 4) == p3
assert hash(p1) == hash(p2) == hash((1, 2))
#
assert not p1 == None
assert p1 != None
assert not None == p1
assert None != p1

def test_key_convert_case(self):
schema = """
Expand Down

0 comments on commit 72a6d00

Please sign in to comment.