Skip to content

feat: resolve namespace package submodule imports#32

Open
TristanKruse wants to merge 1 commit into
mainfrom
codex/namespace-package-imports
Open

feat: resolve namespace package submodule imports#32
TristanKruse wants to merge 1 commit into
mainfrom
codex/namespace-package-imports

Conversation

@TristanKruse

Copy link
Copy Markdown
Collaborator

Pull Request

Adds support for resolving submodule imports from namespace packages that do not contain __init__.py files.

Previously, imports like from namespace_pkg.domain import model could be treated as external when namespace_pkg/domain/ was a namespace package directory. This change adds a targeted fallback that resolves imported aliases as submodules only when the base import cannot be resolved internally.

Also adds regression tests for absolute and relative namespace-package imports and documents the behavior in the README.

Change Type

  • Bug fix
  • Feature
  • Documentation
  • Refactoring

@TristanKruse

Copy link
Copy Markdown
Collaborator Author

Validation:

  • pytest --tb=short -q: 267 passed
  • mypy src\archunitpython\ --ignore-missing-imports: passed
  • ruff check src\archunitpython\common\extraction\extract_graph.py tests\common\test_extract_graph.py: passed
  • git diff --check: passed

Note: full ruff check src tests still reports existing baseline cleanup issues, which are handled separately in #31.

@lukasniessen-bain

Copy link
Copy Markdown
Collaborator

Thanks for the focused change. I found one issue I’d fix before merging.

_resolve_import_targets currently returns only the successfully resolved internal alias targets once any alias resolves. That means a statement like from namespace_pkg.domain import model, remote_model will drop the external/unresolved side if model resolves to namespace_pkg/domain/model.py but remote_model does not resolve internally.

Because this is the core graph extractor, that can hide dependency edges in mixed alias imports. Please preserve an external edge for unresolved aliases, or preserve the original external base edge when not every alias resolves internally, and add a regression test for that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants