Fix: MutableRecord interprets __slots__ incorrectly (issue #133)

This commit is contained in:
joodicator committed 2019-07-03 19:53:30 +02:00
1 parent e97458c970
commit a03e1a7c47
1 file changed
+7 -3
+7 -3
View File
@@ -65,7 +65,8 @@ class MutableRecord(object):
def __repr__(self): def __repr__(self):
return '%s(%s)' % (type(self).__name__, ', '.join( return '%s(%s)' % (type(self).__name__, ', '.join(
'%s=%r' % (a, getattr(self, a)) for a in self._all_slots())) '%s=%r' % (a, getattr(self, a)) for a in self._all_slots()
if hasattr(self, a)))
def __eq__(self, other): def __eq__(self, other):
return type(self) is type(other) and all( return type(self) is type(other) and all(
@@ -83,8 +84,11 @@ class MutableRecord(object):
@classmethod @classmethod
def _all_slots(cls): def _all_slots(cls):
return tuple(f for c in reversed(cls.__mro__) for supcls in reversed(cls.__mro__):
for f in getattr(c, '__slots__', ())) slots = supcls.__dict__.get('__slots__', ())
slots = (slots,) if isinstance(slots, str) else slots
for slot in slots:
yield slot
def attribute_alias(name): def attribute_alias(name):