]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
- A type can now inherit its metatype from its base type. Previously,
authorGuido van Rossum <guido@python.org>
Mon, 8 Apr 2002 01:39:56 +0000 (01:39 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 8 Apr 2002 01:39:56 +0000 (01:39 +0000)
  when PyType_Ready() was called, if ob_type was found to be NULL, it
  was always set to &PyType_Type; now it is set to base->ob_type,
  where base is tp_base, defaulting to &PyObject_Type.

Misc/NEWS
Objects/typeobject.c

index 5098898e8093b484962c1076847e1d0b9db2c503..fc3902bd348cdd7ddf8d71355b850f30f730be36 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -20,6 +20,11 @@ Library
 
 C API
 
+- A type can now inherit its metatype from its base type.  Previously,
+  when PyType_Ready() was called, if ob_type was found to be NULL, it
+  was always set to &PyType_Type; now it is set to base->ob_type,
+  where base is tp_base, defaulting to &PyObject_Type.
+
 - PyType_Ready() accidentally did not inherit tp_is_gc; now it does.
 
 Windows
index 5ec5784c94e3a90d6e731e5e95496740ccce6a3f..158c0ed1f6487ab34d7fb4ac70e13899548d25c9 100644 (file)
@@ -2002,17 +2002,17 @@ PyType_Ready(PyTypeObject *type)
 
        type->tp_flags |= Py_TPFLAGS_READYING;
 
-       /* Initialize ob_type if NULL.  This means extensions that want to be
-          compilable separately on Windows can call PyType_Ready() instead of
-          initializing the ob_type field of their type objects. */
-       if (type->ob_type == NULL)
-               type->ob_type = &PyType_Type;
-
        /* Initialize tp_base (defaults to BaseObject unless that's us) */
        base = type->tp_base;
        if (base == NULL && type != &PyBaseObject_Type)
                base = type->tp_base = &PyBaseObject_Type;
 
+       /* Initialize ob_type if NULL.  This means extensions that want to be
+          compilable separately on Windows can call PyType_Ready() instead of
+          initializing the ob_type field of their type objects. */
+       if (type->ob_type == NULL)
+               type->ob_type = base->ob_type;
+
        /* Initialize tp_bases */
        bases = type->tp_bases;
        if (bases == NULL) {