Python linter warning about variables used after for loop?

Viewed 31

Is there a linter / linter setting that will produce warnings when a variable that was defined inside a for/while loop is used after the end of the loop (at which point it will be whatever it was set to in the last loop iteration)? For example, I would like it to warn about the print statement here:

numbers = range(10)
for x in numbers:
    if x % 2 == 0:
        y = x
print(y)
0 Answers
Related