← Back to Pull requests

PEP 649 `__annotate__` #1214

Closed
unknown closed this pull request without merging on Nov 04, 2026 03:31 UTC
View on GitHub
unknown unknown commented on Nov 02, 2026 23:17 UTC
Author

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

Summary by cubic


Implements PEP 649 lazy annotations, replacing stringized annotation storage with compiled __annotate__(format) functions evaluated on access, reported as __annotate__ in tracebacks whatever a class body binds them as, matching CPython 3.14. f.__annotations__/__annotate__ recompute per access; a class's annotations dict is cached on first read.

  • typing generic forms (List[int], ClassVar[int], Callable[[int], str], …) are now subscriptable, building GenericAlias values with CPython's repr and argument checks; Callable[[a, b], r] stores (a, b, r) so get_type_hints resolves forward references inside the list. Non-dunder attribute calls on an alias route to the origin's own lookup, reaching host classes; an unknown attribute raises with the bare name for any special-form origin (ClassVar, Final, Literal, Annotated), and with the collections.abc class name for the ABC-based forms.

  • get_annotations/get_type_hints implement the annotationlib VALUE/FORWARDREF/STRING format fallbacks and strip Annotated unless include_extras; FORWARDREF raises NameError instead of asking the host, and a class is cached only on that success. A non-dict FORWARDREF/STRING result raises CPython's ValueError, while T.__annotations__ keeps the TypeError. get_type_hints treats Literal aliases as leaves, so their string values aren't resolved as forward references.

  • Literal deduplicates and flattens its values by type and hash, comparing and hashing them as a set.

  • typing subscripts and C.__annotations__ preflight their argument and namespace copies (a flattened Annotated as one combined buffer, the fresh annotations dict guarded across its cache insertion), so a large one raises MemoryError instead of hitting the allocator's hard ceiling.

  • getattr()/hasattr() run __annotations__ synchronously, so an annotation's AttributeError yields the default or False; C.__annotations__ = d replaces one the namespace bound.

  • dataclasses reads evaluated annotations at decoration; Field.type holds the value instead of annotation text.

  • Under from __future__ import annotations, annotation dicts hold strings as before, now covered by class__annotations_future.py.
  • <sup>Written for commit 5e19abb8f2efd1555678622635e0b418a9d09b01. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/pydantic/monty/pull/1214?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> <a href="https://www.cubic.dev/action/auto-fix/pr/pydantic/monty/1214?returnTo=https%3A%2F%2Fgithub.com%2Fpydantic%2Fmonty%2Fpull%2F1214&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>

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

    Diff: 441 lines (+330 / -111) across 5 files Reviewer: samuelcolvin Review duration: 1694m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.50) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 441 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%
    56%
    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.364
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #1214"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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.3% (MEDIUM) · Higher = larger blast radius
    50.3%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 21.8% · Safe to merge
    21.8%
    Repository