Disallow single-line implicit concatenated strings#13928
Merged
MichaReiser merged 1 commit intomainfrom Nov 3, 2024
Merged
Conversation
MichaReiser
commented
Oct 25, 2024
...ormatter/tests/snapshots/black_compatibility@cases__preview_long_strings__regression.py.snap
Outdated
Show resolved
Hide resolved
Contributor
|
d9bec17 to
ba5d612
Compare
ba5d612 to
08de539
Compare
charliermarsh
approved these changes
Nov 2, 2024
Member
charliermarsh
left a comment
There was a problem hiding this comment.
I think this is a smart change. We should document it in the Black deviations though.
Member
Author
Thanks for the feedback. I plan to document the deviations as part of promoting the new style guide. |
MichaReiser
added a commit
that referenced
this pull request
Dec 23, 2024
## Summary This is a bug fix for #13928 We failed to preserve multiline implicit concatenated strings that can't be automatically joined in docstring positions: ```py def test(): ( r"This is a docstring" "and Ruff can't automatically join it" ) ``` ## Test plan Added formatter tests
MichaReiser
added a commit
that referenced
this pull request
Dec 23, 2024
## Summary This is a bug fix for #13928 We failed to preserve multiline implicit concatenated strings that can't be automatically joined in docstring positions: ```py def test(): ( r"This is a docstring" "and Ruff can't automatically join it" ) ``` ## Test plan Added formatter tests
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
Fixes #8272
The formatter is incompatible with
ISC001because it can introduce new single-line implicit concatenated strings if all parts fit on the line. The new implicit concatenated string formatting style already addresses this incompatibility for regular strings and most f-string but not for triple quoted strings and raw strings.This PR proposes to change the formatter style to never collapse the parts of an implicit concatenated string onto a single line unless it has been formatted on a single line by the author.
Is preserved as is because the author wrote the implicit concatenated string on a single line and it fits. The source i already incompatible with ISC001.
The current style collapses this string to match the example above. The style proposed in this PR preserves the multiline formatting in this case because there's a line break between the two parts.
Preview gating
It's technically not required to gate this change behind preview because it doesn't change the formatting of any existing code. But it fits nicely into the other implicit concatenated work that we've been doing and the new implicit concatenated string formatting also largely mitigates that this leads to slightly less consistent formatting (because it's up to the author whether the string remains multiline or not)
Test Plan
Added tests