BUG/QUESTION: Not sure if B020 is expected to trigger here
See original GitHub issuerunning flake8 with the latest version of bugbear on this snippet
for var in (var for var in range(10) if var % 2):
print(var)
results in
t.py:1:5: B020 Found for loop that reassigns the iterable it is iterating with each iterable value.
Is this expected ? I don’t understand how the error message relates to what’s actually happening here, it seems to me that this could be a mistake.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Vscode todo - Bildgewalt - Production
Following the instructions here, press Ctrl+Shift+P, type Run Tasks, select it and ... When the build is finished, restart VSCode to complete the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’ve made a PR to these false positives 👍
It’s comprehensions in general not just generators that have this issue
N.B. we don’t want to exclude comprehensions from this check completely. This example is still bad and should be flagged:
So I think the rule needs to account for the fact that variables declared in the
forclause of a comprehension are local to the scope of that comprehension and should be excluded from the check.