Fix: In src/docformatter/classify.py, is_attribute_docstring() previously... - #375
Open
M001N wants to merge 2 commits into
Open
Fix: In src/docformatter/classify.py, is_attribute_docstring() previously...#375M001N wants to merge 2 commits into
M001N wants to merge 2 commits into
Conversation
added 2 commits
August 16, 2026 16:37
…n parens misclassified as docstring)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
No production code change was needed: the fix for this exact defect (bracket-depth check in is_attribute_docstring/_is_inside_brackets) is already present in this worktree's history via PR #364. I added a dedicated regression test reproducing issue #366's exact snippet to tests/_data/string_files/do_format_code.toml (case issue_366_triple_quote_in_parens_not_docstring, source==expected, i.e. unchanged) and wired it into the existing parametrized test in tests/formatter/test_do_format_code.py, following that file's established pattern (TOML-backed source/expected pairs, one entry per issue).
Problem
PyCQA/docformatter issue reference: #366
Root Cause
In src/docformatter/classify.py, is_attribute_docstring() previously treated any triple-quoted string preceded by an '=' as an attribute docstring even when the string sits inside an unclosed bracket (e.g. a parenthesized concatenation), causing docformatter to reformat its literal contents. This was already fixed upstream in commit e8901bc 'fix: do not treat a bracketed string literal as an attribute docstring (#364)', which added the
_is_inside_brackets()guard (classify.py lines 202-204, 207-232) that this worktree's HEAD already includes (it is an ancestor of the current branch tip). Reproducing the issue's exact snippet against the current code shows the output is byte-identical to the input -- the bug does not manifest here.Testing
PASS -- 73 passed, 1 deselected (the pre-existing unrelated preserve_line_ending failure, excluded per instructions); the new issue_366 case passes, confirming the string is left byte-identical.
Related Issue
#366