Report no parent module for relative imports that climb past the top level #22540
All Vouch review confidence checks passed
Residual risk 0.26 = 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 · 416 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 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.361
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #22540"
general
weight: 0.35
chrikrah
Fixes #22539
A relative import that climbs past the top-level package and names a module after the dots (for example
from ..foo import barinpkg/mod.py) made mypy report a missing module named".foo". With this change it reportsNo parent module -- cannot perform relative import, the same error mypy already gives forfrom .. import foo.What changed
Two files:
mypy/build.py,State.correct_rel_imp(one line). When the import climbs past the top,file_idis stripped to"", and the old joinfile_id + "." + imp.idbuilt".foo". That string is not empty, so theif not new_idcheck right below it never reported the error. The name is now joined only whenfile_idis not empty, sonew_idstays""and the existing check reports it. Valid relative imports are unchanged, because theirfile_idis never empty.test-data/unit/semanal-errors.test: three new cases next totestRelativeImportAtTopLevelModule2: top-levelfrom .m import x, top-levelfrom ..m import x, andfrom ..m import xinsidepkg/mod.py. Each has a realm.py, so the module is not actually missing.I left
correct_relative_importinmypy/util.pyas it is. It has the same join, but after this change the blocker error stops checking before semanal reaches it. I asked on the issue whether you want it changed too, and can add that here if so.Before and after
Issue layout (top-level
foo.py,pkg/__init__.py), master at 1572a1884, Windows, Python 3.12.10:Before:
After:
The other two forms from the issue (
from .foo import barin a top-level file andfrom ...foo import barinpkg/sub/mod.py) change the same way. A validfrom ..foo import barinpkg/sub/ok.pystill resolves topkg.foo.Tests
The three new cases fail on master (
module named ".m") and pass with the change:I did not run the full suite locally; CI will.
AI use
I used Claude Code (claude opus 5.5) for this PR. It wrote the one-line change and the three test cases. I read the change and the tests, checked the before and after output myself.