Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bpo-46841: Fix error message hacks inGET_AWAITABLE#31664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
markshannon merged 4 commits intopython:mainfrombrandtbucher:get-awaitable
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Use an oparg to discover context for GET_AWAITABLE
  • Loading branch information
@brandtbucher
brandtbucher committedMar 3, 2022
commit24541ba4a6d1016d9673970fc2408fbcfafa55cf
12 changes: 11 additions & 1 deletionDoc/library/dis.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -475,15 +475,25 @@ the original TOS1.

**Coroutine opcodes**

.. opcode:: GET_AWAITABLE
.. opcode:: GET_AWAITABLE (where)

Implements ``TOS = get_awaitable(TOS)``, where ``get_awaitable(o)``
returns ``o`` if ``o`` is a coroutine object or a generator object with
the CO_ITERABLE_COROUTINE flag, or resolves
``o.__await__``.

If the ``where`` operand is nonzero, it indicates where the instruction
occurs:

* ``1`` After a call to ``__aenter__``
* ``2`` After a call to ``__aexit__``

.. versionadded:: 3.5

.. versionchanged:: 3.11
Previously, this instruction did not have an oparg.



.. opcode:: GET_AITER

Expand Down
16 changes: 8 additions & 8 deletionsInclude/opcode.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

3 changes: 2 additions & 1 deletionLib/importlib/_bootstrap_external.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -390,6 +390,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.11a5 3481 (Use inline cache for BINARY_OP)
# Python 3.11a5 3482 (Use inline caching for UNPACK_SEQUENCE and LOAD_GLOBAL)
# Python 3.11a5 3483 (Use inline caching for COMPARE_OP and BINARY_SUBSCR)
# Python 3.11a5 3484 (Add an oparg to GET_AWAITABLE)

# Python 3.12 will start with magic number 3500

Expand All@@ -404,7 +405,7 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (3483).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3484).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

_PYCACHE = '__pycache__'
Expand Down
3 changes: 1 addition & 2 deletionsLib/opcode.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -92,7 +92,6 @@ def jabs_op(name, op, entries=0):
def_op('PRINT_EXPR', 70)
def_op('LOAD_BUILD_CLASS', 71)

def_op('GET_AWAITABLE', 73)
def_op('LOAD_ASSERTION_ERROR', 74)
def_op('RETURN_GENERATOR', 75)

Expand DownExpand Up@@ -153,7 +152,7 @@ def jabs_op(name, op, entries=0):
jabs_op('POP_JUMP_IF_NOT_NONE', 128)
jabs_op('POP_JUMP_IF_NONE', 129)
def_op('RAISE_VARARGS', 130) # Number of raise arguments (1, 2, or 3)

def_op('GET_AWAITABLE', 131)
def_op('MAKE_FUNCTION', 132) # Flags
def_op('BUILD_SLICE', 133) # Number of items
jabs_op('JUMP_NO_INTERRUPT', 134) # Target byte offset from beginning of code
Expand Down
16 changes: 5 additions & 11 deletionsPython/ceval.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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,
Expand DownExpand Up@@ -2519,13 +2519,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
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);
Expand DownExpand Up@@ -7711,16 +7705,16 @@ format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg)
}

static void
format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, intprevprevprevopcode, int prevopcode)
format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, intoparg)
{
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",
Expand Down
12 changes: 6 additions & 6 deletionsPython/compile.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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);
}
Expand DownExpand Up@@ -5354,7 +5354,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);
}
Expand DownExpand Up@@ -5486,7 +5486,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);

Expand DownExpand Up@@ -5523,7 +5523,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);

Expand All@@ -5537,7 +5537,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);
Expand DownExpand Up@@ -5711,7 +5711,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;
Expand Down
6 changes: 3 additions & 3 deletionsPython/opcode_targets.h
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.


[8]ページ先頭

©2009-2025 Movatter.jp