[Python-checkins] r50597 - in python/trunk: Lib/test/test_grammar.py Misc/NEWS Python/ast.c Python/import.c

neal.norwitz python-checkins at python.org
Wed Jul 12 07:26:19 CEST 2006


Author: neal.norwitz
Date: Wed Jul 12 07:26:17 2006
New Revision: 50597

Modified:
   python/trunk/Lib/test/test_grammar.py
   python/trunk/Misc/NEWS
   python/trunk/Python/ast.c
   python/trunk/Python/import.c
Log:
Bug #1520864: unpacking singleton tuples in for loop (for x, in) work again.



Modified: python/trunk/Lib/test/test_grammar.py
==============================================================================
--- python/trunk/Lib/test/test_grammar.py	(original)
+++ python/trunk/Lib/test/test_grammar.py	Wed Jul 12 07:26:17 2006
@@ -531,6 +531,11 @@
 for x in Squares(10): n = n+x
 if n != 285: raise TestFailed, 'for over growing sequence'
 
+result = []
+for x, in [(1,), (2,), (3,)]:
+    result.append(x)
+vereq(result, [1, 2, 3])
+
 print 'try_stmt'
 ### try_stmt: 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite]
 ###         | 'try' ':' suite 'finally' ':' suite

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Wed Jul 12 07:26:17 2006
@@ -12,6 +12,8 @@
 Core and builtins
 -----------------
 
+- Bug #1520864: unpacking singleton tuples in for loop (for x, in) work again.
+
 - Bug #1441486: The literal representation of -(sys.maxint - 1)
   again evaluates to a int object, not a long.
 

Modified: python/trunk/Python/ast.c
==============================================================================
--- python/trunk/Python/ast.c	(original)
+++ python/trunk/Python/ast.c	Wed Jul 12 07:26:17 2006
@@ -2666,6 +2666,7 @@
     asdl_seq *_target, *seq = NULL, *suite_seq;
     expr_ty expression;
     expr_ty target;
+    const node *node_target;
     /* for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] */
     REQ(n, for_stmt);
 
@@ -2675,10 +2676,13 @@
             return NULL;
     }
 
-    _target = ast_for_exprlist(c, CHILD(n, 1), Store);
+    node_target = CHILD(n, 1);
+    _target = ast_for_exprlist(c, node_target, Store);
     if (!_target)
         return NULL;
-    if (asdl_seq_LEN(_target) == 1)
+    /* Check the # of children rather than the length of _target, since
+       for x, in ... has 1 element in _target, but still requires a Tuple. */
+    if (NCH(node_target) == 1)
 	target = (expr_ty)asdl_seq_GET(_target, 0);
     else
 	target = Tuple(_target, Store, LINENO(n), n->n_col_offset, c->c_arena);

Modified: python/trunk/Python/import.c
==============================================================================
--- python/trunk/Python/import.c	(original)
+++ python/trunk/Python/import.c	Wed Jul 12 07:26:17 2006
@@ -60,6 +60,7 @@
        Python 2.5a0: 62081 (ast-branch)
        Python 2.5a0: 62091 (with)
        Python 2.5a0: 62092 (changed WITH_CLEANUP opcode)
+       Python 2.5c1: 62101 (fix wrong code: for x, in ...)
 .
 */
 #define MAGIC (62092 | ((long)'\r'<<16) | ((long)'\n'<<24))


More information about the Python-checkins mailing list