Skip to content

pydocformatter docstring formatting (PDF)

Jump to rule table ↓

What it does

The PDF category contains rules that detect formatting and safety issues in Python docstrings, including suspicious Unicode, wrapping, indentation, whitespace, quote placement, and blank-line layout. Category preparation builds a convention-aware semantic block tree and explicit reflow regions for summaries, paragraphs, section entries, reST fields, lists, and block quotes. Reflow preserves recognized same-line Markdown and reStructuredText constructs as atomic source-aware tokens and retains explicit space or backslash hard breaks between independently wrapped segments.

docstring-convention is explicit and never auto-detected. Google sections, NumPy sections, and reST fields are parsed only under their matching convention. The none and pep257 conventions do not interpret convention syntax. The default pep257 convention applies PEP 257/pydocstyle-compatible broad-rule carve-outs, while none is the stricter no-convention profile for generic rules that can act without convention parsing. Independent docstring-parse-* settings control generic lists, headings, doctests, fences, quotes, tables, directives, and literal blocks.

Considered docstrings

PDF rules consider primary module, class, function, method, and nested-definition docstrings:

"""Module docstring."""


class Client:
    """Class docstring."""

    def close(self):
        """Close the client."""

PDF rules also inventory module attributes, class attributes, and self.<name> instance attributes assigned inside __init__. Adjacent attribute docstrings collected by common documentation tools are treated as documentation attached to those inventory entries. Supported forms include same-line docstrings, next-line docstrings, annotations without values, multi-target assignments, and tuple-unpacked assignments:

module_value = 1
"""Module attribute docstring."""

module_name: str
"""Annotated module attribute docstring."""

first = second = 1
"""Shared docstring for both module attributes."""

primary, (fallback, *aliases) = endpoints
"""Shared docstring for tuple-unpacked module attributes."""


class Client:
    class_value = 1
    """Class attribute docstring."""

    def __init__(self, enabled):
        self.instance_value = 1; """Same-line instance attribute docstring."""  # fmt: skip
        self.instance_primary, _ = values
        """Tuple-unpacked instance attribute docstring."""
        if enabled:
            self.conditional_value = 1
            """Nested instance attribute docstring."""

For classes, the final effective direct class-body __slots__ binding also contributes instance attributes when its value is a string literal or a tuple made entirely of string literals. Implicit string concatenation is supported. Mutable list values are not treated as proven inventory because later mutation or aliasing can change the runtime slot names. Usable identifier names retain literal order and exact decoded spelling without private-name mangling or keyword rejection; duplicates, __dict__, __weakref__, and non-identifier strings are ignored. Every exact class-scope rebinding or deletion is considered in source order, including structural pattern captures. Dynamic values, partially static containers, destructuring targets, and final conditional, compound-statement, captured, or deleted bindings do not contribute slot members; a later direct supported assignment can recover, while an annotation-only declaration does not rebind the previous value. Slots are not inherited into subclass inventories. Slot-only members cannot own adjacent docstrings; any real assignment of the same name supplies normal attachment semantics, and the first real annotation supplies type-comparison facts without changing the first-source order among records eligible under the consumer's instance policy. When instance records are excluded, a later real class declaration of the same name remains eligible and owns the inventory position.

Attribute documentation order uses the complete class inventory with instance records enabled, regardless of the missing-instance-documentation setting. Direct class attributes, the __slots__ binding and its usable literal members, and supported initializer attributes form one first-seen source sequence. Names within supported multi-target assignments retain written left-to-right, depth-first order. Module order uses the corresponding direct module inventory.

PDF rules do not consider additional string literals after a primary docstring, local variable strings outside supported attribute locations, bytes literals, f-strings, list destructuring targets, unsupported tuple leaves, subscript targets, cls.<name> targets, or arbitrary object attributes:

def function():
    """Primary docstring."""
    """Ignored additional string."""

    local_value = 1
    """Ignored local string."""


class Client:
    items[0] = 1
    """Ignored subscript target."""

Why is this useful?

Consistent docstring formatting improves readability and keeps documentation stable across automated formatting runs.

Rules

