生成代码文档时如何消除意外缩进警告的原因?



有问题的文档代码位于方法的开头:

"""
Gtk.EventBox::button-release-event signal handler.
:param widget: The clicked widget (The Gtk.EventBox).
:param event: Gdk.EventButton object with information regarding
the event.
:param user_data: The Gtk.LinkButton that should be opened when
the Gtk.EventBox is clicked.
:return: None
"""

警告是:

C:/msys64/home/hope/python+gtk/test/main.py:docstring of main.Builder.advertisem
ent_clicked:4: WARNING: Unexpected indentation.
C:/msys64/home/hope/python+gtk/test/main.py:docstring of main.Builder.advertisem
ent_clicked:5: WARNING: Block quote ends without a blank line; unexpected uninde
nt.

可以做些什么来删除这些警告及其原因?

只需在方法的摘要描述之后,在参数的描述之前添加一个空行:

"""
Gtk.EventBox::button-release-event signal handler.
:param widget: The clicked widget (The Gtk.EventBox).
:param event: Gdk.EventButton object with information regarding
the event.
:param user_data: The Gtk.LinkButton that should be opened when
the Gtk.EventBox is clicked.
:return: None
"""

在这里你可以找到这个建议:

如果您收到 Sphinx 构建错误,显示"意外缩进",则 可能是因为狮身人面像期待一个空行,比如在 文字文本块。你的台词可能已经包裹并混淆了狮身人面像。在 在这种情况下,尝试将文本拉到上一行,即使它 向外延伸超过窗口的边距。或者,您可以按输入以转到下一行,但请确保缩进新行上的文本。

也许这会帮助偶然发现这个问题的人 - 就我而言,我收到了一堆警告,因为我使用的是Google 风格的文档字符串。只需将"sphinx.ext.napoleon"添加到 conf.py 的extensions列表中,警告就会消失。

您可能还想尝试将sphinx.ext.napoleon放在扩展的最顶部,即

做**这个**

extensions = [
"sphinx.ext.napoleon",
"sphinx.ext.autodoc",
# ...
]

而不是这个

extensions = [
"sphinx.ext.autodoc",
# ...
"sphinx.ext.napoleon",
]

为我工作

您使用的 sphinx/rst 指令要求内容具有单行数据。 若要解决此问题,请在数据之前添加额外的缩进(制表符(,然后可以将数据分成多行而不会出错。

例如,注释指令需要单行内容。

.. note::

single line note expected
this line cause error

然而

.. note::
adding extra indent solves the problem
we can add more lines without error
and so on

最新更新