mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-17 00:50:16 +00:00
Use reserved width to include line suffix measurement (#6901)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
edfd888bd6
commit
a3f4d7745a
16 changed files with 504 additions and 80 deletions
|
@ -247,10 +247,13 @@ impl Format<PyFormatContext<'_>> for MaybeParenthesizeExpression<'_> {
|
|||
if format_expression.inspect(f)?.will_break() {
|
||||
// The group here is necessary because `format_expression` may contain IR elements
|
||||
// that refer to the group id
|
||||
group(&format_expression)
|
||||
.with_group_id(Some(group_id))
|
||||
.should_expand(true)
|
||||
.fmt(f)
|
||||
group(&format_args![
|
||||
text("("),
|
||||
soft_block_indent(&format_expression),
|
||||
text(")")
|
||||
])
|
||||
.with_group_id(Some(group_id))
|
||||
.fmt(f)
|
||||
} else {
|
||||
// Only add parentheses if it makes the expression fit on the line.
|
||||
// Using the flat version as the most expanded version gives a left-to-right splitting behavior
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue