summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-09-05 03:53:08 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2006-09-05 03:53:08 (GMT)
commitdac090d3e62cadd24fc6b73ab177bf98326c1849 (patch)
tree4b6fa9d21592bdd09ad8204daec1a4bf18c710de /Python
parent4bc2c0919b2ed31851e9c3423ab85614fe35a75a (diff)
downloadcpython-dac090d3e62cadd24fc6b73ab177bf98326c1849.zip
cpython-dac090d3e62cadd24fc6b73ab177bf98326c1849.tar.gz
cpython-dac090d3e62cadd24fc6b73ab177bf98326c1849.tar.bz2
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. This code should be refactored to eliminate the duplication. I'm sure the listcomp/genexpr code can be refactored. I'm not sure if the for loop can re-use any of the same code though. Will backport to 2.5 (the only place it matters).
Diffstat (limited to 'Python')
-rw-r--r--Python/ast.c16
-rw-r--r--Python/import.c3
2 files changed, 14 insertions, 5 deletions
diff --git a/Python/ast.c b/Python/ast.c
index b356192..4d0b991 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
diff --git a/Python/import.c b/Python/import.c
index da9de8b..a0c5055 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -64,9 +64,10 @@ extern time_t PyOS_GetLastModificationTime(char *, FILE *);
Python 2.5b3: 62111 (fix wrong code: x += yield)
Python 2.5c1: 62121 (fix wrong lnotab with for loops and
storing constants that should have been removed)
+ Python 2.5c2: 62131 (fix wrong code: for x, in ... in listcomp/genexp)
.
*/
-#define MAGIC (62121 | ((long)'\r'<<16) | ((long)'\n'<<24))
+#define MAGIC (62131 | ((long)'\r'<<16) | ((long)'\n'<<24))
/* Magic word as global; note that _PyImport_Init() can change the
value of this global to accommodate for alterations of how the