What should a decorator do if an attribute already exists?

Michael Selik michael.selik at gmail.com
Tue May 10 19:43:00 EDT 2016


On Tue, May 10, 2016 at 11:48 AM Peter Otten <__peter__ at 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 f.__wrapped__.instrument


I'd say Peter's example is Option 6:
Wrap the instrumented function with a second instrumented wrapper.

Since you have various kinds of instruments, silently adding another layer
makes sense to me. Is it OK if the order matters? Will some of the
instruments get confused because they're working on a wrapper instead of
the original function?



More information about the Python-list mailing list