After upgrading to v0.0.262, I'm getting a false B031 error for multiple uses of a generator from itertools.groupby:
x = dict()
for key, group in itertools.groupby(x, lambda x: x):
if key:
for n in group:
print(n)
else:
list(group)
This code will result in B031 Using the generator returned from itertools.groupby() more than once will do nothing on the second usage. However, if I do not have a loop in the if block, I do not get the error, so as far as I can tell, it seems to be specific to loops (including comprehensions). This appears to be a case not caught by the fix in #3801