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

FURB118: Should not replace lambda with operator.itemgetter when the itemgetter use the lambda arguments #11573

Closed
nasyxx opened this issue May 27, 2024 · 2 comments · Fixed by #11574
Assignees
Labels
bug Something isn't working help wanted Contributions especially welcome

Comments

@nasyxx
Copy link

nasyxx commented May 27, 2024

operator.itemgetter cannot be used to replace a lambda function for indexing with lambda arguments.

# xxx.py
xs = [1, 2, 3, 4, 5]

xm = map(lambda x: x[5-x], xs)
xxx.py:
  3:10 FURB118 [*] Use `operator.itemgetter(5-x)` instead of defining a lambda

Here if replaced with operator.itemgetter(5-x), the x would be a undefined variable

ruff: 0.4.5
python: 3.12.2
@charliermarsh
Copy link
Member

Makes sense, thanks.

@charliermarsh
Copy link
Member

Fixed in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Contributions especially welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants