Preserving the argspec of a function after generating a closure

Victor Ng crankycoder at gmail.com
Fri Mar 11 11:55:51 EST 2005


Is there a way to preserve the argspec of a function after wrapping it
in a closure?

I'm looking for a general way to say "wrap function F in a closure",
such that inspect.getargspec on the closure would return the same
(args, varargs, varkw, defaults)  tuple ass the enclosed function.

The typical code I'm using is something like this:

def wrapFunc(func):
    def tmpWrapper(*args, **kwargs):
        return func(*args, **kwargs)
    tmpWrapper.func_name = func.func_name
    return wrapFunc

This preserves the function name - how do I do more?

vic

-- 
"Never attribute to malice that which can be adequately explained by
stupidity."  - Hanlon's Razor



More information about the Python-list mailing list