summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-04-06 01:05:01 (GMT)
committerGuido van Rossum <guido@python.org>2002-04-06 01:05:01 (GMT)
commit8ace1ab53a49d90d66e8a03491a272c70ad4eb46 (patch)
treed08f5976ad3e74100608cade6362c0ad41be1099 /Lib
parent181e41ad4064cc94b9f41ce49ee541a132f93615 (diff)
downloadcpython-8ace1ab53a49d90d66e8a03491a272c70ad4eb46.zip
cpython-8ace1ab53a49d90d66e8a03491a272c70ad4eb46.tar.gz
cpython-8ace1ab53a49d90d66e8a03491a272c70ad4eb46.tar.bz2
- Changed new-style class instantiation so that when C's __new__
method returns something that's not a C instance, its __init__ is not called. [SF bug #537450]
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_descr.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 8d8c276..ab55952 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -2897,6 +2897,27 @@ def dictproxyiteritems():
keys.sort()
vereq(keys, ['__dict__', '__doc__', '__module__', '__weakref__', 'meth'])
+def funnynew():
+ if verbose: print "Testing __new__ returning something unexpected..."
+ class C(object):
+ def __new__(cls, arg):
+ if isinstance(arg, str): return [1, 2, 3]
+ elif isinstance(arg, int): return object.__new__(D)
+ else: return object.__new__(cls)
+ class D(C):
+ def __init__(self, arg):
+ self.foo = arg
+ vereq(C("1"), [1, 2, 3])
+ vereq(D("1"), [1, 2, 3])
+ d = D(None)
+ veris(d.foo, None)
+ d = C(1)
+ vereq(isinstance(d, D), True)
+ vereq(d.foo, 1)
+ d = D(1)
+ vereq(isinstance(d, D), True)
+ vereq(d.foo, 1)
+
def test_main():
class_docstrings()
lists()
@@ -2959,6 +2980,7 @@ def test_main():
dictproxyitervalues()
dictproxyiteritems()
pickleslots()
+ funnynew()
if verbose: print "All OK"
if __name__ == "__main__":