Consider the following:
def my_wrapper(wrapper_argument=False, *args, **kwargs):
return my_function(*args, **kwargs)
def my_function(arg1, arg2, params=None):
# do_stuff
return result
when I call the above with:
my_wrapper('foo', 'bar', wrapper_argument=True)
I get:
TypeError: my_function() got multiple values for argument 'wrapper_argument'
Why? Is the ordering of the arguments perhaps wrong?
You are assigning foo
to wrapper_argument
(because its the first positional argument); then you are assigning it again as an optional keyword argument.
When you pass these arguments from your wrapper to the callable, Python pops the error.
To avoid it, don't pass in an optional keyword argument similar to an existing keyword argument.
Since the question is for Python 3, you can re-order the arguments in the function definition as follows:
Instead of:
def my_wrapper(wrapper_argument=False, *args, **kwargs):
do:
def my_wrapper(*args, wrapper_argument=False, **kwargs):
and keep everything else the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With