René's URL Explorer Experiment


Title: [C API] Add `PyTupleWriter` API · Issue #161694 · python/cpython · GitHub

Open Graph Title: [C API] Add `PyTupleWriter` API · Issue #161694 · python/cpython

X Title: [C API] Add `PyTupleWriter` API · Issue #161694 · python/cpython

Description: Currently, to build a tuple, PyTuple_New() should be used with PyTuple_SetItem() or PyTuple_SET_ITEM(). This API has multiple issues: it modifies an immutable tuple and the tuple is directly tracked by the GC. There is also _PyTuple_Resi...

Open Graph Description: Currently, to build a tuple, PyTuple_New() should be used with PyTuple_SetItem() or PyTuple_SET_ITEM(). This API has multiple issues: it modifies an immutable tuple and the tuple is directly tracke...

X Description: Currently, to build a tuple, PyTuple_New() should be used with PyTuple_SetItem() or PyTuple_SET_ITEM(). This API has multiple issues: it modifies an immutable tuple and the tuple is directly tracke...

Opengraph URL: https://github.com/python/cpython/issues/161694

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[C API] Add `PyTupleWriter` API","articleBody":"Currently, to build a tuple, `PyTuple_New()` should be used with `PyTuple_SetItem()` or `PyTuple_SET_ITEM()`. This API has multiple issues: it modifies an **immutable** tuple and the tuple is directly **tracked by the GC**. There is also `_PyTuple_Resize()` function to resize an **immutable** tuple.\n\nI propose adding a new `PyTupleWriter` C API to clarify the \"build\" phase which ends with a Finish() call (or Discard() on error or if the builder is no longer needed).\n\nThe problem of designing such API is that it should be *as efficient* or even more efficient than the existing `PyTuple_New()` + `PyTuple_SET_ITEM()` pattern. I made a [first attempt](https://github.com/python/cpython/pull/107139) in 2023. Last year, I made a [second attempt](https://github.com/python/cpython/issues/139888) which didn't convince other developers. The API was based on `PyTupleWriter_Create()` + `PyTupleWriter_Add()` + `PyTupleWriter_Finish()`, and `PyTupleWriter_Create()` allocated a structure on the heap memory.\n\nI'm back with a different design: `PyTupleWriter_Create()` no longer allocates a structure on the heap memory, it's just a `PyTupleObject*` pointer hidden as an opaque `PyTupleWriter*` type. So `PyTupleWriter_Create()` and `PyTupleWriter_Finish()` are fast. The API basically allocates an array of `PyObject*` and the caller has to fill the array. The array is not initialized for best performance. The caller is responsible to fill all items, otherwise the tuple contains uninitialized memory.\n\nSee https://github.com/python/cpython/issues/139888 for the rationale on adding `PyTupleWriter` API.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-161639\n* gh-161908\n* gh-161911\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/vstinner","@type":"Person","name":"vstinner"},"datePublished":"2026-11-09T17:46:17Z","url":"https://github.com/python/cpython/issues/161694"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:ba35a883-0301-6223-7863-c37904cf08f0
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id925C:161320:1E26E99:27D7C51:6B0231C0
html-safe-nonce1a7970c31de3adea21470d5b1856243df2188e317bf481d3460c7bd3d2850f42
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MjVDOjE2MTMyMDoxRTI2RTk5OjI3RDdDNTE6NkIwMjMxQzAiLCJ2aXNpdG9yX2lkIjoiMzI4MjYzODQ1MDk1MTU5ODUyOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac3e84d3cf673249b9ad9d71cf7b03c00173bef05cbf95cf69fab0caee74bafa36
hovercard-subject-tagissue:6291484360
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/161694/issue_layout
twitter:imagehttps://opengraph.githubassets.com/a93c4c78738ddec3ac4b1a0f2d33e8b52012df9c798406f612075e27dac5a8a2/python/cpython/issues/161694
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/a93c4c78738ddec3ac4b1a0f2d33e8b52012df9c798406f612075e27dac5a8a2/python/cpython/issues/161694
og:image:altCurrently, to build a tuple, PyTuple_New() should be used with PyTuple_SetItem() or PyTuple_SET_ITEM(). This API has multiple issues: it modifies an immutable tuple and the tuple is directly tracke...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamevstinner
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/161694#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F161694
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F161694
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/161694
Reloadhttps://github.com/python/cpython/issues/161694
Reloadhttps://github.com/python/cpython/issues/161694
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/161694
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/161694
[C API] Add PyTupleWriter APIhttps://github.com/python/cpython/issues/161694#top
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-C-APIhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-C-API%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Nov 9, 2026https://github.com/python/cpython/issues/161694#issue-6291484360
first attempthttps://github.com/python/cpython/pull/107139
second attempthttps://github.com/python/cpython/issues/139888
#139888https://github.com/python/cpython/issues/139888
gh-161694: [C API] Add PyTupleWriter API #161639https://github.com/python/cpython/pull/161639
gh-161694: Check for integer overflow in PyObject_GC_Resize() #161908https://github.com/python/cpython/pull/161908
gh-161694: Check for integer overflow in _PyObject_VAR_SIZE() #161911https://github.com/python/cpython/pull/161911
vstinnerhttps://github.com/vstinner
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-C-APIhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-C-API%22
on Nov 9, 2026https://github.com/python/cpython/issues/161694#event-35597213066
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Nov 9, 2026https://github.com/python/cpython/issues/161694#issuecomment-6747426490
#161635https://github.com/python/cpython/issues/161635
https://github.com/encukou
encukouhttps://github.com/encukou
on Nov 10, 2026https://github.com/python/cpython/issues/161694#issuecomment-6765029439
vstinnerhttps://github.com/vstinner
on Nov 12, 2026https://github.com/python/cpython/issues/161694#event-35953395790
pythongh-161694: Check for integer overflow in PyObject_GC_Resize()https://github.com/vstinner/cpython/commit/97510e4bb1ddbd3b9fb2a25fe7b21176c8842ad5
pythongh-161694https://github.com/python/cpython/issues/161694
97510e4https://github.com/vstinner/cpython/commit/97510e4bb1ddbd3b9fb2a25fe7b21176c8842ad5
pythongh-161694: Check for integer overflow in PyObject_GC_Resize()https://github.com/vstinner/cpython/commit/8477da1bae05a49d42d1fa77a5a3f9adc006dc41
pythongh-161694https://github.com/python/cpython/issues/161694
8477da1https://github.com/vstinner/cpython/commit/8477da1bae05a49d42d1fa77a5a3f9adc006dc41
pythongh-161694: Check for integer overflow in PyObject_GC_Resize()https://github.com/vstinner/cpython/commit/e494234eed610143c8485814a4a954fe4c562815
pythongh-161694https://github.com/python/cpython/issues/161694
e494234https://github.com/vstinner/cpython/commit/e494234eed610143c8485814a4a954fe4c562815
pythongh-161694: Check for integer overflow in _PyObject_VAR_SIZE()https://github.com/vstinner/cpython/commit/3ac5d7b07c1b3ac68c4702d6486d8c478138e163
pythongh-161694https://github.com/python/cpython/issues/161694
3ac5d7bhttps://github.com/vstinner/cpython/commit/3ac5d7b07c1b3ac68c4702d6486d8c478138e163
pythongh-161694: Check for integer overflow in _PyObject_VAR_SIZE()https://github.com/vstinner/cpython/commit/1cd073ffa3b0f82400394af2ab9df2a83362f688
pythongh-161694https://github.com/python/cpython/issues/161694
1cd073fhttps://github.com/vstinner/cpython/commit/1cd073ffa3b0f82400394af2ab9df2a83362f688
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Nov 19, 2026https://github.com/python/cpython/issues/161694#issuecomment-7017097261
@encukouhttps://github.com/encukou
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/161694
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/161694
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-C-APIhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-C-API%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.