Skip to content

Commit d7537ac

Browse files
bpo-46076: Improve documentation for per-attribute docstrings with __slots__ (GH-30109) (GH-30206)
1 parent cdb4579 commit d7537ac

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Doc/reference/datamodel.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,9 +1877,12 @@ Notes on using *__slots__*
18771877
* Nonempty *__slots__* does not work for classes derived from "variable-length"
18781878
built-in types such as :class:`int`, :class:`bytes` and :class:`tuple`.
18791879

1880-
* Any non-string iterable may be assigned to *__slots__*. Mappings may also be
1881-
used; however, in the future, special meaning may be assigned to the values
1882-
corresponding to each key.
1880+
* Any non-string :term:`iterable` may be assigned to *__slots__*.
1881+
1882+
* If a :class:`dictionary <dict>` is used to assign *__slots__*, the dictionary
1883+
keys will be used as the slot names. The values of the dictionary can be used
1884+
to provide per-attribute docstrings that will be recognised by
1885+
:func:`inspect.getdoc` and displayed in the output of :func:`help`.
18831886

18841887
* :attr:`~instance.__class__` assignment works only if both classes have the
18851888
same *__slots__*.

0 commit comments

Comments
 (0)