[pypy-commit] pypy py3.5: __qualname__ should not use the parent scope for "global" functions.

amauryfa pypy.commits at gmail.com
Tue Nov 8 03:17:12 EST 2016


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3.5
Changeset: r88199:9da9ea8cb259
Date: 2016-11-08 09:16 +0100
http://bitbucket.org/pypy/pypy/changeset/9da9ea8cb259/

Log:	__qualname__ should not use the parent scope for "global" functions.

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
@@ -210,7 +210,9 @@
 
     def sub_scope(self, kind, name, node, lineno):
         """Convenience function for compiling a sub scope."""
-        if self.qualname:
+        if self.scope.lookup(name) == symtable.SCOPE_GLOBAL_EXPLICIT:
+            qualname = name
+        elif self.qualname:
             qualname = '%s.%s' % (self.qualname, name)
         else:
             qualname = name
diff --git a/pypy/interpreter/test/test_function.py b/pypy/interpreter/test/test_function.py
--- a/pypy/interpreter/test/test_function.py
+++ b/pypy/interpreter/test/test_function.py
@@ -38,6 +38,17 @@
                 pass
         assert A.f.__qualname__ == 'test_qualname_method.<locals>.A.f'
 
+    def test_qualname_global(self):
+        def f():
+            global inner_global
+            def inner_global():
+                def inner_function2():
+                    pass
+                return inner_function2
+            return inner_global
+        assert f().__qualname__ == 'inner_global'
+        assert f()().__qualname__ == 'inner_global.<locals>.inner_function2'
+
     def test_annotations(self):
         def f(): pass
         ann = f.__annotations__


More information about the pypy-commit mailing list