Support `from m import *` #1314
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 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.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1314"
general
weight: 0.35
davidhewitt
from m importused to be rejected at parse time. It now bindsm.__all__, or every name ofmnot starting with_, for bundled, host and file modules, at module level, in REPL feeds and inexec()snippets.In a function or class body it raises CPython's
SyntaxError: import only allowed at module level.How it works
The names are only known at runtime, so the compiler emits a loop driven by one new opcode,
ImportStar, with au8mode:LOADis separate fromBINDso a property such asos.environcan suspend for the host and resume.BINDstores into the frame's locals dict, its globals dict, or a module global slot.A slot-global binding interns the name at runtime and appends a slot, as
exec()already does, so later feeds,exec()snippets and functions see it.from math importmakespowreturn afloat).__all__is read as CPython reads it, by index from 0 untilIndexError, so any sequence works (range,deque,Counter, a class with__getitem__).Mappings and other values raise
PySequence_GetItem'sTypeError; that check is now shared withbisect.__name__in its namespace.This also fixes the general
module 'x' has no attribute 'y'error for a file module that rebinds__name__.__all__now have one: their public names, lessbase64'sMAXBINSIZEandMAXLINESIZE.To set it in one place, each module's
create_modulenow returns itsModuleandStandardLib::createallocates it.No
heap/changes and nounsafe.The opcode fingerprint in
dump_format.rsis updated without aDUMP_VERSIONbump, following #1173.Dumps from before this change load as before: their modules simply have no
__all__.Other changes
ParseError::NotSupportedis removed; the wildcard rejection was its only user.repl_rejected_snippet_locationsusedfrom math importas its rejected snippet; it now usestype Alias = int.mount-fs, so file-module error cases can run on CPython.Remaining differences
Documented under "Star imports" in
limitations/modules.md:__all__lists only what Monty implements, in Monty's order, and is always alist.__all__is read in full before the first name is bound; this shows only through a__getitem__with side effects, or when an earlier binding fails.SyntaxError.Tests
import__star.py(replacesimport__star_error.py),import__star_host.py,import__star_bundled.py, and three traceback cases.repl_star_import_binds_names_for_later_feedschecks names bound in one feed are visible in the next, across a dump round trip.make test-cases(1518 passed), theimport__cases undermemory-model-checksandref-count-return,make lint-rs,make lint-py, mdformat.cargo nextest run -p monty -p monty-type-checking -p monty-typespassed (1236) before the bundled__all__change; it was not re-run after it.Follow-ups
statcan drop0002-stat-no-accelerator.patch.The candidate scan shows
bisectandstatnow load from CPython's source;posixpath,pathlibandtypesmove on to other blockers.__name__.exceptreports theexceptbody's line instead of the raising line.<!-- This is an auto-generated description by cubic. -->
---
Summary by cubic
from m importused to be rejected at parse time; it now bindsm.__all__, or every name ofmnot starting with_, for bundled, host, and file modules, at module level, in REPL feeds, and inexec()snippets. In a function or class body it raises CPython'sSyntaxError: import only allowed at module level.Notable changes
powafterfrom math import *).__all__now have one, listing only the names Monty implements.__name__, which also fixes the message for file modules that rebind it.exec()snippets see them.__all__is subject to the feed's time limit and growth checks, so an endless__all__times out.__all__.docs/limitations/modules.md.<sup>Written for commit 30f8448a167894b07e1dfc84e928e8adaf0fdb7f. Summary will update on new commits.</sup>
<a href="https://cubic.dev/pr/pydantic/monty/pull/1314?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. -->