New submission from STINNER Victor <vstin...@python.org>: While reviewing changes of bpo-40077 "Convert static types to PyType_FromSpec()", I noticed that some static types don't implement tp_traverse.
The doc says: Heap-allocated types (...) hold a reference to their type. Their traversal function must therefore either visit Py_TYPE(self), or delegate this responsibility by calling tp_traverse of another heap-allocated type (such as a heap-allocated superclass). If they do not, the type object may not be garbage-collected. https://docs.python.org/dev/c-api/typeobj.html#c.PyTypeObject.tp_traverse Porting to 3.9 says: for types that have a custom tp_traverse function, ensure that all custom tp_traverse functions of heap-allocated types visit the object’s type https://docs.python.org/dev/whatsnew/3.9.html#changes-in-the-c-api -- It seems like converting a static type to a heap allocated type requires to *add* a new tp_traverse function, if it wasn't the case. Maybe we can provide a base tp_traverse implementation in the base object type: visit the type if it's a heap type? See attached PR. See bpo-35810 and bpo-40217 for more information. ---------- components: C API, Interpreter Core messages: 371884 nosy: pablogsal, vstinner priority: normal severity: normal status: open title: Visit the type of instance of heap types if tp_traverse is not implemented versions: Python 3.10, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41036> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com