Repository navigation
fix: preserve escaped newlines inside ordinary strings - #407
Merged
weibullguy merged 2 commits intoNov 2, 2026
Merged
Conversation
Dodothereal
marked this pull request as ready for review
October 30, 2026 09:32
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
Prevent an escaped physical newline inside a quoted string from being mistaken for a backslash continuation between tokens.
On current master, even a file without docstrings can be corrupted:
Formatting duplicates the opening
print(and produces invalid Python. Assignments can become duplicated chained assignments, with more copies added on every pass.Use the existing original-row comparison to distinguish a string starting on the previous token's row from a genuine inter-token continuation. Existing explicit-continuation behavior is retained.
Add 52 regression cases covering ordinary quote styles, raw/bytes/Unicode prefixes, calls and returns, repeated continuations, concatenation, missing final newlines, parenthesized strings, shifted rows after docstring formatting, LF/CRLF, and default/
--blackmodes. They check exact output, AST equivalence, and second-pass idempotence.This was found during source inspection and synthetic testing, not from a production incident. It is distinct from #406's docstring-classification guard and from the already merged #378/#387 fixes.
Validation
Against upstream
82069d7f1e105bd86c69fd9ae0587ca00da3c312, on Linux / CPython 3.12.14:The complete tox/pre-commit aggregate and other interpreters/platforms' full test suites were not run locally. All seven hosted checks pass for
b65883028ffa171b8f35a001993d177d16a04598.AI assistance
Prepared with OpenAI Codex assistance for diagnosis, implementation, tests, and this description. A separate Codex agent independently reviewed and tested the exact final patch, with no actionable findings. The additional review was automated.