Add `annotationlib`, `get_type_hints` formats and PEP 563 handling #1194
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.53) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.53 · 518 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.374
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #1194"
general
weight: 0.35
samuelcolvin
from __future__ import annotationsis recorded on the functions and classes that follow it, soget_type_hints()evaluates their annotations as PEP 563 strings in the given namespaces only.typing.get_type_hints(format=)acceptsVALUE,FORWARDREFandSTRING.FORWARDREFloads an unresolved name as aForwardRefstringifier that composes source text for every operation, as CPython's annotationlib does;STRINGreturns the stored text.annotationlibmodule:Format,ForwardRef(a native type, alsotyping.ForwardRef) andget_annotations(), with a narrowed type stub.limitations/typing.mdandlimitations/annotationlib.md.Claude-Session: https://claude.ai/code/session_018zfZ5wGot8GsLjx4cowPZx
<!-- This is an auto-generated description by cubic. -->
---
Summary by cubic
Adds PEP 563 handling, a new
annotationlibmodule, and format support fortyping.get_type_hints().from __future__ import annotationswas previously accepted as a no-op; the flag is now stamped on each compiledCode, inherited byexec()/eval()calls (including a global bound toexec), and persisted across REPL feeds, soget_type_hints()evaluates those annotations as PEP 563 strings in the given namespaces only. A__future__import after any other statement is now aSyntaxError, as in CPython.typing.get_type_hints(format=)now acceptsVALUE,FORWARDREF, andSTRING.FORWARDREFreturns an unresolved name as aForwardRefstringifier that composes source text for every operation, matching CPython's annotationlib;STRINGreturns the stored text. The newannotationlibmodule providesFormat,ForwardRef(alsotyping.ForwardRef), andget_annotations(), with a narrowed type stub.Behavior changes
type.__build_class__builtin that carries the PEP 563 flag; a plaintype()call doesn't, and its hand-built namespaces treat string annotations as forward references.FORWARDREFevaluation created compose source text; aForwardRefbuilt by code an annotation calls behaves normally.ForwardRef.evaluate()requires dict orNoneglobals/localsforVALUEandFORWARDREF;STRINGreturns the text before the namespaces are validated. It honorsmodule=by selecting that module's namespace (file module, bundled module, or__main__), and resolves a composed reference against the globals it was built in.Documentation
limitations/typing.mdandlimitations/annotationlib.md.<sup>Written for commit 985a117cd5c0a25d03336397b526bb386aafddac. Summary will update on new commits.</sup>
<a href="https://cubic.dev/pr/pydantic/monty/pull/1194?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/1194?returnTo=https%3A%2F%2Fgithub.com%2Fpydantic%2Fmonty%2Fpull%2F1194&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. -->