19

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.

3
  • What about using :py:attr: with the property?
    – Vincent
    Commented Nov 27, 2014 at 12:44
  • I tried :py:attr: too. Nothing changed: the link does not appear.
    – Felix
    Commented Nov 27, 2014 at 12:46
  • Are you using functools.wraps to retain the wrapped function's documentation? Could you provide an example of what you're doing, and the expected and actual output?
    – jonrsharpe
    Commented Nov 27, 2014 at 13:01

3 Answers 3

27

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`
        """
5

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`
1

I use :py:obj: instead.

:py:attr: won't work for me when the property is in another page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.