diff options
author | Wenzel Jakob <wenzel.jakob@epfl.ch> | 2022-05-27 08:27:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-27 08:27:39 (GMT) |
commit | 5e34b494a08015e9b5a3deade23943bdba284a93 (patch) | |
tree | 829c824df2d307b14d0cf9efc51e2bbfcca92589 /Doc/c-api | |
parent | 20d30ba2ccf9182e4f08db112f428c909148a40b (diff) | |
download | cpython-5e34b494a08015e9b5a3deade23943bdba284a93.zip cpython-5e34b494a08015e9b5a3deade23943bdba284a93.tar.gz cpython-5e34b494a08015e9b5a3deade23943bdba284a93.tar.bz2 |
gh-60074: add new stable API function PyType_FromMetaclass (GH-93012)
Added a new stable API function ``PyType_FromMetaclass``, which mirrors
the behavior of ``PyType_FromModuleAndSpec`` except that it takes an
additional metaclass argument. This is, e.g., useful for language
binding tools that need to store additional information in the type
object.
Diffstat (limited to 'Doc/c-api')
-rw-r--r-- | Doc/c-api/type.rst | 20 | ||||
-rw-r--r-- | Doc/c-api/typeobj.rst | 2 |
2 files changed, 17 insertions, 5 deletions
diff --git a/Doc/c-api/type.rst b/Doc/c-api/type.rst index d740e4e..99b3845 100644 --- a/Doc/c-api/type.rst +++ b/Doc/c-api/type.rst @@ -190,11 +190,16 @@ Creating Heap-Allocated Types The following functions and structs are used to create :ref:`heap types <heap-types>`. -.. c:function:: PyObject* PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) +.. c:function:: PyObject* PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module, PyType_Spec *spec, PyObject *bases) - Creates and returns a :ref:`heap type <heap-types>` from the *spec* + Create and return a :ref:`heap type <heap-types>` from the *spec* (:const:`Py_TPFLAGS_HEAPTYPE`). + The metaclass *metaclass* is used to construct the resulting type object. + When *metaclass* is ``NULL``, the default :c:type:`PyType_Type` is used + instead. Note that metaclasses that override + :c:member:`~PyTypeObject.tp_new` are not supported. + The *bases* argument can be used to specify base classes; it can either be only one class or a tuple of classes. If *bases* is ``NULL``, the *Py_tp_bases* slot is used instead. @@ -210,6 +215,12 @@ The following functions and structs are used to create This function calls :c:func:`PyType_Ready` on the new type. + .. versionadded:: 3.12 + +.. c:function:: PyObject* PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) + + Equivalent to ``PyType_FromMetaclass(NULL, module, spec, bases)``. + .. versionadded:: 3.9 .. versionchanged:: 3.10 @@ -217,15 +228,16 @@ The following functions and structs are used to create The function now accepts a single class as the *bases* argument and ``NULL`` as the ``tp_doc`` slot. + .. c:function:: PyObject* PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) - Equivalent to ``PyType_FromModuleAndSpec(NULL, spec, bases)``. + Equivalent to ``PyType_FromMetaclass(NULL, NULL, spec, bases)``. .. versionadded:: 3.3 .. c:function:: PyObject* PyType_FromSpec(PyType_Spec *spec) - Equivalent to ``PyType_FromSpecWithBases(spec, NULL)``. + Equivalent to ``PyType_FromMetaclass(NULL, NULL, spec, NULL)``. .. c:type:: PyType_Spec diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst index b3f371b..df47904 100644 --- a/Doc/c-api/typeobj.rst +++ b/Doc/c-api/typeobj.rst @@ -2071,7 +2071,7 @@ flag set. This is done by filling a :c:type:`PyType_Spec` structure and calling :c:func:`PyType_FromSpec`, :c:func:`PyType_FromSpecWithBases`, -or :c:func:`PyType_FromModuleAndSpec`. +:c:func:`PyType_FromModuleAndSpec`, or :c:func:`PyType_FromMetaclass`. .. _number-structs: |