From 87711b0c89aed6bc7db5886bc65e06e5aebe0c94 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Sun, 8 Sep 2024 10:25:01 +0900 Subject: [PATCH] nb_type_new(): adaption for older Python versions, follow ``tp_traverse`` recommendations in test suite --- src/nb_type.cpp | 4 +++- tests/test_stl.cpp | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/nb_type.cpp b/src/nb_type.cpp index 783b45e4..23ff4e3f 100644 --- a/src/nb_type.cpp +++ b/src/nb_type.cpp @@ -1176,7 +1176,9 @@ PyObject *nb_type_new(const type_init_data *t) noexcept { *s++ = { Py_tp_members, (void*) members }; #if PY_VERSION_HEX < 0x03090000 - (void) is_generic; // unsupported on Python 3.8 + // Features that are unsupported in Python 3.8 + (void) is_generic; + type_vectorcall = nullptr; #else if (is_generic) *s++ = { Py_tp_methods, (void*) class_getitem_method }; diff --git a/tests/test_stl.cpp b/tests/test_stl.cpp index 7d26093a..9dd97a96 100644 --- a/tests/test_stl.cpp +++ b/tests/test_stl.cpp @@ -70,6 +70,10 @@ int funcwrapper_tp_traverse(PyObject *self, visitproc visit, void *arg) { nb::object f = nb::cast(w->f, nb::rv_policy::none); Py_VISIT(f.ptr()); + #if PY_VERSION_HEX >= 0x03090000 + Py_VISIT(Py_TYPE(self)); + #endif + return 0; }