I'm looking for a way to decorate an arbitrary python function, so that an alternate function is called instead of the original, with all parameters passed as a list or dict.
More precisely, something like this (where f is any function, and replacement_f takes a list and a dict):
def replace_func(f, replacement_f):
def new_f(*args, **kwargs):
replacement_f(args, kwargs)
return new_f
However, I cannot reference replacement_f
inside new_f
. And I can't use the standard trick of passing replacement_f
to new_f
as the default for a different parameter, because I'm using the *args
and **kwargs
variable argument lists.
The location where the original function is called cannot change, and will accept both positional and named parameters.
I fear that isn't very clear, but I'm happy to clarify if needed.
Thanks