- 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 commit is contained in:
Guido van Rossum 2002-04-06 01:05:01 +00:00
parent 181e41ad40
commit 8ace1ab53a
3 changed files with 30 additions and 0 deletions

View file

@ -169,6 +169,10 @@ type_call(PyTypeObject *type, PyObject *args, PyObject *kwds)
(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) {