Let's say I have a function foo that gets a few parameters
def foo(width, height, depth=0):
...
I want to write a wrapper function that gets all of foo's parameters and passes them on, e.g.
def goo(width, height, depth=0):
...
foo(width, height, depth)
...
But this is ugly, since I have to repeat the variables and the default values.
What's the idiomatic way to do this in python?
A few options I thought about:
passing to
gooa dictionary calledfoo_paramsand callingfoo(**foo_params)but then is error prone since I don't know if all the arguments are therewriting another wrapper for foo that checks if the params with default values are
Noneand if so doesn't pass themPutting the default values as constants so I won't repeat them
*argsand**kwargs(similar to your option 1, but no need to pass a dict togoo()). If a parameter is missing, the error will bubble up fromfoo()instead ofgoo(). Since they have the same function signature, that shouldn't be too confusing.*argsand**kwargsas well. its the most general method and widely accepted