Skip to content

Loop variable use in closure not considered #175

@inducer

Description

@inducer

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions