I'm experimenting with the new monitoring interface in PEP 669. The LINE event happens multiple times for the line in the body of a for loop (as I expect), but the for statement itself only gets an event on entering, not each time around the loop.
This code:
importsysdefloop3():
foriinrange(3):
print(i)
print("done")
the_code=loop3.__code__defline_callback(code, line_number):
assertcode==the_codeprint(f"LINE: {line_number}")
my_id=sys.monitoring.COVERAGE_IDsys.monitoring.use_tool_id(my_id, "repro")
sys.monitoring.register_callback(my_id, sys.monitoring.events.LINE, line_callback)
sys.monitoring.set_local_events(my_id, the_code, sys.monitoring.events.LINE)
loop3()produces:
LINE: 4
LINE: 5
0
LINE: 5
1
LINE: 5
2
LINE: 6
done
I would expect Line 4 to be monitored after each "LINE: 5", including after the last one.
This is with commit 263abd3 of CPython.
I'm experimenting with the new monitoring interface in PEP 669. The LINE event happens multiple times for the line in the body of a for loop (as I expect), but the for statement itself only gets an event on entering, not each time around the loop.
This code:
produces:
I would expect Line 4 to be monitored after each "LINE: 5", including after the last one.
This is with commit 263abd3 of CPython.