Skip to content

Commit 2b76964

Browse files
committed
Python: Expand tests of __new__ a bit more
1 parent a4e6433 commit 2b76964

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,27 @@ def __new__(cls, arg):
4444
inst.some_method() # $ MISSING: pt,tt=WithNew.some_method
4545
return inst
4646

47-
def __init__(self, arg):
47+
def __init__(self, arg=None):
4848
print("WithNew.__init__", arg)
4949

5050
def some_method(self):
51-
print("WithNew.__init__")
51+
print("WithNew.some_method")
5252

5353
WithNew(44) # $ tt=WithNew.__new__ tt=WithNew.__init__
5454
print()
5555

56+
class WithNewSub(WithNew):
57+
def __new__(cls):
58+
print("WithNewSub.__new__")
59+
inst = super().__new__(cls, 44.1) # $ pt,tt=WithNew.__new__
60+
assert isinstance(inst, cls)
61+
inst.some_method() # $ MISSING: pt,tt=WithNew.some_method
62+
return inst
63+
64+
WithNewSub() # $ tt=WithNewSub.__new__ tt=WithNew.__init__
65+
print()
66+
67+
# ------------------------------------------------------------------------------
5668

5769
class ExtraCallToInit(object):
5870
def __new__(cls, arg):

0 commit comments

Comments
 (0)