[Python-Dev] Proposed tweaks to functools.wraps
Nick Coghlan
ncoghlan at gmail.com
Fri Aug 13 18:07:03 CEST 2010
On Sat, Aug 14, 2010 at 1:01 AM, Eric Snow <esnow at verio.net> wrote:
> Actually, what is the problem with having all decorators add a __decorated__ to the function that ultimately gets returned, pointing to the function they decorated? I guess I never saw that discussion. Perhaps set it to None when the decorator is the same as the decorated (no wrapping involved). The alternative is sifting through closures, trying to figure out which is the decorated function. Finding the original decorated function has been a real pain, particularly when a function has more than one closure cell.
Because decorators don't always return simple wrapper functions -
sometimes they return the original function and sometimes they
completely replace the original function with something else entirely
(which may not be callable, or even mutable). We refused the
temptation to try to guess when it was appropriate to add the
referring attribute.
functools.update_wrapper and functools.wraps are explicit though, so
it's easy to add the attribute there, we just hadn't thought of doing
it before now.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev
mailing list