In the Python data model reference section on slots there is a list of notes on using __slots__
. I am thoroughly confused by the 1st and 6th items, because the
From the answer you linked:
The proper use of
__slots__
is to save space in objects. Instead of having a dynamic dict...
"When inheriting from a class without __slots__
, the __dict__
attribute of that class will always be accessible", so adding your own __slots__
cannot prevent objects from having a __dict__
, and cannot save space.
The bit about __slots__
not being inherited is a little obtuse. Remember that it's a magic attribute and doesn't behave like other attributes, then re-read that as saying this magic slots behavior isn't inherited. (That's really all there is to it.)