From eb2784e8a2dc17b0f551b68d2b41eece3e5348a7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 9 Aug 2017 21:20:42 +1000 Subject: [PATCH] py/objtuple: Allow to use inplace-multiplication operator on tuples. --- py/objtuple.c | 3 ++- tests/basics/tuple_mult.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/py/objtuple.c b/py/objtuple.c index 0b05755fb3..cbe6454943 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -148,7 +148,8 @@ mp_obj_t mp_obj_tuple_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { mp_seq_cat(s->items, o->items, o->len, p->items, p->len, mp_obj_t); return MP_OBJ_FROM_PTR(s); } - case MP_BINARY_OP_MULTIPLY: { + case MP_BINARY_OP_MULTIPLY: + case MP_BINARY_OP_INPLACE_MULTIPLY: { mp_int_t n; if (!mp_obj_get_int_maybe(rhs, &n)) { return MP_OBJ_NULL; // op not supported diff --git a/tests/basics/tuple_mult.py b/tests/basics/tuple_mult.py index b128b29689..cac95185a0 100644 --- a/tests/basics/tuple_mult.py +++ b/tests/basics/tuple_mult.py @@ -11,6 +11,11 @@ a = (1, 2, 3) c = a * 3 print(a, c) +# inplace multiplication +a = (1, 2) +a *= 2 +print(a) + # unsupported type on RHS try: () * None