[Python-Dev] decorator support (original) (raw)

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