Rules in this category cover literal and quote normalization, suspicious Unicode, source-level formatting, blank-line layout, placeholder and summary presence, first-line style, convention section and entry style, consistency between docstrings and signatures or attribute inventories, and missing owner docstrings. Reflow rules operate on the semantic regions prepared for the selected convention, while structural rules normalize spacing, conservative type spelling, and section syntax or diagnose high-confidence malformed entry syntax, malformed reStructuredText directive introducers, indentation, and NumPy return-entry shape. Convention normalization owns ASCII spaces and tabs only; non-default whitespace and suspicious controls are preserved or left unchanged for PDF004 and source-preserving rules. Semantic rules validate documented parameters, return values, yields, raised exceptions, optional assertion-derived AssertionError, emitted warnings, methods, attributes, and one-to-one reStructuredText value/type field pairing. Wording rules diagnose generic parameter, attribute, return, yield, exception, warning, and method descriptions using family-specific conservative patterns. Recognized inline markup and accepted interior nonbreaking spaces are indivisible regardless of URL balancing; ambiguous markup and suspicious Unicode that would require payload reconstruction are reported without an unsafe fix. Valid and high-confidence malformed directive blocks are protected from prose reflow when directive parsing is enabled. PDF101 owns hard-break-aware layout, while PDF102 preserves space hard breaks during trailing-whitespace cleanup. Signature-validation rules check the presence, exact variadic spelling, and relative declaration order of parsed parameter documentation; attribute-validation rules can likewise compare value-bearing owner documentation with first-seen module or class inventory order. Partial documentation can be order-checked without requiring omitted names to be added. Summary and entry punctuation rules can insert missing periods, replace safely mapped semicolons and standalone commas with periods when the source mapping is exact, and leave potential structured-content introductions, structural colons, and expressive punctuation unchanged. Google and NumPy method signatures remain opaque, while legacy NumPy name : type and fallback typed Google method entries retain parsed type slots.

Convention profiles choose among antagonistic PDF policies such as zero or one blank line and required or forbidden documented types. Each profile broadly selects at most one rule from an incompatible pair and may select neither. Some rules are therefore ignored by broad selectors for every docstring-convention value while remaining restorable by exact rule-code or rule-name selection. Rules that require parsed convention sections or entries can instead be disabled under none and pep257, where exact selection cannot restore them because there is no parsed target to check. These convention opt-in rules are distinct from globally opt-in rules controlled by require-explicit; the rule list reports convention effects separately and reserves the Require explicit column for that setting.

Individual rule documentation describes relevant Ruff compatibility and differences.

Code ranges

PDF rules are grouped by contiguous hundred ranges so related rules stay close together and future rules have predictable homes.

Range Topic Notes
PDF0xx Literal normalization and safety Docstring literal shape, quote style, value-preserving string spelling, and suspicious Unicode.
PDF1xx Core source formatting Indentation, reflow, whitespace, quote placement, and one-line docstring layout.
PDF2xx Blank lines and basic docstring structure Excess or missing blank lines inside docstrings, blank-line spacing around docstring statements, empty or placeholder docstrings, missing summaries, and ambiguous multiline summaries.
PDF3xx Summary and entry wording style Summary punctuation, imperative mood, signature duplication, capitalization, first-word wording, and conservative generic entry descriptions.
PDF4xx Convention structure Section names, headers, underlines, content, order, entry and directive syntax, entry indentation, NumPy return shape, spacing, punctuation, and conservative type spelling.
PDF5xx Docstring/signature validation Parameter and attribute presence, extraneous names, configured variadic spelling, relative declaration order, and return, yield, exception, or attribute documentation consistency.
PDF6xx Owner docstring presence Package, module, class, nested class, function, method, dunder method, __init__, and decorator-driven function docstring presence.
PDF7xx Entry completeness and type consistency Parsed parameter, return, yield, exception, warning, attribute, and method descriptions, reStructuredText value/type pairing, type presence policies, and conservative annotation/type mismatch checks.

Options

