mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-46841: Fix error message hacks in GET_AWAITABLE
(GH-31664)
This commit is contained in:
parent
03c2a36b2b
commit
586b24d3be
8 changed files with 37 additions and 32 deletions
|
@ -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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue