Skip to content

Commit f9f0049

Browse files
authored
Properly visit self in >=3.9 traverse (#4051)
* Properly visit self in >=3.9 traverse * Add comment about 3.9 behavior
1 parent 432bc5c commit f9f0049

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

include/pybind11/detail/class.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,10 @@ extern "C" inline int pybind11_set_dict(PyObject *self, PyObject *new_dict, void
531531
extern "C" inline int pybind11_traverse(PyObject *self, visitproc visit, void *arg) {
532532
PyObject *&dict = *_PyObject_GetDictPtr(self);
533533
Py_VISIT(dict);
534+
// https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_traverse
535+
#if PY_VERSION_HEX >= 0x03090000
536+
Py_VISIT(Py_TYPE(self));
537+
#endif
534538
return 0;
535539
}
536540

0 commit comments

Comments
 (0)