mpb <mpb.m...@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 <rep...@bugs.python.org> <https://bugs.python.org/issue30449> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com