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 | ncogh...@gmail.com | Brisbane, Australia --------------------------------------------------------------- _______________________________________________ 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