From 9a2913ed1c57e6d167cad70d87ad32d504cb6f43 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 2 Aug 2015 20:53:54 +0100 Subject: [PATCH] py/objlist: Make list += accept all arguments and add test. --- py/objlist.c | 3 --- tests/basics/list_extend.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tests/basics/list_extend.py diff --git a/py/objlist.c b/py/objlist.c index 9404032128..21220441b5 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -121,9 +121,6 @@ STATIC mp_obj_t list_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { return MP_OBJ_UNCAST(s); } case MP_BINARY_OP_INPLACE_ADD: { - if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) { - return MP_OBJ_NULL; // op not supported - } list_extend(lhs, rhs); return lhs; } diff --git a/tests/basics/list_extend.py b/tests/basics/list_extend.py new file mode 100644 index 0000000000..21cdb41e69 --- /dev/null +++ b/tests/basics/list_extend.py @@ -0,0 +1,33 @@ +# test list.__iadd__ and list.extend (they are equivalent) + +l = [1, 2] +l.extend([]) +print(l) + +l.extend([3]) +print(l) + +l.extend([4, 5]) +print(l) + +l.extend(range(6, 10)) +print(l) + +l.extend("abc") +print(l) + +l = [1, 2] +l += [] +print(l) + +l += [3] +print(l) + +l += [4, 5] +print(l) + +l += range(6, 10) +print(l) + +l += "abc" +print(l)