Sphinx :ivar tag goes looking for cross-references

前端 未结 4 699
粉色の甜心
粉色の甜心 2021-01-07 22:35

I want to document Python object attributes with Sphinx. I understand I should use

:ivar varname: description
:ivar type varname: description
4条回答
  •  别那么骄傲
    2021-01-07 23:11

    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.

提交回复
热议问题