python 2.7-我应该如何使用Google样式的Sphinx记录列表,可选内容和收益?

如何使用Sphinx-Napoleon在Google样式的文档字符串上指示列表类型,可选参数和生成器的返回类型?

我试过了

List[type]
list of type

Optional[type]
type, optional

Yields:
   type: 

分别; 但是所有生成的输出都不令人满意,这与生成的文档的其余部分不一致。 例如

Optional[type]

只是给

可选[类型]

没有type的任何链接。

我尝试了所有内置主题,并且遇到了相同的问题。

我应该如何在Sphinx-Napoleon中使用Google样式的文档字符串记录这些元素?

1个解决方案
2 votes

我知道这已经很老了,但是您是否看过这个例子? 特别是行:

def __init__(self, param1, param2, param3):
        """Example of docstring on the __init__ method.

        The __init__ method may be documented in either the class level
        docstring, or as a docstring on the __init__ method itself.

        Either form is acceptable, but the two should not be mixed. Choose one
        convention to document the __init__ method and be consistent with it.

        Note:
            Do not include the `self` parameter in the ``Args`` section.

        Args:
            param1 (str): Description of `param1`.
            param2 (:obj:`int`, optional): Description of `param2`. Multiple
                lines are supported.
            param3 (:obj:`list` of :obj:`str`): Description of `param3`.

        """
        self.attr1 = param1
        self.attr2 = param2
        self.attr3 = param3  #: Doc comment *inline* with attribute

        #: list of str: Doc comment *before* attribute, with type specified
        self.attr4 = ['attr4']

        self.attr5 = None
        """str: Docstring *after* attribute, with type specified."""
Colonder answered 2020-06-22T07:09:26Z
translate from https://stackoverflow.com:/questions/34099302/how-should-i-document-lists-optionals-and-yields-using-google-style-sphinx