gpt4 book ai didi

python - 狮身人面像 : "WARNING: py:class reference target not found" for class variable

转载 作者:太空狗 更新时间:2023-10-29 21:58:30 26 4
gpt4 key购买 nike

我有两个文件,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:

现在,当我使用挑剔的标志 (-n) 运行 build html 时,我得到以下警告,WARNING: py :未找到类引用目标: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 .

最佳答案

在你的代码中你有

class B():
a = bar.A

您必须使用实例化而不是类别名。当我将 a = bar.A 替换为 a = bar.A()

时,警告就消失了

关于python - 狮身人面像 : "WARNING: py:class reference target not found" for class variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26721133/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com