[Python-checkins] CVS: python/dist/src/Modules parsermodule.c,2.65,2.66

Guido van Rossum gvanrossum@users.sourceforge.net
2001年10月15日 08:44:07 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv24320/Modules
Modified Files:
	parsermodule.c 
Log Message:
Very subtle syntax change: in a list comprehension, the testlist in
"for <var> in <testlist> may no longer be a single test followed by
a comma. This solves SF bug #431886. Note that if the testlist
contains more than one test, a trailing comma is still allowed, for
maximum backward compatibility; but this example is not:
 [(x, y) for x in range(10), for y in range(10)]
 ^
The fix involved creating a new nonterminal 'testlist_safe' whose
definition doesn't allow the trailing comma if there's only one test:
 testlist_safe: test [(',' test)+ [',']]
Index: parsermodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/parsermodule.c,v
retrieving revision 2.65
retrieving revision 2.66
diff -C2 -d -r2.65 -r2.66
*** parsermodule.c	2001年08月15日 16:44:56	2.65
--- parsermodule.c	2001年10月15日 15:44:05	2.66
***************
*** 1040,1043 ****
--- 1040,1051 ----
 
 
+ static int
+ validate_testlist_safe(node *tree)
+ {
+ return (validate_repeating_list(tree, testlist_safe,
+ validate_test, "testlist_safe"));
+ }
+ 
+ 
 /* '*' NAME [',' '**' NAME] | '**' NAME
 */
***************
*** 1219,1223 ****
 && validate_exprlist(CHILD(tree, 1))
 && validate_name(CHILD(tree, 2), "in")
! && validate_testlist(CHILD(tree, 3)));
 
 return res;
--- 1227,1231 ----
 && validate_exprlist(CHILD(tree, 1))
 && validate_name(CHILD(tree, 2), "in")
! && validate_testlist_safe(CHILD(tree, 3)));
 
 return res;

AltStyle によって変換されたページ (->オリジナル) /