Hi,
I propose adding PyTuple_FromArray() function:
PyObject* PyTuple_FromArray(PyObject *const *array, Py_ssize_t size)
Create a tuple of size items and copy references from array to the new tuple.
- On success, return a new reference.
- On failure, set an exception and return NULL.
array can be NULL is size is 0.
It's a convenient API to create a tuple from an array of Python objects.
Compared to PyTuple_New()+PyTuple_SET_ITEM(), it has the advantage of only tracking the tuple in the GC once the tuple is fully initialized, and so is safer.
Pull request: python/cpython#139691
Vote:
Hi,
I propose adding
PyTuple_FromArray()function:It's a convenient API to create a tuple from an array of Python objects.
Compared to
PyTuple_New()+PyTuple_SET_ITEM(), it has the advantage of only tracking the tuple in the GC once the tuple is fully initialized, and so is safer.Pull request: python/cpython#139691
Vote: