Mar-08-2020, 02:57 PM
(This post was last modified: Mar-08-2020, 02:57 PM by Gribouillis.)
Mro is the way to go. Use
Edit: bugfix: changed getattr to __dict__.get to avoid repetition in case subclasses don't have slots.
def all_slots(ob): if not hasattr(ob, 'mro'): ob = type(ob) for cls in reversed(ob.mro()): yield from cls.__dict__.get('__slots__', ())and replace
for attr in self.__slots__
with for attr in all_slots(self)
Edit: bugfix: changed getattr to __dict__.get to avoid repetition in case subclasses don't have slots.