section-not-over-indented (D214)#
Derived from the pydocstyle linter.
Fix is always available.
What it does#
Checks for over-indented sections in docstrings.
Why is this bad?#
Multi-line 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.
Each section should use consistent indentation, with the section headers matching the indentation of the docstring's opening quotes, and the section bodies being indented one level further.
Example#
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
Use instead:
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