Skip to content

Commit 8589b55

Browse files
authored
Avoid set changed size during iteration (RustPython#5860)
1 parent 8cac433 commit 8589b55

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

Lib/test/test_set.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,6 @@ def test_ixor(self):
582582
else:
583583
self.assertNotIn(c, self.s)
584584

585-
# TODO: RUSTPYTHON
586-
@unittest.expectedFailure
587585
def test_inplace_on_self(self):
588586
t = self.s.copy()
589587
t |= t

vm/src/builtins/set.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,9 @@ impl PySetInner {
426426
vm: &VirtualMachine,
427427
) -> PyResult<()> {
428428
for iterable in others {
429-
for item in iterable.iter(vm)? {
430-
self.content.delete_if_exists(vm, &*item?)?;
429+
let items = iterable.iter(vm)?.collect::<Result<Vec<_>, _>>()?;
430+
for item in items {
431+
self.content.delete_if_exists(vm, &*item)?;
431432
}
432433
}
433434
Ok(())

0 commit comments

Comments
 (0)