fix(resolution): resolve Python module members through an aliased from-import (#1626) - #1635
Open
maxmilian wants to merge 1 commit into
Open
fix(resolution): resolve Python module members through an aliased from-import (#1626)#1635maxmilian wants to merge 1 commit into
maxmilian wants to merge 1 commit into
Conversation
…m-import (colbymchenry#1626) resolvePythonModuleMember rebuilt the submodule's dotted path by joining the import source with the LOCAL name. Under 'from pkg import mod as alias' that produces 'pkg.alias' — a module that does not exist — so the file lookup found nothing and the call fell through to unresolved_refs with status='failed'. codegraph_callers then reported the target as having fewer callers than it does, which is the same wrong 'is this dead code?' answer colbymchenry#578 produced for the unaliased form. Join with the exported name instead. For an unaliased import the two names are identical, so nothing changes there; '*' (the namespace form) keeps using the local name, which is what it already bound to. Scope note: the issue also reports 'import top as alias' failing. That form is a namespace import and binds at source, so it resolves on current main — a probe against the reverted resolver confirms it already produces its call edge. The regression test pins both halves so the working one cannot silently break. Co-Authored-By: Claude <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.
Fixes the
from … import … as …half of #1626.resolvePythonModuleMemberrebuilds the submodule's dotted path by joining the import source with the local name. Underfrom pkg import mod as aliasthat producespkg.alias— a module that doesn't exist — so the file lookup finds nothing, the member never resolves, and the call lands inunresolved_refswithstatus='failed'.codegraph_callersthen reports the target as having fewer callers than it does, which is exactly the wrong "is this dead code?" answer that #578 produced for the unaliased form.Joining with the exported name fixes it. For an unaliased import the two names are identical, so nothing changes there; the namespace form (
exportedName === '*') keeps binding at the local name, which is what it already did.Scope: the report has two halves and only one reproduces
The issue also lists
import build_api_contract as builder→builder.source_fingerprint()as producing no edge. That form resolves on currentmain. It's a namespace import that binds atsource— the real module name — so it never goes through the local-name join this PR fixes.I checked rather than assumed: with the resolver change reverted, a probe on the plain-aliased call site in the test fixture still reports one
callsedge. So if @JoeyNPP is still seeing that case fail on a real project, there's a second cause and it isn't this one — worth keeping #1626 open on that half, or splitting it out.Tests
One case added beside the existing #578 test in
resolution.test.ts(same integration shape — realCodeGraph.initwithindex: true), asserting both halves:from pkg import module as mod_alias→mod_alias.func()resolves topkg/module.py— fails before the change (expected [] to have a length of 1)import top_level as tl→tl.top_func()resolves — green before and after, pinned so fixing one half can't break the otherFull suite: 178 files / 3053 tests passing (3052 on
mainplus this one).tsc --noEmitclean.Reported by @JoeyNPP.