Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug that results in a false negative when two import statements… #9755

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/pyright-internal/src/analyzer/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,11 @@ export class Binder extends ParseTreeWalker {

AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode!);

let uriOfFirstSubmodule: Uri | undefined;
if (importInfo && importInfo.isImportFound && !importInfo.isNativeLib && importInfo.resolvedUris.length > 0) {
uriOfFirstSubmodule = importInfo.resolvedUris[0];
}

// See if there's already a matching alias declaration for this import.
// if so, we'll update it rather than creating a new one. This is required
// to handle cases where multiple import statements target the same
Expand All @@ -2578,7 +2583,12 @@ export class Binder extends ParseTreeWalker {
// python module loader.
const existingDecl = symbol
.getDeclarations()
.find((decl) => decl.type === DeclarationType.Alias && decl.firstNamePart === firstNamePartValue);
.find(
(decl) =>
decl.type === DeclarationType.Alias &&
decl.firstNamePart === firstNamePartValue &&
(!uriOfFirstSubmodule || uriOfFirstSubmodule.equals(decl.uri))
);
let newDecl: AliasDeclaration;
let uriOfLastSubmodule: Uri;
if (importInfo && importInfo.isImportFound && !importInfo.isNativeLib && importInfo.resolvedUris.length > 0) {
Expand Down
Loading