You cannot use farg
as keyword argument in that case; it cannot be interpreted as both a positional and a keyword argument, Python interprets it as a keyword argument in this case.
Use
self.test_var_kwargs(self, 1, myarg2="two", myarg3=3)
instead.
Functions act as descriptors; when looked up on an instance, they get wrapped in a new object called a method, which automatically adds the instance as a first argument to the function when called. This wrapper essentially does this:
class Method(object):
def __init__(self, function, instance, cls):
self.func = function
self.instance = instance
self.cls = cls
def __call__(self, *args, **kw):
return self.func(self.instance, *args, **kw)
Your farg
keyword argument is then lumped under the **kw
catchall and passed on to the underlying function, with *args
left empty.
But the test_var_kwargs
method you defined has one positional argument (next to self
, and thus an exception is raised.