Cleanup: quiet deprecation warning building with Python 3.14

Replace use of `_PyDict_Pop` with `PyDict_Pop` when available.
This commit is contained in:
Campbell Barton
2025-06-30 15:55:19 +10:00
parent 6e67489785
commit 3b538a01d9
2 changed files with 44 additions and 5 deletions

View File

@@ -188,9 +188,27 @@ void BPY_context_dict_clear_members_array(void **dict_p,
* while supported it's good to avoid for low level functions like this that run often. */
for (uint i = 0; i < context_members_len; i++) {
PyObject *key = PyUnicode_FromString(context_members[i]);
PyObject *item = _PyDict_Pop(dict, key, Py_None);
Py_DECREF(key);
PyObject *item;
#if PY_VERSION_HEX >= 0x030d0000
switch (PyDict_Pop(dict, key, &item)) {
case 1: {
Py_DECREF(item);
break;
}
case -1: {
/* Not expected, but allow for an error. */
BLI_assert(false);
PyErr_Clear();
break;
}
}
#else /* Remove when Python 3.12 support is dropped. */
item = _PyDict_Pop(dict, key, Py_None);
Py_DECREF(item);
#endif
Py_DECREF(key);
}
if (use_gil) {

View File

@@ -592,18 +592,39 @@ static PyTypeObject BPyContextTempOverride_Type = {
static PyObject *bpy_context_temp_override_extract_known_args(const char *const *kwds_static,
PyObject *kwds)
{
PyObject *sentinel = Py_Ellipsis;
PyObject *kwds_parse = PyDict_New();
for (int i = 0; kwds_static[i]; i++) {
PyObject *key = PyUnicode_FromString(kwds_static[i]);
PyObject *val = _PyDict_Pop(kwds, key, sentinel);
PyObject *val;
#if PY_VERSION_HEX >= 0x030d0000
switch (PyDict_Pop(kwds, key, &val)) {
case 1: {
if (PyDict_SetItem(kwds_parse, key, val) == -1) {
BLI_assert_unreachable();
}
Py_DECREF(val);
break;
}
case -1: {
/* Not expected, but allow for an error. */
BLI_assert(false);
PyErr_Clear();
break;
}
}
#else /* Remove when Python 3.12 support is dropped. */
PyObject *sentinel = Py_Ellipsis;
val = _PyDict_Pop(kwds, key, sentinel);
if (val != sentinel) {
if (PyDict_SetItem(kwds_parse, key, val) == -1) {
BLI_assert_unreachable();
}
}
Py_DECREF(key);
Py_DECREF(val);
#endif
Py_DECREF(key);
}
return kwds_parse;
}