Allow parenthesized content exceed configured line width#7490
Merged
MichaReiser merged 2 commits intomainfrom Sep 20, 2023
Merged
Allow parenthesized content exceed configured line width#7490MichaReiser merged 2 commits intomainfrom
MichaReiser merged 2 commits intomainfrom
Conversation
Member
Author
|
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
4745612 to
cf7cd83
Compare
CodSpeed Performance ReportMerging #7490 will not alter performanceComparing Summary
|
cf7cd83 to
eea0824
Compare
MichaReiser
commented
Sep 19, 2023
| // Measure in fully expanded mode and allow overflows | ||
| self.stack.push( | ||
| TagKind::FitsExpanded, | ||
| args.with_measure_mode(MeasureMode::AllLinesAllowTextOverflow) |
Member
Author
There was a problem hiding this comment.
This is the main change. Adding a match on args.mode() is mainly to align it with how other group-like IR elements get formatted and avoids extra work in PrintMode::Expanded
MichaReiser
commented
Sep 19, 2023
| // It's not necessary to wrap the content if it is not inside of an optional_parentheses group. | ||
| write!(f, [inner]) | ||
| } | ||
| write!(f, [token(self.left), inner, token(self.right)]) |
Member
Author
There was a problem hiding this comment.
We need to move the parentheses out because we want the group outer group to break if the opening or closing parentheses don't fit on the line.
1d593e1 to
86bc539
Compare
konstin
approved these changes
Sep 19, 2023
Comment on lines
+399
to
+403
| if True: | ||
| if True: | ||
| if True: | ||
| if True: | ||
| msg += " " + _( |
Member
There was a problem hiding this comment.
i'd flatten this and expand the lines instead
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
This PR changes the formatting for all
parenthesizedexpressions to exceed the configured line width without breaking the enclosing expression. This is only relevant for the optional parentheses (can_omit_optional_parentheses) layout (used bymaybe_parenthesize_expression).The basic idea is that when the content of a parenthesized expression doesn't fit when breaking after the opening
(,[, or{, then adding an extra indentation level won't help either.You can see in the above example that adding the extra parentheses can never make the string fit, it's simply too long (this becomes less of a problem with the preview string splitting but can still happen with very long identifier names)
This change is implemented by changing the definition of
fits_expandedto allow for text overflows when the condition is met (the optional parentheses are omitted).Closes #7431
Fixes Poetry's assert diffs python-poetry/poetry@master...Secrus:poetry:ruff-formatter#diff-5f9be6a1e39172bd52265fbad21be3b1d184c0856263f30c21ff941e73dfb594L425
Test Plan
Added tests
Main
PR