Jeroen Demeyer schrieb am 18.06.19 um 15:25:
Victor Stinner recently added the function PyObject_CallNoArgs() for calling an object without any arguments, see https://docs.python.org/3.9/c-api/object.html#c.PyObject_CallNoArgs
The next obvious question is: should we have PyObject_CallOneArg(), PyObject_CallTwoArgs()? Of course, this cannot continue forever, so I suggest adding the 1 and 2 argument variants which would cover most use cases. Cython has something like that and it becomes very natural to use these functions.
The main advantage is that we can implement these variants much more efficiently than the existing PyObject_CallFunction() or PyObject_CallFunctionObjArgs().
For internal use in CPython, we could also add a generic inline function
_PyObject_CallObjectPosArgs(PyObject *func, int nargs, ...)
and special-case its implementation with a switch statement for nargs in (0,1,2). The C-compiler should be more than happy to generate the expected code for us.
Whether that should then become an official C-API function, well, it could, I guess.