summaryrefslogtreecommitdiff
path: root/tests/basics/fun_callstardblstar.py
diff options
context:
space:
mode:
authorDavid Lechner <david@lechnology.com>2020-03-24 23:54:45 -0500
committerDamien George <damien@micropython.org>2022-03-31 16:59:30 +1100
commit783b1a868fb0f3c1fd6cf7231311c24801c33505 (patch)
treecb182083ad7661e8026ce5b280e972511389beaa /tests/basics/fun_callstardblstar.py
parent1e99d29f362f8cccc60a36fcbd8590404c719f40 (diff)
py/runtime: Allow multiple *args in a function call.
This is a partial implementation of PEP 448 to allow unpacking multiple star args in a function or method call. This is implemented by changing the emitted bytecodes so that both positional args and star args are stored as positional args. A bitmap is added to indicate if an argument at a given position is a positional argument or a star arg. In the generated code, this new bitmap takes the place of the old star arg. It is stored as a small int, so this means only the first N arguments can be star args where N is the number of bits in a small int. The runtime is modified to interpret this new bytecode format while still trying to perform as few memory reallocations as possible. Signed-off-by: David Lechner <david@pybricks.com>
Diffstat (limited to 'tests/basics/fun_callstardblstar.py')
-rw-r--r--tests/basics/fun_callstardblstar.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/basics/fun_callstardblstar.py b/tests/basics/fun_callstardblstar.py
index f2fd29107..aceb04a84 100644
--- a/tests/basics/fun_callstardblstar.py
+++ b/tests/basics/fun_callstardblstar.py
@@ -6,6 +6,11 @@ def f(a, b, c, d):
f(*(1, 2), **{'c':3, 'd':4})
f(*(1, 2), **{['c', 'd'][i]:(3 + i) for i in range(2)})
+try:
+ eval("f(**{'a': 1}, *(2, 3, 4))")
+except SyntaxError:
+ print("SyntaxError")
+
# test calling a method with *tuple and **dict
class A:
@@ -15,3 +20,8 @@ class A:
a = A()
a.f(*(1, 2), **{'c':3, 'd':4})
a.f(*(1, 2), **{['c', 'd'][i]:(3 + i) for i in range(2)})
+
+try:
+ eval("a.f(**{'a': 1}, *(2, 3, 4))")
+except SyntaxError:
+ print("SyntaxError")