[pypy-commit] pypy py3.5: Bypass error in visit_starred, use python 3.5 asdl

raffael_t pypy.commits at gmail.com
Fri May 27 16:06:38 EDT 2016


Author: Raffael Tfirst <raffael.tfirst at gmail.com>
Branch: py3.5
Changeset: r84738:5090279ba5d4
Date: 2016-05-27 22:01 +0200
http://bitbucket.org/pypy/pypy/changeset/5090279ba5d4/

Log:	Bypass error in visit_starred, use python 3.5 asdl

diff --git a/pypy/interpreter/astcompiler/astbuilder.py b/pypy/interpreter/astcompiler/astbuilder.py
--- a/pypy/interpreter/astcompiler/astbuilder.py
+++ b/pypy/interpreter/astcompiler/astbuilder.py
@@ -1194,11 +1194,10 @@
             return self.handle_listcomp(second_child)
         elif first_child_type == tokens.LBRACE:
             maker = atom_node.get_child(1)
-            #TODO: check STAR and DOUBLESTAR
             if maker.type == tokens.RBRACE:
                 return ast.Dict(None, None, atom_node.get_lineno(), atom_node.get_column())
             n_maker_children = maker.num_children()
-            # or maker.get_child(0).type == tokens.STAR
+            #import pdb;pdb.set_trace()
             if n_maker_children == 1 or maker.get_child(1).type == tokens.COMMA:
                 elts = []
                 for i in range(0, n_maker_children, 2):
diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -1049,10 +1049,11 @@
             self.emit_op_arg(op, elt_count)
 
     def visit_Starred(self, star):
-        if star.ctx != ast.Store:
-            self.error("can use starred expression only as assignment target",
-                       star)
-        self.error("starred assignment target must be in a list or tuple", star)
+        if star.ctx != ast.Load:
+            if star.ctx != ast.Store:
+                self.error("can use starred expression only as assignment target",
+                           star)
+            self.error("starred assignment target must be in a list or tuple", star)
 
     def visit_Tuple(self, tup):
         self.update_position(tup.lineno)
diff --git a/pypy/interpreter/astcompiler/tools/Python.asdl b/pypy/interpreter/astcompiler/tools/Python.asdl
--- a/pypy/interpreter/astcompiler/tools/Python.asdl
+++ b/pypy/interpreter/astcompiler/tools/Python.asdl
@@ -1,4 +1,4 @@
--- ASDL's five builtin types are identifier, int, string, bytes, object
+-- ASDL's six builtin types are identifier, int, string, bytes, object, singleton
 
 module Python
 {
@@ -9,13 +9,14 @@
         -- not really an actual node but useful in Jython's typesystem.
         | Suite(stmt* body)
 
-    stmt = FunctionDef(identifier name, arguments args, 
-                           stmt* body, expr* decorator_list, expr? returns)
-          | ClassDef(identifier name, 
+    stmt = FunctionDef(identifier name, arguments args,
+                       stmt* body, expr* decorator_list, expr? returns)
+          | AsyncFunctionDef(identifier name, arguments args,
+                             stmt* body, expr* decorator_list, expr? returns)
+
+          | ClassDef(identifier name,
              expr* bases,
              keyword* keywords,
-             expr? starargs,
-             expr? kwargs,
              stmt* body,
              expr* decorator_list)
           | Return(expr? value)
@@ -26,9 +27,11 @@
 
           -- use 'orelse' because else is a keyword in target languages
           | For(expr target, expr iter, stmt* body, stmt* orelse)
+          | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse)
           | While(expr test, stmt* body, stmt* orelse)
           | If(expr test, stmt* body, stmt* orelse)
           | With(withitem* items, stmt* body)
+          | AsyncWith(withitem* items, stmt* body)
 
           | Raise(expr? exc, expr? cause)
           | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
@@ -59,43 +62,40 @@
          | DictComp(expr key, expr value, comprehension* generators)
          | GeneratorExp(expr elt, comprehension* generators)
          -- the grammar constrains where yield expressions can occur
+         | Await(expr value)
          | Yield(expr? value)
          | YieldFrom(expr value)
          -- need sequences for compare to distinguish between
          -- x < 4 < 3 and (x < 4) < 3
          | Compare(expr left, cmpop* ops, expr* comparators)
-         | Call(expr func, expr* args, keyword* keywords,
-             expr? starargs, expr? kwargs)
+         | Call(expr func, expr* args, keyword* keywords)
          | Num(object n) -- a number as a PyObject.
          | Str(string s) -- need to specify raw, unicode, etc?
-         | Bytes(string s)
+         | Bytes(bytes s)
+         | NameConstant(singleton value)
          | Ellipsis
-         -- other literals? bools?
 
          -- the following expression can appear in assignment context
          | Attribute(expr value, identifier attr, expr_context ctx)
          | Subscript(expr value, slice slice, expr_context ctx)
          | Starred(expr value, expr_context ctx)
          | Name(identifier id, expr_context ctx)
-         | List(expr* elts, expr_context ctx) 
+         | List(expr* elts, expr_context ctx)
          | Tuple(expr* elts, expr_context ctx)
 
-         -- PyPy modification
-         | Const(object value)
-
           -- col_offset is the byte offset in the utf8 string the parser uses
           attributes (int lineno, int col_offset)
 
     expr_context = Load | Store | Del | AugLoad | AugStore | Param
 
-    slice = Slice(expr? lower, expr? upper, expr? step) 
-          | ExtSlice(slice* dims) 
-          | Index(expr value) 
+    slice = Slice(expr? lower, expr? upper, expr? step)
+          | ExtSlice(slice* dims)
+          | Index(expr value)
 
-    boolop = And | Or 
+    boolop = And | Or
 
-    operator = Add | Sub | Mult | Div | Mod | Pow | LShift 
-                 | RShift | BitOr | BitXor | BitAnd | FloorDiv | MatMul
+    operator = Add | Sub | Mult | MatMul | Div | Mod | Pow | LShift
+                 | RShift | BitOr | BitXor | BitAnd | FloorDiv
 
     unaryop = Invert | Not | UAdd | USub
 
@@ -106,14 +106,14 @@
     excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
                     attributes (int lineno, int col_offset)
 
-    arguments = (arg* args, identifier? vararg, expr? varargannotation,
-                     arg* kwonlyargs, identifier? kwarg,
-                     expr? kwargannotation, expr* defaults,
-                     expr* kw_defaults)
+    arguments = (arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults,
+                 arg? kwarg, expr* defaults)
+
     arg = (identifier arg, expr? annotation)
+           attributes (int lineno, int col_offset)
 
-    -- keyword arguments supplied to call
-    keyword = (identifier arg, expr value)
+    -- keyword arguments supplied to call (NULL identifier for **kwargs)
+    keyword = (identifier? arg, expr value)
 
     -- import name with optional 'as' alias.
     alias = (identifier name, identifier? asname)


More information about the pypy-commit mailing list