[英]reStructuredText link in Python
If I have the following function in Python:如果我在 Python 中有以下函数:
def _add_parameter(self, a):
# do something
And I want to add a docstring to link to the above function using reStructuredText, I just need to add an underscore at the end of the function name like the following:我想添加一个文档字符串以使用 reStructuredText 链接到上述函数,我只需要在函数名称的末尾添加一个下划线,如下所示:
"""
The _add_parameter_ adds parameters.
"""
But instead of linking it to the function, I get a cannot find declaration to go to
warning.但是,我没有将其链接到函数,而是收到了一个
cannot find declaration to go to
。 How do I fix this?我该如何解决?
The autodoc extension only documents non private members, ie members where the name does not start with an underscore. autodoc 扩展仅记录非私有成员,即名称不以下划线开头的成员。 From the documentation:
从文档中:
.. autoclass:: Noodle
:members:
will document all non-private member functions and properties (that is,
those whose name doesn’t start with _).
So, when autodoc tries to find the place to link to, it doesn't find it.因此,当 autodoc 试图找到要链接的位置时,它找不到它。
To override not documenting private members you can use :private-members:
, but I cannot tell from experience if that works.However, it is generally preferred to only document the public interface.要覆盖不记录私有成员,您可以使用
:private-members:
,但我无法根据经验判断这是否有效。但是,通常最好只记录公共接口。
Since the formatting of the comments made me confused, here it is with proper formatting:由于评论的格式让我感到困惑,这里有正确的格式:
class A:
def foo(): ...
def bar(): ...
"""
:py:meth:`A.foo`
:py:func:`bar`
"""
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.