mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-39166: Fix trace of last iteration of async for loops (#17800)
This commit is contained in:
parent
850a8856e1
commit
4c53e63cc9
3 changed files with 87 additions and 5 deletions
|
@ -526,6 +526,82 @@ class TraceTestCase(unittest.TestCase):
|
|||
(7, 'line'),
|
||||
(7, 'return')])
|
||||
|
||||
def test_20_async_for_loop(self):
|
||||
class AsyncIteratorWrapper:
|
||||
def __init__(self, obj):
|
||||
self._it = iter(obj)
|
||||
|
||||
def __aiter__(self):
|
||||
return self
|
||||
|
||||
async def __anext__(self):
|
||||
try:
|
||||
return next(self._it)
|
||||
except StopIteration:
|
||||
raise StopAsyncIteration
|
||||
|
||||
async def doit_async():
|
||||
async for letter in AsyncIteratorWrapper("abc"):
|
||||
x = letter
|
||||
y = 42
|
||||
|
||||
def run(tracer):
|
||||
x = doit_async()
|
||||
try:
|
||||
sys.settrace(tracer)
|
||||
x.send(None)
|
||||
finally:
|
||||
sys.settrace(None)
|
||||
|
||||
tracer = self.make_tracer()
|
||||
events = [
|
||||
(0, 'call'),
|
||||
(1, 'line'),
|
||||
(-12, 'call'),
|
||||
(-11, 'line'),
|
||||
(-11, 'return'),
|
||||
(-9, 'call'),
|
||||
(-8, 'line'),
|
||||
(-8, 'return'),
|
||||
(-6, 'call'),
|
||||
(-5, 'line'),
|
||||
(-4, 'line'),
|
||||
(-4, 'return'),
|
||||
(1, 'exception'),
|
||||
(2, 'line'),
|
||||
(1, 'line'),
|
||||
(-6, 'call'),
|
||||
(-5, 'line'),
|
||||
(-4, 'line'),
|
||||
(-4, 'return'),
|
||||
(1, 'exception'),
|
||||
(2, 'line'),
|
||||
(1, 'line'),
|
||||
(-6, 'call'),
|
||||
(-5, 'line'),
|
||||
(-4, 'line'),
|
||||
(-4, 'return'),
|
||||
(1, 'exception'),
|
||||
(2, 'line'),
|
||||
(1, 'line'),
|
||||
(-6, 'call'),
|
||||
(-5, 'line'),
|
||||
(-4, 'line'),
|
||||
(-4, 'exception'),
|
||||
(-3, 'line'),
|
||||
(-2, 'line'),
|
||||
(-2, 'exception'),
|
||||
(-2, 'return'),
|
||||
(1, 'exception'),
|
||||
(3, 'line'),
|
||||
(3, 'return')]
|
||||
try:
|
||||
run(tracer.trace)
|
||||
except Exception:
|
||||
pass
|
||||
self.compare_events(doit_async.__code__.co_firstlineno,
|
||||
tracer.events, events)
|
||||
|
||||
|
||||
class SkipLineEventsTraceTestCase(TraceTestCase):
|
||||
"""Repeat the trace tests, but with per-line events skipped"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue