diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/dict_comp.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/dict_comp.py index cf4df74d92bba9..cf6d4f54402392 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/dict_comp.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/dict_comp.py @@ -86,3 +86,19 @@ k: str(v) for vvvvvvvvvvvvvvvvvvvvvvv in value if str(v) not in self.choices.field.empty_values } + +a = { + k: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +} + +a = { + k: [1, 2, 3,] + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +} + +aaaaaaaaaaaaaaaaaaaaa = { + k: o for o in self.registry.values if o.__class__ is not ModelAdmin +} diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/generator_exp.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/generator_exp.py index f586dcd7fb3737..90d9f13509968b 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/generator_exp.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/generator_exp.py @@ -25,3 +25,19 @@ # trailing ) ) + +a = ( + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +) + +a = ( + [1, 2, 3,] + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +) + +aaaaaaaaaaaaaaaaaaaaa = ( + o for o in self.registry.values if o.__class__ is not ModelAdmin +) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/list_comp.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/list_comp.py index d0cf86ea2ffce2..21f89cb0196134 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/list_comp.py +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/list_comp.py @@ -56,4 +56,20 @@ # Tuples with BinOp [i for i in (aaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccc)] -[(aaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccc) for i in b] \ No newline at end of file +[(aaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccc) for i in b] + +a = [ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +] + +a = [ + [1, 2, 3,] + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +] + +aaaaaaaaaaaaaaaaaaaaa = [ + o for o in self.registry.values if o.__class__ is not ModelAdmin +] diff --git a/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs b/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs index 0a17f3bfc14ec5..ae50d82eccd82d 100644 --- a/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_dict_comp.rs @@ -37,7 +37,7 @@ impl FormatNodeRule for FormatExprDictComp { space(), value.format(), soft_line_break_or_space(), - group(&joined) + &joined )), "}" )] diff --git a/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs b/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs index 3113a494758e06..8f9c2076ebf33b 100644 --- a/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_generator_exp.rs @@ -51,22 +51,18 @@ impl FormatNodeRule for FormatExprGeneratorExp { if self.parentheses == GeneratorExpParentheses::StripIfOnlyFunctionArg { write!( f, - [ - group(&elt.format()), - soft_line_break_or_space(), - group(&joined), - ] + [group(&elt.format()), soft_line_break_or_space(), &joined,] ) } else { write!( f, [parenthesized( "(", - &format_args!( + &group(&format_args!( group(&elt.format()), soft_line_break_or_space(), - group(&joined) - ), + &joined + )), ")" )] ) diff --git a/crates/ruff_python_formatter/src/expression/expr_list_comp.rs b/crates/ruff_python_formatter/src/expression/expr_list_comp.rs index 4763f6b4ee430b..315b3651f6d574 100644 --- a/crates/ruff_python_formatter/src/expression/expr_list_comp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_list_comp.rs @@ -31,7 +31,7 @@ impl FormatNodeRule for FormatExprListComp { &group(&format_args![ group(&elt.format()), soft_line_break_or_space(), - group(&joined) + &joined ]), "]" )] diff --git a/crates/ruff_python_formatter/src/expression/expr_set_comp.rs b/crates/ruff_python_formatter/src/expression/expr_set_comp.rs index 71704a33c6f8c0..89c9e070a6aac6 100644 --- a/crates/ruff_python_formatter/src/expression/expr_set_comp.rs +++ b/crates/ruff_python_formatter/src/expression/expr_set_comp.rs @@ -31,7 +31,7 @@ impl FormatNodeRule for FormatExprSetComp { &group(&format_args!( group(&elt.format()), soft_line_break_or_space(), - group(&joined) + &joined )), "}" )] diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__dict_comp.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__dict_comp.py.snap index 651e8e56449e57..e76cf4df71eb14 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@expression__dict_comp.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__dict_comp.py.snap @@ -92,6 +92,22 @@ selected_choices = { k: str(v) for vvvvvvvvvvvvvvvvvvvvvvv in value if str(v) not in self.choices.field.empty_values } + +a = { + k: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +} + +a = { + k: [1, 2, 3,] + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +} + +aaaaaaaaaaaaaaaaaaaaa = { + k: o for o in self.registry.values if o.__class__ is not ModelAdmin +} ``` ## Output @@ -241,6 +257,26 @@ selected_choices = { for vvvvvvvvvvvvvvvvvvvvvvv in value if str(v) not in self.choices.field.empty_values } + +a = { + k: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +} + +a = { + k: [ + 1, + 2, + 3, + ] + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +} + +aaaaaaaaaaaaaaaaaaaaa = { + k: o for o in self.registry.values if o.__class__ is not ModelAdmin +} ``` diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__generator_exp.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__generator_exp.py.snap index 2bc38c773cb068..d3b3547974b963 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@expression__generator_exp.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__generator_exp.py.snap @@ -31,6 +31,22 @@ len( # trailing ) ) + +a = ( + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +) + +a = ( + [1, 2, 3,] + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +) + +aaaaaaaaaaaaaaaaaaaaa = ( + o for o in self.registry.values if o.__class__ is not ModelAdmin +) ``` ## Output @@ -62,6 +78,26 @@ len( for b in c # trailing ) + +a = ( + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +) + +a = ( + [ + 1, + 2, + 3, + ] + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +) + +aaaaaaaaaaaaaaaaaaaaa = ( + o for o in self.registry.values if o.__class__ is not ModelAdmin +) ``` diff --git a/crates/ruff_python_formatter/tests/snapshots/format@expression__list_comp.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@expression__list_comp.py.snap index f480119b8e16c6..57e59f3c0458cf 100644 --- a/crates/ruff_python_formatter/tests/snapshots/format@expression__list_comp.py.snap +++ b/crates/ruff_python_formatter/tests/snapshots/format@expression__list_comp.py.snap @@ -62,7 +62,24 @@ selected_choices = [ # Tuples with BinOp [i for i in (aaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccc)] -[(aaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccc) for i in b]``` +[(aaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccc) for i in b] + +a = [ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +] + +a = [ + [1, 2, 3,] + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +] + +aaaaaaaaaaaaaaaaaaaaa = [ + o for o in self.registry.values if o.__class__ is not ModelAdmin +] +``` ## Output ```py @@ -141,6 +158,26 @@ selected_choices = [ ) for i in b ] + +a = [ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +] + +a = [ + [ + 1, + 2, + 3, + ] + for f in bbbbbbbbbbbbbbb + if f not in ccccccccccc +] + +aaaaaaaaaaaaaaaaaaaaa = [ + o for o in self.registry.values if o.__class__ is not ModelAdmin +] ```