Title: Interned strings are immortal, despite what the documentation says · Issue #113993 · python/cpython · GitHub
Open Graph Title: Interned strings are immortal, despite what the documentation says · Issue #113993 · python/cpython
X Title: Interned strings are immortal, despite what the documentation says · Issue #113993 · python/cpython
Description: Bug report Bug description: The sys.intern documentation explicitly says: Interned strings are not immortal; you must keep a reference to the return value of intern() around to benefit from it. However, they were made immortal in #19474 ...
Open Graph Description: Bug report Bug description: The sys.intern documentation explicitly says: Interned strings are not immortal; you must keep a reference to the return value of intern() around to benefit from it. How...
X Description: Bug report Bug description: The sys.intern documentation explicitly says: Interned strings are not immortal; you must keep a reference to the return value of intern() around to benefit from it. How...
Opengraph URL: https://github.com/python/cpython/issues/113993
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Interned strings are immortal, despite what the documentation says","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nThe [`sys.intern` documentation](https://docs.python.org/3.13/library/sys.html#sys.intern) explicitly says:\r\n\r\n\u003e Interned strings are not [immortal](https://docs.python.org/3.13/glossary.html#term-immortal); you must keep a reference to the return value of [`intern()`](https://docs.python.org/3.13/library/sys.html#sys.intern) around to benefit from it.\r\n\r\nHowever, they were made immortal in https://github.com/python/cpython/pull/19474 (Implement Immortal Objects -- implementation of PEP 683), without a documentation update. The 3.12 What's New also doesn't mention the change. [edit: it's now clear that the PR author (@eduardo-elizondo) intended it but the reviewer (@markshannon) did not]\r\nPEP-683 itself only mentions the change as a possible optimization.\r\n\r\nMeanwhile, `pathlib` [interns every path segment it processes](https://github.com/python/cpython/blob/79970792fd2c70f77c38e08c7b3a9daf6a11bde1/Lib/pathlib/__init__.py#L257), presumably depending on the documented behaviour. In CPython's test suite, that causes names of temporary directories to leak (stealthily, since interned strings are excluded from the total refcount).\r\n[edit: Worse, `type_setattro`, `PyObject_SetAttr` or `PyDict_SetItemString` immortalize keys, so strings used for key/attribute names this way are not reclaimed until interpreter shutdown.]\r\nOn the other hand, free-threading (PEP-703) ~~seems to rely~~ [edit: relies] on these being immortal.\r\n\r\nWhat's the correct behaviour? [edit: specifically, in 3.12 and non-free-threading 3.13, should this change be reverted or documented?]\r\n\r\n@eduardo-elizondo @ericsnowcurrently\r\n\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-120520\r\n* gh-120945\r\n* gh-121358\r\n* gh-121364\r\n* gh-121851\r\n* gh-121854\r\n* gh-123065\n* gh-124938\n* gh-127250\n\u003c!-- /gh-linked-prs --\u003e\r\n\r\nRelated fixes:\r\n- https://github.com/python/cpython/pull/121903\r\n- https://github.com/python/cpython/pull/122303\r\n- https://github.com/python/cpython/pull/122421","author":{"url":"https://github.com/encukou","@type":"Person","name":"encukou"},"datePublished":"2024-01-12T16:49:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":37},"url":"https://github.com/113993/cpython/issues/113993"}
| 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:067b7dcf-15d0-6fde-3f80-d9945d2dc5f0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9F68:21E6C4:42247B:5C6941:696A213E |
| html-safe-nonce | 9a9c5437427eb08ff61bc1b4ed1c8017ae8ca6b94251d2d4ca103452032f2a97 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjY4OjIxRTZDNDo0MjI0N0I6NUM2OTQxOjY5NkEyMTNFIiwidmlzaXRvcl9pZCI6IjcwMzM0NDM4MTAxMTIzMTU3MTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9ea37b94ff91c2c9d3d4439d2c2b2237f742896358960d0c7b128722e2a0faca |
| hovercard-subject-tag | issue:2079272299 |
| 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/113993/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0f13f20e7322b8e7eee66231ccd0759add4e89b09a620db709772bf04bb40c17/python/cpython/issues/113993 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0f13f20e7322b8e7eee66231ccd0759add4e89b09a620db709772bf04bb40c17/python/cpython/issues/113993 |
| og:image:alt | Bug report Bug description: The sys.intern documentation explicitly says: Interned strings are not immortal; you must keep a reference to the return value of intern() around to benefit from it. How... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | encukou |
| hostname | github.com |
| expected-hostname | github.com |
| None | 014f3d193f36b7d393f88ca22d06fbacd370800b40a547c1ea67291e02dc8ea3 |
| 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 | d515f6f09fa57a93bf90355cb894eb84ca4f458f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width