Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.033 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'variables': 0.07; 'subject:help': 0.08; 'undefined': 0.09; 'wrapper': 0.09; 'stored': 0.12; 'assume': 0.14; 'either;': 0.16; 'implies': 0.16; 'said.': 0.16; 'wrote:': 0.18; '(but': 0.19; 'first.': 0.19; 'things.': 0.19; '>>>': 0.22; 'case.': 0.24; 'skip:" 40': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'that.': 0.31; 'to:name:python-list': 0.33; 'knowledge': 0.35; "can't": 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'skip:f 40': 0.36; 'doing': 0.36; "didn't": 0.36; 'method': 0.36; 'effort': 0.37; 'to:addr:python-list': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'skip:i 50': 0.60; 'course': 0.61; 'first': 0.61; 'name': 0.63; 'july': 0.63; 'to,': 0.72; 'otten': 0.84; 'technically': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=HhuFZ5+HOfXf2zjg73A09sZxXBAdODPtaj80zvy1Nag=; b=EGL7hyKoBWAoZDXII7bMF6gCoPMPVlF8234JiJZ2MGJ8NTBaRYoqTungypK6EkNMU+ y4eGzhp1yqqAQUCAsloOAdGvuIZXfxY7Krzh7PkJAAb6YLvD4h9MtjBlYUKGkySlJFWP pCjf9DH9kbT/w+LQ6zqHEAhxEghpE7MZ9wh/591Uydl7449pvTMgO7meCjFIMnjIf8MP TLuS90NlETvbPo4nrtAL/SIl/EF83/BAOVAe6CqQGLJsg+/n4a9/+jBfZnBYEftpP+/E i2bC6N1+yfOeyH+rC7+bXQ9Kjz/pGNuvd3OvZMcyo/5W3ihQcGrpOuYnJbOORKy7ELrF RsEw== X-Received: by 10.152.45.65 with SMTP id k1mr3909231lam.78.1372986882663; Thu, 04 Jul 2013 18:14:42 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Joshua Landau Date: Fri, 5 Jul 2013 02:14:02 +0100 Subject: Re: Decorator help To: python-list Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372986890 news.xs4all.nl 15927 [2001:888:2000:d::a6]:56694 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49913 On 4 July 2013 06:39, Peter Otten <__peter__@web.de> wrote: > Joshua Landau wrote: > >> On 3 July 2013 23:19, Joshua Landau wrote: >>> If you don't want to do that, you'd need to use introspection of a >>> remarkably hacky sort. If you want that, well, it'll take a mo. >> >> After some effort I'm pretty confident that the hacky way is impossible. > > Well, technically it's > > func.func_closure[0].cell_contents.__name__ > > but of course you cannot know that for the general case. I didn't want to do something like that as it implies a lot of knowledge about the function -- which implies that there's no reason to do it hacky in the first place. I was using "inspect.getclosurevars(func).nonlocals" and that "coerces" to a dictionary first. It's the "correct" way of doing things. But you never know what name the function inside the wrapper is bound to, so I didn't accept that. Also, your method has undefined behaviour AFAIK -- the order of func_closure is compiler-dependant. If you want to do something like this, I recommend my method (but it doesn't work for the general case in the slightest): inspect.getclosurevars(func).nonlocals["func"].__name__ If you can't assume the name it's stored in, but you can know the order of closure variables *then* use Peter's. But again, don't use either; it's impossible just as I said.