Skip to content

Commit 7e42541

Browse files
committed
Use _PyObject_CallMethodIdObjArgs()
Issue python#28915: Replace _PyObject_CallMethodId() with _PyObject_CallMethodIdObjArgs() when the format string only use the format 'O' for objects, like "(O)". _PyObject_CallMethodIdObjArgs() avoids the code to parse a format string and avoids the creation of a temporary tuple.
1 parent 4c38154 commit 7e42541

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

Modules/_io/textio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,7 +2435,7 @@ _io_TextIOWrapper_tell_impl(textio *self)
24352435
}
24362436

24372437
finally:
2438-
res = _PyObject_CallMethodId(self->decoder, &PyId_setstate, "(O)", saved_state);
2438+
res = _PyObject_CallMethodIdObjArgs(self->decoder, &PyId_setstate, saved_state, NULL);
24392439
Py_DECREF(saved_state);
24402440
if (res == NULL)
24412441
return NULL;
@@ -2449,7 +2449,7 @@ _io_TextIOWrapper_tell_impl(textio *self)
24492449
if (saved_state) {
24502450
PyObject *type, *value, *traceback;
24512451
PyErr_Fetch(&type, &value, &traceback);
2452-
res = _PyObject_CallMethodId(self->decoder, &PyId_setstate, "(O)", saved_state);
2452+
res = _PyObject_CallMethodIdObjArgs(self->decoder, &PyId_setstate, saved_state, NULL);
24532453
_PyErr_ChainExceptions(type, value, traceback);
24542454
Py_DECREF(saved_state);
24552455
Py_XDECREF(res);

Objects/descrobject.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,8 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *args)
804804

805805
if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &def))
806806
return NULL;
807-
return _PyObject_CallMethodId(pp->mapping, &PyId_get, "(OO)", key, def);
807+
return _PyObject_CallMethodIdObjArgs(pp->mapping, &PyId_get,
808+
key, def, NULL);
808809
}
809810

810811
static PyObject *

Python/sysmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o)
130130

131131
buffer = _PyObject_GetAttrId(outf, &PyId_buffer);
132132
if (buffer) {
133-
result = _PyObject_CallMethodId(buffer, &PyId_write, "(O)", encoded);
133+
result = _PyObject_CallMethodIdObjArgs(buffer, &PyId_write, encoded, NULL);
134134
Py_DECREF(buffer);
135135
Py_DECREF(encoded);
136136
if (result == NULL)

0 commit comments

Comments
 (0)