I want to document Python object attributes with Sphinx. I understand I should use
:ivar varname: description
:ivar type varname: description
As mzjn referred there is an open issue for this SO post. In that thread there is also already a work-around for the issue posted. In sum, you use inline comments #:
instead of the docstring.
Take a look at the python.py
file in the commit referred by the user here. The docstring entries were removed (red lines), and he added inline comments in the constructor (green lines).
I have been looking for documentation on this but could not find it. For instance:
(...)
def __init__(self, function, fixtureinfo, config, cls=None, module=None):
#: access to the :class:`_pytest.config.Config` object for the test session
self.config = config
(...)
As noted by Nick Bastin this work-around renders completely differently from :ivar:
. There is no type support, and it always renders the default value.