[Python-Dev] decorator module in stdlib? (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Fri Apr 10 16:53:00 CEST 2009


Guido van Rossum wrote:

On Wed, Apr 8, 2009 at 9:31 PM, Michele Simionato

But I feel strongly about the possibility of being able to preserve (not change!) the function signature. That could be added to functools if enough people want it.

No objection in principle here - it's just hard to do cleanly without PEP 362's signature attribute to underpin it. Without that as a basis, I expect you'd end up being forced to do something similar to what Michele does in the decorator module - inspect the function being wrapped and then use exec to generate a wrapper with a matching signature.

Another nice introspection enhancement might be to give class and function objects writable file and line attributes (initially set appropriately by the compiler) and have the inspect modules use those when they're available. Then functools.update_wrapper() could be adjusted to copy those attributes, meaning that the wrapper function would point back to the original (decorated) function for the source code, rather than to the definition of the wrapper (note that the actual wrapper code could still be found by looking at the metadata on the function's code attribute).

Unfortunately-ideas-aren't-working-code'ly, Nick.

-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia



More information about the Python-Dev mailing list