New submission from Max Bachmann <kont...@maxbachmann.de>:

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.

----------
components: C API
messages: 382927
nosy: maxbachmann
priority: normal
severity: normal
status: open
title: PyObject_Call not behaving as documented
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42629>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to