Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #89443

Re: Function decorator having arguments is complicated

References <CAFTm5Ru5NbFOtLPoVSPujeakrGawdHXjNkWJOVs1XrvBNnOUOQ@mail.gmail.com> <20150427042426.GD32422@stoneleaf.us> <CAPTjJmpYOoTLCL6hk2MDk5_V2ffmA-wON2rbnG_cE6oDjg9YoQ@mail.gmail.com> <20150427044500.GE32422@stoneleaf.us>
Date 2015-04-27 15:25 +1000
Subject Re: Function decorator having arguments is complicated
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.37.1430112335.3680.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Apr 27, 2015 at 2:45 PM, Ethan Furman <ethan@stoneleaf.us> 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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Function decorator having arguments is complicated Chris Angelico <rosuav@gmail.com> - 2015-04-27 15:25 +1000

csiph-web