如何解决 pydocstyle 错误"D205: 1 blank line required between summary line and description (found 0)"?



我正在尝试使用 pydocstyle 来检查我的文档字符串的质量,但出现此错误:

D205: 1 blank line required between summary line and description (found 0)

这就是我的代码的样子

def func(input):
"""
Function that does something interesting.
Args:
-input- Input of the function
Returns:
output- Output of the function
"""
data = words + sentences
corpus= somefunction(data)

当我在文档字符串和函数语句之间放置一个空行时;

def func(input):
"""
Function that does something interesting.
Args:
-input- Input of the function
Returns:
output- Output of the function
"""
data = words + sentences
corpus= somefunction(data)

我得到这个错误:

D202: No blank lines allowed after function docstring (found 1)

我该如何解决此问题?谢谢你的帮助。

参见 PEP 257 -- 文档字符串约定

def func(input):
"""**summary line, max. 79 chars including period** Do something interesting.
**description starts after blank line above**
Args:
-input- Input of the function
Returns:
output- Output of the function
"""
# no blank line allowed here
data = [words, sentences]
corpus = somefunction(data)

要解决此问题,请在文档字符串的第一行之后添加一个空行。

根据 PEP 257 -- 文档字符串约定,多行文档字符串由摘要行(第一行(组成,就像单行文档字符串一样,后跟一个空行,然后是更详细的描述。摘要行必须适合一行,并用空行与文档字符串的其余部分隔开,这一点很重要。

def func(input):
"""Function that does something interesting.
Args:
- input - Input of the function
Returns:
- output - Output of the function
"""
data = words + sentences
corpus = somefunction(data)

注意

  • 摘要行可以与开始引号在同一行开始,也可以从下一开始,最好是前者。
  • 在开始引号之后或结束引号之前不应有空行

阅读更多...

使 python 脚本同时符合pydocstylepycodestyle是一个挑战。但有一件事非常有帮助,那就是在你的文档字符串中,将第一行写成函数或类的摘要,包括 79 个字符,包括..这样,您可以遵守在不间断行末尾有一个句点的 PEP 257(根据pydocstyle(和 PEP 8 的 79 个字符限制(根据pycodestyle(。

然后在留下一个空行后(因为使用代码编辑器的新行快捷方式比手动按enter更好(,您可以编写任何您想要的内容,然后只关注pycodestyle这比pydocstyle稍微容易一些,主要原因是我们对行和缩进的理解与系统由于缩进设置而理解的完全不同, 选项卡设置,我们使用的各种代码编辑器中的行设置。因此,通过这种方式,您将从pycodestyle中获得可以轻松理解和纠正的TODO,而不是在 1 个空白行的神秘TODO上用头撞墙pydocstyle你看到它在那里,但系统无法识别。

最新更新