# it as a leak.
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()
lists()
imulbug()
copy_setstate()
subtype_resurrection()
+ funnynew()
if verbose: print "All OK"
if __name__ == "__main__":
-What's New in Python 2.2.2?
-Release date: dd-mmm-2002
-===========================
+What's New in Python 2.2.2b1?
+Release date: 7-Oct-2002
+=============================
Core and builtins
+- 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] (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.)
+
- u'%c' will now raise a ValueError in case the argument is an
integer outside the valid range of Unicode code point ordinals.
(kwds == NULL ||
(PyDict_Check(kwds) && PyDict_Size(kwds) == 0)))
return obj;
+ /* If the returned object is not an instance of type,
+ it won't be initialized. */
+ if (!PyType_IsSubtype(obj->ob_type, type))
+ return obj;
type = obj->ob_type;
if (PyType_HasFeature(type, Py_TPFLAGS_HAVE_CLASS) &&
type->tp_init != NULL &&