我有两个文件,foo.py
和bar.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:
现在,当我使用nit pick标志(-n
)运行build html
时,我会得到以下内容,并发出警告: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.
如何修复此警告?
到目前为止,我已经尝试过在谷歌和文档中搜索,但没有成功。它也与如何导入A
无关。我试过from bar import A
,但没有成功。错误消息非常不透明。
我设置的测试项目的副本可以在这里找到。
在您的代码中,您有
class B():
a = bar.A
您必须使用实例化而不是类别名。当我用a = bar.A()
替换a = bar.A
时,警告刚刚消失