Skip to content

Commit

Permalink
Merge pull request #23 from kived/objc-hash-cmp
Browse files Browse the repository at this point in the history
add hash and comparison to objc instances
  • Loading branch information
kived committed Mar 2, 2016
2 parents 4b30acf + 7bbe5f5 commit 111962e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pyobjus/pyobjus_types.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,17 @@ cdef class ObjcClassInstance:
self.resolve_methods()
self.resolve_fields()

def __hash__(self):
return self.get_address()

def __richcmp__(self, other, op):
if isinstance(other, ObjcClassInstance):
if op == 2:
return hash(self) == hash(other)
if op == 3:
return hash(self) != hash(other)
return False

def get_address(self):
return <unsigned long><void *>self.o_instance

Expand Down

0 comments on commit 111962e

Please sign in to comment.