-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR does not fix this formatting. It only adds tests for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this PR fix? Sorry, trying to parse!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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