diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-09-05 03:56:01 +0000 |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-09-05 03:56:01 +0000 |
commit | 3b3aae013b158114fdc90a72355d2d9b1b434875 (patch) | |
tree | ae53663bc7081e890b6f731b740d04abba15daf0 /Python/ast.c | |
parent | 541a48b262a099d55298e32f62d8b1f4a0b97e8e (diff) | |
download | cpython-git-3b3aae013b158114fdc90a72355d2d9b1b434875.tar.gz |
Bug #1520864 (again): unpacking singleton tuples in list comprehensions and
generator expressions (x for x, in ... ) works again.
Sigh, I only fixed for loops the first time, not list comps and genexprs too.
I couldn't find any more unpacking cases where there is a similar bug lurking.
Diffstat (limited to 'Python/ast.c')
-rw-r--r-- | Python/ast.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Python/ast.c b/Python/ast.c index b356192d89..4d0b991c2c 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -983,17 +983,21 @@ ast_for_listcomp(struct compiling *c, const node *n) comprehension_ty lc; asdl_seq *t; expr_ty expression; + node *for_ch; REQ(ch, list_for); - t = ast_for_exprlist(c, CHILD(ch, 1), Store); + for_ch = CHILD(ch, 1); + t = ast_for_exprlist(c, for_ch, Store); if (!t) return NULL; expression = ast_for_testlist(c, CHILD(ch, 3)); if (!expression) return NULL; - if (asdl_seq_LEN(t) == 1) + /* Check the # of children rather than the length of t, since + [x for x, in ... ] has 1 element in t, but still requires a Tuple. */ + if (NCH(for_ch) == 1) lc = comprehension((expr_ty)asdl_seq_GET(t, 0), expression, NULL, c->c_arena); else @@ -1129,17 +1133,21 @@ ast_for_genexp(struct compiling *c, const node *n) comprehension_ty ge; asdl_seq *t; expr_ty expression; + node *for_ch; REQ(ch, gen_for); - t = ast_for_exprlist(c, CHILD(ch, 1), Store); + for_ch = CHILD(ch, 1); + t = ast_for_exprlist(c, for_ch, Store); if (!t) return NULL; expression = ast_for_expr(c, CHILD(ch, 3)); if (!expression) return NULL; - if (asdl_seq_LEN(t) == 1) + /* Check the # of children rather than the length of t, since + (x for x, in ...) has 1 element in t, but still requires a Tuple. */ + if (NCH(for_ch) == 1) ge = comprehension((expr_ty)asdl_seq_GET(t, 0), expression, NULL, c->c_arena); else |