Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!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.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'explicitly': 0.05; 'say,': 0.05; 'arguments': 0.09; 'subject:Function': 0.09; 'variables.': 0.09; "wouldn't": 0.14; 'both,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'levels,': 0.16; 'nesting': 0.16; 'referencing': 0.16; 'repetition': 0.16; 'scope,': 0.16; 'wrote:': 0.18; '(where': 0.19; 'to:name:python-list@python.org': 0.22; 'mon,': 0.24; 'class.': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'on,': 0.29; 'especially': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'easier': 0.31; 'cases': 0.33; 'common': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'next': 0.36; 'method': 0.36; 'level': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'track': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'simple': 0.61; 'more': 0.64; 'talking': 0.65; 'gain': 0.79; '2015': 0.84; 'ethan': 0.84; 'furman': 0.84; 'capture': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=AmvCAPY70On/y8nt/db7EiEQWMs5uMhbTxAzQZ0+QUU=; b=fQZpED8YrjVNBv0ZbBXHA2wXs9/JdgP62/sSj6uzFsV9RlGAZHmbCeKrDf4AXuIT1R puxnfqI1U2B4qq1/PQa8Wfij9LhBhR8LYJ8cS/BrDyFYcrrYD4xaeLPt3TcYXuVLYdQj mEaqNyTOQjA67NH83zaCYQVOwyFXLJKeY7gCdewIFVXS6r183aYDnueFPoLy36BPaCuJ x9WyTHfrlVaBf8Il4r5y1/aO41/rNGHUYCWj075DsIHFJ+OUz5T8vHRIlnBjHpYLwpgu E5Zguk3l0zEtriGEunmYGxJTRAYGSmzLP4LfQD8HmGGZWHKLBPgsc8tyetAlInJARz1w +4PA== MIME-Version: 1.0 X-Received: by 10.50.43.196 with SMTP id y4mr11185658igl.14.1430112327064; Sun, 26 Apr 2015 22:25:27 -0700 (PDT) In-Reply-To: <20150427044500.GE32422@stoneleaf.us> References: <20150427042426.GD32422@stoneleaf.us> <20150427044500.GE32422@stoneleaf.us> Date: Mon, 27 Apr 2015 15:25:27 +1000 Subject: Re: Function decorator having arguments is complicated From: Chris Angelico To: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430112335 news.xs4all.nl 2842 [2001:888:2000:d::a6]:51009 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:89443 On Mon, Apr 27, 2015 at 2:45 PM, Ethan Furman wrote: >> What's the advantage of that over a simple closure? You have the same >> number of nesting levels, plus a lot more boiler-plate repetition - >> instead of just referencing names from the outer scope, you have to >> explicitly capture them all with "self.n=n" for each one. I'm not sure >> you really even gain much clarity. >> >> In a way, a closure is a short-hand for an object with a __call__ >> method that auto-captures all its local variables. > > I find it much easier to keep track of what is going on, especially in > those cases where there is pre-, post-, or both, processing going on. > > YMMV. Perhaps in the complicated cases, but in the common and simple case that the OP's talking about (where the purpose of the outermost function is solely to capture arguments for the next level in), I wouldn't bother with a class. But as you say, YMMV. ChrisA