跳到内容

empty-docstring-section (D414)

源自 pydocstyle 代码检查器。

作用

检查具有空节的文档字符串。

为什么这不好?

多行文档字符串中的空节可能表示未完成或不完整的文档字符串。

多行文档字符串通常由摘要行、空白行和一系列节组成,每个节都有一个节标题和一个节正文。每个节正文应为非空;空节应添加内容或完全删除。

示例

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
    ------
    """
    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

参考