Skip to content

fix(extract): ignore contained symbols when resolving imported modules (#3887) - #3898

Closed
harshaygadekar wants to merge 1 commit into
Graphify-Labs:v8from
harshaygadekar:fix/nested-def-module-call-resolution
Closed

harshaygadekar wants to merge 1 commit into
Graphify-Labs:v8from
harshaygadekar:fix/nested-def-module-call-resolution

Conversation

@harshaygadekar

Copy link
Copy Markdown
Contributor

Fixes #3887

Summary

In _resolve_python_member_calls, candidate imported modules matching a receiver name (module.func()) are gathered from the caller file's imported_by_filenode targets:

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)]

when a file imports both a module (from services import store) and a function from that module (from services.store import sort_todos), and sort_todos contains a nested function (def key(t): ...):

  1. PR Fix Python nested function call resolution #3410 added contains edges from enclosing functions to their nested functions, so sort_todos in contains_children evaluates to True.
  2. _module_stem_key(sort_todos) looks at the node's source_file (services/store.py), whose stem is "store".
  3. mods ends up with two entries: the module file node services/store.py and the function node sort_todos.
  4. Because len(mods) == 2 != 1, the god-node ambiguity guard bails out, silently dropping the calls edge for every store.<func>() call in that caller.

Fix

Filter out nodes that are themselves contained inside another node by adding and t not in file_of_node.

file_of_node is already populated on line 3903 for all contains edges (file_of_node[tgt] = src). Top-level file and module nodes are never the target of a contains edge, so t not in file_of_node is True strictly for genuine module/file nodes and False for any symbol (function, method, class) defined inside a file.

Evidence/verification

Before Fix

Running extraction on a caller importing both store and sort_todos (with nested def key in sort_todos):

$ uv run python contribution-docs/reproduction-scripts/reproduce_issue_3887.py
============================================================
Issue #3887 Reproduction Results:
Extracted Calls Edges:
  board() -> sort_todos()

[FAILED] get_archived_panel() -> parse_todo_file() call edge MISSING!

After Fix

With and t not in file_of_node:

$ uv run python contribution-docs/reproduction-scripts/reproduce_issue_3887.py
============================================================
Issue #3887 Reproduction Results:
Extracted Calls Edges:
  board() -> sort_todos()
  get_archived_panel() -> parse_todo_file()

[PASSED] get_archived_panel() -> parse_todo_file() call edge FOUND.

Verification

  • Added regression test test_python_module_call_resolves_when_same_file_imports_function_with_nested_def in tests/test_extract.py.
  • Ran uv run pytest tests/test_extract.py -k "nested_def or test_python_module_qualified_call" (3 passed in 0.98s).
  • Ran all Python member call tests in test_extract.py (31 passed in 1.53s).
  • Ran uv run ruff check graphify/extract.py tests/test_extract.py (clean).
  • Ran uv run python -m tools.skillgen --check (134 artifacts match).

Graphify-Labs#3887)

In _resolve_python_member_calls, candidate imported modules are gathered from imported_by_filenode by checking 	 in contains_children. Following Graphify-Labs#3410, functions enclosing a nested def also have contains edges to their nested functions. When a caller imports both a module and a function from that module (where the function contains a nested def), both the module and the function matched the candidate filter because the function's _module_stem_key evaluates to the stem of its source file. The resulting len(mods) == 2 triggered the ambiguity guard and dropped all module.func() calls from that file.

Exclude contained symbols by verifying 	 not in file_of_node, which is already populated for all containment targets and excludes top-level file/module nodes.
Copilot AI lite review requested due to automatic review settings September 28, 2026 16:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @harshaygadekar. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).


Graphify review — findings

Fixes module.func() call resolution in _resolve_python_member_calls when a file imports both a module and a function from it, and that function has a nested def — the resolver now excludes real definition nodes (t not in file_of_node) so an enclosing function tracked as a contains child is no longer mistaken for an imported module and dropped as ambiguous (#3887).

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 2412 functions depend on the 686 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 712 callers, 48 callees
  • new: _rebuild_code() — 144 callers, 55 callees
  • new: extract_js() — 87 callers, 4 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: main() — 98 callers, 3 callees
  • new: dispatch_command() — 2 callers, 125 callees
  • new: _get_extractor() — 26 callers, 6 callees
  • new: run_pipeline() — 8 callers, 13 callees
  • …and 34 more — each is listed as a finding

Verification — 2412 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 2237 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

128 of 302 test file(s) selected (42%) via static blast radius.

  • tests/test_astro_extraction.py — impact
  • tests/test_astro_import_ids.py — impact
  • tests/test_build.py — impact
  • tests/test_builtin_global_type_refs.py — impact
  • tests/test_case_sensitive_resolution.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cobol_extractor.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_cpp_objc_cross_file_calls.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_cross_language_call_resolution.py — impact
  • tests/test_cross_repo_external_call_guards.py — impact
  • tests/test_cross_repo_member_calls.py — impact
  • tests/test_csharp_call_site_generic_args.py — impact
  • tests/test_csharp_enum_members.py — impact
  • tests/test_csharp_field_generic_args.py — impact
  • tests/test_csharp_generic_callsites.py — impact
  • tests/test_csharp_interface_dispatch.py — impact
  • tests/test_csharp_member_calls.py — impact
  • tests/test_csharp_member_nodes.py — impact
  • tests/test_csharp_object_creation.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_csharp_type_resolution.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_duplicate_annotation_edges.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • tests/test_erlang_extractor.py — impact
  • tests/test_extract.py — impact, changed-test
  • tests/test_extract_cache_location.py — impact
  • tests/test_extract_php_closures.py — impact
  • tests/test_file_label_disambiguation.py — impact
  • tests/test_file_node_id_spec.py — impact
  • tests/test_forwarding_review_findings.py — impact
  • tests/test_go_builtin_call_targets.py — impact
  • tests/test_go_import_repoint.py — impact
  • tests/test_go_interface_methods.py — impact
  • tests/test_go_qualified_resolution.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_import_self_loops.py — impact
  • tests/test_imported_export_forwarding.py — impact
  • tests/test_incremental.py — impact
  • tests/test_indirect_call_arrow_single_param_shadow.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • tests/test_indirect_call_catch_binding_shadow.py — impact
  • tests/test_indirect_call_external_import_shadow.py — impact
  • tests/test_indirect_call_for_of_binding_shadow.py — impact
  • tests/test_indirect_call_function_expression_shadow.py — impact
  • tests/test_indirect_call_nested_closure_shadow.py — impact
  • … and 78 more

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Docs that may be stale (advisory)

…and 10 more.

· 42 more finding(s) on lines outside this diff (see the check run).

safishamsi added a commit that referenced this pull request Sep 29, 2026
…ction

HTML node-info field fix (#3918), Kotlin annotated-inferred-property
crash (#3915/#3899), SQL DDL-before-DO (#3900), Razor @functions (#3908),
Blade @extends (#3907), and imported-module resolution (#3898).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.72 (now on PyPI) via an authorship-preserving cherry-pick, so your commit keeps contributor-graph credit. Thanks @harshaygadekar! Imported-module resolution ignores same-named contained symbols.

Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[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+)

3 participants