-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Parenthesize unsplittable nodes if it makes them fit #6734
Conversation
This reverts commit 9a8ba58.
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
mode
from BestFitting
"@@ -223,6 +223,35 @@ impl Format<PyFormatContext<'_>> for MaybeParenthesizeExpression<'_> { | |||
} | |||
} | |||
}, | |||
OptionalParentheses::IfFits => match parenthesize { |
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'm not very happy with this name. The branches are the same as for Never
except for IfBreaks
.
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.
BetterFitOnly
?
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.
The formatter changes bring back the BestFitting::print_mode
@@ -311,6 +314,14 @@ impl<'a> Printer<'a> { | |||
_ => { | |||
self.state.measured_group_fits = true; | |||
|
|||
// Set the print mode for this group in case this group was measured as part of a | |||
// previous `fits_group` call. | |||
if let Some(id) = id { |
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 was a bug in the Printer where group modes set during a previous fits
test stuck around.
6524c22
to
93f9521
Compare
PR Check ResultsBenchmarkLinux
Windows
|
Ouch, this is, not too surprisingly, not good for performance. |
Is that mostly due to the |
It's a combination of memoized and best fitting, both of them allocate, and best fitting requires a The solution is to limit the condition of when to use this layout. It should only be necessary if the content length is close to the max line length (I have to do some math tomorrow) |
3668767
to
33c1161
Compare
33c1161
to
431973a
Compare
Splitting the PR must have confused graphite. See #6816 |
Summary
This PR implements black's logic where it parenthesizes unsplittable nodes like constants or identifiers
if it makes them fit the line
closes #6271
Test Plan
I added new test plans, diffed the output for
django
to ensure this PR introduces no regression, and verified that the similarity indices improvemain
This PR