Author: Raffael Tfirst <raffael.tfi...@gmail.com>
Branch: py3.5
Changeset: r84667:3d80438bd661
Date: 2016-05-24 21:54 +0200
http://bitbucket.org/pypy/pypy/changeset/3d80438bd661/

Log:    Add ast test for unpack in set, add TODO, define STAR as first token
        as Set

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
@@ -466,6 +466,7 @@
                              classdef_node.get_column())
         call = self.handle_call(classdef_node.get_child(3), call_name)
         body = self.handle_suite(classdef_node.get_child(6))
+        #TODO: any order
         return ast.ClassDef(
             name, call.args, call.keywords, call.starargs, call.kwargs,
             body, decorators, classdef_node.get_lineno(), 
classdef_node.get_column())
@@ -1198,7 +1199,7 @@
             if maker.type == tokens.RBRACE:
                 return ast.Dict(None, None, atom_node.get_lineno(), 
atom_node.get_column())
             n_maker_children = maker.num_children()
-            if n_maker_children == 1 or maker.get_child(1).type == 
tokens.COMMA:
+            if n_maker_children == 1 or maker.get_child(1).type == 
tokens.COMMA or maker.get_child(0).type == tokens.STAR:
                 elts = []
                 for i in range(0, n_maker_children, 2):
                     elts.append(self.handle_expr(maker.get_child(i)))
diff --git a/pypy/interpreter/astcompiler/test/test_astbuilder.py 
b/pypy/interpreter/astcompiler/test/test_astbuilder.py
--- a/pypy/interpreter/astcompiler/test/test_astbuilder.py
+++ b/pypy/interpreter/astcompiler/test/test_astbuilder.py
@@ -732,6 +732,29 @@
             assert isinstance(elt, ast.Num)
             assert self.space.eq_w(elt.n, self.space.wrap(i))
 
+    def test_set_unpack(self):
+        s = self.get_first_expr("{*{1}}")
+        assert isinstance(s, ast.Set)
+        assert len(s.elts) == 1
+        sta0 = s.elts[0]
+        assert isinstance(sta0, ast.Starred)
+        s0 = sta0.value
+        assert isinstance(s0, ast.Set)
+        assert len(s0.elts) == 1
+        assert isinstance(s0.elts[0], ast.Num)
+        assert self.space.eq_w(s0.elts[0].n, self.space.wrap(1))
+        s = self.get_first_expr("{*{0, 1, 2, 3, 4, 5}}")
+        assert isinstance(s, ast.Set)
+        assert len(s.elts) == 1
+        sta0 = s.elts[0]
+        assert isinstance(sta0, ast.Starred)
+        s0 = sta0.value
+        assert isinstance(s0, ast.Set)
+        assert len(s0.elts) == 6
+        for i, elt in enumerate(s0.elts):
+            assert isinstance(elt, ast.Num)
+            assert self.space.eq_w(elt.n, self.space.wrap(i))
+
     def test_set_context(self):
         tup = self.get_ast("(a, b) = c").body[0].targets[0]
         assert all(elt.ctx == ast.Store for elt in tup.elts)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to