Skip to content

feat(parser): Python module-aware import resolution#1

Merged
sdsrss merged 1 commit intomainfrom
feat/python-import-resolution
Mar 16, 2026
Merged

feat(parser): Python module-aware import resolution#1
sdsrss merged 1 commit intomainfrom
feat/python-import-resolution

Conversation

@sdsrss
Copy link
Copy Markdown
Owner

@sdsrss sdsrss commented Mar 16, 2026

Summary

  • A. import X resolution: Resolves module-level imports (import myutils) to the target file's <module> node via dotted-path-to-file-path mapping
  • B. from X import Y constraint: Constrains symbol lookup to the resolved module's file, eliminating false positives from same-named symbols in other files
  • C. External import tracking: Creates virtual external_module nodes under an <external> pseudo-file for unresolved imports (os, flask, etc.), making them visible in dependency_graph

Test plan

  • test_build_python_module_map — module path mapping (incl. __init__.py, suffix matching)
  • test_python_from_import_resolutionfrom myapp.utils import helper cross-file edge
  • test_python_import_module_resolutionimport myutils module-level edge
  • test_python_external_import_creates_virtual_nodes — external imports create <external> nodes
  • test_python_mixed_internal_external_imports — mixed internal + external in one file
  • All 177 tests pass (143 unit + 20 integration + 8 parser + 6 plugin)

🤖 Generated with Claude Code

Python dependency detection was broken because imports were resolved by
global name lookup only, causing three failures: `import X` never matched
module nodes, `from X import Y` had false positives from same-named
symbols in other files, and external package imports were silently dropped.

Fix by adding module path metadata to Python import relations, then using
file-path-constrained resolution in the indexer. External imports now
create virtual nodes under an `<external>` pseudo-file so dependency_graph
can report them.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sdsrss sdsrss merged commit 2b260f5 into main Mar 16, 2026
1 check passed
@sdsrss sdsrss deleted the feat/python-import-resolution branch March 16, 2026 15:28
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.

1 participant