[Python-checkins] python/dist/src/Lib/test test_descr.py,1.113.4.24,1.113.4.25

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Mon, 07 Oct 2002 11:08:28 -0700


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

Modified Files:
      Tag: release22-maint
	test_descr.py 
Log Message:
Backport, at the reqest of Kevin Jacobs:

- 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]

XXX This is arguably a semantic change, but it's hard to imagine a
reason for wanting to depend on the old behavior.  If problems with
this are reported within a week of the release of 2.2.2 beta 1, we may
revert this change.


Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.113.4.24
retrieving revision 1.113.4.25
diff -C2 -d -r1.113.4.24 -r1.113.4.25
*** test_descr.py	1 Aug 2002 19:03:41 -0000	1.113.4.24
--- test_descr.py	7 Oct 2002 18:08:26 -0000	1.113.4.25
***************
*** 3018,3021 ****
--- 3018,3042 ----
      del C.__del__
  
+ 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()
***************
*** 3079,3082 ****
--- 3100,3104 ----
      copy_setstate()
      subtype_resurrection()
+     funnynew()
      if verbose: print "All OK"