Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77660
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'output': 0.05; '(using': 0.07; 'finally:': 0.07; 'referring': 0.07; 'report.': 0.07; 'sys': 0.07; 'constructor': 0.09; 'function,': 0.09; 'obj': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'try:': 0.09; 'python': 0.11; 'def': 0.12; 'corresponds': 0.16; 'different,': 0.16; 'doing,': 0.16; 'funcs': 0.16; "function's": 0.16; 'instance:': 0.16; 'object).': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'reproduce': 0.16; 'say.': 0.16; 'subject:3.3': 0.16; 'tracing': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; "python's": 0.19; 'seems': 0.21; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'case.': 0.24; 'simpler': 0.24; 'question': 0.24; 'second': 0.26; 'pass': 0.26; 'defined': 0.27; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'function': 0.29; 'matching': 0.30; 'skip:g 30': 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; "skip:' 10": 0.31; 'bug?': 0.31; 'inspect': 0.31; 'file': 0.32; 'class': 0.32; 'checked': 0.32; 'skip:- 30': 0.32; 'open': 0.33; 'linux': 0.33; 'skip:_ 10': 0.34; "i'd": 0.34; 'something': 0.35; 'definition': 0.35; 'test': 0.35; 'but': 0.35; 'returning': 0.36; 'method': 0.36; 'shows': 0.36; "i'll": 0.36; 'hi,': 0.36; 'so,': 0.37; 'to:addr:python- list': 0.38; 'skip:- 10': 0.38; 'fact': 0.38; 'anything': 0.39; 'expect': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'helps': 0.61; 'name': 0.63; 'more': 0.64; 'within': 0.65; 'results': 0.69; 'qualified': 0.72; 'expectations': 0.74; '2014,': 0.84; '3.4': 0.84; 'otten': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: __qualname__ in python 3.3 |
| Date | Sat, 06 Sep 2014 20:11:01 +0200 |
| Organization | None |
| References | <540b3293$0$2056$426a74cc@news.free.fr> <mailman.13836.1410022089.18130.python-list@python.org> <540b3fe4$0$2055$426a74cc@news.free.fr> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p57bd8c29.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.13840.1410027079.18130.python-list@python.org> (permalink) |
| Lines | 103 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1410027079 news.xs4all.nl 2846 [2001:888:2000:d::a6]:34937 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:77660 |
Show key headers only | View raw
ISE Development wrote: > Peter Otten wrote: > >> 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? > > Python 3.3 behaves in the same way in that case. > > This following shows the behaviour I am referring to: > > import gc > import sys > import inspect > > def global_trace(frame,event,arg): > if event == 'call': > code = frame.f_code > funcs = [obj for obj in gc.get_referrers(code) > if inspect.isfunction(obj)] > if len(funcs) == 1: > f = funcs[0] > print(f.__qualname__) > > def test(): > class C: > def method(self): > self > c = C() > c.method() > > sys.settrace(global_trace) > try: > test() > finally: > sys.settrace(None) > > which produces: > > test > C > test.<locals>.C.method OK, I get the same output in Python 3.4. That C seems to be an internal function that helps build the class test.<locals>.C, and I have no expectations as to its name. If anything I'd use something completely different, _init_namespace_C, say. I'm sorry I am not familiar enough with Python's internals to answer your question -- but if in doubt, file a report.
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