This exception also will be raised whenever a function has been called with the combination of keyword arguments
and args
, kwargs
Example:
def function(a, b, c, *args, **kwargs):
print(f"a: {a}, b: {b}, c: {c}, args: {args}, kwargs: {kwargs}")
function(a=1, b=2, c=3, *(4,))
And it'll raise:
TypeError Traceback (most recent call last)
<ipython-input-4-1dcb84605fe5> in <module>
----> 1 function(a=1, b=2, c=3, *(4,))
TypeError: function() got multiple values for argument 'a'
And Also it'll become more complicated, whenever you misuse it in the inheritance. so be careful we this stuff!
1- Calling a function with keyword arguments
and args
:
class A:
def __init__(self, a, b, *args, **kwargs):
self.a = a
self.b = b
class B(A):
def __init__(self, *args, **kwargs):
a = 1
b = 2
super(B, self).__init__(a=a, b=b, *args, **kwargs)
B(3, c=2)
Exception:
TypeError Traceback (most recent call last)
<ipython-input-5-17e0c66a5a95> in <module>
11 super(B, self).__init__(a=a, b=b, *args, **kwargs)
12
---> 13 B(3, c=2)
<ipython-input-5-17e0c66a5a95> in __init__(self, *args, **kwargs)
9 a = 1
10 b = 2
---> 11 super(B, self).__init__(a=a, b=b, *args, **kwargs)
12
13 B(3, c=2)
TypeError: __init__() got multiple values for argument 'a'
2- Calling a function with keyword arguments
and kwargs
which it contains keyword arguments too:
class A:
def __init__(self, a, b, *args, **kwargs):
self.a = a
self.b = b
class B(A):
def __init__(self, *args, **kwargs):
a = 1
b = 2
super(B, self).__init__(a=a, b=b, *args, **kwargs)
B(**{'a': 2})
Exception:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-c465f5581810> in <module>
11 super(B, self).__init__(a=a, b=b, *args, **kwargs)
12
---> 13 B(**{'a': 2})
<ipython-input-7-c465f5581810> in __init__(self, *args, **kwargs)
9 a = 1
10 b = 2
---> 11 super(B, self).__init__(a=a, b=b, *args, **kwargs)
12
13 B(**{'a': 2})
TypeError: __init__() got multiple values for keyword argument 'a'
Horizontol_drawbox
function? If it starts withfillBox
, then that's the fault (assigned one time with positional argument, and a second time with keyword argument). – Cilyan