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
1 change: 0 additions & 1 deletion Lib/test/test_contains.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def __getitem__(self, n):
return [self.el][n]

class TestContains(unittest.TestCase):
@unittest.expectedFailure # TODO: RUSTPYTHON; Wrong error message
def test_common_tests(self):
a = base_set(1)
b = myset(1)
Expand Down
16 changes: 14 additions & 2 deletions crates/vm/src/protocol/sequence.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
AsObject, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
builtins::{PyList, PyListRef, PySlice, PyTuple, PyTupleRef},
convert::ToPyObject,
function::PyArithmeticValue,
Expand Down Expand Up @@ -398,7 +398,19 @@ impl PySequence<'_> {
return f(self, target, vm);
}

let iter = self.obj.to_owned().get_iter(vm)?;
// CPython parity: when neither __contains__ nor __iter__ is available,
// `PySequence_Contains` rewords the get_iter TypeError into the
// membership-test wording. Other exception types propagate unchanged.
let iter = self.obj.to_owned().get_iter(vm).map_err(|e| {
if e.fast_isinstance(vm.ctx.exceptions.type_error) {
vm.new_type_error(format!(
"argument of type '{}' is not a container or iterable",
self.obj.class().name()
))
} else {
e
}
})?;
let iter = iter.iter::<PyObjectRef>(vm)?;

for elem in iter {
Expand Down
Loading