Skip to content

Commit e5862f7

Browse files
authored
bpo-44616: Mark all clean up instructions at end of named exception block as artificial (GH-27109)
1 parent f572cbf commit e5862f7

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

Lib/test/test_sys_settrace.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,29 @@ def func():
10771077
(1, 'line'),
10781078
(1, 'return')])
10791079

1080+
def test_no_tracing_of_named_except_cleanup(self):
1081+
1082+
def func():
1083+
x = 0
1084+
try:
1085+
1/x
1086+
except ZeroDivisionError as error:
1087+
if x:
1088+
raise
1089+
return "done"
1090+
1091+
self.run_and_compare(func,
1092+
[(0, 'call'),
1093+
(1, 'line'),
1094+
(2, 'line'),
1095+
(3, 'line'),
1096+
(3, 'exception'),
1097+
(4, 'line'),
1098+
(5, 'line'),
1099+
(7, 'line'),
1100+
(7, 'return')])
1101+
1102+
10801103
class SkipLineEventsTraceTestCase(TraceTestCase):
10811104
"""Repeat the trace tests, but with per-line events skipped"""
10821105

Python/compile.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3312,11 +3312,11 @@ compiler_try_except(struct compiler *c, stmt_ty s)
33123312
/* second # body */
33133313
VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body);
33143314
compiler_pop_fblock(c, HANDLER_CLEANUP, cleanup_body);
3315+
/* name = None; del name; # Mark as artificial */
3316+
UNSET_LOC(c);
33153317
ADDOP(c, POP_BLOCK);
33163318
ADDOP(c, POP_BLOCK);
33173319
ADDOP(c, POP_EXCEPT);
3318-
/* name = None; del name; # Mark as artificial */
3319-
UNSET_LOC(c);
33203320
ADDOP_LOAD_CONST(c, Py_None);
33213321
compiler_nameop(c, handler->v.ExceptHandler.name, Store);
33223322
compiler_nameop(c, handler->v.ExceptHandler.name, Del);
@@ -3348,7 +3348,6 @@ compiler_try_except(struct compiler *c, stmt_ty s)
33483348
return 0;
33493349
VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body);
33503350
compiler_pop_fblock(c, HANDLER_CLEANUP, cleanup_body);
3351-
/* name = None; del name; # Mark as artificial */
33523351
UNSET_LOC(c);
33533352
ADDOP(c, POP_BLOCK);
33543353
ADDOP(c, POP_EXCEPT);

Python/importlib_zipimport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,8 +1403,8 @@ const unsigned char _Py_M__zipimport[] = {
14031403
23,35,13,20,20,29,30,34,30,42,44,53,20,54,13,17,
14041404
20,24,13,17,16,26,13,54,17,39,28,43,44,48,50,57,
14051405
59,67,69,77,79,83,28,84,21,25,21,25,0,0,17,39,
1406-
24,35,17,39,17,39,17,39,17,39,36,39,21,33,21,39,
1407-
21,39,21,39,21,39,21,39,0,0,0,0,0,0,0,0,
1406+
24,35,17,39,17,39,17,39,17,39,36,39,21,33,21,33,
1407+
21,33,21,33,21,33,21,33,0,0,0,0,0,0,0,0,
14081408
0,0,24,39,40,47,49,53,24,54,17,21,16,20,24,28,
14091409
16,28,13,25,17,25,23,32,33,34,23,35,13,20,20,24,
14101410
26,35,37,44,20,44,13,44,13,44,13,44,12,24,9,83,

0 commit comments

Comments
 (0)