Sphinx文档:如何引用Python属性?

时间:2014-11-27 12:34:58

标签: python python-sphinx

如何引用用@property修饰的方法?

对于简单方法,:py:meth:工作正常,但不适用于属性:它不会创建指向它们的链接。

3 个答案:

答案 0 :(得分:9)

您应该使用:py:attr:代替。这个例子适合我:

class SomeClass(object):
    """This is the docstring of SomeClass."""

    @property
    def some_property(self):
        """This is the docstring of some_property"""
        return None

    def some_method(self):
        """This is the docstring of some_method.

        And this is a reference to :py:attr:`~some_property`
        """

答案 1 :(得分:0)

我改用:py:obj:

:py:attr:在该属性位于另一页中时对我不起作用。

答案 2 :(得分:0)

这对我有用。它使用正确的链接呈现MyClass.my_prop

:attr:`.MyClass.my_prop`

这仅渲染my_prop,具有相同的链接。

:attr:`~.MyClass.my_prop`
相关问题