summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2023-05-12 23:14:44 +1000
committerDamien George <damien@micropython.org>2023-05-19 13:33:54 +1000
commitca9068e0efc5e53ff7042ef68ad4a4ec9ff91915 (patch)
tree4e277242f5af8d056cc222ccefa540277ba917dc
parent9accb7dd446f7f17720f574d0449c294c4df1685 (diff)
py/objarray: Disallow memoryview addition.
Following CPython. This is important for subsequent commits to work correctly. Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--py/objarray.c6
-rw-r--r--tests/basics/op_error_memoryview.py12
2 files changed, 17 insertions, 1 deletions
diff --git a/py/objarray.c b/py/objarray.c
index 0d9411d7c..a3adb255e 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -292,6 +292,12 @@ STATIC mp_obj_t array_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs
mp_obj_array_t *lhs = MP_OBJ_TO_PTR(lhs_in);
switch (op) {
case MP_BINARY_OP_ADD: {
+ #if MICROPY_PY_BUILTINS_MEMORYVIEW
+ if (lhs->base.type == &mp_type_memoryview) {
+ return MP_OBJ_NULL; // op not supported
+ }
+ #endif
+
// allow to add anything that has the buffer protocol (extension to CPython)
mp_buffer_info_t lhs_bufinfo;
mp_buffer_info_t rhs_bufinfo;
diff --git a/tests/basics/op_error_memoryview.py b/tests/basics/op_error_memoryview.py
index 233f7f9ab..485370428 100644
--- a/tests/basics/op_error_memoryview.py
+++ b/tests/basics/op_error_memoryview.py
@@ -7,7 +7,17 @@ except:
# unsupported binary operators
try:
+ memoryview(b"") + b""
+except TypeError:
+ print("TypeError")
+
+try:
+ memoryview(b"") + memoryview(b"")
+except TypeError:
+ print("TypeError")
+
+try:
m = memoryview(bytearray())
m += bytearray()
except TypeError:
- print('TypeError')
+ print("TypeError")