diff Objects/typeobject.c @ 25657:0690ea6d1153 2.2

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.
author Guido van Rossum <guido@python.org>
date Mon, 07 Oct 2002 18:08:27 +0000
parents a7dbe4e7f5de
children e374ea7ac4ce
line wrap: on
line diff
--- a/Objects/typeobject.c	Mon Oct 07 17:19:41 2002 +0000
+++ b/Objects/typeobject.c	Mon Oct 07 18:08:27 2002 +0000
@@ -189,6 +189,10 @@
 		    (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 &&