[issue13672] Add co_qualname attribute in code objects
Meador Inge
report at bugs.python.org
Tue Jan 24 20:41:25 CET 2012
Meador Inge <meadori at gmail.com> added the comment:
On Wed, Dec 28, 2011 at 3:11 PM, Eric Snow <report at bugs.python.org> wrote:
> One sticky point is that there isn't a guarantee of one-to-one between function object and code object. A code object could be bound to several
> different functions as happens with function definitions (particularly lambdas) inside comprehensions.
>
> Also, if a code object is not associated with a function, i.e. one generated by exec, what should the qualname for the code object be? How
> about, in CPython, the code objects created for classes and modules?
We already these issues with 'co_name', though. These cases can be
treated the same as they are for 'co_name':
'<listcomp>'
>>> compile('[i for i in [1, 2]]', '<foo>', 'exec').co_consts[0].co_qualname
'<listcomp>'
>>> compile('class T: pass', '<foo>', 'exec').co_consts[0].co_qualname
'T'
>>> compile('class T: pass', '<foo>', 'exec').co_consts[0].co_name
'T'
>>> compile('a = 12', '<foo>', 'exec').co_name
'<module>'
>>> compile('a = 12', '<foo>', 'exec').co_qualname
'<module>'
>>> compile('lambda x: x', '<foo>', 'exec').co_consts[0].co_qualname
'<lambda>'
>>> compile('lambda x: x', '<foo>', 'exec').co_consts[0].co_name
'<lambda>'
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13672>
_______________________________________
More information about the Python-bugs-list
mailing list