Skip to content

Add PyTuple_FromArray() function #79

@vstinner

Description

@vstinner

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    voteThe WG is voting (or has voted)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions