1
votes

I'm documenting my Python project with Sphinx, and want to document class attributes inside the class docstring block. Attribute inline docstrings are ugly.

I did try adding attribute docstring to class docstring block but when Sphinx makes html, it does not show properly.

class MyClass():
    """
        MyClass docstring block.

        Attributes:
            name - A single attribute.
            :attr name - A single attribute.
    """

    name = "ABC"

The generated html displays a simple line. Instead with attribute inline docstring display a nice style.

Attribute inline docstring

Attribute docstring in class block docstring

1
Do not post images of code. Post your actual code. - Steve Piercy

1 Answers

1
votes

You should put a colon after the attribute name:

class MyClass():
    """MyClass docstring block.

        Attributes:
            name: A single attribute.
            name: A single attribute.
    """

    name = "ABC"