[pypy-svn] r66211 - in pypy/branch/parser-compiler/pypy/interpreter/astcompiler: . test

benjamin at codespeak.net benjamin at codespeak.net
Tue Jul 14 17:32:41 CEST 2009


Author: benjamin
Date: Tue Jul 14 17:32:40 2009
New Revision: 66211

Modified:
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py
Log:
fix handling of statements with semicolons

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/astbuilder.py	Tue Jul 14 17:32:40 2009
@@ -62,8 +62,9 @@
                 if sub_stmts_count == 1:
                     stmts.append(self.handle_stmt(stmt))
                 else:
+                    stmt = stmt.children[0]
                     for j in range(sub_stmts_count):
-                        small_stmt = stmt.children[j]
+                        small_stmt = stmt.children[j * 2]
                         stmts.append(self.handle_stmt(small_stmt))
             return ast.Module(stmts)
         elif n.type == syms.eval_input:
@@ -116,13 +117,13 @@
         sequence = None
         expr_type = expr.__class__
         if expr_type is ast.Attribute:
-            if ctx is ast.Store:
+            if ctx == ast.Store:
                 self.check_forbidden_name(expr.attr, node)
             expr.ctx = ctx
         elif expr_type is ast.Subscript:
             expr.ctx = ctx
         elif expr_type is ast.Name:
-            if ctx is ast.Store:
+            if ctx == ast.Store:
                 self.check_forbidden_name(expr.id, node)
             expr.ctx = ctx
         elif expr_type is ast.List:
@@ -161,7 +162,7 @@
         else:
             raise AssertionError("unkown expression in set_context()")
         if error is not None:
-            if ctx is ast.Store:
+            if ctx == ast.Store:
                 action = "assign to"
             else:
                 action = "delete"

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_astbuilder.py	Tue Jul 14 17:32:40 2009
@@ -46,6 +46,12 @@
         assert isinstance(mod, ast.Interactive)
         assert len(mod.body) == 1
 
+        mod = self.get_ast("x = 23; y = 23; b = 23")
+        assert isinstance(mod, ast.Module)
+        assert len(mod.body) == 3
+        for stmt in mod.body:
+            assert isinstance(stmt, ast.Assign)
+
     def test_print(self):
         pri = self.get_first_stmt("print x")
         assert isinstance(pri, ast.Print)



More information about the Pypy-commit mailing list