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
_______________________________________________
code-quality mailing list
code-quality@python.org
https://mail.python.org/mailman/listinfo/code-quality

Reply via email to