跳到内容

header 和 content 之间的空行 (D412)

源自 pydocstyle 代码检查器。

修复总是可用的。

作用

检查文档字符串部分是否在节标题和节内容之间包含空行。

为什么这不好?

此规则强制多行文档字符串使用一致的样式。

多行文档字符串通常由摘要行组成,后跟一个空行,然后是一系列节,每个节都有一个节标题和一个节内容。节标题和节内容之间不应有空行。

示例

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

参考