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

[Bug]: tries to replace single element tuple with operator.itemgetter #335

Open
3 tasks done
Skylion007 opened this issue Apr 21, 2024 · 0 comments
Open
3 tasks done
Assignees
Labels
bug Something isn't working

Comments

@Skylion007
Copy link

Skylion007 commented Apr 21, 2024

Has your issue already been fixed?

  • Have you checked to see if your issue still exists on the master branch? See the docs for instructions on how to setup a local build of Refurb.
  • Have you looked at the open/closed issues to see if anyone has already reported your issue?
  • If reporting a false positive/incorrect suggestion, have you double checked that the suggested fix changes the code semantics?

The Bug

The following code:

# Your code here
a = list(range(10))
index = 1
f = lambda x: (x[index],)
print(f(a))

Emits the following error:

test.py:2:5 [FURB118]: Replace `lambda x: (x[index],)` with `operator.itemgetter(index)`

But it should not be emitting an error instance because this is not semantically equivalent (the lambda returned a single element tuple, this returns a single element). This also one case that is impossible for operator.itemgetter() to operate on. (You cannot trick it into generating a one element tuple to my knowledge).

Version Info

refurb-2.0.0

Python Version

3.10.12

Config File

# N/A

Extra Info

ruff issue linked here: astral-sh/ruff#11075

@Skylion007 Skylion007 added the bug Something isn't working label Apr 21, 2024
@Skylion007 Skylion007 changed the title [Bug]: tries to replace tuple getter with operator.itemgetter [Bug]: tries to replace single element tuple with operator.itemgetter Apr 22, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants
@Skylion007 @dosisod and others