FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-111489: Add PyTuple_FromArray() function by vstinner · Pull Request #139691 · python/cpython · GitHub

Repository navigation

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

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

vstinner merged 4 commits into
python:mainfrom
vstinner:tuple_fromarray

Conversation

vstinner commented Oct 7, 2025 •
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Member

vstinner commented Oct 7, 2025

Copy link
Copy Markdown
Member Author

cc @serhiy-storchaka @encukou

Comment thread Lib/test/test_capi/test_tuple.py Outdated
Comment thread Lib/test/test_capi/test_tuple.py Outdated
Comment thread Modules/_testcapi/tuple.c Outdated
Comment thread Modules/_testcapi/tuple.c Outdated
Comment thread Modules/_testcapi/tuple.c Outdated
Comment thread Modules/_testcapi/tuple.c Outdated
Comment thread Doc/c-api/tuple.rst Outdated

vstinner commented Oct 7, 2025

Copy link
Copy Markdown
Member Author

@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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is not the empty tuple singleton a CPython implementation detail?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Comment thread Lib/test/test_capi/test_tuple.py Outdated
Comment thread Modules/_testcapi/tuple.c Outdated
Comment thread Objects/tupleobject.c Outdated
Use also UNINITIALIZED_SIZE in test code.

vstinner commented Oct 7, 2025

Copy link
Copy Markdown
Member Author

I updated the PR for the latest review.

serhiy-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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM. 👍

Comment thread Doc/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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 commented Oct 7, 2025

Copy link
Copy Markdown
Member

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

vstinner commented Oct 7, 2025

Copy link
Copy Markdown
Member Author

Do you want to open a WG vote for this?

I created capi-workgroup/decisions#79.

vstinner commented Oct 7, 2025 •
edited
Loading

Copy link
Copy Markdown
Member Author

I exchanged array and size parameters, new API:

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

vstinner commented Oct 8, 2025

Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
Member Author

I created capi-workgroup/decisions#79.

The C API Working Group accepted this API.

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

Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
Member Author

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

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL