fix(parser): extract Python module-level calls (closes #291)#292
Merged
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
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.



Root cause
PythonParser._extract_references_implgated call-edge emission behindelif node.type == 'call' and fn_id:. A call written as a bare top-level statement (e.g.setup_app()) is walked withfn_id is None(no enclosing def/class), so the branch was skipped entirely — no CALLS edge. Result: a function called only at module level gotref_count=0/status=dead(false positive) and was invisible totrace --direction up. This is issue #219, already fixed for the TS/JS parsers, but never applied to the Python parser.Pattern mirrored from #219
The TS/JS fix attributes module-top-level calls to a synthetic source id
<file>:0:<module>with no correspondinggraph_nodesrow (graph_model.is_module_level_source_id()recognises it;_module_level_caller_entryrenders it in trace-up). Applied the analogous change inpython_parser.py:module_node_id = f"{file_path}:0:<module>"once.elif node.type == 'call' and fn_id:->elif node.type == 'call':, withsource_id = fn_id if fn_id else module_node_id, and emit edgesfrom=source_id.Same synthetic-id format, no new format invented, no fake node created.
Fix location
scripts/parsers/python_parser.py—_extract_references_impl(call-edge branch + newmodule_node_id).Verification
Repro
def setup_app / helper / caller+ module-levelsetup_app()/caller():Before:
setup_apprc=0/dead,callerrc=0/dead (both wrong); only edgecaller->helper.After (parser output):
Full scan:
setup_apprc=1,callerrc=1.Anti-pollution (#223 constraint):
SELECT COUNT(*) FROM graph_nodes WHERE name='<module>'= 0; backend.json has no<module>node.No regression:
helper(called fromcaller's body) still rc>=1; a genuinely-never-calledpy_never_calledstays rc=0/dead (control).Tests
Added 3 Python golden cases to
tests/test_graph_accuracy_golden.py(mirrors the TS #219/#223 fixtures): rc>=1 + caller-from-file for module-level-called fns, trace-up surfaces themodule_level=Truecaller, and a genuinely-dead control stays dead.Closes #291.
🤖 Generated with Claude Code