Tweak breaking groups for comprehensions (#6321)

## Summary

Fixes some comprehension formatting by avoiding creating the group for
the comprehension itself (so that if it breaks, all parts break on their
own lines, e.g. the `for` and the `if` clauses).

Closes https://github.com/astral-sh/ruff/issues/6063.

## Test Plan

Bunch of new fixtures.
This commit is contained in:
Charlie Marsh 2023-08-04 10:00:54 -04:00 committed by GitHub
parent 99baad12d8
commit 4d47dfd6c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 166 additions and 9 deletions

View file

@ -44,7 +44,7 @@ impl FormatNodeRule<ExprDictComp> for FormatExprDictComp {
space(),
value.format(),
soft_line_break_or_space(),
group(&joined)
&joined
)),
"}"
)]

View file

@ -60,7 +60,7 @@ impl FormatNodeRule<ExprGeneratorExp> for FormatExprGeneratorExp {
leading_comments(dangling),
group(&elt.format()),
soft_line_break_or_space(),
group(&joined),
&joined
]
)
} else {
@ -69,11 +69,11 @@ impl FormatNodeRule<ExprGeneratorExp> for FormatExprGeneratorExp {
[parenthesized_with_dangling_comments(
"(",
dangling,
&format_args!(
&group(&format_args!(
group(&elt.format()),
soft_line_break_or_space(),
group(&joined)
),
&joined
)),
")"
)]
)

View file

@ -38,7 +38,7 @@ impl FormatNodeRule<ExprListComp> for FormatExprListComp {
&group(&format_args![
group(&elt.format()),
soft_line_break_or_space(),
group(&joined)
&joined
]),
"]"
)]

View file

@ -38,7 +38,7 @@ impl FormatNodeRule<ExprSetComp> for FormatExprSetComp {
&group(&format_args!(
group(&elt.format()),
soft_line_break_or_space(),
group(&joined)
&joined
)),
"}"
)]