Skip to content

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

@kasium

Description

@kasium

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:

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions