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

B031 does not take into account if-else statements #465

Open
amyasnikov opened this issue Mar 24, 2024 · 0 comments
Open

B031 does not take into account if-else statements #465

amyasnikov opened this issue Mar 24, 2024 · 0 comments

Comments

@amyasnikov
Copy link

Bugbear reports false-positive "more that one" usage of the generator even if it occurs inside 2 different branches of the if-else statement.

This code

import itertools

for _, group in itertools.groupby([]):
    if True:
        print(group, True)
    else:
        print(group, False)

produces

b031.py:7:15: 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.

but it's obvious that group cannot be used twice here.

flake8 --version:

7.0.0 (flake8-bugbear: 24.2.6, mccabe: 0.7.0, pycodestyle: 2.11.1, pyflakes: 3.2.0) CPython 3.11.2 on Linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant