Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Lawrence D’Oliveiro
On Monday, July 4, 2016 at 12:06:21 PM UTC+12, Chris Angelico wrote: > On Mon, Jul 4, 2016 at 9:59 AM, Lawrence D’Oliveiro wrote: >> #begin try_func >> result.__name__ = func.__name__ >> result.__doc__ = func.__doc__ >> return \ >> result >> #end try_func

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Ian Kelly
On Sun, Jul 3, 2016 at 6:06 PM, Lawrence D’Oliveiro wrote: > On Monday, July 4, 2016 at 12:02:23 PM UTC+12, Ian wrote: >> I'm talking about the docstring of the *decorator*, not func. > > *Sigh*. Originally somebody was complaining that the lambda version didn’t > allow for good (or any) docstrin

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Lawrence D’Oliveiro
On Monday, July 4, 2016 at 12:02:23 PM UTC+12, Ian wrote: > I'm talking about the docstring of the *decorator*, not func. *Sigh*. Originally somebody was complaining that the lambda version didn’t allow for good (or any) docstrings. So I posted my version, and I went to all the effort of ensurin

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Chris Angelico
On Mon, Jul 4, 2016 at 9:59 AM, Lawrence D’Oliveiro wrote: > #begin try_func > result.__name__ = func.__name__ > result.__doc__ = func.__doc__ > return \ > result > #end try_func This is the bit we're talking about. You're doing manually what functools.

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Ian Kelly
On Sun, Jul 3, 2016 at 5:25 PM, Lawrence D’Oliveiro wrote: > On Monday, July 4, 2016 at 10:39:30 AM UTC+12, Ian wrote: >> Sorry, but you're the one who doesn't seem to get it. Because it's a >> decorator, "your" function is replacing the caller's function in the >> caller's namespace. > > No it is

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Lawrence D’Oliveiro
On Monday, July 4, 2016 at 11:39:56 AM UTC+12, Chris Angelico wrote: > In the same way, people expect "f = deco(f)" to return *the same function, > decorated*. I am not changing that in anyway. The decorated function generated by the caller is returned *unchanged*. Once again, the only docstring

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Chris Angelico
On Mon, Jul 4, 2016 at 9:25 AM, Lawrence D’Oliveiro wrote: > On Monday, July 4, 2016 at 10:39:30 AM UTC+12, Ian wrote: >> Sorry, but you're the one who doesn't seem to get it. Because it's a >> decorator, "your" function is replacing the caller's function in the >> caller's namespace. > > No it is

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Lawrence D’Oliveiro
On Monday, July 4, 2016 at 10:39:30 AM UTC+12, Ian wrote: > Sorry, but you're the one who doesn't seem to get it. Because it's a > decorator, "your" function is replacing the caller's function in the > caller's namespace. No it is not. The replacement happens here: def generated_decorator

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Ian Kelly
On Sun, Jul 3, 2016 at 3:17 PM, Lawrence D’Oliveiro wrote: > On Sunday, July 3, 2016 at 11:53:46 PM UTC+12, Ian wrote: >> On Sat, Jul 2, 2016 at 11:37 PM, Lawrence D’Oliveiro wrote: >>> That is a function that I am generating, so naturally I want to give it a >>> useful docstring. Am I “clobbering

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Lawrence D’Oliveiro
On Sunday, July 3, 2016 at 11:53:46 PM UTC+12, Ian wrote: > On Sat, Jul 2, 2016 at 11:37 PM, Lawrence D’Oliveiro wrote: >> That is a function that I am generating, so naturally I want to give it a >> useful docstring. Am I “clobbering” any objects passed in by the caller, >> or returned by the call

Re: Meta decorator with parameters, defined in explicit functions

2016-07-03 Thread Ian Kelly
On Sat, Jul 2, 2016 at 11:37 PM, Lawrence D’Oliveiro wrote: > On Sunday, July 3, 2016 at 4:49:15 PM UTC+12, Ian wrote: >> >> On Sat, Jul 2, 2016 at 12:40 AM, Lawrence D’Oliveiro wrote: >>> >>> On Saturday, July 2, 2016 at 5:10:06 PM UTC+12, Ian wrote: You should use functools.wraps inste

