On Tue, May 17, 2016 at 3:05 PM, Steven D'Aprano
wrote:
> Although the instrumentation is used inside the decorator, it is actually part
> of the public API for the function. So the user can do this:
>
>
> @decorate
> def myfunction():
> ...
>
>
> # later
On Monday 16 May 2016 23:06, Kevin Conway wrote:
>> I have a decorator that adds an attribute to the decorated function
>
> I might try to argue that this is not actually a decorator or, at least,
> this is not a great decorator pattern for Python. Adding the attribute to
> the function object
On Monday 16 May 2016 22:20, jmp wrote:
> On 05/10/2016 05:45 PM, Steven D'Aprano wrote:
>> I have a decorator that adds an attribute to the decorated function:
> [snip]
>> I think 5 is clearly wrong, 4 is too difficult, and 3 seems pointless. So I
>> think either 1 or 2 is the right thing to do.
On Monday 16 May 2016 18:14, Francesco Loffredo wrote:
> On 10/05/2016 17:45, Steven D'Aprano wrote:
>> I have a decorator that adds an attribute to the decorated function:
[...]
>> My question is, what should I do if the decorated function already has an
>> instrument attribute?
> From your
> I have a decorator that adds an attribute to the decorated function
I might try to argue that this is not actually a decorator or, at least,
this is not a great decorator pattern for Python. Adding the attribute to
the function object implies you need to access it at some later point. If
so
On 05/10/2016 05:45 PM, Steven D'Aprano wrote:
I have a decorator that adds an attribute to the decorated function:
[snip]
I think 5 is clearly wrong, 4 is too difficult, and 3 seems pointless. So I
think either 1 or 2 is the right thing to do.
Thoughts?
It depends if the attribute
On 10/05/2016 17:45, Steven D'Aprano wrote:
I have a decorator that adds an attribute to the decorated function:
def decorate(func):
instrument = make_instrument()
@functools.wraps(func)
def inner(*args):
instrument.start()
result = func(*args)
On Tue, May 10, 2016 at 11:48 AM Peter Otten <__pete...@web.de> wrote:
> Steven D'Aprano wrote:
> > I have a decorator that adds an attribute to the decorated function:
> >inner.instrument = instrument
> >return inner
>
> the original instrument is still accessible as
On 05/10/2016 08:45 AM, Steven D'Aprano wrote:
I have a decorator that adds an attribute to the decorated function:
My question is, what should I do if the decorated function already has an
instrument attribute?
If the decorator is adding an attribute for the decorated thing to use,
and
On 2016-05-10 17:06, Stephen Hansen wrote:
On Tue, May 10, 2016, at 08:45 AM, Steven D'Aprano wrote:
I have a decorator that adds an attribute to the decorated function:
[...]
My question is, what should I do if the decorated function already has an
instrument attribute?
1. raise an exception?
Steven D'Aprano wrote:
> I have a decorator that adds an attribute to the decorated function:
>
>
> def decorate(func):
> instrument = make_instrument()
>
> @functools.wraps(func)
> def inner(*args):
> instrument.start()
> result = func(*args)
>
On Tue, May 10, 2016, at 08:45 AM, Steven D'Aprano wrote:
> I have a decorator that adds an attribute to the decorated function:
> [...]
> My question is, what should I do if the decorated function already has an
> instrument attribute?
>
> 1. raise an exception?
This. Your decorator should,
12 matches
Mail list logo