-
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
Hug multiline-strings preview style #9243
Conversation
fa8855c
to
2fef90f
Compare
|
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
2fef90f
to
a58cd85
Compare
This comment was marked as resolved.
This comment was marked as resolved.
a58cd85
to
b849250
Compare
I plan to make changes to this implementation. |
8968a35
to
fab614e
Compare
Signed-off-by: Micha Reiser <[email protected]>
fab614e
to
61a1f07
Compare
The stable style formatting changes now match Black's stable formatting. We can consider it a bugfix. |
@@ -1493,7 +1498,13 @@ impl<'a, 'print> FitsMeasurer<'a, 'print> { | |||
return Fits::No; | |||
} | |||
match args.measure_mode() { | |||
MeasureMode::FirstLine => return Fits::Yes, | |||
MeasureMode::FirstLine => { | |||
return if exceeds_width(self, args) { |
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 a bug fix in the printer. So far, it always returned Fits::Yes
if a text contained a newline character regardless if the text before the newline exceeded the line width. This was incorrect.
@charliermarsh or @konstin I changed the implementation quiet significantly. It would be great to get a second review. |
cc @zanieb
|
@T-256 The diff shows that the old version (main) used to parenthesize The diff isn't showing the difference to the commit version in Git because some projects in our ecosystem check may not use Ruff formatter. |
Summary
This PR implements the hugging for multiline strings in call expression.
The implementation doesn't match black's behavior exactly yet:
call(nested("""multiline\nstring"))
. Ruff will not to ensure consistency withhug_parentheses
"multiline" % placeholder
strings. This can get pretty hard to read if the formatting has many arguments. The solution here is to use f-strings instead.I find 1 and 2 acceptable and wouldn't support them. 3. is a pre-existing deviation that we should tackle separately.
Test Plan
becomes