[docs] [issue30449] Improve __slots__ datamodel documentation
mpb
report at bugs.python.org
Fri Dec 29 22:15:32 EST 2017
mpb <mpb.mail at gmail.com> added the comment:
Can __slots__ be assigned a string? If so, what are the consequences? I find the current docs lack clarity. For example from the docs for 3.7.0a3:
https://docs.python.org/3.7/reference/datamodel.html#slots
> 3.3.2.4. __slots__
>
> [snip]
>
> object.__slots__
> This class variable can be assigned a string,
> iterable, or sequence of strings [snip]
However, "3.3.2.4.1. Notes on using __slots__" does not discuss what happens when a string is assigned to __slots__.
The "notes" section does discuss assigning a "sequence of strings" to __slots__.
The "notes" section also says: "Any non-string iterable may be assigned to __slots__."
Based on quick experimentation, it appears that the string must be a single identifier. I get a TypeError if I try to assign "foo bar" to __slots__. The consequence of a string appears to be that only a single slot is created. It would be nice if this was stated clearly in the docs.
The docs for 2.7 seem similar to version 3.7.0a3. So maybe all versions of the docs could be improved regarding the specifics of what happens when you assign a string to __slots__.
----------
nosy: +mpb
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue30449>
_______________________________________
More information about the docs
mailing list