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
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
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
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.
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
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
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
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
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
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
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
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:
>>
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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_
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
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
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
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
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
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,
35 matches
Mail list logo