8000 bpo-44263: Mention PyType_Ready in the gc protocol warning (GH-26445)… · python/cpython@d8ce746 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d8ce746

Browse files
bpo-44263: Mention PyType_Ready in the gc protocol warning (GH-26445) (#26446)
(cherry picked from commit 43cf7c8) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com> Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
1 parent addd329 commit d8ce746

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
@@ -169,13 +178,6 @@ The following functions and structs are used to create
169178
The associated module is not inherited by subclasses; it must be specified
170179
for each class individually.
171180
172-
If some of the bases in *bases* implements the GC protocol and the type being
173-
created does not include the :const:`Py_TPFLAGS_HAVE_GC` in the flags included in
174-
*spec*, then the GC protocol will be automatically implemented from its parents. On
175-
the contrary, if the type being created does include :const:`Py_TPFLAGS_HAVE_GC` in
176-
its flags then it *must* implement the GC protocol itself by at least including a slot
177-
for :c:member:`~PyTypeObject.tp_traverse` in *spec*.
178-
179181
This function calls :c:func:`PyType_Ready` on the new type.
180182
181183
.. versionadded:: 3.9

0 commit comments

Comments
 (0)
0