Skip to content

gh-144161: Clarify immortality of interned strings - #159701

Open
bearomorphism wants to merge 1 commit into
python:mainfrom
bearomorphism:gh-144161-interned-string-docs
Open

bearomorphism wants to merge 1 commit into
python:mainfrom
bearomorphism:gh-144161-interned-string-docs

Conversation

@bearomorphism

@bearomorphism bearomorphism commented Oct 19, 2026 •

Copy link
Copy Markdown

Closes #144161.

The sys.intern() and PyUnicode_InternInPlace() documentation currently says that interned strings are not immortal, while the free-threading HOWTO says that they are. Clarify that interned strings are not necessarily immortal and that the current free-threaded build makes all interned strings immortal.

Keep the advice to retain a reference to the result, and describe free-threaded immortality as an implementation detail that may change. Also clarify that the HOWTO describes additional immortalization relative to the default build, rather than implying immortality is exclusive to free-threaded Python.

This follows the discussion and earlier work in #144176, whose author explicitly invited others to pick it up. Credit to Hernani Samuel Diniz for that patch. The new wording incorporates the review feedback and uses the current free-threaded build glossary term.

Validation

  • make -C Doc html JOBS=4 passed with warnings treated as errors; inspected the rendered sections and links.
  • pre-commit run --files Doc/library/sys.rst Doc/c-api/unicode.rst Doc/howto/free-threading-python.rst passed all applicable hooks.
  • git diff --check passed before committing.
  • Checked interning behavior with regular CPython 3.14.2 and free-threaded CPython 3.14.2, including the latter with -X gil=1. A dynamically created interned string was mortal in the regular build and immortal in the free-threaded build; the interned empty string was immortal in both.
  • Checked the corresponding implementation in this checkout. These runtime checks used released interpreters, not a build of the development checkout.

Documentation only; no runtime changes or NEWS entry.

AI assistance was used to investigate the behavior, draft the documentation, and run validation.

Co-authored-by: Hernani Samuel Diniz [email protected]

Clarify build-dependent interning behavior in the Python and C APIs and the free-threading HOWTO. Follow the discussion and earlier work in pythongh-144176 while retaining the advice to keep a reference to the result.

Co-authored-by: Hernani Samuel Diniz <[email protected]>
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35238385 | 📁 Comparing b758414 against main (036d309)

  🔍 Preview build  

3 files changed
± c-api/unicode.html
± howto/free-threading-python.html
± library/sys.html

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

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Inconsistent documentation: are interned strings immortal or not?

1 participant