Brent Westbrook
0ebdebddd8
Keep lambda parameters on one line and parenthesize the body if it expands ( #21385 )
...
## Summary
This PR makes two changes to our formatting of `lambda` expressions:
1. We now parenthesize the body expression if it expands
2. We now try to keep the parameters on a single line
The latter of these fixes #8179 :
Black formatting and this PR's formatting:
```py
def a():
return b(
c,
d,
e,
f=lambda self, *args, **kwargs: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
*args, **kwargs
),
)
```
Stable Ruff formatting
```py
def a():
return b(
c,
d,
e,
f=lambda self,
*args,
**kwargs: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(*args, **kwargs),
)
```
We don't parenthesize the body expression here because the call to
`aaaa...` has its own parentheses, but adding a binary operator shows
the new parenthesization:
```diff
@@ -3,7 +3,7 @@
c,
d,
e,
- f=lambda self, *args, **kwargs: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
- *args, **kwargs
- ) + 1,
+ f=lambda self, *args, **kwargs: (
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(*args, **kwargs) + 1
+ ),
)
```
This is actually a new divergence from Black, which formats this input
like this:
```py
def a():
return b(
c,
d,
e,
f=lambda self, *args, **kwargs: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
*args, **kwargs
)
+ 1,
)
```
But I think this is an improvement, unlike the case from #8179 .
One other, smaller benefit is that because we now add parentheses to
lambda bodies, we also remove redundant parentheses:
```diff
@pytest.mark.parametrize(
"f",
[
- lambda x: (x.expanding(min_periods=5).cov(x, pairwise=True)),
- lambda x: (x.expanding(min_periods=5).corr(x, pairwise=True)),
+ lambda x: x.expanding(min_periods=5).cov(x, pairwise=True),
+ lambda x: x.expanding(min_periods=5).corr(x, pairwise=True),
],
)
def test_moment_functions_zero_length_pairwise(f):
```
## Test Plan
New tests taken from #8465 and probably a few more I should grab from
the ecosystem results.
---------
Co-authored-by: Micha Reiser <micha@reiser.io >
2025-12-12 12:02:25 -05:00
..
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-10-14 10:14:59 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-01-09 10:20:06 +01:00
2025-01-09 10:20:06 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-01-09 10:20:06 +01:00
2025-01-09 10:20:06 +01:00
2024-11-15 19:31:15 +01:00
2025-01-09 10:20:06 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-11-18 12:02:09 -06:00
2024-11-15 19:31:15 +01:00
2025-10-14 10:14:59 -04:00
2025-10-17 08:49:16 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-01-09 10:20:06 +01:00
2024-11-15 19:31:15 +01:00
2025-10-14 10:14:59 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-10-14 10:14:59 -04:00
2025-01-09 10:20:06 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-05-22 07:52:21 +02:00
2024-11-15 19:31:15 +01:00
2025-10-14 10:14:59 -04:00
2025-01-09 10:20:06 +01:00
2025-10-14 10:14:59 -04:00
2025-10-14 10:14:59 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-10-14 10:14:59 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-10-14 10:14:59 -04:00
2025-10-14 10:14:59 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-10-14 10:14:59 -04:00
2024-11-15 19:31:15 +01:00
2025-12-12 12:02:25 -05:00
2025-12-12 12:02:25 -05:00
2025-10-14 10:14:59 -04:00
2024-11-15 19:31:15 +01:00
2025-10-14 10:14:59 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-10-14 10:14:59 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-01-09 10:20:06 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-01-09 10:20:06 +01:00
2024-11-15 19:31:15 +01:00
2025-10-14 10:14:59 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-01-09 10:20:06 +01:00
2025-10-07 12:23:11 -04:00
2024-11-15 19:31:15 +01:00
2025-04-11 10:21:47 +02:00
2025-10-07 12:23:11 -04:00
2025-10-07 12:23:11 -04:00
2025-10-07 12:23:11 -04:00
2024-11-15 19:31:15 +01:00
2024-12-09 09:32:12 +00:00
2025-10-07 12:23:11 -04:00
2025-10-07 12:23:11 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-11-17 09:11:36 -06:00
2024-11-15 19:31:15 +01:00
2025-01-09 10:20:06 +01:00
2024-11-15 19:31:15 +01:00
2025-05-30 15:00:56 -05:00
2024-11-15 19:31:15 +01:00
2025-10-07 12:23:11 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-10-07 12:23:11 -04:00
2025-10-17 08:49:16 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-07-27 12:41:03 +00:00
2025-10-07 12:23:11 -04:00
2025-07-27 12:41:03 +00:00
2025-12-12 12:02:25 -05:00
2025-01-09 10:20:06 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-10-07 12:23:11 -04:00
2024-11-15 19:31:15 +01:00
2025-07-27 12:41:03 +00:00
2024-11-15 19:31:15 +01:00
2025-11-18 10:48:14 -05:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-01-09 10:20:06 +01:00
2025-06-15 06:53:06 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-10-07 12:23:11 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-10-27 10:34:29 +00:00
2024-11-15 19:31:15 +01:00
2025-10-07 12:23:11 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-11-18 12:02:09 -06:00
2024-11-15 19:31:15 +01:00
2025-11-18 12:02:09 -06:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-11-17 07:30:34 -06:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-12-12 12:02:25 -05:00
2025-10-31 14:53:40 -04:00
2024-11-15 19:31:15 +01:00
2025-10-07 12:23:11 -04:00
2024-11-15 19:31:15 +01:00
2025-11-18 10:48:14 -05:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-05-22 07:52:21 +02:00
2025-05-22 07:52:21 +02:00
2025-10-07 12:23:11 -04:00
2025-10-07 12:23:11 -04:00
2024-11-15 19:31:15 +01:00
2025-10-27 09:52:17 -05:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-10-07 12:23:11 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-10-31 14:53:40 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-12-09 09:32:12 +00:00
2025-10-07 12:23:11 -04:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-10-07 12:23:11 -04:00
2024-11-15 19:31:15 +01:00
2025-01-09 10:20:06 +01:00
2024-11-15 19:31:15 +01:00
2025-01-09 10:20:06 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-11-17 07:30:34 -06:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-11-03 17:06:52 -05:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-01-09 10:20:06 +01:00
2025-01-09 10:20:06 +01:00
2025-01-09 10:20:06 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-10-14 11:17:45 -04:00
2024-11-15 19:31:15 +01:00
2025-11-17 07:30:34 -06:00
2025-02-18 12:03:13 -05:00
2025-10-13 14:13:27 -04:00
2025-10-07 12:23:11 -04:00
2025-10-07 12:23:11 -04:00
2024-11-15 19:31:15 +01:00
2025-06-24 16:25:44 +02:00
2024-11-15 19:31:15 +01:00
2024-11-15 19:31:15 +01:00
2025-06-24 16:25:44 +02:00
2025-10-07 12:23:11 -04:00
2025-06-07 16:02:43 +02:00
2024-11-15 19:31:15 +01:00