Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 3 additions & 5 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,24 +469,22 @@ def foo(a: int, b: str) -> str:
%4d LOAD_GLOBAL 0 (Exception)
CHECK_EXC_MATCH
POP_JUMP_IF_FALSE 24 (to L9)
POP_JUMP_IF_FALSE 22 (to L9)
L4: NOT_TAKEN
L5: STORE_FAST 0 (e)
%4d L6: LOAD_FAST 0 (e)
LOAD_ATTR 2 (__traceback__)
STORE_FAST 1 (tb)
L7: POP_EXCEPT
LOAD_CONST 1 (None)
PUSH_NULL
STORE_FAST 0 (e)
DELETE_FAST 0 (e)
%4d LOAD_FAST 1 (tb)
RETURN_VALUE
-- L8: LOAD_CONST 1 (None)
-- L8: PUSH_NULL
STORE_FAST 0 (e)
DELETE_FAST 0 (e)
RERAISE 1
%4d L9: RERAISE 0
Expand Down
28 changes: 10 additions & 18 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2526,7 +2526,7 @@ codegen_try_except(compiler *c, stmt_ty s)
try:
# body
finally:
name = None # in case body contains "del name"
name = <NULL> # in case body contains "del name"
del name
*/

Expand All @@ -2541,26 +2541,22 @@ codegen_try_except(compiler *c, stmt_ty s)
/* second # body */
VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body);
_PyCompile_PopFBlock(c, COMPILE_FBLOCK_HANDLER_CLEANUP, cleanup_body);
/* name = None; del name; # Mark as artificial */
/* name = <NULL>; del name; # Mark as artificial */
ADDOP(c, NO_LOCATION, POP_BLOCK);
ADDOP(c, NO_LOCATION, POP_BLOCK);
ADDOP(c, NO_LOCATION, POP_EXCEPT);
ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None);
ADDOP(c, NO_LOCATION, PUSH_NULL);
RETURN_IF_ERROR(
codegen_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Store));
RETURN_IF_ERROR(
codegen_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Del));
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, end);

/* except: */
USE_LABEL(c, cleanup_end);

/* name = None; del name; # artificial */
ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None);
/* name = <NULL>; del name; # artificial */
ADDOP(c, NO_LOCATION, PUSH_NULL);
RETURN_IF_ERROR(
codegen_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Store));
RETURN_IF_ERROR(
codegen_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Del));

ADDOP_I(c, NO_LOCATION, RERAISE, 1);
}
Expand Down Expand Up @@ -2725,7 +2721,7 @@ codegen_try_star_except(compiler *c, stmt_ty s)
try:
# body
finally:
name = None # in case body contains "del name"
name = <NULL> # in case body contains "del name"
del name
*/
/* second try: */
Expand All @@ -2739,27 +2735,23 @@ codegen_try_star_except(compiler *c, stmt_ty s)
/* second # body */
VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body);
_PyCompile_PopFBlock(c, COMPILE_FBLOCK_HANDLER_CLEANUP, cleanup_body);
/* name = None; del name; # artificial */
/* name = <NULL>; del name; # artificial */
ADDOP(c, NO_LOCATION, POP_BLOCK);
if (handler->v.ExceptHandler.name) {
ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None);
ADDOP(c, NO_LOCATION, PUSH_NULL);
RETURN_IF_ERROR(
codegen_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Store));
RETURN_IF_ERROR(
codegen_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Del));
}
ADDOP_JUMP(c, NO_LOCATION, JUMP_NO_INTERRUPT, except);

/* except: */
USE_LABEL(c, cleanup_end);

/* name = None; del name; # artificial */
/* name = <NULL>; del name; # artificial */
if (handler->v.ExceptHandler.name) {
ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None);
ADDOP(c, NO_LOCATION, PUSH_NULL);
RETURN_IF_ERROR(
codegen_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Store));
RETURN_IF_ERROR(
codegen_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Del));
}

/* add exception raised to the res list */
Expand Down
Loading