python-2.7 - 我应该如何使用 Google 风格的 Sphinx 记录列表、选项和 yield ?

标签 python-2.7 types generator python-sphinx sphinx-napoleon

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

我已经尝试过

List[type]
list of type

Optional[type]
type, optional

Yields:
   type: 

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

Optional[type]

只是给出

Optional[type]

没有任何 type 的链接.

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

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

最佳答案

我知道这已经很老了,但是你看过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."""

关于python-2.7 - 我应该如何使用 Google 风格的 Sphinx 记录列表、选项和 yield ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34099302/

相关文章:

arrays - 如何将不同类型的值转换为数据字节

python - 在 Python 中对生成器进行索引和切片

python - Django 项目 : django-admin. py:找不到命令

python - 解决 "Number of subsets without consecutive numbers"时出现OverFlowError

java - 我们如何在 Java 中使用泛型类型和基元

python - 如何编写良好的生成器链接函数

c++ - C++中具有概率分布的 vector 的随机生成器

python - py2exe 与 scipy.sparse.sparsetools.csr

python - numpy fromfile(count = -1) 在 Mac OS 上返回零数组以获得巨大的文件大小

c# - 如何检查列是否可以转换为 double ? (DataTable.Column.DataType)