Re: Meta decorator with parameters, defined in explicit functions

2016-07-02 Thread Lawrence D’Oliveiro
On Sunday, July 3, 2016 at 4:49:15 PM UTC+12, Ian wrote: > > On Sat, Jul 2, 2016 at 12:40 AM, Lawrence D’Oliveiro wrote: >> >> On Saturday, July 2, 2016 at 5:10:06 PM UTC+12, Ian wrote: >>> >>> You should use functools.wraps instead of clobbering the decorated >>> function's name and docstring: >>

Re: Meta decorator with parameters, defined in explicit functions

2016-07-02 Thread Ian Kelly
On Sat, Jul 2, 2016 at 12:40 AM, Lawrence D’Oliveiro wrote: > On Saturday, July 2, 2016 at 5:10:06 PM UTC+12, Ian wrote: >> You should use functools.wraps instead of clobbering the decorated >> function's name and docstring: > > Where am I doing that? Using the implementation you posted: >>> @de

Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-07-02 Thread Ben Finney
dieter writes: > Ben Finney writes: > > ... Rather, the motivation was that a complex thing, with many > > moving parts, has an unexplained implementation: a nested set of > > functions without names to explain their part in the pattern. > > In a previous reply, I have tried to explain (apparent

Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-07-02 Thread dieter
Ben Finney writes: > ... > Rather, the motivation was that a complex thing, with many moving parts, > has an unexplained implementation: a nested set of functions without > names to explain their part in the pattern. In a previous reply, I have tried to explain (apparently without success) that t

Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Lawrence D’Oliveiro
On Saturday, July 2, 2016 at 5:10:06 PM UTC+12, Ian wrote: > You should use functools.wraps instead of clobbering the decorated > function's name and docstring: Where am I doing that? > Just to satisfy my own curiosity, do you have something against > putting the return keyword and the returned ex

Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Ian Kelly
On Fri, Jul 1, 2016 at 11:32 PM, Ben Finney wrote: > Ian Kelly writes: > >> You should use functools.wraps instead of clobbering the decorated >> function's name and docstring: >> >> @functools.wraps(decorator) >> def decorate(*args, **kwargs): >> ... > > Thanks. Can y

Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Ben Finney
Ian Kelly writes: > You should use functools.wraps instead of clobbering the decorated > function's name and docstring: > > @functools.wraps(decorator) > def decorate(*args, **kwargs): > ... Thanks. Can you write the full implementation with that, so I can be sure of

Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Ian Kelly
On Fri, Jul 1, 2016 at 4:08 PM, Lawrence D’Oliveiro wrote: > On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: >> There is a clever one-line decorator that has been copy-pasted without >> explanation in many code bases for many years:: >> >> decorator_with_args = lambda decorat

Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Ben Finney
Ben Bacarisse writes: > By replying I'm not accepting the premise -- I have no idea if there > is widespread fear and suspicion of lambdas among Python users but it > seems unlikely. I can testify, as the person who started this thread, that there is no fear or suspicion of lambda here. I use it

Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Lawrence D’Oliveiro
On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: > There is a clever one-line decorator that has been copy-pasted without > explanation in many code bases for many years:: > > decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda > func: decorator(func, *args

Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread Ben Bacarisse
dieter writes: >> Lawrence D’Oliveiro wrote: >>> I don’t know why this fear and suspicion of lambdas is so widespread among >>> Python users ... former Java/C# programmers, perhaps? By replying I'm not accepting the premise -- I have no idea if there is widespread fear and suspicion of lambdas

Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-07-01 Thread dieter
Peter Otten <__pete...@web.de> writes: > Lawrence D’Oliveiro wrote: > >> On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: >> >>> I would like to see a more Pythonic, more explicit and expressive >>> replacement with its component parts easily understood. >> >> I don’t know why t

Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-06-30 Thread Peter Otten
Lawrence D’Oliveiro wrote: > On Thursday, June 30, 2016 at 7:26:01 PM UTC+12, Peter Otten wrote: >> foo = lambda : >> >> there is syntactic sugar in Python that allows you to write it as >> >> def foo(): >> return >> >> with the nice side effects that it improves the readability of traceb

Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-06-30 Thread Steven D'Aprano
On Thursday 30 June 2016 17:43, Lawrence D’Oliveiro wrote: > On Thursday, June 30, 2016 at 7:26:01 PM UTC+12, Peter Otten wrote: >> foo = lambda : >> >> there is syntactic sugar in Python that allows you to write it as >> >> def foo(): >> return >> >> with the nice side effects that it im

Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-06-30 Thread Lawrence D’Oliveiro
On Thursday, June 30, 2016 at 7:26:01 PM UTC+12, Peter Otten wrote: > foo = lambda : > > there is syntactic sugar in Python that allows you to write it as > > def foo(): > return > > with the nice side effects that it improves the readability of tracebacks > and allows you to provide a do

Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions

2016-06-30 Thread Peter Otten
Lawrence D’Oliveiro wrote: > On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: > >> I would like to see a more Pythonic, more explicit and expressive >> replacement with its component parts easily understood. > > I don’t know why this fear and suspicion of lambdas is so widesprea

Re: Meta decorator with parameters, defined in explicit functions

2016-06-29 Thread Steven D'Aprano
On Thu, 30 Jun 2016 12:43 pm, Lawrence D’Oliveiro wrote: > On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: >> There is a clever one-line decorator that has been copy-pasted without >> explanation in many code bases for many years:: >> >> decorator_with_args = lambda decorato

Re: Meta decorator with parameters, defined in explicit functions

2016-06-29 Thread Lawrence D’Oliveiro
On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: > decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda > func: decorator(func, *args, **kwargs) Ah, I see why there are 3 lambdas, instead of 2. It’s so that you can write decorator_func = decorator_with_

Re: Meta decorator with parameters, defined in explicit functions

2016-06-29 Thread Lawrence D’Oliveiro
On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote: > There is a clever one-line decorator that has been copy-pasted without > explanation in many code bases for many years:: > > decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda > func: decorator(func, *args

Re: Meta decorator with parameters, defined in explicit functions

2016-06-28 Thread Steven D'Aprano
On Tuesday 28 June 2016 15:02, Ben Finney wrote: > Howdy all, > > I want an explicit replacement for a common decorator idiom. > > There is a clever one-line decorator that has been copy-pasted without > explanation in many code bases for many years:: > > decorator_with_args = lambda decora

Re: Meta decorator with parameters, defined in explicit functions

2016-06-28 Thread dieter
Ben Finney writes: > I want an explicit replacement for a common decorator idiom. > > There is a clever one-line decorator that has been copy-pasted without > explanation in many code bases for many years:: > > decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda > func: dec

Re: Meta decorator with parameters, defined in explicit functions

2016-06-27 Thread Paul Rubin
Ben Finney writes: > decorator_with_args = lambda decorator: lambda *args, **kwargs: > lambda func: decorator(func, *args, **kwargs) > I would like to see a more Pythonic, more explicit and expressive > replacement with its component parts easily understood. How's this: from functools im

Re: Meta decorator with parameters, defined in explicit functions

2016-06-27 Thread Zachary Ware
On Tue, Jun 28, 2016 at 12:02 AM, Ben Finney wrote: > Howdy all, > > I want an explicit replacement for a common decorator idiom. > > There is a clever one-line decorator that has been copy-pasted without > explanation in many code bases for many years:: > > decorator_with_args = lambda decora

Meta decorator with parameters, defined in explicit functions

2016-06-27 Thread Ben Finney
Howdy all, I want an explicit replacement for a common decorator idiom. There is a clever one-line decorator that has been copy-pasted without explanation in many code bases for many years:: decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda func: decorator(func, *args,