Skip to content
Snippets Groups Projects
Commit b349479a authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

tests/class_new: Add another testcase for __new__/__init__ interaction.

Similar to the existing testcase, but test that returning both value of
native type and instance of another user class from __new__ lead to
__init__ not being called, for better coverage.
parent ca21aed0
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,9 @@ a.meth()
a = a.__new__(A)
a.meth()
# __new__ returns not an instance of the class (None here), __init__
# should not be called
class B:
def __new__(self, v1, v2):
print("B.__new__", v1, v2)
......@@ -43,3 +46,21 @@ class B:
print("B.__init__", v1, v2)
print("B inst:", B(1, 2))
# Variation of the above, __new__ returns an instance of another class,
# __init__ should not be called
class Dummy: pass
class C:
def __new__(cls):
print("C.__new__")
return Dummy()
def __init__(self):
# Should not be called in this test
print("C.__init__")
c = C()
print(isinstance(c, Dummy))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment