Python 2.7 function with keyword arguments in superclass: how to access from subclass?
<p>Are keyword arguments handled somehow specially in inherited methods? </p>

<p>When I call an instance method with keyword arguments from the class it's defined in, all goes well. When I call it from a subclass, Python complains about too many parameters passed. </p>

<p>Here's the example. The "simple" methods don't use keyword args, and inheritance works fine (even for me :-) The "KW" methods use keyword args, and inheritance doesn't work anymore... at least I can't see the difference. </p>

<pre><code>class aClass(object):
  def aSimpleMethod(self, show):
    print('show: %s' % show)
  def aKWMethod(self, **kwargs):
    for kw in kwargs:
      print('%s: %s' % (kw, kwargs[kw]))

class aSubClass(aClass):
  def anotherSimpleMethod(self, show):
    self.aSimpleMethod(show)
  def anotherKWMethod(self, **kwargs):
    self.aKWMethod(kwargs)

aClass().aSimpleMethod('this')
aSubClass().anotherSimpleMethod('that')
aClass().aKWMethod(show='this')
</code></pre>

<p>prints <code>this</code>, <code>that</code>, and <code>this</code>, as I expected. But</p>

<pre><code>aSubClass().anotherKWMethod(show='that')
</code></pre>

<p>throws:</p>

<pre><code>TypeError: aKWMethod() takes exactly 1 argument (2 given)
</code></pre>

<p>Just to demonstrate in the simplest terms possible what is going wrong, note that this error has nothing to do with inheritance. Consider the following case:</p>

<pre><code>&gt;&gt;&gt; def f(**kwargs):
...     pass
...
&gt;&gt;&gt; f(a='test') # works fine!
&gt;&gt;&gt; f('test')
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
TypeError: f() takes 0 positional arguments but 1 was given
</code></pre>

<p>The point is that <code>**kwargs</code> <em>only</em> allows keyword arguments and cannot be replaced by a positional argument. </p>

python python-2.7 inheritance variadic