summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2022-03-04 12:41:17 (GMT)
committerGitHub <noreply@github.com>2022-03-04 12:41:17 (GMT)
commit586b24d3be1aec5d2568b070a249b4d75e608782 (patch)
treee5e92e960433634f839118b51039a3fec3429d3e /Python
parent03c2a36b2bd2d4469160d1607619ee144175d753 (diff)
downloadcpython-586b24d3be1aec5d2568b070a249b4d75e608782.zip
cpython-586b24d3be1aec5d2568b070a249b4d75e608782.tar.gz
cpython-586b24d3be1aec5d2568b070a249b4d75e608782.tar.bz2
bpo-46841: Fix error message hacks in `GET_AWAITABLE` (GH-31664)
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c16
-rw-r--r--Python/compile.c12
-rw-r--r--Python/opcode_targets.h6
3 files changed, 14 insertions, 20 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 915ab93..67c8b46 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -95,7 +95,7 @@ static int check_args_iterable(PyThreadState *, PyObject *func, PyObject *vararg
static int check_except_type_valid(PyThreadState *tstate, PyObject* right);
static int check_except_star_type_valid(PyThreadState *tstate, PyObject* right);
static void format_kwargs_error(PyThreadState *, PyObject *func, PyObject *kwargs);
-static void format_awaitable_error(PyThreadState *, PyTypeObject *, int, int);
+static void format_awaitable_error(PyThreadState *, PyTypeObject *, int);
static int get_exception_handler(PyCodeObject *, int, int*, int*, int*);
static _PyInterpreterFrame *
_PyEvalFramePushAndInit(PyThreadState *tstate, PyFunctionObject *func,
@@ -2505,13 +2505,7 @@ handle_eval_breaker:
PyObject *iter = _PyCoro_GetAwaitableIter(iterable);
if (iter == NULL) {
- int opcode_at_minus_4 = 0;
- if ((next_instr - first_instr) > 4) {
- opcode_at_minus_4 = _Py_OPCODE(next_instr[-4]);
- }
- format_awaitable_error(tstate, Py_TYPE(iterable),
- opcode_at_minus_4,
- _Py_OPCODE(next_instr[-2]));
+ format_awaitable_error(tstate, Py_TYPE(iterable), oparg);
}
Py_DECREF(iterable);
@@ -7638,16 +7632,16 @@ format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg)
}
static void
-format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevprevopcode, int prevopcode)
+format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int oparg)
{
if (type->tp_as_async == NULL || type->tp_as_async->am_await == NULL) {
- if (prevopcode == BEFORE_ASYNC_WITH) {
+ if (oparg == 1) {
_PyErr_Format(tstate, PyExc_TypeError,
"'async with' received an object from __aenter__ "
"that does not implement __await__: %.100s",
type->tp_name);
}
- else if (prevopcode == WITH_EXCEPT_START || (prevopcode == CALL && prevprevprevopcode == LOAD_CONST)) {
+ else if (oparg == 2) {
_PyErr_Format(tstate, PyExc_TypeError,
"'async with' received an object from __aexit__ "
"that does not implement __await__: %.100s",
diff --git a/Python/compile.c b/Python/compile.c
index 14595d9..ac9ddbc 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1978,7 +1978,7 @@ compiler_unwind_fblock(struct compiler *c, struct fblockinfo *info,
return 0;
}
if (info->fb_type == ASYNC_WITH) {
- ADDOP(c, GET_AWAITABLE);
+ ADDOP_I(c, GET_AWAITABLE, 2);
ADDOP_LOAD_CONST(c, Py_None);
ADD_YIELD_FROM(c, 1);
}
@@ -5353,7 +5353,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
ADDOP_I(c, CALL, 0);
if (is_async_generator && type != COMP_GENEXP) {
- ADDOP(c, GET_AWAITABLE);
+ ADDOP_I(c, GET_AWAITABLE, 0);
ADDOP_LOAD_CONST(c, Py_None);
ADD_YIELD_FROM(c, 1);
}
@@ -5485,7 +5485,7 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos)
VISIT(c, expr, item->context_expr);
ADDOP(c, BEFORE_ASYNC_WITH);
- ADDOP(c, GET_AWAITABLE);
+ ADDOP_I(c, GET_AWAITABLE, 1);
ADDOP_LOAD_CONST(c, Py_None);
ADD_YIELD_FROM(c, 1);
@@ -5522,7 +5522,7 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos)
SET_LOC(c, s);
if(!compiler_call_exit_with_nones(c))
return 0;
- ADDOP(c, GET_AWAITABLE);
+ ADDOP_I(c, GET_AWAITABLE, 2);
ADDOP_LOAD_CONST(c, Py_None);
ADD_YIELD_FROM(c, 1);
@@ -5536,7 +5536,7 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos)
ADDOP_JUMP(c, SETUP_CLEANUP, cleanup);
ADDOP(c, PUSH_EXC_INFO);
ADDOP(c, WITH_EXCEPT_START);
- ADDOP(c, GET_AWAITABLE);
+ ADDOP_I(c, GET_AWAITABLE, 2);
ADDOP_LOAD_CONST(c, Py_None);
ADD_YIELD_FROM(c, 1);
compiler_with_except_finish(c, cleanup);
@@ -5710,7 +5710,7 @@ compiler_visit_expr1(struct compiler *c, expr_ty e)
}
VISIT(c, expr, e->v.Await.value);
- ADDOP(c, GET_AWAITABLE);
+ ADDOP_I(c, GET_AWAITABLE, 0);
ADDOP_LOAD_CONST(c, Py_None);
ADD_YIELD_FROM(c, 1);
break;
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index 7be7b16..2060793 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -72,15 +72,15 @@ static void *opcode_targets[256] = {
&&TARGET_PRINT_EXPR,
&&TARGET_LOAD_BUILD_CLASS,
&&TARGET_PRECALL_NO_KW_ISINSTANCE,
- &&TARGET_GET_AWAITABLE,
+ &&TARGET_PRECALL_NO_KW_LIST_APPEND,
&&TARGET_LOAD_ASSERTION_ERROR,
&&TARGET_RETURN_GENERATOR,
- &&TARGET_PRECALL_NO_KW_LIST_APPEND,
&&TARGET_PRECALL_NO_KW_METHOD_DESCRIPTOR_O,
&&TARGET_PRECALL_NO_KW_METHOD_DESCRIPTOR_NOARGS,
&&TARGET_PRECALL_NO_KW_STR_1,
&&TARGET_PRECALL_NO_KW_TUPLE_1,
&&TARGET_PRECALL_NO_KW_TYPE_1,
+ &&TARGET_PRECALL_NO_KW_METHOD_DESCRIPTOR_FAST,
&&TARGET_LIST_TO_TUPLE,
&&TARGET_RETURN_VALUE,
&&TARGET_IMPORT_STAR,
@@ -130,7 +130,7 @@ static void *opcode_targets[256] = {
&&TARGET_POP_JUMP_IF_NOT_NONE,
&&TARGET_POP_JUMP_IF_NONE,
&&TARGET_RAISE_VARARGS,
- &&TARGET_PRECALL_NO_KW_METHOD_DESCRIPTOR_FAST,
+ &&TARGET_GET_AWAITABLE,
&&TARGET_MAKE_FUNCTION,
&&TARGET_BUILD_SLICE,
&&TARGET_JUMP_NO_INTERRUPT,