Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77655
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: __qualname__ in python 3.3 |
| Date | 2014-09-06 18:47 +0200 |
| Organization | None |
| References | <540b3293$0$2056$426a74cc@news.free.fr> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.13836.1410022089.18130.python-list@python.org> (permalink) |
ISE Development wrote: > Hi, > > 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): > pass > t = T() > t.method() > > 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. I don't understand what you are doing, so I tried to reproduce the unqualified class name in 3.4 with the simpler approach of returning T: Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> def test(): ... class T: ... def method(self): pass ... return T ... >>> T = test() >>> T.__qualname__ 'test.<locals>.T' >>> T.method.__qualname__ 'test.<locals>.T.method' If you do it that way with 3.3 (I don't have it handy) do you still see T instead of test.<locals>.T?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
__qualname__ in python 3.3 ISE Development <isenntp@gmail.com> - 2014-09-06 18:13 +0200
Re: __qualname__ in python 3.3 Peter Otten <__peter__@web.de> - 2014-09-06 18:47 +0200
Re: __qualname__ in python 3.3 ISE Development <isenntp@gmail.com> - 2014-09-06 19:09 +0200
Re: __qualname__ in python 3.3 Peter Otten <__peter__@web.de> - 2014-09-06 20:11 +0200
Re: __qualname__ in python 3.3 Antoine Pitrou <antoine@python.org> - 2014-09-07 13:03 +0000
Re: __qualname__ in python 3.3 ISE Development <isenntp@gmail.com> - 2014-09-08 00:25 +0200
csiph-web