[code-quality] This seems like a good warning candidate...
Skip Montanaro
skip.montanaro at gmail.com
Mon Dec 8 19:16:45 CET 2014
I just bumped into a bug, reusing the same loop variable in two nested for
loops. Here's an example:
def f(x):
for i in range(x):
for i in [1, 2, 3]:
print i
Neither pylint nor flake8 warned about this problematic usage. Had i or x
shadowed a global of the same name, pylint would have complained, e.g.:
x = 7
def f(x):
for i in range(x):
for i in [1, 2, 3]:
x = i
print i, x
Using the same variable in nested loops within the same function seems at
least as serious as a shadowed global (or builtin) name.
Skip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/code-quality/attachments/20141208/3b767da2/attachment.html>
More information about the code-quality
mailing list