Skip to content

fix: do not treat a bracketed string literal as an attribute docstring - #364

Open
Sanjays2402 wants to merge 1 commit into
PyCQA:masterfrom
Sanjays2402:fix/nested-string-not-attribute-docstring
Open

fix: do not treat a bracketed string literal as an attribute docstring#364
Sanjays2402 wants to merge 1 commit into
PyCQA:masterfrom
Sanjays2402:fix/nested-string-not-attribute-docstring

Conversation

@Sanjays2402

Copy link
Copy Markdown

Closes #344.

is_attribute_docstring() returned True for any triple-quoted string with an = anywhere before it, so a string passed as a call argument (or placed in a list/dict literal after an assignment) was classified as an attribute docstring and reformatted — collapsing textwrap.dedent("""...""") scripts onto one line. A string nested inside an unclosed bracket is an argument or collection element, never an attribute docstring, so the classifier now rejects it.

Regression test fails without the source change and passes with it; the rest of the suite is unchanged (same 29 pre-existing end-to-end errors before and after).

is_attribute_docstring() returned True for any triple-quoted string that had
an '=' anywhere before it, so a string passed as a call argument or placed in
a list/dict literal after an assignment was classified as an attribute
docstring and reformatted. This corrupted non-docstring literals such as
textwrap.dedent("""..."""), collapsing multi-line scripts onto one line.

A string nested inside an unclosed bracket is an argument or a collection
element, never an attribute docstring, so the classifier now rejects it.

Adds a parametrized regression test covering call, dict and list nesting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docformatter incorrectly reformats non-docstring string literals inside function call arguments

1 participant