跳到内容

非大写部分名称 (D405)

源自 pydocstyle 代码检查器。

修复总是可用的。

作用

检查文档字符串中的节标题是否未以大写字母开头。

为什么这不好?

为了风格一致,文档字符串中的所有节标题都应大写。

多行文档字符串通常由摘要行、一个空行以及一系列节组成。每个节通常都有一个标题和一个正文。

当使用 numpygoogle 约定启用此规则,当使用 pep257 约定禁用此规则。

示例

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

Options (选项)

参考