Skip to content

Commit 7bd1304

Browse files
bpo-44263: Mention PyType_Ready in the gc protocol warning (GH-26445)
(cherry picked from commit 43cf7c8) Co-authored-by: Pablo Galindo <[email protected]>
1 parent a30cbae commit 7bd1304

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

Doc/c-api/gcsupport.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ Constructors for container types must conform to two rules:
3838
a :c:member:`~PyTypeObject.tp_traverse` handler or explicitly use one
3939
from its subclass or subclasses.
4040

41-
Some APIs like :c:func:`PyType_FromSpecWithBases` or
42-
:c:func:`PyType_FromSpec` will automatically populate the
41+
When calling :c:func:`PyType_Ready` or some of the APIs that indirectly
42+
call it like :c:func:`PyType_FromSpecWithBases` or
43+
:c:func:`PyType_FromSpec` the interpreter will automatically populate the
4344
:c:member:`~PyTypeObject.tp_flags`, :c:member:`~PyTypeObject.tp_traverse`
4445
and :c:member:`~PyTypeObject.tp_clear` fields if the type inherits from a
4546
class that implements the garbage collector protocol and the child class

Doc/c-api/type.rst

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ Type Objects
9797
from a type's base class. Return ``0`` on success, or return ``-1`` and sets an
9898
exception on error.
9999
100+
.. note::
101+
If some of the base classes implements the GC protocol and the provided
102+
type does not include the :const:`Py_TPFLAGS_HAVE_GC` in its flags, then
103+
the GC protocol will be automatically implemented from its parents. On
104+
the contrary, if the type being created does include
105+
:const:`Py_TPFLAGS_HAVE_GC` in its flags then it **must** implement the
106+
GC protocol itself by at least implementing the
107+
:c:member:`~PyTypeObject.tp_traverse` handle.
108+
100109
.. c:function:: void* PyType_GetSlot(PyTypeObject *type, int slot)
101110
102111
Return the function pointer stored in the given slot. If the
@@ -168,13 +177,6 @@ The following functions and structs are used to create
168177
The associated module is not inherited by subclasses; it must be specified
169178
for each class individually.
170179
171-
If some of the bases in *bases* implements the GC protocol and the type being
172-
created does not include the :const:`Py_TPFLAGS_HAVE_GC` in the flags included in
173-
*spec*, then the GC protocol will be automatically implemented from its parents. On
174-
the contrary, if the type being created does include :const:`Py_TPFLAGS_HAVE_GC` in
175-
its flags then it *must* implement the GC protocol itself by at least including a slot
176-
for :c:member:`~PyTypeObject.tp_traverse` in *spec*.
177-
178180
This function calls :c:func:`PyType_Ready` on the new type.
179181
180182
.. versionadded:: 3.9

0 commit comments

Comments
 (0)