From 1c72409f7ff218726b8142d0d03417ccdc32ce0f Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sun, 22 Mar 2026 17:27:20 -0400 Subject: [PATCH] chore: some minor CPython API cleanup (#6005) * chore: use PyType_GetFlags Signed-off-by: Henry Schreiner * chore: use public VectorCall in 3.9+ Signed-off-by: Henry Schreiner --------- Signed-off-by: Henry Schreiner --- include/pybind11/attr.h | 2 +- include/pybind11/cast.h | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/pybind11/attr.h b/include/pybind11/attr.h index b4486dc0f..d337595a0 100644 --- a/include/pybind11/attr.h +++ b/include/pybind11/attr.h @@ -378,7 +378,7 @@ struct type_record { #ifdef PYBIND11_BACKWARD_COMPATIBILITY_TP_DICTOFFSET dynamic_attr |= base_info->type->tp_dictoffset != 0; #else - dynamic_attr |= (base_info->type->tp_flags & Py_TPFLAGS_MANAGED_DICT) != 0; + dynamic_attr |= (PyType_GetFlags(base_info->type) & Py_TPFLAGS_MANAGED_DICT) != 0; #endif if (caster) { diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 6d0e851fa..9c8cdd0c7 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -2240,8 +2240,13 @@ public: if (m_names) { nargs -= m_names.size(); } - PyObject *result = _PyObject_Vectorcall( - ptr, m_args.data() + 1, nargs | PY_VECTORCALL_ARGUMENTS_OFFSET, m_names.ptr()); + PyObject *result = +#if PY_VERSION_HEX >= 0x03090000 + PyObject_Vectorcall( +#else + _PyObject_Vectorcall( +#endif + ptr, m_args.data() + 1, nargs | PY_VECTORCALL_ARGUMENTS_OFFSET, m_names.ptr()); if (!result) { throw error_already_set(); }