Skip to content

Commit

Permalink
fix __eq__ for __slots__
Browse files Browse the repository at this point in the history
  • Loading branch information
emmettbutler committed Jun 23, 2016
1 parent 3e95b8d commit 2c48b59
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion parsely_raw_data/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ def __eq__(self, other):
"""Compare and return True if all public attributes are equal."""
if not isinstance(other, self.__class__):
return False
# __slots__ is not inherited from the superclass when accessed as self.__slots__
# work around this here by manually inspecting the __slots__ or everything
# on the MRO
mro_slots = [item for slots in
[a.__slots__ for a in type(self).mro() if hasattr(a, "__slots__")]
for item in slots]
return all(getattr(self, p) == getattr(other, p)
for p in self.__slots__
for p in mro_slots
if not p.startswith('_'))

def __repr__(self):
Expand Down

0 comments on commit 2c48b59

Please sign in to comment.