GeezerVison is showing github.com — [C API] Make _PyTuple_FromArray() function public · Issue #111489 · python/cpython
[C API] Make _PyTuple_FromArray() function public #111489DescriptionI dislike PyList_New() + PyList_SET_ITEM() API since the list is immediately tracked by the GC and so calling gc.get_objects() can expose an invalid list object (ex: calling repr(list) can crash). See:
The internal PyObject * _PyTuple_FromArray(PyObject *const *src, Py_ssize_t n) function should be made public.
cc @erlend-aasland
UPDATE: I updated the issue to request promoting _PyTuple_FromArray() instead of _PyList_FromArraySteal().
Linked PRs
Reacted by Erlend E. Aasland Activityvstinner commented on Oct 30, 2023 We should also make PyObject* _PyTuple_FromArraySteal(PyObject *const *src, Py_ssize_t n) public. encukou commented on Oct 30, 2023 Can you wait until the new guidelines are approved? Not everyone is happy with the term steal. vstinner commented on Oct 30, 2023 vstinner commented on Dec 11, 2023 vstinner commented on Dec 20, 2023 @encukou:
Can you wait until the new guidelines are approved?
Ok, I close the issue. vstinner commented on Oct 7, 2025 Let me retry to implement these functions. I reopen the issue. vstinner commented on Oct 7, 2025 Let's start with the non controversial part: I created #139691 to add PyTuple_FromArray(). vstinner commented on Oct 7, 2025 changed the title [-][C API] Make _PyList_FromArraySteal() function public[/-] [+][C API] Make _PyList_FromArray() function public[/+] on Oct 9, 2025changed the title [-][C API] Make _PyList_FromArray() function public[/-] [+][C API] Make _PyTuple_FromArray() function public[/+] on Oct 9, 2025vstinner commented on Oct 10, 2025 Oh, the function _PyList_FromArraySteal() was replaced with _PyList_FromStackRefSteal() which gets a const _PyStackRef *src array (commit ab094d1). vstinner commented on Oct 10, 2025 I close the issue.
I added PyTuple_FromArray() to Python 3.15.
The C API Working Group is against adding PyTuple_FromArraySteal() to the public C API.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|