← Back to Pull requests

Add sys.intern #1439

Open
unknown opened this pull request with 334 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 26, 2026 11:30 UTC
Author

Summary

Add sys.intern(string, /) using Monty’s session string table. Equal strings passed to sys.intern share a string ID with
each other and with compiled literals of the same text.

Monty retains new entries for the lifetime of the session. The existing worker memory budget accounts for the entries.

Tests

The import__sys.py fixture exercises identity for runtime strings and literals, including Unicode text, and checks
CPython’s errors for invalid argument types and call shapes. The type-checking fixture checks the stub’s return type.

All 1,632 fixture cases passed with CPython 3.14.10. The production build check, type-checking suite, dump compatibility
tests, Clippy, and Ruff passed.

  • I have read the contribution guide.

  • I understand and can explain the proposed changes, including any generated with AI assistance.
  • <!-- This is an auto-generated description by cubic. -->
    ---

    Summary by cubic


    Adds sys.intern(string, /) to Monty's production sys module. Equal strings passed to it share identity while the runtime intern stays alive, so repeated calls return the same object.

  • Runtime interns live in a weak index keyed by a private per-heap hash seed and are released when the string dies, including through collected cycles; a literal compiled later keeps its own identity until sys.intern is called on it.

  • Existing compiled literals are reused, short text returns an inline string that can differ in identity from a literal, and allocation is preflighted against the worker memory budget.

  • Raises TypeError matching CPython for non-string arguments, wrong arity, and keyword arguments.

  • Sys module functions are now available in production builds; setrecursionlimit stays behind test-hooks.

  • Updates type stubs, type-checking, runtime allocation and subprocess memory-budget tests, dump-compat lifetime tests, and the sys limitations doc, which now spells out the identity rules and the fixed string and bytes hash seeds behind sys.flags.hash_randomization.
  • <sup>Written for commit 32562ea06a47f7c91301f1eb4539b769af62ec8f. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/pydantic/monty/pull/1439?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    Diff: 334 lines (+250 / -84) across 4 files Reviewer: rewitt94 Review duration: 6358m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.47) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 334 lines diff across 4 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.348
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #1439"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.2% (MEDIUM) · Higher = larger blast radius
    47.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.1% · Safe to merge
    25.1%
    Repository