Sphinx:类警告:"警告:找不到py:类引用目标"

Cea*_*sta 7 python python-sphinx

我有两个文件,foo.pybar.py.

foo.py 包含:

import bar


class B():
    a = bar.A
Run Code Online (Sandbox Code Playgroud)

bar.py 包含:

class A():
    pass
Run Code Online (Sandbox Code Playgroud)

我正在docs/index.rst通过以下方式生成这些文档:

.. automodule:: bar
   :members:
   :undoc-members:

.. automodule:: foo
   :members:
   :undoc-members:
Run Code Online (Sandbox Code Playgroud)

现在,当我build html使用nit-picky flag(-n)运行时,我得到以下内容,并发出警告WARNING: py:class reference target not found: A:

(env)bash-3.2$ make html
sphinx-build -b html -d _build/doctrees  -n . _build/html
Running Sphinx v1.2.3
loading pickled environment... done
building [html]: targets for 1 source files that are out of date
updating environment: 0 added, 1 changed, 0 removed
reading sources... [100%] index
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index
/Users/caesarbautista/Desktop/test_docs/docs/index.rst:12: WARNING: py:class reference target not found: A
writing additional files... genindex py-modindex search
copying static files... done
copying extra files... done
dumping search index... done
dumping object inventory... done
build succeeded, 1 warning.

Build finished. The HTML pages are in _build/html.
Run Code Online (Sandbox Code Playgroud)

我该如何修复此警告?

到目前为止,我已经尝试搜索谷歌和文档没有运气.它也与A导入方式无关.我试过from bar import A没有成功.错误消息非常不透明.

我可以在这里找到我设置的测试项目的副本.

nin*_*701 1

在你的代码中你有

class B():
    a = bar.A
Run Code Online (Sandbox Code Playgroud)

您必须使用实例化而不是类别名。a = bar.A当我替换为时警告就消失了a = bar.A()

  • 我不认为这是要走的路。`a = bar.A` 和 `a = bar.A()` 都是完全有效的 Python 语句,可以包含在代码中,具有不同的含义,并且您不必从一个更改为另一个让文档发挥作用,因为它会影响程序的功能。(这当然有可能是一个错字,但这与所提出的问题是分开的。) (2认同)