-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathclass.py
More file actions
62 lines (54 loc) · 1.22 KB
/
class.py
File metadata and controls
62 lines (54 loc) · 1.22 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
# Copyright 2018 The go-python Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
doc="Test class definitions"
class C1:
"Test 1"
def method1(self, x):
"method1"
return x+1
def method2(self, m2):
"method2"
return self.method1(m2)+m2
c = C1()
assert c.method1(1) == 2
assert c.method2(1) == 3
doc="Test class definitions 2"
class C2:
"Test 2"
_VAR = 1
VAR = _VAR + 1
def method1(self, x):
"method1"
return self.VAR + x
def method2(self, m2):
"method2"
return self.method1(m2)+m2
c = C2()
assert c.method1(1) == 3
assert c.method2(1) == 4
# FIXME more corner cases in CLASS_DEREF
doc="CLASS_DEREF"
def classderef(y):
x = y
class DeRefTest:
VAR = x
def method1(self, x):
"method1"
return self.VAR+x
return DeRefTest
x = classderef(1)
c = x()
assert c.method1(1) == 2
doc="CLASS_DEREF2"
def classderef2(x):
class DeRefTest:
VAR = x
def method1(self, x):
"method1"
return self.VAR+x
return DeRefTest
x = classderef2(1)
c = x()
assert c.method1(1) == 2
doc="finished"