Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross referencing decorators

The python domain in sphinx has .. py:decorator:: to document decorators, but how to cross reference a decorator?

For functions (documented with .. py:function::) there is :py:func:. What is the equivalent for decorators?

like image 628
Stefan Avatar asked Jan 23 '26 22:01

Stefan


1 Answers

I found the answer in sphinx's documentation:

There is no py:deco role to link to a decorator that is marked up with this directive; rather, use the py:func role. http://sphinx-doc.org/domains.html#directive-py:decorator

The official solution is to use :py:func:. It works too. Unfoutunately sphinx adds brackets after the decorator name.

text py:func:`mydecorator` text

becomes in the output:

text mydecorator() text

The brakets can be disabled globally, but I quite like them when referencing real functions.

like image 163
Stefan Avatar answered Jan 26 '26 13:01

Stefan