Repository navigation
Description
Two Python call-resolution defects, found while indexing a 602-file polyglot monorepo with v0.9.56. They are separate bugs but share a root cause: call targets appear to be matched on bare name against a global symbol table, without consulting the importing module's namespace or the enclosing lexical scope.
The second is the more serious. It produces wrong edges labelled EXTRACTED with confidence_score: 1.0, which is worse than a missing edge, because nothing downstream can distinguish it from a real one.
Corpus: 602 code files → 3477 nodes, 6221 edges. graphify extract . --code-only (no LLM), Python 3.14, Windows. Paths below are anonymised; the shapes are verbatim.
1. import module + module.func() calls are never resolved
from mod import func → func() resolves correctly. import mod → mod.func() produces no edge at all.
# pkg_a/collect.py
def q(conn, sql): ... # returns tuples
def qd(conn, sql): ... # returns dicts
# pkg_a/store.py
import collect
rows = collect.qd(conn, sql) # line 119
# pkg_a/waker.py
import collect
rows = collect.q(conn, SIGNALS_SQL) # line 103graphify explain on qd() reports degree 2 — its contains edge and a docstring rationale_for edge. The call from store.py is absent. q() shows only its one same-file caller and misses both cross-module ones.
This is not a general cross-file failure: 331 of 2476 calls edges (13%) are cross-file and correct. The split is exactly import style. In this corpus one package uses from x import y throughout and its call graph is good; a second uses import x + x.y() and its cross-module edges are essentially all missing.
Why it is easy to miss: "what calls this?" is the question the graph exists to answer, and a package where resolution fails returns nothing rather than an error. A function with no callers looks like a leaf, not like a gap.
2. Nested functions resolve to same-named module-level functions in unrelated files
This one manufactures edges that do not exist.
# pkg_b/probe.py
def trace(...):
def walk(n, d=0): # line 53 — nested, local to trace()
...
walk(root)There is exactly one module-level walk in the corpus, in an unrelated tree:
# pkg_c/overlay.py
def walk(node, path=""): # line 74GRAPH_REPORT.md promotes the collision into the "Surprising Connections (you probably didn't know these)" section:
- `trace()` --calls--> `walk()` [INFERRED]
pkg_b/probe.py → pkg_c/overlay.py
The two files share no import, no package and no call path. The nested walk shadows everything else; the local definition should win unconditionally.
A second entry in the same section is worse, because it is not even marked inferred:
- `parse_date()` --references--> `_date()` [EXTRACTED]
pkg_d/deadlines.py → pkg_b/grid.py
pkg_d/deadlines.py imports only stdlib, requests, and one local config module. _date is defined only in pkg_b/grid.py. There is no relationship of any kind. The edge carries confidence: EXTRACTED, confidence_score: 1.0.
Of the five entries in "Surprising Connections" on this corpus, we could not verify a single one as real. Because that section is framed as insight rather than as a guess, name collisions in a polyglot monorepo surface there as confident discoveries — and short generic names (walk, main, trace, diff, esc, _date) are exactly the ones that collide.
Suggested fixes
- Resolve
module.attr()through the import table. Theimportsedges are already correct and 100% cross-file, so the alias→module binding is present — it just is not consulted when resolving a dotted call. - Scope-check before falling back to global name matching. If a name is bound by a
def/lambda/assignment in an enclosing scope, resolve there and stop. - Never emit a cross-file edge as
EXTRACTED/ 1.0 on a bare name match alone. If resolution came from a global name table with no import path connecting the two files, it is by definition inferred, and low confidence. Gating "Surprising Connections" on the existence of an import path between the two files would have removed all five false positives here.
Reproduces every time on this corpus; happy to test a patch.
Activity
rohit-jsfreaky commentedon Sep 16, 2026
Tested both halves on
v8(0.9.63) withgraphify extract <dir> --code-only.Bug 2 no longer reproduces — a nested
walk()insidetrace(), with one unrelated module-levelwalk()elsewhere, resolves to the local nested definition. Looks like #3410 covered it.Bug 1 only reproduces when the importing file's directory has an
__init__.py:import collect— sibling, no__init__.pyfrom . import collectfrom pkg_a import collectimport pkg_a.collect as colimport collect— sibling, with__init__.pyThe failing shape is an implicit relative import, which Python 3 removed, and
_repoint_python_sibling_importsskips package directories deliberately:That function landed with #3430, after this was filed, and its docstring names the same symptom ("causing downstream member calls (
greeter.greet()) to be dropped"). So the valid-Python side of bug 1 looks covered on currentv8.Worth re-checking your corpus against 0.9.63 — does the directory holding
collect.pyandstore.pyhave an__init__.py? If it does,import collectthere is an implicit relative import and would not run under Python 3 either, which would make the missing edge correct rather than a gap.chore(fork): 0.9.65 升级收尾——契约测试标 xfail + CLAUDE.md 记录升级经验
fix(extract): 嵌套函数节点补契约五字段——修 get_node body 档静默返回错误函数体
omsenjalia commentedon Oct 18, 2026
This looks fixed on the
v8branch by c967797f (Fix Python nested function resolution). Could a maintainer confirm and close?