如何在Python中向numpydocstring添加作者身份

2024-06-28 19:41:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我们从Sphinx切换到样式numpydocstring,.. sectionauthor::似乎不再正确呈现。但是,我们需要能够为类的每个方法分配一个作者。在

有没有一种方法可以正确地将作者身份添加到numpydocstring中?在

一个天真的例子:

class A:
    def f(self):
        """ My function

        It does this and that.

        Returns
        -------
        object

        .. sectionauthor:: name of the author

        Examples
        --------
            >>> A().f()

        """
        pass

编译到本帮助文档中(注意,问题返回:部分):

enter image description here

另外,在NumPy docstring中使用.. sectionauthor::是在其他地方建议的(不能回忆源代码),所以可能只是没有正确使用/放置。在


Tags: 方法selfmydefsphinx身份itfunction
1条回答
网友
1楼 · 发布于 2024-06-28 19:41:13

明白了。。。在

首先,NumPy style documentation不鼓励将作者信息添加到docstring:“请注意,虽然许可证和作者信息通常包含在源文件中,但并不属于docstring。

也就是说,在文档中直接识别作者并不少见(请参阅R语言中函数/方法的帮助手册)。在

但是,如果需要添加作者,可以使用:Authors:reStructured inline markup标记来完成,如下所示:

:Authors:
    John Doe <John.Doe@email.com>

正如所发现的,它的位置是有限的。:Authors:似乎仍然正确地呈现docstring,如果放置在远离描述、参数和返回节的地方;例如,在Examples节之后。在

下面是一个连续的例子:

enter image description here

相关问题 更多 >