Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 17 additions & 0 deletions Lib/test/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,23 @@ async def foo():
('branch right', 'foo', 1, 3),
('branch left', 'func', 12, 12)])

def test_async_for_exception(self):
async def items():
yield 1
raise ValueError

async def consume():
async for item in items():
pass

def run():
try:
consume().send(None)
except ValueError:
pass

self.check_events(run, expected=[], recorders=(BranchRightRecorder,))


def test_match(self):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix :mod:`sys.monitoring` reporting a loop-exit branch when an
:keyword:`async for` iterator raises an exception other than
:exc:`StopAsyncIteration`.
7 changes: 6 additions & 1 deletion Modules/_testinternalcapi/test_cases.c.h

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

7 changes: 5 additions & 2 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1953,9 +1953,12 @@ dummy_func(
}
}

tier1 op(_MONITOR_END_ASYNC_FOR, ( -- )) {
tier1 op(_MONITOR_END_ASYNC_FOR, (exc_slot[1] -- exc_slot[1])) {
assert((next_instr-oparg)->op.code == END_SEND || (next_instr-oparg)->op.code >= MIN_INSTRUMENTED_OPCODE);
INSTRUMENTED_JUMP(next_instr-oparg, this_instr+1, PY_MONITORING_EVENT_BRANCH_RIGHT);
PyObject *exc = PyStackRef_AsPyObjectBorrow(exc_slot[0]);
if (PyErr_GivenExceptionMatches(exc, PyExc_StopAsyncIteration)) {
INSTRUMENTED_JUMP(next_instr-oparg, this_instr+1, PY_MONITORING_EVENT_BRANCH_RIGHT);
}
}

macro(INSTRUMENTED_END_ASYNC_FOR) =
Expand Down
7 changes: 6 additions & 1 deletion Python/generated_cases.c.h

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

Loading