blank-line-before-class-docstring (PDF209)¶
PDF208 no-blank-line-before-class-docstring
Next rule →PDF210 no-blank-line-after-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 PDF208.
What it does¶
PDF209 requires exactly one blank line immediately before class docstrings.
Only the adjacent blank-line run before the docstring statement is changed. Comments, decorators, class headers, and non-blank lines before the docstring are preserved. The rule applies only to primary class docstrings. It does not apply to function docstrings, attribute docstrings, or simple-suite class docstrings written on the same physical line as the class header.
Why is this useful?¶
This supports the class-docstring spacing style used by projects that prefer one blank line between the class header or leading body comments and the docstring.
Ruff compatibility¶
This rule replaces Ruff's D203. Like Ruff, it is incompatible with the no-blank-line-before-class-docstring style.
Examples¶
The canonical fix inserts one blank line before a class docstring:
class Client:
"""Docstring."""
value = 1
class Client:
"""Docstring."""
value = 1
Excess blank lines are collapsed to one, and leading comments stay attached above the separator:
class Client:
# Leading comment.
"""Docstring."""
value = 1
class Client:
# Leading comment.
"""Docstring."""
value = 1
Decorated classes are handled the same way:
@decorator
class Client:
"""Docstring."""
value = 1
@decorator
class Client:
"""Docstring."""
value = 1
Function docstrings are ignored:
def function():
"""Docstring."""
return None
Options¶
None.
PDF208 no-blank-line-before-class-docstring
Next rule →PDF210 no-blank-line-after-class-docstring