Repository navigation
fix(extract): ignore contained symbols when resolving imported modules (#3887) - #3898
harshaygadekar wants to merge 1 commit into
Conversation
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.
|
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. |
There was a problem hiding this comment.
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— impacttests/test_astro_import_ids.py— impacttests/test_build.py— impacttests/test_builtin_global_type_refs.py— impacttests/test_case_sensitive_resolution.py— impacttests/test_cjs_module_extension.py— impacttests/test_cobol_extractor.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_language_call_resolution.py— impacttests/test_cross_repo_external_call_guards.py— impacttests/test_cross_repo_member_calls.py— impacttests/test_csharp_call_site_generic_args.py— impacttests/test_csharp_enum_members.py— impacttests/test_csharp_field_generic_args.py— impacttests/test_csharp_generic_callsites.py— impacttests/test_csharp_interface_dispatch.py— impacttests/test_csharp_member_calls.py— impacttests/test_csharp_member_nodes.py— impacttests/test_csharp_object_creation.py— impacttests/test_csharp_partial_classes.py— impacttests/test_csharp_type_resolution.py— impacttests/test_definition_file_portability.py— impacttests/test_detect.py— impacttests/test_dotnet.py— impacttests/test_duplicate_annotation_edges.py— impacttests/test_elixir_import_resolution.py— impacttests/test_erlang_extractor.py— impacttests/test_extract.py— impact, changed-testtests/test_extract_cache_location.py— impacttests/test_extract_php_closures.py— impacttests/test_file_label_disambiguation.py— impacttests/test_file_node_id_spec.py— impacttests/test_forwarding_review_findings.py— impacttests/test_go_builtin_call_targets.py— impacttests/test_go_import_repoint.py— impacttests/test_go_interface_methods.py— impacttests/test_go_qualified_resolution.py— impacttests/test_import_extension_resolution.py— impacttests/test_import_self_loops.py— impacttests/test_imported_export_forwarding.py— impacttests/test_incremental.py— impacttests/test_indirect_call_arrow_single_param_shadow.py— impacttests/test_indirect_call_block_scoped_shadow.py— impacttests/test_indirect_call_catch_binding_shadow.py— impacttests/test_indirect_call_external_import_shadow.py— impacttests/test_indirect_call_for_of_binding_shadow.py— impacttests/test_indirect_call_function_expression_shadow.py— impacttests/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)
CHANGELOG.md§ 0.9.69 (2026-09-26) (lines 5-15): references changed symbolscontainsCHANGELOG.md§ 0.9.68 (2026-09-25) (lines 16-28): references changed symbolscontainsCHANGELOG.md§ 0.9.63 (2026-09-16) (lines 78-85): references changed symbolscontainsCHANGELOG.md§ 0.9.57 (2026-09-09) (lines 146-153): references changed symbolscontainsCHANGELOG.md§ 0.9.47 (2026-08-19) (lines 284-300): references changed symbolscontainsCHANGELOG.md§ 0.9.43 (2026-08-14) (lines 338-346): references changed symbolscontainsCHANGELOG.md§ 0.9.33 (2026-08-05) (lines 447-453): references changed symbolscontainsCHANGELOG.md§ 0.9.22 (2026-07-20) (lines 570-579): references changed symbolscontainsCHANGELOG.md§ 0.9.17 (2026-07-16) (lines 625-654): references changed symbolscontainsCHANGELOG.md§ 0.9.16 (2026-07-14) (lines 655-686): references changed symbolscontains
…and 10 more.
· 42 more finding(s) on lines outside this diff (see the check run).
…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]>
|
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. |
Fixes #3887
Summary
In
_resolve_python_member_calls, candidate imported modules matching a receiver name (module.func()) are gathered from the caller file'simported_by_filenodetargets:when a file imports both a module (
from services import store) and a function from that module (from services.store import sort_todos), andsort_todoscontains a nested function (def key(t): ...):containsedges from enclosing functions to their nested functions, sosort_todos in contains_childrenevaluates toTrue._module_stem_key(sort_todos)looks at the node'ssource_file(services/store.py), whose stem is"store".modsends up with two entries: the module file nodeservices/store.pyand the function nodesort_todos.len(mods) == 2 != 1, the god-node ambiguity guard bails out, silently dropping thecallsedge for everystore.<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_nodeis already populated on line 3903 for allcontainsedges (file_of_node[tgt] = src). Top-level file and module nodes are never the target of acontainsedge, sot not in file_of_nodeisTruestrictly for genuine module/file nodes andFalsefor any symbol (function, method, class) defined inside a file.Evidence/verification
Before Fix
Running extraction on a caller importing both
storeandsort_todos(with nesteddef keyinsort_todos):After Fix
With
and t not in file_of_node:Verification
test_python_module_call_resolves_when_same_file_imports_function_with_nested_defintests/test_extract.py.uv run pytest tests/test_extract.py -k "nested_def or test_python_module_qualified_call"(3 passed in 0.98s).test_extract.py(31 passed in 1.53s).uv run ruff check graphify/extract.py tests/test_extract.py(clean).uv run python -m tools.skillgen --check(134 artifacts match).