no-blank-line-before-class-docstring (PDF208)¶
PDF207 blank-line-after-function-docstring
Next rule →PDF209 blank-line-before-class-docstring
Part of the PDF rule category.
View source · View documentation source · Search issues
Fix is always available.
Rule is incompatible with PDF209.
What it does¶
PDF208 removes blank lines 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?¶
Keeping a class docstring directly attached to the class body follows Ruff's default class-docstring spacing convention.
Ruff compatibility¶
This rule replaces Ruff's D211.
Examples¶
The canonical fix removes blank lines before a class docstring:
class Client:
"""Docstring."""
value = 1
class Client:
"""Docstring."""
value = 1
Comments are preserved; only the adjacent blank-line run before the docstring is removed:
class Client:
# Leading comment.
"""Docstring."""
value = 1
class Client:
# Leading comment.
"""Docstring."""
value = 1
Function docstrings and attribute docstrings are ignored:
class Client:
value = 1
"""Attribute docstring."""
def function():
"""Function docstring."""
return None
Options¶
None.
PDF207 blank-line-after-function-docstring
Next rule →PDF209 blank-line-before-class-docstring