Jeremy Kloth added the comment: IMHO, this is a documentation bug with PyObject_CallMethod. The change to its documentation to differ from PyObject_CallFunction was changed back in 2004. It should have been updated then to reflect the already well-entrenched behavior of those 2 (at the time) functions, but that ship has sailed.
It would be a huge mistake to change how they handle the format strings now as they have operated they way they have since at least Python 1.5.2 (when I learned Python's C API). There is just too much C code that would potentially break (third-party C extensions). I think that a good change for the docs would be to separate the specification of the "building format string" away from the Py_BuildValue function so as to allow for differences in how the resulting object is created in those C functions that use that specification. Similar, I suppose, to how the "parsing format string" is defined independently from PyArg_ParseTuple. Now to the "attractive nuisance" that the single argument passed as varargs is handled. I believe it may be best to introduce a new format character just for this purpose. Possibly "T" (for tuple) or "V" (for varargs) using uppercase as that seems to be the practice for referencing objects. And at the same time, add a check in the "call" functions (those that *use* Py_VaBuildValue to create a argument tuple, of which there are also internal ones). The check could be as simple as: if (format[0] == 'O' && format[1] == '\0') { va_start(va, format); PyObject *ob = (PyObject *)va_arg(va, PyObject *); if (ob != NULL) { if (PyTuple_Check(ob)) { if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, "use 'V' format code to support varargs")) { args = NULL; } else { args = ob; } } else { args = PyTuple_Pack(1, ob); } } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_SystemError, "argument is NULL"); args = NULL; } va_end(va); } else { args = //...whatever happens now... } ---------- nosy: +jkloth _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26820> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com