PyCQA / PyCQA/flake8-bugbear

False positive `B023` with loop's local variable

Open
#402 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.1k
Forks
123
Avg merge
2d 5h
Merged PRs (30d)
5

Description

def some_fn(*_) -> None:
    ...


for _ in range(1):
    foo = 0
    some_fn(lambda: foo)

Since foo is a local variable in the loop, B023 shouldn't happen here (unless I am mistaken about something).

Running flake8==6.0.0 with flake8-bugbear==23.7.10 on this:

> flake8 a.py
a.py:7:21: B023 Function definition does not bind loop variable 'foo'.

I think this relates to https://github.com/PyCQA/flake8-bugbear/issues/269 or https://github.com/PyCQA/flake8-bugbear/issues/380.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report using the shown a.py example and the specified flake8 command. Then locate the B023 implementation and its existing tests, and add coverage showing that a loop-local variable should not trigger B023; done means the example produces no B023 while genuine loop-variable cases remain detected.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.