PyCQA / flake8-bugbear

A plugin for Flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pycodestyle.
MIT License
1.06k stars 104 forks source link

B031 false positive when reassigning the returned generator #395

Open tomasr8 opened 1 year ago

tomasr8 commented 1 year ago

Code to reproduce:

from itertools import groupby

for _, gen in groupby([]):
    gen = list(gen)
    print(gen)

This wrongly triggers B031 even though the generator is indeed saved to a list as suggested in the error message. You can make the error go away by assigning to a new variable so maybe not worth it to track reassignments?