Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'mrab': 0.05; 'cherrypy': 0.09; 'subject:skip:c 10': 0.09; 'subtle': 0.09; 'def': 0.12; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'lambda': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'decorators': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'that.': 0.31; 'apparently': 0.31; 'not.': 0.33; "i'd": 0.34; 'case,': 0.35; 'but': 0.35; 'charset :us-ascii': 0.36; 'thanks': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'making': 0.63; 'happen': 0.63; 'helping': 0.70; 'difference.': 0.84; 'received:50.22': 0.84 Date: Tue, 29 Oct 2013 12:54:05 -0500 From: Tim Chase To: python-list@python.org Subject: Re: stacked decorators and consolidating In-Reply-To: <526FF395.9040306@mrabarnett.plus.com> References: <20131029115427.537e1bcd@bigbox.christie.dr> <526FF395.9040306@mrabarnett.plus.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1383069148 news.xs4all.nl 15975 [2001:888:2000:d::a6]:49636 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:57946 On 2013-10-29 17:42, MRAB wrote: > If you apply the stacked decorators you get: > > myfun = dec1(args1)(dec2(args2)(dec3(args3)(myfun))) > > If you apply dec_all you get: > > myfun = dec1(args1)(dec2(args2)(dec3(args3)))(myfun) > > See the difference? You need the lambda to fix that. In this case, they happen to be CherryPy decorators: @cherrypy.expose() @cherrypy.tools.json_in() @cherrypy.tools.json_out() def myfunc(...): pass I'd have figured they would be associative, making the result end up the same either way, but apparently not. Thanks for helping shed some light on the subtle difference. -tkc