From 967325c35782fe1935e3fc164026cfeabcbe6ad8 Mon Sep 17 00:00:00 2001 From: DetachHead Date: Thu, 21 Mar 2024 22:58:39 +1000 Subject: [PATCH] report non-top level duplicate imports --- packages/pyright-internal/src/analyzer/binder.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/pyright-internal/src/analyzer/binder.ts b/packages/pyright-internal/src/analyzer/binder.ts index c94d2574d9..4863fa0d92 100644 --- a/packages/pyright-internal/src/analyzer/binder.ts +++ b/packages/pyright-internal/src/analyzer/binder.ts @@ -1931,7 +1931,14 @@ export class Binder extends ParseTreeWalker { const nameNode = importSymbolNode.alias || importSymbolNode.name; AnalyzerNodeInfo.setFlowNode(importSymbolNode, this._currentFlowNode!); - + if (this._currentScope.lookUpSymbolRecursive(nameNode.value)) { + this._addDiagnostic( + this._fileInfo.diagnosticRuleSet.reportDuplicateImport, + DiagnosticRule.reportDuplicateImport, + LocMessage.duplicateImport().format({ importName: nameNode.value }), + node + ); + } const symbol = this._bindNameToScope(this._currentScope, nameNode); if (symbol) {