Skip to content

bpo-45383: Inherit MetaClass from bases in FromSpec API #28748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jun 9, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Document caveats, suggest that PyType_From* is not for user-provided …
…classes
  • Loading branch information
encukou committed May 31, 2022
commit f86d2b5a6aa47feb8199ab25b51f3c330594ec2d
15 changes: 14 additions & 1 deletion Doc/c-api/type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ The following functions and structs are used to create
.. c:function:: PyObject* PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module, PyType_Spec *spec, PyObject *bases)

Create and return a :ref:`heap type <heap-types>` from the *spec*
(:const:`Py_TPFLAGS_HEAPTYPE`).
(see :const:`Py_TPFLAGS_HEAPTYPE`).

The metaclass *metaclass* is used to construct the resulting type object.
When *metaclass* is ``NULL``, the metaclass is derived from *bases*
Expand All @@ -216,6 +216,19 @@ The following functions and structs are used to create

This function calls :c:func:`PyType_Ready` on the new type.

Note that this function does *not* fully match the behavior of
calling :py:class:`type() <type>` or using the :keyword:`class` statement.
With user-provided base types or metaclasses, prefer
:ref:`calling <capi-call>` :py:class:`type` (or the metaclass)
over ``PyType_From*`` functions.
Specifically:

* :py:meth:`~object.__new__` is not called on the new class
(and it must be set to ``type.__new__``).
* :py:meth:`~object.__init__` is not called on the new class.
* :py:meth:`~object.__init_subclass__` is not called on any bases.
* :py:meth:`~object.__set_name__` is not called on new descriptors.

.. versionadded:: 3.12

.. c:function:: PyObject* PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases)
Expand Down