diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2014-07-29 15:21:39 (GMT) |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2014-07-29 15:21:39 (GMT) |
commit | 9b1d670361215f8d56de7a05cb1d430009735fd5 (patch) | |
tree | 66761b1a850a46ce95d9874d52674760c99df66f /Python/ast.c | |
parent | c3828075598ca775555b29b78e67d3fa8e856c00 (diff) | |
download | cpython-9b1d670361215f8d56de7a05cb1d430009735fd5.zip cpython-9b1d670361215f8d56de7a05cb1d430009735fd5.tar.gz cpython-9b1d670361215f8d56de7a05cb1d430009735fd5.tar.bz2 |
Issue #21591: Handle exec backwards compatibility in the AST builder.
Instead of deferring until runtime. This makes sure we hit the right
conditions in dealing with unqualified exec statements.
Reviewed by Victor Stinner. Test follows in a later commit.
Diffstat (limited to 'Python/ast.c')
-rw-r--r-- | Python/ast.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Python/ast.c b/Python/ast.c index 80e6354..ffd5679 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -2679,6 +2679,18 @@ ast_for_exec_stmt(struct compiling *c, const node *n) expr1 = ast_for_expr(c, CHILD(n, 1)); if (!expr1) return NULL; + + if (expr1->kind == Tuple_kind && n_children < 4 && + (asdl_seq_LEN(expr1->v.Tuple.elts) == 2 || + asdl_seq_LEN(expr1->v.Tuple.elts) == 3)) { + /* Backwards compatibility: pass exec args as a tuple */ + globals = (expr_ty) asdl_seq_GET(expr1->v.Tuple.elts, 1); + if (asdl_seq_LEN(expr1->v.Tuple.elts) == 3) { + locals = (expr_ty) asdl_seq_GET(expr1->v.Tuple.elts, 2); + } + expr1 = (expr_ty) asdl_seq_GET(expr1->v.Tuple.elts, 0); + } + if (n_children >= 4) { globals = ast_for_expr(c, CHILD(n, 3)); if (!globals) |