diff --git a/Lib/test/test_memoryview.py b/Lib/test/test_memoryview.py index a869a6ca9c..2cd5e90a89 100644 --- a/Lib/test/test_memoryview.py +++ b/Lib/test/test_memoryview.py @@ -150,8 +150,6 @@ def test_tolist(self): l = m.tolist() self.assertEqual(l, list(b"abcdef")) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_compare(self): # memoryviews can compare for equality with other objects # having the buffer interface. diff --git a/vm/src/builtins/bytes.rs b/vm/src/builtins/bytes.rs index 9109a2d7de..b1198b6920 100644 --- a/vm/src/builtins/bytes.rs +++ b/vm/src/builtins/bytes.rs @@ -531,6 +531,16 @@ impl Comparable for PyBytes { ) -> PyResult { Ok(if let Some(res) = op.identical_optimization(zelf, other) { res.into() + } else if other.isinstance(&vm.ctx.types.memoryview_type) + && op != PyComparisonOp::Eq + && op != PyComparisonOp::Ne + { + return Err(vm.new_type_error(format!( + "'{}' not supported between instances of '{}' and '{}'", + op.operator_token(), + zelf.class().name, + other.class().name + ))); } else { zelf.inner.cmp(other, op, vm) }) diff --git a/vm/src/builtins/memory.rs b/vm/src/builtins/memory.rs index 55afcc08b9..35497bc8e5 100644 --- a/vm/src/builtins/memory.rs +++ b/vm/src/builtins/memory.rs @@ -711,7 +711,10 @@ impl PyMemoryView { return Ok(false); } - let other = try_buffer_from_object(vm, other)?; + let other = match try_buffer_from_object(vm, other) { + Ok(buf) => buf, + Err(_) => return Ok(false), + }; let a_options = &zelf.options; let b_options = other.get_options();