How are instance and class attributes correctly documented in Python when using reStructredText docstrings? I have the following example class:
class TestClass(object):
""" This is a test class to demonstrate documentation.
:param first_name: first name of the person
:type first_name: str
:param last_name: last name of the person
:type last_name: str
:param name: full name of the person
:type name: str
:cvar species: species of the person
:type species: str
"""
species = 'human'
def __init__(self, first_name, last_name):
self.name = ' '.join((first_name, last_name))
I already know that I should document the functionality of the __init__
function in the class docstring, including it's parameters first_name
and last_name
. But what about the instance attribute name
and the class attribute species
?
The goal is to show the documentation correctly in PyCharm and to have the code compatible with Sphinx and other docstring parsers. This is how PyCharm is currently displaying the documentation. Parameters are shown correctly, but the description for the attributes are missing.