Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B023: false positive for nested function inside loop #468

Open
fwinkl opened this issue Apr 25, 2024 · 1 comment
Open

B023: false positive for nested function inside loop #468

fwinkl opened this issue Apr 25, 2024 · 1 comment

Comments

@fwinkl
Copy link

fwinkl commented Apr 25, 2024

The following (admittedly bad) code produces what I think must be a false positive:

for _ in range(10):
   foo = []
   def bar():
      foo.append(42)

   bar()
test.py:4:7: B023 Function definition does not bind loop variable 'foo'.

At the very least the warning is confusing because foo is not actually a loop variable.

Using:

flake8 --version
7.0.0 (flake8-bugbear: 24.2.6, flake8-builtins: 2.5.0, mccabe: 0.7.0, pycodestyle: 2.11.1, pyflakes: 3.2.0) CPython 3.10.12 on Linux
@cooperlees
Copy link
Collaborator

cooperlees commented Apr 26, 2024

Agree. I think we should ignore this, even tho I'd never want it in my code bases. I don't think this is particularly worth a dedicated check here, but could be convinced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants