summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2013-01-06 14:00:39 +0100
committerStefan Behnel <stefan_ml@behnel.de>2013-01-06 14:00:39 +0100
commit159a3b9a07a74581d594e5c8cbddf6ce362aad2c (patch)
tree6ae02d38b751c25a0f76a0f16d780facd14574d4
parent502394e7378b1d470a106e5a6bf0c66839acfd24 (diff)
downloadcython-159a3b9a07a74581d594e5c8cbddf6ce362aad2c.tar.gz
add <locals> to __qualname__ for closures as defined by PEP 3155
-rwxr-xr-xCython/Compiler/ExprNodes.py11
-rw-r--r--tests/run/cyfunction.pyx14
2 files changed, 16 insertions, 9 deletions
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
index 3c4d8650d..d3f968b2c 100755
--- a/Cython/Compiler/ExprNodes.py
+++ b/Cython/Compiler/ExprNodes.py
@@ -6019,10 +6019,13 @@ class DictItemNode(ExprNode):
class ModuleNameMixin(object):
def set_qualified_name(self, env, self_name):
self.module_name = env.global_scope().qualified_name
- prefix = env.qualified_name[len(self.module_name)+1:]
- if prefix:
- self_name = prefix + '.' + self_name
- self.qualname = StringEncoding.EncodedString(self_name)
+ qualified_name = [self_name]
+ while env and not env.is_module_scope:
+ if env.is_closure_scope:
+ qualified_name.append('<locals>')
+ qualified_name.append(env.name)
+ env = env.parent_scope
+ self.qualname = StringEncoding.EncodedString('.'.join(qualified_name[::-1]))
def get_py_mod_name(self, code):
return code.get_py_string_const(
diff --git a/tests/run/cyfunction.pyx b/tests/run/cyfunction.pyx
index 2c3e024a0..3c19d21f6 100644
--- a/tests/run/cyfunction.pyx
+++ b/tests/run/cyfunction.pyx
@@ -47,20 +47,24 @@ def test_qualname():
def test_nested_qualname():
"""
- >>> func = test_nested_qualname()
+ >>> func, lambda_func = test_nested_qualname()
+
>>> func().__qualname__
- 'test_nested_qualname.outer.Test'
+ 'test_nested_qualname.<locals>.outer.<locals>.Test'
>>> func().test.__qualname__
- 'test_nested_qualname.outer.Test.test'
+ 'test_nested_qualname.<locals>.outer.<locals>.Test.test'
>>> func()().test.__qualname__
- 'test_nested_qualname.outer.Test.test'
+ 'test_nested_qualname.<locals>.outer.<locals>.Test.test'
+
+ >>> lambda_func.__qualname__
+ 'test_nested_qualname.<locals>.<lambda>'
"""
def outer():
class Test(object):
def test(self):
return 123
return Test
- return outer
+ return outer, lambda:None
def test_doc():