Skip to content

Commit fe15ee6

Browse files
authored
[mypyc] Avoid uses of _PyObject_CallMethodOneArg on 3.13 (python#17526)
It's no longer available in CPython 3.13 betas. This fixes some dict primitives on 3.13. Work on mypyc/mypyc#1056.
1 parent 8332c6e commit fe15ee6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

mypyc/lib-rt/dict_ops.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ PyObject *CPyDict_SetDefault(PyObject *dict, PyObject *key, PyObject *value) {
7878
return ret;
7979
}
8080
_Py_IDENTIFIER(setdefault);
81-
return _PyObject_CallMethodIdObjArgs(dict, &PyId_setdefault, key, value, NULL);
81+
PyObject *name = _PyUnicode_FromId(&PyId_setdefault); /* borrowed */
82+
if (name == NULL) {
83+
return NULL;
84+
}
85+
return PyObject_CallMethodObjArgs(dict, name, key, value, NULL);
8286
}
8387

8488
PyObject *CPyDict_SetDefaultWithNone(PyObject *dict, PyObject *key) {
@@ -133,7 +137,11 @@ static inline int CPy_ObjectToStatus(PyObject *obj) {
133137

134138
static int CPyDict_UpdateGeneral(PyObject *dict, PyObject *stuff) {
135139
_Py_IDENTIFIER(update);
136-
PyObject *res = _PyObject_CallMethodIdOneArg(dict, &PyId_update, stuff);
140+
PyObject *name = _PyUnicode_FromId(&PyId_update); /* borrowed */
141+
if (name == NULL) {
142+
return -1;
143+
}
144+
PyObject *res = PyObject_CallMethodOneArg(dict, name, stuff);
137145
return CPy_ObjectToStatus(res);
138146
}
139147

mypyc/lib-rt/pythonsupport.h

+2
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ _CPyObject_HasAttrId(PyObject *v, _Py_Identifier *name) {
401401
_PyObject_CallMethodIdObjArgs((self), (name), NULL)
402402
#define _PyObject_CallMethodIdOneArg(self, name, arg) \
403403
_PyObject_CallMethodIdObjArgs((self), (name), (arg), NULL)
404+
#define PyObject_CallMethodOneArg(self, name, arg) \
405+
PyObject_CallMethodObjArgs((self), (name), (arg), NULL)
404406
#endif
405407

406408
#if CPY_3_13_FEATURES

0 commit comments

Comments
 (0)