diff --git a/vm/src/builtins/memory.rs b/vm/src/builtins/memory.rs index a34d8db3a..8b1777356 100644 --- a/vm/src/builtins/memory.rs +++ b/vm/src/builtins/memory.rs @@ -1,6 +1,5 @@ use super::{ - PyBytes, PyBytesRef, PyInt, PyList, PyListRef, PySlice, PyStr, PyStrRef, PyTuple, PyTupleRef, - PyTypeRef, + PyBytes, PyBytesRef, PyInt, PyListRef, PySlice, PyStr, PyStrRef, PyTuple, PyTupleRef, PyTypeRef, }; use crate::common::{ borrow::{BorrowedValue, BorrowedValueMut}, @@ -630,15 +629,13 @@ impl PyMemoryView { )); } - let tup = shape.payload_if_subclass::(vm); - let list = shape.payload_if_subclass::(vm); - - let l = tup.map(|t| PyList::from(t.as_slice().iter().cloned().collect_vec())); - let list_from_tuple = l.as_ref(); - - let shape = list.xor(list_from_tuple).ok_or_else(|| { - vm.new_type_error("memoryview: must be a list or a tuple".to_owned()) - })?; + let shape = match shape { + Either::A(tup) => { + let elements = tup.as_slice().iter().cloned().collect_vec(); + vm.ctx.new_list(elements) + } + Either::B(list) => list, + }; let shape_vec = shape.borrow_vec(); let shape_ndim = shape_vec.len();