Skip to content

Commit

Permalink
Fixed bug that results in a false negative when two import statements…
Browse files Browse the repository at this point in the history
… shadow the same symbol and an attribute is accessed between the two import statements. This addresses #9752. (#9755)
  • Loading branch information
erictraut authored Jan 24, 2025
1 parent 07ef416 commit 9f71e14
Showing 1 changed file with 11 additions and 1 deletion.
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

0 comments on commit 9f71e14

Please sign in to comment.