【发布时间】: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