Skip to content

Commit d43a48c

Browse files
committed
Python: Add type(self)() tests
1 parent 16483f7 commit d43a48c

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

python/ql/test/experimental/library-tests/CallGraph/InlineCallGraphTest.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pointsTo_found_typeTracker_notFound
77
| code/class_attr_assign.py:10:9:10:27 | ControlFlowNode for Attribute() | my_func |
88
| code/class_attr_assign.py:11:9:11:25 | ControlFlowNode for Attribute() | my_func |
99
| code/class_attr_assign.py:26:9:26:25 | ControlFlowNode for Attribute() | DummyObject.method |
10+
| code/class_construction.py:23:1:23:11 | ControlFlowNode for Attribute() | X.foo |
1011
| code/class_super.py:50:1:50:6 | ControlFlowNode for Attribute() | outside_def |
1112
| code/conditional_in_argument.py:18:5:18:11 | ControlFlowNode for Attribute() | X.bar |
1213
| code/func_defined_outside_class.py:21:1:21:11 | ControlFlowNode for Attribute() | A.foo |

python/ql/test/experimental/library-tests/CallGraph/code/class_construction.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
class X(object):
22
def __init__(self, arg):
33
print("X.__init__", arg)
4+
self.arg = arg
45

5-
X(42) # $ tt=X.__init__
6+
def foo(self):
7+
print("X.foo", self.arg)
8+
9+
def meth(self):
10+
print("X.meth")
11+
return type(self)(42.1) # $ MISSING: tt=X.__init__ tt=Y.__init__
12+
13+
@classmethod
14+
def cm(cls):
15+
print("X.cm")
16+
cls(42.2) # $ MISSING: tt=X.__init__ tt=Y.__init__
17+
18+
x = X(42.0) # $ tt=X.__init__
19+
x_421 = x.meth() # $ pt,tt=X.meth
20+
X.cm() # $ pt,tt=X.cm
21+
x.foo() # $ pt,tt=X.foo
22+
print()
23+
x_421.foo() # $ pt=X.foo MISSING: tt=X.foo
624
print()
725

826

@@ -11,7 +29,9 @@ def __init__(self, arg):
1129
print("Y.__init__", arg)
1230
super().__init__(-arg) # $ pt,tt=X.__init__
1331

14-
Y(43) # $ tt=Y.__init__
32+
y = Y(43) # $ tt=Y.__init__
33+
y.meth() # $ pt,tt=X.meth
34+
y.cm() # $ pt,tt=X.cm
1535
print()
1636

1737
# ---

0 commit comments

Comments
 (0)