Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

FURB118 bug: incorrectly replaces 1 element tuple lambdas with itemgetter #11075

Closed
Skylion007 opened this issue Apr 21, 2024 · 1 comment · Fixed by #11095
Closed

FURB118 bug: incorrectly replaces 1 element tuple lambdas with itemgetter #11075

Skylion007 opened this issue Apr 21, 2024 · 1 comment · Fixed by #11095
Assignees
Labels
bug Something isn't working fixes Related to suggested fixes for violations

Comments

@Skylion007
Copy link
Contributor

There is a bad fixit generated by ruff for FURB118 with operator.itemgetter().

It tries to replace this line:

            return lambda x: (x[index],)

with this line

            return operator.itemgetter(index)

However, these are not equivalent, in the first instance, the code will return a 1 element tuple, while in the second one, it will just return that element.

@Skylion007 Skylion007 changed the title FURB118 bug: does not recognize 1 element tuples FURB118 bug: incorrectly replaces 1 element tuple lambdas with itemgetter Apr 21, 2024
@dhruvmanila dhruvmanila added bug Something isn't working fixes Related to suggested fixes for violations labels Apr 22, 2024
@charliermarsh charliermarsh self-assigned this Apr 22, 2024
@charliermarsh
Copy link
Member

I'll take a look, thanks @Skylion007.

charliermarsh added a commit that referenced this issue Apr 23, 2024
…ple (#11095)

## Summary

The `operator.itemgetter` behavior changes where there's more than one
argument, such that `operator.itemgetter(0)` yields `r[0]`, rather than
`(r[0],)`.

Closes #11075.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working fixes Related to suggested fixes for violations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@charliermarsh @Skylion007 @dhruvmanila and others