How does one specify a type for variables in Python docstrings for Sphinx?

You can specify types of parameters in Python docstrings like this:

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
    """
    ...

With Sphinx' autodoc feature, this yields the parameters list, and each parameter is properly tagged with their types.

But how do I do this with instance attributes? Something like this

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

    :type edge_indices: list of int
    """

does not work. One can put a single-word type after the :ivar but here, it consists of three words, so that would not work.


I had this same issue. The answer is vartype :

class Foo:
    """
    :ivar edge_indices: description
    :vartype edge_indices: list of int
    """
链接地址: http://www.djcxy.com/p/23922.html

上一篇: 有处理大型机数据的模式吗?

下一篇: 如何为Sphinx的Python文档中的变量指定一个类型?