summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2020-01-23 09:25:17 (GMT)
committerGitHub <noreply@github.com>2020-01-23 09:25:17 (GMT)
commit13bc13960cc83dbd1cb5701d9a59ac9b9144b205 (patch)
tree582d8286864561b8a29be0491f837c22efd1f07e /Lib
parentf9e07e116c32b6dc4561d0bdeb452ccde13b0e7c (diff)
downloadcpython-13bc13960cc83dbd1cb5701d9a59ac9b9144b205.zip
cpython-13bc13960cc83dbd1cb5701d9a59ac9b9144b205.tar.gz
cpython-13bc13960cc83dbd1cb5701d9a59ac9b9144b205.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/importlib/_bootstrap_external.py4
-rw-r--r--Lib/opcode.py8
-rw-r--r--Lib/test/test_extcall.py4
3 files changed, 9 insertions, 7 deletions
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 @@ _code_type = type(_write_atomic.__code__)
# 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 @@ _code_type = type(_write_atomic.__code__)
# 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_AND', 77)
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 @@ hasfree.append(148)
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 @@ What about willful misconduct?
>>> 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):