mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
SF patch 1631942 by Collin Winter:
(a) "except E, V" -> "except E as V" (b) V is now limited to a simple name (local variable) (c) V is now deleted at the end of the except block
This commit is contained in:
parent
893523e80a
commit
b940e113bf
295 changed files with 817 additions and 743 deletions
|
@ -1955,13 +1955,66 @@ compiler_try_except(struct compiler *c, stmt_ty s)
|
|||
}
|
||||
ADDOP(c, POP_TOP);
|
||||
if (handler->name) {
|
||||
basicblock *cleanup_end, *cleanup_body;
|
||||
expr_context_ty orig_ctx;
|
||||
|
||||
assert(handler->name->kind == Name_kind);
|
||||
|
||||
cleanup_end = compiler_new_block(c);
|
||||
cleanup_body = compiler_new_block(c);
|
||||
if(!(cleanup_end || cleanup_body))
|
||||
return 0;
|
||||
|
||||
VISIT(c, expr, handler->name);
|
||||
ADDOP(c, POP_TOP);
|
||||
|
||||
/*
|
||||
try:
|
||||
# body
|
||||
except type as name:
|
||||
try:
|
||||
# body
|
||||
finally:
|
||||
name = None
|
||||
del name
|
||||
*/
|
||||
|
||||
/* second try: */
|
||||
ADDOP_JREL(c, SETUP_FINALLY, cleanup_end);
|
||||
compiler_use_next_block(c, cleanup_body);
|
||||
if (!compiler_push_fblock(c, FINALLY_TRY, cleanup_body))
|
||||
return 0;
|
||||
|
||||
/* second # body */
|
||||
VISIT_SEQ(c, stmt, handler->body);
|
||||
ADDOP(c, POP_BLOCK);
|
||||
compiler_pop_fblock(c, FINALLY_TRY, cleanup_body);
|
||||
|
||||
/* finally: */
|
||||
ADDOP_O(c, LOAD_CONST, Py_None, consts);
|
||||
compiler_use_next_block(c, cleanup_end);
|
||||
if (!compiler_push_fblock(c, FINALLY_END, cleanup_end))
|
||||
return 0;
|
||||
|
||||
/* name = None */
|
||||
ADDOP_O(c, LOAD_CONST, Py_None, consts);
|
||||
orig_ctx = handler->name->v.Name.ctx;
|
||||
handler->name->v.Name.ctx = Store;
|
||||
VISIT(c, expr, handler->name);
|
||||
|
||||
/* del name */
|
||||
handler->name->v.Name.ctx = Del;
|
||||
VISIT(c, expr, handler->name);
|
||||
handler->name->v.Name.ctx = orig_ctx;
|
||||
|
||||
ADDOP(c, END_FINALLY);
|
||||
compiler_pop_fblock(c, FINALLY_END, cleanup_end);
|
||||
}
|
||||
else {
|
||||
ADDOP(c, POP_TOP);
|
||||
ADDOP(c, POP_TOP);
|
||||
ADDOP(c, POP_TOP);
|
||||
VISIT_SEQ(c, stmt, handler->body);
|
||||
}
|
||||
ADDOP(c, POP_TOP);
|
||||
VISIT_SEQ(c, stmt, handler->body);
|
||||
ADDOP_JREL(c, JUMP_FORWARD, end);
|
||||
compiler_use_next_block(c, except);
|
||||
if (handler->type)
|
||||
|
|
|
@ -1049,7 +1049,7 @@ static arc arcs_46_1[2] = {
|
|||
{0, 1},
|
||||
};
|
||||
static arc arcs_46_2[2] = {
|
||||
{28, 3},
|
||||
{83, 3},
|
||||
{0, 2},
|
||||
};
|
||||
static arc arcs_46_3[1] = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue