Xavier de Gaye added the comment: The difference lies in the line numbers. When tracing lines, the interpreter operates on the basis of physical lines, not logical lines (https://docs.python.org/3/reference/lexical_analysis.html#line-structure). The local trace function is called on the first instruction of each physical line (see the comment in maybe_call_line_trace() in Python/ceval.c).
In the first case of as_context.py, the 'zero' case, we have: 25 74 SETUP_EXCEPT 49 (to 126) 27 77 LOAD_NAME 6 (Context) 80 CALL_FUNCTION 0 (0 positional, 0 keyword pair) 83 SETUP_WITH 20 (to 106) 86 STORE_NAME 7 (zero) 28 89 LOAD_NAME 8 (print) 92 LOAD_CONST 5 ('zero') 95 LOAD_NAME 7 (zero) ... After 'CALL_FUNCTION' has been run and the trace function set up, the __raise() local trace function is invoked for the first time upon running the 'LOAD_NAME' instruction, since 'SETUP_WITH' and 'STORE_NAME' are not the first instruction of line 27. In the 'two' case, we have: 41 >> 214 SETUP_EXCEPT 49 (to 266) 42 217 LOAD_NAME 6 (Context) 220 CALL_FUNCTION 0 (0 positional, 0 keyword pair) 223 SETUP_WITH 20 (to 246) 43 226 STORE_NAME 11 (two) 44 229 LOAD_NAME 8 (print) 232 LOAD_CONST 9 ('two') 235 LOAD_NAME 11 (two) .... Here the __raise() local trace function is invoked for the first time upon running the 'STORE_NAME' instruction. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25474> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com