From b565c36963178817fedec4971c6719ea96987c71 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 30 Aug 2017 21:29:23 +0300 Subject: [PATCH] tests/object_new: Better messages, check user __new__() method. Make messages more verbose and easier to follow and check that user class' __new__() is not called by object.__new__(user_class). --- tests/basics/object_new.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/basics/object_new.py b/tests/basics/object_new.py index a9c9482cbb..1bf7bc0ecb 100644 --- a/tests/basics/object_new.py +++ b/tests/basics/object_new.py @@ -12,6 +12,11 @@ except AttributeError: class Foo: + def __new__(cls): + # Should not be called in this test + print("in __new__") + raise RuntimeError + def __init__(self): print("in __init__") self.attr = "something" @@ -19,12 +24,13 @@ class Foo: o = object.__new__(Foo) #print(o) -print(hasattr(o, "attr")) -print(isinstance(o, Foo)) +print("Result of __new__ has .attr:", hasattr(o, "attr")) +print("Result of __new__ is already a Foo:", isinstance(o, Foo)) + o.__init__() #print(dir(o)) -print(hasattr(o, "attr")) -print(o.attr) +print("After __init__ has .attr:", hasattr(o, "attr")) +print(".attr:", o.attr) # should only be able to call __new__ on user types try: