class (listtree)__slots__ [' '' ' ( print(xoksuperclass produces __dict__ displays at xa and at the following classes display correctly as well--any nonslot class like listtree generates an instance __dict__and can thus safely assume its presenceclass a__slots__ [' 'class (alisttree)pass class a__slots__ [' 'class (alisttree)__slots__ [' 'both ok by bullet above displays at ba at although it renders subclass slots pointlessthis is positive side effect for tools classes like listtree (and its predecessorin generalthoughsome tools might need to catch exceptions when __dict__ is absent or use hasattr or getattr to test or provide defaults if slot usage may preclude namespace dictionary in instance objects inspected for exampleyou should now be able to understand why the mapattrs py program earlier in this must check for the presence of __dict__ before fetching it-instance objects created from classes with __slots__ won' have one in factif we use the highlighted alternative line in the followingthe mapattrs function fails with an exception when attempting to look for an attribute name in the instance at the front of the inheritance path sequencedef mapattrs(instancewithobject=falsebysource=false)for attr in dir(instance)for obj in inheritsif attr in obj __dict__may fail if __slots__ used class c__slots__ [' ' (mapattrs(xattributeerror'cobject has no attribute '__dict__either of the following works around the issueand allows the tool to support slots-the first provides defaultand the second is more verbose but seems marginally more explicit in its intentif attr in getattr(obj'__dict__'{})if hasattr(obj'__dict__'and attr in obj __dict__as mentioned earliersome tools may benefit from mapping dir results to objects in the mro this wayinstead of scanning an instance __dict__ in general--without this more inclusive approachattributes implemented by class-level tools like slots won' be reported as instance data even sothis doesn' necessarily excuse such tools from allowing for missing __dict__ in the instance too advanced class topics