跳到内容

missing-blank-line-after-last-section (D413) | 缺少末节后的空行 (D413)

源自 pydocstyle 代码检查器。

修复总是可用的。

作用

Checks for missing blank lines after the last section of a multiline docstring. | 检查多行文档字符串的末节后是否缺少空行。

为什么这不好?

This rule enforces a consistent style for multiline docstrings. | 此规则强制多行文档字符串采用一致的风格。

Multiline docstrings are typically composed of a summary line, followed by a blank line, followed by a series of sections, each with a section header and a section body. | 多行文档字符串通常由摘要行、空行以及一系列节组成,每个节都有一个节标题和一个节正文。

This rule may not apply to all projects; its applicability is a matter of convention. By default, the rule is disabled when using the google, numpy, and pep257 conventions. | 此规则可能不适用于所有项目;其适用性是一个约定问题。默认情况下,在使用 googlenumpypep257 约定的时候,该规则会被禁用。

示例

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

Options (选项)

参考