forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.py
More file actions
166 lines (114 loc) · 2.47 KB
/
class.py
File metadata and controls
166 lines (114 loc) · 2.47 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
__name__ = "class"
class Foo:
def __init__(self, x):
assert x == 5
self.x = x
def square(self):
return self.x * self.x
y = 7
foo = Foo(5)
assert foo.y == Foo.y
assert foo.x == 5
assert foo.square() == 25
assert Foo.__name__ == "Foo"
assert Foo.__qualname__ == "Foo"
assert Foo.__module__ == "class"
assert Foo.square.__name__ == "square"
assert Foo.square.__qualname__ == "Foo.square"
assert Foo.square.__module__ == "class"
class Bar:
""" W00t """
def __init__(self, x):
self.x = x
def get_x(self):
assert __class__ is Bar
return self.x
@classmethod
def fubar(cls, x):
assert __class__ is cls
assert cls is Bar
assert x == 2
@staticmethod
def kungfu(x):
assert __class__ is Bar
assert x == 3
assert Bar.__doc__ == " W00t "
bar = Bar(42)
bar.fubar(2)
Bar.fubar(2)
bar.kungfu(3)
Bar.kungfu(3)
class Bar2(Bar):
def __init__(self):
super().__init__(101)
bar2 = Bar2()
assert bar2.get_x() == 101
class A():
def test(self):
return 100
class B():
def test1(self):
return 200
@classmethod
def test3(cls):
return 300
class C(A,B):
def test(self):
return super().test()
def test1(self):
return super().test1()
@classmethod
def test3(cls):
return super().test3()
c = C()
assert c.test() == 100
assert c.test1() == 200
assert c.test3() == 300
assert C.test3() == 300
class Me():
def test(me):
return 100
class Me2(Me):
def test(me):
return super().test()
class A():
def f(self):
pass
class B(A):
def f(self):
super().f()
class C(B):
def f(self):
super().f()
C().f()
me = Me2()
assert me.test() == 100
a = super(bool, True)
assert isinstance(a, super)
assert type(a) is super
assert a.conjugate() == 1
class T1:
"test1"
assert T1.__doc__ == "test1"
class T2:
'''test2'''
assert T2.__doc__ == "test2"
class T3:
"""
test3
"""
assert T3.__doc__ == "\n test3\n "
class T4:
"""test4"""
def t1(self):
"""t1"""
pass
assert T4.__doc__ == "test4"
assert T4.t1.__doc__ == "t1"
cm = classmethod(lambda cls: cls)
assert cm.__func__(int) is int
assert str(super(int, 5)) == "<super: <class 'int'>, <int object>>"
class T5(int):
pass
assert str(super(int, T5(5))) == "<super: <class 'int'>, <T5 object>>"
#assert str(super(type, None)) == "<super: <class 'type'>, NULL>"