mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
Avoid line break before for
in comprehension if outer expression expands (#5912)
This commit is contained in:
parent
c2b7b46717
commit
eeb8a5fe0a
10 changed files with 107 additions and 12 deletions
|
@ -75,3 +75,14 @@
|
|||
) in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension # Trailing
|
||||
} # Trailing
|
||||
# Trailing
|
||||
|
||||
|
||||
# Regression tests for https://github.com/astral-sh/ruff/issues/5911
|
||||
selected_choices = {
|
||||
k: str(v) for v in value if str(v) not in self.choices.field.empty_values
|
||||
}
|
||||
|
||||
selected_choices = {
|
||||
k: str(v)
|
||||
for vvvvvvvvvvvvvvvvvvvvvvv in value if str(v) not in self.choices.field.empty_values
|
||||
}
|
||||
|
|
|
@ -43,3 +43,13 @@
|
|||
if
|
||||
gggggggggggggggggggggggggggggggggggggggggggg
|
||||
]
|
||||
|
||||
# Regression tests for https://github.com/astral-sh/ruff/issues/5911
|
||||
selected_choices = [
|
||||
str(v) for v in value if str(v) not in self.choices.field.empty_values
|
||||
]
|
||||
|
||||
selected_choices = [
|
||||
str(v)
|
||||
for vvvvvvvvvvvvvvvvvvvvvvv in value if str(v) not in self.choices.field.empty_values
|
||||
]
|
||||
|
|
|
@ -43,3 +43,13 @@
|
|||
if
|
||||
gggggggggggggggggggggggggggggggggggggggggggg
|
||||
}
|
||||
|
||||
# Regression tests for https://github.com/astral-sh/ruff/issues/5911
|
||||
selected_choices = {
|
||||
str(v) for v in value if str(v) not in self.choices.field.empty_values
|
||||
}
|
||||
|
||||
selected_choices = {
|
||||
str(v)
|
||||
for vvvvvvvvvvvvvvvvvvvvvvv in value if str(v) not in self.choices.field.empty_values
|
||||
}
|
||||
|
|
|
@ -31,14 +31,14 @@ impl FormatNodeRule<ExprDictComp> for FormatExprDictComp {
|
|||
f,
|
||||
[parenthesized(
|
||||
"{",
|
||||
&format_args!(
|
||||
&group(&format_args!(
|
||||
group(&key.format()),
|
||||
text(":"),
|
||||
space(),
|
||||
value.format(),
|
||||
soft_line_break_or_space(),
|
||||
group(&joined)
|
||||
),
|
||||
)),
|
||||
"}"
|
||||
)]
|
||||
)
|
||||
|
|
|
@ -28,11 +28,11 @@ impl FormatNodeRule<ExprListComp> for FormatExprListComp {
|
|||
f,
|
||||
[parenthesized(
|
||||
"[",
|
||||
&format_args!(
|
||||
&group(&format_args![
|
||||
group(&elt.format()),
|
||||
soft_line_break_or_space(),
|
||||
group(&joined)
|
||||
),
|
||||
]),
|
||||
"]"
|
||||
)]
|
||||
)
|
||||
|
|
|
@ -28,11 +28,11 @@ impl FormatNodeRule<ExprSetComp> for FormatExprSetComp {
|
|||
f,
|
||||
[parenthesized(
|
||||
"{",
|
||||
&format_args!(
|
||||
&group(&format_args!(
|
||||
group(&elt.format()),
|
||||
soft_line_break_or_space(),
|
||||
group(&joined)
|
||||
),
|
||||
)),
|
||||
"}"
|
||||
)]
|
||||
)
|
||||
|
|
|
@ -278,16 +278,14 @@ aaaaaaaaaaaaaa + {
|
|||
eeeeeee,
|
||||
}
|
||||
aaaaaaaaaaaaaa + [
|
||||
a
|
||||
for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
]
|
||||
(
|
||||
aaaaaaaaaaaaaa
|
||||
+ (a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)
|
||||
)
|
||||
aaaaaaaaaaaaaa + {
|
||||
a
|
||||
for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||
}
|
||||
|
||||
# Wraps it in parentheses if it needs to break both left and right
|
||||
|
|
|
@ -80,7 +80,19 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression
|
|||
a, # Trailing
|
||||
) in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension # Trailing
|
||||
} # Trailing
|
||||
# Trailing```
|
||||
# Trailing
|
||||
|
||||
|
||||
# Regression tests for https://github.com/astral-sh/ruff/issues/5911
|
||||
selected_choices = {
|
||||
k: str(v) for v in value if str(v) not in self.choices.field.empty_values
|
||||
}
|
||||
|
||||
selected_choices = {
|
||||
k: str(v)
|
||||
for vvvvvvvvvvvvvvvvvvvvvvv in value if str(v) not in self.choices.field.empty_values
|
||||
}
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
|
@ -217,6 +229,18 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression
|
|||
) in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension # Trailing
|
||||
} # Trailing
|
||||
# Trailing
|
||||
|
||||
|
||||
# Regression tests for https://github.com/astral-sh/ruff/issues/5911
|
||||
selected_choices = {
|
||||
k: str(v) for v in value if str(v) not in self.choices.field.empty_values
|
||||
}
|
||||
|
||||
selected_choices = {
|
||||
k: str(v)
|
||||
for vvvvvvvvvvvvvvvvvvvvvvv in value
|
||||
if str(v) not in self.choices.field.empty_values
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -49,6 +49,16 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression
|
|||
if
|
||||
gggggggggggggggggggggggggggggggggggggggggggg
|
||||
]
|
||||
|
||||
# Regression tests for https://github.com/astral-sh/ruff/issues/5911
|
||||
selected_choices = [
|
||||
str(v) for v in value if str(v) not in self.choices.field.empty_values
|
||||
]
|
||||
|
||||
selected_choices = [
|
||||
str(v)
|
||||
for vvvvvvvvvvvvvvvvvvvvvvv in value if str(v) not in self.choices.field.empty_values
|
||||
]
|
||||
```
|
||||
|
||||
## Output
|
||||
|
@ -101,6 +111,17 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression
|
|||
< hhhhhhhhhhhhhhhhhhhhhhhhhh
|
||||
if gggggggggggggggggggggggggggggggggggggggggggg
|
||||
]
|
||||
|
||||
# Regression tests for https://github.com/astral-sh/ruff/issues/5911
|
||||
selected_choices = [
|
||||
str(v) for v in value if str(v) not in self.choices.field.empty_values
|
||||
]
|
||||
|
||||
selected_choices = [
|
||||
str(v)
|
||||
for vvvvvvvvvvvvvvvvvvvvvvv in value
|
||||
if str(v) not in self.choices.field.empty_values
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -49,6 +49,16 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression
|
|||
if
|
||||
gggggggggggggggggggggggggggggggggggggggggggg
|
||||
}
|
||||
|
||||
# Regression tests for https://github.com/astral-sh/ruff/issues/5911
|
||||
selected_choices = {
|
||||
str(v) for v in value if str(v) not in self.choices.field.empty_values
|
||||
}
|
||||
|
||||
selected_choices = {
|
||||
str(v)
|
||||
for vvvvvvvvvvvvvvvvvvvvvvv in value if str(v) not in self.choices.field.empty_values
|
||||
}
|
||||
```
|
||||
|
||||
## Output
|
||||
|
@ -101,6 +111,17 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression
|
|||
< hhhhhhhhhhhhhhhhhhhhhhhhhh
|
||||
if gggggggggggggggggggggggggggggggggggggggggggg
|
||||
}
|
||||
|
||||
# Regression tests for https://github.com/astral-sh/ruff/issues/5911
|
||||
selected_choices = {
|
||||
str(v) for v in value if str(v) not in self.choices.field.empty_values
|
||||
}
|
||||
|
||||
selected_choices = {
|
||||
str(v)
|
||||
for vvvvvvvvvvvvvvvvvvvvvvv in value
|
||||
if str(v) not in self.choices.field.empty_values
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue