[Python-checkins] CVS: python/dist/src/Lib/test test_descr.py,1.127,1.128

Guido van Rossum gvanrossum@users.sourceforge.net
Fri, 05 Apr 2002 17:05:03 -0800


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv2721/Lib/test

Modified Files:
	test_descr.py 
Log Message:
- 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]



Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.127
retrieving revision 1.128
diff -C2 -d -r1.127 -r1.128
*** test_descr.py	3 Apr 2002 22:41:50 -0000	1.127
--- test_descr.py	6 Apr 2002 01:05:01 -0000	1.128
***************
*** 2898,2901 ****
--- 2898,2922 ----
      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()
***************
*** 2960,2963 ****
--- 2981,2985 ----
      dictproxyiteritems()
      pickleslots()
+     funnynew()
      if verbose: print "All OK"