no-blank-line-after-section (D410)
源自 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