Docstring options below control visible formatting output, missing-documentation policy, decorator policies, and typed class-attribute policy. Convention and parser-selection settings are generally documented in the configuration reference; an individual rule page also lists a parser setting when the settings audit identifies it as a direct rule option or selection dependency, as for PDF418.

Setting Default Effect
line-length 88 Maximum display width for docstring wrapping and one-line docstring checks.
url-aware-wrapping true Balance line selection around destination-bearing tokens; markup atomicity is unconditional.
indent-style space Indentation style used for generated docstring indentation.
indent-width 4 Indentation width and tab display width used by generated docstring formatting.
docstring-blank-line-style blank Choose whether inserted or normalized blank docstring lines are blank or indentation-aligned.
docstring-blank-line-after-last-section false Keep one blank line after the final recognized section when enabled.
docstring-missing-documentation has-section Select when missing parameter, return, yield, exception, and attribute docs are reported.
docstring-missing-documentation-public-only true Limit broad missing documentation checks to public API names when enabled.
docstring-require-init-attribute-documentation false Include supported self.* attributes and literal slot members in class missing-attribute documentation checks.
docstring-include-assertion-errors false Treat syntactic assertions as possible AssertionError occurrences for PDF506 and PDF507.
docstring-class-attribute-no-type-base-classes list Direct class bases whose class attribute entries should not include docstring types.
docstring-forbidden-function-decorators list Report docstrings on functions decorated by configured no-docstring decorators.
docstring-optional-function-decorators list Allow functions decorated by configured decorators to omit docstrings.
docstring-placeholder-markers list Whole-docstring markers reported as unfinished documentation by PDF213.
docstring-property-decorators list Treat functions decorated by configured decorators as properties.

Rules in this category

See rule table column explanations.

