This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pablogsal
Recipients corona10, lukasz.langa, pablogsal, petr.viktorin, serhiy.storchaka, shihai1991, tim.peters, vstinner
Date 2020-05-22.20:10:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> What would be the downsides of reverting and documenting that tp_traverse must visit Py_TYPE(self)?

Not much IMHO, I actually would prefer this solution over any automatic "hacks". The reason is that any hack will be technically violating the contract: if I read the tp_traverse of any of these classes I would say "wait a minute....this is wrong: the class owns a strong reference to its parent so...why is not visiting it?". But the answer would be that we are hacking because we didn't want to force users to migrate once we added the strong reference.

Notice that the root of this problem was bpo-35810. In that issue we added a guide to the docs: In  there it says that you should decref now the parent on tp_dealloc:

static void
foo_dealloc(foo_struct *instance) {
    PyObject *type = Py_TYPE(instance);
#if PY_VERSION_HEX >= 0x03080000
    // This was not needed before Python 3.8 (Python issue 35810)

but it forgot about that you should also visit the parent in tp_traverse.

So, I propose to do the following:

* Revert the hack.
* Fix the tp_traverse of all the relevant classes in the stdlib to correctly visit its parent.
* Modify the documentation of master, 3.9 and 3.8 to add the missing information: You MUST visit the parent in tp_traverse:

What do you think?
Date User Action Args
2020-05-22 20:10:55pablogsalsetrecipients: + pablogsal, tim.peters, vstinner, petr.viktorin, lukasz.langa, serhiy.storchaka, corona10, shihai1991
2020-05-22 20:10:55pablogsalsetmessageid: <>
2020-05-22 20:10:55pablogsallinkissue40217 messages
2020-05-22 20:10:55pablogsalcreate