Skip to content

test_inplace_on_self now works in test_set and test_weakset #4708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 0 additions & 2 deletions Lib/test/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,6 @@ def test_ixor(self):
else:
self.assertNotIn(c, self.s)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_inplace_on_self(self):
t = self.s.copy()
t |= t
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_weakset.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,6 @@ def test_ixor(self):
else:
self.assertNotIn(c, self.s)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_inplace_on_self(self):
t = self.s.copy()
t |= t
Expand Down
19 changes: 13 additions & 6 deletions vm/src/builtins/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,16 +384,18 @@ impl PySetInner {
others: impl std::iter::Iterator<Item = ArgIterable>,
vm: &VirtualMachine,
) -> PyResult<()> {
let mut temp_inner = self.copy();
self.clear();
for iterable in others {
let temp_inner = PySetInner::default();
for item in iterable.iter(vm)? {
let obj = item?;
if temp_inner.contains(&obj, vm)? {
self.add(obj, vm)?;
if self.contains(&obj, vm)? {
temp_inner.add(obj, vm)?;
}
}
temp_inner = self.copy()
self.clear();
for item in temp_inner.elements() {
self.add(item, vm)?;
}
}
Ok(())
}
Expand All @@ -403,11 +405,16 @@ impl PySetInner {
others: impl std::iter::Iterator<Item = ArgIterable>,
vm: &VirtualMachine,
) -> PyResult<()> {
let temp_inner = self.copy();
for iterable in others {
for item in iterable.iter(vm)? {
self.content.delete_if_exists(vm, &*item?)?;
temp_inner.content.delete_if_exists(vm, &*item?)?;
}
}
self.clear();
for item in temp_inner.elements() {
self.add(item, vm)?;
}
Ok(())
}

Expand Down