【问题标题】:How does one specify a type for variables in Python docstrings for Sphinx?如何为 Sphinx 的 Python 文档字符串中的变量指定一种类型?
【发布时间】:2014-12-16 19:26:41
【问题描述】:

您可以像这样在 Python 文档字符串中指定参数类型:

def __init__(self, canvas, segments):
    """Class constructor.

    :param canvas: the PDF canvas object
    :param segment: The layer segments to be drawn.

    :type canvas: `canvas.Canvas`
    :type segments: list of str
    """
    ...

使用 Sphinx 的自动文档功能,这会产生参数列表,并且每个参数都被正确地标记了它们的类型。

但是如何使用实例属性来做到这一点?像这样的

class Path(object):
    """
    :ivar edge_indices: The indices within `textured_points` of the places.

    :type edge_indices: list of int
    """

不起作用。可以在:ivar 之后放置一个single-word 类型,但在这里,它由三个单词组成,所以这行不通。

【问题讨论】:

    标签: python python-sphinx docstring autodoc


    【解决方案1】:

    我也有同样的问题。答案是vartype

    class Foo:
        """
        :ivar edge_indices: description
        :vartype edge_indices: list of int
        """
    

    【讨论】:

      猜你喜欢
      • 2019-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-02
      • 2020-11-05
      相关资源
      最近更新 更多