On 17.11.2021 15:26, tmkehrenb...@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/ _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/HLBTXCBOTQYD7JJ5WVH3TZEVJEB6H2XB/ Code of Conduct: http://python.org/psf/codeofconduct/