[New-bugs-announce] [issue30449] Improve __slots__ datamodel documentation
report at bugs.python.org
Tue May 23 21:01:47 EDT 2017
New submission from Aaron Hall:
The __slots__ documentation in the datamodel needs improvement.
> 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.
The __slots__ definition for such a subclass is not meaningless: other slots declared will still be used, and the __dict__ will not be instantiated unless it is looked for (although this may be an implementation detail).
> The action of a __slots__ declaration is limited to the class where it is defined. As a result, subclasses will have a __dict__ unless they also define __slots__ (which must only contain names of any additional slots).
That's not quite right either. The action of a __slots__ declaration is not entirely limited to the class where it is defined. They can have implications for multiple inheritance, and child classes will have access to those slots.
I have some changes I'd like to make to the entire section on __slots__, and I'll be providing a pull request soon.
assignee: docs at python
nosy: Aaron Hall, docs at python
title: Improve __slots__ datamodel documentation
versions: Python 2.7, Python 3.6, Python 3.7
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce