Sphinx autodoc给出警告:找不到py:class引用目标:键入警告

Dou*_*der 14 python metaclass python-sphinx autodoc

我有一些在python中使用元类的代码.但是当sphinx autodoc运行时,它会给出错误:

WARNING: py:class reference target not found: type

错误发生在自动生成的.rst文件的行中:

.. automodule:: API.list.blockList
    :members: # this is the line in error
    :show-inheritance:
Run Code Online (Sandbox Code Playgroud)

并且blockList扩展了API.list.list,它已\__metaclass__设置为我的元类.

据我所知,sphinx并不认为内置类型类存在.我已经尝试导入内置类型,以使sphinx意识到它在那里,但这没有奏效.

如果我从API.list.list中删除元类赋值,并从代码中删除元类,那么sphinx工作正常.

Igu*_*aut 16

这只是Python文档中的一个错误 - 对某些Python内置函数(包括type)的引用无法正确解析(例如,参见https://bugs.python.org/issue11975).

要使警告消失,您可以将nitpick_ignore选项添加到Sphinx配置中.例如,在Astropy项目中,我们有:

nitpick_ignore = [('py:class', 'type')]
Run Code Online (Sandbox Code Playgroud)

事实上,有足够的例外,我们只是将它们全部放在一个单独的文件中,我们将它们读出来.看到:

https://github.com/astropy/astropy/blob/35501fcba6811705fcd53669742db8346727672d/docs/conf.py#L195

以及异常文件本身:

https://github.com/astropy/astropy/blob/35501fcba6811705fcd53669742db8346727672d/docs/nitpick-exceptions

上述文件中的许多异常特定于Astropy,但其他异常处理Python和Numpy中的一些损坏的引用,并且可能通常有用.