简体   繁体   中英

Referencing Python method documentation without full class name in Sphinx

I'm trying to reference

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

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 (ie, in the same style and simply as __enter__ and not as object.__enter__ .

Is there a way to accomplish this?

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

An alternative:

:meth:`~.object.__enter__`

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

Or just use this:

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

See http://sphinx-doc.org/markup/inline.html#cross-referencing-syntax and http://sphinx-doc.org/rest.html#hyperlinks .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM