Skip to content

Commit 2216bf4

Browse files
committed
fix: pass a tuple of bases for Python 3.9
PyType_FromSpecWithBases accepts a single class only from Python 3.10. Also discard the release() result explicitly for clang-tidy. Assisted-by: ClaudeCode:claude-fable-5-2
1 parent 6a8698f commit 2216bf4

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎include/pybind11/detail/function_record_pyobject.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,13 @@ inline PyTypeObject *get_function_record_module_PyTypeObject() {
168168
0,
169169
Py_TPFLAGS_DEFAULT,
170170
slots};
171-
PyObject *py_obj
172-
= PyType_FromSpecWithBases(&spec, reinterpret_cast<PyObject *>(&PyModule_Type));
171+
// Python < 3.10 needs a tuple for the bases.
172+
auto bases = reinterpret_steal<object>(
173+
PyTuple_Pack(1, reinterpret_cast<PyObject *>(&PyModule_Type)));
174+
if (!bases) {
175+
throw error_already_set();
176+
}
177+
PyObject *py_obj = PyType_FromSpecWithBases(&spec, bases.ptr());
173178
if (py_obj == nullptr) {
174179
throw error_already_set();
175180
}

‎include/pybind11/pybind11-inl.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ PYBIND11_INLINE void cpp_function::initialize_generic(unique_function_record &&u
682682
rec->def->ml_flags = METH_FASTCALL | METH_KEYWORDS;
683683

684684
object py_func_rec = detail::function_record_PyObject_New(rec->scope, rec);
685-
unique_rec.release();
685+
(void) unique_rec.release();
686686
guarded_strdup.release();
687687
#if defined(PYBIND11_FUNCTION_RECORD_QUALNAME)
688688
if (PyModule_Check(py_func_rec.ptr()) != 0) {

0 commit comments

Comments
 (0)