Commit 3421e034 authored by Stefan Behnel's avatar Stefan Behnel

fix "__qualname__" of names defined as 'global'

parent 8524b21f
...@@ -6679,6 +6679,8 @@ class ModuleNameMixin(object): ...@@ -6679,6 +6679,8 @@ class ModuleNameMixin(object):
def set_qualified_name(self, env, self_name): def set_qualified_name(self, env, self_name):
self.module_name = env.global_scope().qualified_name self.module_name = env.global_scope().qualified_name
qualified_name = [self_name] qualified_name = [self_name]
entry = env.lookup(self_name)
if not entry or not (entry.is_pyglobal and not entry.is_pyclass_attr):
while env and not env.is_module_scope: while env and not env.is_module_scope:
if env.is_closure_scope: if env.is_closure_scope:
qualified_name.append('<locals>') qualified_name.append('<locals>')
......
...@@ -47,24 +47,42 @@ def test_qualname(): ...@@ -47,24 +47,42 @@ def test_qualname():
def test_nested_qualname(): def test_nested_qualname():
""" """
>>> func, lambda_func = test_nested_qualname() >>> func, lambda_func, XYZ = test_nested_qualname()
>>> func().__qualname__ >>> func().__qualname__
'test_nested_qualname.<locals>.outer.<locals>.Test' 'test_nested_qualname.<locals>.outer.<locals>.Test'
>>> func().test.__qualname__ >>> func().test.__qualname__
'test_nested_qualname.<locals>.outer.<locals>.Test.test' 'test_nested_qualname.<locals>.outer.<locals>.Test.test'
>>> func()().__qualname__
'test_nested_qualname.<locals>.outer.<locals>.Test'
>>> func()().test.__qualname__ >>> func()().test.__qualname__
'test_nested_qualname.<locals>.outer.<locals>.Test.test' 'test_nested_qualname.<locals>.outer.<locals>.Test.test'
>>> func()().test().__qualname__
'XYZinner'
>>> func()().test()().__qualname__
'XYZinner'
>>> lambda_func.__qualname__ >>> lambda_func.__qualname__
'test_nested_qualname.<locals>.<lambda>' 'test_nested_qualname.<locals>.<lambda>'
>>> XYZ.__qualname__
'XYZ'
""" """
def outer(): def outer():
class Test(object): class Test(object):
def test(self): def test(self):
return 123 global XYZinner
class XYZinner(object): pass
return XYZinner
return Test return Test
return outer, lambda:None
global XYZ
class XYZ(object): pass
return outer, lambda:None, XYZ
def test_doc(): def test_doc():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment