[Python-Dev] decorator support
Raymond Hettinger
raymond.hettinger at verizon.net
Sun Sep 5 07:07:35 CEST 2004
In my experiments with decorators, it is common to wrap the original
function with a new function.
After creating the new function, there are efforts to make it look like
the old:
newf.__doc__ = oldf.__doc__ # copy the docstring
newf.__dict__.update(oldf.__dict__) # copy attributes
newf.__name__ = oldf.__name__ # keep the name (new in Py2.4)
All is well and good except the argspec. Running help() on the new
function gives:
funcname(*args, **kwds)
The original docstring
Running help() on the original function gives:
funcname(arg1, arg2)
The original docstring
So, it would be nice if there were some support for carrying forward the
argspec to inform help(), calltips(), and inspect().
FWIW, I do know that with sufficient gyrations a decorator could do this
on its own, but it is way too difficult for general use.
Raymond
More information about the Python-Dev
mailing list