Skip to content

New check: mutated loop variable #5072

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

Closed
nickdrozd opened this issue Sep 25, 2021 · 0 comments · Fixed by #5649
Closed

New check: mutated loop variable #5072

nickdrozd opened this issue Sep 25, 2021 · 0 comments · Fixed by #5649

Comments

@nickdrozd
Copy link
Contributor

Current problem

Here's one I came across in the wild the other day:

for i in range(5):
    print(i)
    i += 1

Pylint doesn't have any problem with it. In the real-world case I saw, it didn't cause a change in behavior, but the variable mutation line was unintended and unneeded.

Desired solution

Mutating the variable of a for-loop is most likely a mistake, and in any case it's not a very good practice. I would like Pylint to flag it, and I think such a check could be enabled by default without too much difficulty.

Additional context

No response

@nickdrozd nickdrozd added Enhancement ✨ Improvement to a component Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 25, 2021
@Pierre-Sassoulas Pierre-Sassoulas added Discussion 🤔 Proposal 📨 and removed Enhancement ✨ Improvement to a component Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 25, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.14.0 milestone Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants