Is there any way to return from the return value from inspect.getcallargs(func)
to the *args, **kw
pair, which can really be used to call func
?
Use case: let's say I'm writing a decorator, and I want to change a specific function argument by name. Here is the beginning of some code for this:
@fix_x def a(x): print x @fix_x def b(**q): print q['x'] def fix_x(func): def wrapper(*args, **kw): argspec = inspect.getargspec(func) callargs = inspect.getcallargs(func, *args, **kw) if 'x' in callargs: callargs['x'] += 5 elif 'x' in callargs[argspec.keywords]: callargs[argspec.keywords]['x'] += 5 # ...and now I'd like a simple way to call func with callargs...?
(I'm actually doing something more complex with the challenges between making them and wanting to call them, but this should give an idea of ββwhat I'm looking for.)
source share