no-blank-line-before-section (D411)
源自 pydocstyle 代码检查器。
修复总是可用的。
作用
检查文档字符串的各个部分是否没有用空行分隔。
为什么这不好?
此规则强制 numpy 风格和 Google 风格的文档字符串保持一致,并有助于确保与文档工具的兼容性。
多行文档字符串通常由摘要行、一个空行以及一系列部分组成,每个部分都有一个节标题和一个节正文。各部分应由单个空行分隔。
当使用 numpy
和 google
约定启用此规则,当使用 pep257
约定禁用此规则。
示例
def calculate_speed(distance: float, time: float) -> float:
"""Calculate speed as distance divided by time.
Parameters
----------
distance : float
Distance traveled.
time : float
Time spent traveling.
Returns
-------
float
Speed as distance divided by time.
Raises
------
FasterThanLightError
If speed is greater than the speed of light.
"""
try:
return distance / time
except ZeroDivisionError as exc:
raise FasterThanLightError from exc
建议改为
def calculate_speed(distance: float, time: float) -> float:
"""Calculate speed as distance divided by time.
Parameters
----------
distance : float
Distance traveled.
time : float
Time spent traveling.
Returns
-------
float
Speed as distance divided by time.
Raises
------
FasterThanLightError
If speed is greater than the speed of light.
"""
try:
return distance / time
except ZeroDivisionError as exc:
raise FasterThanLightError from exc