[Python-checkins] python/dist/src/Python ast.c,1.1.2.66,1.1.2.67

jhylton@users.sourceforge.net jhylton at users.sourceforge.net
Thu Oct 13 17:42:44 CEST 2005


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

Modified Files:
      Tag: ast-branch
	ast.c 
Log Message:
Fix two separate problems.

Generate expected error for assignments to literals, e.g. 1 = 1 or (1,) = 1.

Fix assignment of lineno for FromImport statements: Use the line
number of the module being imported, not of the names being bound from
it.  Fixes test_future.



Index: ast.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v
retrieving revision 1.1.2.66
retrieving revision 1.1.2.67
diff -u -d -r1.1.2.66 -r1.1.2.67
--- ast.c	12 Oct 2005 03:18:07 -0000	1.1.2.66
+++ ast.c	13 Oct 2005 15:42:40 -0000	1.1.2.67
@@ -392,10 +392,20 @@
         case GeneratorExp_kind:
             return ast_error(n, "assignment to generator expression "
                              "not possible");
-        default:
-	    return ast_error(n, "unexpected node in assignment");
-	    break;
+        case Num_kind:
+        case Str_kind:
+	    return ast_error(n, "can't assign to literal");
+       default: {
+	   char buf[300];
+	   PyOS_snprintf(buf, sizeof(buf), 
+			 "unexpected expression in assignment %d (line %d)", 
+			 e->kind, e->lineno);
+	   return ast_error(n, buf);
+       }
     }
+    /* If the LHS is a list or tuple, we need to set the assignment
+       context for all the tuple elements.  
+    */
     if (s) {
 	int i;
 
@@ -2112,6 +2122,7 @@
 	stmt_ty import;
         int n_children;
         const char *from_modules;
+	int lineno = LINENO(n);
 	alias_ty mod = alias_for_import_name(CHILD(n, 1));
 	if (!mod)
             return NULL;
@@ -2129,7 +2140,7 @@
             }
         }
         else if (from_modules[0] == '*') {
-            n = CHILD(n,3); /* from ... import * */
+            n = CHILD(n, 3); /* from ... import * */
         }
         else if (from_modules[0] == '(')
             n = CHILD(n, 4);                  /* from ... import (x, y, z) */
@@ -2166,7 +2177,7 @@
             }
 	    asdl_seq_APPEND(aliases, import_alias);
         }
-	import = ImportFrom(mod->name, aliases, LINENO(n));
+	import = ImportFrom(mod->name, aliases, lineno);
 	free(mod);
 	return import;
     }



More information about the Python-checkins mailing list