Repository navigation
fix(lang-python): resolve imports from namespace packages - #775
Merged
Merged
Conversation
Look up each named child on the existing import roots when the namespace has no initializer. Classify matched children as local and keep the existing fallback for external packages. Closes #767
Search the existing import roots using the actual path components so a dotted filename cannot shadow a valid child or impersonate an external module.
Use real import-root paths for the named import source before looking up any child. A dotted filename cannot stand in for a namespace parent.
Walk named import components in search order. Restrict later lookups to a selected regular package, and retain possible children across the remaining namespace roots.
…llback The standard-library name table spans Python versions and platforms. Keep a real namespace child reachable even when the table contains the same package name.
Separate parent traversal, concrete module lookup, and namespace child collection to keep each operation within the repository complexity budget.
This was referenced Dec 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolve named child modules of Python namespace packages on supported import roots.
A matching child adds a local edge and clears the false external package classification.
Closes #767
Tier
Tier 2 from
cargo xtask risk-tier --base origin/main.The Python resolver and CLI regression paths use the default tier.
Task
from demo import workertodemo/worker.pywhendemohas no initializer.src/roots.Fail-first test
python_from_namespace_imports_reach_local_children_without_external_findings.running 1 test. The trace todemo/worker.pyreturnedpaths: [].Checks
64bcfebe64bcfebe. The named regression ran and passed.Safety proof
requestsunder Unlisted dependencies.The report keeps
demo/unused.py (unreferenced)and the three dotted filenames.interrogate: none run at Tier 2.Runtime evidence
3ad65860: Python printed42, whilecodeint check --allreported the child as unreferenced anddemoas unlisted.64bcfebe: the CLI regression showed direct paths fordemo/worker.py,src/demo/extra.py,demo/ns/child.py,src/service/ns/task.py, andcgi/local.py.The trace also reaches the root and nested initializers when imported explicitly.
The Orphan files report retained
demo/unused.pyand the three dotted filenames as unreferenced. It also kept the paths shadowed by the selectedservicepackage unreferenced.Metric version impact
The combined follow-up will bump affected Metric versions once under ADR 0044.
Gaps