We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent df6605e commit b565c36Copy full SHA for b565c36
tests/basics/object_new.py
@@ -12,19 +12,25 @@
12
13
class Foo:
14
15
+ def __new__(cls):
16
+ # Should not be called in this test
17
+ print("in __new__")
18
+ raise RuntimeError
19
+
20
def __init__(self):
21
print("in __init__")
22
self.attr = "something"
23
24
25
o = object.__new__(Foo)
26
#print(o)
-print(hasattr(o, "attr"))
-print(isinstance(o, Foo))
27
+print("Result of __new__ has .attr:", hasattr(o, "attr"))
28
+print("Result of __new__ is already a Foo:", isinstance(o, Foo))
29
30
o.__init__()
31
#print(dir(o))
-print(o.attr)
32
+print("After __init__ has .attr:", hasattr(o, "attr"))
33
+print(".attr:", o.attr)
34
35
# should only be able to call __new__ on user types
36
try:
0 commit comments