Repository navigation
fix(go): resolve shadowed imports as local receivers - #5411
sdivyanshu90 wants to merge 1 commit into
Conversation
Fixes Graphify-Labs#5409 Co-authored-by: OpenAI <[email protected]>
|
Thanks for the pull request, @sdivyanshu90. 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.11 and 3.13, and that the change keeps extraction deterministic. |
|
@safishamsi Could you please review this PR? |
There was a problem hiding this comment.
Graphify review 
2 possible issues to check · High impact
Go selector calls now treat a visible local binding as taking precedence over an import with the same name.
2 possible issues we couldn't confirm
- A local variable named like an imported package may not stop its calls from being treated as package calls when its type is unknown ·
graphify/extractors/go.py:897 - Method values passed as arguments through a shadowed package name are recorded with the wrong receiver ·
graphify/extractors/go.py:996
They don't change the score.
What this review covered
- We didn't review 1 file that isn't source code, such as docs, config, images, or generated or third-party code.
- 3 of 3 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 3896 functions depend on this change
- 1 function became more coupled.
extract()(1337 callers). - Gate, test list and every flagged function: in the Graphify check.
Reviewed ae08a2d · Full report in the Graphify check
…batch Fold the Python-lambda (#5417), Go-import-shadow (#5411) and COBOL GO-TO (#5423) AST-output changes into one combined _AST_CACHE_SCHEMA bump 53 -> 54, so cached Python/Go/COBOL extractions re-run. Fix the #5422 regression test's cwd-fragile `query` assertion to check the queried node (returncode==0 is the real invariant). 0.9.119 changelog and version bump. The headline is the #5320 anyio regression fix (graph commands broke on core installs in 0.9.118). Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed in v0.9.119 via an authorship-preserving cherry-pick. A local variable that shadows an imported package name now resolves as a local receiver (lexically scoped), and an unknown local fails closed instead of falling back to a package call. Thanks @sdivyanshu90! |
Fixes #5409
When a local Go receiver shadows an import alias, selectors can produce a false EXTRACTED call into the imported package. Use the visible lexical binding before classifying an import selector and reuse the receiver type resolver for calls and method values. Keep unknown local types from resolving as package calls.
The regression covers a nested binding, restoration of package lookup outside that block, a typed parameter, an unknown parameter and a method value passed as an argument. The AST cache schema bump retires the old call facts.
Validation
python -m pytest tests/test_go_import_shadowing.py tests/test_multilang.py -q --tb=shortreported 107 passed and one skipped. The regression failed on clean upstream.ruff check .passed.python -m pytest tests -q --tb=shortreported 11,723 passed, 222 skipped, one xfailed and one YAML test failure. The YAML failure also occurred on clean upstream. Six Terraform cache failures from the concurrent upstream run did not recur in the final Go run.python -m pyright --pythonpath /home/somu/.venvs/gvenv/bin/python --outputjsonmatched upstream diagnostics exactly (783 errors and four warnings).python -m graphify update .completed locally.