【发布时间】:2016-01-18 06:10:33
【问题描述】:
http://www.sphinx-doc.org/en/stable/domains.html#cross-referencing-python-objects 的 Sphinx 文档说,
:py:func: 引用一个 Python 函数;可以使用带点的名称。角色文本不需要包括尾括号以增强可读性; 它们将由 Sphinx 自动添加,如果 add_function_parentheses 配置值为 True(默认)。
:py:meth: 引用对象的方法。角色文本可以包括类型名和方法名;如果它发生在描述中 一个类型,类型名称可以省略。可以使用带点的名称。
但我找不到他们的行为方式有什么不同。
这是我为其生成文档的 Python 模块。
"""foo module."""
def hello(name):
"""Print hello addressed to *name*.
Args:
name (str): Name to address.
"""
print('hello', name)
class Foo:
"""Foo class."""
def bye(self, name):
"""Print bye addressed to *name*.
Args:
name (str): Name to address.
"""
print('bye', name)
if __name__ == '__main__':
hello('world')
Foo().bye('python')
这是我在index.rst 文件中的内容。
Foo Documentation
=================
See :func:`foo.hello` and :func:`foo.Foo.bye`.
Also, see :meth:`foo.hello` and :meth:`foo.Foo.bye`.
foo module
==========
.. automodule:: foo
:members:
执行make html 后,这是我看到的输出。
:func: 和 :meth: 角色都生成了到 hello 和 Foo.bye 的有效交叉引用超链接,无论目标是函数还是方法。
那么:func: 和:meth: 角色之间的区别是什么。你能举一个他们表现不同的例子吗?
【问题讨论】:
标签: python python-sphinx cross-reference