多行摘要首行 (D212)
源自 pydocstyle 代码检查器。
修复总是可用的。
作用
检查文档字符串摘要行是否位于文档字符串的第一个物理行。
为什么这不好?
PEP 257 建议多行文档字符串应包含“一个摘要行,就像单行文档字符串一样,后跟一个空行,然后是更详细的描述。”
摘要行应位于文档字符串的第一个物理行上,紧跟在起始引号之后。
此规则可能不适用于所有项目;其适用性是一个约定问题。 默认情况下,在使用 google
约定时启用此规则,而在使用 numpy
和 pep257
约定时禁用此规则。
有关替代方案,请参阅 D213。
示例
def sort_list(l: list[int]) -> list[int]:
"""
Return a sorted copy of the list.
Sort the list in ascending order and return a copy of the result using the
bubble sort algorithm.
"""
建议改为
def sort_list(l: list[int]) -> list[int]:
"""Return a sorted copy of the list.
Sort the list in ascending order and return a copy of the result using the bubble
sort algorithm.
"""