#3887·graphify

[Bug]: Python: from-importing a function that has a nested def makes every module.func() call from that file lose its calls edge (0.9.58+)

Author: wpoPRCreated Sep 28, 2026Updated Sep 28, 2026

What happened?

Since 0.9.58, if a file does from pkg import mod and also from pkg.mod import f, where f is a function that contains a nested def, every mod.<anything>() call in that file loses its calls edge. 0.9.57 resolves them. Still reproduces on 0.9.70 and on v8@4c21b15e9b.

Root cause (found by instrumenting the resolver; the intermediate edge does not survive to graph.json): since #3410 an outer function with a nested def is the source of a contains edge. The module arm of _resolve_python_member_calls treats any imports target that has contains children as a candidate module:

python
mods = [t for t in imported_by_filenode.get(caller_file, ())
        if t in contains_children
        and (_module_stem_key(t) == rkey or file_aliases.get(t) == rkey)]
if len(mods) != 1:  # not an imported module, or ambiguous -> bail
    continue

The imports views -> sort_todos edge makes sort_todos a candidate, and _module_stem_key takes the stem of its file (store), which matches the receiver. So mods == [store.py, sort_todos], and the resolver bails as ambiguous.

Steps to reproduce

bash
mkdir -p repro/app/api repro/app/services && cd repro
touch app/api/__init__.py app/services/__init__.py
cat > app/services/store.py <<'EOF'
def sort_todos(todos):
    def key(t):
        return t
    return sorted(todos, key=key)


def parse_todo_file(path):
    return path
EOF
cat > app/api/views.py <<'EOF'
from services import store
from services.store import sort_todos


def get_archived_panel():
    return store.parse_todo_file(1)


def board():
    return sort_todos([])
EOF
git init -q . && graphify update .

Error output or graph output

calls edges from app/api/views.py
0.9.57:  board() -> sort_todos(); get_archived_panel() -> parse_todo_file()
0.9.58, 0.9.62, 0.9.66, 0.9.70:  board() -> sort_todos()        <- parse_todo_file() lost
controls: without the nested `def key` in sort_todos -> both edges on every version

Suggested fix (one line, verified): a node that is itself contained by another node is not a module:

diff
             mods = [t for t in imported_by_filenode.get(caller_file, ())
                     if t in contains_children
+                    and t not in file_of_node
                     and (_module_stem_key(t) == rkey or file_aliases.get(t) == rkey)]

On a 485-file Python subtree of our repo this line alone restores exactly the 8 lost mod.func() edges and adds or removes nothing else (full graph diff, 0.9.70 vs 0.9.70 + this line: +8 calls, −0). On the whole ~2,470-file repo, combined with the fix from the companion issue, the 8 are recovered and no edge is removed.

Version: 0.9.58 → 0.9.70 (last good: 0.9.57) · OS: macOS · Python: 3.11 · Install: uv (uv venv + uv pip install graphifyy==<v>; reproduced on a clean fixture, no LLM backend)

Additional context: related but different: #2447 (other causes in the same arm), #2428 / PR #2429 (alias stem; the un-aliased repro above is not covered by #2429), #3272 (package-form import outside the package tree).