True. It is tricky. However, not as tricky as finding the decorated function after the fact (unless I am missing something). But maybe that is a fringe need (finding the original function).
-eric -----Original Message----- From: Nick Coghlan [mailto:ncogh...@gmail.com] Sent: Friday, August 13, 2010 10:07 AM To: Eric Snow Cc: python-dev@python.org Subject: Re: [Python-Dev] Proposed tweaks to functools.wraps On Sat, Aug 14, 2010 at 1:01 AM, Eric Snow <es...@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 | ncogh...@gmail.com | Brisbane, Australia This email message is intended for the use of the person to whom it has been sent, and may contain information that is confidential or legally protected. If you are not the intended recipient or have received this message in error, you are not authorized to copy, distribute, or otherwise use this message or its attachments. Please notify the sender immediately by return e-mail and permanently delete this message and any attachments. Verio, Inc. makes no warranty that this email is error or virus free. Thank you. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com