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

sil*_*gan 7 restructuredtext python-2.7 python-sphinx msys2 windows-10

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

"""
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
"""
Run Code Online (Sandbox Code Playgroud)

警告是:

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.
Run Code Online (Sandbox Code Playgroud)

如何删除这些警告及其原因?

sil*_*gan 10

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

"""
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
"""
Run Code Online (Sandbox Code Playgroud)

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

如果你得到一个Sphinx构建错误,上面写着"意外的缩进",那可能是因为Sphinx期望一个空行,例如在文字文本块之后.你的线可能已经包裹并混淆了Sphinx.在这种情况下,尝试将文本拉到上一行,即使它延伸到窗口边缘之外.或者,您可以按 Enter键转到下一行,但请务必在新行上缩进文本.


小智 10

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