Python: Add type(self)() tests

This commit is contained in:
Rasmus Wriedt Larsen
2022-10-24 14:38:28 +02:00
parent 16483f7d40
commit d43a48c265
2 changed files with 23 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ pointsTo_found_typeTracker_notFound
| code/class_attr_assign.py:10:9:10:27 | ControlFlowNode for Attribute() | my_func |
| code/class_attr_assign.py:11:9:11:25 | ControlFlowNode for Attribute() | my_func |
| code/class_attr_assign.py:26:9:26:25 | ControlFlowNode for Attribute() | DummyObject.method |
| code/class_construction.py:23:1:23:11 | ControlFlowNode for Attribute() | X.foo |
| code/class_super.py:50:1:50:6 | ControlFlowNode for Attribute() | outside_def |
| code/conditional_in_argument.py:18:5:18:11 | ControlFlowNode for Attribute() | X.bar |
| code/func_defined_outside_class.py:21:1:21:11 | ControlFlowNode for Attribute() | A.foo |

View File

@@ -1,8 +1,26 @@
class X(object):
def __init__(self, arg):
print("X.__init__", arg)
self.arg = arg
X(42) # $ tt=X.__init__
def foo(self):
print("X.foo", self.arg)
def meth(self):
print("X.meth")
return type(self)(42.1) # $ MISSING: tt=X.__init__ tt=Y.__init__
@classmethod
def cm(cls):
print("X.cm")
cls(42.2) # $ MISSING: tt=X.__init__ tt=Y.__init__
x = X(42.0) # $ tt=X.__init__
x_421 = x.meth() # $ pt,tt=X.meth
X.cm() # $ pt,tt=X.cm
x.foo() # $ pt,tt=X.foo
print()
x_421.foo() # $ pt=X.foo MISSING: tt=X.foo
print()
@@ -11,7 +29,9 @@ class Y(X):
print("Y.__init__", arg)
super().__init__(-arg) # $ pt,tt=X.__init__
Y(43) # $ tt=Y.__init__
y = Y(43) # $ tt=Y.__init__
y.meth() # $ pt,tt=X.meth
y.cm() # $ pt,tt=X.cm
print()
# ---