[issue13672] Add co_qualname attribute in code objects
Meador Inge
report at bugs.python.org
Tue Jan 24 21:09:55 CET 2012
Meador Inge <meadori at gmail.com> added the comment:
This seems to be a useful feature to me. Another area where it can help
is with fixing function types. Currently the qualname can be lost:
>>> def f():
... def g():
... pass
... return g
...
>>> g = f()
>>> g
<function f.<locals>.g at 0x7f1dac4d8ba0>
>>> types.FunctionType(f.__code__, {})
<function f at 0x7f1dac4dfae0>
>>> types.FunctionType(g.__code__, {})
There is no way to specify a qualname when constructing a
'FunctionType'. The name is derived from the code object. The
qualname could be too if we fix this issue. I will open another issue
for the 'FunctionType' problem.
I have attached a WIP patch. It passes the full test suite. I am
somewhat unsure about the CAPI changes, though. They are a breaking API
change. Do we need a *_QualName version instead like we did for
'PyFunction_NewWithQualName'? I think probably so. I will add doc
updates to the patch once the API stuff gets worked out.
----------
keywords: +patch
Added file: http://bugs.python.org/file24317/issue13672-v0.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13672>
_______________________________________
More information about the Python-bugs-list
mailing list