I've tried to read python 2.7
docs, but no chance to undestand unfortunately.
Why does that happening? How it is connected with MRO and super call inside of init?
First example:
class SuperFirst(object):
def __init__(self):
super(SuperFirst, self).__init__()
print "We were in SuperFirst's __init__"
class SuperSecond(object):
def __init__(self):
super(SuperSecond, self).__init__()
print "We were in SuperSecond's __init__"
class JustThird(SuperFirst, SuperSecond):
def __init__(self):
super(JustThird, self).__init__()
print "We were in JustThird's __init__"
JustThird()
This outputs:
We were in SuperSecond's __init__
We were in SuperFirst's __init__
We were in JustThird's __init__
Now lets remove the super call inside of the init of the first parent:
class SuperFirst(object):
def __init__(self):
print "We were in SuperFirst's __init__"
class SuperSecond(object):
def __init__(self):
super(SuperSecond, self).__init__()
print "We were in SuperSecond's __init__"
class JustThird(SuperFirst, SuperSecond):
def __init__(self):
super(JustThird, self).__init__()
print "We were in JustThird's __init__"
JustThird()
Output:
We were in SuperFirst's __init__
We were in JustThird's __init__
Now keep it only in the first parent:
class SuperFirst(object):
def __init__(self):
super(SuperFirst, self).__init__()
print "We were in SuperFirst's __init__"
class SuperSecond(object):
def __init__(self):
print "We were in SuperSecond's __init__"
class JustThird(SuperFirst, SuperSecond):
def __init__(self):
super(JustThird, self).__init__()
print "We were in JustThird's __init__"
JustThird()
Output:
We were in SuperSecond's __init__
We were in SuperFirst's __init__
We were in JustThird's __init__
Now remove from both parents:
class SuperFirst(object):
def __init__(self):
print "We were in SuperFirst's __init__"
class SuperSecond(object):
def __init__(self):
print "We were in SuperSecond's __init__"
class JustThird(SuperFirst, SuperSecond):
def __init__(self):
super(JustThird, self).__init__()
print "We were in JustThird's __init__"
JustThird()
Output:
We were in SuperFirst's __init__
We were in JustThird's __init__