![](https://secure.gravatar.com/avatar/0a2191a85455df6d2efdb22c7463c304.jpg?s=120&d=mm&r=g)
On 17.11.2021 15:26, tmkehrenberg@gmail.com wrote:
Hi all,
I have seen discussion of docstrings for class attributes before on this list, but not with this exact proposal.
My motivation is that I have a dataclass for which I want to write docstrings that can be accessed at runtime. In my specific case, the docstrings would be used to create a help message.
Sphinx supports a syntax to document class attributes. It looks like this:
@dataclass class A: """Docstring for class A.""" x: int """Docstring for x""" y: bool = True "Docstring for y"
See https://www.python.org/dev/peps/pep-0224/ Perhaps it's time to revive the idea for its 20th anniversary :-)
It is a bit awkward that the docstring is *below* the definition of the attribute, but it can't be put above because it could be confused for the class docstring.
My proposal would be to just enshrine this syntax as the syntax for attribute docstring, and to make them available at runtime. They would be stored in a dictionary like the type annotations. For example like this:
A.__attrdoc__ == {"x": "Docstring for x", "y": "Docstring for y"} -- Marc-Andre Lemburg eGenix.com
Professional Python Services directly from the Experts (#1, Nov 18 2021)
Python Projects, Coaching and Support ... https://www.egenix.com/ Python Product Development ... https://consulting.egenix.com/
::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 https://www.egenix.com/company/contact/ https://www.malemburg.com/