9

您可以像这样在 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 的 autodoc 功能,这会产生参数列表,并且每个参数都用它们的类型正确标记。

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

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

    :type edge_indices: list of int
    """

不起作用。可以在 the 后面放一个单词类型,:ivar但是这里它由三个单词组成,这样就行不通了。

4

1 回答 1

6

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

class Foo:
    """
    :ivar edge_indices: description
    :vartype edge_indices: list of int
    """
于 2017-01-26T02:21:55.423 回答