0

我有一个项目,其中一些功能以拿破仑 numpy 风格记录。本着 numpyness 的精神,我有一堆属于 class 的函数参数array-like。这是一个例子:

def foo(x, y):
    """
    Foo the arguments together to make a bar.

    Parameters
    ----------
    x : array-like
        This is an argument.
    y : array-like
        I like it, give me another!

    Returns
    -------
    bar : numpy.ndarray
        Works every time
    """
    pass

这工作得很好,并且类型包含在没有链接的输出中:

生成

问题是我在每个函数的每一行都收到警告:

/.../my_project/my_module.py:docstring of my_project.my_module.foo:: WARNING: py:class reference target not found: array-like
/.../my_project/my_module.py:docstring of my_project.my_module.foo:: WARNING: py:class reference target not found: array-like

我相当确信有一些解决方案。似乎PR #7690以某种方式解决了这个问题,但我在拿破仑或更广泛的 sphinx 文档中的任何地方都找不到有意义的参考“预处理”。

那么如何摆脱警告呢?

4

1 回答 1

3

通过 PR 挖掘,我找到了查看位置:配置项允许您为、等napoleon_type_aliases设置映射。在这种特殊情况下,添加以下内容即可:array-likedict-likeconf.py

napoleon_use_param = True
napoleon_type_aliases = {
    'array-like': ':term:`array-like <array_like>`',
    'array_like': ':term:`array_like`',
}

napoleon_use_param必须True为此工作。它被记录为默认为True,但在我的设置中的某个地方,它没有设置。额外的安全永远不会受到伤害。

要链接到array_likenumpy 站点上的术语,必须intersphinx启用扩展,并且必须链接到 numpy:intersphinx_mappingconf.py

intersphinx_mapping = {
    ...
    'numpy': ('https://numpy.org/doc/stable/', None),
    ...
}
于 2021-02-13T07:25:33.057 回答