python - 交叉引用装饰器

标签 python python-sphinx python-decorators cross-reference

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 可以全局禁用,但在引用实际函数时我非常喜欢它们。

关于python - 交叉引用装饰器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30353856/

相关文章:

python - 使用 strip() 只删除一个元素

python - 如何确保 netcdf 文件在 python 中关闭?

python - Sphinx Autodoc 从文档字符串中跳过成员

python - 当使用实体列表调用 db.put() 时,是否会为每个实体调用特定于模型的 put() ?

python-sphinx - 将可点击的 SVG 图像插入到 Sphinx 文档中

python - 如何制作功能装饰器链?

python - 在 Python 中添加将字符串转换为小写的装饰器

带参数的 Python/Flask 嵌套装饰器

python - matplotlib 在数据坐标中注释 basemap