PyCQA/flake8-bugbear

Loop variable use in closure not considered

Open

#175 opened on Jul 11, 2021

 (1 comment) (0 reactions) (0 assignees)Python (116 forks)github user discovery
enhancementhelp wanted

Repository metrics

Stars
 (1,116 stars)
PR merge metrics
 (Avg merge 4h 17m) (3 merged PRs in 30d)

Description

Running

flake8==3.9.2
flake8-bugbear==21.4.3
flake8-polyfill==1.0.2
flake8-quotes==3.2.0

on

def main():
    def f(x):
        print(i, x)

    for i in [1, 2, 3]:
        f('HI')

gives me

bugbearbug.py:5:9: B007 Loop control variable 'i' not used within the loop body. If this is intended, start the name with an underscore.

Clearly, i is being used (within the nested function), but bugbear doesn't seem to see it.

Contributor guide