Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

New rule: Unnecessary enumerate() #2608

Closed
ngnpope opened this issue Feb 6, 2023 · 1 comment
Closed

New rule: Unnecessary enumerate() #2608

ngnpope opened this issue Feb 6, 2023 · 1 comment

Comments

@ngnpope
Copy link
Contributor

ngnpope commented Feb 6, 2023

Fairly sure this is not covered by anything, but something I encountered due to autofixing B007.

Given the following example:

for i, s in enumerate("abc"):
    print(s)

I get the following output:

ruff --version
ruff 0.0.241ruff --isolated --select B007 bug.py 
bug.py:1:5: B007 [*] Loop control variable `i` not used within loop body
Found 1 error.
[*] 1 potentially fixable with the --fix option.ruff --isolated --select B007 --fix bug.py 
Found 1 error (1 fixed, 0 remaining).cat bug.py 
for _i, s in enumerate("abc"):
    print(s)

We could probably identify when builtins.enumerate() is being used and autofix to:

for s in "abc":
    print(s)
@ngnpope
Copy link
Contributor Author

ngnpope commented Feb 6, 2023

Ah, this is covered here by FURB148 / no-ignored-enumerate-items.

@ngnpope ngnpope closed this as completed Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant