-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
help wantedContributions especially welcomeContributions especially welcomeruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
Summary
The B909 rule checks for mutations to loop iterables, but permits cases where return/break would prevent further iterations. However if the return and the mutation are the same statement it flags the value.
Example:
def fail_map(mapping):
for key in mapping:
return mapping.pop(key) # false positive
def success_map(mapping):
for key in mapping:
ret = mapping.pop(key) # passes
return ret
def fail_list(seq):
for val in seq:
return seq.pop(4) # also false positiveUsed ruff check --preview --isolated --select B909 iter_mut_bug.py.
Version
ruff 0.11.11 (0397682 2025-05-22)
Metadata
Metadata
Assignees
Labels
help wantedContributions especially welcomeContributions especially welcomeruleImplementing or modifying a lint ruleImplementing or modifying a lint rule