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

时间:2014-11-03 19:00:42

标签: python python-sphinx

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

foo.py包含:

import bar


class B():
    a = bar.A

bar.py包含:

class A():
    pass

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

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

.. automodule:: foo
   :members:
   :undoc-members:

现在,当我使用挑剔的旗帜(build html)运行-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.

如何修复此警告?

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

我可以找到我设置的测试项目的副本here

1 个答案:

答案 0 :(得分:1)

在您的代码中

class B():
    a = bar.A

您必须使用实例化而不是类别名。 当我用a = bar.A

替换a = bar.A()时,警告就会消失