Multiple Inheritance With Same Method Names but Different Arguments Creates TypeError
<p>I have a four distinct classes. There is a main base/parent class, two main classes that inherit from this parent class, and another class that inherits from both of these main classes. If I have a method with the same name but a different number of arguments as a parent class, I get a TypeError.</p>

<pre><code># Example

class Parent(object):
    def check(self, arg):
        tmp = {
            'one': False,
            'two': False
        }

        try:
            if 'one' in arg:
                tmp['one'] = True

            if 'two' in arg:
                tmp['two'] = True
        except TypeError:
            pass

        return tmp

class Child(Parent):
    def check(self, arg):
        return Parent.check(self, arg)['one']

    def method(self, arg):
        if self.check(arg):
            print 'One!'

class ChildTwo(Parent):
    def check(self, arg):
        return Parent.check(self, arg)['two']

    def method(self, arg):
        if self.check(arg):
            print 'Two!'

class ChildThree(Child, ChildTwo):
    def check(self, arg, arg2):
        print arg2
        return Child.check(self, arg)

    def method(self, arg):
        if self.check(arg, 'test'):
            print 'One!'

        ChildTwo.method(self, arg)

test = ChildThree()
test = test.method('one and two')
</code></pre>

<blockquote>
  <p>runfile('untitled6.py', wdir='./Documents')<br>
  test<br>
  One!<br>
  Traceback (most recent call last):<br>
   File "&lt; stdin >", line 1, in &lt; module ><br>
   File "C:\Users\py\AppData\Local\Continuum\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile<br>
     execfile(filename, namespace)<br>
   File "C:\Users\py\AppData\Local\Continuum\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile<br>
     exec(compile(scripttext, filename, 'exec'), glob, loc)<br>
   File "untitled6.py", line 49, in <br>
     test = test.method('one and two')<br>
   File "untitled6.py", line 46, in method<br>
     ChildTwo.method(self, arg)<br>
   File "untitled6.py", line 34, in method<br>
     if self.check(arg):  </p>
  
  <p>TypeError: check() takes exactly 3 arguments (2 given)</p>
</blockquote>

<p>However, when I remove the second argument from the 'check' method in 'ChildThree', it seems to work fine:</p>

<pre><code>class ChildThree(Child, ChildTwo):
    def check(self, arg):
        return Child.check(self, arg)

    def method(self, arg):
        if self.check(arg):
            print 'One!'

        ChildTwo.method(self, arg)
</code></pre>

<blockquote>
  <p>runfile('untitled6.py', wdir='./Documents')<br>
  One!<br>
  Two!</p>
</blockquote>

<p>I am fairly new to classes/inheritance, so I am not sure why an extra argument causes a TypeError even though it calls the parent class method with a single argument.</p>

<p>Consider this line:</p>

<pre><code>ChildTwo.method(self, arg)
</code></pre>

<p>You passed in <code>self</code> explicitly.  <code>self</code> here is a reference to a <code>ChildThree</code> instance.  Later, in the body of <code>ChildTwo.method</code>:</p>

<pre><code>if self.check(arg):
</code></pre>

<p>It's the same <code>self</code> we're talking about here; <code>self</code> is still a reference on your <code>ChildThree</code> instance.</p>

<p>It looks like you expected <code>self</code> to do something magical, but it doesn't - it's just a plain old name.  For it to refer to a <code>ChildTwo</code> instance it would have had to be called like a bound method.  Compare and contrast:</p>

<ul>
<li><code>my_child_two.method(arg)</code> &lt;-- "self" gets passed implicitly by descriptor protocol </li>
<li><code>ChildTwo.method(self, arg)</code> &lt;-- "self" is just whatever it is  </li>
</ul>

python class inheritance typeerror