the rule seems to check whether or not the loop has a break after the mutation, because that makes the mutation safe:
items = [1, 2, 3]
for item in items:
items.append(item) # no error
break
however i've noticed two issues with this logic:
-
it doesn't seem to account for when there's another statement between the mutation and the break:
items = [1, 2, 3]
for item in items:
items.append(item)
if True:
pass
break # error
this should still be considered safe, because the statement does not effect the flow of the loop at all.
-
if there's a continue statement followed by a break statement, it does not report an error, even though the mutation is unsafe:
items = [1, 2, 3]
for item in items:
items.remove(item)
continue
break
playground
the rule seems to check whether or not the loop has a
breakafter the mutation, because that makes the mutation safe:however i've noticed two issues with this logic:
it doesn't seem to account for when there's another statement between the mutation and the
break:this should still be considered safe, because the statement does not effect the flow of the loop at all.
if there's a
continuestatement followed by abreakstatement, it does not report an error, even though the mutation is unsafe:playground