Skip to content

Commit

Permalink
[mypyc] Replace deprecated _PyDict_GetItemStringWithError (python#17930)
Browse files Browse the repository at this point in the history
`_PyDict_GetItemStringWithError ` was deprecated for Python 3.14 in
python/cpython#119855.
Use `PyDict_GetItemStringRef` instead. It was added in 3.13 but is
available via `pythoncapi_compat.h`.

https://docs.python.org/3/c-api/dict.html#c.PyDict_GetItemStringRef
  • Loading branch information
cdce8p authored Oct 16, 2024
1 parent fbae432 commit f63fdb3
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions mypyc/lib-rt/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,14 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
#endif
if (!skip) {
if (i < nargs && i < max) {
current_arg = PyTuple_GET_ITEM(args, i);
current_arg = Py_NewRef(PyTuple_GET_ITEM(args, i));
}
else if (nkwargs && i >= pos) {
current_arg = _PyDict_GetItemStringWithError(kwargs, kwlist[i]);
if (current_arg) {
int res = PyDict_GetItemStringRef(kwargs, kwlist[i], &current_arg);
if (res == 1) {
--nkwargs;
}
else if (PyErr_Occurred()) {
else if (res == -1) {
return 0;
}
}
Expand All @@ -265,6 +265,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
if (current_arg) {
PyObject **p = va_arg(*p_va, PyObject **);
*p = current_arg;
Py_DECREF(current_arg);
format++;
continue;
}
Expand Down Expand Up @@ -370,8 +371,11 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
Py_ssize_t j;
/* make sure there are no arguments given by name and position */
for (i = pos; i < bound_pos_args && i < len; i++) {
current_arg = _PyDict_GetItemStringWithError(kwargs, kwlist[i]);
if (unlikely(current_arg != NULL)) {
int res = PyDict_GetItemStringRef(kwargs, kwlist[i], &current_arg);
if (res == 1) {
Py_DECREF(current_arg);
}
else if (unlikely(res == 0)) {
/* arg present in tuple and in dict */
PyErr_Format(PyExc_TypeError,
"argument for %.200s%s given by name ('%s') "
Expand All @@ -381,7 +385,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
kwlist[i], i+1);
goto latefail;
}
else if (unlikely(PyErr_Occurred() != NULL)) {
else if (unlikely(res == -1)) {
goto latefail;
}
}
Expand Down

0 comments on commit f63fdb3

Please sign in to comment.