PyCQA/flake8-bugbear

Loop variable use in closure not considered

Ouverte

#175 ouverte le 11 juil. 2021

 (1 commentaire) (0 réaction) (0 personne assignée)Python (116 forks)github user discovery
enhancementhelp wanted

Métriques du dépôt

Stars
 (1 116 étoiles)
Métriques de merge PR
 (Merge moyen 4h 17m) (3 PRs mergées en 30 j)

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.

Guide contributeur