[Python-checkins] python/dist/src/Python ast.c,1.1.2.64,1.1.2.65

jhylton@users.sourceforge.net jhylton at users.sourceforge.net
Thu Sep 29 21:28:02 CEST 2005


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26680/Python

Modified Files:
      Tag: ast-branch
	ast.c 
Log Message:
Add a few missing syntax errors.

Report error for f(lambda x:x[0] = 3) as in recent-ish change to old
compiler.  Add error reporting for generator expressions in assignment
context.

Note that test_genexps still fails because the syntax error printed
doesn't match what doctest expects.  In particular, it prints a
strange generated filename.



Index: ast.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v
retrieving revision 1.1.2.64
retrieving revision 1.1.2.65
diff -u -d -r1.1.2.64 -r1.1.2.65
--- ast.c	30 Aug 2005 23:37:45 -0000	1.1.2.64
+++ ast.c	29 Sep 2005 19:27:58 -0000	1.1.2.65
@@ -1694,7 +1694,18 @@
 		e = ast_for_expr(c, CHILD(ch, 0));
                 if (!e)
                     goto error;
-		assert(e->kind == Name_kind);
+                /* f(lambda x: x[0] = 3) ends up getting parsed with
+                 * LHS test = lambda x: x[0], and RHS test = 3.
+                 * SF bug 132313 points out that complaining about a keyword
+                 * then is very confusing.
+                 */
+                if (e->kind == Lambda_kind) {
+                  ast_error(CHILD(ch, 0), "lambda cannot contain assignment");
+                  goto error;
+                } else if (e->kind != Name_kind) {
+                  ast_error(CHILD(ch, 0), "keyword can't be an expression");
+                  goto error;
+                }
 		key = e->v.Name.id;
 		free(e);
 		e = ast_for_expr(c, CHILD(ch, 2));
@@ -1769,6 +1780,11 @@
         expr1 = ast_for_testlist(c, CHILD(n, 0));
         if (!expr1)
             return NULL;
+        if (expr1->kind == GeneratorExp_kind) {
+          ast_error(CHILD(n, 0), "augmented assignment to generator "
+                                 "expression not possible");
+          return NULL;
+        }
 	if (expr1->kind == Name_kind) {
 		char *var_name = PyString_AS_STRING(expr1->v.Name.id);
 		if (var_name[0] == 'N' && !strcmp(var_name, "None")) {
@@ -1800,6 +1816,13 @@
 	for (i = 0; i < NCH(n) - 2; i += 2) {
 	    expr_ty e = ast_for_testlist(c, CHILD(n, i));
 
+            if (e->kind == GeneratorExp_kind) {
+              ast_error(CHILD(n, i),
+                        "assignment to generator expression not possible");
+              asdl_seq_free(targets);
+              return NULL;
+            }
+
 	    /* set context to assign */
 	    if (!e) {
 		asdl_seq_free(targets);



More information about the Python-checkins mailing list