Code Name Summary Fix available Enabled Source contexts
PDF000 docstring-literal-normalization Docstring literal should be normalized Usually By default Module and Fragment
PDF001 docstring-quote-style Docstring should use triple double quotes Usually By default Module and Fragment
PDF002 docstring-backslash-raw-prefix Docstring with backslashes should use a raw string prefix Sometimes By default Module and Fragment
PDF003 docstring-ascii-only Docstring source contains non-ASCII characters Usually Requires explicit Module and Fragment
PDF004 docstring-suspicious-unicode Docstring contains suspicious Unicode Sometimes By default Module and Fragment
PDF100 docstring-indentation Docstring line is incorrectly indented Always By default Module and Fragment
PDF101 docstring-reflow Docstring chunk needs reflow Usually By default Module and Fragment
PDF102 docstring-trailing-whitespace Non-empty docstring line has trailing whitespace Always By default Module and Fragment
PDF103 docstring-blank-line-whitespace Blank docstring line has whitespace Always By default Module and Fragment
PDF104 opening-quotes-whitespace Docstring has extra whitespace after opening quotes Always By default Module and Fragment
PDF105 closing-quotes-whitespace Docstring has extra whitespace before closing quotes Always By default Module and Fragment
PDF106 multiline-opening-quotes-same-line Multi-line docstring opening quotes should be on the same line as content Always Convention Module and Fragment
PDF107 multiline-opening-quotes-separate-line Multi-line docstring opening quotes should be on a separate line Always Convention opt-in Module and Fragment
PDF108 multiline-closing-quotes-same-line Multi-line docstring closing quotes should be on the same line as content Always Convention opt-in Module and Fragment
PDF109 multiline-closing-quotes-separate-line Multi-line docstring closing quotes should be on a separate line Always By default Module and Fragment
PDF110 one-line-docstring Docstring with one content line should be one line Always By default Module and Fragment
PDF200 too-many-blank-lines Docstring has too many blank lines Always By default Module and Fragment
PDF201 missing-blank-line Docstring is missing a blank line Always By default Module and Fragment
PDF202 empty-docstring Docstring is empty Never By default Module and Fragment
PDF203 summary-too-long Docstring summary does not fit on one line Never By default Module and Fragment
PDF204 no-blank-line-before-function-docstring Function docstring should have no blank lines before it Always By default Module and Fragment
PDF205 blank-line-before-function-docstring Function docstring should have one blank line before it Always Convention opt-in Module and Fragment
PDF206 no-blank-line-after-function-docstring Function docstring has incorrect blank line spacing after it Always Convention opt-in Module and Fragment
PDF207 blank-line-after-function-docstring Function docstring should have one blank line after it Always Convention opt-in Module and Fragment
PDF208 no-blank-line-before-class-docstring Class docstring should have no blank lines before it Always By default Module and Fragment
PDF209 blank-line-before-class-docstring Class docstring should have one blank line before it Always Convention opt-in Module and Fragment
PDF210 no-blank-line-after-class-docstring Class docstring should have no blank lines after it Always Convention opt-in Module and Fragment
PDF211 blank-line-after-class-docstring Class docstring should have one blank line after it Always By default Module and Fragment
PDF212 missing-summary Docstring is missing a summary Never By default Module and Fragment
PDF213 placeholder-docstring Docstring is a placeholder Never By default Module and Fragment
PDF300 summary-trailing-period Docstring summary should end with a period Sometimes Convention Module and Fragment
PDF301 summary-terminal-punctuation Docstring summary should end with terminal punctuation Sometimes Convention Module and Fragment
PDF302 non-imperative-summary Docstring summary should be in imperative mood Never Convention Module and Fragment
PDF303 signature-like-summary Docstring summary should not include a function signature Never Convention Module and Fragment
PDF304 summary-first-word-capitalization Docstring summary first word should be capitalized Usually By default Module and Fragment
PDF305 summary-starts-with-this Docstring summary should not start with 'This' Never Convention Module and Fragment
PDF306 parameter-documentation-too-generic Parameter documentation is too generic Never Convention Module and Fragment
PDF307 attribute-documentation-too-generic Attribute documentation is too generic Never Convention Module and Fragment
PDF308 entry-description-trailing-period Docstring entry description should end with a period Sometimes Convention Module and Fragment
PDF309 entry-description-terminal-punctuation Docstring entry description should end with terminal punctuation Sometimes Convention Module and Fragment
PDF310 entry-description-first-word-capitalization Docstring entry description first word should be capitalized Usually Convention Module and Fragment
PDF311 property-docstring-starts-with-verb Property docstring should not start with a verb Never By default Module and Fragment
PDF312 entry-description-too-generic Docstring entry description is too generic Never Convention Module and Fragment
PDF400 section-name-capitalization Docstring section or reST field name should use canonical capitalization Usually Convention Module and Fragment
PDF401 section-name-pluralization Docstring section or reST field name should use its preferred singular or plural form Usually Convention Module and Fragment
PDF402 section-name-term-normalization Docstring section or reST field name should use the preferred equivalent term Usually Convention Module and Fragment
PDF403 section-name-trailing-content Docstring section name should be followed by a line break Usually Convention Module and Fragment
PDF404 section-name-trailing-colon Docstring section name should end with a colon Usually Convention Module and Fragment
PDF405 section-underline-format Docstring section underline should be normalized Usually Convention Module and Fragment
PDF406 empty-section Docstring section or reST field should not be empty Never Convention Module and Fragment
PDF407 section-order Docstring sections or reST fields should be in the configured order Never Convention Module and Fragment
PDF408 repeated-section Docstring section or reST field should not be repeated Never Convention Module and Fragment
PDF409 docstring-entry-spacing Docstring convention entry spacing should be normalized Usually Convention Module and Fragment
PDF410 exception-entry-normalization Docstring exception or warning entry should use canonical spelling Usually Convention Module and Fragment
PDF411 type-like-token-spacing-normalization Docstring type-like token spacing should be normalized Usually Convention Module and Fragment
PDF412 repeated-docstring-entry Docstring entry should not be repeated Never Convention Module and Fragment
PDF413 section-name-superfluous-colon Docstring section name should not end with a colon Usually Convention Module and Fragment
PDF414 malformed-convention-entry Docstring convention entry should use valid syntax Sometimes Convention Module and Fragment
PDF415 convention-entry-indentation Docstring convention entry should use valid indentation Usually Convention Module and Fragment
PDF416 type-spelling-normalization Docstring type spelling should be normalized Usually Convention Module and Fragment
PDF417 numpy-return-entry-shape NumPy Returns entries should match single-value or multiple-value structure Never Convention Module and Fragment
PDF418 malformed-rest-directive-introducer reST directive must be followed by two colons Never Setting-gated Module and Fragment
PDF500 missing-parameter-documentation Function parameter is missing docstring documentation Never Convention Module and Fragment
PDF501 extraneous-parameter-documentation Docstring documents a parameter that is not in the function signature Never Convention Module and Fragment
PDF502 missing-return-documentation Function return value is missing docstring documentation Never Convention Module and Fragment
PDF503 extraneous-return-documentation Docstring has return documentation for a function that does not return Never Convention Module and Fragment
PDF504 missing-yield-documentation Function yield value is missing docstring documentation Never Convention Module and Fragment
PDF505 extraneous-yield-documentation Docstring has yield documentation for a function that does not yield a meaningful value Never Convention Module and Fragment
PDF506 missing-exception-documentation Raised exception is missing docstring documentation Never Convention Module and Fragment
PDF507 extraneous-exception-documentation Docstring documents an exception that is not explicitly raised Never Convention opt-in Module and Fragment
PDF508 missing-public-class-attribute-documentation Public class attribute is missing docstring documentation Never Convention Module and Fragment
PDF509 extraneous-class-attribute-documentation Class docstring documents an attribute that is not present Never Convention Module and Fragment
PDF510 missing-public-module-attribute-documentation Public module attribute is missing docstring documentation Never Convention opt-in Module
PDF511 extraneous-module-attribute-documentation Module docstring documents an attribute that is not present Never Convention Module
PDF512 duplicate-class-attribute-documentation Attached attribute docstring duplicates class docstring attribute documentation Never Convention Module and Fragment
PDF513 duplicate-module-attribute-documentation Attached attribute docstring duplicates module docstring attribute documentation Never Convention Module
PDF514 private-class-attribute-owner-docstring-forbidden Class docstring documents a private attribute Never Convention Module and Fragment
PDF515 private-module-attribute-owner-docstring-forbidden Module docstring documents a private attribute Never Convention Module
PDF516 private-class-attribute-attached-docstring-forbidden Private class attribute should not have an attached docstring Never Requires explicit Module and Fragment
PDF517 private-module-attribute-attached-docstring-forbidden Private module attribute should not have an attached docstring Never Requires explicit Module
PDF518 public-class-attribute-docstring-must-be-owner Public class attribute must use class docstring documentation, not attached docstring Never Requires explicit Module and Fragment
PDF519 public-class-attribute-docstring-must-be-attached Public class attribute must use attached docstring, not class docstring documentation Never Requires explicit Module and Fragment
PDF520 public-module-attribute-docstring-must-be-owner Public module attribute must use module docstring documentation, not attached docstring Never Requires explicit Module
PDF521 public-module-attribute-docstring-must-be-attached Public module attribute must use attached docstring, not module docstring documentation Never Requires explicit Module
PDF522 private-class-attribute-docstring-must-be-owner Private class attribute must use class docstring documentation, not attached docstring Never Requires explicit Module and Fragment
PDF523 private-class-attribute-docstring-must-be-attached Private class attribute must use attached docstring, not class docstring documentation Never Convention opt-in Module and Fragment
PDF524 private-module-attribute-docstring-must-be-owner Private module attribute must use module docstring documentation, not attached docstring Never Requires explicit Module
PDF525 private-module-attribute-docstring-must-be-attached Private module attribute must use attached docstring, not module docstring documentation Never Convention opt-in Module
PDF526 parameter-documentation-order Docstring parameters are not in function signature order Never Convention Module and Fragment
PDF527 parameter-variadic-marker-style Docstring parameter variadic markers do not use the canonical spelling Usually Convention Module and Fragment
PDF528 class-attribute-documentation-order Class docstring attributes are not in declaration order Never Convention opt-in Module and Fragment
PDF529 module-attribute-documentation-order Module docstring attributes are not in declaration order Never Convention opt-in Module
PDF600 missing-public-package-documentation Public package is missing docstring Never By default Module
PDF601 missing-private-package-documentation Private package is missing docstring Never Requires explicit Module
PDF602 missing-public-module-documentation Public module is missing docstring Never By default Module
PDF603 missing-private-module-documentation Private module is missing docstring Never Requires explicit Module
PDF604 missing-public-class-documentation Public class is missing docstring Never By default Module
PDF605 missing-private-class-documentation Private class is missing docstring Never Requires explicit Module
PDF606 missing-public-nested-class-documentation Public nested class is missing docstring Never By default Module
PDF607 missing-private-nested-class-documentation Private nested class is missing docstring Never Requires explicit Module
PDF608 missing-public-function-documentation Public function is missing docstring Never By default Module
PDF609 missing-private-function-documentation Private function is missing docstring Never Requires explicit Module
PDF610 missing-public-method-documentation Public method is missing docstring Never By default Module
PDF611 missing-private-method-documentation Private method is missing docstring Never Requires explicit Module
PDF612 missing-public-dunder-method-documentation Public dunder method is missing docstring Never Requires explicit Module
PDF613 missing-private-dunder-method-documentation Private dunder method is missing docstring Never Requires explicit Module
PDF614 missing-public-init-documentation Public init method is missing docstring Never By default Module
PDF615 missing-private-init-documentation Private init method is missing docstring Never Requires explicit Module
PDF616 forbidden-function-docstring Function decorated with forbidden decorator should not have a docstring Never By default Module and Fragment
PDF700 parameter-missing-description Function parameter docstring entry is missing a description Never Convention Module and Fragment
PDF701 parameter-type-required Function parameter docstring entry is missing a type Sometimes Convention opt-in Module and Fragment
PDF702 parameter-type-forbidden Function parameter docstring entry should not include a type Never Convention opt-in Module and Fragment
PDF703 parameter-type-mismatch Function parameter docstring type does not match the annotation Never Convention Module and Fragment
PDF704 return-missing-description Function return docstring entry is missing a description Never Convention Module and Fragment
PDF705 return-type-required Function return docstring entry is missing a type Sometimes Convention opt-in Module and Fragment
PDF706 return-type-forbidden Function return docstring entry should not include a type Never Convention opt-in Module and Fragment
PDF707 return-type-mismatch Function return docstring type does not match the annotation Never Convention Module and Fragment
PDF708 yield-missing-description Function yield docstring entry is missing a description Never Convention Module and Fragment
PDF709 yield-type-required Function yield docstring entry is missing a type Sometimes Convention opt-in Module and Fragment
PDF710 yield-type-forbidden Function yield docstring entry should not include a type Never Convention opt-in Module and Fragment
PDF711 yield-type-mismatch Function yield docstring type does not match the annotation Never Convention Module and Fragment
PDF712 class-attribute-missing-description Class attribute docstring entry is missing a description Never Convention Module and Fragment
PDF713 class-attribute-type-required Class attribute docstring entry is missing a type Sometimes Convention opt-in Module and Fragment
PDF714 class-attribute-type-forbidden Class attribute docstring entry should not include a type Never Convention opt-in Module and Fragment
PDF715 class-attribute-type-mismatch Class attribute docstring type does not match the annotation Never Convention Module and Fragment
PDF716 module-attribute-missing-description Module attribute docstring entry is missing a description Never Convention Module and Fragment
PDF717 module-attribute-type-required Module attribute docstring entry is missing a type Sometimes Convention opt-in Module and Fragment
PDF718 module-attribute-type-forbidden Module attribute docstring entry should not include a type Never Convention opt-in Module and Fragment
PDF719 module-attribute-type-mismatch Module attribute docstring type does not match the annotation Never Convention Module and Fragment
PDF720 exception-missing-description Exception docstring entry is missing a description Never Convention Module and Fragment
PDF721 warning-missing-description Warning docstring entry is missing a description Never Convention Module and Fragment
PDF722 orphan-rest-type-field reST type field has no corresponding value field Never Convention Module and Fragment
PDF723 method-missing-description Method docstring entry is missing a description Never Convention Module and Fragment

← Back to all rules