fix(python): resolve module-qualified calls from inside class methods - #2366
Open
rijefff wants to merge 1 commit into
Open
fix(python): resolve module-qualified calls from inside class methods#2366rijefff wants to merge 1 commit into
rijefff wants to merge 1 commit into
Conversation
`_resolve_python_member_calls()` looked `caller_file` up in `file_of_node`, which was populated from `contains` edges only. Methods reach their file through the `method` relation (class -> method) instead, so `caller_file` was `None` for every method and the module-alias arm bailed out. Result: `module.func()` produced a `calls` edge when written in a module-level function, but never when written inside a class method. Two-part fix: 1. Populate `file_of_node` from `method` edges as well, not just `contains`. 2. Walk transitively method -> class -> file when resolving `caller_file`. Adds tests/test_python_member_calls.py, which fails without this change and passes with it. The two shapes that already worked (bare-name call from a method, qualified call from a module-level function) are asserted too so the fix cannot regress them.
rijefff
force-pushed
the
fix/python-member-call-in-class-method
branch
from
August 1, 2026 09:08
4c3c3cc to
195e6ed
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In
_resolve_python_member_calls()(graphify/extract.py), qualified calls of the formmodule.func()resolve only when the caller is a module-level function. When the samecall appears inside a class method, no
callsedge is produced.The module-alias arm bails because
caller_fileisNone.Reproduction
callsedge on mainfunction_qualified()module.attrMachine.method_bare()Machine.method_qualified()module.attrRoot cause
file_of_nodeis populated only fromcontainsedges:Methods are linked to their class through the
methodrelation, notcontains, somethods get no entry in
file_of_node.caller_fileis thereforeNone,imported_by_filenode.get(None, ())is empty, and the armcontinues.Confirmed by instrumenting the resolver:
caller_file=NoneforMachine.method_qualified(),while
function_qualified()resolves to its file.Fix
file_of_nodefrommethodedges (class -> method) as well.caller_file.16 added lines, no existing line changed.
Test
tests/test_python_member_calls.py(new, follows the existingtest_<lang>_member_calls.pynaming). It asserts the previously missing edge and thetwo shapes that already worked, so the fix cannot silently regress them.
assert _has_edge(result, method_qualified, helper, "calls")->FalseFull suite
pytest tests/on this branch (basev8): 3651 passed, 14 failed, 170 skipped.The 14 failures are pre-existing and environmental, not caused by this change — verified by a
control run: reverting only the patch and re-running the full suite produces the same 14
failures, and
commof the two sorted failure lists is empty. They aretest_terraform.py(7,
tree_sitter_hcl not installed),test_ollama_retry_cap.py(4), and one each intest_extract.py,test_install_references.py,test_manifest_ingest.py.Impact
Measured on a private ~272-file Python codebase where most functions are methods on classes:
callsedgesOn that repository's full graph the change adds +2,755 edges (+22.9%).
The failure is silent: the graph simply reports fewer callers, so an agent can conclude
"nothing else calls this" when callers do exist.
Related
Similar resolver gaps are open for other languages: #1313 (Go), #2135 (Rust), #1682 (PHP).
I did not find an existing issue for the Python class-method case.
Not covered here
from pkg import util as u2inside a method (lazy import + alias) still produces no edge —the alias is bound in function scope rather than file scope. Left out deliberately to keep this
change small; happy to file it separately.