Skip to main content
 首页 » 编程设计

python之交叉引用装饰器

2025年05月04日12bjzhanghao

sphinx 中的 python 域有 .. py:decorator:: 来记录装饰器,但如何交叉引用装饰器?

对于函数(用 .. py:function:: 记录)有 :py:func:。装饰器的等价物是什么?

请您参考如下方法:

我在sphinx的文档中找到了答案:

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

官方的解决方案是使用:py:func:。它也有效。不幸的是,sphinx 在装饰器名称后添加了括号。

text py:func:`mydecorator` text 

成为输出:

text mydecorator() text 

brakets 可以全局禁用,但在引用实际函数时我非常喜欢它们。