forked from Rust-related/RustPython
Merge pull request #2357 from hyperbora/fix-memoryview-compare
fix memoryview compare
This commit is contained in:
@@ -150,8 +150,6 @@ class AbstractMemoryTests:
|
||||
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.
|
||||
|
||||
@@ -531,6 +531,16 @@ impl Comparable for PyBytes {
|
||||
) -> PyResult<PyComparisonValue> {
|
||||
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)
|
||||
})
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user