以下代码使Sphinx自动摘要失败:
@dataclasses.dataclass
class Foo:
bar: int
class FooChild(Foo):
pass我的自动摘要模板(_templates/autosummary/class.rst):
{{ name | escape | underline}}
.. currentmodule:: {{ module }}
.. autoclass:: {{ objname }}
:members:
{% block attributes %}
{% if attributes %}
.. rubric:: {{ _('Attributes') }}
.. autosummary::
{% for item in attributes %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}在运行sphinx-build -j 2 -W -b html docs docs/gh-pages时,我会收到以下警告:
Warning, treated as error:
~/path/docs/generated/module.FooChild.rst:14:autosummary:
failed to import FooChild.bar.我需要将警告视为错误,因为否则我的项目中的文档会很快退化,但我希望修复这个错误的根源,或者忽略这个特定的警告。
我找不到任何方法来忽略来自源代码注释的警告,也无法有选择地禁止来自Sphinx配置的警告。请帮帮我!
编辑:下面是生成的FooChild.rst文件的样子:
FooChild
========
.. currentmodule:: package.module
.. autoclass:: FooChild
:members:
.. rubric:: Attributes
.. autosummary::
~FooChild.bar我有一个将conf.py添加到toctree中的api.rst,api.rst旨在触发自动摘要,为所有模块和类创建文档,在本例中只有module.py。
API Overview
************
.. currentmodule:: package
.. autosummary::
:toctree: generated
:recursive:
module发布于 2022-04-11 10:06:37
虽然它没有解决根本原因,但您需要一种忽略此警告的方法:
您可以将__all__添加到模块中,这不包括FooChild。这样,自动摘要就会忽略它。
来自文档autosummary_ignore_module_all https://www.sphinx-doc.org/en/master/usage/extensions/autosummary.html
如果为False,则模块具有
__all__属性集,自动摘要记录__all__中列出的每个成员,而没有其他成员。缺省值为True,如果导入的成员在__all__中列出,则不管autosummary_imported_members的值如何,它都将被记录下来。若要匹配from模块导入*的行为,请将autosummary_ignore_module_all设置为False,将autosummary_imported_members设置为True。新版本4.4.
https://stackoverflow.com/questions/71825264
复制相似问题