Re: Function decorator having arguments is complicated

2015-04-29 Thread Gregory Ewing
On Monday 27 April 2015 12:37, Makoto Kuwata wrote: def multiply(n): def deco(func): def newfunc(*args, **kwargs): return n * func(*args, **kwargs) return newfunc return deco I'd like to be able to write that as def multiply(n)(func)(*args, **kwargs): return n

Re: Function decorator having arguments is complicated

2015-04-27 Thread Ethan Furman
On 04/27, Maxime S wrote: > Le lun. 27 avr. 2015 à 04:39, Makoto Kuwata a écrit : > > > > If function decorator notation could take arguments, > > decorator definition would be more simple: > > > > def multiply(func, n): > > def newfunc(*args, **kwargs): > > return n * func(*args, **kw

Re: Function decorator having arguments is complicated

2015-04-27 Thread Maxime S
Le lun. 27 avr. 2015 à 04:39, Makoto Kuwata a écrit : > > If function decorator notation could take arguments, > decorator definition would be more simple: > > def multiply(func, n): > def newfunc(*args, **kwargs): > return n * func(*args, **kwargs) > return newfunc > > @multiply

Re: Function decorator having arguments is complicated

2015-04-27 Thread Steven D'Aprano
On Monday 27 April 2015 12:37, Makoto Kuwata wrote: > I want to ask Python experts about function decorator which has arguments. > > I feel that function decorator having arguments is complicated, > because three 'def' are nested: > > def multiply(n): > def

Re: Function decorator having arguments is complicated

2015-04-26 Thread Chris Angelico
(Redirecting to the list - hope you don't mind) On Mon, Apr 27, 2015 at 2:36 PM, Makoto Kuwata wrote: > > > On Mon, Apr 27, 2015 at 12:20 PM, Chris Angelico wrote: >> >> >> I agree it would be nice to have extra parameters directly handled, >> but before you go further with the proposal, I sugge

Re: Function decorator having arguments is complicated

2015-04-26 Thread Chris Angelico
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

Re: Function decorator having arguments is complicated

2015-04-26 Thread Ethan Furman
On 04/27, Chris Angelico wrote: > On Mon, Apr 27, 2015 at 2:24 PM, Ethan Furman wrote: > > On 04/27, Makoto Kuwata wrote: > >> > >> I feel that function decorator having arguments is complicated, > >> because three 'def' are nested: >

Re: Function decorator having arguments is complicated

2015-04-26 Thread Chris Angelico
On Mon, Apr 27, 2015 at 2:24 PM, Ethan Furman wrote: > On 04/27, Makoto Kuwata wrote: >> >> I feel that function decorator having arguments is complicated, >> because three 'def' are nested: >> >> def multiply(n): >> def deco(func): >>

Re: Function decorator having arguments is complicated

2015-04-26 Thread Ethan Furman
On 04/27, Makoto Kuwata wrote: > > I feel that function decorator having arguments is complicated, > because three 'def' are nested: > > def multiply(n): > def deco(func): > def newfunc(*args, **kwargs): > return n * func(*args, **kwargs) &

Re: Function decorator having arguments is complicated

2015-04-26 Thread Chris Angelico
On Mon, Apr 27, 2015 at 12:37 PM, Makoto Kuwata wrote: > If function decorator notation could take arguments, > decorator definition would be more simple: > > def multiply(func, n): > def newfunc(*args, **kwargs): > return n * func(*args, **kwargs) > return newfunc > > @multiply

Function decorator having arguments is complicated

2015-04-26 Thread Makoto Kuwata
I want to ask Python experts about function decorator which has arguments. I feel that function decorator having arguments is complicated, because three 'def' are nested: def multiply(n): def deco(func): def newfunc(*args, **kwargs): return n * func(*args