Skip to content

gh-111489: Add PyTuple_FromArray() function - #139691

Merged
vstinner merged 4 commits into
python:mainfrom
vstinner:tuple_fromarray
Oct 10, 2025
Merged

gh-111489: Add PyTuple_FromArray() function#139691
vstinner merged 4 commits into
python:mainfrom
vstinner:tuple_fromarray

Conversation

@vstinner

@vstinnervstinner commented Oct 7, 2025

Copy link
Copy Markdown
Member

@vstinner

Copy link
Copy Markdown
MemberAuthor

Comment threadLib/test/test_capi/test_tuple.py Outdated
Comment threadLib/test/test_capi/test_tuple.py Outdated
Comment threadModules/_testcapi/tuple.c Outdated
Comment threadModules/_testcapi/tuple.c Outdated
Comment threadModules/_testcapi/tuple.c Outdated
Comment threadModules/_testcapi/tuple.c Outdated
Comment threadDoc/c-api/tuple.rst Outdated
@vstinner

Copy link
Copy Markdown
MemberAuthor

@serhiy-storchaka: I addressed your comments. Please review the updated PR.


tup = ()
copy = tuple_fromarray(tup)
self.assertIs(copy, tup)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not the empty tuple singleton a CPython implementation detail?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole file is a CPython implementation detail (_testcapi), no?

Comment threadLib/test/test_capi/test_tuple.py Outdated
Comment threadModules/_testcapi/tuple.c Outdated
Comment threadObjects/tupleobject.c Outdated
Use also UNINITIALIZED_SIZE in test code.
@vstinner

Copy link
Copy Markdown
MemberAuthor

I updated the PR for the latest review.

@serhiy-storchakaserhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

Comment threadDoc/c-api/tuple.rst
Comment on lines +42 to +43
Create a tuple of *size* items and copy references from *array* to the new
tuple.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to formulate this in words more similar to PyTuple_New() or PyTuple_Pack() ("Return a new tuple object of size ... "), but this is not so important.

@encukou

Copy link
Copy Markdown
Member

Implementation looks good, thanks! Do you want to open a WG vote for this?

@vstinner

Copy link
Copy Markdown
MemberAuthor

Do you want to open a WG vote for this?

I created capi-workgroup/decisions#79.

@vstinner

vstinner commented Oct 7, 2025

Copy link
Copy Markdown
MemberAuthor

I exchanged array and size parameters, new API:

PyObject* PyTuple_FromArray(Py_ssize_t size, PyObject *const *array)

@vstinner

Copy link
Copy Markdown
MemberAuthor

I exchanged array and size parameters, new API: (...)

Sorry, I changed my preference back to (array, size) as before :-) See the API discussion at: capi-workgroup/decisions#79

@vstinner

Copy link
Copy Markdown
MemberAuthor

I created capi-workgroup/decisions#79.

The C API Working Group accepted this API.

@vstinner
vstinner merged commit e31c22d into python:mainOct 10, 2025
90 checks passed
@vstinner
vstinner deleted the tuple_fromarray branch October 10, 2025 06:54
@vstinner

Copy link
Copy Markdown
MemberAuthor

Merged. Thanks for your review @serhiy-storchaka and @encukou!

@vstinner

Copy link
Copy Markdown
MemberAuthor

I added the function to pythoncapi-compat: python/pythoncapi-compat@89e023e

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@vstinner@encukou@serhiy-storchaka