Fix formatting of lambda star arguments#6257
Conversation
Previously, the ruff formatter was removing the star argument of `lambda` expressions when formatting. Given the following code snippet ```python lambda *a: () lambda **b: () ``` it would be formated to ```python lambda: () lambda: () ``` We fix this by checking for the presence of `args`, `vararg` or `kwarg` in the `lambda` expression, before we were only checking for the presence of `args`. Fixes astral-sh#5894
|
I don't know why the |
PR Check ResultsBenchmarkLinuxWindows |
|
Deleted is good! Deleted means exact compatibility with Black on that file. |
Ah nice! Do you know why the CI is failing? |
| # ...but we do preserve a trailing comma after the arguments | ||
| a = lambda b,: 0 | ||
|
|
||
| lambda *a: () |
There was a problem hiding this comment.
Unfortunately you can do disturbing things like insert a comment between the star and the parameter. We'll probably want test coverage for cases like this:
(
lambda
*
# test
x: print(x)
)
Hm I'm not sure if this panic is relevant?
but it detected a stability error
@konstin is probably best to direct you to debug that |
|
I'll take a look. |
|
fwiw i have improving the script on my agenda for tomorrow |
|
Looks like it was an unrelated bug in our handling of (e.g.) |
**Summary** Prompted by #6257 (comment), it tried to make the ecosystem script output on failure better understandable. All log messages are now written to a file, which is printed on error. Running locally progress is still shown. Looking through the log output i saw that we currently log syntax errors in input, which is confusing because they aren't actual errors, but we don't check that these files don't change due to parser regressions or improvements. I added `--files-with-errors` to catch that. **Test Plan** CI
…6300) **Summary** Prompted by #6257 (comment), it tried to make the ecosystem script output on failure better understandable. All log messages are now written to a file, which is printed on error. Running locally progress is still shown. Looking through the log output i saw that we currently log syntax errors in input, which is confusing because they aren't actual errors, but we don't check that these files don't change due to parser regressions or improvements. I added `--files-with-errors` to catch that. **Test Plan** CI
Summary
Previously, the ruff formatter was removing the star argument of
lambdaexpressions when formatting.Given the following code snippet
it would be formatted to
We fix this by checking for the presence of
args,varargorkwargin thelambdaexpression, before we were only checking for the presence ofargs.Fixes #5894
Test Plan
Add new tests cases.