mirror of https://github.com/python/cpython
gh-105658: fix excess trace events for except block ending with a conditional block (#109384)
This commit is contained in:
parent
1ce9ea0453
commit
4a54074a0f
|
@ -642,7 +642,8 @@ None >> PUSH_EXC_INFO
|
||||||
CALL 0
|
CALL 0
|
||||||
POP_TOP
|
POP_TOP
|
||||||
RERAISE 0
|
RERAISE 0
|
||||||
>> COPY 3
|
|
||||||
|
None >> COPY 3
|
||||||
POP_EXCEPT
|
POP_EXCEPT
|
||||||
RERAISE 1
|
RERAISE 1
|
||||||
ExceptionTable:
|
ExceptionTable:
|
||||||
|
@ -674,7 +675,8 @@ None PUSH_EXC_INFO
|
||||||
CALL 0
|
CALL 0
|
||||||
POP_TOP
|
POP_TOP
|
||||||
RERAISE 0
|
RERAISE 0
|
||||||
>> COPY 3
|
|
||||||
|
None >> COPY 3
|
||||||
POP_EXCEPT
|
POP_EXCEPT
|
||||||
RERAISE 1
|
RERAISE 1
|
||||||
ExceptionTable:
|
ExceptionTable:
|
||||||
|
@ -1822,9 +1824,9 @@ expected_opinfo_jumpy = [
|
||||||
Instruction(opname='CALL', opcode=53, arg=1, argval=1, argrepr='', offset=414, start_offset=414, starts_line=False, line_number=28, is_jump_target=False, positions=None),
|
Instruction(opname='CALL', opcode=53, arg=1, argval=1, argrepr='', offset=414, start_offset=414, starts_line=False, line_number=28, is_jump_target=False, positions=None),
|
||||||
Instruction(opname='POP_TOP', opcode=32, arg=None, argval=None, argrepr='', offset=422, start_offset=422, starts_line=False, line_number=28, is_jump_target=False, positions=None),
|
Instruction(opname='POP_TOP', opcode=32, arg=None, argval=None, argrepr='', offset=422, start_offset=422, starts_line=False, line_number=28, is_jump_target=False, positions=None),
|
||||||
Instruction(opname='RERAISE', opcode=102, arg=0, argval=0, argrepr='', offset=424, start_offset=424, starts_line=False, line_number=28, is_jump_target=False, positions=None),
|
Instruction(opname='RERAISE', opcode=102, arg=0, argval=0, argrepr='', offset=424, start_offset=424, starts_line=False, line_number=28, is_jump_target=False, positions=None),
|
||||||
Instruction(opname='COPY', opcode=61, arg=3, argval=3, argrepr='', offset=426, start_offset=426, starts_line=False, line_number=28, is_jump_target=False, positions=None),
|
Instruction(opname='COPY', opcode=61, arg=3, argval=3, argrepr='', offset=426, start_offset=426, starts_line=True, line_number=None, is_jump_target=False, positions=None),
|
||||||
Instruction(opname='POP_EXCEPT', opcode=31, arg=None, argval=None, argrepr='', offset=428, start_offset=428, starts_line=False, line_number=28, is_jump_target=False, positions=None),
|
Instruction(opname='POP_EXCEPT', opcode=31, arg=None, argval=None, argrepr='', offset=428, start_offset=428, starts_line=False, line_number=None, is_jump_target=False, positions=None),
|
||||||
Instruction(opname='RERAISE', opcode=102, arg=1, argval=1, argrepr='', offset=430, start_offset=430, starts_line=False, line_number=28, is_jump_target=False, positions=None),
|
Instruction(opname='RERAISE', opcode=102, arg=1, argval=1, argrepr='', offset=430, start_offset=430, starts_line=False, line_number=None, is_jump_target=False, positions=None),
|
||||||
]
|
]
|
||||||
|
|
||||||
# One last piece of inspect fodder to check the default line number handling
|
# One last piece of inspect fodder to check the default line number handling
|
||||||
|
|
|
@ -929,6 +929,35 @@ class TraceTestCase(unittest.TestCase):
|
||||||
(6, 'line'),
|
(6, 'line'),
|
||||||
(6, 'return')])
|
(6, 'return')])
|
||||||
|
|
||||||
|
def test_finally_with_conditional(self):
|
||||||
|
|
||||||
|
# See gh-105658
|
||||||
|
condition = True
|
||||||
|
def func():
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
raise Exception
|
||||||
|
finally:
|
||||||
|
if condition:
|
||||||
|
result = 1
|
||||||
|
result = 2
|
||||||
|
except:
|
||||||
|
result = 3
|
||||||
|
return result
|
||||||
|
|
||||||
|
self.run_and_compare(func,
|
||||||
|
[(0, 'call'),
|
||||||
|
(1, 'line'),
|
||||||
|
(2, 'line'),
|
||||||
|
(3, 'line'),
|
||||||
|
(3, 'exception'),
|
||||||
|
(5, 'line'),
|
||||||
|
(6, 'line'),
|
||||||
|
(8, 'line'),
|
||||||
|
(9, 'line'),
|
||||||
|
(10, 'line'),
|
||||||
|
(10, 'return')])
|
||||||
|
|
||||||
def test_break_to_continue1(self):
|
def test_break_to_continue1(self):
|
||||||
|
|
||||||
def func():
|
def func():
|
||||||
|
@ -2123,7 +2152,7 @@ class JumpTestCase(unittest.TestCase):
|
||||||
output.append(11)
|
output.append(11)
|
||||||
output.append(12)
|
output.append(12)
|
||||||
|
|
||||||
@jump_test(5, 11, [2, 4], (ValueError, 'exception'))
|
@jump_test(5, 11, [2, 4], (ValueError, 'comes after the current code block'))
|
||||||
def test_no_jump_over_return_try_finally_in_finally_block(output):
|
def test_no_jump_over_return_try_finally_in_finally_block(output):
|
||||||
try:
|
try:
|
||||||
output.append(2)
|
output.append(2)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix bug where the line trace of an except block ending with a conditional
|
||||||
|
includes an excess event with the line of the conditional expression.
|
|
@ -3261,18 +3261,6 @@ compiler_continue(struct compiler *c, location loc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static location
|
|
||||||
location_of_last_executing_statement(asdl_stmt_seq *stmts)
|
|
||||||
{
|
|
||||||
for (Py_ssize_t i = asdl_seq_LEN(stmts) - 1; i >= 0; i++) {
|
|
||||||
location loc = LOC((stmt_ty)asdl_seq_GET(stmts, i));
|
|
||||||
if (loc.lineno > 0) {
|
|
||||||
return loc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NO_LOCATION;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Code generated for "try: <body> finally: <finalbody>" is as follows:
|
/* Code generated for "try: <body> finally: <finalbody>" is as follows:
|
||||||
|
|
||||||
SETUP_FINALLY L
|
SETUP_FINALLY L
|
||||||
|
@ -3341,9 +3329,9 @@ compiler_try_finally(struct compiler *c, stmt_ty s)
|
||||||
RETURN_IF_ERROR(
|
RETURN_IF_ERROR(
|
||||||
compiler_push_fblock(c, loc, FINALLY_END, end, NO_LABEL, NULL));
|
compiler_push_fblock(c, loc, FINALLY_END, end, NO_LABEL, NULL));
|
||||||
VISIT_SEQ(c, stmt, s->v.Try.finalbody);
|
VISIT_SEQ(c, stmt, s->v.Try.finalbody);
|
||||||
loc = location_of_last_executing_statement(s->v.Try.finalbody);
|
|
||||||
compiler_pop_fblock(c, FINALLY_END, end);
|
compiler_pop_fblock(c, FINALLY_END, end);
|
||||||
|
|
||||||
|
loc = NO_LOCATION;
|
||||||
ADDOP_I(c, loc, RERAISE, 0);
|
ADDOP_I(c, loc, RERAISE, 0);
|
||||||
|
|
||||||
USE_LABEL(c, cleanup);
|
USE_LABEL(c, cleanup);
|
||||||
|
@ -3392,9 +3380,9 @@ compiler_try_star_finally(struct compiler *c, stmt_ty s)
|
||||||
compiler_push_fblock(c, loc, FINALLY_END, end, NO_LABEL, NULL));
|
compiler_push_fblock(c, loc, FINALLY_END, end, NO_LABEL, NULL));
|
||||||
|
|
||||||
VISIT_SEQ(c, stmt, s->v.TryStar.finalbody);
|
VISIT_SEQ(c, stmt, s->v.TryStar.finalbody);
|
||||||
loc = location_of_last_executing_statement(s->v.Try.finalbody);
|
|
||||||
|
|
||||||
compiler_pop_fblock(c, FINALLY_END, end);
|
compiler_pop_fblock(c, FINALLY_END, end);
|
||||||
|
loc = NO_LOCATION;
|
||||||
ADDOP_I(c, loc, RERAISE, 0);
|
ADDOP_I(c, loc, RERAISE, 0);
|
||||||
|
|
||||||
USE_LABEL(c, cleanup);
|
USE_LABEL(c, cleanup);
|
||||||
|
|
Loading…
Reference in New Issue