在Sphinx中引用没有完整类名的Python方法文档 [英] Referencing Python method documentation without full class name in Sphinx

查看:230
本文介绍了在Sphinx中引用没有完整类名的Python方法文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试参考

http://docs.python.org/2.7/reference/datamodel.html#object.__enter__

,并希望文档中的链接看起来像如果 __输入__ 在当前类中实现了一个func :func:角色(即,以相同的样式并且简单地作为 __输入__ ,而不是 对象.__输入__

from my python Sphinx documentation, and would like the link in the documentation to look as it would for a func :func: role if __enter__ were implemented in the current class (i.e, in the same style and simply as __enter__ and not as object.__enter__.

有没有办法完成这个?

推荐答案

如果您已设置 interphinx ,以下标记将产生指向目标的超链接带有链接文本的Python文档 __输入__

If you have set up intersphinx, the following markup will produce a hyperlink to the specified target in the Python documentation with the link text __enter__:

:meth:`__enter__ <object.__enter__>`

另一种选择:

:meth:`~.object.__enter__`

这将导致链接文本 __ enter __()(默认为括号)请参阅 http://sphinx-doc.org/config.html#confval-add_function_parentheses)。

This will result in the link text __enter__() (with parentheses by default; see http://sphinx-doc.org/config.html#confval-add_function_parentheses).

或者只是使用这个:

`__enter__ <http://docs.python.org/2.7/reference/datamodel.html#object.__enter__>`_

请参阅 http:// sphinx-doc。 org / markup / inline.html#交叉引用语法 http:// sphinx -doc.org/rest.html#hyperlinks

这篇关于在Sphinx中引用没有完整类名的Python方法文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