1

I have the following code:

class TestA(object):
    def __init__(self, *args):
        super(TestA, self).__init__()
        print 'TestA'

class TestB(object):
    def __init__(self, my_var=None):
        super(TestB, self).__init__()
        print 'TestB', my_var

class TestC(object):
    def __init__(self, my_var=None):
        super(TestC, self).__init__()
        print 'TestC', my_var

class TestD(TestB, TestA, TestC):
    def __init__(self):
        print 'TestD'
        super(TestD, self).__init__("Hello World")

And the output is

TestD
TestC None
TestA
TestB Hello World

I would expect to have :

TestD
TestB Hello World
TestA
TestC Hello World

It looks super get only the first parent. When I have read one the answer in stackoverflow I thought it would do what I have expected. What's wrong in my code or my understanding?

Thank you in advance.

M07
  • 1,060
  • 1
  • 14
  • 23
  • 1
    *Each* method in the hierarchy needs to use super. See Raymond Hettinger's classic [`super` considered super](https://rhettinger.wordpress.com/2011/05/26/super-considered-super/). – Daniel Roseman Aug 18 '17 at 16:02
  • Hi @DanielRoseman, I have updated my question because I have not fully understand the behavior of multi-inheritance. Any clues? – M07 Aug 18 '17 at 19:23

0 Answers0