bpo-39320: Handle unpacking of *values in compiler (GH-17984)
* Add three new bytecodes: LIST_TO_TUPLE, LIST_EXTEND, SET_UPDATE. Use them to implement star unpacking expressions.
* Remove four bytecodes BUILD_LIST_UNPACK, BUILD_TUPLE_UNPACK, BUILD_SET_UNPACK and BUILD_TUPLE_UNPACK_WITH_CALL opcodes as they are now unused.
* Update magic number and dis.rst for new bytecodes.
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index b86612b..6c703fa 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -275,6 +275,8 @@
# Python 3.9a0 3421 (simplified bytecode for with blocks #32949)
# Python 3.9a0 3422 (remove BEGIN_FINALLY, END_FINALLY, CALL_FINALLY, POP_FINALLY bytecodes #33387)
# Python 3.9a2 3423 (add IS_OP, CONTAINS_OP and JUMP_IF_NOT_EXC_MATCH bytecodes #39156)
+# Python 3.9a2 3424 (simplify bytecodes for *value unpacking)
+
#
# MAGIC must change whenever the bytecode emitted by the compiler may no
# longer be understood by older implementations of the eval loop (usually
@@ -283,7 +285,7 @@
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.
-MAGIC_NUMBER = (3423).to_bytes(2, 'little') + b'\r\n'
+MAGIC_NUMBER = (3424).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
_PYCACHE = '__pycache__'
diff --git a/Lib/opcode.py b/Lib/opcode.py
index e31563b..5bc2ddc 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -117,6 +117,7 @@
def_op('INPLACE_XOR', 78)
def_op('INPLACE_OR', 79)
+def_op('LIST_TO_TUPLE', 82)
def_op('RETURN_VALUE', 83)
def_op('IMPORT_STAR', 84)
def_op('SETUP_ANNOTATIONS', 85)
@@ -199,20 +200,19 @@
def_op('EXTENDED_ARG', 144)
EXTENDED_ARG = 144
-def_op('BUILD_LIST_UNPACK', 149)
def_op('BUILD_MAP_UNPACK', 150)
def_op('BUILD_MAP_UNPACK_WITH_CALL', 151)
-def_op('BUILD_TUPLE_UNPACK', 152)
-def_op('BUILD_SET_UNPACK', 153)
jrel_op('SETUP_ASYNC_WITH', 154)
def_op('FORMAT_VALUE', 155)
def_op('BUILD_CONST_KEY_MAP', 156)
def_op('BUILD_STRING', 157)
-def_op('BUILD_TUPLE_UNPACK_WITH_CALL', 158)
name_op('LOAD_METHOD', 160)
def_op('CALL_METHOD', 161)
+def_op('LIST_EXTEND', 162)
+def_op('SET_UPDATE', 163)
+
del def_op, name_op, jrel_op, jabs_op
diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py
index 4edb668..1faf29e 100644
--- a/Lib/test/test_extcall.py
+++ b/Lib/test/test_extcall.py
@@ -252,12 +252,12 @@
>>> h(1, *h)
Traceback (most recent call last):
...
- TypeError: test.test_extcall.h() argument after * must be an iterable, not function
+ TypeError: Value after * must be an iterable, not function
>>> h(*[1], *h)
Traceback (most recent call last):
...
- TypeError: test.test_extcall.h() argument after * must be an iterable, not function
+ TypeError: Value after * must be an iterable, not function
>>> dir(*h)
Traceback (most recent call last):