refurb icon indicating copy to clipboard operation
refurb copied to clipboard

[Bug]: FURB148 triggers if index variable is used outside of the loop

Open kasium opened this issue 1 year ago • 0 comments

Has your issue already been fixed?

  • [X] 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.
  • [X] Have you looked at the open/closed issues to see if anyone has already reported your issue?
  • [X] If reporting a false positive/incorrect suggestion, have you double checked that the suggested fix changes the code semantics?

The Bug

The following code:

for index, value in enumerate([1, 2, 3]):
    print(value)
print(f"Last index {index}")

Emits the following error:

$ refurb foo.py
foo.py:1:5 [FURB148]: Index is unused, use `for value in [1, 2, 3]` instead

But it should not emit any error since index is used outside of the code

Version Info

Refurb: v2.0.0
Mypy: v1.10.0

Python Version

Python 3.12.0

Config File

# N/A

Extra Info

None

kasium avatar May 07 '24 12:05 kasium