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

unnecessary-lambda fix is unsafe even when there are no side-effects #10663

Closed
arrdem opened this issue Mar 29, 2024 · 1 comment · Fixed by #10668
Closed

unnecessary-lambda fix is unsafe even when there are no side-effects #10663

arrdem opened this issue Mar 29, 2024 · 1 comment · Fixed by #10668
Assignees
Labels
bug Something isn't working

Comments

@arrdem
Copy link

arrdem commented Mar 29, 2024

  • Ruff version: 0.3.3
  • Linter rule: unnecessary-lambda / PLW0108

Example

def foo(a, b):
  return a + b

def bar(c, d):
  return c, d

HANDLERS = {
  "foo": foo,
  "bar": lambda a, b: bar(a, b)  # "fixes" to just bar 
}

def handle(verb: str, payload):
  a, b = payload
  return HANDLERS[verb](a=a, b=b)

Here we're relying on the lambda to implement renaming of positional arguments. Removing the lambda expression would be incorrect despite an absence of side-effects. A correct refactor would be to rename the arguments to bar, or to eliminate the keyword invocation but the linter fix alone is unsafe despite listing itself as such.

@charliermarsh charliermarsh self-assigned this Mar 30, 2024
@charliermarsh charliermarsh added the bug Something isn't working label Mar 30, 2024
@charliermarsh
Copy link
Member

Thanks. That's... unfortunate, but correct.

charliermarsh added a commit that referenced this issue Mar 30, 2024
## Summary

See the linked issue and comment for more.

Closes #10663.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants