Skip to content

Commit b565c36

Browse files
committed
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).
1 parent df6605e commit b565c36

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

tests/basics/object_new.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,25 @@
1212

1313
class Foo:
1414

15+
def __new__(cls):
16+
# Should not be called in this test
17+
print("in __new__")
18+
raise RuntimeError
19+
1520
def __init__(self):
1621
print("in __init__")
1722
self.attr = "something"
1823

1924

2025
o = object.__new__(Foo)
2126
#print(o)
22-
print(hasattr(o, "attr"))
23-
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+
2430
o.__init__()
2531
#print(dir(o))
26-
print(hasattr(o, "attr"))
27-
print(o.attr)
32+
print("After __init__ has .attr:", hasattr(o, "attr"))
33+
print(".attr:", o.attr)
2834

2935
# should only be able to call __new__ on user types
3036
try:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy