You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(graph): resolve from package import submodule to the real submodule file
While verifying ADR-0018's function-to-file relation fix against the real
billing fixture, found that `billing/tax.py` (which does `from billing
import tax_rates` and genuinely reads `tax_rates.REGION_RATES`) was
recorded in the graph as importing only `billing/__init__.py`, never
`billing/tax_rates.py`. Root cause in `graph/ingest.py`'s
`visit_ImportFrom`: only the bare package name reached `_add_import`,
never the imported names themselves. Python's grammar cannot distinguish
"importing a submodule via its package" from "importing a plain symbol
defined in the package's __init__.py" -- both are
`ImportFrom(module="billing", names=["tax_rates"])`. Only a post-walk
check of whether `billing.tax_rates` corresponds to a real first-party
file can tell them apart, and `_resolve` already does exactly this kind of
lookup for other edge kinds -- it just was never given the candidate to
try.
Fix: `visit_ImportFrom` now records one IMPORTS edge per imported name
(matching plain `import a, b`'s existing per-alias granularity), each
carrying the qualified candidate (`module.name`) in its metadata.
`_resolve` tries that candidate first -- if it's a real first-party file,
that IS what Python binds at runtime, not a guess -- falling back to the
bare package (the `__init__.py`-symbol case) exactly as before when it
isn't.
This changed the correct answer to ADR-0018's own demonstration probe:
`apply_tax` calls `billing/tax_rates.py` now reports SUPPORTED, because
the import genuinely exists -- the CONTRADICTED verdict reported moments
earlier (in the immediately preceding commit) was itself an artifact of
this ingester bug, not the true answer. A second probe against a file
`apply_tax`'s module never imports still correctly reports CONTRADICTED,
confirming the mechanism works once the underlying import graph is
accurate. README.md, BENCHMARK_PROTOCOL.md and ADR-0018 updated to reflect
the corrected sequence rather than leaving a now-stale claim standing.
2 new regression tests in test_graph_ingest.py (submodule-import case;
plain __init__.py-symbol case confirming no regression). No test in the
suite asserted an exact import-edge count, so the per-name edge
granularity change is safe.
520 tests passing (518 + 2 new).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
0 commit comments