0

Maybe I'm a little bit nitpicky, but there is the following statement in Python Documentation, about the definition of __slots__:

When inheriting from a class without __slots__, the __dict__ attribute of that class will always be accessible, so a __slots__ definition in the subclass is meaningless.

However, object does not have a __slots__ and surely have a __dict__. How could a definition of __slots__ in a subclass of object have any effect?

Naitree
  • 1,088
  • 1
  • 14
  • 23
  • As Alex Martelli puts it in the dupe (emphasis mine) - *"Classes with dict-less instances are those which define `__slots__`, **plus most built-in types**"* - `object` instances don't have a dict, `object().__dict__` is an `AttributeError`. – jonrsharpe Oct 09 '15 at 13:25
  • `object` is a builtin type that isn't implemented directly in python, so I wouldn't expect to see `__slots__` anywhere. However it certainly has something equivalent going on. It has no `__dict__` attribute either and you can't assign new attributes to it (try `object().x = 3` in a console) much like classes with slots. – Alex Hall Oct 09 '15 at 13:27
  • So the point is the _instances_ of any superclass are dict-less, rather than the superclasses _themselves_ being dict-less? But it seems the documentation only mentioned "the `__dict__` attribute of _that class_". Can you point me to any reference on this matter? – Naitree Oct 09 '15 at 13:41

0 Answers0