Skip to content

Commit 5769724

Browse files
authored
bpo-40228: More robust frame.setlineno. (GH-19437)
More robust frame.setlineno. Makes no assumptions about source->bytecode translation.
1 parent ec9bea4 commit 5769724

File tree

3 files changed

+269
-330
lines changed

3 files changed

+269
-330
lines changed

Lib/test/test_sys_settrace.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,8 @@ def test_jump_in_nested_finally_3(output):
948948
output.append(11)
949949
output.append(12)
950950

951-
@jump_test(5, 11, [2, 4, 12])
952-
def test_jump_over_return_try_finally_in_finally_block(output):
951+
@jump_test(5, 11, [2, 4], (ValueError, 'unreachable'))
952+
def test_no_jump_over_return_try_finally_in_finally_block(output):
953953
try:
954954
output.append(2)
955955
finally:
@@ -963,8 +963,8 @@ def test_jump_over_return_try_finally_in_finally_block(output):
963963
pass
964964
output.append(12)
965965

966-
@jump_test(3, 4, [1, 4])
967-
def test_jump_infinite_while_loop(output):
966+
@jump_test(3, 4, [1], (ValueError, 'unreachable'))
967+
def test_no_jump_infinite_while_loop(output):
968968
output.append(1)
969969
while True:
970970
output.append(3)
@@ -1357,16 +1357,16 @@ def test_no_jump_between_except_blocks_2(output):
13571357
output.append(7)
13581358
output.append(8)
13591359

1360-
@jump_test(1, 5, [], (ValueError, "into a 'finally'"))
1361-
def test_no_jump_into_finally_block(output):
1360+
@jump_test(1, 5, [5])
1361+
def test_jump_into_finally_block(output):
13621362
output.append(1)
13631363
try:
13641364
output.append(3)
13651365
finally:
13661366
output.append(5)
13671367

1368-
@jump_test(3, 6, [2, 5, 6], (ValueError, "into a 'finally'"))
1369-
def test_no_jump_into_finally_block_from_try_block(output):
1368+
@jump_test(3, 6, [2, 6, 7])
1369+
def test_jump_into_finally_block_from_try_block(output):
13701370
try:
13711371
output.append(2)
13721372
output.append(3)
@@ -1375,8 +1375,8 @@ def test_no_jump_into_finally_block_from_try_block(output):
13751375
output.append(6)
13761376
output.append(7)
13771377

1378-
@jump_test(5, 1, [1, 3], (ValueError, "out of a 'finally'"))
1379-
def test_no_jump_out_of_finally_block(output):
1378+
@jump_test(5, 1, [1, 3, 1, 3, 5])
1379+
def test_jump_out_of_finally_block(output):
13801380
output.append(1)
13811381
try:
13821382
output.append(3)
@@ -1441,23 +1441,23 @@ def test_no_jump_out_of_qualified_except_block(output):
14411441
output.append(6)
14421442
output.append(7)
14431443

1444-
@jump_test(3, 5, [1, 2, -2], (ValueError, 'into'))
1445-
def test_no_jump_between_with_blocks(output):
1444+
@jump_test(3, 5, [1, 2, 5, -2])
1445+
def test_jump_between_with_blocks(output):
14461446
output.append(1)
14471447
with tracecontext(output, 2):
14481448
output.append(3)
14491449
with tracecontext(output, 4):
14501450
output.append(5)
14511451

1452-
@async_jump_test(3, 5, [1, 2, -2], (ValueError, 'into'))
1453-
async def test_no_jump_between_async_with_blocks(output):
1452+
@async_jump_test(3, 5, [1, 2, 5, -2])
1453+
async def test_jump_between_async_with_blocks(output):
14541454
output.append(1)
14551455
async with asynctracecontext(output, 2):
14561456
output.append(3)
14571457
async with asynctracecontext(output, 4):
14581458
output.append(5)
14591459

1460-
@jump_test(5, 7, [2, 4], (ValueError, 'finally'))
1460+
@jump_test(5, 7, [2, 4], (ValueError, "unreachable"))
14611461
def test_no_jump_over_return_out_of_finally_block(output):
14621462
try:
14631463
output.append(2)
@@ -1551,9 +1551,8 @@ def test_no_jump_from_exception_event(output):
15511551
output.append(1)
15521552
1 / 0
15531553

1554-
@jump_test(3, 2, [2], event='return', error=(ValueError,
1555-
"can't jump from a 'yield' statement"))
1556-
def test_no_jump_from_yield(output):
1554+
@jump_test(3, 2, [2, 5], event='return')
1555+
def test_jump_from_yield(output):
15571556
def gen():
15581557
output.append(2)
15591558
yield 3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Setting frame.f_lineno is now robust w.r.t. changes in the source-to-bytecode compiler

0 commit comments

Comments
 (0)