Sphinx 自动摘要:数据类继承
以下代码使Sphinx AutoSummary失败:
@dataclasses.dataclass
class Foo:
bar: int
class FooChild(Foo):
pass
我的autosummary模板( _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/gh docs/gh pogs docs/gh pages
Warning, treated as error:
~/path/docs/generated/module.FooChild.rst:14:autosummary:
failed to import FooChild.bar.
我需要将警告视为错误,因为否则我的项目中的文档会很快降级,但是我想修复此根本原因或忽略此特定的警告。
我找不到任何方法可以忽略源代码注释中的警告,也不能选择性地抑制狮身人面像配置中的警告。请帮忙!
编辑:
这是生成的 foochild.rst
文件看起来像:
FooChild
========
.. currentmodule:: package.module
.. autoclass:: FooChild
:members:
.. rubric:: Attributes
.. autosummary::
~FooChild.bar
我有一个 conf.py
将 api.rst
添加到toctree, api。 RST
旨在触发自室以创建所有模块和类创建文档,在此示例中,只有 module.py.py
。
API Overview
************
.. currentmodule:: package
.. autosummary::
:toctree: generated
:recursive:
module
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然它没有修复根本原因,但是您要求一种忽略此警告的方法:
您可以在模块中添加
__所有__
,但不包括foochild
。这样,AutoSummary将忽略它。来自文档
autosummary_ignore_module_all
:While it doesn't fix the root cause, but you asked for a way to ignore this warning:
You could add
__all__
to your module, that doesn't includeFooChild
. This way it will be ignored by autosummary.From documentation
autosummary_ignore_module_all
https://www.sphinx-doc.org/en/master/usage/extensions/autosummary.html: