Skip to content

Package-form imports (from package import module) are not resolved to import edges — creates disconnected test-file islands #1146

Closed

Description

@janreview

Version: graphifyy 0.8.32 (pip, Windows, Python 3.12)

What happened
The AST extractor resolves from src.services.ai_blog_enricher import X to an import edge, but NOT the package-form from src.services import ai_blog_enricher. Files using the package form get zero edges to the module they import.

Example (measured)

# tests/test_ai_blog_enricher.py line 7
from src.services import ai_blog_enricher

Result: the test file's 141 nodes form a fully disconnected component with 0 edges to src/services/ai_blog_enricher.py (60 nodes) — despite the test calling ai_blog_enricher.analyze_article(...) etc. throughout.

Impact
On a ~6,000-node graph of a Python repo: 76 connected components; 799 nodes outside the giant component, of which 524 (66%) were test files using this import style (from src.services import X is a common pattern for tests that monkeypatch module attributes). GRAPH_REPORT.md then flags them as "possible documentation gaps or missing edges", which sends users hunting for gaps that are actually extractor blind spots.

Suggested fix
When resolving from <pkg> import <name>, check whether <pkg>/<name>.py (or <pkg>/<name>/__init__.py) exists in the corpus and emit the same import edge as for the dotted form.

Activity

  1. safishamsi commented on Jun 6, 2026

    @safishamsi
    Member

    Fixed in v0.8.33 (a380b34).

    from pkg import submod now resolves to a file-level imports_from edge when pkg/submod.py or pkg/submod/__init__.py exists on disk. The fix lives in _collect_python_symbol_resolution_facts — when the resolved target is a package (__init__.py), each imported name is checked as a potential submodule file. Matched submodules are stored in a new module_imports field and emitted as imports_from edges in _apply_symbol_resolution_facts using canonical stem-based IDs.

    Upgrade: uv tool upgrade graphifyy

  2. janreview commented on Jun 6, 2026

    @janreview
    Author

    Confirmed fixed in v0.8.33 on the same repo that produced the report: components 76->61, nodes outside the giant component 799->339 (the remainder are genuinely standalone archive/scripts), and the 141-node test island now has its imports_from edge to the service. The builtin uses@0.5 edges from #1147 are gone too (0 remaining; str dropped out of the god-node top-10). Thanks for the fast turnaround!

  3. safishamsi commented on Jun 6, 2026

    @safishamsi
    Member

    Haha always fun working on weekends

  4. janreview commented on Jun 6, 2026

    @janreview
    Author

    Yes, always good fun on weekends ;)

  5. added a commit that references this issue on Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions