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
77 lines (51 loc) · 1.01 KB
/
class.py
File metadata and controls
77 lines (51 loc) · 1.01 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
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
class Fubar:
def __init__(self):
self.x = 100
@property
def foo(self):
value = self.x
self.x += 1
return value
f = Fubar()
assert f.foo == 100
assert f.foo == 101
class Bar:
""" W00t """
def __init__(self, x):
self.x = x
def get_x(self):
return self.x
@classmethod
def fubar(cls, x):
assert cls is Bar
assert x == 2
@staticmethod
def kungfu(x):
assert x == 3
# TODO:
# 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)
# TODO: make this work:
# bar2 = Bar2()
# assert bar2.get_x() == 101
a = super(int, 2)
assert isinstance(a, super)
assert type(a) is super