dosisod / refurb

A tool for refurbishing and modernizing Python codebases
GNU General Public License v3.0
2.48k stars 54 forks source link

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

Open Skylion007 opened 6 months ago

Skylion007 commented 6 months ago

Has your issue already been fixed?

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: https://github.com/astral-sh/ruff/issues/11075