Skip to content

bpo-46344: Fix trace bug in else of try and try-star blocks #30544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions Lib/test/test_sys_settrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,16 +644,22 @@ def func():
4
else:
6
if False:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cover the original issue?
The compiler will optimize out the if False.
Might be a good idea to add another test with a non-constant predicate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test did fail without the fix. But sure, I'll add a test with a non const.

8
else:
10
finally:
8
12

self.run_and_compare(func,
[(0, 'call'),
(1, 'line'),
(2, 'line'),
(6, 'line'),
(8, 'line'),
(8, 'return')])
(7, 'line'),
(10, 'line'),
(12, 'line'),
(12, 'return')])

def test_nested_loops(self):

Expand Down Expand Up @@ -1222,16 +1228,22 @@ def func():
4
else:
6
if False:
8
else:
10
finally:
8
12

self.run_and_compare(func,
[(0, 'call'),
(1, 'line'),
(2, 'line'),
(6, 'line'),
(8, 'line'),
(8, 'return')])
(7, 'line'),
(10, 'line'),
(12, 'line'),
(12, 'return')])

def test_try_except_star_named_no_exception(self):

Expand Down
2 changes: 0 additions & 2 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3475,7 +3475,6 @@ compiler_try_except(struct compiler *c, stmt_ty s)
POP_EXCEPT_AND_RERAISE(c);
compiler_use_next_block(c, orelse);
VISIT_SEQ(c, stmt, s->v.Try.orelse);
ADDOP_JUMP(c, JUMP_FORWARD, end);
compiler_use_next_block(c, end);
return 1;
}
Expand Down Expand Up @@ -3702,7 +3701,6 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
POP_EXCEPT_AND_RERAISE(c);
compiler_use_next_block(c, orelse);
VISIT_SEQ(c, stmt, s->v.TryStar.orelse);
ADDOP_JUMP(c, JUMP_FORWARD, end);
compiler_use_next_block(c, end);
return 1;
}
Expand Down