46

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

我试过了

List[type]
list of type

Optional[type]
type, optional

Yields:
   type: 

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

Optional[type]

只是给

可选[类型]

没有任何链接type

我已经尝试了每个内置主题并且遇到了同样的问题。

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

4

1 回答 1

2

I know this is quite old, but did you take a look at this example? Particularly lines:

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."""
于 2017-09-08T19:40:14.157 回答