Repository navigation
Conversation
typeToSymbol resolved the package of a class or module type with getPackageInfo(node, ...), which classifies by the file containing the reference. Every reference emitted while visiting a project file is in the project, so any class reached through an alias declaration (`pkg.Thing`, or `Thing` re-exported from a submodule) was emitted under the project package instead of the package that declares it. Functions already used guessPackage(decl.moduleName, decl.path) and were correct. Use guessPackage with the type's own moduleName and filePath for classes, modules and TypeVar bounds, falling back to a local symbol when the package is unknown, as getFunctionSymbol does. Adds a snapshot test with a fake `widgets` package exposed through extraPaths and listed in testEnv.json, so references to classes re-exported from a submodule are checked against the dependency's package.
anguslees
force-pushed
the
fix-external-class-package
branch
from
October 14, 2026 23:49
1c06795 to
d6175bb
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.
Problem
References to a class or module reached through an alias declaration (
pkg.Thing,or
Thingre-exported from a submodule) are emitted under the project packageinstead of the package that declares them. Functions are unaffected.
With
requests2.32.3 listed in--environment:Over a random sample of 300 documents of a large project, 8% of occurrences whose
module belonged to a wheel listed in
--environmentcarried the project package.After this change it is 0.0%.
This breaks cross-repository navigation to the dependency's own index, folds every
dependency's classes into the project namespace, and members built from a cached
class symbol (
Session#get().(url)) inherit the wrong package.Cause
typeToSymbolresolves the package of class and module types by the filecontaining the reference:
getPackageInforeturnsthis.projectPackagewhenevernode's file is under theproject root, which is always the case while visiting a project file. The function
path already uses the declaring file and is correct:
The TypeVar-bound branch of
getScipSymbolhas the same pattern.Fix
Use
guessPackagewith the type's ownmoduleNameandfilePathfor classes,modules and TypeVar bounds. When no package is found, fall back to a local symbol,
as
getFunctionSymboldoes.Test
New snapshot
external_class_import. A fake wheelwidgets1.2.3 lives insnapshots/site-packages/and is listed intestEnv.json;widgets/__init__.pyre-exports
WidgetandWidgetErrorfromwidgets/models.py. The test projectreaches it through
extraPathsin itspyrightconfig.json, so its files stayoutside the project root and are classified as external.
pythonVersionis pinnedto 3.11 because a config file otherwise makes pyright take the version from the
local interpreter, which would differ from the other snapshots.
Snapshot before and after the fix:
No existing snapshot changes.
npm run build-agent,npm run check-snapshots,npm testandnpm run check:prettierall pass.