Skip to content

fix(lang-python): resolve imports from namespace packages - #775

Merged
avidianity merged 9 commits into
mainfrom
fix/issue-767
Dec 2, 2026
Merged

avidianity merged 9 commits into
mainfrom
fix/issue-767

Conversation

@avidianity

@avidianity avidianity commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

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

  • Resolve from demo import worker to demo/worker.py when demo has no initializer.
  • Resolve grouped and aliased imports across repository and src/ roots.
  • Keep real external dependency findings and unrelated Orphan files.

Fail-first test

  • Test: python_from_namespace_imports_reach_local_children_without_external_findings.
  • Before the change: running 1 test. The trace to demo/worker.py returned paths: [].
  • After the change: both named CLI regressions ran and passed.

Checks

Check Result
Python crate tests 35 passed
Namespace and regular-package CLI regressions 2 passed
Pre-commit and commit-message hooks Passed
Repository codeint check Passed after splitting the resolver by operation
Merged-result check Passed
Standards and Spec reviews PASS on 64bcfebe
Independent reviewer PASS on 64bcfebe. The named regression ran and passed.

Safety proof

  • Safety fact: a missing local target keeps the existing external classification.
  • Proof: the CLI regression reaches both namespace children and reports only requests under Unlisted dependencies.
    The report keeps demo/unused.py (unreferenced) and the three dotted filenames.
  • interrogate: none run at Tier 2.

Runtime evidence

  • Feature maps: check and trace.
  • Baseline 3ad65860: Python printed 42, while codeint check --all reported the child as unreferenced and demo as unlisted.
  • PASS on 64bcfebe: the CLI regression showed direct paths for demo/worker.py, src/demo/extra.py, demo/ns/child.py, src/service/ns/task.py, and cgi/local.py.
    The trace also reaches the root and nested initializers when imported explicitly.
    The Orphan files report retained demo/unused.py and the three dotted filenames as unreferenced. It also kept the paths shadowed by the selected service package unreferenced.
  • The synthetic Git fixture and report files are removed after the test.

Metric version impact

  • Orphan files: a resolved namespace child can become reachable from a Production entry point.
  • Import cycles: a newly resolved child edge can complete a cycle.
  • Import boundaries: a local child can trigger an internal zone rule in place of an external package rule.
  • Unlisted dependencies: a matched namespace import no longer creates a finding for its local name.
  • Unused dependencies: a matching declared dependency can become unused when this was its only apparent external import.
  • Dev dependencies imported in Production: a local child no longer counts as a Production import of a same-named dev dependency.

The combined follow-up will bump affected Metric versions once under ADR 0044.

Gaps

  • Deferred coverage: none within named imports with concrete local child files.
  • Pre-existing failures: none observed.
  • Environmental failures: none observed.

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.
@avidianity avidianity closed this Dec 2, 2026
@avidianity avidianity reopened this Dec 2, 2026
…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.
@avidianity avidianity closed this Dec 2, 2026
@avidianity avidianity reopened this Dec 2, 2026
@github-actions github-actions Bot added the tier-2 Tier 2 from the tier check label Dec 2, 2026
Separate parent traversal, concrete module lookup, and namespace child collection to keep each operation within the repository complexity budget.
@avidianity
avidianity merged commit 3445a9d into main Dec 2, 2026
19 of 20 checks passed
@avidianity
avidianity deleted the fix/issue-767 branch December 2, 2026 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tier-2 Tier 2 from the tier check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python from-import misses local namespace package child modules

1 participant