Is it possible to pass arbitrary number of named default arguments to a Python function conditionally ?
For eg. there\'s a function:
def func(arg, ar
You can write a helper function
def caller(func, *args, **kwargs):
return func(*args, **{k:v for k,v in kwargs.items() if v != caller.DONT_PASS})
caller.DONT_PASS = object()
Use this function to call another function and use caller.DONT_PASS to specify arguments that you don't want to pass.
caller(func, 'arg', 'arg2', arg3 = 'some value' if condition else caller.DONT_PASS)
Note that this caller() only support conditionally passing keyword arguments. To support positional arguments, you may need to use module inspect to inspect the function.