Ruff no-blank-line-before-section (D411)
no-blank-line-before-section в Ruff проверяет код на предупреждение D411. Правило относится к группе pydocstyle.
Почему это неправильно
Docstring помогает понять публичный интерфейс и должна быть оформлена так, чтобы её корректно читали люди и инструменты.
Если валидатор показывает это предупреждение, исправьте место, на которое указывает Ruff, ориентируясь на смысл правила no-blank-line-before-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 всегда может предложить автоисправление для этого правила.
