[pypy-commit] pypy stdlib-2.7.9: merged upstream

alex_gaynor noreply at buildbot.pypy.org
Thu Dec 18 00:53:32 CET 2014


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: stdlib-2.7.9
Changeset: r75006:abfb4eb09565
Date: 2014-12-17 15:53 -0800
http://bitbucket.org/pypy/pypy/changeset/abfb4eb09565/

Log:	merged upstream

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
@@ -277,10 +277,17 @@
         globs = None
         locs = None
         to_execute = self.handle_expr(exec_node.children[1])
-        if child_count >= 4:
+        if child_count < 4:
+            if isinstance(to_execute, ast.Tuple) and \
+                    (len(to_execute.elts) == 2 or len(to_execute.elts) == 3):
+                globs = to_execute.elts[1]
+                if len(to_execute.elts) == 3:
+                    locs = to_execute.elts[2]
+                to_execute = to_execute.elts[0]
+        elif child_count >= 4:
             globs = self.handle_expr(exec_node.children[3])
-        if child_count == 6:
-            locs = self.handle_expr(exec_node.children[5])
+            if child_count == 6:
+                locs = self.handle_expr(exec_node.children[5])
         return ast.Exec(to_execute, globs, locs, exec_node.lineno,
                         exec_node.column)
 
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1619,13 +1619,6 @@
     def prepare_exec(f, prog, globals, locals, compile_flags, builtin, codetype):
         """Manipulate parameters to exec statement to (codeobject, dict, dict).
         """
-        if (globals is None and locals is None and
-            isinstance(prog, tuple) and
-            (len(prog) == 2 or len(prog) == 3)):
-            globals = prog[1]
-            if len(prog) == 3:
-                locals = prog[2]
-            prog = prog[0]
         if globals is None:
             globals = f.f_globals
             if locals is None:
diff --git a/pypy/interpreter/test/test_exec.py b/pypy/interpreter/test/test_exec.py
--- a/pypy/interpreter/test/test_exec.py
+++ b/pypy/interpreter/test/test_exec.py
@@ -18,8 +18,7 @@
     ''')
 
 
-class AppTestExecStmt: 
-
+class AppTestExecStmt:
     def test_string(self):
         g = {}
         l = {}
@@ -30,7 +29,7 @@
         g = {}
         exec "a = 3" in g
         assert g['a'] == 3
-        
+
     def test_builtinsupply(self):
         g = {}
         exec "pass" in g
@@ -63,7 +62,7 @@
         l = {}
         exec ("a = 3", g, l)
         assert l['a'] == 3
-        
+
     def test_tupleglobals(self):
         g = {}
         exec ("a = 3", g)
@@ -207,9 +206,8 @@
     def test_exec_and_name_lookups(self):
         ns = {}
         exec """def f():
-        exec 'x=1' in locals()
-        return x
-""" in ns
+            exec 'x=1' in locals()
+            return x""" in ns
 
         f = ns['f']
 
@@ -246,3 +244,18 @@
         exec c
         assert len(x) == 6
         assert ord(x[0]) == 0x0439
+
+    def test_nested_qualified_exec(self):
+        code = ["""
+def g():
+    def f():
+        if True:
+            exec "" in {}, {}
+        """, """
+def g():
+    def f():
+        if True:
+            exec("", {}, {})
+        """]
+        for c in code:
+            compile(c, "<code>", "exec")


More information about the pypy-commit mailing list