diff Objects/typeobject.c @ 22859:bbf05af3c191 legacy-trunk

- 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]
author Guido van Rossum <guido@python.org>
date Sat, 06 Apr 2002 01:05:01 +0000
parents 32eec6d79c93
children 252438bb05d9
line wrap: on
line diff
--- a/Objects/typeobject.c	Sat Apr 06 00:23:25 2002 +0000
+++ b/Objects/typeobject.c	Sat Apr 06 01:05:01 2002 +0000
@@ -169,6 +169,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 (type->tp_init != NULL &&
 		    type->tp_init(obj, args, kwds) < 0) {