Skip to content
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

Formatter: lambda star argument gets removed #5894

Closed
Tracked by #6069 ...
konstin opened this issue Jul 19, 2023 · 3 comments · Fixed by #6257
Closed
Tracked by #6069 ...

Formatter: lambda star argument gets removed #5894

konstin opened this issue Jul 19, 2023 · 3 comments · Fixed by #6257
Assignees
Labels
bug Something isn't working formatter Related to the formatter good first issue Good for newcomers help wanted Contributions especially welcome

Comments

@konstin
Copy link
Member

konstin commented Jul 19, 2023

lambda *a: () gets formatted as lambda: () the varargs argument gets lost

@konstin konstin added bug Something isn't working formatter Related to the formatter labels Jul 19, 2023
@MichaReiser
Copy link
Member

Playground

@MichaReiser MichaReiser added good first issue Good for newcomers help wanted Contributions especially welcome labels Jul 31, 2023
@MichaReiser MichaReiser added this to the Formatter: Alpha milestone Jul 31, 2023
@LaBatata101
Copy link
Contributor

Can I take a shot at this?

@charliermarsh
Copy link
Member

To my knowledge it's unclaimed, go for it. Here's the PR that added initial lambda formatting, for reference: https://github.com/astral-sh/ruff/pull/5806/files#diff-bb97e8c9522dd5f1f97942d8f546fc3c931fc8293e128a1a3360d8dda56c9b7d

LaBatata101 added a commit to LaBatata101/ruff that referenced this issue Aug 1, 2023
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
LaBatata101 added a commit to LaBatata101/ruff that referenced this issue Aug 1, 2023
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
charliermarsh added a commit that referenced this issue Aug 2, 2023
## Summary
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 formatted 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 #5894

## Test Plan

Add new tests cases.

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working formatter Related to the formatter good first issue Good for newcomers help wanted Contributions especially welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants