@zzzen/pyright-internal 1.1.254
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/aliasDeclarationUtils.d.ts +9 -0
- package/dist/analyzer/aliasDeclarationUtils.js +128 -0
- package/dist/analyzer/aliasDeclarationUtils.js.map +1 -0
- package/dist/analyzer/analysis.d.ts +18 -0
- package/dist/analyzer/analysis.js +81 -0
- package/dist/analyzer/analysis.js.map +1 -0
- package/dist/analyzer/analyzerFileInfo.d.ts +39 -0
- package/dist/analyzer/analyzerFileInfo.js +17 -0
- package/dist/analyzer/analyzerFileInfo.js.map +1 -0
- package/dist/analyzer/analyzerNodeInfo.d.ts +32 -0
- package/dist/analyzer/analyzerNodeInfo.js +138 -0
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -0
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +54 -0
- package/dist/analyzer/backgroundAnalysisProgram.js +222 -0
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -0
- package/dist/analyzer/binder.d.ts +149 -0
- package/dist/analyzer/binder.js +3195 -0
- package/dist/analyzer/binder.js.map +1 -0
- package/dist/analyzer/checker.d.ts +116 -0
- package/dist/analyzer/checker.js +3828 -0
- package/dist/analyzer/checker.js.map +1 -0
- package/dist/analyzer/circularDependency.d.ts +7 -0
- package/dist/analyzer/circularDependency.js +51 -0
- package/dist/analyzer/circularDependency.js.map +1 -0
- package/dist/analyzer/codeFlowEngine.d.ts +21 -0
- package/dist/analyzer/codeFlowEngine.js +1132 -0
- package/dist/analyzer/codeFlowEngine.js.map +1 -0
- package/dist/analyzer/codeFlowTypes.d.ts +82 -0
- package/dist/analyzer/codeFlowTypes.js +134 -0
- package/dist/analyzer/codeFlowTypes.js.map +1 -0
- package/dist/analyzer/codeFlowUtils.d.ts +2 -0
- package/dist/analyzer/codeFlowUtils.js +348 -0
- package/dist/analyzer/codeFlowUtils.js.map +1 -0
- package/dist/analyzer/commentUtils.d.ts +4 -0
- package/dist/analyzer/commentUtils.js +131 -0
- package/dist/analyzer/commentUtils.js.map +1 -0
- package/dist/analyzer/constraintSolver.d.ts +7 -0
- package/dist/analyzer/constraintSolver.js +605 -0
- package/dist/analyzer/constraintSolver.js.map +1 -0
- package/dist/analyzer/constructorTransform.d.ts +4 -0
- package/dist/analyzer/constructorTransform.js +219 -0
- package/dist/analyzer/constructorTransform.js.map +1 -0
- package/dist/analyzer/dataClasses.d.ts +9 -0
- package/dist/analyzer/dataClasses.js +762 -0
- package/dist/analyzer/dataClasses.js.map +1 -0
- package/dist/analyzer/declaration.d.ts +90 -0
- package/dist/analyzer/declaration.js +42 -0
- package/dist/analyzer/declaration.js.map +1 -0
- package/dist/analyzer/declarationUtils.d.ts +12 -0
- package/dist/analyzer/declarationUtils.js +212 -0
- package/dist/analyzer/declarationUtils.js.map +1 -0
- package/dist/analyzer/docStringConversion.d.ts +2 -0
- package/dist/analyzer/docStringConversion.js +699 -0
- package/dist/analyzer/docStringConversion.js.map +1 -0
- package/dist/analyzer/docStringUtils.d.ts +3 -0
- package/dist/analyzer/docStringUtils.js +103 -0
- package/dist/analyzer/docStringUtils.js.map +1 -0
- package/dist/analyzer/functionTransform.d.ts +4 -0
- package/dist/analyzer/functionTransform.js +96 -0
- package/dist/analyzer/functionTransform.js.map +1 -0
- package/dist/analyzer/importResolver.d.ts +97 -0
- package/dist/analyzer/importResolver.js +1617 -0
- package/dist/analyzer/importResolver.js.map +1 -0
- package/dist/analyzer/importResult.d.ts +33 -0
- package/dist/analyzer/importResult.js +11 -0
- package/dist/analyzer/importResult.js.map +1 -0
- package/dist/analyzer/importStatementUtils.d.ts +46 -0
- package/dist/analyzer/importStatementUtils.js +618 -0
- package/dist/analyzer/importStatementUtils.js.map +1 -0
- package/dist/analyzer/namedTuples.d.ts +5 -0
- package/dist/analyzer/namedTuples.js +342 -0
- package/dist/analyzer/namedTuples.js.map +1 -0
- package/dist/analyzer/packageTypeReport.d.ts +52 -0
- package/dist/analyzer/packageTypeReport.js +45 -0
- package/dist/analyzer/packageTypeReport.js.map +1 -0
- package/dist/analyzer/packageTypeVerifier.d.ts +37 -0
- package/dist/analyzer/packageTypeVerifier.js +908 -0
- package/dist/analyzer/packageTypeVerifier.js.map +1 -0
- package/dist/analyzer/parentDirectoryCache.d.ts +23 -0
- package/dist/analyzer/parentDirectoryCache.js +71 -0
- package/dist/analyzer/parentDirectoryCache.js.map +1 -0
- package/dist/analyzer/parseTreeCleaner.d.ts +8 -0
- package/dist/analyzer/parseTreeCleaner.js +51 -0
- package/dist/analyzer/parseTreeCleaner.js.map +1 -0
- package/dist/analyzer/parseTreeUtils.d.ts +98 -0
- package/dist/analyzer/parseTreeUtils.js +1753 -0
- package/dist/analyzer/parseTreeUtils.js.map +1 -0
- package/dist/analyzer/parseTreeWalker.d.ts +81 -0
- package/dist/analyzer/parseTreeWalker.js +437 -0
- package/dist/analyzer/parseTreeWalker.js.map +1 -0
- package/dist/analyzer/patternMatching.d.ts +6 -0
- package/dist/analyzer/patternMatching.js +866 -0
- package/dist/analyzer/patternMatching.js.map +1 -0
- package/dist/analyzer/program.d.ts +158 -0
- package/dist/analyzer/program.js +1902 -0
- package/dist/analyzer/program.js.map +1 -0
- package/dist/analyzer/properties.d.ts +10 -0
- package/dist/analyzer/properties.js +368 -0
- package/dist/analyzer/properties.js.map +1 -0
- package/dist/analyzer/protocols.d.ts +8 -0
- package/dist/analyzer/protocols.js +409 -0
- package/dist/analyzer/protocols.js.map +1 -0
- package/dist/analyzer/pyTypedUtils.d.ts +6 -0
- package/dist/analyzer/pyTypedUtils.js +42 -0
- package/dist/analyzer/pyTypedUtils.js.map +1 -0
- package/dist/analyzer/pythonPathUtils.d.ts +14 -0
- package/dist/analyzer/pythonPathUtils.js +173 -0
- package/dist/analyzer/pythonPathUtils.js.map +1 -0
- package/dist/analyzer/scope.d.ts +39 -0
- package/dist/analyzer/scope.js +110 -0
- package/dist/analyzer/scope.js.map +1 -0
- package/dist/analyzer/scopeUtils.d.ts +6 -0
- package/dist/analyzer/scopeUtils.js +72 -0
- package/dist/analyzer/scopeUtils.js.map +1 -0
- package/dist/analyzer/service.d.ts +144 -0
- package/dist/analyzer/service.js +1197 -0
- package/dist/analyzer/service.js.map +1 -0
- package/dist/analyzer/sourceFile.d.ts +123 -0
- package/dist/analyzer/sourceFile.js +908 -0
- package/dist/analyzer/sourceFile.js.map +1 -0
- package/dist/analyzer/sourceMapper.d.ts +47 -0
- package/dist/analyzer/sourceMapper.js +543 -0
- package/dist/analyzer/sourceMapper.js.map +1 -0
- package/dist/analyzer/staticExpressions.d.ts +4 -0
- package/dist/analyzer/staticExpressions.js +242 -0
- package/dist/analyzer/staticExpressions.js.map +1 -0
- package/dist/analyzer/symbol.d.ts +50 -0
- package/dist/analyzer/symbol.js +160 -0
- package/dist/analyzer/symbol.js.map +1 -0
- package/dist/analyzer/symbolNameUtils.d.ts +8 -0
- package/dist/analyzer/symbolNameUtils.js +53 -0
- package/dist/analyzer/symbolNameUtils.js.map +1 -0
- package/dist/analyzer/symbolUtils.d.ts +7 -0
- package/dist/analyzer/symbolUtils.js +46 -0
- package/dist/analyzer/symbolUtils.js.map +1 -0
- package/dist/analyzer/testWalker.d.ts +14 -0
- package/dist/analyzer/testWalker.js +92 -0
- package/dist/analyzer/testWalker.js.map +1 -0
- package/dist/analyzer/tracePrinter.d.ts +11 -0
- package/dist/analyzer/tracePrinter.js +222 -0
- package/dist/analyzer/tracePrinter.js.map +1 -0
- package/dist/analyzer/typeCache.d.ts +40 -0
- package/dist/analyzer/typeCache.js +134 -0
- package/dist/analyzer/typeCache.js.map +1 -0
- package/dist/analyzer/typeDocStringUtils.d.ts +12 -0
- package/dist/analyzer/typeDocStringUtils.js +293 -0
- package/dist/analyzer/typeDocStringUtils.js.map +1 -0
- package/dist/analyzer/typeEvaluator.d.ts +18 -0
- package/dist/analyzer/typeEvaluator.js +16598 -0
- package/dist/analyzer/typeEvaluator.js.map +1 -0
- package/dist/analyzer/typeEvaluatorTypes.d.ts +220 -0
- package/dist/analyzer/typeEvaluatorTypes.js +16 -0
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -0
- package/dist/analyzer/typeEvaluatorWithTracker.d.ts +6 -0
- package/dist/analyzer/typeEvaluatorWithTracker.js +121 -0
- package/dist/analyzer/typeEvaluatorWithTracker.js.map +1 -0
- package/dist/analyzer/typeGuards.d.ts +6 -0
- package/dist/analyzer/typeGuards.js +1293 -0
- package/dist/analyzer/typeGuards.js.map +1 -0
- package/dist/analyzer/typePrinter.d.ts +17 -0
- package/dist/analyzer/typePrinter.js +603 -0
- package/dist/analyzer/typePrinter.js.map +1 -0
- package/dist/analyzer/typeStubWriter.d.ts +48 -0
- package/dist/analyzer/typeStubWriter.js +605 -0
- package/dist/analyzer/typeStubWriter.js.map +1 -0
- package/dist/analyzer/typeUtils.d.ts +134 -0
- package/dist/analyzer/typeUtils.js +2380 -0
- package/dist/analyzer/typeUtils.js.map +1 -0
- package/dist/analyzer/typeVarContext.d.ts +50 -0
- package/dist/analyzer/typeVarContext.js +250 -0
- package/dist/analyzer/typeVarContext.js.map +1 -0
- package/dist/analyzer/typedDicts.d.ts +12 -0
- package/dist/analyzer/typedDicts.js +695 -0
- package/dist/analyzer/typedDicts.js.map +1 -0
- package/dist/analyzer/types.d.ts +484 -0
- package/dist/analyzer/types.js +1844 -0
- package/dist/analyzer/types.js.map +1 -0
- package/dist/backgroundAnalysis.d.ts +14 -0
- package/dist/backgroundAnalysis.js +42 -0
- package/dist/backgroundAnalysis.js.map +1 -0
- package/dist/backgroundAnalysisBase.d.ts +83 -0
- package/dist/backgroundAnalysisBase.js +429 -0
- package/dist/backgroundAnalysisBase.js.map +1 -0
- package/dist/backgroundThreadBase.d.ts +34 -0
- package/dist/backgroundThreadBase.js +134 -0
- package/dist/backgroundThreadBase.js.map +1 -0
- package/dist/commands/commandController.d.ts +13 -0
- package/dist/commands/commandController.js +48 -0
- package/dist/commands/commandController.js.map +1 -0
- package/dist/commands/commandResult.d.ts +9 -0
- package/dist/commands/commandResult.js +19 -0
- package/dist/commands/commandResult.js.map +1 -0
- package/dist/commands/commands.d.ts +7 -0
- package/dist/commands/commands.js +11 -0
- package/dist/commands/commands.js.map +1 -0
- package/dist/commands/createTypeStub.d.ts +8 -0
- package/dist/commands/createTypeStub.js +50 -0
- package/dist/commands/createTypeStub.js.map +1 -0
- package/dist/commands/quickActionCommand.d.ts +8 -0
- package/dist/commands/quickActionCommand.js +31 -0
- package/dist/commands/quickActionCommand.js.map +1 -0
- package/dist/commands/restartServer.d.ts +8 -0
- package/dist/commands/restartServer.js +20 -0
- package/dist/commands/restartServer.js.map +1 -0
- package/dist/common/cancellationUtils.d.ts +16 -0
- package/dist/common/cancellationUtils.js +60 -0
- package/dist/common/cancellationUtils.js.map +1 -0
- package/dist/common/chokidarFileWatcherProvider.d.ts +9 -0
- package/dist/common/chokidarFileWatcherProvider.js +88 -0
- package/dist/common/chokidarFileWatcherProvider.js.map +1 -0
- package/dist/common/collectionUtils.d.ts +114 -0
- package/dist/common/collectionUtils.js +292 -0
- package/dist/common/collectionUtils.js.map +1 -0
- package/dist/common/commandLineOptions.d.ts +41 -0
- package/dist/common/commandLineOptions.js +46 -0
- package/dist/common/commandLineOptions.js.map +1 -0
- package/dist/common/configOptions.d.ts +144 -0
- package/dist/common/configOptions.js +908 -0
- package/dist/common/configOptions.js.map +1 -0
- package/dist/common/console.d.ts +61 -0
- package/dist/common/console.js +191 -0
- package/dist/common/console.js.map +1 -0
- package/dist/common/core.d.ts +67 -0
- package/dist/common/core.js +118 -0
- package/dist/common/core.js.map +1 -0
- package/dist/common/crypto.d.ts +1 -0
- package/dist/common/crypto.js +37 -0
- package/dist/common/crypto.js.map +1 -0
- package/dist/common/debug.d.ts +13 -0
- package/dist/common/debug.js +131 -0
- package/dist/common/debug.js.map +1 -0
- package/dist/common/deferred.d.ts +11 -0
- package/dist/common/deferred.js +62 -0
- package/dist/common/deferred.js.map +1 -0
- package/dist/common/diagnostic.d.ts +59 -0
- package/dist/common/diagnostic.js +134 -0
- package/dist/common/diagnostic.js.map +1 -0
- package/dist/common/diagnosticRules.d.ts +67 -0
- package/dist/common/diagnosticRules.js +83 -0
- package/dist/common/diagnosticRules.js.map +1 -0
- package/dist/common/diagnosticSink.d.ts +34 -0
- package/dist/common/diagnosticSink.js +110 -0
- package/dist/common/diagnosticSink.js.map +1 -0
- package/dist/common/editAction.d.ts +29 -0
- package/dist/common/editAction.js +11 -0
- package/dist/common/editAction.js.map +1 -0
- package/dist/common/extensibility.d.ts +11 -0
- package/dist/common/extensibility.js +10 -0
- package/dist/common/extensibility.js.map +1 -0
- package/dist/common/extensions.d.ts +3 -0
- package/dist/common/extensions.js +15 -0
- package/dist/common/extensions.js.map +1 -0
- package/dist/common/fileBasedCancellationUtils.d.ts +11 -0
- package/dist/common/fileBasedCancellationUtils.js +259 -0
- package/dist/common/fileBasedCancellationUtils.js.map +1 -0
- package/dist/common/fileSystem.d.ts +72 -0
- package/dist/common/fileSystem.js +69 -0
- package/dist/common/fileSystem.js.map +1 -0
- package/dist/common/fullAccessHost.d.ts +19 -0
- package/dist/common/fullAccessHost.js +193 -0
- package/dist/common/fullAccessHost.js.map +1 -0
- package/dist/common/host.d.ts +21 -0
- package/dist/common/host.js +30 -0
- package/dist/common/host.js.map +1 -0
- package/dist/common/logTracker.d.ts +15 -0
- package/dist/common/logTracker.js +129 -0
- package/dist/common/logTracker.js.map +1 -0
- package/dist/common/lspUtils.d.ts +3 -0
- package/dist/common/lspUtils.js +20 -0
- package/dist/common/lspUtils.js.map +1 -0
- package/dist/common/memUtils.d.ts +3 -0
- package/dist/common/memUtils.js +37 -0
- package/dist/common/memUtils.js.map +1 -0
- package/dist/common/pathConsts.d.ts +8 -0
- package/dist/common/pathConsts.js +19 -0
- package/dist/common/pathConsts.js.map +1 -0
- package/dist/common/pathUtils.d.ts +170 -0
- package/dist/common/pathUtils.js +762 -0
- package/dist/common/pathUtils.js.map +1 -0
- package/dist/common/positionUtils.d.ts +7 -0
- package/dist/common/positionUtils.js +71 -0
- package/dist/common/positionUtils.js.map +1 -0
- package/dist/common/progressReporter.d.ts +15 -0
- package/dist/common/progressReporter.js +44 -0
- package/dist/common/progressReporter.js.map +1 -0
- package/dist/common/pythonVersion.d.ts +20 -0
- package/dist/common/pythonVersion.js +71 -0
- package/dist/common/pythonVersion.js.map +1 -0
- package/dist/common/realFileSystem.d.ts +8 -0
- package/dist/common/realFileSystem.js +368 -0
- package/dist/common/realFileSystem.js.map +1 -0
- package/dist/common/stringUtils.d.ts +47 -0
- package/dist/common/stringUtils.js +160 -0
- package/dist/common/stringUtils.js.map +1 -0
- package/dist/common/textEditUtils.d.ts +3 -0
- package/dist/common/textEditUtils.js +29 -0
- package/dist/common/textEditUtils.js.map +1 -0
- package/dist/common/textRange.d.ts +47 -0
- package/dist/common/textRange.js +211 -0
- package/dist/common/textRange.js.map +1 -0
- package/dist/common/textRangeCollection.d.ts +13 -0
- package/dist/common/textRangeCollection.js +108 -0
- package/dist/common/textRangeCollection.js.map +1 -0
- package/dist/common/timing.d.ts +31 -0
- package/dist/common/timing.js +100 -0
- package/dist/common/timing.js.map +1 -0
- package/dist/common/uriParser.d.ts +12 -0
- package/dist/common/uriParser.js +25 -0
- package/dist/common/uriParser.js.map +1 -0
- package/dist/common/workspaceEditUtils.d.ts +7 -0
- package/dist/common/workspaceEditUtils.js +63 -0
- package/dist/common/workspaceEditUtils.js.map +1 -0
- package/dist/languageServerBase.d.ts +211 -0
- package/dist/languageServerBase.js +923 -0
- package/dist/languageServerBase.js.map +1 -0
- package/dist/languageService/analyzerServiceExecutor.d.ts +8 -0
- package/dist/languageService/analyzerServiceExecutor.js +97 -0
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -0
- package/dist/languageService/autoImporter.d.ts +84 -0
- package/dist/languageService/autoImporter.js +635 -0
- package/dist/languageService/autoImporter.js.map +1 -0
- package/dist/languageService/callHierarchyProvider.d.ts +12 -0
- package/dist/languageService/callHierarchyProvider.js +368 -0
- package/dist/languageService/callHierarchyProvider.js.map +1 -0
- package/dist/languageService/codeActionProvider.d.ts +6 -0
- package/dist/languageService/codeActionProvider.js +53 -0
- package/dist/languageService/codeActionProvider.js.map +1 -0
- package/dist/languageService/completionProvider.d.ts +147 -0
- package/dist/languageService/completionProvider.js +2220 -0
- package/dist/languageService/completionProvider.js.map +1 -0
- package/dist/languageService/definitionProvider.d.ts +17 -0
- package/dist/languageService/definitionProvider.js +206 -0
- package/dist/languageService/definitionProvider.js.map +1 -0
- package/dist/languageService/documentHighlightProvider.d.ts +7 -0
- package/dist/languageService/documentHighlightProvider.js +63 -0
- package/dist/languageService/documentHighlightProvider.js.map +1 -0
- package/dist/languageService/documentSymbolCollector.d.ts +37 -0
- package/dist/languageService/documentSymbolCollector.js +344 -0
- package/dist/languageService/documentSymbolCollector.js.map +1 -0
- package/dist/languageService/documentSymbolProvider.d.ts +37 -0
- package/dist/languageService/documentSymbolProvider.js +308 -0
- package/dist/languageService/documentSymbolProvider.js.map +1 -0
- package/dist/languageService/hoverProvider.d.ts +25 -0
- package/dist/languageService/hoverProvider.js +366 -0
- package/dist/languageService/hoverProvider.js.map +1 -0
- package/dist/languageService/importAdder.d.ts +24 -0
- package/dist/languageService/importAdder.js +296 -0
- package/dist/languageService/importAdder.js.map +1 -0
- package/dist/languageService/importSorter.d.ts +15 -0
- package/dist/languageService/importSorter.js +152 -0
- package/dist/languageService/importSorter.js.map +1 -0
- package/dist/languageService/indentationUtils.d.ts +4 -0
- package/dist/languageService/indentationUtils.js +597 -0
- package/dist/languageService/indentationUtils.js.map +1 -0
- package/dist/languageService/quickActions.d.ts +4 -0
- package/dist/languageService/quickActions.js +97 -0
- package/dist/languageService/quickActions.js.map +1 -0
- package/dist/languageService/referencesProvider.d.ts +36 -0
- package/dist/languageService/referencesProvider.js +236 -0
- package/dist/languageService/referencesProvider.js.map +1 -0
- package/dist/languageService/renameModuleProvider.d.ts +58 -0
- package/dist/languageService/renameModuleProvider.js +884 -0
- package/dist/languageService/renameModuleProvider.js.map +1 -0
- package/dist/languageService/signatureHelpProvider.d.ts +26 -0
- package/dist/languageService/signatureHelpProvider.js +180 -0
- package/dist/languageService/signatureHelpProvider.js.map +1 -0
- package/dist/languageService/tooltipUtils.d.ts +9 -0
- package/dist/languageService/tooltipUtils.js +129 -0
- package/dist/languageService/tooltipUtils.js.map +1 -0
- package/dist/localization/localize.d.ts +1324 -0
- package/dist/localization/localize.js +788 -0
- package/dist/localization/localize.js.map +1 -0
- package/dist/localization/package.nls.de.json +1 -0
- package/dist/localization/package.nls.en-us.json +636 -0
- package/dist/localization/package.nls.es.json +1 -0
- package/dist/localization/package.nls.fr.json +1 -0
- package/dist/localization/package.nls.ja.json +1 -0
- package/dist/localization/package.nls.ru.json +1 -0
- package/dist/localization/package.nls.zh-cn.json +1 -0
- package/dist/localization/package.nls.zh-tw.json +1 -0
- package/dist/nodeMain.d.ts +1 -0
- package/dist/nodeMain.js +21 -0
- package/dist/nodeMain.js.map +1 -0
- package/dist/nodeServer.d.ts +3 -0
- package/dist/nodeServer.js +31 -0
- package/dist/nodeServer.js.map +1 -0
- package/dist/parser/characterStream.d.ts +27 -0
- package/dist/parser/characterStream.js +120 -0
- package/dist/parser/characterStream.js.map +1 -0
- package/dist/parser/characters.d.ts +17 -0
- package/dist/parser/characters.js +240 -0
- package/dist/parser/characters.js.map +1 -0
- package/dist/parser/parseNodes.d.ts +750 -0
- package/dist/parser/parseNodes.js +1406 -0
- package/dist/parser/parseNodes.js.map +1 -0
- package/dist/parser/parser.d.ts +191 -0
- package/dist/parser/parser.js +3806 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/stringTokenUtils.d.ts +25 -0
- package/dist/parser/stringTokenUtils.js +455 -0
- package/dist/parser/stringTokenUtils.js.map +1 -0
- package/dist/parser/tokenizer.d.ts +71 -0
- package/dist/parser/tokenizer.js +1111 -0
- package/dist/parser/tokenizer.js.map +1 -0
- package/dist/parser/tokenizerTypes.d.ts +223 -0
- package/dist/parser/tokenizerTypes.js +164 -0
- package/dist/parser/tokenizerTypes.js.map +1 -0
- package/dist/parser/unicode.d.ts +23 -0
- package/dist/parser/unicode.js +2899 -0
- package/dist/parser/unicode.js.map +1 -0
- package/dist/pyright.d.ts +1 -0
- package/dist/pyright.js +645 -0
- package/dist/pyright.js.map +1 -0
- package/dist/pyrightFileSystem.d.ts +28 -0
- package/dist/pyrightFileSystem.js +196 -0
- package/dist/pyrightFileSystem.js.map +1 -0
- package/dist/readonlyAugmentedFileSystem.d.ts +40 -0
- package/dist/readonlyAugmentedFileSystem.js +155 -0
- package/dist/readonlyAugmentedFileSystem.js.map +1 -0
- package/dist/server.d.ts +21 -0
- package/dist/server.js +232 -0
- package/dist/server.js.map +1 -0
- package/dist/tests/chainedSourceFiles.test.d.ts +1 -0
- package/dist/tests/chainedSourceFiles.test.js +153 -0
- package/dist/tests/chainedSourceFiles.test.js.map +1 -0
- package/dist/tests/checker.test.d.ts +1 -0
- package/dist/tests/checker.test.js +346 -0
- package/dist/tests/checker.test.js.map +1 -0
- package/dist/tests/collectionUtils.test.d.ts +1 -0
- package/dist/tests/collectionUtils.test.js +153 -0
- package/dist/tests/collectionUtils.test.js.map +1 -0
- package/dist/tests/common.test.d.ts +1 -0
- package/dist/tests/common.test.js +125 -0
- package/dist/tests/common.test.js.map +1 -0
- package/dist/tests/config.test.d.ts +1 -0
- package/dist/tests/config.test.js +230 -0
- package/dist/tests/config.test.js.map +1 -0
- package/dist/tests/debug.test.d.ts +1 -0
- package/dist/tests/debug.test.js +102 -0
- package/dist/tests/debug.test.js.map +1 -0
- package/dist/tests/deferred.test.d.ts +1 -0
- package/dist/tests/deferred.test.js +65 -0
- package/dist/tests/deferred.test.js.map +1 -0
- package/dist/tests/diagnosticOverrides.test.d.ts +1 -0
- package/dist/tests/diagnosticOverrides.test.js +108 -0
- package/dist/tests/diagnosticOverrides.test.js.map +1 -0
- package/dist/tests/docStringConversion.test.d.ts +1 -0
- package/dist/tests/docStringConversion.test.js +695 -0
- package/dist/tests/docStringConversion.test.js.map +1 -0
- package/dist/tests/docStringUtils.test.d.ts +1 -0
- package/dist/tests/docStringUtils.test.js +70 -0
- package/dist/tests/docStringUtils.test.js.map +1 -0
- package/dist/tests/documentSymbolCollector.test.d.ts +1 -0
- package/dist/tests/documentSymbolCollector.test.js +635 -0
- package/dist/tests/documentSymbolCollector.test.js.map +1 -0
- package/dist/tests/filesystem.test.d.ts +1 -0
- package/dist/tests/filesystem.test.js +194 -0
- package/dist/tests/filesystem.test.js.map +1 -0
- package/dist/tests/fourSlashParser.test.d.ts +1 -0
- package/dist/tests/fourSlashParser.test.js +281 -0
- package/dist/tests/fourSlashParser.test.js.map +1 -0
- package/dist/tests/fourSlashRunner.test.d.ts +1 -0
- package/dist/tests/fourSlashRunner.test.js +52 -0
- package/dist/tests/fourSlashRunner.test.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.Found.Type.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.Found.Type.fourslash.js +30 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.Found.Type.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.Found.duplication.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.Found.duplication.fourslash.js +42 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.Found.duplication.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.NotFound.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.NotFound.fourslash.js +13 -0
- package/dist/tests/fourslash/completions.autoimport.Lib.NotFound.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.disabled.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.disabled.fourslash.js +23 -0
- package/dist/tests/fourslash/completions.autoimport.disabled.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.duplicates.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.duplicates.fourslash.js +35 -0
- package/dist/tests/fourslash/completions.autoimport.duplicates.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.fourslash.js +27 -0
- package/dist/tests/fourslash/completions.autoimport.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.fromImport.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.fromImport.fourslash.js +128 -0
- package/dist/tests/fourslash/completions.autoimport.fromImport.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.plainText.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.plainText.fourslash.js +27 -0
- package/dist/tests/fourslash/completions.autoimport.plainText.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js +43 -0
- package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.submodule.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.submodule.fourslash.js +29 -0
- package/dist/tests/fourslash/completions.autoimport.submodule.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.autoimport.topLevel.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.topLevel.fourslash.js +50 -0
- package/dist/tests/fourslash/completions.autoimport.topLevel.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.js +116 -0
- package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.builtinOverride.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.builtinOverride.fourslash.js +21 -0
- package/dist/tests/fourslash/completions.builtinOverride.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.call.stringLiteral.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.call.stringLiteral.fourslash.js +54 -0
- package/dist/tests/fourslash/completions.call.stringLiteral.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.call.typedDict.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.call.typedDict.fourslash.js +245 -0
- package/dist/tests/fourslash/completions.call.typedDict.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.call.typedDict.list.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.call.typedDict.list.fourslash.js +162 -0
- package/dist/tests/fourslash/completions.call.typedDict.list.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.call.typedDict.states.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.call.typedDict.states.fourslash.js +132 -0
- package/dist/tests/fourslash/completions.call.typedDict.states.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.classVariable.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.classVariable.fourslash.js +37 -0
- package/dist/tests/fourslash/completions.classVariable.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.comment.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.comment.fourslash.js +27 -0
- package/dist/tests/fourslash/completions.comment.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.class.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.class.fourslash.js +30 -0
- package/dist/tests/fourslash/completions.declNames.class.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.exception.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.exception.fourslash.js +18 -0
- package/dist/tests/fourslash/completions.declNames.exception.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.for.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.for.fourslash.js +26 -0
- package/dist/tests/fourslash/completions.declNames.for.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.importAlias.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.importAlias.fourslash.js +15 -0
- package/dist/tests/fourslash/completions.declNames.importAlias.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.lambda.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.lambda.fourslash.js +36 -0
- package/dist/tests/fourslash/completions.declNames.lambda.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.method.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.method.fourslash.js +68 -0
- package/dist/tests/fourslash/completions.declNames.method.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.overload.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.overload.fourslash.js +147 -0
- package/dist/tests/fourslash/completions.declNames.overload.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.declNames.topLevelOverload.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.declNames.topLevelOverload.fourslash.js +131 -0
- package/dist/tests/fourslash/completions.declNames.topLevelOverload.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js +73 -0
- package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js +58 -0
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js +154 -0
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js +143 -0
- package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js +109 -0
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js +50 -0
- package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.enums.members.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.enums.members.fourslash.js +44 -0
- package/dist/tests/fourslash/completions.enums.members.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.excluded.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.excluded.fourslash.js +12 -0
- package/dist/tests/fourslash/completions.excluded.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.fourslash.js +51 -0
- package/dist/tests/fourslash/completions.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.fstring.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.fstring.fourslash.js +32 -0
- package/dist/tests/fourslash/completions.fstring.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js +96 -0
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.fuzzyMatching.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.fuzzyMatching.fourslash.js +30 -0
- package/dist/tests/fourslash/completions.fuzzyMatching.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.importDunderNames.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.importDunderNames.fourslash.js +29 -0
- package/dist/tests/fourslash/completions.importDunderNames.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.importSubmodule.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.importSubmodule.fourslash.js +22 -0
- package/dist/tests/fourslash/completions.importSubmodule.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.importsDuplicates.fourslash.d.ts +0 -0
- package/dist/tests/fourslash/completions.importsDuplicates.fourslash.js +22 -0
- package/dist/tests/fourslash/completions.importsDuplicates.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.inList.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.inList.fourslash.js +32 -0
- package/dist/tests/fourslash/completions.inList.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.included.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.included.fourslash.js +12 -0
- package/dist/tests/fourslash/completions.included.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js +54 -0
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.inherited.function.docFromStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.inherited.function.docFromStub.fourslash.js +26 -0
- package/dist/tests/fourslash/completions.inherited.function.docFromStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.inherited.overload.docFromScrWithStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.inherited.overload.docFromScrWithStub.fourslash.js +49 -0
- package/dist/tests/fourslash/completions.inherited.overload.docFromScrWithStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.inherited.overload.docFromStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.inherited.overload.docFromStub.fourslash.js +50 -0
- package/dist/tests/fourslash/completions.inherited.overload.docFromStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.inherited.property.docFromSrc.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.inherited.property.docFromSrc.fourslash.js +101 -0
- package/dist/tests/fourslash/completions.inherited.property.docFromSrc.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.inherited.property.docFromStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.inherited.property.docFromStub.fourslash.js +105 -0
- package/dist/tests/fourslash/completions.inherited.property.docFromStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.keywords.pythonVersion.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.keywords.pythonVersion.fourslash.js +67 -0
- package/dist/tests/fourslash/completions.keywords.pythonVersion.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.js +75 -0
- package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.js +66 -0
- package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.libStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.libStub.fourslash.js +66 -0
- package/dist/tests/fourslash/completions.libStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.literals.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.literals.fourslash.js +31 -0
- package/dist/tests/fourslash/completions.literals.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.localCode.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.localCode.fourslash.js +71 -0
- package/dist/tests/fourslash/completions.localCode.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.moduleContext.UnknownMemberOnInstance.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.moduleContext.UnknownMemberOnInstance.fourslash.js +17 -0
- package/dist/tests/fourslash/completions.moduleContext.UnknownMemberOnInstance.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.moduleContext.UnknownStaticFunctionOnClass.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.moduleContext.UnknownStaticFunctionOnClass.fourslash.js +57 -0
- package/dist/tests/fourslash/completions.moduleContext.UnknownStaticFunctionOnClass.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.moduleContext.libCodeNoStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.moduleContext.libCodeNoStub.fourslash.js +27 -0
- package/dist/tests/fourslash/completions.moduleContext.libCodeNoStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.overloads.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.overloads.fourslash.js +37 -0
- package/dist/tests/fourslash/completions.overloads.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.default.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.default.fourslash.js +47 -0
- package/dist/tests/fourslash/completions.override.default.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.default.importStub.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.default.importStub.js +49 -0
- package/dist/tests/fourslash/completions.override.default.importStub.js.map +1 -0
- package/dist/tests/fourslash/completions.override.default.imported.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.default.imported.fourslash.js +60 -0
- package/dist/tests/fourslash/completions.override.default.imported.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.default.stub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.default.stub.fourslash.js +47 -0
- package/dist/tests/fourslash/completions.override.default.stub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.fourslash.js +47 -0
- package/dist/tests/fourslash/completions.override.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.property.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.property.fourslash.js +31 -0
- package/dist/tests/fourslash/completions.override.property.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.property.stub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.property.stub.fourslash.js +31 -0
- package/dist/tests/fourslash/completions.override.property.stub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.staticAndClassmethod.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.staticAndClassmethod.fourslash.js +63 -0
- package/dist/tests/fourslash/completions.override.staticAndClassmethod.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override.stub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override.stub.fourslash.js +47 -0
- package/dist/tests/fourslash/completions.override.stub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.override2.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.override2.fourslash.js +66 -0
- package/dist/tests/fourslash/completions.override2.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.parameters.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.parameters.fourslash.js +22 -0
- package/dist/tests/fourslash/completions.parameters.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.params.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.params.fourslash.js +23 -0
- package/dist/tests/fourslash/completions.params.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.parentFolder.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.parentFolder.fourslash.js +15 -0
- package/dist/tests/fourslash/completions.parentFolder.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.parentFolders.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.parentFolders.fourslash.js +68 -0
- package/dist/tests/fourslash/completions.parentFolders.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.plainText.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.plainText.fourslash.js +34 -0
- package/dist/tests/fourslash/completions.plainText.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.private.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.private.fourslash.js +61 -0
- package/dist/tests/fourslash/completions.private.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.property.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.property.fourslash.js +28 -0
- package/dist/tests/fourslash/completions.property.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.propertyDocStrings.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.propertyDocStrings.fourslash.js +64 -0
- package/dist/tests/fourslash/completions.propertyDocStrings.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.self.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.self.fourslash.js +43 -0
- package/dist/tests/fourslash/completions.self.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.stringLiteral.escape.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.stringLiteral.escape.fourslash.js +71 -0
- package/dist/tests/fourslash/completions.stringLiteral.escape.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.stringLiteral.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.stringLiteral.fourslash.js +78 -0
- package/dist/tests/fourslash/completions.stringLiteral.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.typeAlias.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.typeAlias.fourslash.js +29 -0
- package/dist/tests/fourslash/completions.typeAlias.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.typeshed.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.typeshed.fourslash.js +9 -0
- package/dist/tests/fourslash/completions.typeshed.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.vardecls.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.vardecls.fourslash.js +33 -0
- package/dist/tests/fourslash/completions.vardecls.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.variableDocStrings.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.variableDocStrings.fourslash.js +68 -0
- package/dist/tests/fourslash/completions.variableDocStrings.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.wildcardimports.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.wildcardimports.fourslash.js +109 -0
- package/dist/tests/fourslash/completions.wildcardimports.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.with.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.with.fourslash.js +25 -0
- package/dist/tests/fourslash/completions.with.fourslash.js.map +1 -0
- package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js +64 -0
- package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.builtinClass.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.builtinClass.fourslash.js +24 -0
- package/dist/tests/fourslash/findDefinitions.builtinClass.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.classes.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.classes.fourslash.js +93 -0
- package/dist/tests/fourslash/findDefinitions.classes.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferSource.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferSource.fourslash.js +23 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferSource.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferSource.onlyStubs.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferSource.onlyStubs.js +19 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferSource.onlyStubs.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferStub.fourslash.js +23 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferStub.onlySource.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferStub.onlySource.fourslash.js +20 -0
- package/dist/tests/fourslash/findDefinitions.definitionFilter.preferStub.onlySource.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.fields.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.fields.fourslash.js +123 -0
- package/dist/tests/fourslash/findDefinitions.fields.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.functions.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.functions.fourslash.js +79 -0
- package/dist/tests/fourslash/findDefinitions.functions.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.methods.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.methods.fourslash.js +154 -0
- package/dist/tests/fourslash/findDefinitions.methods.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.modules.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.modules.fourslash.js +42 -0
- package/dist/tests/fourslash/findDefinitions.modules.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.namespaceImport.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.namespaceImport.fourslash.js +34 -0
- package/dist/tests/fourslash/findDefinitions.namespaceImport.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.overloads.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.overloads.fourslash.js +213 -0
- package/dist/tests/fourslash/findDefinitions.overloads.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.parameters.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.parameters.fourslash.js +154 -0
- package/dist/tests/fourslash/findDefinitions.parameters.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.function.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.function.fourslash.js +23 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.function.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.innerClass.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.innerClass.fourslash.js +29 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.innerClass.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.innerClassMethod.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.innerClassMethod.fourslash.js +30 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.innerClassMethod.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClass.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClass.fourslash.js +25 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClass.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassMethod.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassMethod.fourslash.js +26 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassMethod.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadOnly.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadOnly.fourslash.js +28 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadOnly.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadWrite.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadWrite.fourslash.js +33 -0
- package/dist/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadWrite.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.class.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.class.fourslash.js +26 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.class.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.function1.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.function1.fourslash.js +25 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.function1.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.function2.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.function2.fourslash.js +25 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.function2.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.relativeImport1.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.relativeImport1.fourslash.js +20 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.relativeImport1.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.relativeImport2.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.relativeImport2.fourslash.js +20 -0
- package/dist/tests/fourslash/findDefinitions.sourceOnly.relativeImport2.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.stubOnly.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.stubOnly.fourslash.js +59 -0
- package/dist/tests/fourslash/findDefinitions.stubOnly.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.stubPackages.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.stubPackages.fourslash.js +59 -0
- package/dist/tests/fourslash/findDefinitions.stubPackages.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.typedDict.keys.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.typedDict.keys.fourslash.js +94 -0
- package/dist/tests/fourslash/findDefinitions.typedDict.keys.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.variables.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.variables.fourslash.js +79 -0
- package/dist/tests/fourslash/findDefinitions.variables.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findDefinitions.wildcardimports.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.wildcardimports.fourslash.js +106 -0
- package/dist/tests/fourslash/findDefinitions.wildcardimports.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findTypeDefinitions.builtinClass.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findTypeDefinitions.builtinClass.fourslash.js +24 -0
- package/dist/tests/fourslash/findTypeDefinitions.builtinClass.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findTypeDefinitions.classes.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findTypeDefinitions.classes.fourslash.js +66 -0
- package/dist/tests/fourslash/findTypeDefinitions.classes.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findTypeDefinitions.unions.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findTypeDefinitions.unions.fourslash.js +26 -0
- package/dist/tests/fourslash/findTypeDefinitions.unions.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.classPropertyReadWrite.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.classPropertyReadWrite.js +36 -0
- package/dist/tests/fourslash/findallreferences.classPropertyReadWrite.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.fourslash.js +30 -0
- package/dist/tests/fourslash/findallreferences.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.importalias.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.importalias.fourslash.js +30 -0
- package/dist/tests/fourslash/findallreferences.importalias.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.invokedFromLibrary.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.invokedFromLibrary.fourslash.js +46 -0
- package/dist/tests/fourslash/findallreferences.invokedFromLibrary.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.module.nested.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.module.nested.fourslash.js +60 -0
- package/dist/tests/fourslash/findallreferences.module.nested.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.modules.duplicated.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.modules.duplicated.fourslash.js +54 -0
- package/dist/tests/fourslash/findallreferences.modules.duplicated.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.modules.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.modules.fourslash.js +41 -0
- package/dist/tests/fourslash/findallreferences.modules.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.modules.shadow.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.modules.shadow.fourslash.js +83 -0
- package/dist/tests/fourslash/findallreferences.modules.shadow.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.openFiles.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.openFiles.fourslash.js +32 -0
- package/dist/tests/fourslash/findallreferences.openFiles.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.parameter.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.parameter.fourslash.js +22 -0
- package/dist/tests/fourslash/findallreferences.parameter.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.class.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.class.fourslash.js +29 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.class.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classMethod.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classMethod.fourslash.js +33 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classMethod.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadOnly.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadOnly.fourslash.js +36 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadOnly.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadWrite.fourslash.skip.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadWrite.fourslash.skip.js +44 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadWrite.fourslash.skip.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.function.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.function.fourslash.js +31 -0
- package/dist/tests/fourslash/findallreferences.sourceAndStub.function.fourslash.js.map +1 -0
- package/dist/tests/fourslash/findallreferences.variable.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.variable.fourslash.js +22 -0
- package/dist/tests/fourslash/findallreferences.variable.fourslash.js.map +1 -0
- package/dist/tests/fourslash/fourslash.d.ts +301 -0
- package/dist/tests/fourslash/fourslash.js +25 -0
- package/dist/tests/fourslash/fourslash.js.map +1 -0
- package/dist/tests/fourslash/highlightreferences.attributes.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/highlightreferences.attributes.fourslash.js +30 -0
- package/dist/tests/fourslash/highlightreferences.attributes.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.js +63 -0
- package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.classNoInit.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.classNoInit.fourslash.js +14 -0
- package/dist/tests/fourslash/hover.classNoInit.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromScr.stringFormat.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromScr.stringFormat.fourslash.js +47 -0
- package/dist/tests/fourslash/hover.docFromScr.stringFormat.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.fourslash.js +77 -0
- package/dist/tests/fourslash/hover.docFromSrc.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.js +22 -0
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js +22 -0
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.js +21 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js +20 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js +38 -0
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js +25 -0
- package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.js +18 -0
- package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docstring.links.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docstring.links.fourslash.js +12 -0
- package/dist/tests/fourslash/hover.docstring.links.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docstring.overloads.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docstring.overloads.fourslash.js +38 -0
- package/dist/tests/fourslash/hover.docstring.overloads.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docstring.split.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docstring.split.fourslash.js +24 -0
- package/dist/tests/fourslash/hover.docstring.split.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.fourslash.js +20 -0
- package/dist/tests/fourslash/hover.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.import.django.view.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.import.django.view.fourslash.js +23 -0
- package/dist/tests/fourslash/hover.import.django.view.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.import.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.import.fourslash.js +10 -0
- package/dist/tests/fourslash/hover.import.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js +61 -0
- package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.js +51 -0
- package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js +40 -0
- package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inherited.overload.docFromSrcWithStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inherited.overload.docFromSrcWithStub.fourslash.js +43 -0
- package/dist/tests/fourslash/hover.inherited.overload.docFromSrcWithStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inherited.overload.docFromStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inherited.overload.docFromStub.fourslash.js +44 -0
- package/dist/tests/fourslash/hover.inherited.overload.docFromStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inherited.property.docFromSrcWithStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inherited.property.docFromSrcWithStub.fourslash.js +84 -0
- package/dist/tests/fourslash/hover.inherited.property.docFromSrcWithStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.inherited.property.docFromStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.inherited.property.docFromStub.fourslash.js +88 -0
- package/dist/tests/fourslash/hover.inherited.property.docFromStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.init.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.init.fourslash.js +38 -0
- package/dist/tests/fourslash/hover.init.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.js +49 -0
- package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.js +39 -0
- package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.libStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.libStub.fourslash.js +39 -0
- package/dist/tests/fourslash/hover.libStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.optionalAliasParameter.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.optionalAliasParameter.fourslash.js +14 -0
- package/dist/tests/fourslash/hover.optionalAliasParameter.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.plainText.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.plainText.fourslash.js +20 -0
- package/dist/tests/fourslash/hover.plainText.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.typedDict.key.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.typedDict.key.fourslash.js +50 -0
- package/dist/tests/fourslash/hover.typedDict.key.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.variable.docString.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.variable.docString.fourslash.js +35 -0
- package/dist/tests/fourslash/hover.variable.docString.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.wildcardimports.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.wildcardimports.fourslash.js +73 -0
- package/dist/tests/fourslash/hover.wildcardimports.fourslash.js.map +1 -0
- package/dist/tests/fourslash/import.publicSymbols.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.publicSymbols.fourslash.js +63 -0
- package/dist/tests/fourslash/import.publicSymbols.fourslash.js.map +1 -0
- package/dist/tests/fourslash/import.pytyped.dunderAll.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.pytyped.dunderAll.fourslash.js +72 -0
- package/dist/tests/fourslash/import.pytyped.dunderAll.fourslash.js.map +1 -0
- package/dist/tests/fourslash/import.pytyped.privateSymbols.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.pytyped.privateSymbols.fourslash.js +61 -0
- package/dist/tests/fourslash/import.pytyped.privateSymbols.fourslash.js.map +1 -0
- package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.js +35 -0
- package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.js.map +1 -0
- package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.js +35 -0
- package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.js.map +1 -0
- package/dist/tests/fourslash/import.wildcard.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.wildcard.fourslash.js +24 -0
- package/dist/tests/fourslash/import.wildcard.fourslash.js.map +1 -0
- package/dist/tests/fourslash/importnotresolved.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/importnotresolved.fourslash.js +13 -0
- package/dist/tests/fourslash/importnotresolved.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingModuleSource.disablingInStrictMode.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/missingModuleSource.disablingInStrictMode.fourslash.js +18 -0
- package/dist/tests/fourslash/missingModuleSource.disablingInStrictMode.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingModuleSource.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/missingModuleSource.fourslash.js +13 -0
- package/dist/tests/fourslash/missingModuleSource.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.js +31 -0
- package/dist/tests/fourslash/missingTypeStub.codeAction.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingTypeStub.command.multipart.fourslash.d.ts +7 -0
- package/dist/tests/fourslash/missingTypeStub.command.multipart.fourslash.js +44 -0
- package/dist/tests/fourslash/missingTypeStub.command.multipart.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingTypeStub.command.singlefile.fourslash.d.ts +7 -0
- package/dist/tests/fourslash/missingTypeStub.command.singlefile.fourslash.js +35 -0
- package/dist/tests/fourslash/missingTypeStub.command.singlefile.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingTypeStub.command.singlepart.fourslash.d.ts +7 -0
- package/dist/tests/fourslash/missingTypeStub.command.singlepart.fourslash.js +35 -0
- package/dist/tests/fourslash/missingTypeStub.command.singlepart.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingTypeStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/missingTypeStub.fourslash.js +18 -0
- package/dist/tests/fourslash/missingTypeStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/missingTypeStub.invokeCodeAction.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/missingTypeStub.invokeCodeAction.fourslash.js +34 -0
- package/dist/tests/fourslash/missingTypeStub.invokeCodeAction.fourslash.js.map +1 -0
- package/dist/tests/fourslash/noerrors.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/noerrors.fourslash.js +9 -0
- package/dist/tests/fourslash/noerrors.fourslash.js.map +1 -0
- package/dist/tests/fourslash/orderImports1.command.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/orderImports1.command.fourslash.js +17 -0
- package/dist/tests/fourslash/orderImports1.command.fourslash.js.map +1 -0
- package/dist/tests/fourslash/orderImports2.command.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/orderImports2.command.fourslash.js +21 -0
- package/dist/tests/fourslash/orderImports2.command.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.externallyHidden.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.externallyHidden.fourslash.js +23 -0
- package/dist/tests/fourslash/rename.externallyHidden.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.js +23 -0
- package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.fourslash.js +26 -0
- package/dist/tests/fourslash/rename.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.library.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.library.fourslash.js +26 -0
- package/dist/tests/fourslash/rename.library.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.library.sourceAndStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.library.sourceAndStub.fourslash.js +29 -0
- package/dist/tests/fourslash/rename.library.sourceAndStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.multipleDecl.fourslash.d.ts +2 -0
- package/dist/tests/fourslash/rename.multipleDecl.fourslash.js +19 -0
- package/dist/tests/fourslash/rename.multipleDecl.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.sourceAndStub.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.sourceAndStub.fourslash.js +33 -0
- package/dist/tests/fourslash/rename.sourceAndStub.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.string.excluded.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.string.excluded.fourslash.js +39 -0
- package/dist/tests/fourslash/rename.string.excluded.fourslash.js.map +1 -0
- package/dist/tests/fourslash/rename.string.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.string.fourslash.js +25 -0
- package/dist/tests/fourslash/rename.string.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js +62 -0
- package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.complicated.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.complicated.fourslash.js +97 -0
- package/dist/tests/fourslash/signature.complicated.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.cornercases.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.cornercases.fourslash.js +22 -0
- package/dist/tests/fourslash/signature.cornercases.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.docstrings.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.docstrings.fourslash.js +42 -0
- package/dist/tests/fourslash/signature.docstrings.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.docstrings.overloaded.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.docstrings.overloaded.fourslash.js +49 -0
- package/dist/tests/fourslash/signature.docstrings.overloaded.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.docstrings.wildcardimports.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.docstrings.wildcardimports.fourslash.js +115 -0
- package/dist/tests/fourslash/signature.docstrings.wildcardimports.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.overload.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.overload.fourslash.js +63 -0
- package/dist/tests/fourslash/signature.overload.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.simple.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.simple.fourslash.js +104 -0
- package/dist/tests/fourslash/signature.simple.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/fourSlashParser.d.ts +10 -0
- package/dist/tests/harness/fourslash/fourSlashParser.js +347 -0
- package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -0
- package/dist/tests/harness/fourslash/fourSlashTypes.d.ts +81 -0
- package/dist/tests/harness/fourslash/fourSlashTypes.js +65 -0
- package/dist/tests/harness/fourslash/fourSlashTypes.js.map +1 -0
- package/dist/tests/harness/fourslash/runner.d.ts +20 -0
- package/dist/tests/harness/fourslash/runner.js +93 -0
- package/dist/tests/harness/fourslash/runner.js.map +1 -0
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +40 -0
- package/dist/tests/harness/fourslash/testLanguageService.js +120 -0
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -0
- package/dist/tests/harness/fourslash/testState.Consts.d.ts +11 -0
- package/dist/tests/harness/fourslash/testState.Consts.js +50 -0
- package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -0
- package/dist/tests/harness/fourslash/testState.d.ts +232 -0
- package/dist/tests/harness/fourslash/testState.js +1381 -0
- package/dist/tests/harness/fourslash/testState.js.map +1 -0
- package/dist/tests/harness/testAccessHost.d.ts +8 -0
- package/dist/tests/harness/testAccessHost.js +26 -0
- package/dist/tests/harness/testAccessHost.js.map +1 -0
- package/dist/tests/harness/testHost.d.ts +16 -0
- package/dist/tests/harness/testHost.js +161 -0
- package/dist/tests/harness/testHost.js.map +1 -0
- package/dist/tests/harness/utils.d.ts +74 -0
- package/dist/tests/harness/utils.js +328 -0
- package/dist/tests/harness/utils.js.map +1 -0
- package/dist/tests/harness/vfs/factory.d.ts +32 -0
- package/dist/tests/harness/vfs/factory.js +173 -0
- package/dist/tests/harness/vfs/factory.js.map +1 -0
- package/dist/tests/harness/vfs/filesystem.d.ts +430 -0
- package/dist/tests/harness/vfs/filesystem.js +1455 -0
- package/dist/tests/harness/vfs/filesystem.js.map +1 -0
- package/dist/tests/harness/vfs/pathValidation.d.ts +24 -0
- package/dist/tests/harness/vfs/pathValidation.js +123 -0
- package/dist/tests/harness/vfs/pathValidation.js.map +1 -0
- package/dist/tests/importAdder.test.d.ts +1 -0
- package/dist/tests/importAdder.test.js +1192 -0
- package/dist/tests/importAdder.test.js.map +1 -0
- package/dist/tests/importResolver.test.d.ts +1 -0
- package/dist/tests/importResolver.test.js +450 -0
- package/dist/tests/importResolver.test.js.map +1 -0
- package/dist/tests/importStatementUtils.test.d.ts +1 -0
- package/dist/tests/importStatementUtils.test.js +371 -0
- package/dist/tests/importStatementUtils.test.js.map +1 -0
- package/dist/tests/indentationUtils.ptvs.test.d.ts +1 -0
- package/dist/tests/indentationUtils.ptvs.test.js +324 -0
- package/dist/tests/indentationUtils.ptvs.test.js.map +1 -0
- package/dist/tests/indentationUtils.reindent.test.d.ts +1 -0
- package/dist/tests/indentationUtils.reindent.test.js +332 -0
- package/dist/tests/indentationUtils.reindent.test.js.map +1 -0
- package/dist/tests/indentationUtils.test.d.ts +1 -0
- package/dist/tests/indentationUtils.test.js +375 -0
- package/dist/tests/indentationUtils.test.js.map +1 -0
- package/dist/tests/ipythonMode.test.d.ts +1 -0
- package/dist/tests/ipythonMode.test.js +303 -0
- package/dist/tests/ipythonMode.test.js.map +1 -0
- package/dist/tests/localizer.test.d.ts +1 -0
- package/dist/tests/localizer.test.js +64 -0
- package/dist/tests/localizer.test.js.map +1 -0
- package/dist/tests/parseTreeUtils.test.d.ts +1 -0
- package/dist/tests/parseTreeUtils.test.js +228 -0
- package/dist/tests/parseTreeUtils.test.js.map +1 -0
- package/dist/tests/parser.test.d.ts +1 -0
- package/dist/tests/parser.test.js +101 -0
- package/dist/tests/parser.test.js.map +1 -0
- package/dist/tests/pathUtils.test.d.ts +1 -0
- package/dist/tests/pathUtils.test.js +253 -0
- package/dist/tests/pathUtils.test.js.map +1 -0
- package/dist/tests/pyrightFileSystem.test.d.ts +1 -0
- package/dist/tests/pyrightFileSystem.test.js +152 -0
- package/dist/tests/pyrightFileSystem.test.js.map +1 -0
- package/dist/tests/renameModule.folder.test.d.ts +1 -0
- package/dist/tests/renameModule.folder.test.js +229 -0
- package/dist/tests/renameModule.folder.test.js.map +1 -0
- package/dist/tests/renameModule.fromImports.test.d.ts +1 -0
- package/dist/tests/renameModule.fromImports.test.js +790 -0
- package/dist/tests/renameModule.fromImports.test.js.map +1 -0
- package/dist/tests/renameModule.imports.test.d.ts +1 -0
- package/dist/tests/renameModule.imports.test.js +380 -0
- package/dist/tests/renameModule.imports.test.js.map +1 -0
- package/dist/tests/renameModule.misc.test.d.ts +1 -0
- package/dist/tests/renameModule.misc.test.js +615 -0
- package/dist/tests/renameModule.misc.test.js.map +1 -0
- package/dist/tests/renameModule.relativePath.test.d.ts +1 -0
- package/dist/tests/renameModule.relativePath.test.js +231 -0
- package/dist/tests/renameModule.relativePath.test.js.map +1 -0
- package/dist/tests/renameModuleTestUtils.d.ts +4 -0
- package/dist/tests/renameModuleTestUtils.js +148 -0
- package/dist/tests/renameModuleTestUtils.js.map +1 -0
- package/dist/tests/sourceFile.test.d.ts +1 -0
- package/dist/tests/sourceFile.test.js +25 -0
- package/dist/tests/sourceFile.test.js.map +1 -0
- package/dist/tests/stringUtils.test.d.ts +1 -0
- package/dist/tests/stringUtils.test.js +69 -0
- package/dist/tests/stringUtils.test.js.map +1 -0
- package/dist/tests/symbolNameUtils.test.d.ts +1 -0
- package/dist/tests/symbolNameUtils.test.js +83 -0
- package/dist/tests/symbolNameUtils.test.js.map +1 -0
- package/dist/tests/testState.test.d.ts +1 -0
- package/dist/tests/testState.test.js +521 -0
- package/dist/tests/testState.test.js.map +1 -0
- package/dist/tests/testUtils.d.ts +27 -0
- package/dist/tests/testUtils.js +213 -0
- package/dist/tests/testUtils.js.map +1 -0
- package/dist/tests/tokenizer.test.d.ts +1 -0
- package/dist/tests/tokenizer.test.js +1277 -0
- package/dist/tests/tokenizer.test.js.map +1 -0
- package/dist/tests/typeEvaluator1.test.d.ts +1 -0
- package/dist/tests/typeEvaluator1.test.js +1023 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -0
- package/dist/tests/typeEvaluator2.test.d.ts +1 -0
- package/dist/tests/typeEvaluator2.test.js +869 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -0
- package/dist/tests/typeEvaluator3.test.d.ts +1 -0
- package/dist/tests/typeEvaluator3.test.js +915 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -0
- package/dist/tests/typeEvaluator4.test.d.ts +1 -0
- package/dist/tests/typeEvaluator4.test.js +901 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -0
- package/dist/tests/updateSymbolReference.test.d.ts +1 -0
- package/dist/tests/updateSymbolReference.test.js +980 -0
- package/dist/tests/updateSymbolReference.test.js.map +1 -0
- package/dist/tests/zipfs.test.d.ts +1 -0
- package/dist/tests/zipfs.test.js +112 -0
- package/dist/tests/zipfs.test.js.map +1 -0
- package/dist/workspaceMap.d.ts +6 -0
- package/dist/workspaceMap.js +73 -0
- package/dist/workspaceMap.js.map +1 -0
- package/package.json +45 -0
@@ -0,0 +1,3195 @@
|
|
1
|
+
"use strict";
|
2
|
+
/*
|
3
|
+
* binder.ts
|
4
|
+
* Copyright (c) Microsoft Corporation.
|
5
|
+
* Licensed under the MIT license.
|
6
|
+
* Author: Eric Traut
|
7
|
+
*
|
8
|
+
* A parse tree walker that performs basic name binding (creation of
|
9
|
+
* scopes and associated symbol tables).
|
10
|
+
* The binder walks the parse tree by scopes starting at the module
|
11
|
+
* level. When a new scope is detected, it is pushed onto a list and
|
12
|
+
* walked separately at a later time. (The exception is a class scope,
|
13
|
+
* which is immediately walked.) Walking the tree in this manner
|
14
|
+
* simulates the order in which execution normally occurs in a Python
|
15
|
+
* file. The binder attempts to statically detect runtime errors that
|
16
|
+
* would be reported by the python interpreter when executing the code.
|
17
|
+
* This binder doesn't perform any static type checking.
|
18
|
+
*/
|
19
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
20
|
+
if (k2 === undefined) k2 = k;
|
21
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
22
|
+
}) : (function(o, m, k, k2) {
|
23
|
+
if (k2 === undefined) k2 = k;
|
24
|
+
o[k2] = m[k];
|
25
|
+
}));
|
26
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
27
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
28
|
+
}) : function(o, v) {
|
29
|
+
o["default"] = v;
|
30
|
+
});
|
31
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
32
|
+
if (mod && mod.__esModule) return mod;
|
33
|
+
var result = {};
|
34
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
35
|
+
__setModuleDefault(result, mod);
|
36
|
+
return result;
|
37
|
+
};
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
+
exports.ReturnFinder = exports.YieldFinder = exports.Binder = void 0;
|
40
|
+
const collectionUtils_1 = require("../common/collectionUtils");
|
41
|
+
const debug_1 = require("../common/debug");
|
42
|
+
const diagnosticRules_1 = require("../common/diagnosticRules");
|
43
|
+
const pathUtils_1 = require("../common/pathUtils");
|
44
|
+
const positionUtils_1 = require("../common/positionUtils");
|
45
|
+
const textRange_1 = require("../common/textRange");
|
46
|
+
const textRange_2 = require("../common/textRange");
|
47
|
+
const localize_1 = require("../localization/localize");
|
48
|
+
const analyzerFileInfo_1 = require("./analyzerFileInfo");
|
49
|
+
const AnalyzerNodeInfo = __importStar(require("./analyzerNodeInfo"));
|
50
|
+
const codeFlowTypes_1 = require("./codeFlowTypes");
|
51
|
+
const ParseTreeUtils = __importStar(require("./parseTreeUtils"));
|
52
|
+
const parseTreeWalker_1 = require("./parseTreeWalker");
|
53
|
+
const scope_1 = require("./scope");
|
54
|
+
const StaticExpressions = __importStar(require("./staticExpressions"));
|
55
|
+
const symbol_1 = require("./symbol");
|
56
|
+
const symbolNameUtils_1 = require("./symbolNameUtils");
|
57
|
+
// For each flow node within an execution context, we'll add a small
|
58
|
+
// amount to the complexity factor. Without this, the complexity
|
59
|
+
// calculation fails to take into account large numbers of non-cyclical
|
60
|
+
// flow nodes. This number is somewhat arbitrary and is tuned empirically.
|
61
|
+
const flowNodeComplexityFactor = 0.05;
|
62
|
+
class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
63
|
+
constructor(fileInfo, _moduleSymbolOnly = false) {
|
64
|
+
super();
|
65
|
+
this._moduleSymbolOnly = _moduleSymbolOnly;
|
66
|
+
// A queue of deferred analysis operations.
|
67
|
+
this._deferredBindingTasks = [];
|
68
|
+
// Flow nodes used within try blocks.
|
69
|
+
this._currentExceptTargets = [];
|
70
|
+
// Flow nodes used within try/finally flows.
|
71
|
+
this._finallyTargets = [];
|
72
|
+
// Aliases of "typing" and "typing_extensions".
|
73
|
+
this._typingImportAliases = [];
|
74
|
+
// Aliases of "sys".
|
75
|
+
this._sysImportAliases = [];
|
76
|
+
// Aliases of "dataclasses".
|
77
|
+
this._dataclassesImportAliases = [];
|
78
|
+
// Map of imports of specific symbols imported from "typing" and "typing_extensions"
|
79
|
+
// and the names they alias to.
|
80
|
+
this._typingSymbolAliases = new Map();
|
81
|
+
// Map of imports of specific symbols imported from "dataclasses"
|
82
|
+
// and the names they alias to.
|
83
|
+
this._dataclassesSymbolAliases = new Map();
|
84
|
+
// List of string nodes associated with the "__all__" symbol.
|
85
|
+
this._dunderAllStringNodes = [];
|
86
|
+
// One or more statements are manipulating __all__ in a manner that a
|
87
|
+
// static analyzer doesn't understand.
|
88
|
+
this._usesUnsupportedDunderAllForm = false;
|
89
|
+
// Are we currently binding code located within an except block?
|
90
|
+
this._isInExceptSuite = false;
|
91
|
+
// Map of symbols at the module level that may be externally
|
92
|
+
// hidden depending on whether they are listed in the __all__ list.
|
93
|
+
this._potentialHiddenSymbols = new Map();
|
94
|
+
// Map of symbols at the module level that may be private depending
|
95
|
+
// on whether they are listed in the __all__ list.
|
96
|
+
this._potentialPrivateSymbols = new Map();
|
97
|
+
// Estimates the overall complexity of the code flow graph for
|
98
|
+
// the current function.
|
99
|
+
this._codeFlowComplexity = 0;
|
100
|
+
this._fileInfo = fileInfo;
|
101
|
+
}
|
102
|
+
bindModule(node) {
|
103
|
+
var _a;
|
104
|
+
// We'll assume that if there is no builtins scope provided, we must be
|
105
|
+
// binding the builtins module itself.
|
106
|
+
const isBuiltInModule = this._fileInfo.builtinsScope === undefined;
|
107
|
+
this._createNewScope(isBuiltInModule ? 4 /* Builtin */ : 3 /* Module */, this._fileInfo.builtinsScope, () => {
|
108
|
+
AnalyzerNodeInfo.setScope(node, this._currentScope);
|
109
|
+
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
110
|
+
// Bind implicit names.
|
111
|
+
// List taken from https://docs.python.org/3/reference/import.html#__name__
|
112
|
+
this._addImplicitSymbolToCurrentScope('__doc__', node, 'str | None');
|
113
|
+
this._addImplicitSymbolToCurrentScope('__name__', node, 'str');
|
114
|
+
this._addImplicitSymbolToCurrentScope('__qualname__', node, 'str');
|
115
|
+
this._addImplicitSymbolToCurrentScope('__loader__', node, 'Any');
|
116
|
+
this._addImplicitSymbolToCurrentScope('__package__', node, 'str');
|
117
|
+
this._addImplicitSymbolToCurrentScope('__spec__', node, 'Any');
|
118
|
+
this._addImplicitSymbolToCurrentScope('__path__', node, 'Iterable[str]');
|
119
|
+
this._addImplicitSymbolToCurrentScope('__file__', node, 'str');
|
120
|
+
this._addImplicitSymbolToCurrentScope('__cached__', node, 'str');
|
121
|
+
this._addImplicitSymbolToCurrentScope('__dict__', node, 'Dict[str, Any]');
|
122
|
+
this._addImplicitSymbolToCurrentScope('__annotations__', node, 'Dict[str, Any]');
|
123
|
+
this._addImplicitSymbolToCurrentScope('__builtins__', node, 'Any');
|
124
|
+
// Create a start node for the module.
|
125
|
+
this._currentFlowNode = this._createStartFlowNode();
|
126
|
+
this._walkStatementsAndReportUnreachable(node.statements);
|
127
|
+
// Associate the code flow node at the end of the module with the module.
|
128
|
+
AnalyzerNodeInfo.setAfterFlowNode(node, this._currentFlowNode);
|
129
|
+
AnalyzerNodeInfo.setCodeFlowExpressions(node, this._currentScopeCodeFlowExpressions);
|
130
|
+
AnalyzerNodeInfo.setCodeFlowComplexity(node, this._codeFlowComplexity);
|
131
|
+
});
|
132
|
+
// Perform all analysis that was deferred during the first pass.
|
133
|
+
this._bindDeferred();
|
134
|
+
// Use the __all__ list to determine whether any potential private
|
135
|
+
// symbols should be made externally hidden or private.
|
136
|
+
this._potentialHiddenSymbols.forEach((symbol, name) => {
|
137
|
+
var _a;
|
138
|
+
if (!((_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.some((sym) => sym === name))) {
|
139
|
+
if (this._fileInfo.isStubFile) {
|
140
|
+
symbol.setIsExternallyHidden();
|
141
|
+
}
|
142
|
+
else {
|
143
|
+
symbol.setPrivatePyTypedImport();
|
144
|
+
}
|
145
|
+
}
|
146
|
+
});
|
147
|
+
this._potentialPrivateSymbols.forEach((symbol, name) => {
|
148
|
+
var _a;
|
149
|
+
if (!((_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.some((sym) => sym === name))) {
|
150
|
+
symbol.setIsPrivateMember();
|
151
|
+
}
|
152
|
+
});
|
153
|
+
if (this._dunderAllNames) {
|
154
|
+
AnalyzerNodeInfo.setDunderAllInfo(node, {
|
155
|
+
names: this._dunderAllNames,
|
156
|
+
stringNodes: this._dunderAllStringNodes,
|
157
|
+
usesUnsupportedDunderAllForm: this._usesUnsupportedDunderAllForm,
|
158
|
+
});
|
159
|
+
}
|
160
|
+
else {
|
161
|
+
AnalyzerNodeInfo.setDunderAllInfo(node, /* names */ undefined);
|
162
|
+
}
|
163
|
+
// Set __all__ flags on the module symbols.
|
164
|
+
const scope = AnalyzerNodeInfo.getScope(node);
|
165
|
+
if (scope && this._dunderAllNames) {
|
166
|
+
for (const name of this._dunderAllNames) {
|
167
|
+
(_a = scope.symbolTable.get(name)) === null || _a === void 0 ? void 0 : _a.setIsInDunderAll();
|
168
|
+
}
|
169
|
+
}
|
170
|
+
}
|
171
|
+
visitModule(node) {
|
172
|
+
// Tree walking should start with the children of
|
173
|
+
// the node, so we should never get here.
|
174
|
+
(0, debug_1.fail)('We should never get here');
|
175
|
+
return false;
|
176
|
+
}
|
177
|
+
visitSuite(node) {
|
178
|
+
this._walkStatementsAndReportUnreachable(node.statements);
|
179
|
+
return false;
|
180
|
+
}
|
181
|
+
visitModuleName(node) {
|
182
|
+
const importResult = AnalyzerNodeInfo.getImportInfo(node);
|
183
|
+
(0, debug_1.assert)(importResult !== undefined);
|
184
|
+
if (importResult.isNativeLib) {
|
185
|
+
return true;
|
186
|
+
}
|
187
|
+
if (!importResult.isImportFound) {
|
188
|
+
this._addDiagnostic(this._fileInfo.diagnosticRuleSet.reportMissingImports, diagnosticRules_1.DiagnosticRule.reportMissingImports, localize_1.Localizer.Diagnostic.importResolveFailure().format({ importName: importResult.importName }), node);
|
189
|
+
return true;
|
190
|
+
}
|
191
|
+
// Source found, but type stub is missing
|
192
|
+
if (!importResult.isStubFile &&
|
193
|
+
importResult.importType === 1 /* ThirdParty */ &&
|
194
|
+
!importResult.pyTypedInfo) {
|
195
|
+
const diagnostic = this._addDiagnostic(this._fileInfo.diagnosticRuleSet.reportMissingTypeStubs, diagnosticRules_1.DiagnosticRule.reportMissingTypeStubs, localize_1.Localizer.Diagnostic.stubFileMissing().format({ importName: importResult.importName }), node);
|
196
|
+
if (diagnostic) {
|
197
|
+
// Add a diagnostic action for resolving this diagnostic.
|
198
|
+
const createTypeStubAction = {
|
199
|
+
action: "pyright.createtypestub" /* createTypeStub */,
|
200
|
+
moduleName: importResult.importName,
|
201
|
+
};
|
202
|
+
diagnostic.addAction(createTypeStubAction);
|
203
|
+
}
|
204
|
+
}
|
205
|
+
return true;
|
206
|
+
}
|
207
|
+
visitClass(node) {
|
208
|
+
this.walkMultiple(node.decorators);
|
209
|
+
const classDeclaration = {
|
210
|
+
type: 4 /* Class */,
|
211
|
+
node,
|
212
|
+
path: this._fileInfo.filePath,
|
213
|
+
range: (0, positionUtils_1.convertOffsetsToRange)(node.name.start, textRange_2.TextRange.getEnd(node.name), this._fileInfo.lines),
|
214
|
+
moduleName: this._fileInfo.moduleName,
|
215
|
+
isInExceptSuite: this._isInExceptSuite,
|
216
|
+
};
|
217
|
+
const symbol = this._bindNameToScope(this._currentScope, node.name.value);
|
218
|
+
if (symbol) {
|
219
|
+
symbol.addDeclaration(classDeclaration);
|
220
|
+
}
|
221
|
+
// Stash the declaration in the parse node for later access.
|
222
|
+
AnalyzerNodeInfo.setDeclaration(node, classDeclaration);
|
223
|
+
this.walkMultiple(node.arguments);
|
224
|
+
this._createNewScope(2 /* Class */, this._getNonClassParentScope(), () => {
|
225
|
+
AnalyzerNodeInfo.setScope(node, this._currentScope);
|
226
|
+
this._addImplicitSymbolToCurrentScope('__doc__', node, 'str | None');
|
227
|
+
this._addImplicitSymbolToCurrentScope('__module__', node, 'str');
|
228
|
+
this._dunderSlotsEntries = undefined;
|
229
|
+
if (!this._moduleSymbolOnly) {
|
230
|
+
// Analyze the suite.
|
231
|
+
this.walk(node.suite);
|
232
|
+
}
|
233
|
+
if (this._dunderSlotsEntries) {
|
234
|
+
this._addSlotsToCurrentScope(this._dunderSlotsEntries);
|
235
|
+
}
|
236
|
+
this._dunderSlotsEntries = undefined;
|
237
|
+
});
|
238
|
+
this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ false, /* unbound */ false);
|
239
|
+
return false;
|
240
|
+
}
|
241
|
+
visitFunction(node) {
|
242
|
+
this._createVariableAnnotationFlowNode();
|
243
|
+
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
244
|
+
const symbol = this._bindNameToScope(this._currentScope, node.name.value);
|
245
|
+
const containingClassNode = ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true);
|
246
|
+
const functionDeclaration = {
|
247
|
+
type: 3 /* Function */,
|
248
|
+
node,
|
249
|
+
isMethod: !!containingClassNode,
|
250
|
+
isGenerator: false,
|
251
|
+
path: this._fileInfo.filePath,
|
252
|
+
range: (0, positionUtils_1.convertOffsetsToRange)(node.name.start, textRange_2.TextRange.getEnd(node.name), this._fileInfo.lines),
|
253
|
+
moduleName: this._fileInfo.moduleName,
|
254
|
+
isInExceptSuite: this._isInExceptSuite,
|
255
|
+
};
|
256
|
+
if (symbol) {
|
257
|
+
symbol.addDeclaration(functionDeclaration);
|
258
|
+
}
|
259
|
+
// Stash the declaration in the parse node for later access.
|
260
|
+
AnalyzerNodeInfo.setDeclaration(node, functionDeclaration);
|
261
|
+
this.walkMultiple(node.decorators);
|
262
|
+
node.parameters.forEach((param) => {
|
263
|
+
if (param.defaultValue) {
|
264
|
+
this.walk(param.defaultValue);
|
265
|
+
}
|
266
|
+
if (param.typeAnnotation) {
|
267
|
+
this.walk(param.typeAnnotation);
|
268
|
+
}
|
269
|
+
if (param.typeAnnotationComment) {
|
270
|
+
this.walk(param.typeAnnotationComment);
|
271
|
+
}
|
272
|
+
});
|
273
|
+
if (node.returnTypeAnnotation) {
|
274
|
+
this.walk(node.returnTypeAnnotation);
|
275
|
+
}
|
276
|
+
if (node.functionAnnotationComment) {
|
277
|
+
this.walk(node.functionAnnotationComment);
|
278
|
+
}
|
279
|
+
// Don't walk the body of the function until we're done analyzing
|
280
|
+
// the current scope.
|
281
|
+
this._createNewScope(1 /* Function */, this._getNonClassParentScope(), () => {
|
282
|
+
AnalyzerNodeInfo.setScope(node, this._currentScope);
|
283
|
+
const enclosingClass = ParseTreeUtils.getEnclosingClass(node);
|
284
|
+
if (enclosingClass) {
|
285
|
+
// Add the implicit "__class__" symbol described in PEP 3135.
|
286
|
+
this._addImplicitSymbolToCurrentScope('__class__', node, 'class');
|
287
|
+
}
|
288
|
+
this._deferBinding(() => {
|
289
|
+
// Create a start node for the function.
|
290
|
+
this._currentFlowNode = this._createStartFlowNode();
|
291
|
+
this._codeFlowComplexity = 0;
|
292
|
+
node.parameters.forEach((paramNode) => {
|
293
|
+
if (paramNode.name) {
|
294
|
+
const symbol = this._bindNameToScope(this._currentScope, paramNode.name.value);
|
295
|
+
if (symbol) {
|
296
|
+
const paramDeclaration = {
|
297
|
+
type: 2 /* Parameter */,
|
298
|
+
node: paramNode,
|
299
|
+
path: this._fileInfo.filePath,
|
300
|
+
range: (0, positionUtils_1.convertOffsetsToRange)(paramNode.start, textRange_2.TextRange.getEnd(paramNode), this._fileInfo.lines),
|
301
|
+
moduleName: this._fileInfo.moduleName,
|
302
|
+
isInExceptSuite: this._isInExceptSuite,
|
303
|
+
};
|
304
|
+
symbol.addDeclaration(paramDeclaration);
|
305
|
+
AnalyzerNodeInfo.setDeclaration(paramNode.name, paramDeclaration);
|
306
|
+
}
|
307
|
+
this._createFlowAssignment(paramNode.name);
|
308
|
+
}
|
309
|
+
});
|
310
|
+
this._targetFunctionDeclaration = functionDeclaration;
|
311
|
+
this._currentReturnTarget = this._createBranchLabel();
|
312
|
+
// Walk the statements that make up the function.
|
313
|
+
this.walk(node.suite);
|
314
|
+
// Associate the code flow node at the end of the suite with
|
315
|
+
// the suite.
|
316
|
+
AnalyzerNodeInfo.setAfterFlowNode(node.suite, this._currentFlowNode);
|
317
|
+
// Compute the final return flow node and associate it with
|
318
|
+
// the function's parse node. If this node is unreachable, then
|
319
|
+
// the function never returns.
|
320
|
+
this._addAntecedent(this._currentReturnTarget, this._currentFlowNode);
|
321
|
+
const returnFlowNode = this._finishFlowLabel(this._currentReturnTarget);
|
322
|
+
AnalyzerNodeInfo.setAfterFlowNode(node, returnFlowNode);
|
323
|
+
AnalyzerNodeInfo.setCodeFlowExpressions(node, this._currentScopeCodeFlowExpressions);
|
324
|
+
AnalyzerNodeInfo.setCodeFlowComplexity(node, this._codeFlowComplexity);
|
325
|
+
});
|
326
|
+
});
|
327
|
+
this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ false, /* unbound */ false);
|
328
|
+
// We'll walk the child nodes in a deferred manner, so don't walk them now.
|
329
|
+
return false;
|
330
|
+
}
|
331
|
+
visitLambda(node) {
|
332
|
+
this._createVariableAnnotationFlowNode();
|
333
|
+
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
334
|
+
// Analyze the parameter defaults in the context of the parent's scope
|
335
|
+
// before we add any names from the function's scope.
|
336
|
+
node.parameters.forEach((param) => {
|
337
|
+
if (param.defaultValue) {
|
338
|
+
this.walk(param.defaultValue);
|
339
|
+
}
|
340
|
+
});
|
341
|
+
this._createNewScope(1 /* Function */, this._getNonClassParentScope(), () => {
|
342
|
+
AnalyzerNodeInfo.setScope(node, this._currentScope);
|
343
|
+
this._deferBinding(() => {
|
344
|
+
// Create a start node for the lambda.
|
345
|
+
this._currentFlowNode = this._createStartFlowNode();
|
346
|
+
node.parameters.forEach((paramNode) => {
|
347
|
+
if (paramNode.name) {
|
348
|
+
const symbol = this._bindNameToScope(this._currentScope, paramNode.name.value);
|
349
|
+
if (symbol) {
|
350
|
+
const paramDeclaration = {
|
351
|
+
type: 2 /* Parameter */,
|
352
|
+
node: paramNode,
|
353
|
+
path: this._fileInfo.filePath,
|
354
|
+
range: (0, positionUtils_1.convertOffsetsToRange)(paramNode.start, textRange_2.TextRange.getEnd(paramNode), this._fileInfo.lines),
|
355
|
+
moduleName: this._fileInfo.moduleName,
|
356
|
+
isInExceptSuite: this._isInExceptSuite,
|
357
|
+
};
|
358
|
+
symbol.addDeclaration(paramDeclaration);
|
359
|
+
AnalyzerNodeInfo.setDeclaration(paramNode.name, paramDeclaration);
|
360
|
+
}
|
361
|
+
this._createFlowAssignment(paramNode.name);
|
362
|
+
this.walk(paramNode.name);
|
363
|
+
}
|
364
|
+
});
|
365
|
+
// Walk the expression that make up the lambda body.
|
366
|
+
this.walk(node.expression);
|
367
|
+
AnalyzerNodeInfo.setCodeFlowExpressions(node, this._currentScopeCodeFlowExpressions);
|
368
|
+
});
|
369
|
+
});
|
370
|
+
// We'll walk the child nodes in a deferred manner.
|
371
|
+
return false;
|
372
|
+
}
|
373
|
+
visitCall(node) {
|
374
|
+
var _a, _b;
|
375
|
+
this._disableTrueFalseTargets(() => {
|
376
|
+
this.walk(node.leftExpression);
|
377
|
+
node.arguments.forEach((argNode) => {
|
378
|
+
if (this._currentFlowNode) {
|
379
|
+
AnalyzerNodeInfo.setFlowNode(argNode, this._currentFlowNode);
|
380
|
+
}
|
381
|
+
this.walk(argNode);
|
382
|
+
});
|
383
|
+
});
|
384
|
+
// Create a call flow node. We'll skip this if the call is part of
|
385
|
+
// a decorator. We assume that decorators are not NoReturn functions.
|
386
|
+
// There are libraries that make extensive use of unannotated decorators,
|
387
|
+
// and this can lead to a performance issue when walking the control
|
388
|
+
// flow graph if we need to evaluate every decorator.
|
389
|
+
if (!ParseTreeUtils.isNodeContainedWithinNodeType(node, 13 /* Decorator */)) {
|
390
|
+
this._createCallFlowNode(node);
|
391
|
+
}
|
392
|
+
// Is this an manipulation of dunder all?
|
393
|
+
if (this._currentScope.type === 3 /* Module */ &&
|
394
|
+
node.leftExpression.nodeType === 35 /* MemberAccess */ &&
|
395
|
+
node.leftExpression.leftExpression.nodeType === 38 /* Name */ &&
|
396
|
+
node.leftExpression.leftExpression.value === '__all__') {
|
397
|
+
let emitDunderAllWarning = true;
|
398
|
+
// Is this a call to "__all__.extend()"?
|
399
|
+
if (node.leftExpression.memberName.value === 'extend' && node.arguments.length === 1) {
|
400
|
+
const argExpr = node.arguments[0].valueExpression;
|
401
|
+
// Is this a call to "__all__.extend([<list>])"?
|
402
|
+
if (argExpr.nodeType === 31 /* List */) {
|
403
|
+
argExpr.entries.forEach((listEntryNode) => {
|
404
|
+
var _a, _b;
|
405
|
+
if (listEntryNode.nodeType === 48 /* StringList */ &&
|
406
|
+
listEntryNode.strings.length === 1 &&
|
407
|
+
listEntryNode.strings[0].nodeType === 49 /* String */) {
|
408
|
+
(_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.push(listEntryNode.strings[0].value);
|
409
|
+
(_b = this._dunderAllStringNodes) === null || _b === void 0 ? void 0 : _b.push(listEntryNode.strings[0]);
|
410
|
+
emitDunderAllWarning = false;
|
411
|
+
}
|
412
|
+
});
|
413
|
+
}
|
414
|
+
else if (argExpr.nodeType === 35 /* MemberAccess */ &&
|
415
|
+
argExpr.leftExpression.nodeType === 38 /* Name */ &&
|
416
|
+
argExpr.memberName.value === '__all__') {
|
417
|
+
// Is this a call to "__all__.extend(<mod>.__all__)"?
|
418
|
+
const namesToAdd = this._getDunderAllNamesFromImport(argExpr.leftExpression.value);
|
419
|
+
if (namesToAdd && namesToAdd.length > 0) {
|
420
|
+
namesToAdd.forEach((name) => {
|
421
|
+
var _a;
|
422
|
+
(_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.push(name);
|
423
|
+
});
|
424
|
+
emitDunderAllWarning = false;
|
425
|
+
}
|
426
|
+
}
|
427
|
+
}
|
428
|
+
else if (node.leftExpression.memberName.value === 'remove' && node.arguments.length === 1) {
|
429
|
+
// Is this a call to "__all__.remove()"?
|
430
|
+
const argExpr = node.arguments[0].valueExpression;
|
431
|
+
if (argExpr.nodeType === 48 /* StringList */ &&
|
432
|
+
argExpr.strings.length === 1 &&
|
433
|
+
argExpr.strings[0].nodeType === 49 /* String */ &&
|
434
|
+
this._dunderAllNames) {
|
435
|
+
this._dunderAllNames = this._dunderAllNames.filter((name) => name !== argExpr.strings[0].value);
|
436
|
+
this._dunderAllStringNodes = this._dunderAllStringNodes.filter((node) => node.value !== argExpr.strings[0].value);
|
437
|
+
emitDunderAllWarning = false;
|
438
|
+
}
|
439
|
+
}
|
440
|
+
else if (node.leftExpression.memberName.value === 'append' && node.arguments.length === 1) {
|
441
|
+
// Is this a call to "__all__.append()"?
|
442
|
+
const argExpr = node.arguments[0].valueExpression;
|
443
|
+
if (argExpr.nodeType === 48 /* StringList */ &&
|
444
|
+
argExpr.strings.length === 1 &&
|
445
|
+
argExpr.strings[0].nodeType === 49 /* String */) {
|
446
|
+
(_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.push(argExpr.strings[0].value);
|
447
|
+
(_b = this._dunderAllStringNodes) === null || _b === void 0 ? void 0 : _b.push(argExpr.strings[0]);
|
448
|
+
emitDunderAllWarning = false;
|
449
|
+
}
|
450
|
+
}
|
451
|
+
if (emitDunderAllWarning) {
|
452
|
+
this._usesUnsupportedDunderAllForm = true;
|
453
|
+
this._addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnsupportedDunderAll, diagnosticRules_1.DiagnosticRule.reportUnsupportedDunderAll, localize_1.Localizer.Diagnostic.unsupportedDunderAllOperation(), node);
|
454
|
+
}
|
455
|
+
}
|
456
|
+
return false;
|
457
|
+
}
|
458
|
+
visitAssignment(node) {
|
459
|
+
if (this._handleTypingStubAssignmentOrAnnotation(node)) {
|
460
|
+
return false;
|
461
|
+
}
|
462
|
+
this._bindPossibleTupleNamedTarget(node.leftExpression);
|
463
|
+
if (node.typeAnnotationComment) {
|
464
|
+
this.walk(node.typeAnnotationComment);
|
465
|
+
this._addTypeDeclarationForVariable(node.leftExpression, node.typeAnnotationComment);
|
466
|
+
}
|
467
|
+
// If there is a type annotation associated with the assignment and annotation evaluations are
|
468
|
+
// not deferred, the Python interpreter creates an entry in the local symbol table (presumably
|
469
|
+
// to store the __annotation__ attribute) before it evaluates the RHS of the assignment. This
|
470
|
+
// can affect the evaluation of the RHS if the name of the symbol is the same as a name that
|
471
|
+
// is defined in an outer scope.
|
472
|
+
let createdAssignmentTargetFlowNodes = false;
|
473
|
+
if (node.leftExpression.nodeType === 54 /* TypeAnnotation */ &&
|
474
|
+
!(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(this._fileInfo)) {
|
475
|
+
this._createAssignmentTargetFlowNodes(node.leftExpression, /* walkTargets */ true, /* unbound */ false);
|
476
|
+
createdAssignmentTargetFlowNodes = true;
|
477
|
+
}
|
478
|
+
this.walk(node.rightExpression);
|
479
|
+
let isPossibleTypeAlias = true;
|
480
|
+
if (ParseTreeUtils.getEnclosingFunction(node)) {
|
481
|
+
// We will assume that type aliases are defined only at the module level
|
482
|
+
// or as class variables, not as local variables within a function.
|
483
|
+
isPossibleTypeAlias = false;
|
484
|
+
}
|
485
|
+
else if (node.rightExpression.nodeType === 9 /* Call */ && this._fileInfo.isTypingStubFile) {
|
486
|
+
// Some special built-in types defined in typing.pyi use
|
487
|
+
// assignments of the form List = _Alias(). We don't want to
|
488
|
+
// treat these as type aliases.
|
489
|
+
isPossibleTypeAlias = false;
|
490
|
+
}
|
491
|
+
else if (ParseTreeUtils.isWithinLoop(node)) {
|
492
|
+
// Assume that it's not a type alias if it's within a loop.
|
493
|
+
isPossibleTypeAlias = false;
|
494
|
+
}
|
495
|
+
this._addInferredTypeAssignmentForVariable(node.leftExpression, node.rightExpression, isPossibleTypeAlias);
|
496
|
+
// If we didn't create assignment target flow nodes above, do so now.
|
497
|
+
if (!createdAssignmentTargetFlowNodes) {
|
498
|
+
this._createAssignmentTargetFlowNodes(node.leftExpression, /* walkTargets */ true, /* unbound */ false);
|
499
|
+
}
|
500
|
+
// Is this an assignment to dunder all?
|
501
|
+
if (this._currentScope.type === 3 /* Module */) {
|
502
|
+
if ((node.leftExpression.nodeType === 38 /* Name */ && node.leftExpression.value === '__all__') ||
|
503
|
+
(node.leftExpression.nodeType === 54 /* TypeAnnotation */ &&
|
504
|
+
node.leftExpression.valueExpression.nodeType === 38 /* Name */ &&
|
505
|
+
node.leftExpression.valueExpression.value === '__all__')) {
|
506
|
+
const expr = node.rightExpression;
|
507
|
+
this._dunderAllNames = [];
|
508
|
+
let emitDunderAllWarning = false;
|
509
|
+
if (expr.nodeType === 31 /* List */) {
|
510
|
+
expr.entries.forEach((listEntryNode) => {
|
511
|
+
if (listEntryNode.nodeType === 48 /* StringList */ &&
|
512
|
+
listEntryNode.strings.length === 1 &&
|
513
|
+
listEntryNode.strings[0].nodeType === 49 /* String */) {
|
514
|
+
this._dunderAllNames.push(listEntryNode.strings[0].value);
|
515
|
+
this._dunderAllStringNodes.push(listEntryNode.strings[0]);
|
516
|
+
}
|
517
|
+
else {
|
518
|
+
emitDunderAllWarning = true;
|
519
|
+
}
|
520
|
+
});
|
521
|
+
}
|
522
|
+
else if (expr.nodeType === 52 /* Tuple */) {
|
523
|
+
expr.expressions.forEach((tupleEntryNode) => {
|
524
|
+
if (tupleEntryNode.nodeType === 48 /* StringList */ &&
|
525
|
+
tupleEntryNode.strings.length === 1 &&
|
526
|
+
tupleEntryNode.strings[0].nodeType === 49 /* String */) {
|
527
|
+
this._dunderAllNames.push(tupleEntryNode.strings[0].value);
|
528
|
+
this._dunderAllStringNodes.push(tupleEntryNode.strings[0]);
|
529
|
+
}
|
530
|
+
else {
|
531
|
+
emitDunderAllWarning = true;
|
532
|
+
}
|
533
|
+
});
|
534
|
+
}
|
535
|
+
else {
|
536
|
+
emitDunderAllWarning = true;
|
537
|
+
}
|
538
|
+
if (emitDunderAllWarning) {
|
539
|
+
this._usesUnsupportedDunderAllForm = true;
|
540
|
+
this._addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnsupportedDunderAll, diagnosticRules_1.DiagnosticRule.reportUnsupportedDunderAll, localize_1.Localizer.Diagnostic.unsupportedDunderAllOperation(), node);
|
541
|
+
}
|
542
|
+
}
|
543
|
+
}
|
544
|
+
// Is this an assignment to dunder slots?
|
545
|
+
if (this._currentScope.type === 2 /* Class */) {
|
546
|
+
if ((node.leftExpression.nodeType === 38 /* Name */ && node.leftExpression.value === '__slots__') ||
|
547
|
+
(node.leftExpression.nodeType === 54 /* TypeAnnotation */ &&
|
548
|
+
node.leftExpression.valueExpression.nodeType === 38 /* Name */ &&
|
549
|
+
node.leftExpression.valueExpression.value === '__slots__')) {
|
550
|
+
const expr = node.rightExpression;
|
551
|
+
this._dunderSlotsEntries = [];
|
552
|
+
let isExpressionUnderstood = true;
|
553
|
+
if (expr.nodeType === 48 /* StringList */) {
|
554
|
+
this._dunderSlotsEntries.push(expr);
|
555
|
+
}
|
556
|
+
else if (expr.nodeType === 31 /* List */) {
|
557
|
+
expr.entries.forEach((listEntryNode) => {
|
558
|
+
if (listEntryNode.nodeType === 48 /* StringList */ &&
|
559
|
+
listEntryNode.strings.length === 1 &&
|
560
|
+
listEntryNode.strings[0].nodeType === 49 /* String */) {
|
561
|
+
this._dunderSlotsEntries.push(listEntryNode);
|
562
|
+
}
|
563
|
+
else {
|
564
|
+
isExpressionUnderstood = false;
|
565
|
+
}
|
566
|
+
});
|
567
|
+
}
|
568
|
+
else if (expr.nodeType === 52 /* Tuple */) {
|
569
|
+
expr.expressions.forEach((tupleEntryNode) => {
|
570
|
+
if (tupleEntryNode.nodeType === 48 /* StringList */ &&
|
571
|
+
tupleEntryNode.strings.length === 1 &&
|
572
|
+
tupleEntryNode.strings[0].nodeType === 49 /* String */) {
|
573
|
+
this._dunderSlotsEntries.push(tupleEntryNode);
|
574
|
+
}
|
575
|
+
else {
|
576
|
+
isExpressionUnderstood = false;
|
577
|
+
}
|
578
|
+
});
|
579
|
+
}
|
580
|
+
else {
|
581
|
+
isExpressionUnderstood = false;
|
582
|
+
}
|
583
|
+
if (!isExpressionUnderstood) {
|
584
|
+
this._dunderSlotsEntries = undefined;
|
585
|
+
}
|
586
|
+
}
|
587
|
+
}
|
588
|
+
return false;
|
589
|
+
}
|
590
|
+
visitAssignmentExpression(node) {
|
591
|
+
// Temporarily disable true/false targets in case this assignment
|
592
|
+
// expression is located within an if/else conditional.
|
593
|
+
this._disableTrueFalseTargets(() => {
|
594
|
+
// Evaluate the operand expression.
|
595
|
+
this.walk(node.rightExpression);
|
596
|
+
});
|
597
|
+
const evaluationNode = ParseTreeUtils.getEvaluationNodeForAssignmentExpression(node);
|
598
|
+
if (!evaluationNode) {
|
599
|
+
this._addError(localize_1.Localizer.Diagnostic.assignmentExprContext(), node);
|
600
|
+
this.walk(node.name);
|
601
|
+
}
|
602
|
+
else {
|
603
|
+
// Bind the name to the containing scope. This special logic is required
|
604
|
+
// because of the behavior defined in PEP 572. Targets of assignment
|
605
|
+
// expressions don't bind to a list comprehension's scope but instead
|
606
|
+
// bind to its containing scope.
|
607
|
+
const containerScope = AnalyzerNodeInfo.getScope(evaluationNode);
|
608
|
+
// If we're in a list comprehension (possibly nested), make sure that
|
609
|
+
// local for targets don't collide with the target of the assignment
|
610
|
+
// expression.
|
611
|
+
let curScope = this._currentScope;
|
612
|
+
while (curScope && curScope !== containerScope) {
|
613
|
+
const localSymbol = curScope.lookUpSymbol(node.name.value);
|
614
|
+
if (localSymbol) {
|
615
|
+
this._addError(localize_1.Localizer.Diagnostic.assignmentExprComprehension().format({ name: node.name.value }), node.name);
|
616
|
+
break;
|
617
|
+
}
|
618
|
+
curScope = curScope.parent;
|
619
|
+
}
|
620
|
+
this._bindNameToScope(containerScope, node.name.value);
|
621
|
+
this._addInferredTypeAssignmentForVariable(node.name, node.rightExpression);
|
622
|
+
this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ true, /* unbound */ false);
|
623
|
+
}
|
624
|
+
return false;
|
625
|
+
}
|
626
|
+
visitAugmentedAssignment(node) {
|
627
|
+
this.walk(node.leftExpression);
|
628
|
+
this.walk(node.rightExpression);
|
629
|
+
this._bindPossibleTupleNamedTarget(node.destExpression);
|
630
|
+
this._createAssignmentTargetFlowNodes(node.destExpression, /* walkTargets */ false, /* unbound */ false);
|
631
|
+
// Is this an assignment to dunder all of the form
|
632
|
+
// __all__ += <expression>?
|
633
|
+
if (node.operator === 1 /* AddEqual */ &&
|
634
|
+
this._currentScope.type === 3 /* Module */ &&
|
635
|
+
node.leftExpression.nodeType === 38 /* Name */ &&
|
636
|
+
node.leftExpression.value === '__all__') {
|
637
|
+
const expr = node.rightExpression;
|
638
|
+
let emitDunderAllWarning = true;
|
639
|
+
if (expr.nodeType === 31 /* List */) {
|
640
|
+
// Is this the form __all__ += ["a", "b"]?
|
641
|
+
expr.entries.forEach((listEntryNode) => {
|
642
|
+
var _a;
|
643
|
+
if (listEntryNode.nodeType === 48 /* StringList */ &&
|
644
|
+
listEntryNode.strings.length === 1 &&
|
645
|
+
listEntryNode.strings[0].nodeType === 49 /* String */) {
|
646
|
+
(_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.push(listEntryNode.strings[0].value);
|
647
|
+
this._dunderAllStringNodes.push(listEntryNode.strings[0]);
|
648
|
+
}
|
649
|
+
});
|
650
|
+
emitDunderAllWarning = false;
|
651
|
+
}
|
652
|
+
else if (expr.nodeType === 35 /* MemberAccess */ &&
|
653
|
+
expr.leftExpression.nodeType === 38 /* Name */ &&
|
654
|
+
expr.memberName.value === '__all__') {
|
655
|
+
// Is this using the form "__all__ += <mod>.__all__"?
|
656
|
+
const namesToAdd = this._getDunderAllNamesFromImport(expr.leftExpression.value);
|
657
|
+
if (namesToAdd) {
|
658
|
+
namesToAdd.forEach((name) => {
|
659
|
+
var _a;
|
660
|
+
(_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.push(name);
|
661
|
+
});
|
662
|
+
emitDunderAllWarning = false;
|
663
|
+
}
|
664
|
+
}
|
665
|
+
if (emitDunderAllWarning) {
|
666
|
+
this._usesUnsupportedDunderAllForm = true;
|
667
|
+
this._addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnsupportedDunderAll, diagnosticRules_1.DiagnosticRule.reportUnsupportedDunderAll, localize_1.Localizer.Diagnostic.unsupportedDunderAllOperation(), node);
|
668
|
+
}
|
669
|
+
}
|
670
|
+
return false;
|
671
|
+
}
|
672
|
+
visitDel(node) {
|
673
|
+
node.expressions.forEach((expr) => {
|
674
|
+
this._bindPossibleTupleNamedTarget(expr);
|
675
|
+
this.walk(expr);
|
676
|
+
this._createAssignmentTargetFlowNodes(expr, /* walkTargets */ false, /* unbound */ true);
|
677
|
+
});
|
678
|
+
return false;
|
679
|
+
}
|
680
|
+
visitTypeAnnotation(node) {
|
681
|
+
if (this._handleTypingStubAssignmentOrAnnotation(node)) {
|
682
|
+
return false;
|
683
|
+
}
|
684
|
+
// Walk the type annotation first so it is "before" the target
|
685
|
+
// in the code flow graph.
|
686
|
+
this.walk(node.typeAnnotation);
|
687
|
+
this._createVariableAnnotationFlowNode();
|
688
|
+
this._bindPossibleTupleNamedTarget(node.valueExpression);
|
689
|
+
this._addTypeDeclarationForVariable(node.valueExpression, node.typeAnnotation);
|
690
|
+
// For type annotations that are not part of assignments (e.g. simple variable
|
691
|
+
// annotations), we need to populate the reference map. Otherwise the type
|
692
|
+
// analyzer's code flow engine won't run and detect cases where the variable
|
693
|
+
// is unbound.
|
694
|
+
const expressionList = [];
|
695
|
+
if (this._isNarrowingExpression(node.valueExpression, expressionList)) {
|
696
|
+
expressionList.forEach((expr) => {
|
697
|
+
const referenceKey = (0, codeFlowTypes_1.createKeyForReference)(expr);
|
698
|
+
this._currentScopeCodeFlowExpressions.add(referenceKey);
|
699
|
+
});
|
700
|
+
}
|
701
|
+
this.walk(node.valueExpression);
|
702
|
+
return false;
|
703
|
+
}
|
704
|
+
visitFor(node) {
|
705
|
+
this._bindPossibleTupleNamedTarget(node.targetExpression);
|
706
|
+
this._addInferredTypeAssignmentForVariable(node.targetExpression, node);
|
707
|
+
this.walk(node.iterableExpression);
|
708
|
+
const preForLabel = this._createLoopLabel();
|
709
|
+
const preElseLabel = this._createBranchLabel();
|
710
|
+
const postForLabel = this._createBranchLabel();
|
711
|
+
this._addAntecedent(preForLabel, this._currentFlowNode);
|
712
|
+
this._currentFlowNode = preForLabel;
|
713
|
+
this._addAntecedent(preElseLabel, this._currentFlowNode);
|
714
|
+
this._createAssignmentTargetFlowNodes(node.targetExpression, /* walkTargets */ true, /* unbound */ false);
|
715
|
+
this._bindLoopStatement(preForLabel, postForLabel, () => {
|
716
|
+
this.walk(node.forSuite);
|
717
|
+
this._addAntecedent(preForLabel, this._currentFlowNode);
|
718
|
+
});
|
719
|
+
this._currentFlowNode = this._finishFlowLabel(preElseLabel);
|
720
|
+
if (node.elseSuite) {
|
721
|
+
this.walk(node.elseSuite);
|
722
|
+
}
|
723
|
+
this._addAntecedent(postForLabel, this._currentFlowNode);
|
724
|
+
this._currentFlowNode = this._finishFlowLabel(postForLabel);
|
725
|
+
if (node.asyncToken) {
|
726
|
+
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
727
|
+
if (!enclosingFunction || !enclosingFunction.isAsync) {
|
728
|
+
this._addError(localize_1.Localizer.Diagnostic.asyncNotInAsyncFunction(), node.asyncToken);
|
729
|
+
}
|
730
|
+
}
|
731
|
+
return false;
|
732
|
+
}
|
733
|
+
visitContinue(node) {
|
734
|
+
if (this._currentContinueTarget) {
|
735
|
+
this._addAntecedent(this._currentContinueTarget, this._currentFlowNode);
|
736
|
+
}
|
737
|
+
this._currentFlowNode = Binder._unreachableFlowNode;
|
738
|
+
// Continue nodes don't have any children.
|
739
|
+
return false;
|
740
|
+
}
|
741
|
+
visitBreak(node) {
|
742
|
+
if (this._currentBreakTarget) {
|
743
|
+
this._addAntecedent(this._currentBreakTarget, this._currentFlowNode);
|
744
|
+
}
|
745
|
+
this._currentFlowNode = Binder._unreachableFlowNode;
|
746
|
+
// Break nodes don't have any children.
|
747
|
+
return false;
|
748
|
+
}
|
749
|
+
visitReturn(node) {
|
750
|
+
if (this._targetFunctionDeclaration) {
|
751
|
+
if (!this._targetFunctionDeclaration.returnStatements) {
|
752
|
+
this._targetFunctionDeclaration.returnStatements = [];
|
753
|
+
}
|
754
|
+
this._targetFunctionDeclaration.returnStatements.push(node);
|
755
|
+
}
|
756
|
+
if (node.returnExpression) {
|
757
|
+
this.walk(node.returnExpression);
|
758
|
+
}
|
759
|
+
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
760
|
+
if (this._currentReturnTarget) {
|
761
|
+
this._addAntecedent(this._currentReturnTarget, this._currentFlowNode);
|
762
|
+
}
|
763
|
+
this._finallyTargets.forEach((target) => {
|
764
|
+
this._addAntecedent(target, this._currentFlowNode);
|
765
|
+
});
|
766
|
+
this._currentFlowNode = Binder._unreachableFlowNode;
|
767
|
+
return false;
|
768
|
+
}
|
769
|
+
visitYield(node) {
|
770
|
+
if (this._isInListComprehension(node, /* ignoreOutermostIterable */ true)) {
|
771
|
+
this._addError(localize_1.Localizer.Diagnostic.yieldWithinListCompr(), node);
|
772
|
+
}
|
773
|
+
this._bindYield(node);
|
774
|
+
return false;
|
775
|
+
}
|
776
|
+
visitYieldFrom(node) {
|
777
|
+
if (this._isInListComprehension(node, /* ignoreOutermostIterable */ true)) {
|
778
|
+
this._addError(localize_1.Localizer.Diagnostic.yieldWithinListCompr(), node);
|
779
|
+
}
|
780
|
+
this._bindYield(node);
|
781
|
+
return false;
|
782
|
+
}
|
783
|
+
visitMemberAccess(node) {
|
784
|
+
this.walk(node.leftExpression);
|
785
|
+
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
786
|
+
return false;
|
787
|
+
}
|
788
|
+
visitName(node) {
|
789
|
+
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
790
|
+
// Name nodes have no children.
|
791
|
+
return false;
|
792
|
+
}
|
793
|
+
visitIndex(node) {
|
794
|
+
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
795
|
+
return true;
|
796
|
+
}
|
797
|
+
visitIf(node) {
|
798
|
+
const preIfFlowNode = this._currentFlowNode;
|
799
|
+
const thenLabel = this._createBranchLabel();
|
800
|
+
const elseLabel = this._createBranchLabel();
|
801
|
+
const postIfLabel = this._createBranchLabel(preIfFlowNode);
|
802
|
+
postIfLabel.affectedExpressions = this._trackCodeFlowExpressions(() => {
|
803
|
+
// Determine if the test condition is always true or always false. If so,
|
804
|
+
// we can treat either the then or the else clause as unconditional.
|
805
|
+
const constExprValue = StaticExpressions.evaluateStaticBoolLikeExpression(node.testExpression, this._fileInfo.executionEnvironment, this._fileInfo.definedConstants, this._typingImportAliases, this._sysImportAliases);
|
806
|
+
this._bindConditional(node.testExpression, thenLabel, elseLabel);
|
807
|
+
// Handle the if clause.
|
808
|
+
this._currentFlowNode =
|
809
|
+
constExprValue === false ? Binder._unreachableFlowNode : this._finishFlowLabel(thenLabel);
|
810
|
+
this.walk(node.ifSuite);
|
811
|
+
this._addAntecedent(postIfLabel, this._currentFlowNode);
|
812
|
+
// Now handle the else clause if it's present. If there
|
813
|
+
// are chained "else if" statements, they'll be handled
|
814
|
+
// recursively here.
|
815
|
+
this._currentFlowNode =
|
816
|
+
constExprValue === true ? Binder._unreachableFlowNode : this._finishFlowLabel(elseLabel);
|
817
|
+
if (node.elseSuite) {
|
818
|
+
this.walk(node.elseSuite);
|
819
|
+
}
|
820
|
+
else {
|
821
|
+
this._bindNeverCondition(node.testExpression, postIfLabel, /* isPositiveTest */ false);
|
822
|
+
}
|
823
|
+
this._addAntecedent(postIfLabel, this._currentFlowNode);
|
824
|
+
this._currentFlowNode = this._finishFlowLabel(postIfLabel);
|
825
|
+
});
|
826
|
+
return false;
|
827
|
+
}
|
828
|
+
visitWhile(node) {
|
829
|
+
const thenLabel = this._createBranchLabel();
|
830
|
+
const elseLabel = this._createBranchLabel();
|
831
|
+
const postWhileLabel = this._createBranchLabel();
|
832
|
+
// Determine if the test condition is always true or always false. If so,
|
833
|
+
// we can treat either the while or the else clause as unconditional.
|
834
|
+
const constExprValue = StaticExpressions.evaluateStaticBoolLikeExpression(node.testExpression, this._fileInfo.executionEnvironment, this._fileInfo.definedConstants, this._typingImportAliases, this._sysImportAliases);
|
835
|
+
const preLoopLabel = this._createLoopLabel();
|
836
|
+
this._addAntecedent(preLoopLabel, this._currentFlowNode);
|
837
|
+
this._currentFlowNode = preLoopLabel;
|
838
|
+
this._bindConditional(node.testExpression, thenLabel, elseLabel);
|
839
|
+
// Handle the while clause.
|
840
|
+
this._currentFlowNode =
|
841
|
+
constExprValue === false ? Binder._unreachableFlowNode : this._finishFlowLabel(thenLabel);
|
842
|
+
this._bindLoopStatement(preLoopLabel, postWhileLabel, () => {
|
843
|
+
this.walk(node.whileSuite);
|
844
|
+
});
|
845
|
+
this._addAntecedent(preLoopLabel, this._currentFlowNode);
|
846
|
+
this._currentFlowNode =
|
847
|
+
constExprValue === true ? Binder._unreachableFlowNode : this._finishFlowLabel(elseLabel);
|
848
|
+
if (node.elseSuite) {
|
849
|
+
this.walk(node.elseSuite);
|
850
|
+
}
|
851
|
+
this._addAntecedent(postWhileLabel, this._currentFlowNode);
|
852
|
+
this._currentFlowNode = this._finishFlowLabel(postWhileLabel);
|
853
|
+
return false;
|
854
|
+
}
|
855
|
+
visitAssert(node) {
|
856
|
+
const assertTrueLabel = this._createBranchLabel();
|
857
|
+
const assertFalseLabel = this._createBranchLabel();
|
858
|
+
this._bindConditional(node.testExpression, assertTrueLabel, assertFalseLabel);
|
859
|
+
if (node.exceptionExpression) {
|
860
|
+
this._currentFlowNode = this._finishFlowLabel(assertFalseLabel);
|
861
|
+
this.walk(node.exceptionExpression);
|
862
|
+
}
|
863
|
+
this._currentFlowNode = this._finishFlowLabel(assertTrueLabel);
|
864
|
+
return false;
|
865
|
+
}
|
866
|
+
visitExcept(node) {
|
867
|
+
if (node.typeExpression) {
|
868
|
+
this.walk(node.typeExpression);
|
869
|
+
}
|
870
|
+
if (node.name) {
|
871
|
+
this.walk(node.name);
|
872
|
+
const symbol = this._bindNameToScope(this._currentScope, node.name.value);
|
873
|
+
this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ true, /* unbound */ false);
|
874
|
+
if (symbol) {
|
875
|
+
const declaration = {
|
876
|
+
type: 1 /* Variable */,
|
877
|
+
node: node.name,
|
878
|
+
isConstant: (0, symbolNameUtils_1.isConstantName)(node.name.value),
|
879
|
+
inferredTypeSource: node,
|
880
|
+
path: this._fileInfo.filePath,
|
881
|
+
range: (0, positionUtils_1.convertOffsetsToRange)(node.name.start, textRange_2.TextRange.getEnd(node.name), this._fileInfo.lines),
|
882
|
+
moduleName: this._fileInfo.moduleName,
|
883
|
+
isInExceptSuite: this._isInExceptSuite,
|
884
|
+
};
|
885
|
+
symbol.addDeclaration(declaration);
|
886
|
+
}
|
887
|
+
}
|
888
|
+
const wasInExceptSuite = this._isInExceptSuite;
|
889
|
+
this._isInExceptSuite = true;
|
890
|
+
this.walk(node.exceptSuite);
|
891
|
+
this._isInExceptSuite = wasInExceptSuite;
|
892
|
+
if (node.name) {
|
893
|
+
// The exception name is implicitly unbound at the end of
|
894
|
+
// the except block.
|
895
|
+
this._createFlowAssignment(node.name, /* unbound */ true);
|
896
|
+
}
|
897
|
+
return false;
|
898
|
+
}
|
899
|
+
visitRaise(node) {
|
900
|
+
if (this._targetFunctionDeclaration) {
|
901
|
+
if (!this._targetFunctionDeclaration.raiseStatements) {
|
902
|
+
this._targetFunctionDeclaration.raiseStatements = [];
|
903
|
+
}
|
904
|
+
this._targetFunctionDeclaration.raiseStatements.push(node);
|
905
|
+
}
|
906
|
+
if (node.typeExpression) {
|
907
|
+
this.walk(node.typeExpression);
|
908
|
+
}
|
909
|
+
if (node.valueExpression) {
|
910
|
+
this.walk(node.valueExpression);
|
911
|
+
}
|
912
|
+
if (node.tracebackExpression) {
|
913
|
+
this.walk(node.tracebackExpression);
|
914
|
+
}
|
915
|
+
this._finallyTargets.forEach((target) => {
|
916
|
+
this._addAntecedent(target, this._currentFlowNode);
|
917
|
+
});
|
918
|
+
this._currentFlowNode = Binder._unreachableFlowNode;
|
919
|
+
return false;
|
920
|
+
}
|
921
|
+
visitTry(node) {
|
922
|
+
// The try/except/else/finally statement is tricky to model using static code
|
923
|
+
// flow rules because the finally clause is executed regardless of whether an
|
924
|
+
// exception is raised or a return statement is executed. Code within the finally
|
925
|
+
// clause needs to be reachable always, and we conservatively assume that any
|
926
|
+
// statement within the try block can generate an exception, so we assume that its
|
927
|
+
// antecedent is the pre-try flow. We implement this with a "gate" node in the
|
928
|
+
// control flow graph. If analysis starts within the finally clause, the gate is
|
929
|
+
// opened, and all raise/return statements within try/except/else blocks are
|
930
|
+
// considered antecedents. If analysis starts outside (after) the finally clause,
|
931
|
+
// the gate is closed, and only paths that don't hit a raise/return statement
|
932
|
+
// in try/except/else blocks are considered.
|
933
|
+
//
|
934
|
+
//
|
935
|
+
// 1. PostElse
|
936
|
+
// ^
|
937
|
+
// |
|
938
|
+
// 3. TryExceptElseReturnOrExcept |
|
939
|
+
// ^ |
|
940
|
+
// | | 2. PostExcept (for each except)
|
941
|
+
// | | ^
|
942
|
+
// 4. ReturnOrRaiseLabel | |
|
943
|
+
// ^ | |
|
944
|
+
// | | |---------
|
945
|
+
// 5. PreFinallyGate | |
|
946
|
+
// ^ | |
|
947
|
+
// |------------------ | |
|
948
|
+
// | | |
|
949
|
+
// 6. PreFinallyLabel
|
950
|
+
// ^
|
951
|
+
// (finally block)
|
952
|
+
// ^
|
953
|
+
// 7. PostFinally
|
954
|
+
// ^ (only if isAfterElseAndExceptsReachable)
|
955
|
+
// (after finally)
|
956
|
+
// Create one flow label for every except clause.
|
957
|
+
const preTryFlowNode = this._currentFlowNode;
|
958
|
+
const curExceptTargets = node.exceptClauses.map(() => this._createBranchLabel());
|
959
|
+
const preFinallyLabel = this._createBranchLabel(preTryFlowNode);
|
960
|
+
let isAfterElseAndExceptsReachable = false;
|
961
|
+
// Create a label for all of the return or raise labels that are
|
962
|
+
// encountered within the try/except/else blocks. This conditionally
|
963
|
+
// connects the return/raise statement to the finally clause.
|
964
|
+
const preFinallyReturnOrRaiseLabel = this._createBranchLabel(preTryFlowNode);
|
965
|
+
const preFinallyGate = {
|
966
|
+
flags: codeFlowTypes_1.FlowFlags.PreFinallyGate,
|
967
|
+
id: this._getUniqueFlowNodeId(),
|
968
|
+
antecedent: preFinallyReturnOrRaiseLabel,
|
969
|
+
isGateClosed: false,
|
970
|
+
};
|
971
|
+
preFinallyLabel.affectedExpressions = this._trackCodeFlowExpressions(() => {
|
972
|
+
if (node.finallySuite) {
|
973
|
+
this._addAntecedent(preFinallyLabel, preFinallyGate);
|
974
|
+
}
|
975
|
+
// Add the finally target as an exception target unless there is
|
976
|
+
// a "bare" except clause that accepts all exception types.
|
977
|
+
const hasBareExceptClause = node.exceptClauses.some((except) => !except.typeExpression);
|
978
|
+
if (!hasBareExceptClause) {
|
979
|
+
curExceptTargets.push(preFinallyReturnOrRaiseLabel);
|
980
|
+
}
|
981
|
+
// An exception may be generated before the first flow node
|
982
|
+
// added by the try block, so all of the exception targets
|
983
|
+
// must have the pre-try flow node as an antecedent.
|
984
|
+
curExceptTargets.forEach((exceptLabel) => {
|
985
|
+
this._addAntecedent(exceptLabel, this._currentFlowNode);
|
986
|
+
});
|
987
|
+
// We don't perfectly handle nested finally clauses, which are not
|
988
|
+
// possible to model fully within a static analyzer, but we do handle
|
989
|
+
// a single level of finally statements, and we handle most cases
|
990
|
+
// involving nesting. Returns or raises within the try/except/raise
|
991
|
+
// block will execute the finally target(s).
|
992
|
+
if (node.finallySuite) {
|
993
|
+
this._finallyTargets.push(preFinallyReturnOrRaiseLabel);
|
994
|
+
}
|
995
|
+
// Handle the try block.
|
996
|
+
this._useExceptTargets(curExceptTargets, () => {
|
997
|
+
this.walk(node.trySuite);
|
998
|
+
});
|
999
|
+
// Handle the else block, which is executed only if
|
1000
|
+
// execution falls through the try block.
|
1001
|
+
if (node.elseSuite) {
|
1002
|
+
this.walk(node.elseSuite);
|
1003
|
+
}
|
1004
|
+
this._addAntecedent(preFinallyLabel, this._currentFlowNode);
|
1005
|
+
if (!this._isCodeUnreachable()) {
|
1006
|
+
isAfterElseAndExceptsReachable = true;
|
1007
|
+
}
|
1008
|
+
// Handle the except blocks.
|
1009
|
+
node.exceptClauses.forEach((exceptNode, index) => {
|
1010
|
+
this._currentFlowNode = this._finishFlowLabel(curExceptTargets[index]);
|
1011
|
+
this.walk(exceptNode);
|
1012
|
+
this._addAntecedent(preFinallyLabel, this._currentFlowNode);
|
1013
|
+
if (!this._isCodeUnreachable()) {
|
1014
|
+
isAfterElseAndExceptsReachable = true;
|
1015
|
+
}
|
1016
|
+
});
|
1017
|
+
if (node.finallySuite) {
|
1018
|
+
this._finallyTargets.pop();
|
1019
|
+
}
|
1020
|
+
// Handle the finally block.
|
1021
|
+
this._currentFlowNode = this._finishFlowLabel(preFinallyLabel);
|
1022
|
+
});
|
1023
|
+
if (node.finallySuite) {
|
1024
|
+
this.walk(node.finallySuite);
|
1025
|
+
// Add a post-finally node at the end. If we traverse this node,
|
1026
|
+
// we'll set the "ignore" flag in the pre-finally node.
|
1027
|
+
const postFinallyNode = {
|
1028
|
+
flags: codeFlowTypes_1.FlowFlags.PostFinally,
|
1029
|
+
id: this._getUniqueFlowNodeId(),
|
1030
|
+
finallyNode: node.finallySuite,
|
1031
|
+
antecedent: this._currentFlowNode,
|
1032
|
+
preFinallyGate,
|
1033
|
+
};
|
1034
|
+
this._currentFlowNode = isAfterElseAndExceptsReachable ? postFinallyNode : Binder._unreachableFlowNode;
|
1035
|
+
}
|
1036
|
+
return false;
|
1037
|
+
}
|
1038
|
+
visitAwait(node) {
|
1039
|
+
var _a;
|
1040
|
+
// Make sure this is within an async lambda or function.
|
1041
|
+
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
1042
|
+
if (enclosingFunction === undefined || !enclosingFunction.isAsync) {
|
1043
|
+
if (this._fileInfo.isIPythonMode && enclosingFunction === undefined) {
|
1044
|
+
// Top level await is allowed in ipython mode.
|
1045
|
+
return true;
|
1046
|
+
}
|
1047
|
+
// Allow if it's within a generator expression. Execution of
|
1048
|
+
// generator expressions is deferred and therefore can be
|
1049
|
+
// run within the context of an async function later.
|
1050
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 32 /* ListComprehension */) {
|
1051
|
+
this._addError(localize_1.Localizer.Diagnostic.awaitNotInAsync(), node);
|
1052
|
+
}
|
1053
|
+
}
|
1054
|
+
return true;
|
1055
|
+
}
|
1056
|
+
visitGlobal(node) {
|
1057
|
+
const globalScope = this._currentScope.getGlobalScope().scope;
|
1058
|
+
node.nameList.forEach((name) => {
|
1059
|
+
const nameValue = name.value;
|
1060
|
+
// Is the binding inconsistent?
|
1061
|
+
if (this._currentScope.getBindingType(nameValue) === 0 /* Nonlocal */) {
|
1062
|
+
this._addError(localize_1.Localizer.Diagnostic.nonLocalRedefinition().format({ name: nameValue }), name);
|
1063
|
+
}
|
1064
|
+
const valueWithScope = this._currentScope.lookUpSymbolRecursive(nameValue);
|
1065
|
+
// Was the name already assigned within this scope before it was declared global?
|
1066
|
+
if (valueWithScope && valueWithScope.scope === this._currentScope) {
|
1067
|
+
this._addError(localize_1.Localizer.Diagnostic.globalReassignment().format({ name: nameValue }), name);
|
1068
|
+
}
|
1069
|
+
// Add it to the global scope if it's not already added.
|
1070
|
+
this._bindNameToScope(globalScope, nameValue);
|
1071
|
+
if (this._currentScope !== globalScope) {
|
1072
|
+
this._currentScope.setBindingType(nameValue, 1 /* Global */);
|
1073
|
+
}
|
1074
|
+
});
|
1075
|
+
return true;
|
1076
|
+
}
|
1077
|
+
visitNonlocal(node) {
|
1078
|
+
const globalScope = this._currentScope.getGlobalScope().scope;
|
1079
|
+
if (this._currentScope === globalScope) {
|
1080
|
+
this._addError(localize_1.Localizer.Diagnostic.nonLocalInModule(), node);
|
1081
|
+
}
|
1082
|
+
else {
|
1083
|
+
node.nameList.forEach((name) => {
|
1084
|
+
const nameValue = name.value;
|
1085
|
+
// Is the binding inconsistent?
|
1086
|
+
if (this._currentScope.getBindingType(nameValue) === 1 /* Global */) {
|
1087
|
+
this._addError(localize_1.Localizer.Diagnostic.globalRedefinition().format({ name: nameValue }), name);
|
1088
|
+
}
|
1089
|
+
const valueWithScope = this._currentScope.lookUpSymbolRecursive(nameValue);
|
1090
|
+
// Was the name already assigned within this scope before it was declared nonlocal?
|
1091
|
+
if (valueWithScope && valueWithScope.scope === this._currentScope) {
|
1092
|
+
this._addError(localize_1.Localizer.Diagnostic.nonLocalReassignment().format({ name: nameValue }), name);
|
1093
|
+
}
|
1094
|
+
else if (!valueWithScope || valueWithScope.scope === globalScope) {
|
1095
|
+
this._addError(localize_1.Localizer.Diagnostic.nonLocalNoBinding().format({ name: nameValue }), name);
|
1096
|
+
}
|
1097
|
+
if (valueWithScope) {
|
1098
|
+
this._currentScope.setBindingType(nameValue, 0 /* Nonlocal */);
|
1099
|
+
}
|
1100
|
+
});
|
1101
|
+
}
|
1102
|
+
return true;
|
1103
|
+
}
|
1104
|
+
visitImportAs(node) {
|
1105
|
+
var _a, _b, _c, _d, _e, _f;
|
1106
|
+
if (node.module.nameParts.length > 0) {
|
1107
|
+
const firstNamePartValue = node.module.nameParts[0].value;
|
1108
|
+
let symbolName;
|
1109
|
+
if (node.alias) {
|
1110
|
+
// The symbol name is defined by the alias.
|
1111
|
+
symbolName = node.alias.value;
|
1112
|
+
}
|
1113
|
+
else {
|
1114
|
+
// There was no alias, so we need to use the first element of
|
1115
|
+
// the name parts as the symbol.
|
1116
|
+
symbolName = firstNamePartValue;
|
1117
|
+
}
|
1118
|
+
const symbol = this._bindNameToScope(this._currentScope, symbolName);
|
1119
|
+
if (symbol &&
|
1120
|
+
(this._currentScope.type === 3 /* Module */ || this._currentScope.type === 4 /* Builtin */) &&
|
1121
|
+
(!node.alias ||
|
1122
|
+
node.module.nameParts.length !== 1 ||
|
1123
|
+
node.module.nameParts[0].value !== node.alias.value)) {
|
1124
|
+
if (this._fileInfo.isStubFile || this._fileInfo.isInPyTypedPackage) {
|
1125
|
+
// PEP 484 indicates that imported symbols should not be
|
1126
|
+
// considered "reexported" from a type stub file unless
|
1127
|
+
// they are imported using the "as" form and the aliased
|
1128
|
+
// name is entirely redundant.
|
1129
|
+
this._potentialHiddenSymbols.set(symbolName, symbol);
|
1130
|
+
}
|
1131
|
+
}
|
1132
|
+
const importInfo = AnalyzerNodeInfo.getImportInfo(node.module);
|
1133
|
+
(0, debug_1.assert)(importInfo !== undefined);
|
1134
|
+
if (symbol) {
|
1135
|
+
this._createAliasDeclarationForMultipartImportName(node, node.alias, importInfo, symbol);
|
1136
|
+
}
|
1137
|
+
this._createFlowAssignment(node.alias ? node.alias : node.module.nameParts[0]);
|
1138
|
+
if (node.module.nameParts.length === 1) {
|
1139
|
+
if (firstNamePartValue === 'typing' || firstNamePartValue === 'typing_extensions') {
|
1140
|
+
this._typingImportAliases.push((_b = (_a = node.alias) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : firstNamePartValue);
|
1141
|
+
}
|
1142
|
+
else if (firstNamePartValue === 'sys') {
|
1143
|
+
this._sysImportAliases.push((_d = (_c = node.alias) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : firstNamePartValue);
|
1144
|
+
}
|
1145
|
+
else if (firstNamePartValue === 'dataclasses') {
|
1146
|
+
this._dataclassesImportAliases.push((_f = (_e = node.alias) === null || _e === void 0 ? void 0 : _e.value) !== null && _f !== void 0 ? _f : firstNamePartValue);
|
1147
|
+
}
|
1148
|
+
}
|
1149
|
+
}
|
1150
|
+
return true;
|
1151
|
+
}
|
1152
|
+
visitImportFrom(node) {
|
1153
|
+
const typingSymbolsOfInterest = ['Final', 'TypeAlias', 'ClassVar', 'Required', 'NotRequired', 'Annotated'];
|
1154
|
+
const dataclassesSymbolsOfInterest = ['InitVar'];
|
1155
|
+
const importInfo = AnalyzerNodeInfo.getImportInfo(node.module);
|
1156
|
+
let resolvedPath = '';
|
1157
|
+
if (importInfo && importInfo.isImportFound && !importInfo.isNativeLib) {
|
1158
|
+
resolvedPath = importInfo.resolvedPaths[importInfo.resolvedPaths.length - 1];
|
1159
|
+
}
|
1160
|
+
// If this file is a module __init__.py(i), relative imports of submodules
|
1161
|
+
// using the syntax "from .x import y" introduce a symbol x into the
|
1162
|
+
// module namespace. We do this first (before adding the individual imported
|
1163
|
+
// symbols below) in case one of the imported symbols is the same name as the
|
1164
|
+
// submodule. In that case, we want to the symbol to appear later in the
|
1165
|
+
// declaration list because it should "win" when resolving the alias.
|
1166
|
+
const fileName = (0, pathUtils_1.stripFileExtension)((0, pathUtils_1.getFileName)(this._fileInfo.filePath));
|
1167
|
+
const isModuleInitFile = fileName === '__init__' && node.module.leadingDots === 1 && node.module.nameParts.length === 1;
|
1168
|
+
let isTypingImport = false;
|
1169
|
+
let isDataclassesImport = false;
|
1170
|
+
if (node.module.nameParts.length === 1) {
|
1171
|
+
const firstNamePartValue = node.module.nameParts[0].value;
|
1172
|
+
if (firstNamePartValue === 'typing' || firstNamePartValue === 'typing_extensions') {
|
1173
|
+
isTypingImport = true;
|
1174
|
+
}
|
1175
|
+
if (firstNamePartValue === 'dataclasses') {
|
1176
|
+
isDataclassesImport = true;
|
1177
|
+
}
|
1178
|
+
}
|
1179
|
+
if (node.isWildcardImport) {
|
1180
|
+
if (ParseTreeUtils.getEnclosingClass(node) || ParseTreeUtils.getEnclosingFunction(node)) {
|
1181
|
+
this._addError(localize_1.Localizer.Diagnostic.wildcardInFunction(), node);
|
1182
|
+
}
|
1183
|
+
if (importInfo) {
|
1184
|
+
const names = [];
|
1185
|
+
const lookupInfo = this._fileInfo.importLookup(resolvedPath);
|
1186
|
+
if (lookupInfo) {
|
1187
|
+
const wildcardNames = this._getWildcardImportNames(lookupInfo);
|
1188
|
+
if (isModuleInitFile) {
|
1189
|
+
// If the symbol is going to be immediately replaced with a same-named
|
1190
|
+
// imported symbol, skip this.
|
1191
|
+
const isImmediatelyReplaced = wildcardNames.some((name) => {
|
1192
|
+
return name === node.module.nameParts[0].value;
|
1193
|
+
});
|
1194
|
+
if (!isImmediatelyReplaced) {
|
1195
|
+
this._addImplicitFromImport(node, importInfo);
|
1196
|
+
}
|
1197
|
+
}
|
1198
|
+
wildcardNames.forEach((name) => {
|
1199
|
+
const localSymbol = this._bindNameToScope(this._currentScope, name);
|
1200
|
+
if (localSymbol) {
|
1201
|
+
const importedSymbol = lookupInfo.symbolTable.get(name);
|
1202
|
+
// Is the symbol in the target module's symbol table? If so,
|
1203
|
+
// alias it.
|
1204
|
+
if (importedSymbol) {
|
1205
|
+
const aliasDecl = {
|
1206
|
+
type: 6 /* Alias */,
|
1207
|
+
node,
|
1208
|
+
path: resolvedPath,
|
1209
|
+
loadSymbolsFromPath: true,
|
1210
|
+
range: (0, textRange_1.getEmptyRange)(),
|
1211
|
+
usesLocalName: false,
|
1212
|
+
symbolName: name,
|
1213
|
+
moduleName: this._fileInfo.moduleName,
|
1214
|
+
isInExceptSuite: this._isInExceptSuite,
|
1215
|
+
};
|
1216
|
+
localSymbol.addDeclaration(aliasDecl);
|
1217
|
+
names.push(name);
|
1218
|
+
}
|
1219
|
+
else {
|
1220
|
+
// The symbol wasn't in the target module's symbol table. It's probably
|
1221
|
+
// an implicitly-imported submodule referenced by __all__.
|
1222
|
+
if (importInfo && importInfo.filteredImplicitImports) {
|
1223
|
+
const implicitImport = importInfo.filteredImplicitImports.find((imp) => imp.name === name);
|
1224
|
+
if (implicitImport) {
|
1225
|
+
const submoduleFallback = {
|
1226
|
+
type: 6 /* Alias */,
|
1227
|
+
node,
|
1228
|
+
path: implicitImport.path,
|
1229
|
+
loadSymbolsFromPath: true,
|
1230
|
+
range: (0, textRange_1.getEmptyRange)(),
|
1231
|
+
usesLocalName: false,
|
1232
|
+
moduleName: this._fileInfo.moduleName,
|
1233
|
+
isInExceptSuite: this._isInExceptSuite,
|
1234
|
+
};
|
1235
|
+
const aliasDecl = {
|
1236
|
+
type: 6 /* Alias */,
|
1237
|
+
node,
|
1238
|
+
path: resolvedPath,
|
1239
|
+
loadSymbolsFromPath: true,
|
1240
|
+
usesLocalName: false,
|
1241
|
+
symbolName: name,
|
1242
|
+
submoduleFallback,
|
1243
|
+
range: (0, textRange_1.getEmptyRange)(),
|
1244
|
+
moduleName: this._fileInfo.moduleName,
|
1245
|
+
isInExceptSuite: this._isInExceptSuite,
|
1246
|
+
};
|
1247
|
+
localSymbol.addDeclaration(aliasDecl);
|
1248
|
+
}
|
1249
|
+
}
|
1250
|
+
}
|
1251
|
+
}
|
1252
|
+
});
|
1253
|
+
}
|
1254
|
+
this._createFlowWildcardImport(node, names);
|
1255
|
+
if (isTypingImport) {
|
1256
|
+
typingSymbolsOfInterest.forEach((s) => {
|
1257
|
+
this._typingSymbolAliases.set(s, s);
|
1258
|
+
});
|
1259
|
+
}
|
1260
|
+
if (isDataclassesImport) {
|
1261
|
+
dataclassesSymbolsOfInterest.forEach((s) => {
|
1262
|
+
this._dataclassesSymbolAliases.set(s, s);
|
1263
|
+
});
|
1264
|
+
}
|
1265
|
+
}
|
1266
|
+
}
|
1267
|
+
else {
|
1268
|
+
if (isModuleInitFile) {
|
1269
|
+
this._addImplicitFromImport(node, importInfo);
|
1270
|
+
}
|
1271
|
+
node.imports.forEach((importSymbolNode) => {
|
1272
|
+
const importedName = importSymbolNode.name.value;
|
1273
|
+
const nameNode = importSymbolNode.alias || importSymbolNode.name;
|
1274
|
+
const symbol = this._bindNameToScope(this._currentScope, nameNode.value);
|
1275
|
+
if (symbol) {
|
1276
|
+
// All import statements of the form `from . import x` treat x
|
1277
|
+
// as an externally-visible (not hidden) symbol.
|
1278
|
+
if (node.module.nameParts.length > 0) {
|
1279
|
+
if (this._currentScope.type === 3 /* Module */ ||
|
1280
|
+
this._currentScope.type === 4 /* Builtin */) {
|
1281
|
+
if (!importSymbolNode.alias ||
|
1282
|
+
importSymbolNode.alias.value !== importSymbolNode.name.value) {
|
1283
|
+
if (this._fileInfo.isStubFile || this._fileInfo.isInPyTypedPackage) {
|
1284
|
+
// PEP 484 indicates that imported symbols should not be
|
1285
|
+
// considered "reexported" from a type stub file unless
|
1286
|
+
// they are imported using the "as" form using a redundant form.
|
1287
|
+
// Py.typed packages follow the same rule as PEP 484.
|
1288
|
+
this._potentialHiddenSymbols.set(nameNode.value, symbol);
|
1289
|
+
}
|
1290
|
+
}
|
1291
|
+
}
|
1292
|
+
}
|
1293
|
+
// Is the import referring to an implicitly-imported module?
|
1294
|
+
let implicitImport;
|
1295
|
+
if (importInfo && importInfo.filteredImplicitImports) {
|
1296
|
+
implicitImport = importInfo.filteredImplicitImports.find((imp) => imp.name === importedName);
|
1297
|
+
}
|
1298
|
+
let submoduleFallback;
|
1299
|
+
let loadSymbolsFromPath = true;
|
1300
|
+
if (implicitImport) {
|
1301
|
+
submoduleFallback = {
|
1302
|
+
type: 6 /* Alias */,
|
1303
|
+
node: importSymbolNode,
|
1304
|
+
path: implicitImport.path,
|
1305
|
+
loadSymbolsFromPath: true,
|
1306
|
+
range: (0, textRange_1.getEmptyRange)(),
|
1307
|
+
usesLocalName: false,
|
1308
|
+
moduleName: this._fileInfo.moduleName,
|
1309
|
+
isInExceptSuite: this._isInExceptSuite,
|
1310
|
+
};
|
1311
|
+
// Handle the case of "from . import X" within an __init__ file.
|
1312
|
+
// In this case, we want to always resolve to the submodule rather
|
1313
|
+
// than the resolved path.
|
1314
|
+
if (fileName === '__init__' &&
|
1315
|
+
node.module.leadingDots === 1 &&
|
1316
|
+
node.module.nameParts.length === 0) {
|
1317
|
+
loadSymbolsFromPath = false;
|
1318
|
+
}
|
1319
|
+
}
|
1320
|
+
const aliasDecl = {
|
1321
|
+
type: 6 /* Alias */,
|
1322
|
+
node: importSymbolNode,
|
1323
|
+
path: resolvedPath,
|
1324
|
+
loadSymbolsFromPath,
|
1325
|
+
usesLocalName: !!importSymbolNode.alias,
|
1326
|
+
symbolName: importedName,
|
1327
|
+
submoduleFallback,
|
1328
|
+
range: (0, textRange_1.getEmptyRange)(),
|
1329
|
+
moduleName: this._fileInfo.moduleName,
|
1330
|
+
isInExceptSuite: this._isInExceptSuite,
|
1331
|
+
isNativeLib: importInfo === null || importInfo === void 0 ? void 0 : importInfo.isNativeLib,
|
1332
|
+
};
|
1333
|
+
symbol.addDeclaration(aliasDecl);
|
1334
|
+
this._createFlowAssignment(importSymbolNode.alias || importSymbolNode.name);
|
1335
|
+
if (isTypingImport) {
|
1336
|
+
if (typingSymbolsOfInterest.some((s) => s === importSymbolNode.name.value)) {
|
1337
|
+
this._typingSymbolAliases.set(nameNode.value, importSymbolNode.name.value);
|
1338
|
+
}
|
1339
|
+
}
|
1340
|
+
if (isDataclassesImport) {
|
1341
|
+
if (dataclassesSymbolsOfInterest.some((s) => s === importSymbolNode.name.value)) {
|
1342
|
+
this._dataclassesSymbolAliases.set(nameNode.value, importSymbolNode.name.value);
|
1343
|
+
}
|
1344
|
+
}
|
1345
|
+
}
|
1346
|
+
});
|
1347
|
+
}
|
1348
|
+
return true;
|
1349
|
+
}
|
1350
|
+
visitWith(node) {
|
1351
|
+
node.withItems.forEach((item) => {
|
1352
|
+
this.walk(item.expression);
|
1353
|
+
if (item.target) {
|
1354
|
+
this._bindPossibleTupleNamedTarget(item.target);
|
1355
|
+
this._addInferredTypeAssignmentForVariable(item.target, item);
|
1356
|
+
this._createAssignmentTargetFlowNodes(item.target, /* walkTargets */ true, /* unbound */ false);
|
1357
|
+
}
|
1358
|
+
});
|
1359
|
+
// We need to treat the "with" body as though it is wrapped in a try/except
|
1360
|
+
// block because some context managers catch and suppress exceptions.
|
1361
|
+
// We'll make use of a special "context manager label" which acts like
|
1362
|
+
// a regular branch label in most respects except that it is disabled
|
1363
|
+
// if none of the context managers support exception suppression. We won't
|
1364
|
+
// be able to determine whether any context managers support exception
|
1365
|
+
// processing until the type evaluation phase.
|
1366
|
+
//
|
1367
|
+
// (pre with suite)
|
1368
|
+
// ^
|
1369
|
+
// |<--------------------|
|
1370
|
+
// (with suite)<--------------|
|
1371
|
+
// ^ |
|
1372
|
+
// | ContextManagerSwallowExceptionTarget
|
1373
|
+
// | ^
|
1374
|
+
// | PostContextManagerLabel
|
1375
|
+
// | ^
|
1376
|
+
// |---------------------|
|
1377
|
+
// |
|
1378
|
+
// (after with)
|
1379
|
+
//
|
1380
|
+
// In addition to the ContextManagerSwallowExceptionTarget, we'll create
|
1381
|
+
// a second target called ContextManagerForwardExceptionTarget that forwards
|
1382
|
+
// exceptions to existing exception targets if they exist.
|
1383
|
+
const contextManagerSwallowExceptionTarget = this._createContextManagerLabel(node.withItems.map((item) => item.expression), !!node.isAsync,
|
1384
|
+
/* blockIfSwallowsExceptions */ false);
|
1385
|
+
this._addAntecedent(contextManagerSwallowExceptionTarget, this._currentFlowNode);
|
1386
|
+
const contextManagerForwardExceptionTarget = this._createContextManagerLabel(node.withItems.map((item) => item.expression), !!node.isAsync,
|
1387
|
+
/* blockIfSwallowsExceptions */ true);
|
1388
|
+
this._currentExceptTargets.forEach((exceptionTarget) => {
|
1389
|
+
this._addAntecedent(exceptionTarget, contextManagerForwardExceptionTarget);
|
1390
|
+
});
|
1391
|
+
const preWithSuiteNode = this._currentFlowNode;
|
1392
|
+
const postContextManagerLabel = this._createBranchLabel(preWithSuiteNode);
|
1393
|
+
this._addAntecedent(postContextManagerLabel, contextManagerSwallowExceptionTarget);
|
1394
|
+
postContextManagerLabel.affectedExpressions = this._trackCodeFlowExpressions(() => {
|
1395
|
+
this._useExceptTargets([contextManagerSwallowExceptionTarget, contextManagerForwardExceptionTarget], () => {
|
1396
|
+
this.walk(node.suite);
|
1397
|
+
});
|
1398
|
+
this._addAntecedent(postContextManagerLabel, this._currentFlowNode);
|
1399
|
+
this._currentFlowNode = postContextManagerLabel;
|
1400
|
+
// Model the call to `__exit__` as a potential exception generator.
|
1401
|
+
if (!this._isCodeUnreachable()) {
|
1402
|
+
this._addExceptTargets(this._currentFlowNode);
|
1403
|
+
}
|
1404
|
+
if (node.asyncToken) {
|
1405
|
+
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
1406
|
+
if (!enclosingFunction || !enclosingFunction.isAsync) {
|
1407
|
+
this._addError(localize_1.Localizer.Diagnostic.asyncNotInAsyncFunction(), node.asyncToken);
|
1408
|
+
}
|
1409
|
+
}
|
1410
|
+
});
|
1411
|
+
return false;
|
1412
|
+
}
|
1413
|
+
visitTernary(node) {
|
1414
|
+
const preTernaryFlowNode = this._currentFlowNode;
|
1415
|
+
const trueLabel = this._createBranchLabel();
|
1416
|
+
const falseLabel = this._createBranchLabel();
|
1417
|
+
const postExpressionLabel = this._createBranchLabel(preTernaryFlowNode);
|
1418
|
+
postExpressionLabel.affectedExpressions = this._trackCodeFlowExpressions(() => {
|
1419
|
+
// Handle the test expression.
|
1420
|
+
this._bindConditional(node.testExpression, trueLabel, falseLabel);
|
1421
|
+
// Handle the "true" portion (the "if" expression).
|
1422
|
+
this._currentFlowNode = this._finishFlowLabel(trueLabel);
|
1423
|
+
this.walk(node.ifExpression);
|
1424
|
+
this._addAntecedent(postExpressionLabel, this._currentFlowNode);
|
1425
|
+
// Handle the "false" portion (the "else" expression).
|
1426
|
+
this._currentFlowNode = this._finishFlowLabel(falseLabel);
|
1427
|
+
this.walk(node.elseExpression);
|
1428
|
+
this._addAntecedent(postExpressionLabel, this._currentFlowNode);
|
1429
|
+
this._currentFlowNode = this._finishFlowLabel(postExpressionLabel);
|
1430
|
+
});
|
1431
|
+
return false;
|
1432
|
+
}
|
1433
|
+
visitUnaryOperation(node) {
|
1434
|
+
if (node.operator === 38 /* Not */ && this._currentFalseTarget && this._currentTrueTarget) {
|
1435
|
+
// Swap the existing true/false targets.
|
1436
|
+
this._bindConditional(node.expression, this._currentFalseTarget, this._currentTrueTarget);
|
1437
|
+
}
|
1438
|
+
else {
|
1439
|
+
// Temporarily set the true/false targets to undefined because
|
1440
|
+
// this unary operation is not part of a chain of logical expressions
|
1441
|
+
// (AND/OR/NOT subexpressions).
|
1442
|
+
this._disableTrueFalseTargets(() => {
|
1443
|
+
// Evaluate the operand expression.
|
1444
|
+
this.walk(node.expression);
|
1445
|
+
});
|
1446
|
+
}
|
1447
|
+
return false;
|
1448
|
+
}
|
1449
|
+
visitBinaryOperation(node) {
|
1450
|
+
if (node.operator === 36 /* And */ || node.operator === 37 /* Or */) {
|
1451
|
+
let trueTarget = this._currentTrueTarget;
|
1452
|
+
let falseTarget = this._currentFalseTarget;
|
1453
|
+
let postRightLabel;
|
1454
|
+
if (!trueTarget || !falseTarget) {
|
1455
|
+
postRightLabel = this._createBranchLabel();
|
1456
|
+
trueTarget = falseTarget = postRightLabel;
|
1457
|
+
}
|
1458
|
+
const preRightLabel = this._createBranchLabel();
|
1459
|
+
if (node.operator === 36 /* And */) {
|
1460
|
+
this._bindConditional(node.leftExpression, preRightLabel, falseTarget);
|
1461
|
+
}
|
1462
|
+
else {
|
1463
|
+
this._bindConditional(node.leftExpression, trueTarget, preRightLabel);
|
1464
|
+
}
|
1465
|
+
this._currentFlowNode = this._finishFlowLabel(preRightLabel);
|
1466
|
+
this._bindConditional(node.rightExpression, trueTarget, falseTarget);
|
1467
|
+
if (postRightLabel) {
|
1468
|
+
this._currentFlowNode = this._finishFlowLabel(postRightLabel);
|
1469
|
+
}
|
1470
|
+
}
|
1471
|
+
else {
|
1472
|
+
// Temporarily set the true/false targets to undefined because
|
1473
|
+
// this binary operation is not part of a chain of logical expressions
|
1474
|
+
// (AND/OR/NOT subexpressions).
|
1475
|
+
this._disableTrueFalseTargets(() => {
|
1476
|
+
this.walk(node.leftExpression);
|
1477
|
+
this.walk(node.rightExpression);
|
1478
|
+
});
|
1479
|
+
}
|
1480
|
+
return false;
|
1481
|
+
}
|
1482
|
+
visitListComprehension(node) {
|
1483
|
+
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
1484
|
+
this._createNewScope(0 /* ListComprehension */, this._getNonClassParentScope(), () => {
|
1485
|
+
var _a;
|
1486
|
+
AnalyzerNodeInfo.setScope(node, this._currentScope);
|
1487
|
+
const falseLabel = this._createBranchLabel();
|
1488
|
+
// We'll walk the forIfNodes list twice. The first time we'll
|
1489
|
+
// bind targets of for statements. The second time we'll walk
|
1490
|
+
// expressions and create the control flow graph.
|
1491
|
+
for (let i = 0; i < node.forIfNodes.length; i++) {
|
1492
|
+
const compr = node.forIfNodes[i];
|
1493
|
+
const addedSymbols = new Map();
|
1494
|
+
if (compr.nodeType === 33 /* ListComprehensionFor */) {
|
1495
|
+
this._bindPossibleTupleNamedTarget(compr.targetExpression, addedSymbols);
|
1496
|
+
this._addInferredTypeAssignmentForVariable(compr.targetExpression, compr);
|
1497
|
+
// Async for is not allowed outside of an async function.
|
1498
|
+
if (compr.asyncToken) {
|
1499
|
+
if (!enclosingFunction || !enclosingFunction.isAsync) {
|
1500
|
+
// Allow if it's within a generator expression. Execution of
|
1501
|
+
// generator expressions is deferred and therefore can be
|
1502
|
+
// run within the context of an async function later.
|
1503
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 31 /* List */) {
|
1504
|
+
this._addError(localize_1.Localizer.Diagnostic.asyncNotInAsyncFunction(), compr.asyncToken);
|
1505
|
+
}
|
1506
|
+
}
|
1507
|
+
}
|
1508
|
+
}
|
1509
|
+
}
|
1510
|
+
for (let i = 0; i < node.forIfNodes.length; i++) {
|
1511
|
+
const compr = node.forIfNodes[i];
|
1512
|
+
if (compr.nodeType === 33 /* ListComprehensionFor */) {
|
1513
|
+
this.walk(compr.iterableExpression);
|
1514
|
+
this._createAssignmentTargetFlowNodes(compr.targetExpression,
|
1515
|
+
/* walkTargets */ true,
|
1516
|
+
/* unbound */ false);
|
1517
|
+
}
|
1518
|
+
else {
|
1519
|
+
const trueLabel = this._createBranchLabel();
|
1520
|
+
this._bindConditional(compr.testExpression, trueLabel, falseLabel);
|
1521
|
+
this._currentFlowNode = this._finishFlowLabel(trueLabel);
|
1522
|
+
}
|
1523
|
+
}
|
1524
|
+
this.walk(node.expression);
|
1525
|
+
this._addAntecedent(falseLabel, this._currentFlowNode);
|
1526
|
+
this._currentFlowNode = this._finishFlowLabel(falseLabel);
|
1527
|
+
});
|
1528
|
+
return false;
|
1529
|
+
}
|
1530
|
+
visitMatch(node) {
|
1531
|
+
// Evaluate the subject expression.
|
1532
|
+
this.walk(node.subjectExpression);
|
1533
|
+
const expressionList = [];
|
1534
|
+
const isSubjectNarrowable = this._isNarrowingExpression(node.subjectExpression, expressionList);
|
1535
|
+
if (isSubjectNarrowable) {
|
1536
|
+
expressionList.forEach((expr) => {
|
1537
|
+
const referenceKey = (0, codeFlowTypes_1.createKeyForReference)(expr);
|
1538
|
+
this._currentScopeCodeFlowExpressions.add(referenceKey);
|
1539
|
+
});
|
1540
|
+
}
|
1541
|
+
const postMatchLabel = this._createBranchLabel();
|
1542
|
+
let foundIrrefutableCase = false;
|
1543
|
+
// Model the match statement as a series of if/elif clauses
|
1544
|
+
// each of which tests for the specified pattern (and optionally
|
1545
|
+
// for the guard condition).
|
1546
|
+
node.cases.forEach((caseStatement) => {
|
1547
|
+
const postCaseLabel = this._createBranchLabel();
|
1548
|
+
const preGuardLabel = this._createBranchLabel();
|
1549
|
+
const preSuiteLabel = this._createBranchLabel();
|
1550
|
+
// Evaluate the pattern.
|
1551
|
+
this._addAntecedent(preGuardLabel, this._currentFlowNode);
|
1552
|
+
if (!caseStatement.isIrrefutable) {
|
1553
|
+
this._addAntecedent(postCaseLabel, this._currentFlowNode);
|
1554
|
+
}
|
1555
|
+
else if (!caseStatement.guardExpression) {
|
1556
|
+
foundIrrefutableCase = true;
|
1557
|
+
}
|
1558
|
+
this._currentFlowNode = this._finishFlowLabel(preGuardLabel);
|
1559
|
+
// Bind the pattern.
|
1560
|
+
this.walk(caseStatement.pattern);
|
1561
|
+
if (isSubjectNarrowable) {
|
1562
|
+
this._createFlowNarrowForPattern(node.subjectExpression, caseStatement);
|
1563
|
+
}
|
1564
|
+
// Apply the guard expression.
|
1565
|
+
if (caseStatement.guardExpression) {
|
1566
|
+
this._bindConditional(caseStatement.guardExpression, preSuiteLabel, postCaseLabel);
|
1567
|
+
}
|
1568
|
+
else {
|
1569
|
+
this._addAntecedent(preSuiteLabel, this._currentFlowNode);
|
1570
|
+
}
|
1571
|
+
this._currentFlowNode = this._finishFlowLabel(preSuiteLabel);
|
1572
|
+
// Bind the body of the case statement.
|
1573
|
+
this.walk(caseStatement.suite);
|
1574
|
+
this._addAntecedent(postMatchLabel, this._currentFlowNode);
|
1575
|
+
this._currentFlowNode = this._finishFlowLabel(postCaseLabel);
|
1576
|
+
});
|
1577
|
+
// Add a final narrowing step for the subject expression for the entire
|
1578
|
+
// match statement. This will compute the narrowed type if no case
|
1579
|
+
// statements are matched.
|
1580
|
+
if (isSubjectNarrowable) {
|
1581
|
+
this._createFlowNarrowForPattern(node.subjectExpression, node);
|
1582
|
+
}
|
1583
|
+
// Create an "implied else" to conditionally gate code flow based on
|
1584
|
+
// whether the narrowed type of the subject expression is Never at this point.
|
1585
|
+
if (!foundIrrefutableCase) {
|
1586
|
+
this._createFlowExhaustedMatch(node);
|
1587
|
+
}
|
1588
|
+
this._addAntecedent(postMatchLabel, this._currentFlowNode);
|
1589
|
+
this._currentFlowNode = this._finishFlowLabel(postMatchLabel);
|
1590
|
+
return false;
|
1591
|
+
}
|
1592
|
+
visitPatternAs(node) {
|
1593
|
+
const postOrLabel = this._createBranchLabel();
|
1594
|
+
node.orPatterns.forEach((orPattern) => {
|
1595
|
+
this.walk(orPattern);
|
1596
|
+
this._addAntecedent(postOrLabel, this._currentFlowNode);
|
1597
|
+
});
|
1598
|
+
this._currentFlowNode = this._finishFlowLabel(postOrLabel);
|
1599
|
+
if (node.target) {
|
1600
|
+
this.walk(node.target);
|
1601
|
+
const symbol = this._bindNameToScope(this._currentScope, node.target.value);
|
1602
|
+
this._createAssignmentTargetFlowNodes(node.target, /* walkTargets */ false, /* unbound */ false);
|
1603
|
+
if (symbol) {
|
1604
|
+
const declaration = {
|
1605
|
+
type: 1 /* Variable */,
|
1606
|
+
node: node.target,
|
1607
|
+
isConstant: (0, symbolNameUtils_1.isConstantName)(node.target.value),
|
1608
|
+
inferredTypeSource: node,
|
1609
|
+
path: this._fileInfo.filePath,
|
1610
|
+
range: (0, positionUtils_1.convertOffsetsToRange)(node.target.start, textRange_2.TextRange.getEnd(node.target), this._fileInfo.lines),
|
1611
|
+
moduleName: this._fileInfo.moduleName,
|
1612
|
+
isInExceptSuite: this._isInExceptSuite,
|
1613
|
+
};
|
1614
|
+
symbol.addDeclaration(declaration);
|
1615
|
+
}
|
1616
|
+
}
|
1617
|
+
return false;
|
1618
|
+
}
|
1619
|
+
visitPatternCapture(node) {
|
1620
|
+
if (!node.isWildcard) {
|
1621
|
+
this._addPatternCaptureTarget(node.target);
|
1622
|
+
}
|
1623
|
+
return true;
|
1624
|
+
}
|
1625
|
+
visitPatternMappingExpandEntry(node) {
|
1626
|
+
if (node.target.value !== '_') {
|
1627
|
+
this._addPatternCaptureTarget(node.target);
|
1628
|
+
}
|
1629
|
+
return true;
|
1630
|
+
}
|
1631
|
+
_getNonClassParentScope() {
|
1632
|
+
// We may not be able to use the current scope if it's a class scope.
|
1633
|
+
// Walk up until we find a non-class scope instead.
|
1634
|
+
let parentScope = this._currentScope;
|
1635
|
+
while (parentScope.type === 2 /* Class */) {
|
1636
|
+
parentScope = parentScope.parent;
|
1637
|
+
}
|
1638
|
+
return parentScope;
|
1639
|
+
}
|
1640
|
+
_addSlotsToCurrentScope(slotNameNodes) {
|
1641
|
+
(0, debug_1.assert)(this._currentScope.type === 2 /* Class */);
|
1642
|
+
let slotsContainsDict = false;
|
1643
|
+
for (const slotNameNode of slotNameNodes) {
|
1644
|
+
const slotName = slotNameNode.strings[0].value;
|
1645
|
+
if (slotName === '__dict__') {
|
1646
|
+
slotsContainsDict = true;
|
1647
|
+
continue;
|
1648
|
+
}
|
1649
|
+
let symbol = this._currentScope.lookUpSymbol(slotName);
|
1650
|
+
if (!symbol) {
|
1651
|
+
symbol = this._currentScope.addSymbol(slotName, 1 /* InitiallyUnbound */ | 4 /* ClassMember */);
|
1652
|
+
const honorPrivateNaming = this._fileInfo.diagnosticRuleSet.reportPrivateUsage !== 'none';
|
1653
|
+
if ((0, symbolNameUtils_1.isPrivateOrProtectedName)(slotName) && honorPrivateNaming) {
|
1654
|
+
symbol.setIsPrivateMember();
|
1655
|
+
}
|
1656
|
+
}
|
1657
|
+
const declaration = {
|
1658
|
+
type: 1 /* Variable */,
|
1659
|
+
node: slotNameNode,
|
1660
|
+
isConstant: (0, symbolNameUtils_1.isConstantName)(slotName),
|
1661
|
+
isDefinedBySlots: true,
|
1662
|
+
path: this._fileInfo.filePath,
|
1663
|
+
range: (0, positionUtils_1.convertOffsetsToRange)(slotNameNode.start, slotNameNode.start + slotNameNode.length, this._fileInfo.lines),
|
1664
|
+
moduleName: this._fileInfo.moduleName,
|
1665
|
+
isInExceptSuite: this._isInExceptSuite,
|
1666
|
+
};
|
1667
|
+
symbol.addDeclaration(declaration);
|
1668
|
+
}
|
1669
|
+
if (!slotsContainsDict) {
|
1670
|
+
this._currentScope.setSlotsNames(slotNameNodes.map((node) => node.strings[0].value));
|
1671
|
+
}
|
1672
|
+
}
|
1673
|
+
_isInListComprehension(node, ignoreOutermostIterable = false) {
|
1674
|
+
let curNode = node;
|
1675
|
+
let prevNode;
|
1676
|
+
let prevPrevNode;
|
1677
|
+
while (curNode) {
|
1678
|
+
if (curNode.nodeType === 32 /* ListComprehension */) {
|
1679
|
+
if (ignoreOutermostIterable && curNode.forIfNodes.length > 0) {
|
1680
|
+
const outermostCompr = curNode.forIfNodes[0];
|
1681
|
+
if (prevNode === outermostCompr && outermostCompr.nodeType === 33 /* ListComprehensionFor */) {
|
1682
|
+
if (prevPrevNode === outermostCompr.iterableExpression) {
|
1683
|
+
return false;
|
1684
|
+
}
|
1685
|
+
}
|
1686
|
+
}
|
1687
|
+
return true;
|
1688
|
+
}
|
1689
|
+
prevPrevNode = prevNode;
|
1690
|
+
prevNode = curNode;
|
1691
|
+
curNode = curNode.parent;
|
1692
|
+
}
|
1693
|
+
return false;
|
1694
|
+
}
|
1695
|
+
_addPatternCaptureTarget(target) {
|
1696
|
+
const symbol = this._bindNameToScope(this._currentScope, target.value);
|
1697
|
+
this._createAssignmentTargetFlowNodes(target, /* walkTargets */ false, /* unbound */ false);
|
1698
|
+
if (symbol) {
|
1699
|
+
const declaration = {
|
1700
|
+
type: 1 /* Variable */,
|
1701
|
+
node: target,
|
1702
|
+
isConstant: (0, symbolNameUtils_1.isConstantName)(target.value),
|
1703
|
+
inferredTypeSource: target.parent,
|
1704
|
+
path: this._fileInfo.filePath,
|
1705
|
+
range: (0, positionUtils_1.convertOffsetsToRange)(target.start, textRange_2.TextRange.getEnd(target), this._fileInfo.lines),
|
1706
|
+
moduleName: this._fileInfo.moduleName,
|
1707
|
+
isInExceptSuite: this._isInExceptSuite,
|
1708
|
+
};
|
1709
|
+
symbol.addDeclaration(declaration);
|
1710
|
+
}
|
1711
|
+
}
|
1712
|
+
_useExceptTargets(targets, callback) {
|
1713
|
+
const prevExceptTargets = this._currentExceptTargets;
|
1714
|
+
this._currentExceptTargets = targets;
|
1715
|
+
callback();
|
1716
|
+
this._currentExceptTargets = prevExceptTargets;
|
1717
|
+
}
|
1718
|
+
// Attempts to resolve the module name, import it, and return
|
1719
|
+
// its __all__ symbols.
|
1720
|
+
_getDunderAllNamesFromImport(varName) {
|
1721
|
+
var _a;
|
1722
|
+
const varSymbol = this._currentScope.lookUpSymbol(varName);
|
1723
|
+
if (!varSymbol) {
|
1724
|
+
return undefined;
|
1725
|
+
}
|
1726
|
+
// There should be only one declaration for the variable.
|
1727
|
+
const aliasDecl = varSymbol.getDeclarations().find((decl) => decl.type === 6 /* Alias */);
|
1728
|
+
const resolvedPath = (aliasDecl === null || aliasDecl === void 0 ? void 0 : aliasDecl.path) && aliasDecl.loadSymbolsFromPath
|
1729
|
+
? aliasDecl.path
|
1730
|
+
: ((_a = aliasDecl === null || aliasDecl === void 0 ? void 0 : aliasDecl.submoduleFallback) === null || _a === void 0 ? void 0 : _a.path) && aliasDecl.submoduleFallback.loadSymbolsFromPath
|
1731
|
+
? aliasDecl.submoduleFallback.path
|
1732
|
+
: undefined;
|
1733
|
+
if (!resolvedPath) {
|
1734
|
+
return undefined;
|
1735
|
+
}
|
1736
|
+
const lookupInfo = this._fileInfo.importLookup(resolvedPath);
|
1737
|
+
if (!lookupInfo) {
|
1738
|
+
return undefined;
|
1739
|
+
}
|
1740
|
+
return lookupInfo.dunderAllNames;
|
1741
|
+
}
|
1742
|
+
_addImplicitFromImport(node, importInfo) {
|
1743
|
+
const symbolName = node.module.nameParts[0].value;
|
1744
|
+
const symbol = this._bindNameToScope(this._currentScope, symbolName);
|
1745
|
+
if (symbol) {
|
1746
|
+
this._createAliasDeclarationForMultipartImportName(node, /* importAlias */ undefined, importInfo, symbol);
|
1747
|
+
}
|
1748
|
+
this._createFlowAssignment(node.module.nameParts[0]);
|
1749
|
+
}
|
1750
|
+
_createAliasDeclarationForMultipartImportName(node, importAlias, importInfo, symbol) {
|
1751
|
+
var _a;
|
1752
|
+
const firstNamePartValue = node.module.nameParts[0].value;
|
1753
|
+
// See if there's already a matching alias declaration for this import.
|
1754
|
+
// if so, we'll update it rather than creating a new one. This is required
|
1755
|
+
// to handle cases where multiple import statements target the same
|
1756
|
+
// starting symbol such as "import a.b.c" and "import a.d". In this case,
|
1757
|
+
// we'll build a single declaration that describes the combined actions
|
1758
|
+
// of both import statements, thus reflecting the behavior of the
|
1759
|
+
// python module loader.
|
1760
|
+
const existingDecl = symbol
|
1761
|
+
.getDeclarations()
|
1762
|
+
.find((decl) => decl.type === 6 /* Alias */ && decl.firstNamePart === firstNamePartValue);
|
1763
|
+
let newDecl;
|
1764
|
+
let pathOfLastSubmodule;
|
1765
|
+
if (importInfo && importInfo.isImportFound && !importInfo.isNativeLib && importInfo.resolvedPaths.length > 0) {
|
1766
|
+
pathOfLastSubmodule = importInfo.resolvedPaths[importInfo.resolvedPaths.length - 1];
|
1767
|
+
}
|
1768
|
+
else {
|
1769
|
+
pathOfLastSubmodule = '*** unresolved ***';
|
1770
|
+
}
|
1771
|
+
const isResolved = importInfo && importInfo.isImportFound && !importInfo.isNativeLib && importInfo.resolvedPaths.length > 0;
|
1772
|
+
if (existingDecl) {
|
1773
|
+
newDecl = existingDecl;
|
1774
|
+
}
|
1775
|
+
else if (isResolved) {
|
1776
|
+
newDecl = {
|
1777
|
+
type: 6 /* Alias */,
|
1778
|
+
node,
|
1779
|
+
path: pathOfLastSubmodule,
|
1780
|
+
loadSymbolsFromPath: false,
|
1781
|
+
range: (0, textRange_1.getEmptyRange)(),
|
1782
|
+
usesLocalName: !!importAlias,
|
1783
|
+
moduleName: importInfo.importName,
|
1784
|
+
firstNamePart: firstNamePartValue,
|
1785
|
+
isInExceptSuite: this._isInExceptSuite,
|
1786
|
+
};
|
1787
|
+
}
|
1788
|
+
else {
|
1789
|
+
// If we couldn't resolve the import, create a dummy declaration with a
|
1790
|
+
// bogus path so it gets an unknown type (rather than an unbound type) at
|
1791
|
+
// analysis time.
|
1792
|
+
newDecl = {
|
1793
|
+
type: 6 /* Alias */,
|
1794
|
+
node,
|
1795
|
+
path: pathOfLastSubmodule,
|
1796
|
+
loadSymbolsFromPath: true,
|
1797
|
+
range: (0, textRange_1.getEmptyRange)(),
|
1798
|
+
usesLocalName: !!importAlias,
|
1799
|
+
moduleName: (_a = importInfo === null || importInfo === void 0 ? void 0 : importInfo.importName) !== null && _a !== void 0 ? _a : '',
|
1800
|
+
firstNamePart: firstNamePartValue,
|
1801
|
+
isUnresolved: true,
|
1802
|
+
isInExceptSuite: this._isInExceptSuite,
|
1803
|
+
};
|
1804
|
+
}
|
1805
|
+
// Add the implicit imports for this module if it's the last
|
1806
|
+
// name part we're resolving.
|
1807
|
+
if (importAlias || node.module.nameParts.length === 1) {
|
1808
|
+
newDecl.path = pathOfLastSubmodule;
|
1809
|
+
newDecl.loadSymbolsFromPath = true;
|
1810
|
+
newDecl.isUnresolved = false;
|
1811
|
+
if (importInfo) {
|
1812
|
+
this._addImplicitImportsToLoaderActions(importInfo, newDecl);
|
1813
|
+
}
|
1814
|
+
}
|
1815
|
+
else {
|
1816
|
+
// Fill in the remaining name parts.
|
1817
|
+
let curLoaderActions = newDecl;
|
1818
|
+
for (let i = 1; i < node.module.nameParts.length; i++) {
|
1819
|
+
const namePartValue = node.module.nameParts[i].value;
|
1820
|
+
// Is there an existing loader action for this name?
|
1821
|
+
let loaderActions = curLoaderActions.implicitImports
|
1822
|
+
? curLoaderActions.implicitImports.get(namePartValue)
|
1823
|
+
: undefined;
|
1824
|
+
if (!loaderActions) {
|
1825
|
+
const loaderActionPath = importInfo && i < importInfo.resolvedPaths.length
|
1826
|
+
? importInfo.resolvedPaths[i]
|
1827
|
+
: '*** unresolved ***';
|
1828
|
+
// Allocate a new loader action.
|
1829
|
+
loaderActions = {
|
1830
|
+
path: loaderActionPath,
|
1831
|
+
loadSymbolsFromPath: false,
|
1832
|
+
implicitImports: new Map(),
|
1833
|
+
isUnresolved: !isResolved,
|
1834
|
+
};
|
1835
|
+
if (!curLoaderActions.implicitImports) {
|
1836
|
+
curLoaderActions.implicitImports = new Map();
|
1837
|
+
}
|
1838
|
+
curLoaderActions.implicitImports.set(namePartValue, loaderActions);
|
1839
|
+
}
|
1840
|
+
// If this is the last name part we're resolving, add in the
|
1841
|
+
// implicit imports as well.
|
1842
|
+
if (i === node.module.nameParts.length - 1) {
|
1843
|
+
if (importInfo && i < importInfo.resolvedPaths.length) {
|
1844
|
+
loaderActions.path = importInfo.resolvedPaths[i];
|
1845
|
+
loaderActions.loadSymbolsFromPath = true;
|
1846
|
+
this._addImplicitImportsToLoaderActions(importInfo, loaderActions);
|
1847
|
+
}
|
1848
|
+
}
|
1849
|
+
curLoaderActions = loaderActions;
|
1850
|
+
}
|
1851
|
+
}
|
1852
|
+
if (!existingDecl) {
|
1853
|
+
symbol.addDeclaration(newDecl);
|
1854
|
+
}
|
1855
|
+
}
|
1856
|
+
_getWildcardImportNames(lookupInfo) {
|
1857
|
+
const namesToImport = [];
|
1858
|
+
// If a dunder all symbol is defined, it takes precedence.
|
1859
|
+
if (lookupInfo.dunderAllNames) {
|
1860
|
+
if (!lookupInfo.usesUnsupportedDunderAllForm) {
|
1861
|
+
return lookupInfo.dunderAllNames;
|
1862
|
+
}
|
1863
|
+
(0, collectionUtils_1.appendArray)(namesToImport, lookupInfo.dunderAllNames);
|
1864
|
+
}
|
1865
|
+
lookupInfo.symbolTable.forEach((symbol, name) => {
|
1866
|
+
if (!symbol.isExternallyHidden() && !(0, symbolNameUtils_1.isPrivateOrProtectedName)(name)) {
|
1867
|
+
namesToImport.push(name);
|
1868
|
+
}
|
1869
|
+
});
|
1870
|
+
return namesToImport;
|
1871
|
+
}
|
1872
|
+
_walkStatementsAndReportUnreachable(statements) {
|
1873
|
+
let foundUnreachableStatement = false;
|
1874
|
+
for (const statement of statements) {
|
1875
|
+
AnalyzerNodeInfo.setFlowNode(statement, this._currentFlowNode);
|
1876
|
+
if (!foundUnreachableStatement) {
|
1877
|
+
foundUnreachableStatement = this._isCodeUnreachable();
|
1878
|
+
}
|
1879
|
+
if (!foundUnreachableStatement) {
|
1880
|
+
this.walk(statement);
|
1881
|
+
}
|
1882
|
+
else {
|
1883
|
+
// If we're within a function, we need to look for unreachable yield
|
1884
|
+
// statements because they affect the behavior of the function (making
|
1885
|
+
// it a generator) even if they're never executed.
|
1886
|
+
if (this._targetFunctionDeclaration && !this._targetFunctionDeclaration.isGenerator) {
|
1887
|
+
const yieldFinder = new YieldFinder();
|
1888
|
+
if (yieldFinder.checkContainsYield(statement)) {
|
1889
|
+
this._targetFunctionDeclaration.isGenerator = true;
|
1890
|
+
}
|
1891
|
+
}
|
1892
|
+
}
|
1893
|
+
}
|
1894
|
+
return false;
|
1895
|
+
}
|
1896
|
+
_createStartFlowNode() {
|
1897
|
+
const flowNode = {
|
1898
|
+
flags: codeFlowTypes_1.FlowFlags.Start,
|
1899
|
+
id: this._getUniqueFlowNodeId(),
|
1900
|
+
};
|
1901
|
+
return flowNode;
|
1902
|
+
}
|
1903
|
+
_createBranchLabel(preBranchAntecedent) {
|
1904
|
+
const flowNode = {
|
1905
|
+
flags: codeFlowTypes_1.FlowFlags.BranchLabel,
|
1906
|
+
id: this._getUniqueFlowNodeId(),
|
1907
|
+
antecedents: [],
|
1908
|
+
preBranchAntecedent,
|
1909
|
+
affectedExpressions: undefined,
|
1910
|
+
};
|
1911
|
+
return flowNode;
|
1912
|
+
}
|
1913
|
+
// Create a flow node that narrows the type of the subject expression for
|
1914
|
+
// a specified case statement or the entire match statement (if the flow
|
1915
|
+
// falls through the bottom of all cases).
|
1916
|
+
_createFlowNarrowForPattern(subjectExpression, statement) {
|
1917
|
+
const flowNode = {
|
1918
|
+
flags: codeFlowTypes_1.FlowFlags.NarrowForPattern,
|
1919
|
+
id: this._getUniqueFlowNodeId(),
|
1920
|
+
subjectExpression,
|
1921
|
+
statement,
|
1922
|
+
antecedent: this._currentFlowNode,
|
1923
|
+
};
|
1924
|
+
this._currentFlowNode = flowNode;
|
1925
|
+
}
|
1926
|
+
_createContextManagerLabel(expressions, isAsync, blockIfSwallowsExceptions) {
|
1927
|
+
const flowNode = {
|
1928
|
+
flags: codeFlowTypes_1.FlowFlags.PostContextManager | codeFlowTypes_1.FlowFlags.BranchLabel,
|
1929
|
+
id: this._getUniqueFlowNodeId(),
|
1930
|
+
antecedents: [],
|
1931
|
+
expressions,
|
1932
|
+
affectedExpressions: undefined,
|
1933
|
+
isAsync,
|
1934
|
+
blockIfSwallowsExceptions,
|
1935
|
+
};
|
1936
|
+
return flowNode;
|
1937
|
+
}
|
1938
|
+
_createLoopLabel() {
|
1939
|
+
const flowNode = {
|
1940
|
+
flags: codeFlowTypes_1.FlowFlags.LoopLabel,
|
1941
|
+
id: this._getUniqueFlowNodeId(),
|
1942
|
+
antecedents: [],
|
1943
|
+
affectedExpressions: undefined,
|
1944
|
+
};
|
1945
|
+
return flowNode;
|
1946
|
+
}
|
1947
|
+
_finishFlowLabel(node) {
|
1948
|
+
// If there were no antecedents, this is unreachable.
|
1949
|
+
if (node.antecedents.length === 0) {
|
1950
|
+
return Binder._unreachableFlowNode;
|
1951
|
+
}
|
1952
|
+
// If there was only one antecedent and this is a simple
|
1953
|
+
// branch label, there's no need for a label to exist.
|
1954
|
+
if (node.antecedents.length === 1 && node.flags === codeFlowTypes_1.FlowFlags.BranchLabel) {
|
1955
|
+
return node.antecedents[0];
|
1956
|
+
}
|
1957
|
+
// The cyclomatic complexity is the number of edges minus the
|
1958
|
+
// number of nodes in the graph. Add n-1 where n is the number
|
1959
|
+
// of antecedents (edges) and 1 represents the label node.
|
1960
|
+
this._codeFlowComplexity += node.antecedents.length - 1;
|
1961
|
+
return node;
|
1962
|
+
}
|
1963
|
+
// Creates a node that creates a "gate" that is closed (doesn't allow for code
|
1964
|
+
// flow) if the specified expression is never once it is narrowed (in either the
|
1965
|
+
// positive or negative case).
|
1966
|
+
_bindNeverCondition(node, target, isPositiveTest) {
|
1967
|
+
const expressionList = [];
|
1968
|
+
if (node.nodeType === 55 /* UnaryOperation */ && node.operator === 38 /* Not */) {
|
1969
|
+
this._bindNeverCondition(node.expression, target, !isPositiveTest);
|
1970
|
+
}
|
1971
|
+
else if (node.nodeType === 7 /* BinaryOperation */ &&
|
1972
|
+
(node.operator === 36 /* And */ || node.operator === 37 /* Or */)) {
|
1973
|
+
let isAnd = node.operator === 36 /* And */;
|
1974
|
+
if (isPositiveTest) {
|
1975
|
+
isAnd = !isAnd;
|
1976
|
+
}
|
1977
|
+
if (isAnd) {
|
1978
|
+
// In the And case, we need to gate the synthesized else clause if both
|
1979
|
+
// of the operands evaluate to never once they are narrowed.
|
1980
|
+
const savedCurrentFlowNode = this._currentFlowNode;
|
1981
|
+
this._bindNeverCondition(node.leftExpression, target, isPositiveTest);
|
1982
|
+
this._currentFlowNode = savedCurrentFlowNode;
|
1983
|
+
this._bindNeverCondition(node.rightExpression, target, isPositiveTest);
|
1984
|
+
}
|
1985
|
+
else {
|
1986
|
+
const initialCurrentFlowNode = this._currentFlowNode;
|
1987
|
+
// In the Or case, we need to gate the synthesized else clause if either
|
1988
|
+
// of the operands evaluate to never.
|
1989
|
+
const afterLabel = this._createBranchLabel();
|
1990
|
+
this._bindNeverCondition(node.leftExpression, afterLabel, isPositiveTest);
|
1991
|
+
// If the condition didn't result in any new flow nodes, we can skip
|
1992
|
+
// checking the other condition.
|
1993
|
+
if (initialCurrentFlowNode !== this._currentFlowNode) {
|
1994
|
+
this._currentFlowNode = this._finishFlowLabel(afterLabel);
|
1995
|
+
const prevCurrentNode = this._currentFlowNode;
|
1996
|
+
this._bindNeverCondition(node.rightExpression, target, isPositiveTest);
|
1997
|
+
// If the second condition resulted in no new control flow node, we can
|
1998
|
+
// eliminate this entire subgraph.
|
1999
|
+
if (prevCurrentNode === this._currentFlowNode) {
|
2000
|
+
this._currentFlowNode = initialCurrentFlowNode;
|
2001
|
+
}
|
2002
|
+
}
|
2003
|
+
}
|
2004
|
+
}
|
2005
|
+
else {
|
2006
|
+
// Limit only to expressions that contain a narrowable subexpression
|
2007
|
+
// that is a name. This avoids complexities with composite expressions like
|
2008
|
+
// member access or index expressions.
|
2009
|
+
if (this._isNarrowingExpression(node, expressionList, /* neverNarrowingExpressions */ true)) {
|
2010
|
+
const filteredExprList = expressionList.filter((expr) => expr.nodeType === 38 /* Name */);
|
2011
|
+
if (filteredExprList.length > 0) {
|
2012
|
+
this._currentFlowNode = this._createFlowConditional(isPositiveTest ? codeFlowTypes_1.FlowFlags.TrueNeverCondition : codeFlowTypes_1.FlowFlags.FalseNeverCondition, this._currentFlowNode, node);
|
2013
|
+
}
|
2014
|
+
}
|
2015
|
+
this._addAntecedent(target, this._currentFlowNode);
|
2016
|
+
}
|
2017
|
+
}
|
2018
|
+
_bindConditional(node, trueTarget, falseTarget) {
|
2019
|
+
this._setTrueFalseTargets(trueTarget, falseTarget, () => {
|
2020
|
+
this.walk(node);
|
2021
|
+
});
|
2022
|
+
if (!this._isLogicalExpression(node)) {
|
2023
|
+
this._addAntecedent(trueTarget, this._createFlowConditional(codeFlowTypes_1.FlowFlags.TrueCondition, this._currentFlowNode, node));
|
2024
|
+
this._addAntecedent(falseTarget, this._createFlowConditional(codeFlowTypes_1.FlowFlags.FalseCondition, this._currentFlowNode, node));
|
2025
|
+
}
|
2026
|
+
}
|
2027
|
+
_disableTrueFalseTargets(callback) {
|
2028
|
+
this._setTrueFalseTargets(/* trueTarget */ undefined, /* falseTarget */ undefined, callback);
|
2029
|
+
}
|
2030
|
+
_setTrueFalseTargets(trueTarget, falseTarget, callback) {
|
2031
|
+
const savedTrueTarget = this._currentTrueTarget;
|
2032
|
+
const savedFalseTarget = this._currentFalseTarget;
|
2033
|
+
this._currentTrueTarget = trueTarget;
|
2034
|
+
this._currentFalseTarget = falseTarget;
|
2035
|
+
callback();
|
2036
|
+
this._currentTrueTarget = savedTrueTarget;
|
2037
|
+
this._currentFalseTarget = savedFalseTarget;
|
2038
|
+
}
|
2039
|
+
_createFlowConditional(flags, antecedent, expression) {
|
2040
|
+
if (antecedent.flags & codeFlowTypes_1.FlowFlags.Unreachable) {
|
2041
|
+
return antecedent;
|
2042
|
+
}
|
2043
|
+
const staticValue = StaticExpressions.evaluateStaticBoolLikeExpression(expression, this._fileInfo.executionEnvironment, this._fileInfo.definedConstants, this._typingImportAliases, this._sysImportAliases);
|
2044
|
+
if ((staticValue === true && flags & codeFlowTypes_1.FlowFlags.FalseCondition) ||
|
2045
|
+
(staticValue === false && flags & codeFlowTypes_1.FlowFlags.TrueCondition)) {
|
2046
|
+
return Binder._unreachableFlowNode;
|
2047
|
+
}
|
2048
|
+
const expressionList = [];
|
2049
|
+
if (!this._isNarrowingExpression(expression, expressionList)) {
|
2050
|
+
return antecedent;
|
2051
|
+
}
|
2052
|
+
expressionList.forEach((expr) => {
|
2053
|
+
const referenceKey = (0, codeFlowTypes_1.createKeyForReference)(expr);
|
2054
|
+
this._currentScopeCodeFlowExpressions.add(referenceKey);
|
2055
|
+
});
|
2056
|
+
// Select the first name expression.
|
2057
|
+
const filteredExprList = expressionList.filter((expr) => expr.nodeType === 38 /* Name */);
|
2058
|
+
const conditionalFlowNode = {
|
2059
|
+
flags,
|
2060
|
+
id: this._getUniqueFlowNodeId(),
|
2061
|
+
reference: filteredExprList.length > 0 ? filteredExprList[0] : undefined,
|
2062
|
+
expression,
|
2063
|
+
antecedent,
|
2064
|
+
};
|
2065
|
+
this._addExceptTargets(conditionalFlowNode);
|
2066
|
+
return conditionalFlowNode;
|
2067
|
+
}
|
2068
|
+
// Indicates whether the expression is a NOT, AND or OR expression.
|
2069
|
+
_isLogicalExpression(expression) {
|
2070
|
+
switch (expression.nodeType) {
|
2071
|
+
case 55 /* UnaryOperation */: {
|
2072
|
+
return expression.operator === 38 /* Not */;
|
2073
|
+
}
|
2074
|
+
case 7 /* BinaryOperation */: {
|
2075
|
+
return expression.operator === 36 /* And */ || expression.operator === 37 /* Or */;
|
2076
|
+
}
|
2077
|
+
}
|
2078
|
+
return false;
|
2079
|
+
}
|
2080
|
+
// Determines whether the specified expression can be used for conditional
|
2081
|
+
// type narrowing. The expression atoms (names, member accesses and index)
|
2082
|
+
// are provided as an output in the expressionList.
|
2083
|
+
// If filterForNeverNarrowing is true, we limit some types of narrowing
|
2084
|
+
// expressions for performance reasons.
|
2085
|
+
// The isComplexExpression parameter is used internally to determine whether
|
2086
|
+
// the call is an atom (name, member access, index - plus a "not" form of
|
2087
|
+
// these) or something more complex (binary operator, call, etc.).
|
2088
|
+
_isNarrowingExpression(expression, expressionList, filterForNeverNarrowing = false, isComplexExpression = false) {
|
2089
|
+
switch (expression.nodeType) {
|
2090
|
+
case 38 /* Name */:
|
2091
|
+
case 35 /* MemberAccess */:
|
2092
|
+
case 24 /* Index */: {
|
2093
|
+
if (filterForNeverNarrowing) {
|
2094
|
+
// Never narrowing doesn't support member access or index
|
2095
|
+
// expressions.
|
2096
|
+
if (expression.nodeType !== 38 /* Name */) {
|
2097
|
+
return false;
|
2098
|
+
}
|
2099
|
+
// Never narrowing doesn't support simple names (falsy
|
2100
|
+
// or truthy narrowing) because it's too expensive and
|
2101
|
+
// provides relatively little utility.
|
2102
|
+
if (!isComplexExpression) {
|
2103
|
+
return false;
|
2104
|
+
}
|
2105
|
+
}
|
2106
|
+
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(expression)) {
|
2107
|
+
expressionList.push(expression);
|
2108
|
+
return true;
|
2109
|
+
}
|
2110
|
+
return false;
|
2111
|
+
}
|
2112
|
+
case 4 /* AssignmentExpression */: {
|
2113
|
+
expressionList.push(expression.name);
|
2114
|
+
this._isNarrowingExpression(expression.rightExpression, expressionList, filterForNeverNarrowing,
|
2115
|
+
/* isComplexExpression */ true);
|
2116
|
+
return true;
|
2117
|
+
}
|
2118
|
+
case 7 /* BinaryOperation */: {
|
2119
|
+
const isOrIsNotOperator = expression.operator === 39 /* Is */ || expression.operator === 40 /* IsNot */;
|
2120
|
+
const equalsOrNotEqualsOperator = expression.operator === 12 /* Equals */ || expression.operator === 28 /* NotEquals */;
|
2121
|
+
if (isOrIsNotOperator || equalsOrNotEqualsOperator) {
|
2122
|
+
// Look for "X is None", "X is not None", "X == None", "X != None".
|
2123
|
+
// These are commonly-used patterns used in control flow.
|
2124
|
+
if (expression.rightExpression.nodeType === 11 /* Constant */ &&
|
2125
|
+
expression.rightExpression.constType === 26 /* None */) {
|
2126
|
+
return this._isNarrowingExpression(expression.leftExpression, expressionList, filterForNeverNarrowing,
|
2127
|
+
/* isComplexExpression */ true);
|
2128
|
+
}
|
2129
|
+
// Look for "type(X) is Y" or "type(X) is not Y".
|
2130
|
+
if (isOrIsNotOperator &&
|
2131
|
+
expression.leftExpression.nodeType === 9 /* Call */ &&
|
2132
|
+
expression.leftExpression.leftExpression.nodeType === 38 /* Name */ &&
|
2133
|
+
expression.leftExpression.leftExpression.value === 'type' &&
|
2134
|
+
expression.leftExpression.arguments.length === 1 &&
|
2135
|
+
expression.leftExpression.arguments[0].argumentCategory === 0 /* Simple */) {
|
2136
|
+
return this._isNarrowingExpression(expression.leftExpression.arguments[0].valueExpression, expressionList, filterForNeverNarrowing,
|
2137
|
+
/* isComplexExpression */ true);
|
2138
|
+
}
|
2139
|
+
const isLeftNarrowing = this._isNarrowingExpression(expression.leftExpression, expressionList, filterForNeverNarrowing,
|
2140
|
+
/* isComplexExpression */ true);
|
2141
|
+
// Look for "X is Y" or "X is not Y".
|
2142
|
+
if (isOrIsNotOperator) {
|
2143
|
+
return isLeftNarrowing;
|
2144
|
+
}
|
2145
|
+
// Look for X == <literal>, X != <literal> or <literal> == X, <literal> != X
|
2146
|
+
if (equalsOrNotEqualsOperator) {
|
2147
|
+
const isRightNarrowing = this._isNarrowingExpression(expression.rightExpression, expressionList, filterForNeverNarrowing,
|
2148
|
+
/* isComplexExpression */ true);
|
2149
|
+
return isLeftNarrowing || isRightNarrowing;
|
2150
|
+
}
|
2151
|
+
}
|
2152
|
+
// Look for "<string> in Y" or "<string> not in Y".
|
2153
|
+
if (expression.operator === 41 /* In */ || expression.operator === 42 /* NotIn */) {
|
2154
|
+
if (expression.leftExpression.nodeType === 48 /* StringList */ &&
|
2155
|
+
this._isNarrowingExpression(expression.rightExpression, expressionList, filterForNeverNarrowing,
|
2156
|
+
/* isComplexExpression */ true)) {
|
2157
|
+
return true;
|
2158
|
+
}
|
2159
|
+
}
|
2160
|
+
// Look for "X in Y" or "X not in Y".
|
2161
|
+
if (expression.operator === 41 /* In */ || expression.operator === 42 /* NotIn */) {
|
2162
|
+
return this._isNarrowingExpression(expression.leftExpression, expressionList, filterForNeverNarrowing,
|
2163
|
+
/* isComplexExpression */ true);
|
2164
|
+
}
|
2165
|
+
return false;
|
2166
|
+
}
|
2167
|
+
case 55 /* UnaryOperation */: {
|
2168
|
+
return (expression.operator === 38 /* Not */ &&
|
2169
|
+
this._isNarrowingExpression(expression.expression, expressionList, filterForNeverNarrowing,
|
2170
|
+
/* isComplexExpression */ false));
|
2171
|
+
}
|
2172
|
+
case 5 /* AugmentedAssignment */: {
|
2173
|
+
return this._isNarrowingExpression(expression.rightExpression, expressionList, filterForNeverNarrowing,
|
2174
|
+
/* isComplexExpression */ true);
|
2175
|
+
}
|
2176
|
+
case 9 /* Call */: {
|
2177
|
+
if (expression.leftExpression.nodeType === 38 /* Name */ &&
|
2178
|
+
(expression.leftExpression.value === 'isinstance' ||
|
2179
|
+
expression.leftExpression.value === 'issubclass') &&
|
2180
|
+
expression.arguments.length === 2) {
|
2181
|
+
return this._isNarrowingExpression(expression.arguments[0].valueExpression, expressionList, filterForNeverNarrowing,
|
2182
|
+
/* isComplexExpression */ true);
|
2183
|
+
}
|
2184
|
+
if (expression.leftExpression.nodeType === 38 /* Name */ &&
|
2185
|
+
expression.leftExpression.value === 'callable' &&
|
2186
|
+
expression.arguments.length === 1) {
|
2187
|
+
return this._isNarrowingExpression(expression.arguments[0].valueExpression, expressionList, filterForNeverNarrowing,
|
2188
|
+
/* isComplexExpression */ true);
|
2189
|
+
}
|
2190
|
+
// Is this potentially a call to a user-defined type guard function?
|
2191
|
+
if (expression.arguments.length >= 1) {
|
2192
|
+
// Never narrowing doesn't support type guards because they do not
|
2193
|
+
// offer negative narrowing.
|
2194
|
+
if (filterForNeverNarrowing) {
|
2195
|
+
return false;
|
2196
|
+
}
|
2197
|
+
return this._isNarrowingExpression(expression.arguments[0].valueExpression, expressionList, filterForNeverNarrowing,
|
2198
|
+
/* isComplexExpression */ true);
|
2199
|
+
}
|
2200
|
+
}
|
2201
|
+
}
|
2202
|
+
return false;
|
2203
|
+
}
|
2204
|
+
_createAssignmentTargetFlowNodes(target, walkTargets, unbound) {
|
2205
|
+
switch (target.nodeType) {
|
2206
|
+
case 38 /* Name */:
|
2207
|
+
case 35 /* MemberAccess */: {
|
2208
|
+
this._createFlowAssignment(target, unbound);
|
2209
|
+
if (walkTargets) {
|
2210
|
+
this.walk(target);
|
2211
|
+
}
|
2212
|
+
break;
|
2213
|
+
}
|
2214
|
+
case 24 /* Index */: {
|
2215
|
+
this._createFlowAssignment(target, unbound);
|
2216
|
+
if (walkTargets) {
|
2217
|
+
this.walk(target);
|
2218
|
+
}
|
2219
|
+
break;
|
2220
|
+
}
|
2221
|
+
case 52 /* Tuple */: {
|
2222
|
+
target.expressions.forEach((expr) => {
|
2223
|
+
this._createAssignmentTargetFlowNodes(expr, walkTargets, unbound);
|
2224
|
+
});
|
2225
|
+
break;
|
2226
|
+
}
|
2227
|
+
case 54 /* TypeAnnotation */: {
|
2228
|
+
this._createAssignmentTargetFlowNodes(target.valueExpression, /* walkTargets */ false, unbound);
|
2229
|
+
if (walkTargets) {
|
2230
|
+
this.walk(target);
|
2231
|
+
}
|
2232
|
+
break;
|
2233
|
+
}
|
2234
|
+
case 56 /* Unpack */: {
|
2235
|
+
this._createAssignmentTargetFlowNodes(target.expression, /* walkTargets */ false, unbound);
|
2236
|
+
if (walkTargets) {
|
2237
|
+
this.walk(target);
|
2238
|
+
}
|
2239
|
+
break;
|
2240
|
+
}
|
2241
|
+
case 31 /* List */: {
|
2242
|
+
target.entries.forEach((entry) => {
|
2243
|
+
this._createAssignmentTargetFlowNodes(entry, walkTargets, unbound);
|
2244
|
+
});
|
2245
|
+
break;
|
2246
|
+
}
|
2247
|
+
default: {
|
2248
|
+
if (walkTargets) {
|
2249
|
+
this.walk(target);
|
2250
|
+
}
|
2251
|
+
}
|
2252
|
+
}
|
2253
|
+
}
|
2254
|
+
_createCallFlowNode(node) {
|
2255
|
+
if (!this._isCodeUnreachable()) {
|
2256
|
+
const flowNode = {
|
2257
|
+
flags: codeFlowTypes_1.FlowFlags.Call,
|
2258
|
+
id: this._getUniqueFlowNodeId(),
|
2259
|
+
node,
|
2260
|
+
antecedent: this._currentFlowNode,
|
2261
|
+
};
|
2262
|
+
this._currentFlowNode = flowNode;
|
2263
|
+
}
|
2264
|
+
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
2265
|
+
if (!this._isCodeUnreachable()) {
|
2266
|
+
this._addExceptTargets(this._currentFlowNode);
|
2267
|
+
}
|
2268
|
+
}
|
2269
|
+
_createVariableAnnotationFlowNode() {
|
2270
|
+
if (!this._isCodeUnreachable()) {
|
2271
|
+
const flowNode = {
|
2272
|
+
flags: codeFlowTypes_1.FlowFlags.VariableAnnotation,
|
2273
|
+
id: this._getUniqueFlowNodeId(),
|
2274
|
+
antecedent: this._currentFlowNode,
|
2275
|
+
};
|
2276
|
+
this._currentFlowNode = flowNode;
|
2277
|
+
}
|
2278
|
+
}
|
2279
|
+
_createFlowAssignment(node, unbound = false) {
|
2280
|
+
let targetSymbolId = symbol_1.indeterminateSymbolId;
|
2281
|
+
if (node.nodeType === 38 /* Name */) {
|
2282
|
+
const symbolWithScope = this._currentScope.lookUpSymbolRecursive(node.value);
|
2283
|
+
(0, debug_1.assert)(symbolWithScope !== undefined);
|
2284
|
+
targetSymbolId = symbolWithScope.symbol.id;
|
2285
|
+
}
|
2286
|
+
const prevFlowNode = this._currentFlowNode;
|
2287
|
+
if (!this._isCodeUnreachable() && (0, codeFlowTypes_1.isCodeFlowSupportedForReference)(node)) {
|
2288
|
+
const flowNode = {
|
2289
|
+
flags: codeFlowTypes_1.FlowFlags.Assignment,
|
2290
|
+
id: this._getUniqueFlowNodeId(),
|
2291
|
+
node,
|
2292
|
+
antecedent: this._currentFlowNode,
|
2293
|
+
targetSymbolId,
|
2294
|
+
};
|
2295
|
+
const referenceKey = (0, codeFlowTypes_1.createKeyForReference)(node);
|
2296
|
+
this._currentScopeCodeFlowExpressions.add(referenceKey);
|
2297
|
+
if (unbound) {
|
2298
|
+
flowNode.flags |= codeFlowTypes_1.FlowFlags.Unbind;
|
2299
|
+
}
|
2300
|
+
// Assume that an assignment to a member access expression
|
2301
|
+
// can potentially generate an exception.
|
2302
|
+
if (node.nodeType === 35 /* MemberAccess */) {
|
2303
|
+
this._addExceptTargets(flowNode);
|
2304
|
+
}
|
2305
|
+
this._currentFlowNode = flowNode;
|
2306
|
+
}
|
2307
|
+
// If we're marking the node as unbound and there is already a flow node
|
2308
|
+
// associated with the node, don't replace it. This case applies for symbols
|
2309
|
+
// introduced in except clauses. If there is no use the previous flow node
|
2310
|
+
// associated, use the previous flow node (applies in the del case).
|
2311
|
+
// Otherwise, the node will be evaluated as unbound at this point in the flow.
|
2312
|
+
if (!unbound || AnalyzerNodeInfo.getFlowNode(node) === undefined) {
|
2313
|
+
AnalyzerNodeInfo.setFlowNode(node, unbound ? prevFlowNode : this._currentFlowNode);
|
2314
|
+
}
|
2315
|
+
}
|
2316
|
+
_createFlowWildcardImport(node, names) {
|
2317
|
+
if (!this._isCodeUnreachable()) {
|
2318
|
+
const flowNode = {
|
2319
|
+
flags: codeFlowTypes_1.FlowFlags.WildcardImport,
|
2320
|
+
id: this._getUniqueFlowNodeId(),
|
2321
|
+
node,
|
2322
|
+
names,
|
2323
|
+
antecedent: this._currentFlowNode,
|
2324
|
+
};
|
2325
|
+
this._addExceptTargets(flowNode);
|
2326
|
+
this._currentFlowNode = flowNode;
|
2327
|
+
}
|
2328
|
+
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
2329
|
+
}
|
2330
|
+
_createFlowExhaustedMatch(node) {
|
2331
|
+
if (!this._isCodeUnreachable()) {
|
2332
|
+
const flowNode = {
|
2333
|
+
flags: codeFlowTypes_1.FlowFlags.ExhaustedMatch,
|
2334
|
+
id: this._getUniqueFlowNodeId(),
|
2335
|
+
node,
|
2336
|
+
antecedent: this._currentFlowNode,
|
2337
|
+
};
|
2338
|
+
this._currentFlowNode = flowNode;
|
2339
|
+
}
|
2340
|
+
AnalyzerNodeInfo.setAfterFlowNode(node, this._currentFlowNode);
|
2341
|
+
}
|
2342
|
+
_isCodeUnreachable() {
|
2343
|
+
return !!(this._currentFlowNode.flags & codeFlowTypes_1.FlowFlags.Unreachable);
|
2344
|
+
}
|
2345
|
+
_addExceptTargets(flowNode) {
|
2346
|
+
// If there are any except targets, then we're in a try block, and we
|
2347
|
+
// have to assume that an exception can be raised after every assignment.
|
2348
|
+
if (this._currentExceptTargets) {
|
2349
|
+
this._currentExceptTargets.forEach((label) => {
|
2350
|
+
this._addAntecedent(label, flowNode);
|
2351
|
+
});
|
2352
|
+
}
|
2353
|
+
}
|
2354
|
+
_trackCodeFlowExpressions(callback) {
|
2355
|
+
const savedExpressions = this._currentScopeCodeFlowExpressions;
|
2356
|
+
this._currentScopeCodeFlowExpressions = new Set();
|
2357
|
+
callback();
|
2358
|
+
const scopedExpressions = this._currentScopeCodeFlowExpressions;
|
2359
|
+
if (savedExpressions) {
|
2360
|
+
this._currentScopeCodeFlowExpressions.forEach((value) => {
|
2361
|
+
savedExpressions.add(value);
|
2362
|
+
});
|
2363
|
+
}
|
2364
|
+
this._currentScopeCodeFlowExpressions = savedExpressions;
|
2365
|
+
return scopedExpressions;
|
2366
|
+
}
|
2367
|
+
_bindLoopStatement(preLoopLabel, postLoopLabel, callback) {
|
2368
|
+
const savedContinueTarget = this._currentContinueTarget;
|
2369
|
+
const savedBreakTarget = this._currentBreakTarget;
|
2370
|
+
this._currentContinueTarget = preLoopLabel;
|
2371
|
+
this._currentBreakTarget = postLoopLabel;
|
2372
|
+
preLoopLabel.affectedExpressions = this._trackCodeFlowExpressions(callback);
|
2373
|
+
this._currentContinueTarget = savedContinueTarget;
|
2374
|
+
this._currentBreakTarget = savedBreakTarget;
|
2375
|
+
}
|
2376
|
+
_addAntecedent(label, antecedent) {
|
2377
|
+
if (!(this._currentFlowNode.flags & codeFlowTypes_1.FlowFlags.Unreachable)) {
|
2378
|
+
// Don't add the same antecedent twice.
|
2379
|
+
if (!label.antecedents.some((existing) => existing.id === antecedent.id)) {
|
2380
|
+
label.antecedents.push(antecedent);
|
2381
|
+
}
|
2382
|
+
}
|
2383
|
+
}
|
2384
|
+
_bindNameToScope(scope, name, addedSymbols) {
|
2385
|
+
// Is this name already bound to a scope other than the local one?
|
2386
|
+
const bindingType = this._currentScope.getBindingType(name);
|
2387
|
+
if (bindingType !== undefined) {
|
2388
|
+
const scopeToUse = bindingType === 0 /* Nonlocal */
|
2389
|
+
? this._currentScope.parent
|
2390
|
+
: this._currentScope.getGlobalScope().scope;
|
2391
|
+
const symbolWithScope = scopeToUse.lookUpSymbolRecursive(name);
|
2392
|
+
if (symbolWithScope) {
|
2393
|
+
return symbolWithScope.symbol;
|
2394
|
+
}
|
2395
|
+
}
|
2396
|
+
else {
|
2397
|
+
// Don't overwrite an existing symbol.
|
2398
|
+
let symbol = scope.lookUpSymbol(name);
|
2399
|
+
if (!symbol) {
|
2400
|
+
symbol = scope.addSymbol(name, 1 /* InitiallyUnbound */ | 4 /* ClassMember */);
|
2401
|
+
if (this._currentScope.type === 3 /* Module */ || this._currentScope.type === 4 /* Builtin */) {
|
2402
|
+
if ((0, symbolNameUtils_1.isPrivateOrProtectedName)(name)) {
|
2403
|
+
if ((0, symbolNameUtils_1.isPrivateName)(name)) {
|
2404
|
+
// Private names are obscured, so they are always externally hidden.
|
2405
|
+
symbol.setIsExternallyHidden();
|
2406
|
+
}
|
2407
|
+
else if (this._fileInfo.isStubFile || this._fileInfo.isInPyTypedPackage) {
|
2408
|
+
if (this._currentScope.type === 4 /* Builtin */) {
|
2409
|
+
// Don't include private-named symbols in the builtin scope.
|
2410
|
+
symbol.setIsExternallyHidden();
|
2411
|
+
}
|
2412
|
+
else {
|
2413
|
+
this._potentialPrivateSymbols.set(name, symbol);
|
2414
|
+
}
|
2415
|
+
}
|
2416
|
+
else {
|
2417
|
+
symbol.setIsPrivateMember();
|
2418
|
+
}
|
2419
|
+
}
|
2420
|
+
}
|
2421
|
+
if (addedSymbols) {
|
2422
|
+
addedSymbols.set(name, symbol);
|
2423
|
+
}
|
2424
|
+
}
|
2425
|
+
return symbol;
|
2426
|
+
}
|
2427
|
+
return undefined;
|
2428
|
+
}
|
2429
|
+
_bindPossibleTupleNamedTarget(target, addedSymbols) {
|
2430
|
+
switch (target.nodeType) {
|
2431
|
+
case 38 /* Name */: {
|
2432
|
+
this._bindNameToScope(this._currentScope, target.value, addedSymbols);
|
2433
|
+
break;
|
2434
|
+
}
|
2435
|
+
case 52 /* Tuple */: {
|
2436
|
+
target.expressions.forEach((expr) => {
|
2437
|
+
this._bindPossibleTupleNamedTarget(expr, addedSymbols);
|
2438
|
+
});
|
2439
|
+
break;
|
2440
|
+
}
|
2441
|
+
case 31 /* List */: {
|
2442
|
+
target.entries.forEach((expr) => {
|
2443
|
+
this._bindPossibleTupleNamedTarget(expr, addedSymbols);
|
2444
|
+
});
|
2445
|
+
break;
|
2446
|
+
}
|
2447
|
+
case 54 /* TypeAnnotation */: {
|
2448
|
+
this._bindPossibleTupleNamedTarget(target.valueExpression, addedSymbols);
|
2449
|
+
break;
|
2450
|
+
}
|
2451
|
+
case 56 /* Unpack */: {
|
2452
|
+
this._bindPossibleTupleNamedTarget(target.expression, addedSymbols);
|
2453
|
+
break;
|
2454
|
+
}
|
2455
|
+
}
|
2456
|
+
}
|
2457
|
+
_addImplicitSymbolToCurrentScope(nameValue, node, type) {
|
2458
|
+
const symbol = this._addSymbolToCurrentScope(nameValue, /* isInitiallyUnbound */ false);
|
2459
|
+
if (symbol) {
|
2460
|
+
symbol.addDeclaration({
|
2461
|
+
type: 0 /* Intrinsic */,
|
2462
|
+
node,
|
2463
|
+
intrinsicType: type,
|
2464
|
+
path: this._fileInfo.filePath,
|
2465
|
+
range: (0, textRange_1.getEmptyRange)(),
|
2466
|
+
moduleName: this._fileInfo.moduleName,
|
2467
|
+
isInExceptSuite: this._isInExceptSuite,
|
2468
|
+
});
|
2469
|
+
symbol.setIsIgnoredForProtocolMatch();
|
2470
|
+
}
|
2471
|
+
}
|
2472
|
+
// Adds a new symbol with the specified name if it doesn't already exist.
|
2473
|
+
_addSymbolToCurrentScope(nameValue, isInitiallyUnbound) {
|
2474
|
+
let symbol = this._currentScope.lookUpSymbol(nameValue);
|
2475
|
+
if (!symbol) {
|
2476
|
+
let symbolFlags = 0 /* None */;
|
2477
|
+
if (isInitiallyUnbound) {
|
2478
|
+
symbolFlags |= 1 /* InitiallyUnbound */;
|
2479
|
+
}
|
2480
|
+
if (this._currentScope.type === 2 /* Class */) {
|
2481
|
+
symbolFlags |= 4 /* ClassMember */;
|
2482
|
+
}
|
2483
|
+
if (this._fileInfo.isStubFile && (0, symbolNameUtils_1.isPrivateOrProtectedName)(nameValue)) {
|
2484
|
+
symbolFlags |= 2 /* ExternallyHidden */;
|
2485
|
+
}
|
2486
|
+
// Add the symbol. Assume that symbols with a default type source ID
|
2487
|
+
// are "implicit" symbols added to the scope. These are not initially unbound.
|
2488
|
+
symbol = this._currentScope.addSymbol(nameValue, symbolFlags);
|
2489
|
+
}
|
2490
|
+
return symbol;
|
2491
|
+
}
|
2492
|
+
_createNewScope(scopeType, parentScope, callback) {
|
2493
|
+
const prevScope = this._currentScope;
|
2494
|
+
const newScope = new scope_1.Scope(scopeType, parentScope);
|
2495
|
+
this._currentScope = newScope;
|
2496
|
+
// If this scope is an execution scope, allocate a new reference map.
|
2497
|
+
const isExecutionScope = scopeType === 4 /* Builtin */ || scopeType === 3 /* Module */ || scopeType === 1 /* Function */;
|
2498
|
+
const prevExpressions = this._currentScopeCodeFlowExpressions;
|
2499
|
+
if (isExecutionScope) {
|
2500
|
+
this._currentScopeCodeFlowExpressions = new Set();
|
2501
|
+
}
|
2502
|
+
callback();
|
2503
|
+
this._currentScopeCodeFlowExpressions = prevExpressions;
|
2504
|
+
this._currentScope = prevScope;
|
2505
|
+
return newScope;
|
2506
|
+
}
|
2507
|
+
_addInferredTypeAssignmentForVariable(target, source, isPossibleTypeAlias = false) {
|
2508
|
+
switch (target.nodeType) {
|
2509
|
+
case 38 /* Name */: {
|
2510
|
+
const name = target;
|
2511
|
+
const symbolWithScope = this._currentScope.lookUpSymbolRecursive(name.value);
|
2512
|
+
if (symbolWithScope && symbolWithScope.symbol) {
|
2513
|
+
const declaration = {
|
2514
|
+
type: 1 /* Variable */,
|
2515
|
+
node: target,
|
2516
|
+
isConstant: (0, symbolNameUtils_1.isConstantName)(target.value),
|
2517
|
+
inferredTypeSource: source,
|
2518
|
+
isInferenceAllowedInPyTyped: this._isInferenceAllowedInPyTyped(name.value),
|
2519
|
+
typeAliasName: isPossibleTypeAlias ? target : undefined,
|
2520
|
+
path: this._fileInfo.filePath,
|
2521
|
+
range: (0, positionUtils_1.convertOffsetsToRange)(name.start, textRange_2.TextRange.getEnd(name), this._fileInfo.lines),
|
2522
|
+
moduleName: this._fileInfo.moduleName,
|
2523
|
+
isInExceptSuite: this._isInExceptSuite,
|
2524
|
+
docString: this._getVariableDocString(target),
|
2525
|
+
};
|
2526
|
+
symbolWithScope.symbol.addDeclaration(declaration);
|
2527
|
+
}
|
2528
|
+
break;
|
2529
|
+
}
|
2530
|
+
case 35 /* MemberAccess */: {
|
2531
|
+
const memberAccessInfo = this._getMemberAccessInfo(target);
|
2532
|
+
if (memberAccessInfo) {
|
2533
|
+
const name = target.memberName;
|
2534
|
+
let symbol = memberAccessInfo.classScope.lookUpSymbol(name.value);
|
2535
|
+
if (!symbol) {
|
2536
|
+
symbol = memberAccessInfo.classScope.addSymbol(name.value, 1 /* InitiallyUnbound */);
|
2537
|
+
const honorPrivateNaming = this._fileInfo.diagnosticRuleSet.reportPrivateUsage !== 'none';
|
2538
|
+
if ((0, symbolNameUtils_1.isPrivateOrProtectedName)(name.value) && honorPrivateNaming) {
|
2539
|
+
symbol.setIsPrivateMember();
|
2540
|
+
}
|
2541
|
+
}
|
2542
|
+
if (memberAccessInfo.isInstanceMember) {
|
2543
|
+
// If a method (which has a declared type) is being overwritten
|
2544
|
+
// by an expression with no declared type, don't mark it as
|
2545
|
+
// an instance member because the type evaluator will think
|
2546
|
+
// that it doesn't need to perform object binding.
|
2547
|
+
if (!symbol.isClassMember() ||
|
2548
|
+
!symbol
|
2549
|
+
.getDeclarations()
|
2550
|
+
.some((decl) => decl.type === 3 /* Function */ && decl.isMethod)) {
|
2551
|
+
symbol.setIsInstanceMember();
|
2552
|
+
}
|
2553
|
+
}
|
2554
|
+
else {
|
2555
|
+
symbol.setIsClassMember();
|
2556
|
+
}
|
2557
|
+
const declaration = {
|
2558
|
+
type: 1 /* Variable */,
|
2559
|
+
node: target.memberName,
|
2560
|
+
isConstant: (0, symbolNameUtils_1.isConstantName)(name.value),
|
2561
|
+
inferredTypeSource: source,
|
2562
|
+
isDefinedByMemberAccess: true,
|
2563
|
+
path: this._fileInfo.filePath,
|
2564
|
+
range: (0, positionUtils_1.convertOffsetsToRange)(target.memberName.start, target.memberName.start + target.memberName.length, this._fileInfo.lines),
|
2565
|
+
moduleName: this._fileInfo.moduleName,
|
2566
|
+
isInExceptSuite: this._isInExceptSuite,
|
2567
|
+
docString: this._getVariableDocString(target),
|
2568
|
+
};
|
2569
|
+
symbol.addDeclaration(declaration);
|
2570
|
+
}
|
2571
|
+
break;
|
2572
|
+
}
|
2573
|
+
case 52 /* Tuple */: {
|
2574
|
+
target.expressions.forEach((expr) => {
|
2575
|
+
this._addInferredTypeAssignmentForVariable(expr, source);
|
2576
|
+
});
|
2577
|
+
break;
|
2578
|
+
}
|
2579
|
+
case 54 /* TypeAnnotation */: {
|
2580
|
+
this._addInferredTypeAssignmentForVariable(target.valueExpression, source);
|
2581
|
+
break;
|
2582
|
+
}
|
2583
|
+
case 56 /* Unpack */: {
|
2584
|
+
this._addInferredTypeAssignmentForVariable(target.expression, source);
|
2585
|
+
break;
|
2586
|
+
}
|
2587
|
+
case 31 /* List */: {
|
2588
|
+
target.entries.forEach((entry) => {
|
2589
|
+
this._addInferredTypeAssignmentForVariable(entry, source);
|
2590
|
+
});
|
2591
|
+
break;
|
2592
|
+
}
|
2593
|
+
}
|
2594
|
+
}
|
2595
|
+
_isInferenceAllowedInPyTyped(symbolName) {
|
2596
|
+
const exemptSymbols = ['__match_args__', '__slots__', '__all__'];
|
2597
|
+
return exemptSymbols.some((name) => name === symbolName);
|
2598
|
+
}
|
2599
|
+
_addTypeDeclarationForVariable(target, typeAnnotation) {
|
2600
|
+
var _a, _b, _c;
|
2601
|
+
let declarationHandled = false;
|
2602
|
+
switch (target.nodeType) {
|
2603
|
+
case 38 /* Name */: {
|
2604
|
+
const name = target;
|
2605
|
+
const symbolWithScope = this._currentScope.lookUpSymbolRecursive(name.value);
|
2606
|
+
if (symbolWithScope && symbolWithScope.symbol) {
|
2607
|
+
const finalInfo = this._isAnnotationFinal(typeAnnotation);
|
2608
|
+
const isExplicitTypeAlias = this._isAnnotationTypeAlias(typeAnnotation);
|
2609
|
+
let typeAnnotationNode = typeAnnotation;
|
2610
|
+
let innerTypeAnnotationNode = typeAnnotation;
|
2611
|
+
if (isExplicitTypeAlias) {
|
2612
|
+
typeAnnotationNode = undefined;
|
2613
|
+
innerTypeAnnotationNode = undefined;
|
2614
|
+
// Type aliases are allowed only in the global or class scope.
|
2615
|
+
if (this._currentScope.type !== 2 /* Class */ &&
|
2616
|
+
this._currentScope.type !== 3 /* Module */ &&
|
2617
|
+
this._currentScope.type !== 4 /* Builtin */) {
|
2618
|
+
this._addError(localize_1.Localizer.Diagnostic.typeAliasNotInModuleOrClass(), typeAnnotation);
|
2619
|
+
}
|
2620
|
+
}
|
2621
|
+
else if (finalInfo.isFinal) {
|
2622
|
+
innerTypeAnnotationNode = finalInfo.finalTypeNode;
|
2623
|
+
if (!finalInfo.finalTypeNode) {
|
2624
|
+
typeAnnotationNode = undefined;
|
2625
|
+
}
|
2626
|
+
}
|
2627
|
+
// Is this annotation indicating that the variable is a "ClassVar"?
|
2628
|
+
let classVarInfo = this._isAnnotationClassVar(typeAnnotation);
|
2629
|
+
if (classVarInfo.isClassVar) {
|
2630
|
+
innerTypeAnnotationNode = classVarInfo.classVarTypeNode;
|
2631
|
+
if (!classVarInfo.classVarTypeNode) {
|
2632
|
+
typeAnnotationNode = undefined;
|
2633
|
+
}
|
2634
|
+
}
|
2635
|
+
// PEP 591 indicates that a Final variable initialized within a class
|
2636
|
+
// body should also be considered a ClassVar.
|
2637
|
+
if (finalInfo.isFinal) {
|
2638
|
+
const containingClass = ParseTreeUtils.getEnclosingClassOrFunction(target);
|
2639
|
+
if (containingClass && containingClass.nodeType === 10 /* Class */) {
|
2640
|
+
// Make sure it's part of an assignment.
|
2641
|
+
if (((_a = target.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* Assignment */ ||
|
2642
|
+
((_c = (_b = target.parent) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 3 /* Assignment */) {
|
2643
|
+
classVarInfo = {
|
2644
|
+
isClassVar: true,
|
2645
|
+
classVarTypeNode: undefined,
|
2646
|
+
};
|
2647
|
+
}
|
2648
|
+
}
|
2649
|
+
}
|
2650
|
+
const declaration = {
|
2651
|
+
type: 1 /* Variable */,
|
2652
|
+
node: target,
|
2653
|
+
isConstant: (0, symbolNameUtils_1.isConstantName)(name.value),
|
2654
|
+
isFinal: finalInfo.isFinal,
|
2655
|
+
isClassVar: classVarInfo.isClassVar,
|
2656
|
+
isRequired: this._isRequiredAnnotation(innerTypeAnnotationNode),
|
2657
|
+
isNotRequired: this._isNotRequiredAnnotation(innerTypeAnnotationNode),
|
2658
|
+
typeAliasAnnotation: isExplicitTypeAlias ? typeAnnotation : undefined,
|
2659
|
+
typeAliasName: isExplicitTypeAlias ? target : undefined,
|
2660
|
+
path: this._fileInfo.filePath,
|
2661
|
+
typeAnnotationNode,
|
2662
|
+
range: (0, positionUtils_1.convertOffsetsToRange)(name.start, textRange_2.TextRange.getEnd(name), this._fileInfo.lines),
|
2663
|
+
moduleName: this._fileInfo.moduleName,
|
2664
|
+
isInExceptSuite: this._isInExceptSuite,
|
2665
|
+
docString: this._getVariableDocString(target),
|
2666
|
+
};
|
2667
|
+
symbolWithScope.symbol.addDeclaration(declaration);
|
2668
|
+
if (classVarInfo.isClassVar) {
|
2669
|
+
symbolWithScope.symbol.setIsClassVar();
|
2670
|
+
}
|
2671
|
+
else {
|
2672
|
+
symbolWithScope.symbol.setIsInstanceMember();
|
2673
|
+
}
|
2674
|
+
// Look for an 'InitVar' either by itself or wrapped in an 'Annotated'.
|
2675
|
+
if (typeAnnotation.nodeType === 24 /* Index */) {
|
2676
|
+
if (this._isDataclassesAnnotation(typeAnnotation.baseExpression, 'InitVar')) {
|
2677
|
+
symbolWithScope.symbol.setIsInitVar();
|
2678
|
+
}
|
2679
|
+
else if (this._isTypingAnnotation(typeAnnotation.baseExpression, 'Annotated') &&
|
2680
|
+
typeAnnotation.items.length > 0) {
|
2681
|
+
const item0Expr = typeAnnotation.items[0].valueExpression;
|
2682
|
+
if (item0Expr.nodeType === 24 /* Index */ &&
|
2683
|
+
this._isDataclassesAnnotation(item0Expr.baseExpression, 'InitVar')) {
|
2684
|
+
symbolWithScope.symbol.setIsInitVar();
|
2685
|
+
}
|
2686
|
+
}
|
2687
|
+
}
|
2688
|
+
}
|
2689
|
+
declarationHandled = true;
|
2690
|
+
break;
|
2691
|
+
}
|
2692
|
+
case 35 /* MemberAccess */: {
|
2693
|
+
// We need to determine whether this expression is declaring a class or
|
2694
|
+
// instance variable. This is difficult because python doesn't provide
|
2695
|
+
// a keyword for accessing "this". Instead, it uses naming conventions
|
2696
|
+
// of "cls" and "self", but we don't want to rely on these naming
|
2697
|
+
// conventions here. Instead, we'll apply some heuristics to determine
|
2698
|
+
// whether the symbol on the LHS is a reference to the current class
|
2699
|
+
// or an instance of the current class.
|
2700
|
+
const memberAccessInfo = this._getMemberAccessInfo(target);
|
2701
|
+
if (memberAccessInfo) {
|
2702
|
+
const name = target.memberName;
|
2703
|
+
let symbol = memberAccessInfo.classScope.lookUpSymbol(name.value);
|
2704
|
+
if (!symbol) {
|
2705
|
+
symbol = memberAccessInfo.classScope.addSymbol(name.value, 1 /* InitiallyUnbound */);
|
2706
|
+
const honorPrivateNaming = this._fileInfo.diagnosticRuleSet.reportPrivateUsage !== 'none';
|
2707
|
+
if ((0, symbolNameUtils_1.isPrivateOrProtectedName)(name.value) && honorPrivateNaming) {
|
2708
|
+
symbol.setIsPrivateMember();
|
2709
|
+
}
|
2710
|
+
}
|
2711
|
+
if (memberAccessInfo.isInstanceMember) {
|
2712
|
+
symbol.setIsInstanceMember();
|
2713
|
+
}
|
2714
|
+
else {
|
2715
|
+
symbol.setIsClassMember();
|
2716
|
+
}
|
2717
|
+
const finalInfo = this._isAnnotationFinal(typeAnnotation);
|
2718
|
+
const declaration = {
|
2719
|
+
type: 1 /* Variable */,
|
2720
|
+
node: target.memberName,
|
2721
|
+
isConstant: (0, symbolNameUtils_1.isConstantName)(name.value),
|
2722
|
+
isDefinedByMemberAccess: true,
|
2723
|
+
isFinal: finalInfo.isFinal,
|
2724
|
+
path: this._fileInfo.filePath,
|
2725
|
+
typeAnnotationNode: finalInfo.isFinal && !finalInfo.finalTypeNode ? undefined : typeAnnotation,
|
2726
|
+
range: (0, positionUtils_1.convertOffsetsToRange)(target.memberName.start, target.memberName.start + target.memberName.length, this._fileInfo.lines),
|
2727
|
+
moduleName: this._fileInfo.moduleName,
|
2728
|
+
isInExceptSuite: this._isInExceptSuite,
|
2729
|
+
docString: this._getVariableDocString(target),
|
2730
|
+
};
|
2731
|
+
symbol.addDeclaration(declaration);
|
2732
|
+
declarationHandled = true;
|
2733
|
+
}
|
2734
|
+
break;
|
2735
|
+
}
|
2736
|
+
}
|
2737
|
+
if (!declarationHandled) {
|
2738
|
+
this._addError(localize_1.Localizer.Diagnostic.annotationNotSupported(), typeAnnotation);
|
2739
|
+
}
|
2740
|
+
}
|
2741
|
+
// Determines whether the expression refers to a type exported by the typing
|
2742
|
+
// or typing_extensions modules. We can directly evaluate the types at binding
|
2743
|
+
// time. We assume here that the code isn't making use of some custom type alias
|
2744
|
+
// to refer to the typing types.
|
2745
|
+
_isTypingAnnotation(typeAnnotation, name) {
|
2746
|
+
return this._isKnownAnnotation(typeAnnotation, name, this._typingImportAliases, this._typingSymbolAliases);
|
2747
|
+
}
|
2748
|
+
_isDataclassesAnnotation(typeAnnotation, name) {
|
2749
|
+
return this._isKnownAnnotation(typeAnnotation, name, this._dataclassesImportAliases, this._dataclassesSymbolAliases);
|
2750
|
+
}
|
2751
|
+
_isKnownAnnotation(typeAnnotation, name, importAliases, symbolAliases) {
|
2752
|
+
if (typeAnnotation.nodeType === 38 /* Name */) {
|
2753
|
+
const alias = symbolAliases.get(typeAnnotation.value);
|
2754
|
+
if (alias === name) {
|
2755
|
+
return true;
|
2756
|
+
}
|
2757
|
+
}
|
2758
|
+
else if (typeAnnotation.nodeType === 35 /* MemberAccess */) {
|
2759
|
+
if (typeAnnotation.leftExpression.nodeType === 38 /* Name */ &&
|
2760
|
+
typeAnnotation.memberName.value === name) {
|
2761
|
+
const baseName = typeAnnotation.leftExpression.value;
|
2762
|
+
return importAliases.some((alias) => alias === baseName);
|
2763
|
+
}
|
2764
|
+
}
|
2765
|
+
return false;
|
2766
|
+
}
|
2767
|
+
_getVariableDocString(node) {
|
2768
|
+
var _a, _b, _c, _d;
|
2769
|
+
// Walk up the parse tree to find an assignment expression.
|
2770
|
+
let curNode = node;
|
2771
|
+
let annotationNode;
|
2772
|
+
while (curNode) {
|
2773
|
+
if (curNode.nodeType === 3 /* Assignment */) {
|
2774
|
+
break;
|
2775
|
+
}
|
2776
|
+
if (curNode.nodeType === 54 /* TypeAnnotation */ && !annotationNode) {
|
2777
|
+
annotationNode = curNode;
|
2778
|
+
}
|
2779
|
+
curNode = curNode.parent;
|
2780
|
+
}
|
2781
|
+
if ((curNode === null || curNode === void 0 ? void 0 : curNode.nodeType) !== 3 /* Assignment */) {
|
2782
|
+
// Allow a simple annotation statement to have a docstring even
|
2783
|
+
// though PEP 258 doesn't mention this case. This PEP pre-dated
|
2784
|
+
// PEP 526, so it didn't contemplate this situation.
|
2785
|
+
if (annotationNode) {
|
2786
|
+
curNode = annotationNode;
|
2787
|
+
}
|
2788
|
+
else {
|
2789
|
+
return undefined;
|
2790
|
+
}
|
2791
|
+
}
|
2792
|
+
const parentNode = curNode.parent;
|
2793
|
+
if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.nodeType) !== 47 /* StatementList */) {
|
2794
|
+
return undefined;
|
2795
|
+
}
|
2796
|
+
const suiteOrModule = parentNode.parent;
|
2797
|
+
if (!suiteOrModule ||
|
2798
|
+
(suiteOrModule.nodeType !== 36 /* Module */ && suiteOrModule.nodeType !== 50 /* Suite */)) {
|
2799
|
+
return undefined;
|
2800
|
+
}
|
2801
|
+
const assignmentIndex = suiteOrModule.statements.findIndex((node) => node === parentNode);
|
2802
|
+
if (assignmentIndex < 0 || assignmentIndex === suiteOrModule.statements.length - 1) {
|
2803
|
+
return undefined;
|
2804
|
+
}
|
2805
|
+
const nextStatement = suiteOrModule.statements[assignmentIndex + 1];
|
2806
|
+
if (nextStatement.nodeType !== 47 /* StatementList */ || !ParseTreeUtils.isDocString(nextStatement)) {
|
2807
|
+
return undefined;
|
2808
|
+
}
|
2809
|
+
// See if the assignment is within one of the contexts specified in PEP 258.
|
2810
|
+
let isValidContext = false;
|
2811
|
+
if (((_a = parentNode === null || parentNode === void 0 ? void 0 : parentNode.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 36 /* Module */) {
|
2812
|
+
// If we're at the top level of a module, the attribute docstring is valid.
|
2813
|
+
isValidContext = true;
|
2814
|
+
}
|
2815
|
+
else if (((_b = parentNode === null || parentNode === void 0 ? void 0 : parentNode.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 50 /* Suite */ &&
|
2816
|
+
((_d = (_c = parentNode === null || parentNode === void 0 ? void 0 : parentNode.parent) === null || _c === void 0 ? void 0 : _c.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 10 /* Class */) {
|
2817
|
+
// If we're at the top level of a class, the attribute docstring is valid.
|
2818
|
+
isValidContext = true;
|
2819
|
+
}
|
2820
|
+
else {
|
2821
|
+
const func = ParseTreeUtils.getEnclosingFunction(parentNode);
|
2822
|
+
// If we're within an __init__ method, the attribute docstring is valid.
|
2823
|
+
if (func &&
|
2824
|
+
func.name.value === '__init__' &&
|
2825
|
+
ParseTreeUtils.getEnclosingClass(func, /* stopAtFunction */ true)) {
|
2826
|
+
isValidContext = true;
|
2827
|
+
}
|
2828
|
+
}
|
2829
|
+
if (!isValidContext) {
|
2830
|
+
return undefined;
|
2831
|
+
}
|
2832
|
+
// A docstring can consist of multiple joined strings in a single expression.
|
2833
|
+
const strings = nextStatement.statements[0].strings;
|
2834
|
+
if (strings.length === 1) {
|
2835
|
+
// Common case.
|
2836
|
+
return strings[0].value;
|
2837
|
+
}
|
2838
|
+
return strings.map((s) => s.value).join('');
|
2839
|
+
}
|
2840
|
+
// Determines if the specified type annotation expression is a "Final".
|
2841
|
+
// It returns a value indicating whether the expression is a "Final"
|
2842
|
+
// expression and whether it's a "raw" Final with no type arguments.
|
2843
|
+
_isAnnotationFinal(typeAnnotation) {
|
2844
|
+
let isFinal = false;
|
2845
|
+
let finalTypeNode;
|
2846
|
+
if (typeAnnotation) {
|
2847
|
+
if (this._isTypingAnnotation(typeAnnotation, 'Final')) {
|
2848
|
+
isFinal = true;
|
2849
|
+
}
|
2850
|
+
else if (typeAnnotation.nodeType === 24 /* Index */ && typeAnnotation.items.length === 1) {
|
2851
|
+
// Recursively call to see if the base expression is "Final".
|
2852
|
+
const finalInfo = this._isAnnotationFinal(typeAnnotation.baseExpression);
|
2853
|
+
if (finalInfo.isFinal &&
|
2854
|
+
typeAnnotation.items[0].argumentCategory === 0 /* Simple */ &&
|
2855
|
+
!typeAnnotation.items[0].name &&
|
2856
|
+
!typeAnnotation.trailingComma) {
|
2857
|
+
isFinal = true;
|
2858
|
+
finalTypeNode = typeAnnotation.items[0].valueExpression;
|
2859
|
+
}
|
2860
|
+
}
|
2861
|
+
}
|
2862
|
+
return { isFinal, finalTypeNode };
|
2863
|
+
}
|
2864
|
+
// Determines if the specified type annotation expression is a "ClassVar".
|
2865
|
+
// It returns a value indicating whether the expression is a "ClassVar"
|
2866
|
+
// expression and whether it's a "raw" ClassVar with no type arguments.
|
2867
|
+
_isAnnotationClassVar(typeAnnotation) {
|
2868
|
+
let isClassVar = false;
|
2869
|
+
let classVarTypeNode;
|
2870
|
+
while (typeAnnotation) {
|
2871
|
+
if (typeAnnotation.nodeType === 24 /* Index */ &&
|
2872
|
+
typeAnnotation.items.length > 0 &&
|
2873
|
+
this._isTypingAnnotation(typeAnnotation.baseExpression, 'Annotated')) {
|
2874
|
+
typeAnnotation = typeAnnotation.items[0].valueExpression;
|
2875
|
+
}
|
2876
|
+
else if (this._isTypingAnnotation(typeAnnotation, 'ClassVar')) {
|
2877
|
+
isClassVar = true;
|
2878
|
+
break;
|
2879
|
+
}
|
2880
|
+
else if (typeAnnotation.nodeType === 24 /* Index */ && typeAnnotation.items.length === 1) {
|
2881
|
+
// Recursively call to see if the base expression is "ClassVar".
|
2882
|
+
const finalInfo = this._isAnnotationClassVar(typeAnnotation.baseExpression);
|
2883
|
+
if (finalInfo.isClassVar &&
|
2884
|
+
typeAnnotation.items[0].argumentCategory === 0 /* Simple */ &&
|
2885
|
+
!typeAnnotation.items[0].name &&
|
2886
|
+
!typeAnnotation.trailingComma) {
|
2887
|
+
isClassVar = true;
|
2888
|
+
classVarTypeNode = typeAnnotation.items[0].valueExpression;
|
2889
|
+
}
|
2890
|
+
break;
|
2891
|
+
}
|
2892
|
+
else {
|
2893
|
+
break;
|
2894
|
+
}
|
2895
|
+
}
|
2896
|
+
return { isClassVar, classVarTypeNode };
|
2897
|
+
}
|
2898
|
+
// Determines if the specified type annotation is wrapped in a "Required".
|
2899
|
+
_isRequiredAnnotation(typeAnnotation) {
|
2900
|
+
if (typeAnnotation && typeAnnotation.nodeType === 24 /* Index */ && typeAnnotation.items.length === 1) {
|
2901
|
+
if (this._isTypingAnnotation(typeAnnotation.baseExpression, 'Required')) {
|
2902
|
+
return true;
|
2903
|
+
}
|
2904
|
+
}
|
2905
|
+
return false;
|
2906
|
+
}
|
2907
|
+
// Determines if the specified type annotation is wrapped in a "NotRequired".
|
2908
|
+
_isNotRequiredAnnotation(typeAnnotation) {
|
2909
|
+
if (typeAnnotation && typeAnnotation.nodeType === 24 /* Index */ && typeAnnotation.items.length === 1) {
|
2910
|
+
if (this._isTypingAnnotation(typeAnnotation.baseExpression, 'NotRequired')) {
|
2911
|
+
return true;
|
2912
|
+
}
|
2913
|
+
}
|
2914
|
+
return false;
|
2915
|
+
}
|
2916
|
+
_isAnnotationTypeAlias(typeAnnotation) {
|
2917
|
+
if (!typeAnnotation) {
|
2918
|
+
return false;
|
2919
|
+
}
|
2920
|
+
return this._isTypingAnnotation(typeAnnotation, 'TypeAlias');
|
2921
|
+
}
|
2922
|
+
// Determines whether a member access expression is referring to a
|
2923
|
+
// member of a class (either a class or instance member). This will
|
2924
|
+
// typically take the form "self.x" or "cls.x".
|
2925
|
+
_getMemberAccessInfo(node) {
|
2926
|
+
// We handle only simple names on the left-hand side of the expression,
|
2927
|
+
// not calls, nested member accesses, index expressions, etc.
|
2928
|
+
if (node.leftExpression.nodeType !== 38 /* Name */) {
|
2929
|
+
return undefined;
|
2930
|
+
}
|
2931
|
+
const leftSymbolName = node.leftExpression.value;
|
2932
|
+
// Make sure the expression is within a function (i.e. a method) that's
|
2933
|
+
// within a class definition.
|
2934
|
+
const methodNode = ParseTreeUtils.getEnclosingFunction(node);
|
2935
|
+
if (!methodNode) {
|
2936
|
+
return undefined;
|
2937
|
+
}
|
2938
|
+
const classNode = ParseTreeUtils.getEnclosingClass(methodNode, /* stopAtFunction */ true);
|
2939
|
+
if (!classNode) {
|
2940
|
+
return undefined;
|
2941
|
+
}
|
2942
|
+
// Determine whether the left-hand side indicates a class or
|
2943
|
+
// instance member.
|
2944
|
+
let isInstanceMember = false;
|
2945
|
+
if (methodNode.parameters.length < 1 || !methodNode.parameters[0].name) {
|
2946
|
+
return undefined;
|
2947
|
+
}
|
2948
|
+
const className = classNode.name.value;
|
2949
|
+
const firstParamName = methodNode.parameters[0].name.value;
|
2950
|
+
if (leftSymbolName === className) {
|
2951
|
+
isInstanceMember = false;
|
2952
|
+
}
|
2953
|
+
else {
|
2954
|
+
if (leftSymbolName !== firstParamName) {
|
2955
|
+
return undefined;
|
2956
|
+
}
|
2957
|
+
// To determine whether the first parameter of the method
|
2958
|
+
// refers to the class or the instance, we need to apply
|
2959
|
+
// some heuristics.
|
2960
|
+
if (methodNode.name.value === '__new__') {
|
2961
|
+
// The __new__ method is special. It acts as a classmethod even
|
2962
|
+
// though it doesn't have a @classmethod decorator.
|
2963
|
+
isInstanceMember = false;
|
2964
|
+
}
|
2965
|
+
else {
|
2966
|
+
// Assume that it's an instance member unless we find
|
2967
|
+
// a decorator that tells us otherwise.
|
2968
|
+
isInstanceMember = true;
|
2969
|
+
for (const decorator of methodNode.decorators) {
|
2970
|
+
if (decorator.expression.nodeType === 38 /* Name */) {
|
2971
|
+
const decoratorName = decorator.expression.value;
|
2972
|
+
if (decoratorName === 'staticmethod') {
|
2973
|
+
// A static method doesn't have a "self" or "cls" parameter.
|
2974
|
+
return undefined;
|
2975
|
+
}
|
2976
|
+
else if (decoratorName === 'classmethod') {
|
2977
|
+
// A classmethod implies that the first parameter is "cls".
|
2978
|
+
isInstanceMember = false;
|
2979
|
+
break;
|
2980
|
+
}
|
2981
|
+
}
|
2982
|
+
}
|
2983
|
+
}
|
2984
|
+
}
|
2985
|
+
const classScope = AnalyzerNodeInfo.getScope(classNode);
|
2986
|
+
(0, debug_1.assert)(classScope !== undefined);
|
2987
|
+
return {
|
2988
|
+
classNode,
|
2989
|
+
methodNode,
|
2990
|
+
classScope,
|
2991
|
+
isInstanceMember,
|
2992
|
+
};
|
2993
|
+
}
|
2994
|
+
_addImplicitImportsToLoaderActions(importResult, loaderActions) {
|
2995
|
+
importResult.filteredImplicitImports.forEach((implicitImport) => {
|
2996
|
+
const existingLoaderAction = loaderActions.implicitImports
|
2997
|
+
? loaderActions.implicitImports.get(implicitImport.name)
|
2998
|
+
: undefined;
|
2999
|
+
if (existingLoaderAction) {
|
3000
|
+
existingLoaderAction.path = implicitImport.path;
|
3001
|
+
existingLoaderAction.loadSymbolsFromPath = true;
|
3002
|
+
}
|
3003
|
+
else {
|
3004
|
+
if (!loaderActions.implicitImports) {
|
3005
|
+
loaderActions.implicitImports = new Map();
|
3006
|
+
}
|
3007
|
+
loaderActions.implicitImports.set(implicitImport.name, {
|
3008
|
+
path: implicitImport.path,
|
3009
|
+
loadSymbolsFromPath: true,
|
3010
|
+
implicitImports: new Map(),
|
3011
|
+
});
|
3012
|
+
}
|
3013
|
+
});
|
3014
|
+
}
|
3015
|
+
// Handles some special-case assignment statements that are found
|
3016
|
+
// within the typings.pyi file.
|
3017
|
+
_handleTypingStubAssignmentOrAnnotation(node) {
|
3018
|
+
if (!this._fileInfo.isTypingStubFile) {
|
3019
|
+
return false;
|
3020
|
+
}
|
3021
|
+
let annotationNode;
|
3022
|
+
if (node.nodeType === 54 /* TypeAnnotation */) {
|
3023
|
+
annotationNode = node;
|
3024
|
+
}
|
3025
|
+
else {
|
3026
|
+
if (node.leftExpression.nodeType !== 54 /* TypeAnnotation */) {
|
3027
|
+
return false;
|
3028
|
+
}
|
3029
|
+
annotationNode = node.leftExpression;
|
3030
|
+
}
|
3031
|
+
if (annotationNode.valueExpression.nodeType !== 38 /* Name */) {
|
3032
|
+
return false;
|
3033
|
+
}
|
3034
|
+
const assignedNameNode = annotationNode.valueExpression;
|
3035
|
+
const specialTypes = new Map([
|
3036
|
+
['Tuple', true],
|
3037
|
+
['Generic', true],
|
3038
|
+
['Protocol', true],
|
3039
|
+
['Callable', true],
|
3040
|
+
['Type', true],
|
3041
|
+
['ClassVar', true],
|
3042
|
+
['Final', true],
|
3043
|
+
['Literal', true],
|
3044
|
+
['TypedDict', true],
|
3045
|
+
['Union', true],
|
3046
|
+
['Optional', true],
|
3047
|
+
['Annotated', true],
|
3048
|
+
['TypeAlias', true],
|
3049
|
+
['OrderedDict', true],
|
3050
|
+
['Concatenate', true],
|
3051
|
+
['TypeGuard', true],
|
3052
|
+
['StrictTypeGuard', true],
|
3053
|
+
['Unpack', true],
|
3054
|
+
['Self', true],
|
3055
|
+
['NoReturn', true],
|
3056
|
+
['Never', true],
|
3057
|
+
['LiteralString', true],
|
3058
|
+
]);
|
3059
|
+
const assignedName = assignedNameNode.value;
|
3060
|
+
if (!specialTypes.has(assignedName)) {
|
3061
|
+
return false;
|
3062
|
+
}
|
3063
|
+
const symbol = this._bindNameToScope(this._currentScope, assignedName);
|
3064
|
+
if (symbol) {
|
3065
|
+
symbol.addDeclaration({
|
3066
|
+
type: 5 /* SpecialBuiltInClass */,
|
3067
|
+
node: annotationNode,
|
3068
|
+
path: this._fileInfo.filePath,
|
3069
|
+
range: (0, positionUtils_1.convertOffsetsToRange)(annotationNode.start, textRange_2.TextRange.getEnd(annotationNode), this._fileInfo.lines),
|
3070
|
+
moduleName: this._fileInfo.moduleName,
|
3071
|
+
isInExceptSuite: this._isInExceptSuite,
|
3072
|
+
});
|
3073
|
+
}
|
3074
|
+
return true;
|
3075
|
+
}
|
3076
|
+
_deferBinding(callback) {
|
3077
|
+
if (this._moduleSymbolOnly) {
|
3078
|
+
return;
|
3079
|
+
}
|
3080
|
+
this._deferredBindingTasks.push({
|
3081
|
+
scope: this._currentScope,
|
3082
|
+
codeFlowExpressions: this._currentScopeCodeFlowExpressions,
|
3083
|
+
callback,
|
3084
|
+
});
|
3085
|
+
}
|
3086
|
+
_bindDeferred() {
|
3087
|
+
while (this._deferredBindingTasks.length > 0) {
|
3088
|
+
const nextItem = this._deferredBindingTasks.shift();
|
3089
|
+
// Reset the state
|
3090
|
+
this._currentScope = nextItem.scope;
|
3091
|
+
this._currentScopeCodeFlowExpressions = nextItem.codeFlowExpressions;
|
3092
|
+
nextItem.callback();
|
3093
|
+
}
|
3094
|
+
}
|
3095
|
+
_bindYield(node) {
|
3096
|
+
const functionNode = ParseTreeUtils.getEnclosingFunction(node);
|
3097
|
+
if (!functionNode) {
|
3098
|
+
if (!ParseTreeUtils.getEnclosingLambda(node)) {
|
3099
|
+
this._addError(localize_1.Localizer.Diagnostic.yieldOutsideFunction(), node);
|
3100
|
+
}
|
3101
|
+
}
|
3102
|
+
else if (functionNode.isAsync && node.nodeType === 61 /* YieldFrom */) {
|
3103
|
+
// PEP 525 indicates that 'yield from' is not allowed in an
|
3104
|
+
// async function.
|
3105
|
+
this._addError(localize_1.Localizer.Diagnostic.yieldFromOutsideAsync(), node);
|
3106
|
+
}
|
3107
|
+
if (this._targetFunctionDeclaration) {
|
3108
|
+
if (!this._targetFunctionDeclaration.yieldStatements) {
|
3109
|
+
this._targetFunctionDeclaration.yieldStatements = [];
|
3110
|
+
}
|
3111
|
+
this._targetFunctionDeclaration.yieldStatements.push(node);
|
3112
|
+
this._targetFunctionDeclaration.isGenerator = true;
|
3113
|
+
}
|
3114
|
+
if (node.expression) {
|
3115
|
+
this.walk(node.expression);
|
3116
|
+
}
|
3117
|
+
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
3118
|
+
}
|
3119
|
+
_getUniqueFlowNodeId() {
|
3120
|
+
this._codeFlowComplexity += flowNodeComplexityFactor;
|
3121
|
+
return (0, codeFlowTypes_1.getUniqueFlowNodeId)();
|
3122
|
+
}
|
3123
|
+
_addDiagnostic(diagLevel, rule, message, textRange) {
|
3124
|
+
let diagnostic;
|
3125
|
+
switch (diagLevel) {
|
3126
|
+
case 'error':
|
3127
|
+
diagnostic = this._addError(message, textRange);
|
3128
|
+
break;
|
3129
|
+
case 'warning':
|
3130
|
+
diagnostic = this._addWarning(message, textRange);
|
3131
|
+
break;
|
3132
|
+
case 'information':
|
3133
|
+
diagnostic = this._addInformation(message, textRange);
|
3134
|
+
break;
|
3135
|
+
case 'none':
|
3136
|
+
break;
|
3137
|
+
default:
|
3138
|
+
return (0, debug_1.assertNever)(diagLevel, `${diagLevel} is not expected`);
|
3139
|
+
}
|
3140
|
+
if (diagnostic) {
|
3141
|
+
diagnostic.setRule(rule);
|
3142
|
+
}
|
3143
|
+
return diagnostic;
|
3144
|
+
}
|
3145
|
+
_addError(message, textRange) {
|
3146
|
+
return this._fileInfo.diagnosticSink.addDiagnosticWithTextRange('error', message, textRange);
|
3147
|
+
}
|
3148
|
+
_addWarning(message, textRange) {
|
3149
|
+
return this._fileInfo.diagnosticSink.addDiagnosticWithTextRange('warning', message, textRange);
|
3150
|
+
}
|
3151
|
+
_addInformation(message, textRange) {
|
3152
|
+
return this._fileInfo.diagnosticSink.addDiagnosticWithTextRange('information', message, textRange);
|
3153
|
+
}
|
3154
|
+
}
|
3155
|
+
exports.Binder = Binder;
|
3156
|
+
// Flow node that is used for unreachable code.
|
3157
|
+
Binder._unreachableFlowNode = {
|
3158
|
+
flags: codeFlowTypes_1.FlowFlags.Unreachable,
|
3159
|
+
id: (0, codeFlowTypes_1.getUniqueFlowNodeId)(),
|
3160
|
+
};
|
3161
|
+
class YieldFinder extends parseTreeWalker_1.ParseTreeWalker {
|
3162
|
+
constructor() {
|
3163
|
+
super(...arguments);
|
3164
|
+
this._containsYield = false;
|
3165
|
+
}
|
3166
|
+
checkContainsYield(node) {
|
3167
|
+
this.walk(node);
|
3168
|
+
return this._containsYield;
|
3169
|
+
}
|
3170
|
+
visitYield(node) {
|
3171
|
+
this._containsYield = true;
|
3172
|
+
return false;
|
3173
|
+
}
|
3174
|
+
visitYieldFrom(node) {
|
3175
|
+
this._containsYield = true;
|
3176
|
+
return false;
|
3177
|
+
}
|
3178
|
+
}
|
3179
|
+
exports.YieldFinder = YieldFinder;
|
3180
|
+
class ReturnFinder extends parseTreeWalker_1.ParseTreeWalker {
|
3181
|
+
constructor() {
|
3182
|
+
super(...arguments);
|
3183
|
+
this._containsReturn = false;
|
3184
|
+
}
|
3185
|
+
checkContainsReturn(node) {
|
3186
|
+
this.walk(node);
|
3187
|
+
return this._containsReturn;
|
3188
|
+
}
|
3189
|
+
visitReturn(node) {
|
3190
|
+
this._containsReturn = true;
|
3191
|
+
return false;
|
3192
|
+
}
|
3193
|
+
}
|
3194
|
+
exports.ReturnFinder = ReturnFinder;
|
3195
|
+
//# sourceMappingURL=binder.js.map
|