-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow parenthesized content exceed configured line width #7490
Conversation
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
// Measure in fully expanded mode and allow overflows | ||
self.stack.push( | ||
TagKind::FitsExpanded, | ||
args.with_measure_mode(MeasureMode::AllLinesAllowTextOverflow) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
// 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)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
if True: | ||
if True: | ||
if True: | ||
if True: | ||
msg += " " + _( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd flatten this and expand the lines instead
Summary
This PR changes the formatting for all
parenthesized
expressions 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_expanded
to 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