0

Consider this:

class Base:
  pass

class Derived(Base):
  pass

print(Base.__dict__)
print(Derived.__dict__)

print('__dict__' in Base.__dict__)
print('__dict__' in Derived.__dict__)

The output is:

{'__module__': '__main__', '__dict__': <attribute '__dict__' of 'Base' objects>, '__weakref__': <attribute '__weakref__' of 'Base' objects>, '__doc__': None}
{'__module__': '__main__', '__doc__': None}
True
False

Why are the '__dict__' and '__weakref__' keys missing for the Derived class? What does this mean/affect?

pallgeuer
  • 1,216
  • 1
  • 7
  • 17
  • See https://stackoverflow.com/questions/23529929/python-class-inheritance-and-dict-lookup – Rennnyyy May 23 '20 at 13:45
  • Does this answer your question? [python get only class attribute no superclasses](https://stackoverflow.com/questions/7241528/python-get-only-class-attribute-no-superclasses) – Joe May 23 '20 at 14:34
  • Those are good references. I can't quite connect the dots though how that applies to `'__dict__'` specifically then, and not for example for `'__module__'` or `'__doc__'` and how the Python object model then works. Does it start in the most-subclassed `__dict__` and keeps going with the MRO until it finds the key its looking for in the successive `__dict__`'s? – pallgeuer May 23 '20 at 14:36

0 Answers0