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 maxbachmann
Recipients maxbachmann
Date 2020-12-13.00:21:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1607818885.74.0.707505524552.issue42629@roundup.psfhosted.org>
In-reply-to
Content
The documentation of PyObject_Call here: https://docs.python.org/3/c-api/call.html#c.PyObject_Call
states, that it is the equivalent of the Python expression: callable(*args, **kwargs).

so I would expect:
PyObject* args = PyTuple_New(0);
PyObject* kwargs = PyDict_New();
PyObject_Call(funcObj, args, kwargs)

to behave similar to
args = []
kwargs = {}
func(*args, **kwargs)

however this is not the case since in this case when I edit kwargs inside
PyObject* func(PyObject* /*self*/, PyObject* /*args*/, PyObject* keywds)
{
  PyObject* str = PyUnicode_FromString("test_str");
  PyDict_SetItemString(keywds, "test", str);
}

it changes the original dictionary passed into PyObject_Call. I was wondering, whether this means, that:
a) it is not allowed to modify the keywds argument passed to a PyCFunctionWithKeywords
b) when calling PyObject_Call it is required to copy the kwargs for the call using PyDict_Copy

Neither the documentation of PyObject_Call nor the documentation of PyCFunctionWithKeywords (https://docs.python.org/3/c-api/structures.html#c.PyCFunctionWithKeywords) made this clear to me.
History
Date User Action Args
2020-12-13 00:21:25maxbachmannsetrecipients: + maxbachmann
2020-12-13 00:21:25maxbachmannsetmessageid: <1607818885.74.0.707505524552.issue42629@roundup.psfhosted.org>
2020-12-13 00:21:25maxbachmannlinkissue42629 messages
2020-12-13 00:21:25maxbachmanncreate