GH-90997: Wrap yield from/await in a virtual try/except StopIteration (GH-96010)

This commit is contained in:
Brandt Bucher 2022-08-19 12:33:44 -07:00 committed by GitHub
parent 2d9f252c0c
commit 5bfb3c372b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 142 additions and 106 deletions

View file

@ -411,10 +411,10 @@ 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 (Add CLEANUP_THROW)
# Python 3.13 will start with 3550
#
# MAGIC must change whenever the bytecode emitted by the compiler may no
# longer be understood by older implementations of the eval loop (usually
# due to the addition of new opcodes).
@ -424,7 +424,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 = (3507).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3508).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

View file

@ -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('CLEANUP_THROW', 55)
def_op('STORE_SUBSCR', 60)
def_op('DELETE_SUBSCR', 61)

View file

@ -507,26 +507,31 @@ async def _asyncwith(c):
LOAD_CONST 0 (None)
RETURN_VALUE
%3d >> PUSH_EXC_INFO
%3d >> CLEANUP_THROW
JUMP_BACKWARD 24 (to 22)
>> CLEANUP_THROW
JUMP_BACKWARD 9 (to 56)
>> PUSH_EXC_INFO
WITH_EXCEPT_START
GET_AWAITABLE 2
LOAD_CONST 0 (None)
>> SEND 3 (to 82)
>> SEND 4 (to 92)
YIELD_VALUE 6
RESUME 3
JUMP_BACKWARD_NO_INTERRUPT 4 (to 74)
>> POP_JUMP_FORWARD_IF_TRUE 1 (to 86)
JUMP_BACKWARD_NO_INTERRUPT 4 (to 82)
>> CLEANUP_THROW
>> POP_JUMP_FORWARD_IF_TRUE 1 (to 96)
RERAISE 2
>> POP_TOP
POP_EXCEPT
POP_TOP
POP_TOP
JUMP_BACKWARD 19 (to 58)
JUMP_BACKWARD 24 (to 58)
>> COPY 3
POP_EXCEPT
RERAISE 1
ExceptionTable:
2 rows
6 rows
""" % (_asyncwith.__code__.co_firstlineno,
_asyncwith.__code__.co_firstlineno + 1,
_asyncwith.__code__.co_firstlineno + 2,