-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathclass_super.py
More file actions
108 lines (80 loc) · 1.93 KB
/
Copy pathclass_super.py
File metadata and controls
108 lines (80 loc) · 1.93 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
def outside_def(self):
print("outside_def")
try:
super().foo()
except RuntimeError:
pass
class A(object):
def foo(self):
print("A.foo")
@classmethod
def bar(cls):
print("A.bar")
class B(A):
def foo(self):
print("B.foo")
def foo_on_super(self):
print("B.foo_on_super")
super().foo() # $ pt,tt=A.foo
super(B, self).foo() # $ pt,tt=A.foo
od = outside_def
@staticmethod
def sm():
try:
super().foo()
except RuntimeError:
print("B.sm")
pass
@classmethod
def bar(cls):
print("B.bar")
@classmethod
def bar_on_super(cls):
print("B.bar_on_super")
super().bar() # $ tt=A.bar
super(B, cls).bar() # $ tt=A.bar
b = B()
b.foo() # $ pt,tt=B.foo
b.foo_on_super() # $ pt,tt=B.foo_on_super
b.od() # $ pt=outside_def
b.sm() # $ pt,tt=B.sm
print("="*10, "static method")
B.bar() # $ pt,tt=B.bar
B.bar_on_super() # $ pt,tt=B.bar_on_super
print("="*10, "Manual calls to super")
super(B, b).foo() # $ pt,tt=A.foo
assert A.foo == super(B, B).foo
super(B, B).foo(b) # $ tt=A.foo
try:
super(B, 42).foo()
except TypeError:
pass
# For some reason, points-to isn't able to resolve any calls from here on. I've tried to
# comment out both try-except blocks, but that did not solve the problem :|
print("="*10, "C")
class C(B):
def foo_on_A(self):
print('C.foo_on_A')
super(B, self).foo() # $ tt=A.foo
c = C()
c.foo_on_A() # $ tt=C.foo_on_A
print("="*10, "Diamon hierachy")
class X(object):
def foo(self):
print('X.foo')
class Y(X):
def foo(self):
print('Y.foo')
super().foo() # $ tt=X.foo
class Z(X):
def foo(self):
print('Z.foo')
super().foo() # $ tt=X.foo tt=Y.foo
print("! z.foo()")
z = Z()
z.foo() # $ tt=Z.foo
class ZY(Z, Y):
pass
print("! zy.foo()")
zy = ZY()
zy.foo() # $ tt=Z.foo