Ruff missing-dashed-underline-after-section (D407)

missing-dashed-underline-after-section в Ruff проверяет код на предупреждение D407. Правило относится к группе pydocstyle.

Почему это неправильно

Docstring помогает понять публичный интерфейс и должна быть оформлена так, чтобы её корректно читали люди и инструменты.

Если валидатор показывает это предупреждение, исправьте место, на которое указывает Ruff, ориентируясь на смысл правила missing-dashed-underline-after-section и пример ниже.

Пример ошибки

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

Автоисправление

Ruff всегда может предложить автоисправление для этого правила.