blank-line-after-function-docstring (PDF207)¶
PDF206 no-blank-line-after-function-docstring
Next rule →PDF208 no-blank-line-before-class-docstring
Part of the PDF rule category.
View source · View documentation source · Search issues
Fix is always available.
Rule is ignored by broad selectors for all docstring-convention values.
Rule is incompatible with PDF206.
What it does¶
PDF207 requires exactly one blank line immediately after function, method, and nested-function docstrings when another statement follows in the same function body.
Only the adjacent blank-line run after the docstring statement is changed. Comments and following statements are preserved. The rule applies to ordinary functions, async functions, methods, and nested functions. It does not apply to class docstrings, attribute docstrings, simple-suite docstrings, or function bodies where the docstring is not followed by another body statement.
Why is this useful?¶
Some projects prefer visually separating function docstrings from executable body statements.
Ruff compatibility¶
This is the style-opposite companion to PDF206, which replaces Ruff's D202.
Examples¶
The canonical fix inserts one blank line after a function docstring:
def function():
"""Docstring."""
return None
def function():
"""Docstring."""
return None
Excess blank lines are collapsed to one. For multiline docstrings, the blank line is placed after the closing quote line:
def function():
"""Summary.
Body.
"""
return None
def other():
"""Docstring."""
return None
def function():
"""Summary.
Body.
"""
return None
def other():
"""Docstring."""
return None
A following comment is treated as the next body statement, so the blank line is inserted before that comment:
def function():
"""Docstring."""
# Body comment.
return None
def function():
"""Docstring."""
# Body comment.
return None
Docstrings without a following body statement and simple-suite docstrings are ignored:
def function():
"""Docstring."""
# Body comment.
def simple(): """Docstring."""; return None
Options¶
None.
PDF206 no-blank-line-after-function-docstring
Next rule →PDF208 no-blank-line-before-class-docstring