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

Python 2.7 如何在生成代码文档时消除意外缩进警告的原因?,python-2.7,windows-10,python-sphinx,restructuredtext,msys2,Python 2.7,Windows 10,Python Sphinx,Restructuredtext,Msys2,出现问题的文档代码位于方法的开头: """ 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

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

"""
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构建错误,上面写着“意外缩进”,它会 可能是因为斯芬克斯希望有一个空行,比如在 文字文本块。你的台词可能把斯芬克斯弄糊涂了。在里面 在这种情况下,尝试将文本向上拉到前一行,即使它 延伸超过窗口的边缘。或者,你可以按一下 输入转到下一行,但确保在新行缩进文本


也许这会帮助那些偶然发现这个问题的人——在我的例子中,我收到了一堆警告,因为我使用的是谷歌风格的docstrings。只需将“sphinx.ext.poleon”添加到conf.py中的
扩展
列表中,警告就会消失。

您可能还需要尝试将
sphinx.ext.poleon
放在扩展的最顶端,即

做这个**

extensions = [
    "sphinx.ext.napoleon",
    "sphinx.ext.autodoc",
    # ...
]
而不是这个

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

为我工作

谢谢你,杰瑞。