summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-08-15 22:59:21 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-08-15 22:59:21 (GMT)
commitc0ba828857fa1a4f726a113c811badb5f2259bb9 (patch)
treef241d1c2987545ee7db7e850b63cd60341f81f02 /Python/ast.c
parent8cabfa352b93e7126d5147a2f8f056cad8d724f6 (diff)
downloadcpython-c0ba828857fa1a4f726a113c811badb5f2259bb9.zip
cpython-c0ba828857fa1a4f726a113c811badb5f2259bb9.tar.gz
cpython-c0ba828857fa1a4f726a113c811badb5f2259bb9.tar.bz2
better col_offsets for "for" statements with tuple unpacking #6704
Patch from Frank Wierzbicki.
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 0644da8..2f975ac 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -1047,7 +1047,7 @@ ast_for_listcomp(struct compiling *c, const node *n)
list_if: 'if' test [list_iter]
testlist_safe: test [(',' test)+ [',']]
*/
- expr_ty elt;
+ expr_ty elt, first;
asdl_seq *listcomps;
int i, n_fors;
node *ch;
@@ -1087,11 +1087,11 @@ ast_for_listcomp(struct compiling *c, const node *n)
/* 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.
*/
+ first = (expr_ty)asdl_seq_GET(t, 0);
if (NCH(for_ch) == 1)
- lc = comprehension((expr_ty)asdl_seq_GET(t, 0), expression, NULL,
- c->c_arena);
+ lc = comprehension(first, expression, NULL, c->c_arena);
else
- lc = comprehension(Tuple(t, Store, LINENO(ch), ch->n_col_offset,
+ lc = comprehension(Tuple(t, Store, first->lineno, first->col_offset,
c->c_arena),
expression, NULL, c->c_arena);
if (!lc)
@@ -1226,7 +1226,7 @@ ast_for_genexp(struct compiling *c, const node *n)
for (i = 0; i < n_fors; i++) {
comprehension_ty ge;
asdl_seq *t;
- expr_ty expression;
+ expr_ty expression, first;
node *for_ch;
REQ(ch, gen_for);
@@ -1241,11 +1241,11 @@ ast_for_genexp(struct compiling *c, const node *n)
/* 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. */
+ first = (expr_ty)asdl_seq_GET(t, 0);
if (NCH(for_ch) == 1)
- ge = comprehension((expr_ty)asdl_seq_GET(t, 0), expression,
- NULL, c->c_arena);
+ ge = comprehension(first, expression, NULL, c->c_arena);
else
- ge = comprehension(Tuple(t, Store, LINENO(ch), ch->n_col_offset,
+ ge = comprehension(Tuple(t, Store, first->lineno, first->col_offset,
c->c_arena),
expression, NULL, c->c_arena);
@@ -2844,7 +2844,7 @@ ast_for_for_stmt(struct compiling *c, const node *n)
{
asdl_seq *_target, *seq = NULL, *suite_seq;
expr_ty expression;
- expr_ty target;
+ expr_ty target, first;
const node *node_target;
/* for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] */
REQ(n, for_stmt);
@@ -2861,10 +2861,11 @@ ast_for_for_stmt(struct compiling *c, const node *n)
return NULL;
/* Check the # of children rather than the length of _target, since
for x, in ... has 1 element in _target, but still requires a Tuple. */
+ first = (expr_ty)asdl_seq_GET(_target, 0);
if (NCH(node_target) == 1)
- target = (expr_ty)asdl_seq_GET(_target, 0);
+ target = first;
else
- target = Tuple(_target, Store, LINENO(n), n->n_col_offset, c->c_arena);
+ target = Tuple(_target, Store, first->lineno, first->col_offset, c->c_arena);
expression = ast_for_testlist(c, CHILD(n, 3));
if (!expression)