Refer reST label in python docstring

I want to refer to reST label in my python method docstring and am expecting Sphinx to generate appropriate links.

I tried the following which does not work for me.

myown.rst

.. my-label:
   Some explanation ...

mymodule.py

def somefunc():
    """ See :ref:`my-label`. """
    ... rest of the code ...

This produces "See my-label" as text in the generated html file while I am expecting it to create appropriate hyper-link.

I see this kind of references in python-docs (eg see https://docs.python.org/3/library/functions.html#classmethod ) and reference to Function definitions (which is generic explanation). However, this is not generated from docstrings (as can be seen from funcobject.c) .. so I am inclined to think that it is handcrafted rst !!


Based on comment from @mzjn - the section header was missing in the rst file. Adding that and regenerating fixes the issue.

链接地址: http://www.djcxy.com/p/75500.html

上一篇: 将我的降价自述文件包含在狮身人面像中

下一篇: 在python docstring中引用reST标签