mirror of
https://github.com/AdaCore/cpython.git
synced 2026-02-12 12:57:15 -08:00
Issue #28257: Improved error message when pass a non-iterable as
a var-positional argument. Added opcode BUILD_TUPLE_UNPACK_WITH_CALL.
This commit is contained in:
@@ -125,6 +125,7 @@ extern "C" {
|
||||
#define FORMAT_VALUE 155
|
||||
#define BUILD_CONST_KEY_MAP 156
|
||||
#define BUILD_STRING 157
|
||||
#define BUILD_TUPLE_UNPACK_WITH_CALL 158
|
||||
|
||||
/* EXCEPT_HANDLER is a special, implicit block type which is created when
|
||||
entering an except handler. It is not an opcode but we define it here
|
||||
|
||||
@@ -238,6 +238,7 @@ _code_type = type(_write_atomic.__code__)
|
||||
# #27985)
|
||||
# Python 3.6b1 3376 (simplify CALL_FUNCTIONs & BUILD_MAP_UNPACK_WITH_CALL)
|
||||
# Python 3.6b1 3377 (set __class__ cell from type.__new__ #23722)
|
||||
# Python 3.6b2 3378 (add BUILD_TUPLE_UNPACK_WITH_CALL #28257)
|
||||
#
|
||||
# MAGIC must change whenever the bytecode emitted by the compiler may no
|
||||
# longer be understood by older implementations of the eval loop (usually
|
||||
@@ -246,7 +247,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 = (3377).to_bytes(2, 'little') + b'\r\n'
|
||||
MAGIC_NUMBER = (3378).to_bytes(2, 'little') + b'\r\n'
|
||||
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
|
||||
|
||||
_PYCACHE = '__pycache__'
|
||||
|
||||
@@ -196,8 +196,6 @@ def_op('MAP_ADD', 147)
|
||||
def_op('LOAD_CLASSDEREF', 148)
|
||||
hasfree.append(148)
|
||||
|
||||
jrel_op('SETUP_ASYNC_WITH', 154)
|
||||
|
||||
def_op('EXTENDED_ARG', 144)
|
||||
EXTENDED_ARG = 144
|
||||
|
||||
@@ -207,8 +205,11 @@ 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)
|
||||
|
||||
del def_op, name_op, jrel_op, jabs_op
|
||||
|
||||
@@ -233,6 +233,16 @@ What about willful misconduct?
|
||||
...
|
||||
TypeError: h() argument after * must be an iterable, not function
|
||||
|
||||
>>> h(1, *h)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
TypeError: h() argument after * must be an iterable, not function
|
||||
|
||||
>>> h(*[1], *h)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
TypeError: h() argument after * must be an iterable, not function
|
||||
|
||||
>>> dir(*h)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
|
||||
@@ -46,6 +46,9 @@ Core and Builtins
|
||||
Library
|
||||
-------
|
||||
|
||||
- Issue #28257: Improved error message when pass a non-iterable as
|
||||
a var-positional argument. Added opcode BUILD_TUPLE_UNPACK_WITH_CALL.
|
||||
|
||||
- Issue #28322: Fixed possible crashes when unpickle itertools objects from
|
||||
incorrect pickle data. Based on patch by John Leitch.
|
||||
|
||||
|
||||
@@ -2509,9 +2509,10 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(BUILD_TUPLE_UNPACK_WITH_CALL)
|
||||
TARGET(BUILD_TUPLE_UNPACK)
|
||||
TARGET(BUILD_LIST_UNPACK) {
|
||||
int convert_to_tuple = opcode == BUILD_TUPLE_UNPACK;
|
||||
int convert_to_tuple = opcode != BUILD_LIST_UNPACK;
|
||||
Py_ssize_t i;
|
||||
PyObject *sum = PyList_New(0);
|
||||
PyObject *return_value;
|
||||
@@ -2524,6 +2525,16 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
|
||||
|
||||
none_val = _PyList_Extend((PyListObject *)sum, PEEK(i));
|
||||
if (none_val == NULL) {
|
||||
if (opcode == BUILD_TUPLE_UNPACK_WITH_CALL &&
|
||||
PyErr_ExceptionMatches(PyExc_TypeError)) {
|
||||
PyObject *func = PEEK(1 + oparg);
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s%.200s argument after * "
|
||||
"must be an iterable, not %.200s",
|
||||
PyEval_GetFuncName(func),
|
||||
PyEval_GetFuncDesc(func),
|
||||
PEEK(i)->ob_type->tp_name);
|
||||
}
|
||||
Py_DECREF(sum);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -987,9 +987,9 @@ PyCompile_OpcodeStackEffect(int opcode, int oparg)
|
||||
return 1-oparg;
|
||||
case BUILD_LIST_UNPACK:
|
||||
case BUILD_TUPLE_UNPACK:
|
||||
case BUILD_TUPLE_UNPACK_WITH_CALL:
|
||||
case BUILD_SET_UNPACK:
|
||||
case BUILD_MAP_UNPACK:
|
||||
return 1 - oparg;
|
||||
case BUILD_MAP_UNPACK_WITH_CALL:
|
||||
return 1 - oparg;
|
||||
case BUILD_MAP:
|
||||
@@ -3549,7 +3549,7 @@ compiler_call_helper(struct compiler *c,
|
||||
if (nsubargs > 1) {
|
||||
/* If we ended up with more than one stararg, we need
|
||||
to concatenate them into a single sequence. */
|
||||
ADDOP_I(c, BUILD_TUPLE_UNPACK, nsubargs);
|
||||
ADDOP_I(c, BUILD_TUPLE_UNPACK_WITH_CALL, nsubargs);
|
||||
}
|
||||
else if (nsubargs == 0) {
|
||||
ADDOP_I(c, BUILD_TUPLE, 0);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -157,7 +157,7 @@ static void *opcode_targets[256] = {
|
||||
&&TARGET_FORMAT_VALUE,
|
||||
&&TARGET_BUILD_CONST_KEY_MAP,
|
||||
&&TARGET_BUILD_STRING,
|
||||
&&_unknown_opcode,
|
||||
&&TARGET_BUILD_TUPLE_UNPACK_WITH_CALL,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
|
||||
Reference in New Issue
Block a user