Skip to content

Expose sys._is_interned and order interned-state publication - #9430

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:youknowdot/sys-interned-state-315-20261028
Oct 28, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:youknowdot/sys-interned-state-315-20261028

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Expose sys._is_interned() using the object's existing interned flag. The query does not intern its argument or mistake equal content (or immortality) for interning. It accepts string subclasses without coercion and takes one positional-only argument.
  • Mark a newly inserted string as interned before releasing the string-pool write lock. Previously, another lookup could return the published entry before its interned flag was set. Only the successful insertion is marked; an equal-but-distinct losing input remains uninterned.

The predicate follows CPython’s direct intern-state query; the pool-ordering change closes a RustPython-specific publication window.

This supplies a real prerequisite for the canonical Python 3.15 free-threading string tests, rather than adding a test-only helper or skip. Those tests are not included here: their package is tracked separately in #9428. No Lib modifications or xfail changes.

Validation

  • Independently reviewed flag semantics, publication ordering, positional argument binding, and existing interner ownership/refcount behavior.
  • Focused cargo check and strict cargo clippy -- -D warnings passed with --no-default-features --features threading,stdlib,stdio,importlib,host_env,doc,ucd_3_2_0; bounded executable build passed.
  • Existing canonical test.test_sys.SysModuleTest.test_intern: 1 passed.
  • 18 bounded functional checks matched CPython 3.15 for identity, non-mutating queries, equal-but-distinct strings, subclasses, wrong types/arity, keywords, and Unicode/surrogates.
  • Applicable hooks and git diff --check passed.

Generic argument-error wording still differs from CPython for missing/extra positional arguments and bytes/None inputs; the error types and rejection behavior match. No concurrent stress test or full workspace test run was performed, so these results do not prove general free-threading compatibility.

Build/runtime provenance and the immutable-source comparison were checked against a protected executable copy; runtime checks used disposable HOME/cwd and bounded time/memory. The existing test module's helper performs a finite loopback IPv6 capability probe; no external network connection was made.

Summary by CodeRabbit

  • New Features
    • Added sys._is_interned(string) to check whether a string is interned.
  • Bug Fixes
    • Improved consistency when strings are added to the intern pool.

Query the existing object flag without interning or content lookup. Mark only a successful pool insertion before releasing its write lock so a concurrent lookup cannot return the entry before its flag is set.

Assisted-by: OpenAI Codex: model version unavailable
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 5454614 and 6586b06.

Files selected for processing: 2
  • crates/vm/src/intern.rs
  • crates/vm/src/stdlib/sys.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

The string pool now marks inserted strings as interned before releasing its write lock. The sys module adds sys._is_interned(string) to report whether a string object is interned.

Changes: Interned string state

Layer / File(s) Summary
Interned-state update and query
crates/vm/src/intern.rs, crates/vm/src/stdlib/sys.rs
The pool marks inserted strings as interned before releasing its write lock. The sys module adds sys._is_interned(string) to return a string object's interned state.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Feature

Possibly related issues

Possibly related PRs

Suggested reviewers: youknowone

Merge Risk: Minimal · up to 6586b

The publication ordering and read-only query show no actionable merge-blocking issue. The change appears ready to merge subject to normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title accurately summarizes both main changes: exposing sys._is_interned and ordering interned-state publication while holding the pool write lock.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@youknowone
youknowone marked this pull request as ready for review October 28, 2026 13:01
@youknowone
youknowone enabled auto-merge (squash) October 28, 2026 13:01
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-28T13:02:26.366400Z
We couldn’t complete this review. Comment @codex review to try again.
6586b06 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@youknowone
youknowone merged commit dd32b70 into RustPython:main Oct 28, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants