[pypy-commit] pypy py3.5: Fix comprehension unpack error

raffael_t pypy.commits at gmail.com
Wed Jun 22 15:02:36 EDT 2016


Author: Raffael Tfirst <raffael.tfirst at gmail.com>
Branch: py3.5
Changeset: r85337:2060ceb7f13b
Date: 2016-06-22 21:01 +0200
http://bitbucket.org/pypy/pypy/changeset/2060ceb7f13b/

Log:	Fix comprehension unpack error

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
@@ -1315,25 +1315,28 @@
         return comps
 
     def handle_genexp(self, genexp_node):
-        elt = self.handle_expr(genexp_node.get_child(0))
-        if elt.type == syms.star_expr:
-            self.error("iterable unpacking cannot be used in comprehension", elt)
+        ch = genexp_node.get_child(0)
+        elt = self.handle_expr(ch)
+        if isinstance(elt, ast.Starred):
+            self.error("iterable unpacking cannot be used in comprehension", ch)
         comps = self.comprehension_helper(genexp_node.get_child(1))
         return ast.GeneratorExp(elt, comps, genexp_node.get_lineno(),
                                 genexp_node.get_column())
 
     def handle_listcomp(self, listcomp_node):
-        elt = self.handle_expr(listcomp_node.get_child(0))
-        if elt.type == syms.star_expr:
-            self.error("iterable unpacking cannot be used in comprehension", elt)
+        ch = listcomp_node.get_child(0)
+        elt = self.handle_expr(ch)
+        if isinstance(elt, ast.Starred):
+            self.error("iterable unpacking cannot be used in comprehension", ch)
         comps = self.comprehension_helper(listcomp_node.get_child(1))
         return ast.ListComp(elt, comps, listcomp_node.get_lineno(),
                             listcomp_node.get_column())
 
     def handle_setcomp(self, set_maker):
-        elt = self.handle_expr(set_maker.get_child(0))
-        if elt.type == syms.star_expr:
-            self.error("iterable unpacking cannot be used in comprehension", elt)
+        ch = set_maker.get_child(0)
+        elt = self.handle_expr(ch)
+        if isinstance(elt, ast.Starred):
+            self.error("iterable unpacking cannot be used in comprehension", ch)
         comps = self.comprehension_helper(set_maker.get_child(1))
         return ast.SetComp(elt, comps, set_maker.get_lineno(),
                            set_maker.get_column())


More information about the pypy-commit mailing list