[3.7] bpo-33026: Fix jumping out of "with" block by setting f_lineno.… · python/cpython@04aadf2 (original) (raw)

Original file line number Diff line number Diff line change
@@ -797,6 +797,34 @@ def test_jump_across_with(output):
797 797 with tracecontext(output, 4):
798 798 output.append(5)
799 799
800 +@jump_test(4, 5, [1, 3, 5, 6])
801 +def test_jump_out_of_with_block_within_for_block(output):
802 +output.append(1)
803 +for i in [1]:
804 +with tracecontext(output, 3):
805 +output.append(4)
806 +output.append(5)
807 +output.append(6)
808 +
809 +@jump_test(4, 5, [1, 2, 3, 5, -2, 6])
810 +def test_jump_out_of_with_block_within_with_block(output):
811 +output.append(1)
812 +with tracecontext(output, 2):
813 +with tracecontext(output, 3):
814 +output.append(4)
815 +output.append(5)
816 +output.append(6)
817 +
818 +@jump_test(5, 6, [2, 4, 6, 7])
819 +def test_jump_out_of_with_block_within_finally_block(output):
820 +try:
821 +output.append(2)
822 +finally:
823 +with tracecontext(output, 4):
824 +output.append(5)
825 +output.append(6)
826 +output.append(7)
827 +
800 828 @jump_test(8, 11, [1, 3, 5, 11, 12])
801 829 def test_jump_out_of_complex_nested_blocks(output):
802 830 output.append(1)