[pypy-commit] pypy py3k: issue1804: fix nonlocal decls not being added to free_vars

pjenvey noreply at buildbot.pypy.org
Sat Aug 2 00:23:24 CEST 2014


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r72638:1f716034739d
Date: 2014-08-01 15:21 -0700
http://bitbucket.org/pypy/pypy/changeset/1f716034739d/

Log:	issue1804: fix nonlocal decls not being added to free_vars

diff --git a/pypy/interpreter/astcompiler/symtable.py b/pypy/interpreter/astcompiler/symtable.py
--- a/pypy/interpreter/astcompiler/symtable.py
+++ b/pypy/interpreter/astcompiler/symtable.py
@@ -136,6 +136,7 @@
                 err = "no binding for nonlocal '%s' found" % (name,)
                 raise SyntaxError(err, self.lineno, self.col_offset)
             self.symbols[name] = SCOPE_FREE
+            self.free_vars.append(name)
             free[name] = None
         elif flags & SYM_BOUND:
             self.symbols[name] = SCOPE_LOCAL
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -808,6 +808,17 @@
             return y"""
         yield self.st, test, "f()", 4
 
+    def test_nonlocal_from_arg(self):
+        test = """if 1:
+        def test1(x):
+            def test2():
+                nonlocal x
+                def test3():
+                    return x
+                return test3()
+            return test2()"""
+        yield self.st, test, "test1(2)", 2
+
     def test_lots_of_loops(self):
         source = "for x in y: pass\n" * 1000
         compile_with_astcompiler(source, 'exec', self.space)


More information about the pypy-commit mailing list