From 2c48b5954a33d724b8e422cd7eabe9cbb6f5b9dc Mon Sep 17 00:00:00 2001 From: Emmett Butler Date: Thu, 23 Jun 2016 12:07:37 -0400 Subject: [PATCH] fix __eq__ for __slots__ --- parsely_raw_data/event.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/parsely_raw_data/event.py b/parsely_raw_data/event.py index 0bff2b0..244acdd 100644 --- a/parsely_raw_data/event.py +++ b/parsely_raw_data/event.py @@ -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):