-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_multiple_inheritance.py
46 lines (39 loc) · 1.38 KB
/
test_multiple_inheritance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# see http://stackoverflow.com/q/35626923/4612064
class A(object):
def doit(self):
print "A", self, super(A, self)
super(A, self).doit()
class B(object):
def doit(self):
print "B", self, super(B, self)
class C(A,B):
def doit(self):
print "C", self
A.doit(self)
B.doit(self)
def doit_explain(self):
print "C", self
# calls B.doit()
super(A, self).doit()
print "Back to C"
# calls A.doit() (and super in A also calls B.doit())
super(C, self).doit()
print "Back to C"
# second-time B.doit()
B.doit(self)
print "MRO:", [x.__name__ for x in C.__mro__]
#MRO: ['C', 'A', 'B', 'object']
C().doit()
# C <__main__.C object at 0x7f37575e2d10>
# A <__main__.C object at 0x7f37575e2d10> <super: <class 'A'>, <C object>>
# B <__main__.C object at 0x7f37575e2d10> <super: <class 'B'>, <C object>>
# B <__main__.C object at 0x7f37575e2d10> <super: <class 'B'>, <C object>>
print ''
C().doit_explain()
# C <__main__.C object at 0x7fc100f8f790>
# B <__main__.C object at 0x7fc100f8f790> <super: <class 'B'>, <C object>>
# Back to C
# A <__main__.C object at 0x7fc100f8f790> <super: <class 'A'>, <C object>>
# B <__main__.C object at 0x7fc100f8f790> <super: <class 'B'>, <C object>>
# Back to C
# B <__main__.C object at 0x7fc100f8f790> <super: <class 'B'>, <C object>>