← Back to Pull requests

Share element access for lists and tuples #1411

Closed
unknown closed this pull request without merging on Nov 23, 2026 14:54 UTC
View on GitHub
unknown unknown commented on Nov 23, 2026 10:56 UTC
Author

Summary

List and tuple fast paths now read elements through SequenceItems. The view exposes length, per-item access, and
owned copies so callers can work with compact buffers that construct a Value on demand.

Move bulk insertion, swaps, and GC child traversal into List methods. Host export still copies the list's elements
before recursing because a nested __repr__ can mutate the source list.

This refactor prepares for the storage strategies explored in #1025.

Tests

  • 1,178 Rust tests with memory-model-checks and test-hooks

  • 24 heap-reader compile-fail tests

  • 1,574 Monty and CPython fixture checks with CPython 3.14.10

  • Clippy, formatting, and import checks

  • Five local release benchmarks showed no statistically significant regression against 32bbc255
  • 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


    Encapsulates list, tuple, and namedtuple element access behind a SequenceItems read-only view, moving bulk insertion, swaps, list concatenation, and GC child traversal into List methods in preparation for the storage strategies in #1025.

  • Adds SequenceItems with indexed (map_item, clone_item) and iterator access producing owned Values on demand; callers restrict which heap types the view accepts, with tuple-only lookups (from_tuple) for dict item membership and named-tuple concatenation.

  • Migrates callers from direct slice access and vector mutation to SequenceItems and List methods (extend_owned, swap, for_each_child_id); list.extend, in-place concatenation, starred unpacking, Callable, Decimal, dict item membership, sorted, JSON separators, and package paths reuse owned reads.

  • sorted keeps its periodic deadline check while copying; the CSV writer now copies directive fields through the same guarded loop so a timeout releases their heap references.

  • DictView accepts namedtuples of length two as candidate key/value pairs.

  • Unpacking a named tuple into too few targets now reports the total length, e.g. ValueError: too many values to unpack (expected 1, got 2); CPython omits got 2 for named tuples, so the divergence is documented.

  • Host export still copies list elements before recursing because a nested __repr__ can mutate the source list.

  • Covered by existing Rust, heap-reader, Monty, and CPython fixture tests, plus new tests for list/tuple operands in forward references, namedtuple unpacking and dict-item membership, Decimal with DecimalTuple, csv.writer rows, and a non-sequence import path.
  • <sup>Written for commit 1c5703053726184dc41a308f3874e5318810deb6. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/pydantic/monty/pull/1411?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: 416 lines (+312 / -104) across 5 files Reviewer: davidhewitt Review duration: 238m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 416 lines diff across 5 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.361
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #1411"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 50.0% (MEDIUM) · Higher = larger blast radius
    50.0%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 19.7% · Safe to merge
    19.7%
    Repository