[英]How to add authorship to NumPy docstring, in Python
We switched from Sphinx to style NumPy docstring and .. sectionauthor::
no longer seems to render correctly. 我们从Sphinx切换为NumPy docstring和.. sectionauthor::
样式似乎不再正确呈现。 Yet, we need to be able to assign an author to each method of a class. 但是,我们需要能够为一个类的每个方法分配一个作者。
Is there a way to add authorship to NumPy docstring properly? 有没有一种方法可以适当地向NumPy文档字符串添加作者身份?
A naive example: 一个简单的例子:
class A:
def f(self):
""" My function
It does this and that.
Returns
-------
object
.. sectionauthor:: name of the author
Examples
--------
>>> A().f()
"""
pass
Compiles into this help doc (notice troubled returns: section): 编译到此帮助文档中(注意问题返回:部分):
PS Use of .. sectionauthor::
in NumPy docstring was suggested elsewhere (can't recall the source), so maybe it is simply not used/placed correctly. PS在NumPy中使用.. sectionauthor::
::: docstring在其他地方建议使用(无法回忆起源代码),因此也许根本就没有正确使用/放置它。
figured it out... 弄清楚了...
First of all, NumPy style documentation discourages addition of authors' info to docstring: " Note that license and author info, while often included in source files, do not belong in docstrings. " 首先, NumPy样式文档不鼓励在文档字符串中添加作者的信息:“ 请注意,虽然许可证和作者信息通常包含在源文件中,但并不属于文档字符串。 ”
That said, it is not uncommon to identify authors directly in documentation (see any help manual for functions/methods in R language). 也就是说,直接在文档中标识作者并不罕见(有关R语言的函数/方法,请参见任何帮助手册)。
Still, shall there be a need to add authors, this can be done with :Authors:
reStructured inline markup tag, as following: 尽管如此,还是需要添加作者,可以使用:Authors:
reStructured inline markup tag来完成,如下所示:
:Authors:
John Doe <John.Doe@email.com>
As discovered, its placement is limited. 如所发现的,其放置是有限的。 :Authors:
seems to still render docstring correctly, if placed away from descriptions, parameters, and returns sections; :Authors:
如果放置在远离描述,参数和返回节的位置,似乎仍然可以正确呈现文档字符串; for example, after Examples
section. 例如,在“ Examples
部分之后。
Here is a continued example: 这是一个继续的示例:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.