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"

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"}

Best,
Thomas
_______________________________________________
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/3LGSNMHKJ4RIHASAEZST4F3MW25UTNU5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to