From: Stefan Behnel Date: Sun, 6 Jan 2013 13:00:39 +0000 (+0100) Subject: add to __qualname__ for closures as defined by PEP 3155 X-Git-Tag: 0.18b1~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=159a3b9a07a74581d594e5c8cbddf6ce362aad2c;p=platform%2Fupstream%2Fpython-cython.git add to __qualname__ for closures as defined by PEP 3155 --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 3c4d865..d3f968b 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('') + 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 2c3e024..3c19d21 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..outer..Test' >>> func().test.__qualname__ - 'test_nested_qualname.outer.Test.test' + 'test_nested_qualname..outer..Test.test' >>> func()().test.__qualname__ - 'test_nested_qualname.outer.Test.test' + 'test_nested_qualname..outer..Test.test' + + >>> lambda_func.__qualname__ + 'test_nested_qualname..' """ def outer(): class Test(object): def test(self): return 123 return Test - return outer + return outer, lambda:None def test_doc():