Repository navigation
Description
graphifyy==0.9.53, Python 3.13, macOS. AST only (--code-only), no LLM, no API key.
Summary
from <pkg> import <submodule> resolves the package to its __init__.py but never resolves the imported name as a submodule when the importing file lives outside the package's directory tree. The imports_from edge to the submodule file is missing, and — because the receiver is never bound to a module node — every downstream submodule.attr() call also loses its calls edge.
There is no dangling edge to notice: the emitted imports_from lands on the package's __init__.py, which is a real node. The graph looks well-formed, so auditing graph.json for dangling endpoints does not surface it.
The same import from a file inside the package tree resolves correctly, so this is positional, not syntactic.
Minimal reproducer (stock 0.9.53, no LLM)
src/towmo/__init__.py (empty)
src/towmo/core/__init__.py (empty)
src/towmo/domains/__init__.py (empty)
src/towmo/core/helper.py
src/towmo/domains/inside_pkg_form.py
tests/test_pkg_form.py
# src/towmo/core/helper.py
def do_work(value):
return value * 2
# src/towmo/domains/inside_pkg_form.py -- INSIDE the package tree
from towmo.core import helper
def run():
return helper.do_work(21)
# tests/test_pkg_form.py -- OUTSIDE the package tree
from towmo.core import helper
def test_it():
assert helper.do_work(21) == 42graphify extract . --code-onlyObserved
Edges emitted, by source file:
src/towmo/domains/inside_pkg_form.py
imports_from -> src_towmo_core_init (core/__init__.py)
imports_from -> src_towmo_core_helper (helper.py) <-- present
calls -> src_towmo_core_helper_do_work (do_work()) <-- present
tests/test_pkg_form.py
imports_from -> src_towmo_core_init (core/__init__.py)
(no edge to helper.py, no calls edge to do_work())
Both targets exist as nodes; nothing is dangling. The outside file simply binds helper to core/__init__.py and stops.
Expected
tests/test_pkg_form.py should emit imports_from -> helper.py and calls -> do_work(), exactly as the inside file does.
The distinguishing variable is the importer's location, not the import form
| importer location | from pkg.helper import do_work |
from pkg import helper + helper.do_work() |
|---|---|---|
| inside the package tree | connected | connected |
outside (sibling tests/) |
connected | no edge |
| flat layout, same directory | connected | connected |
The module-form (from towmo.core.helper import do_work) works from anywhere, presumably because the dotted path maps onto a file-path suffix directly. Only the package-form needs to decide whether the imported name is a submodule or a symbol, and that decision appears to be made relative to the importer's own tree.
Impact on a real repository
Measured on a private ~3,200-file Python/TypeScript monorepo using a src/ layout with tests/ and scripts/ as sibling trees — a very common shape:
| importer location | connected | unconnected |
|---|---|---|
inside src/<pkg>/ |
29 | 0 |
outside (tests/, scripts/) |
2 | 28 |
28 of 59 package-form imports (47%) produce no edge at all. The rule "importer outside the package root ⇒ no edge" predicts 57 of 59 outcomes (97%).
One module in that repo is imported this way by six test files and, as a result, is 100% invisible: its set_verifier_for_testing() node has only self-edges (contains, rationale_for) from its own file, despite six real call sites.
The practical consequence is that graphify affected "<symbol>" silently understates blast radius, and a hand-audit of graph.json cannot detect it because the edges that are emitted look correct. Test files are exactly where you want impact analysis to be complete.
Related but, I believe, distinct
- Python: three independent causes drop
mod.func()calls edges — 177/177 unresolved on a real repo (explains #2428 §3's unexplained 42%) #2447 — same downstream symptom (mod.func()calls dropped), but its Cause A is theimport_statementbranch (import mod) producing a module-name-derived id that matches no node. This report is theimport_from_statementbranch importing a submodule, and the emitted target is a real, existing node (__init__.py) rather than a non-existent id. Its Cause B (imports inside a function body) is also separate — function-local imports resolve fine here. - Cross-module
callsedge is dropped for aliased imports when the modules live in a subdirectory #2943 — aliased imports in a subdirectory; the reproducer above uses no alias. - Relative import of a subpackage emits an abs-path slug imports_from target to a non-existent <pkg>.py #2455 — relative subpackage import emitting an abs-path slug to a non-existent
<pkg>.py; here the import is absolute and the target exists.
Happy to test a patch against the real repo and report the before/after connectivity numbers if that is useful.
Activity