docstring-wrap
DocsWraps multi-line docstring bodies at the configured measure.
Python takes any string literal standing first in a module, class, or function as its docstring, whatever quotes surround it, and
canonicalizes every one to the""" form because the quotes are the docstring's frame. A '''-delimited docstring, a plain '...' or "...", and an already-""" docstring all settle on the same triple-double-quote delimiter, a raw r prefix kept verbatim on the opener since PEP 257 sanctions r""" for a docstring carrying a backslash.For a multi-line docstring the rule also lands the opening """ flush with the docstring indent on its own line and drops the closing """ to its own line beneath the last content line, leaving the prose body untouched between them. It runs ahead of
The walker Docstring reads against the PEP 257 definition, so an f-string docstring (f"""..."""), a bytes literal (b"""..."""), and concatenated string forms are excluded by construction, Python assigning none of them a __doc__. When re-delimiting to """ would break the string, wherein the body already holds a """ run or a single-line body ends in ", the rule keeps the original quotes rather than corrupt it.
| Key | Type | Default | Meaning |
|---|---|---|---|
enabled | bool | true | Toggles the rule on or off. |
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.
def greet():
"""
Summary line starts inline with the opener.
Trailing line sits at the docstring's indent.
"""
return 1
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.
A raw-prefixed docstring keeps its r prefix through the requote, landing as r"""...""". PEP 257 sanctions the raw prefix for a docstring carrying a backslash, so the prefix stays verbatim on the opener.
A docstring written in single quotes re-delimits to the canonical """ form. The quote style is the frame, so the rule recognizes a docstring by its position and emits """ whatever quotes the source carried.
A triple-single-quoted docstring converts to the canonical triple-double-quote form PEP 257 sanctions. Its body and framing stay put, leaving the delimiters as the only change.
A docstring whose body already holds a """ run keeps its original quotes, because re-delimiting to """ would abut the closer and break the string. The safe fallback leaves this rare shape untouched.
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.
Wraps multi-line docstring bodies at the configured measure.
Expands a one-line docstring into the multi-line block shape.
For the docstring budgets that govern wrapping, the Configuration chapter covers the description and structured line lengths.