This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Document using __slots__ to provide per-attribute docstrings
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: AlexWaygood, docs@python, miss-islington, rhettinger
Priority: normal Keywords: patch

Created on 2021-12-14 22:25 by AlexWaygood, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30109 merged AlexWaygood, 2021-12-14 22:30
PR 30206 merged miss-islington, 2021-12-19 20:20
PR 30207 merged miss-islington, 2021-12-19 20:20
Messages (6)
msg408573 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2021-12-14 22:25
The ability to add docstrings for individual attributes, by using a dictionary for __slots__ was added in Issue36326. This is a fantastic feature, and deserves better documentation. It appears to currently only be documented in the "What's New" entry for Python 3.8: https://docs.python.org/3/whatsnew/3.8.html#inspect.

Moreover, the data model documentation currently states the following regarding using a mapping to specify __slots__:

"""
Any non-string iterable may be assigned to __slots__. Mappings may also be used; however, in the future, special meaning may be assigned to the values corresponding to each key.
"""

This is arguably now incorrect. A special meaning has been assigned to the values corresponding to each key: the values can be used for per-attribute docstrings.
msg408921 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-12-19 20:20
New changeset aeb9ef4c7287fe367b6e9adcf1c5f994d5bc1a09 by Alex Waygood in branch 'main':
bpo-46076: Improve documentation for per-attribute docstrings with `__slots__` (GH-30109)
https://github.com/python/cpython/commit/aeb9ef4c7287fe367b6e9adcf1c5f994d5bc1a09
msg408922 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-12-19 20:22
Thanks for the PR.
msg408928 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-12-19 21:11
New changeset d7537ac8e3a3ef15d2c5f3fe90e998618b6a97b9 by Miss Islington (bot) in branch '3.10':
bpo-46076: Improve documentation for per-attribute docstrings with `__slots__` (GH-30109) (GH-30206)
https://github.com/python/cpython/commit/d7537ac8e3a3ef15d2c5f3fe90e998618b6a97b9
msg408929 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-12-19 21:11
New changeset 8bfb11a791679a33024c9857e082afed0d71e0b4 by Miss Islington (bot) in branch '3.9':
bpo-46076: Improve documentation for per-attribute docstrings with `__slots__` (GH-30109) (GH-30207)
https://github.com/python/cpython/commit/8bfb11a791679a33024c9857e082afed0d71e0b4
msg408930 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2021-12-19 21:12
Thanks for taking the time to review and merge :)
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90234
2021-12-19 21:12:58AlexWaygoodsetmessages: + msg408930
2021-12-19 21:11:40rhettingersetmessages: + msg408929
2021-12-19 21:11:20rhettingersetmessages: + msg408928
2021-12-19 20:22:58rhettingersetstatus: open -> closed
resolution: fixed
messages: + msg408922

stage: patch review -> resolved
2021-12-19 20:20:38rhettingersetmessages: + msg408921
2021-12-19 20:20:23miss-islingtonsetpull_requests: + pull_request28428
2021-12-19 20:20:19miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request28427
2021-12-14 22:30:39AlexWaygoodsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28332
2021-12-14 22:25:11AlexWaygoodcreate