[pypy-commit] pypy py3.3: Add "<locals>" in the qualname when the object comes from an executed function block.
amauryfa
noreply at buildbot.pypy.org
Thu Dec 18 22:38:45 CET 2014
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3.3
Changeset: r75024:daf8e9141435
Date: 2014-12-18 22:35 +0100
http://bitbucket.org/pypy/pypy/changeset/daf8e9141435/
Log: Add "<locals>" in the qualname when the object comes from an
executed function block.
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
@@ -186,7 +186,10 @@
self.frame_blocks = []
self.interactive = False
self.temporary_name_counter = 1
- self.qualname = qualname
+ if isinstance(self.scope, symtable.FunctionScope):
+ self.qualname = qualname + '.<locals>'
+ else:
+ self.qualname = qualname
self._compile(tree)
def _compile(self, tree):
diff --git a/pypy/interpreter/test/test_class.py b/pypy/interpreter/test/test_class.py
--- a/pypy/interpreter/test/test_class.py
+++ b/pypy/interpreter/test/test_class.py
@@ -114,5 +114,5 @@
class C:
class D:
pass
- assert C.__qualname__ == 'test_qualname.C'
- assert C.D.__qualname__ == 'test_qualname.C.D'
+ assert C.__qualname__ == 'test_qualname.<locals>.C'
+ assert C.D.__qualname__ == 'test_qualname.<locals>.C.D'
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
@@ -22,8 +22,12 @@
assert f.__module__ == 'mymodulename'
def test_qualname(self):
- def f(): pass
- assert f.__qualname__ == 'test_qualname.f'
+ def f():
+ def g():
+ pass
+ return g
+ assert f.__qualname__ == 'test_qualname.<locals>.f'
+ assert f().__qualname__ == 'test_qualname.<locals>.f.<locals>.g'
f.__qualname__ = 'qualname'
assert f.__qualname__ == 'qualname'
raises(TypeError, "f.__qualname__ = b'name'")
More information about the pypy-commit
mailing list