__qualname__ in python 3.3

ISE Development isenntp at gmail.com
Sat Sep 6 18:13:07 CEST 2014


When a class is defined within a function, the class generation function's 
'__qualname__' attrbute is not qualified a name.

For instance:

    def test():
        class T:
            def method(self):
        t = T()

When tracing a call to 'test()' using 'sys.settrace()', extracting the 
'code' object from the frames of 'call' events and matching it to a 
'function' object (using 'gc.get_referrers()') results in the following:

'code' object     'function' object
----------------  ------------------------------------
co_name: test     __qualname__: test
co_name: T        __qualname__: T
co_name: method   __qualname__: test.<locals>.T.method

The second call corresponds to the class definition and not the call to the 
constructor (which is in fact a call to 'object.__init__', a C function 
hence not traced as a 'call' event - I checked this by disassembling the 
code object).

I would expect the second call's '__qualname__' to be 'test.<locals>.T'. Can 
this be considered a bug? If so, I'll open one.

-- isedev

More information about the Python-list mailing list