You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from __future__ importannotationsfromitertoolsimportgroupbydefruff_b031_false_positive(values: list[int]) ->None:
forkey, groupingroupby(values):
ifkey:
list(group)
continue# or break or returnlist(group)
$ ruff check --isolated --select B031 testcase.pytestcase.py:10:14: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usageFound 1 error.
There have been fixes for when the generator is used in different branches of an if statements, see for example #4050, but the warning still triggers if you use continue, break, or return. Tested with Ruff version 0.3.2.
The text was updated successfully, but these errors were encountered:
I think this can be solved. We would need to consider the block outside the if statement as if it's mutually exclusive with the if block if there's a continue / break / return as the last statement in the if block.
@yt2b Sure! It might be a bit tricky to get it right because we don't have control flow graph and the implementation uses visitor and stack to simulate it. This comment has a visualization on what it looks like. Feel free to ping me with any questions you might have :)
There have been fixes for when the generator is used in different branches of an
if
statements, see for example #4050, but the warning still triggers if you usecontinue
,break
, orreturn
. Tested with Ruff version 0.3.2.The text was updated successfully, but these errors were encountered: