astral-sh
ruff
BlogDocsChangelog

Keep lambda parameters on one line and parenthesize the body if it expands

#21385
Comparing
brent/indent-lambda-params
(
05ff8f5
) with
main
(
a9be810
)
CodSpeed Performance Gauge
0%
Untouched
30
Skipped
22

Benchmarks

Skipped (22)

Passed

parser[numpy/globals.py]
crates/ruff_benchmark/benches/parser.rs::parser::benchmark_parser
CodSpeed Performance Gauge
0%
108.9 µs108.9 µs
linter/default-rules[numpy/globals.py]
crates/ruff_benchmark/benches/linter.rs::default_rules::benchmark_default_rules
CodSpeed Performance Gauge
0%
210.3 µs210.3 µs
parser[large/dataset.py]
crates/ruff_benchmark/benches/parser.rs::parser::benchmark_parser
CodSpeed Performance Gauge
0%
5.1 ms5.1 ms
linter/all-rules[numpy/ctypeslib.py]
crates/ruff_benchmark/benches/linter.rs::all_rules::benchmark_all_rules
CodSpeed Performance Gauge
0%
4.4 ms4.4 ms
parser[numpy/ctypeslib.py]
crates/ruff_benchmark/benches/parser.rs::parser::benchmark_parser
CodSpeed Performance Gauge
0%
951.9 µs951.8 µs
linter/all-rules[pydantic/types.py]
crates/ruff_benchmark/benches/linter.rs::all_rules::benchmark_all_rules
CodSpeed Performance Gauge
0%
8.7 ms8.7 ms
parser[unicode/pypinyin.py]
crates/ruff_benchmark/benches/parser.rs::parser::benchmark_parser
CodSpeed Performance Gauge
0%
330 µs330 µs
parser[pydantic/types.py]
crates/ruff_benchmark/benches/parser.rs::parser::benchmark_parser
CodSpeed Performance Gauge
0%
2 ms2 ms
linter/all-with-preview-rules[numpy/globals.py]
crates/ruff_benchmark/benches/linter.rs::preview_rules::benchmark_preview_rules
CodSpeed Performance Gauge
0%
844.1 µs844.1 µs
linter/default-rules[unicode/pypinyin.py]
crates/ruff_benchmark/benches/linter.rs::default_rules::benchmark_default_rules
CodSpeed Performance Gauge
0%
411.5 µs411.5 µs
linter/all-with-preview-rules[pydantic/types.py]
crates/ruff_benchmark/benches/linter.rs::preview_rules::benchmark_preview_rules
CodSpeed Performance Gauge
0%
10.3 ms10.3 ms
linter/default-rules[numpy/ctypeslib.py]
crates/ruff_benchmark/benches/linter.rs::default_rules::benchmark_default_rules
CodSpeed Performance Gauge
0%
1 ms1 ms
lexer[large/dataset.py]
crates/ruff_benchmark/benches/lexer.rs::lexer::benchmark_lexer
CodSpeed Performance Gauge
0%
1.1 ms1.1 ms
lexer[pydantic/types.py]
crates/ruff_benchmark/benches/lexer.rs::lexer::benchmark_lexer
CodSpeed Performance Gauge
0%
496.7 µs496.7 µs
lexer[numpy/ctypeslib.py]
crates/ruff_benchmark/benches/lexer.rs::lexer::benchmark_lexer
CodSpeed Performance Gauge
0%
222.5 µs222.5 µs
lexer[numpy/globals.py]
crates/ruff_benchmark/benches/lexer.rs::lexer::benchmark_lexer
CodSpeed Performance Gauge
0%
29.9 µs29.9 µs
lexer[unicode/pypinyin.py]
crates/ruff_benchmark/benches/lexer.rs::lexer::benchmark_lexer
CodSpeed Performance Gauge
0%
77.3 µs77.3 µs
linter/all-rules[numpy/globals.py]
crates/ruff_benchmark/benches/linter.rs::all_rules::benchmark_all_rules
CodSpeed Performance Gauge
0%
740.3 µs740.3 µs
linter/all-with-preview-rules[numpy/ctypeslib.py]
crates/ruff_benchmark/benches/linter.rs::preview_rules::benchmark_preview_rules
CodSpeed Performance Gauge
0%
5.3 ms5.3 ms
linter/all-rules[large/dataset.py]
crates/ruff_benchmark/benches/linter.rs::all_rules::benchmark_all_rules
CodSpeed Performance Gauge
0%
19 ms19 ms
linter/all-with-preview-rules[large/dataset.py]
crates/ruff_benchmark/benches/linter.rs::preview_rules::benchmark_preview_rules
CodSpeed Performance Gauge
0%
23 ms23 ms
linter/all-rules[unicode/pypinyin.py]
crates/ruff_benchmark/benches/linter.rs::all_rules::benchmark_all_rules
CodSpeed Performance Gauge
0%
2 ms2 ms
linter/default-rules[large/dataset.py]
crates/ruff_benchmark/benches/linter.rs::default_rules::benchmark_default_rules
CodSpeed Performance Gauge
0%
4.4 ms4.4 ms
linter/default-rules[pydantic/types.py]
crates/ruff_benchmark/benches/linter.rs::default_rules::benchmark_default_rules
CodSpeed Performance Gauge
0%
2.2 ms2.2 ms
linter/all-with-preview-rules[unicode/pypinyin.py]
crates/ruff_benchmark/benches/linter.rs::preview_rules::benchmark_preview_rules
CodSpeed Performance Gauge
0%
2.3 ms2.3 ms
formatter[numpy/globals.py]
crates/ruff_benchmark/benches/formatter.rs::formatter::benchmark_formatter
CodSpeed Performance Gauge
0%
249.8 µs250.6 µs
formatter[large/dataset.py]
crates/ruff_benchmark/benches/formatter.rs::formatter::benchmark_formatter
CodSpeed Performance Gauge
-1%
9.7 ms9.7 ms
formatter[numpy/ctypeslib.py]
crates/ruff_benchmark/benches/formatter.rs::formatter::benchmark_formatter
CodSpeed Performance Gauge
-1%
2 ms2 ms
formatter[pydantic/types.py]
crates/ruff_benchmark/benches/formatter.rs::formatter::benchmark_formatter
CodSpeed Performance Gauge
-1%
3.6 ms3.7 ms
formatter[unicode/pypinyin.py]
crates/ruff_benchmark/benches/formatter.rs::formatter::benchmark_formatter
CodSpeed Performance Gauge
-3%
679.4 µs702.7 µs

Commits

Click on a commit to change the comparison range
Base
main
a9be810
-0.25%
add a couple more test cases I tried to get Claude to come up with tests, but most of them weren't very interesting. I think these two additional types of assignments might be worth having, though.
89dc1ad
7 days ago
by ntBre
+0.22%
add too-eagerly parenthesized case from ecosystem the initial code here is only 83 characters wide, so the call expression should fit without wrapping the whole body in parens
9785066
7 days ago
by ntBre
-0.19%
fix snapshot changes for cases with comments
6f6c09c
7 days ago
by ntBre
0%
fix another ecosystem call expansion
9ef9d03
7 days ago
by ntBre
-0.05%
add wrapping case from the ecosystem check the lambda is hugging its enclosing parentheses when it shouldn't be. there seems to be an issue with `best_fitting!` because moving any of the options we're passing to it out of `best_fitting!` avoids this behavior. IR: ``` [ source_position(0), source_position(1), "[", group(expand: propagated, [ indent([ soft_line_break, "(", group([ indent([ soft_line_break, "lambda ", group(["eval_df, _"]), ": ", best_fitting([ [ [ <interned 0> [ "MetricValue(", group(expand: propagated, [ indent([ soft_line_break, group(expand: propagated, [ "scores=eval_df[", group([ indent([soft_line_break, "\"prediction\""]), soft_line_break ]), "].tolist", group(["()"]), ",", soft_line_break_or_space, "aggregate_results={", group([ indent([ soft_line_break, group([ "\"prediction_sum\": sum(", group([ indent([ soft_line_break, group([ "eval_df[", group([ indent([soft_line_break, "\"prediction\""]), soft_line_break ]), "]" ]) ]), soft_line_break ]), ")" ]) ]), soft_line_break ]), "}", if_group_breaks([","]), expand_parent ]) ]), soft_line_break ]), ")" ] ] ] [[group(expand: true, [<ref interned *0>])]] [ [ "(", indent([hard_line_break, <ref interned *0>]), hard_line_break, ")" ] ] ]) ]), soft_line_break ]), ")", if_group_breaks([","]), expand_parent ]), soft_line_break ]), "]", source_position(196), hard_line_break, source_position(196) ] ```
258b1fd
6 days ago
by ntBre
+0.07%
remove comment I don't think we can move the `fits_expanded` call into the assignment formatting because that would wrap the whole lambda in a `fits_expanded`, when we just want to wrap the lambda body in it instead. if I understand correctly, we'd need to duplicate basically this whole function to inject `fits_expanded` in the right place for the lambda formatting in assignments
7dddcc8
6 days ago
by ntBre
+0.07%
Merge branch 'main' into brent/indent-lambda-params
1a3e385
5 days ago
by ntBre
0%
mirror comment handling from `maybe_parenthesize_expression` and update comment
08b1da3
5 days ago
by ntBre
0%
add some more tests
dfd3460
5 days ago
by ntBre
+0.01%
improve dangling header comment placement
43b53ed
5 days ago
by ntBre
0%
clippy
dc240a1
5 days ago
by ntBre
-0.02%
fix assignment instability without parameters too
f20f3e0
4 days ago
by ntBre
+0.03%
format new dangling comments
e8540d9
1 day ago
by ntBre
-0.1%
Merge branch 'main' into brent/indent-lambda-params
05ff8f5
4 hours ago
by ntBre
© 2025 CodSpeed Technology
Home Terms Privacy Docs