Skip to content

Commit

Permalink
fix line tracing of multiline for statements
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Jun 11, 2024
1 parent 6a3386c commit 8aa33e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Lib/test/test_sys_settrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1650,15 +1650,15 @@ def func():
EXPECTED_EVENTS = [
(0, 'call'),
(2, 'line'),
(1, 'line'),
(-3, 'call'),
(-2, 'line'),
(-2, 'return'),
(4, 'line'),
(1, 'line'),
(4, 'line'),
(2, 'line'),
(-2, 'call'),
(-2, 'return'),
(1, 'return'),
(2, 'return'),
]

# C level events should be the same as expected and the same as Python level.
Expand Down
6 changes: 6 additions & 0 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2981,12 +2981,18 @@ compiler_for(struct compiler *c, stmt_ty s)
RETURN_IF_ERROR(compiler_push_fblock(c, loc, FOR_LOOP, start, end, NULL));

VISIT(c, expr, s->v.For.iter);

loc = LOC(s->v.For.iter);
ADDOP(c, loc, GET_ITER);

USE_LABEL(c, start);
ADDOP_JUMP(c, loc, FOR_ITER, cleanup);

/* Add NOP to ensure correct line tracing of multiline for statements.
* It will be removed later if redundant.
*/
ADDOP(c, LOC(s->v.For.target), NOP);

USE_LABEL(c, body);
VISIT(c, expr, s->v.For.target);
VISIT_SEQ(c, stmt, s->v.For.body);
Expand Down

0 comments on commit 8aa33e1

Please sign in to comment.