Merge pull request #2357 from hyperbora/fix-memoryview-compare

fix memoryview compare
This commit is contained in:
Noah
2020-12-13 19:32:14 -06:00
committed by GitHub
3 changed files with 14 additions and 3 deletions

View File

@@ -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.

View File

@@ -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)
})

View File

@@ -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();