diff options
| author | Damien George <damien@micropython.org> | 2023-05-12 23:16:37 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-05-19 13:44:00 +1000 |
| commit | ea7031faff9efe6803d8a8f67ad2e3b4a6d390e3 (patch) | |
| tree | 71faadf644033b57a5e1339102148719ae20a155 /tests | |
| parent | 4b57330465b98df30ef8a10e19a0e197b5797550 (diff) | |
py/runtime: If inplace binop fails then try corresponding normal binop.
The code that handles inplace-operator to normal-binary-operator fallback
is moved in this commit from py/objtype.c to py/runtime.c, making it apply
to all types, not just user classes.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/basics/class_reverse_op.py | 5 | ||||
| -rw-r--r-- | tests/basics/list_mult.py | 10 | ||||
| -rw-r--r-- | tests/basics/string_mult.py | 10 |
3 files changed, 25 insertions, 0 deletions
diff --git a/tests/basics/class_reverse_op.py b/tests/basics/class_reverse_op.py index 11aba6aad..915b3a9ef 100644 --- a/tests/basics/class_reverse_op.py +++ b/tests/basics/class_reverse_op.py @@ -46,3 +46,8 @@ print("a" | B("b")) print("a" + B("b")) print("a" * B("b")) print("a" / B("b")) + +x = "a"; x |= B("b"); print(x) +x = "a"; x += B("b"); print(x) +x = "a"; x *= B("b"); print(x) +x = "a"; x /= B("b"); print(x) diff --git a/tests/basics/list_mult.py b/tests/basics/list_mult.py index 548f88534..125c548ee 100644 --- a/tests/basics/list_mult.py +++ b/tests/basics/list_mult.py @@ -11,6 +11,16 @@ a = [1, 2, 3] c = a * 3 print(a, c) +# check inplace multiplication +a = [4, 5, 6] +a *= 3 +print(a) + +# check reverse inplace multiplication +a = 3 +a *= [7, 8, 9] +print(a) + # unsupported type on RHS try: [] * None diff --git a/tests/basics/string_mult.py b/tests/basics/string_mult.py index c0713c1d3..5a7d82294 100644 --- a/tests/basics/string_mult.py +++ b/tests/basics/string_mult.py @@ -10,3 +10,13 @@ for i in (-4, -2, 0, 2, 4): a = '123' c = a * 3 print(a, c) + +# check inplace multiplication +a = '456' +a *= 3 +print(a) + +# check reverse inplace multiplication +a = 3 +a *= '789' +print(a) |
