Visitar URL original
GH-90997: Wrap `yield from`/`await` in a virtual `try`/`except StopIteration` by brandtbucher · Pull Request #96010 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 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
Prev Previous commit
Next Next commit
Pack everything into END_THROW
  • Loading branch information
brandtbucher committed Aug 17, 2022
commit f4cc3985ae642b712cf92a4d9ca348cc2fe991a1
21 changes: 15 additions & 6 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,17 @@ the original TOS1.
.. versionchanged:: 3.11
Exception representation on the stack now consist of one, not three, items.


.. opcode:: END_THROW

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

END suggests that this is the end of a sequence of bytecodes.
Maybe CLEANUP_THROW as it cleans up _gen_throw?


Handles an exception raised during a :meth:`~generator.throw` or
:meth:`~generator.close` call through the current frame. If TOS is an
instance of :exc:`StopIteration`, pop three values from the stack and push
its ``value`` member. Otherwise, re-raise TOS.

.. versionadded:: 3.12


.. opcode:: BEFORE_ASYNC_WITH

Resolves ``__aenter__`` and ``__aexit__`` from the object on top of the
Expand Down Expand Up @@ -709,14 +720,12 @@ iterations of the loop.
Exception representation on the stack now consist of one, not three, items.


.. opcode:: LOAD_EXCEPTION_TYPE (type)

Pushes an exception type onto the stack, depending on the value of *type*:
.. opcode:: LOAD_ASSERTION_ERROR

* ``0``: :exc:`AssertionError`
* ``1``: :exc:`StopIteration`
Pushes :exc:`AssertionError` onto the stack. Used by the :keyword:`assert`
statement.

.. versionadded:: 3.12
.. versionadded:: 3.9


.. opcode:: LOAD_BUILD_CLASS
Expand Down
32 changes: 16 additions & 16 deletions Include/internal/pycore_opcode.h

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

85 changes: 43 additions & 42 deletions Include/opcode.h

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

3 changes: 0 additions & 3 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
JUMP_BACKWARD = opmap['JUMP_BACKWARD']
FOR_ITER = opmap['FOR_ITER']
LOAD_ATTR = opmap['LOAD_ATTR']
LOAD_EXCEPTION_TYPE = opmap['LOAD_EXCEPTION_TYPE']

CACHE = opmap["CACHE"]

Expand Down Expand Up @@ -498,8 +497,6 @@ def _get_instructions_bytes(code, varname_from_oparg=None,
if arg & (1<<i))
elif deop == BINARY_OP:
_, argrepr = _nb_ops[arg]
elif deop == LOAD_EXCEPTION_TYPE:
argrepr = "StopIteration" if arg else "AssertionError"
yield Instruction(_all_opname[op], op,
arg, argval, argrepr,
offset, starts_line, is_jump_target, positions)
Expand Down
2 changes: 1 addition & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.12a1 3505 (Specialization/Cache for FOR_ITER)
# Python 3.12a1 3506 (Add BINARY_SLICE and STORE_SLICE instructions)
# Python 3.12a1 3507 (Set lineno of module's RESUME to 0)
# Python 3.12a1 3508 (Replace LOAD_ASSERTION_ERROR with LOAD_EXCEPTION_TYPE)
# Python 3.12a1 3508 (Add END_THROW)

# Python 3.13 will start with 3550

Expand Down
4 changes: 3 additions & 1 deletion Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def pseudo_op(name, op, real_ops):
def_op('BEFORE_ASYNC_WITH', 52)
def_op('BEFORE_WITH', 53)
def_op('END_ASYNC_FOR', 54)
def_op('END_THROW', 55)

def_op('STORE_SUBSCR', 60)
def_op('DELETE_SUBSCR', 61)
Expand All @@ -113,6 +114,7 @@ def pseudo_op(name, op, real_ops):
def_op('PRINT_EXPR', 70)
def_op('LOAD_BUILD_CLASS', 71)

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

def_op('LIST_TO_TUPLE', 82)
Expand Down Expand Up @@ -186,7 +188,7 @@ def pseudo_op(name, op, real_ops):
def_op('DELETE_DEREF', 139)
hasfree.append(139)
jrel_op('JUMP_BACKWARD', 140) # Number of words to skip (backwards)
def_op('LOAD_EXCEPTION_TYPE', 141)

def_op('CALL_FUNCTION_EX', 142) # Flags

def_op('EXTENDED_ARG', 144)
Expand Down
Loading