← Back to Pull requests

Add str.format_map(mapping, /) #1482

Open
unknown opened this pull request with 276 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 30, 2026 02:33 UTC
Author

Implements str.format_map(mapping, /) on str.

  • Extends FormatArguments in crates/monty/src/str_format.rs with a Mapping(Value) variant so str.format_map() reuses the existing PEP 3101 format string parser, conversions, nested format specs, attribute/item accesses, and resource-limit checks while delegating named root field lookups directly to mapping.py_getitem(key, vm).

  • Supports dict, collections.defaultdict, collections.Counter, and user-defined mappings implementing __getitem__.

  • Rejects positional fields ({}, {0}, etc.) with ValueError: Format string contains positional fields and validates the single positional-only mapping argument.

  • Updates docs/limitations/format.md.
  • Part of #1275 and #1319.

    <!-- This is an auto-generated description by cubic. -->
    ---

    Summary by cubic


    Implements str.format_map(mapping, /), which previously raised AttributeError. It reuses the existing PEP 3101 format string parser from str.format(), so conversions, nested format specs, attribute/item access, and resource-limit checks all work identically, but named root field lookups delegate to mapping.__getitem__.

  • Supports dict, defaultdict, Counter, and any user-defined mapping with __getitem__.

  • Positional fields ({}, {0}) raise ValueError: Format string contains positional fields, matching CPython.

  • The mapping argument is positional-only and validated to accept exactly one argument with no kwargs.

  • Updates docs/limitations/format.md and adds a test case file.
  • Part of #1275 and #1319.

    <sup>Written for commit 807982c043a57c82b37ef45a83256dc2e852505b. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/pydantic/monty/pull/1482?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: 276 lines (+207 / -69) across 3 files Reviewer: jaheba Review duration: 2370m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.45) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 276 lines diff across 3 files
    0.45
    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%
    42%
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.336
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #1482"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% 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: 44.6% (MEDIUM) · Higher = larger blast radius
    44.6%
    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: 43.0% · Lower = rushed or shallow review
    43.0%
    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.4% · Safe to merge
    25.4%
    Repository