mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
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.
This commit is contained in:
parent
20d30ba2cc
commit
5e34b494a0
12 changed files with 150 additions and 14 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue