Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/flake8_bugbear/B909.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,17 @@ def func():
for elem in some_list:
if some_list.pop() == 2:
return

# should not error - direct return with mutation (Issue #18399)
def fail_map(mapping):
for key in mapping:
return mapping.pop(key)

def success_map(mapping):
for key in mapping:
ret = mapping.pop(key) # should not error
return ret

def fail_list(seq):
for val in seq:
return seq.pop(4)
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ impl<'a> Visitor<'a> for LoopMutationsVisitor<'a> {
if let Some(mutations) = self.mutations.get_mut(&self.branch) {
mutations.clear();
}
visitor::walk_stmt(self, stmt);
}

// Avoid recursion for class and function definitions.
Expand Down
Loading