docs(easy): Document that heap types need to support garbage collection #116935
Description
Activity
- addeddocsDocumentation in the Doc dirDocumentation in the Doc dir
on Mar 17, 2024 I think this is true when a heap type is created by
PyType_From*()with a module explicitly specified. As to #116934,thread_handle_typein_threadmodule.cdoes not hold a module, so switching fromtp_alloc()back toPyObject_New()at the object creation would also fix the refleaks when GC cannot be respected.I'd be happy to open a PR to update the docs but wanted to make sure I understand the comment above.
@neonene Are you suggesting that heap types wouldn't have this requirement if
PyObject_New()was used, making this documentation update unnecessary? If so, is that a favourable or in progress change?As long as not a few heap types work in Python without
tp_traverse, I think the docs can require us to follow the GC-protocol as a current rule. If the docs really need to mention technical reasons,tp_dictandtp_mrowould be stronger thanht_module.Reacted by Savannah Ostrowski- added a commit that references this issue
on Apr 19, 2024 - added a commit that references this issue
on Apr 19, 2024
Documentation
In https://docs.python.org/3/c-api/typeobj.html#c.Py_TPFLAGS_HEAPTYPE, it does not mention that the heap type must support GC. However this is actually the case. The type itself needs to be visited by the GC because it forms a reference cycle with its own module object. We should document this.
Linked PRs