Fix multiline lambda expression statement formating#8466
Conversation
|
Current dependencies on/for this PR:
This stack of pull requests is managed by Graphite. |
a35b27e to
e7fb0ac
Compare
|
|
||
| lambda self, araa, kkkwargs=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(*args, **kwargs), e=1, f=2, g=2: d | ||
|
|
||
| # Regression tests for https://github.com/astral-sh/ruff/issues/8179 |
There was a problem hiding this comment.
This PR does not fix this formatting. It only adds tests for it
There was a problem hiding this comment.
What does this PR fix? Sorry, trying to parse!
There was a problem hiding this comment.
Wait sorry, I now understand.
| let separator = format_with(|f: &mut PyFormatter| { | ||
| token(",").fmt(f)?; | ||
|
|
||
| if f.context().node_level().is_parenthesized() { |
There was a problem hiding this comment.
testing for self.parentheses == ParameterParentheses::Never is, unfortunately, not sufficient because it doesn't handle comments:
a = [
lambda x # comment
x
# comment
: b
]This uses the Never layout but the lambda has comments. The example also shows that testing whether the lambda expression itself is parenthesized isn't sufficient.
e7fb0ac to
3e218fa
Compare
|

Summary
This PR fixes a bug in our formatter where a multiline lambda expression statement was formatted over multiple lines without adding parentheses.
The PR "fixes" the problem by not splitting the lambda parameters if it is not parenthesized
Test Plan
Added test