Title: Tuples should be immutable and safe in C, as well as in Python. · Issue #127058 · python/cpython · GitHub
Open Graph Title: Tuples should be immutable and safe in C, as well as in Python. · Issue #127058 · python/cpython
X Title: Tuples should be immutable and safe in C, as well as in Python. · Issue #127058 · python/cpython
Description: Bug report Bug description: [Apologies if this sounds a bit like a rant. I'm not blaming anyone. Just because something is the wrong choice now, doesn't mean it wasn't the right choice historically] Tuples are immutable in Python, but we...
Open Graph Description: Bug report Bug description: [Apologies if this sounds a bit like a rant. I'm not blaming anyone. Just because something is the wrong choice now, doesn't mean it wasn't the right choice historically...
X Description: Bug report Bug description: [Apologies if this sounds a bit like a rant. I'm not blaming anyone. Just because something is the wrong choice now, doesn't mean it wasn't the right choice ...
Opengraph URL: https://github.com/python/cpython/issues/127058
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Tuples should be immutable and safe in C, as well as in Python.","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\n[Apologies if this sounds a bit like a rant. I'm not blaming anyone. Just because something is the wrong choice now, doesn't mean it wasn't the right choice historically]\r\n\r\nTuples are immutable in Python, but we play all sorts of games in C with tuples, filling them will `NULL`s, mutating them and reusing them.\r\n\r\nWe do this in the mistaken belief that it improves performance.\r\nBut it doesn't. It makes the code base more complicated and fragile as we need to work around tuples that misbehave and do strange things. Any local performance gain is overwhelmed by slowdowns caused by the extra complexity in tuple code, the garbage collector and a few other places.\r\n\r\nSo let's fix this.\r\n\r\nWe need to:\r\n* Provide a new C API `PyTuple_MakePair()`. Pairs are by far the most common type of tuple that we play games with. By providing a fast way to create pairs, we can provide an upgrade path for C code that creates tuples in unsafe ways to do so safely and quickly.\r\n* Deprecate `PyTuple_New`. I don't know when we'll be able to remove it, but we should deprecate it ASAP.\r\n* Change `PyTuple_New` to fill the tuple with pointers to `None` instead of `NULL`. This doesn't fix the mutability issue, but it at least means the GC will only see valid objects. (This might break too much code, so we might just have to clearly document that tuples should be fully initialized in one go, before the tuple escapes the function it was created in)\r\n* Fix our own code to not use `PyTuple_New()` or perform tuple shenanigans. We can't reasonably expect third-party package authors to follow the rules if we don't.\r\n\r\n\r\n\r\n\r\n### CPython versions tested on:\r\n\r\nCPython main branch\r\n\r\n### Operating systems tested on:\r\n\r\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-127758\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/markshannon","@type":"Person","name":"markshannon"},"datePublished":"2024-11-20T14:32:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/127058/cpython/issues/127058"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4f41dbdd-0949-cebb-3432-3147543c92ed |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E2BE:2AEA36:289A52A:3576CAA:696B2787 |
| html-safe-nonce | b4c7fdc295ed1c65d9fba8abf676dc53bb8fd0833bf88d7ab390bdc4e0a7a699 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMkJFOjJBRUEzNjoyODlBNTJBOjM1NzZDQUE6Njk2QjI3ODciLCJ2aXNpdG9yX2lkIjoiNzg3NTAyMjM0OTQ1MzE3NDY2MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9cf5d15fd637a029a4f2f22a733d26e4096883cb131c812e575a657edbe86feb |
| hovercard-subject-tag | issue:2676048317 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/127058/issue_layout |
| twitter:image | https://opengraph.githubassets.com/560a107e9a04ea74da8f0e17b4039fec23a8ab1224f9cbad1e22fedfff828e46/python/cpython/issues/127058 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/560a107e9a04ea74da8f0e17b4039fec23a8ab1224f9cbad1e22fedfff828e46/python/cpython/issues/127058 |
| og:image:alt | Bug report Bug description: [Apologies if this sounds a bit like a rant. I'm not blaming anyone. Just because something is the wrong choice now, doesn't mean it wasn't the right choice historically... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | markshannon |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width