This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jkloth
Recipients jkloth, josh.r, vstinner
Date 2016-04-22.00:26:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1461284804.98.0.248527775323.issue26820@psf.upfronthosting.co.za>
In-reply-to
Content
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...
  }
History
Date User Action Args
2016-04-22 00:26:45jklothsetrecipients: + jkloth, vstinner, josh.r
2016-04-22 00:26:44jklothsetmessageid: <1461284804.98.0.248527775323.issue26820@psf.upfronthosting.co.za>
2016-04-22 00:26:44jklothlinkissue26820 messages
2016-04-22 00:26:43jklothcreate