GH-92236: Remove spurious "line" event when starting coroutine or generator. (GH-92722) (GH-92772)

(cherry picked from commit 22a1db378c)
This commit is contained in:
Miss Islington (bot) 2022-05-13 03:52:54 -07:00 committed by GitHub
parent c41667e71b
commit 2e8b2d0ee2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 107 additions and 0 deletions

View file

@ -7,6 +7,7 @@
import gc
from functools import wraps
import asyncio
from test.support import import_helper
support.requires_working_socket(module=True)
@ -1473,6 +1474,58 @@ def __init__(self):
(3, 'return'),
(1, 'return')])
@support.cpython_only
def test_no_line_event_after_creating_generator(self):
# Spurious line events before call events only show up with C tracer
# Skip this test if the _testcapi module isn't available.
_testcapi = import_helper.import_module('_testcapi')
def gen():
yield 1
def func():
for _ in (
gen()
):
pass
EXPECTED_EVENTS = [
(0, 'call'),
(2, 'line'),
(1, 'line'),
(-3, 'call'),
(-2, 'line'),
(-2, 'return'),
(4, 'line'),
(1, 'line'),
(-2, 'call'),
(-2, 'return'),
(1, 'return'),
]
# C level events should be the same as expected and the same as Python level.
events = []
# Turning on and off tracing must be on same line to avoid unwanted LINE events.
_testcapi.settrace_to_record(events); func(); sys.settrace(None)
start_line = func.__code__.co_firstlineno
events = [
(line-start_line, EVENT_NAMES[what])
for (what, line, arg) in events
]
self.assertEqual(events, EXPECTED_EVENTS)
self.run_and_compare(func, EXPECTED_EVENTS)
EVENT_NAMES = [
'call',
'exception',
'line',
'return'
]
class SkipLineEventsTraceTestCase(TraceTestCase):
"""Repeat the trace tests, but with per-line events skipped"""