Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sphinx documentation: how to reference a Python property?

How can I reference a method, decorated with @property?

For simple methods, :py:meth: is working fine, but not for properties: it does not create a link to them.

like image 974
Felix Avatar asked Nov 27 '14 12:11

Felix


People also ask

What is Ivar in Python?

ivar is an "instance variable", or a variable that is set on an instance object (an instance of a class). Typically these would be defined (in Python) inside of an __init__ method.

Does Sphinx support markdown?

To support Markdown-based documentation, Sphinx can use MyST-Parser. MyST-Parser is a Docutils bridge to markdown-it-py, a Python package for parsing the CommonMark Markdown flavor.


2 Answers

You should use :py:attr: instead. This example works fine for me:

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`
        """
like image 153
Vincent Avatar answered Nov 10 '22 13:11

Vincent


This works for me. It renders MyClass.my_prop with the proper link.

:attr:`.MyClass.my_prop`

This renders just my_prop, with the same link.

:attr:`~.MyClass.my_prop`
like image 44
WhyNotHugo Avatar answered Nov 10 '22 12:11

WhyNotHugo