summaryrefslogtreecommitdiffstatshomepage
path: root/tests/cpydiff/syntax_arg_unpacking.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/cpydiff/syntax_arg_unpacking.py
parent1e99d29f362f8cccc60a36fcbd8590404c719f40 (diff)
downloadmicropython-783b1a868fb0f3c1fd6cf7231311c24801c33505.tar.gz
micropython-783b1a868fb0f3c1fd6cf7231311c24801c33505.zip
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/cpydiff/syntax_arg_unpacking.py')
-rw-r--r--tests/cpydiff/syntax_arg_unpacking.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/cpydiff/syntax_arg_unpacking.py b/tests/cpydiff/syntax_arg_unpacking.py
new file mode 100644
index 0000000000..e54832ddb9
--- /dev/null
+++ b/tests/cpydiff/syntax_arg_unpacking.py
@@ -0,0 +1,23 @@
+"""
+categories: Syntax
+description: Argument unpacking does not work if the argument being unpacked is the nth or greater argument where n is the number of bits in an MP_SMALL_INT.
+cause: The implementation uses an MP_SMALL_INT to flag args that need to be unpacked.
+workaround: Use fewer arguments.
+"""
+
+
+def example(*args):
+ print(len(args))
+
+
+MORE = ["a", "b", "c"]
+
+# fmt: off
+example(
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ *MORE,
+)
+# fmt: on