PyCQA/flake8-bugbear

B031 flagged on non-itertools groupby

Offen

#356 geöffnet am 15.02.2023

 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Python (116 Forks)github user discovery
enhancementhelp wanted

Repository-Metriken

Stars
 (1.116 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 4h 17m) (3 gemergte PRs in 30 T)

Beschreibung

Recent B031 addition: https://github.com/PyCQA/flake8-bugbear/pull/347

A code that defines a groupby function (not itertools.groupby) will still raise B031 error.

Example:

def groupby(x, y):
    return dict().items()


for _, v in groupby(None, None):
    if v:
        ...
    if v:
        ...

Then:

$ flake8 example.py
example.py:8:8: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage. Save the result to a list, if the result is needed multiple times.

flake8: 6.0.0, flake8-bugbear: 23.2.13

Perhaps we can have a better inspection so the error is not raised in such cases?

Contributor Guide