PyCQA/flake8-bugbear

Loop variable use in closure not considered

Aperta

#175 aperta il 11 lug 2021

 (1 commento) (0 reazioni) (0 assegnatari)Python (116 fork)github user discovery
enhancementhelp wanted

Metriche repository

Star
 (1116 stelle)
Metriche merge PR
 (Merge medio 4h 17m) (3 PR mergiate in 30 g)

Descrizione

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.

Guida contributor