Skip to content

docstring-frame โ€‹

A multi-line docstring whose opener or closer shares a line with the body reads as a fragment, with the prose flowing into the triple-quotes rather than sitting between them as a self-contained block.

lands the opening """ flush with the docstring indent on its own line, drops the closing """ to its own line beneath the last content line, and leaves the prose body untouched between them.

The rule fires on every multi-line docstring across module, class, and function scopes. Single-line docstrings (opener, body, and closer all on one line) are left alone for

to handle. Pair with for the description-prose wrap that runs after this rule canonicalizes the opener and closer.

The walker Docstring reads against the PEP 257 definition, so f-string docstrings (f"""...""") and concatenated string forms are excluded by construction. Raw-prefixed (r""") and byte-prefixed (b""") literals canonicalize the same way as plain triple-quoted forms, with the prefix preserved verbatim on the opener. An empty docstring ("""""") lands as an empty multi-line shape, leaving the opener and closer on their own lines with a blank line between them.

Configuration โ€‹

KeyTypeDefaultMeaning
enabledbooltrueToggle the rule on or off

The Canonical Case โ€‹

An already-multi-line docstring whose opener shares its line with the first body sentence drops that body to a new line beneath the opener, leaving the prose between the delimiters untouched.

python
def greet():
    """
    Summary line starts inline with the opener.
    Trailing line sits at the docstring's indent.
    """
    return 1

More Examples โ€‹

When the closing """ shares a line with the final body line, the closer drops to the next line at the docstring's indent. The body content above it is left untouched.

No Change

A multi-line docstring whose opening and closing """ each already sit on their own line is left unchanged. The rule fires only when one of the two boundaries shares a line with body content, so this shape is a noop.

For the docstring budgets that govern wrapping, the Configuration chapter covers the description and structured line lengths.