Skip to content

fix memoryview compare #2357

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

Merged
merged 1 commit into from
Dec 14, 2020
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
2 changes: 0 additions & 2 deletions Lib/test/test_memoryview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions vm/src/builtins/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
5 changes: 4 additions & 1 deletion vm/src/builtins/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down