bpo-40217: Ensure Py_VISIT(Py_TYPE(self)) is always called for PyType_FromSpec types (reverts GH-19414) by pablogsal · Pull Request #20264 · python/cpython
The Python 3.8 behavior is buggy. If a custom tp_traverse visits Py_TYPE(self), its subclasses will crash; if it doesn't, the type may become immortal. I expect that all extension types that use this now either have the latter bug, or are relying on buggy, undocumented implementation details.
I don't like the "Ensure that all custom tp_traverse functions of heap-allocated types visit the object parent but not for subclasses" guideline: it is difficult to understand, and more importantly, subtype_traverse itself doesn't follow it.
So, I'd like to acknowledge that Python 3.8 has the bug, set up a cleaner rule on what tp_traverse should do, and fix subtype_traverse to follow it. Specifically: The traversal function of a heap type must either visit Py_TYPE(self), or delegate this responsibility by calling tp_traverse of another heap type (such as a superclass).
I'll make a PR out of that shortly.