我应该如何使用Google风格的Sphinx记录列表,选项和收益?

时间:2015-12-04 23:38:46

标签: python-2.7 types documentation generator python-sphinx

如何使用Sphinx-Napoleon在Google风格的文档字符串中为生成器指定列表,可选参数和返回类型的类型?

我试过

List[type]
list of type

Optional[type]
type, optional

Yields:
   type: 
分别

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

Optional[type]

刚刚给出

  

可选[类型]

没有type的任何链接。

我尝试过每个内置主题并遇到同样的问题。

我应该如何使用Sphinx-Napoleon的Google风格文档来记录这些元素?

1 个答案:

答案 0 :(得分:2)

我知道这已经很老了,但你看看this example了吗?特别是行:

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."""