Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'true,': 0.05; '(of': 0.07; 'filing': 0.07; 'decorator': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'jan': 0.12; '"""return': 0.16; '201': 0.16; 'function?': 0.16; 'portable': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'robust.': 0.16; 'simpson': 0.16; 'stdlib.': 0.16; 'wrote:': 0.18; 'module': 0.19; 'skip:f 30': 0.19; 'later': 0.20; 'header:User-Agent:1': 0.23; 'certainly': 0.24; 'requirement.': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'convince': 0.31; "d'aprano": 0.31; 'steven': 0.31; "i'd": 0.34; 'but': 0.35; "i'll": 0.36; 'so,': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'black': 0.61; 'received:173': 0.61; 'first': 0.61; 'received:fios.verizon.net': 0.84; 'not:': 0.91; 'whereas': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Skipping decorators in unit tests Date: Fri, 11 Oct 2013 04:17:39 -0400 References: <525768a5$0$29984$c3e8da3$5496439d@news.astraweb.com> <20131011031319.GA30742@cskk.homeip.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0 In-Reply-To: <20131011031319.GA30742@cskk.homeip.net> 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1381479478 news.xs4all.nl 15974 [2001:888:2000:d::a6]:53004 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:56658 On 10/10/2013 11:13 PM, Cameron Simpson wrote: > On 11Oct2013 02:55, Steven D'Aprano wrote: >> def undecorate(f): >> """Return the undecorated inner function from function f.""" >> return f.func_closure[0].cell_contents > > Whereas this feels like black magic. Is this portable to any decorated > function? If so, I'd have hoped it was in the stdlib. If not: black magic. > >> And in use: >> >> py> f(100) >> 201 >> py> undecorate(f)(100) >> 200 > > All lovely, provided you can convince me that undecorate() is robust. > (And if you can, I'll certainly be filing it away in my funcutils > module for later use.) It only works if the decorator returns a closure with the original function as the first member (of func_closure). Often true, but not at all a requirement. -- Terry Jan Reedy