Skip to content

bpo-44263: Mention PyType_Ready in the gc protocol warning #26445

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 1 commit into from
May 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions Doc/c-api/gcsupport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ Constructors for container types must conform to two rules:
a :c:member:`~PyTypeObject.tp_traverse` handler or explicitly use one
from its subclass or subclasses.

Some APIs like :c:func:`PyType_FromSpecWithBases` or
:c:func:`PyType_FromSpec` will automatically populate the
When calling :c:func:`PyType_Ready` or some of the APIs that indirectly
call it like :c:func:`PyType_FromSpecWithBases` or
:c:func:`PyType_FromSpec` the interpreter will automatically populate the
:c:member:`~PyTypeObject.tp_flags`, :c:member:`~PyTypeObject.tp_traverse`
and :c:member:`~PyTypeObject.tp_clear` fields if the type inherits from a
class that implements the garbage collector protocol and the child class
Expand Down
16 changes: 9 additions & 7 deletions Doc/c-api/type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ Type Objects
from a type's base class. Return ``0`` on success, or return ``-1`` and sets an
exception on error.

.. note::
If some of the base classes implements the GC protocol and the provided
type does not include the :const:`Py_TPFLAGS_HAVE_GC` in its flags, then
the GC protocol will be automatically implemented from its parents. On
the contrary, if the type being created does include
:const:`Py_TPFLAGS_HAVE_GC` in its flags then it **must** implement the
GC protocol itself by at least implementing the
:c:member:`~PyTypeObject.tp_traverse` handle.

.. c:function:: void* PyType_GetSlot(PyTypeObject *type, int slot)

Return the function pointer stored in the given slot. If the
Expand Down Expand Up @@ -169,13 +178,6 @@ The following functions and structs are used to create
The associated module is not inherited by subclasses; it must be specified
for each class individually.

If some of the bases in *bases* implements the GC protocol and the type being
created does not include the :const:`Py_TPFLAGS_HAVE_GC` in the flags included in
*spec*, then the GC protocol will be automatically implemented from its parents. On
the contrary, if the type being created does include :const:`Py_TPFLAGS_HAVE_GC` in
its flags then it *must* implement the GC protocol itself by at least including a slot
for :c:member:`~PyTypeObject.tp_traverse` in *spec*.

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

.. versionadded:: 3.9
Expand Down