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
|
@ -74,4 +74,15 @@
|
||||||
a, # Trailing
|
a, # Trailing
|
||||||
) in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension # Trailing
|
) in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension # Trailing
|
||||||
} # 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
|
||||||
|
}
|
||||||
|
|
|
@ -43,3 +43,13 @@
|
||||||
if
|
if
|
||||||
gggggggggggggggggggggggggggggggggggggggggggg
|
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
|
if
|
||||||
gggggggggggggggggggggggggggggggggggggggggggg
|
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,
|
f,
|
||||||
[parenthesized(
|
[parenthesized(
|
||||||
"{",
|
"{",
|
||||||
&format_args!(
|
&group(&format_args!(
|
||||||
group(&key.format()),
|
group(&key.format()),
|
||||||
text(":"),
|
text(":"),
|
||||||
space(),
|
space(),
|
||||||
value.format(),
|
value.format(),
|
||||||
soft_line_break_or_space(),
|
soft_line_break_or_space(),
|
||||||
group(&joined)
|
group(&joined)
|
||||||
),
|
)),
|
||||||
"}"
|
"}"
|
||||||
)]
|
)]
|
||||||
)
|
)
|
||||||
|
|
|
@ -28,11 +28,11 @@ impl FormatNodeRule<ExprListComp> for FormatExprListComp {
|
||||||
f,
|
f,
|
||||||
[parenthesized(
|
[parenthesized(
|
||||||
"[",
|
"[",
|
||||||
&format_args!(
|
&group(&format_args![
|
||||||
group(&elt.format()),
|
group(&elt.format()),
|
||||||
soft_line_break_or_space(),
|
soft_line_break_or_space(),
|
||||||
group(&joined)
|
group(&joined)
|
||||||
),
|
]),
|
||||||
"]"
|
"]"
|
||||||
)]
|
)]
|
||||||
)
|
)
|
||||||
|
|
|
@ -28,11 +28,11 @@ impl FormatNodeRule<ExprSetComp> for FormatExprSetComp {
|
||||||
f,
|
f,
|
||||||
[parenthesized(
|
[parenthesized(
|
||||||
"{",
|
"{",
|
||||||
&format_args!(
|
&group(&format_args!(
|
||||||
group(&elt.format()),
|
group(&elt.format()),
|
||||||
soft_line_break_or_space(),
|
soft_line_break_or_space(),
|
||||||
group(&joined)
|
group(&joined)
|
||||||
),
|
)),
|
||||||
"}"
|
"}"
|
||||||
)]
|
)]
|
||||||
)
|
)
|
||||||
|
|
|
@ -278,16 +278,14 @@ aaaaaaaaaaaaaa + {
|
||||||
eeeeeee,
|
eeeeeee,
|
||||||
}
|
}
|
||||||
aaaaaaaaaaaaaa + [
|
aaaaaaaaaaaaaa + [
|
||||||
a
|
a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
|
||||||
]
|
]
|
||||||
(
|
(
|
||||||
aaaaaaaaaaaaaa
|
aaaaaaaaaaaaaa
|
||||||
+ (a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)
|
+ (a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)
|
||||||
)
|
)
|
||||||
aaaaaaaaaaaaaa + {
|
aaaaaaaaaaaaaa + {
|
||||||
a
|
a for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
||||||
for x in bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Wraps it in parentheses if it needs to break both left and right
|
# 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
|
a, # Trailing
|
||||||
) in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension # Trailing
|
) in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension # Trailing
|
||||||
} # 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
|
## Output
|
||||||
```py
|
```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
|
) in this_is_a_very_long_variable_which_will_cause_a_trailing_comma_which_breaks_the_comprehension # Trailing
|
||||||
} # 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
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,16 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression
|
||||||
if
|
if
|
||||||
gggggggggggggggggggggggggggggggggggggggggggg
|
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
|
## Output
|
||||||
|
@ -101,6 +111,17 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression
|
||||||
< hhhhhhhhhhhhhhhhhhhhhhhhhh
|
< hhhhhhhhhhhhhhhhhhhhhhhhhh
|
||||||
if gggggggggggggggggggggggggggggggggggggggggggg
|
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
|
if
|
||||||
gggggggggggggggggggggggggggggggggggggggggggg
|
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
|
## Output
|
||||||
|
@ -101,6 +111,17 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression
|
||||||
< hhhhhhhhhhhhhhhhhhhhhhhhhh
|
< hhhhhhhhhhhhhhhhhhhhhhhhhh
|
||||||
if gggggggggggggggggggggggggggggggggggggggggggg
|
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