缺少章节名称冒号 (D416)
源自 pydocstyle 代码检查器。
修复总是可用的。
作用
检查不以冒号结尾的文档字符串章节标题。
为什么这不好?
此规则对多行 Google 风格文档字符串强制执行一致的样式。如果多行 Google 风格文档字符串由多个章节组成,则每个章节标题都应以冒号结尾。
多行文档字符串通常由摘要行、空行以及一系列章节组成,每个章节都有章节标题和章节正文。
在使用 google
约定配置时,此规则启用;在使用 pep257
和 numpy
约定配置时,此规则禁用。
示例
def calculate_speed(distance: float, time: float) -> float:
"""Calculate speed as distance divided by time.
Args
distance: Distance traveled.
time: Time spent traveling.
Returns
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.
Args:
distance: Distance traveled.
time: Time spent traveling.
Returns:
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