@zzzen/pyright-internal 1.2.0-dev.20231119 → 1.2.0-dev.20231203
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/analysis.d.ts +1 -1
- package/dist/analyzer/analysis.js +5 -1
- package/dist/analyzer/analysis.js.map +1 -1
- package/dist/analyzer/analyzerFileInfo.d.ts +1 -1
- package/dist/analyzer/analyzerNodeInfo.d.ts +1 -1
- package/dist/analyzer/analyzerNodeInfo.js +1 -1
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.js +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.js +201 -194
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/cacheManager.js +1 -1
- package/dist/analyzer/cacheManager.js.map +1 -1
- package/dist/analyzer/checker.d.ts +4 -1
- package/dist/analyzer/checker.js +403 -248
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +1 -1
- package/dist/analyzer/codeFlowEngine.js +33 -26
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.d.ts +1 -1
- package/dist/analyzer/codeFlowTypes.js +23 -23
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/codeFlowUtils.js +39 -37
- package/dist/analyzer/codeFlowUtils.js.map +1 -1
- package/dist/analyzer/commentUtils.js +7 -0
- package/dist/analyzer/commentUtils.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +51 -47
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +8 -8
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +25 -26
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +124 -109
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +2 -2
- package/dist/analyzer/declaration.js +10 -10
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +41 -41
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +51 -51
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.js +27 -27
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/functionTransform.js +4 -4
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +1 -1
- package/dist/analyzer/importResolver.js +21 -17
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importResult.js +1 -1
- package/dist/analyzer/importResult.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +31 -27
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +36 -32
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +94 -92
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeReport.d.ts +1 -1
- package/dist/analyzer/packageTypeReport.js +2 -2
- package/dist/analyzer/packageTypeReport.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +90 -90
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +14 -14
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parentDirectoryCache.d.ts +2 -2
- package/dist/analyzer/parseTreeCleaner.js +5 -1
- package/dist/analyzer/parseTreeCleaner.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -1
- package/dist/analyzer/parseTreeUtils.js +383 -379
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +161 -157
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.d.ts +1 -1
- package/dist/analyzer/patternMatching.js +52 -50
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +1 -1
- package/dist/analyzer/program.js +18 -14
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +53 -44
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +41 -27
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.js +5 -1
- package/dist/analyzer/pythonPathUtils.js.map +1 -1
- package/dist/analyzer/regions.js +3 -3
- package/dist/analyzer/regions.js.map +1 -1
- package/dist/analyzer/scope.js +8 -8
- package/dist/analyzer/scope.js.map +1 -1
- package/dist/analyzer/scopeUtils.js +1 -1
- package/dist/analyzer/scopeUtils.js.map +1 -1
- package/dist/analyzer/service.js +5 -1
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.js +25 -21
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.d.ts +2 -2
- package/dist/analyzer/sourceMapper.js +12 -8
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +40 -40
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/symbol.d.ts +1 -1
- package/dist/analyzer/symbol.js +26 -26
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/symbolUtils.js +1 -1
- package/dist/analyzer/symbolUtils.js.map +1 -1
- package/dist/analyzer/testWalker.js +5 -5
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/tracePrinter.d.ts +1 -1
- package/dist/analyzer/tracePrinter.js +35 -31
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeCacheUtils.js +5 -1
- package/dist/analyzer/typeCacheUtils.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +13 -9
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +1347 -1270
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +4 -2
- package/dist/analyzer/typeEvaluatorTypes.js +4 -2
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +1 -1
- package/dist/analyzer/typeGuards.js +79 -65
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +1 -1
- package/dist/analyzer/typePrinter.js +80 -76
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +26 -22
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +1 -1
- package/dist/analyzer/typeUtils.js +139 -135
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +2 -0
- package/dist/analyzer/typeVarContext.js +36 -9
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typeWalker.js +10 -10
- package/dist/analyzer/typedDicts.js +76 -102
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +18 -18
- package/dist/analyzer/types.js +186 -191
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +2 -2
- package/dist/backgroundAnalysisBase.js +5 -1
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.js +5 -1
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/commandController.js +6 -7
- package/dist/commands/commandController.js.map +1 -1
- package/dist/commands/commandResult.js +1 -1
- package/dist/commands/commandResult.js.map +1 -1
- package/dist/commands/commands.d.ts +0 -1
- package/dist/commands/commands.js +1 -2
- package/dist/commands/commands.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +196 -196
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/commands/quickActionCommand.js +1 -1
- package/dist/commands/quickActionCommand.js.map +1 -1
- package/dist/common/charCodes.js +1 -1
- package/dist/common/charCodes.js.map +1 -1
- package/dist/common/chokidarFileWatcherProvider.js +5 -1
- package/dist/common/chokidarFileWatcherProvider.js.map +1 -1
- package/dist/common/collectionUtils.d.ts +3 -3
- package/dist/common/collectionUtils.js +3 -3
- package/dist/common/collectionUtils.js.map +1 -1
- package/dist/common/commandLineOptions.d.ts +1 -1
- package/dist/common/commandLineOptions.js +5 -5
- package/dist/common/commandLineOptions.js.map +1 -1
- package/dist/common/configOptions.d.ts +2 -1
- package/dist/common/configOptions.js +102 -10
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/console.js +7 -3
- package/dist/common/console.js.map +1 -1
- package/dist/common/core.d.ts +2 -2
- package/dist/common/core.js +6 -6
- package/dist/common/core.js.map +1 -1
- package/dist/common/diagnostic.d.ts +0 -4
- package/dist/common/diagnostic.js +6 -6
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/diagnosticRules.js +1 -1
- package/dist/common/diagnosticRules.js.map +1 -1
- package/dist/common/diagnosticSink.js +12 -12
- package/dist/common/diagnosticSink.js.map +1 -1
- package/dist/common/editAction.d.ts +1 -1
- package/dist/common/editAction.js +2 -2
- package/dist/common/editAction.js.map +1 -1
- package/dist/common/envVarUtils.js +5 -1
- package/dist/common/envVarUtils.js.map +1 -1
- package/dist/common/extensibility.js +1 -1
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileBasedCancellationUtils.js +5 -1
- package/dist/common/fileBasedCancellationUtils.js.map +1 -1
- package/dist/common/fileSystem.d.ts +1 -0
- package/dist/common/fileSystem.js +2 -2
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/fileWatcher.d.ts +2 -2
- package/dist/common/fullAccessHost.js +10 -6
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/host.d.ts +1 -1
- package/dist/common/host.js +2 -2
- package/dist/common/host.js.map +1 -1
- package/dist/common/lspUtils.js +7 -7
- package/dist/common/lspUtils.js.map +1 -1
- package/dist/common/memUtils.d.ts +1 -1
- package/dist/common/pathUtils.js +12 -8
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/pythonVersion.js +1 -1
- package/dist/common/pythonVersion.js.map +1 -1
- package/dist/common/realFileSystem.js +5 -1
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceProvider.d.ts +1 -1
- package/dist/common/serviceProvider.js +5 -1
- package/dist/common/serviceProvider.js.map +1 -1
- package/dist/common/serviceProviderExtensions.js +1 -1
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/common/stringUtils.js +5 -5
- package/dist/common/stringUtils.js.map +1 -1
- package/dist/common/textEditTracker.js +11 -7
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/common/textRange.js +3 -3
- package/dist/common/textRange.js.map +1 -1
- package/dist/languageServerBase.js +13 -13
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +3 -3
- package/dist/languageService/autoImporter.js +12 -8
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +27 -23
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/codeActionProvider.js +5 -19
- package/dist/languageService/codeActionProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +166 -162
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.js +9 -9
- package/dist/languageService/completionProviderUtils.js.map +1 -1
- package/dist/languageService/definitionProvider.js +14 -10
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentHighlightProvider.js +7 -3
- package/dist/languageService/documentHighlightProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.d.ts +1 -1
- package/dist/languageService/documentSymbolCollector.js +21 -17
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.js +30 -26
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importSorter.js +1 -1
- package/dist/languageService/importSorter.js.map +1 -1
- package/dist/languageService/quickActions.d.ts +1 -2
- package/dist/languageService/quickActions.js +1 -77
- package/dist/languageService/quickActions.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +1 -1
- package/dist/languageService/referencesProvider.js +24 -20
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +8 -4
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.js +8 -4
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +20 -16
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.js +5 -1
- package/dist/languageService/workspaceSymbolProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +19 -18
- package/dist/localization/localize.js +11 -8
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +0 -7
- package/dist/localization/package.nls.de.json +0 -7
- package/dist/localization/package.nls.en-us.json +11 -8
- package/dist/localization/package.nls.es.json +2 -9
- package/dist/localization/package.nls.fr.json +0 -7
- package/dist/localization/package.nls.it.json +0 -7
- package/dist/localization/package.nls.ja.json +0 -7
- package/dist/localization/package.nls.ko.json +0 -7
- package/dist/localization/package.nls.pl.json +0 -7
- package/dist/localization/package.nls.pt-br.json +0 -7
- package/dist/localization/package.nls.qps-ploc.json +0 -7
- package/dist/localization/package.nls.ru.json +0 -7
- package/dist/localization/package.nls.tr.json +0 -7
- package/dist/localization/package.nls.zh-cn.json +0 -7
- package/dist/localization/package.nls.zh-tw.json +0 -7
- package/dist/parser/characterStream.js +3 -3
- package/dist/parser/characterStream.js.map +1 -1
- package/dist/parser/characters.js +13 -9
- package/dist/parser/characters.js.map +1 -1
- package/dist/parser/parseNodes.d.ts +12 -12
- package/dist/parser/parseNodes.js +193 -193
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.js +563 -559
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/stringTokenUtils.js +47 -47
- package/dist/parser/stringTokenUtils.js.map +1 -1
- package/dist/parser/tokenizer.js +288 -288
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/tokenizerTypes.js +35 -35
- package/dist/parser/tokenizerTypes.js.map +1 -1
- package/dist/parser/unicode.d.ts +3 -3
- package/dist/pyright.js +21 -17
- package/dist/pyright.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +1 -0
- package/dist/pyrightFileSystem.js +2 -2
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +2 -1
- package/dist/readonlyAugmentedFileSystem.js +15 -5
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +5 -1
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/checker.test.js +13 -1
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/collectionUtils.test.js +5 -1
- package/dist/tests/collectionUtils.test.js.map +1 -1
- package/dist/tests/common.test.js +5 -1
- package/dist/tests/common.test.js.map +1 -1
- package/dist/tests/debug.test.js +8 -4
- package/dist/tests/debug.test.js.map +1 -1
- package/dist/tests/deferred.test.js +5 -1
- package/dist/tests/deferred.test.js.map +1 -1
- package/dist/tests/diagnosticOverrides.test.js +5 -1
- package/dist/tests/diagnosticOverrides.test.js.map +1 -1
- package/dist/tests/docStringUtils.test.js +5 -1
- package/dist/tests/docStringUtils.test.js.map +1 -1
- package/dist/tests/filesystem.test.js +5 -1
- package/dist/tests/filesystem.test.js.map +1 -1
- package/dist/tests/fourSlashParser.test.js +5 -1
- package/dist/tests/fourSlashParser.test.js.map +1 -1
- package/dist/tests/fourSlashRunner.test.js +5 -1
- package/dist/tests/fourSlashRunner.test.js.map +1 -1
- package/dist/tests/fourslash/fourslash.d.ts +1 -2
- package/dist/tests/harness/fourslash/fourSlashParser.js +13 -13
- package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
- package/dist/tests/harness/fourslash/fourSlashTypes.js +11 -7
- package/dist/tests/harness/fourslash/fourSlashTypes.js.map +1 -1
- package/dist/tests/harness/fourslash/runner.d.ts +1 -1
- package/dist/tests/harness/fourslash/runner.js +5 -1
- package/dist/tests/harness/fourslash/runner.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +5 -1
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.Consts.d.ts +1 -2
- package/dist/tests/harness/fourslash/testState.Consts.js +6 -3
- package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +18 -14
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/fourslash/testStateUtils.js +9 -5
- package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js +5 -1
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js.map +1 -1
- package/dist/tests/harness/testHost.js +5 -1
- package/dist/tests/harness/testHost.js.map +1 -1
- package/dist/tests/harness/utils.d.ts +13 -12
- package/dist/tests/harness/utils.js.map +1 -1
- package/dist/tests/harness/vfs/factory.js +6 -2
- package/dist/tests/harness/vfs/factory.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +4 -3
- package/dist/tests/harness/vfs/filesystem.js +11 -7
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/harness/vfs/pathValidation.js +30 -26
- package/dist/tests/harness/vfs/pathValidation.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +25 -25
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/ipythonMode.test.js +6 -6
- package/dist/tests/ipythonMode.test.js.map +1 -1
- package/dist/tests/localizer.test.js +5 -1
- package/dist/tests/localizer.test.js.map +1 -1
- package/dist/tests/logger.test.js +5 -1
- package/dist/tests/logger.test.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +10 -10
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/parser.test.js +13 -9
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/pathUtils.test.js +5 -1
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/pyrightFileSystem.test.js +48 -1
- package/dist/tests/pyrightFileSystem.test.js.map +1 -1
- package/dist/tests/sourceFile.test.js +5 -1
- package/dist/tests/sourceFile.test.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +5 -1
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- package/dist/tests/stringUtils.test.js +10 -6
- package/dist/tests/stringUtils.test.js.map +1 -1
- package/dist/tests/symbolNameUtils.test.js +5 -1
- package/dist/tests/symbolNameUtils.test.js.map +1 -1
- package/dist/tests/testState.test.js +5 -1
- package/dist/tests/testState.test.js.map +1 -1
- package/dist/tests/testUtils.js +11 -7
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/textRange.test.js +5 -1
- package/dist/tests/textRange.test.js.map +1 -1
- package/dist/tests/tokenizer.test.js +463 -459
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +22 -7
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +14 -6
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +23 -12
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +16 -4
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +13 -5
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +44 -40
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/tests/workspaceEditUtils.test.js +5 -1
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/tests/zipfs.test.js +5 -1
- package/dist/tests/zipfs.test.js.map +1 -1
- package/dist/workspaceFactory.js +2 -2
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +2 -2
package/dist/analyzer/binder.js
CHANGED
@@ -18,7 +18,11 @@
|
|
18
18
|
*/
|
19
19
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
20
20
|
if (k2 === undefined) k2 = k;
|
21
|
-
Object.
|
21
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
22
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
23
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
24
|
+
}
|
25
|
+
Object.defineProperty(o, k2, desc);
|
22
26
|
}) : (function(o, m, k, k2) {
|
23
27
|
if (k2 === undefined) k2 = k;
|
24
28
|
o[k2] = m[k];
|
@@ -109,7 +113,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
109
113
|
// We'll assume that if there is no builtins scope provided, we must be
|
110
114
|
// binding the builtins module itself.
|
111
115
|
const isBuiltInModule = this._fileInfo.builtinsScope === undefined;
|
112
|
-
this._createNewScope(isBuiltInModule ? 4 /* Builtin */ : 3 /* Module */, this._fileInfo.builtinsScope, () => {
|
116
|
+
this._createNewScope(isBuiltInModule ? 4 /* ScopeType.Builtin */ : 3 /* ScopeType.Module */, this._fileInfo.builtinsScope, () => {
|
113
117
|
AnalyzerNodeInfo.setScope(node, this._currentScope);
|
114
118
|
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
115
119
|
// Bind implicit names.
|
@@ -201,13 +205,13 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
201
205
|
}
|
202
206
|
// A source file was found, but the type stub was missing.
|
203
207
|
if (!importResult.isStubFile &&
|
204
|
-
importResult.importType === 1 /* ThirdParty */ &&
|
208
|
+
importResult.importType === 1 /* ImportType.ThirdParty */ &&
|
205
209
|
!importResult.pyTypedInfo) {
|
206
210
|
const diagnostic = this._addDiagnostic(this._fileInfo.diagnosticRuleSet.reportMissingTypeStubs, diagnosticRules_1.DiagnosticRule.reportMissingTypeStubs, localize_1.Localizer.Diagnostic.stubFileMissing().format({ importName: importResult.importName }), node);
|
207
211
|
if (diagnostic) {
|
208
212
|
// Add a diagnostic action for resolving this diagnostic.
|
209
213
|
const createTypeStubAction = {
|
210
|
-
action: "pyright.createtypestub" /* createTypeStub */,
|
214
|
+
action: "pyright.createtypestub" /* Commands.createTypeStub */,
|
211
215
|
moduleName: importResult.importName,
|
212
216
|
};
|
213
217
|
diagnostic.addAction(createTypeStubAction);
|
@@ -218,7 +222,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
218
222
|
visitClass(node) {
|
219
223
|
this.walkMultiple(node.decorators);
|
220
224
|
const classDeclaration = {
|
221
|
-
type: 6 /* Class */,
|
225
|
+
type: 6 /* DeclarationType.Class */,
|
222
226
|
node,
|
223
227
|
path: this._fileInfo.filePath,
|
224
228
|
range: (0, positionUtils_1.convertTextRangeToRange)(node.name, this._fileInfo.lines),
|
@@ -235,7 +239,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
235
239
|
this.walk(node.typeParameters);
|
236
240
|
}
|
237
241
|
this.walkMultiple(node.arguments);
|
238
|
-
this._createNewScope(2 /* Class */, this._getNonClassParentScope(), () => {
|
242
|
+
this._createNewScope(2 /* ScopeType.Class */, this._getNonClassParentScope(), () => {
|
239
243
|
AnalyzerNodeInfo.setScope(node, this._currentScope);
|
240
244
|
this._addImplicitSymbolToCurrentScope('__doc__', node, 'str | None');
|
241
245
|
this._addImplicitSymbolToCurrentScope('__module__', node, 'str');
|
@@ -261,7 +265,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
261
265
|
const symbol = this._bindNameToScope(this._currentScope, node.name);
|
262
266
|
const containingClassNode = ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true);
|
263
267
|
const functionDeclaration = {
|
264
|
-
type: 5 /* Function */,
|
268
|
+
type: 5 /* DeclarationType.Function */,
|
265
269
|
node,
|
266
270
|
isMethod: !!containingClassNode,
|
267
271
|
isGenerator: false,
|
@@ -301,7 +305,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
301
305
|
}
|
302
306
|
// Don't walk the body of the function until we're done analyzing
|
303
307
|
// the current scope.
|
304
|
-
this._createNewScope(1 /* Function */, this._getNonClassParentScope(), () => {
|
308
|
+
this._createNewScope(1 /* ScopeType.Function */, this._getNonClassParentScope(), () => {
|
305
309
|
AnalyzerNodeInfo.setScope(node, this._currentScope);
|
306
310
|
const enclosingClass = ParseTreeUtils.getEnclosingClass(node);
|
307
311
|
if (enclosingClass) {
|
@@ -323,7 +327,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
323
327
|
}
|
324
328
|
if (symbol) {
|
325
329
|
const paramDeclaration = {
|
326
|
-
type: 2 /* Parameter */,
|
330
|
+
type: 2 /* DeclarationType.Parameter */,
|
327
331
|
node: paramNode,
|
328
332
|
path: this._fileInfo.filePath,
|
329
333
|
range: (0, positionUtils_1.convertTextRangeToRange)(paramNode, this._fileInfo.lines),
|
@@ -371,7 +375,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
371
375
|
this.walk(param.defaultValue);
|
372
376
|
}
|
373
377
|
});
|
374
|
-
this._createNewScope(1 /* Function */, this._getNonClassParentScope(), () => {
|
378
|
+
this._createNewScope(1 /* ScopeType.Function */, this._getNonClassParentScope(), () => {
|
375
379
|
AnalyzerNodeInfo.setScope(node, this._currentScope);
|
376
380
|
this._deferBinding(() => {
|
377
381
|
// Create a start node for the lambda.
|
@@ -381,7 +385,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
381
385
|
const symbol = this._bindNameToScope(this._currentScope, paramNode.name);
|
382
386
|
if (symbol) {
|
383
387
|
const paramDeclaration = {
|
384
|
-
type: 2 /* Parameter */,
|
388
|
+
type: 2 /* DeclarationType.Parameter */,
|
385
389
|
node: paramNode,
|
386
390
|
path: this._fileInfo.filePath,
|
387
391
|
range: (0, positionUtils_1.convertTextRangeToRange)(paramNode, this._fileInfo.lines),
|
@@ -421,7 +425,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
421
425
|
// There are libraries that make extensive use of unannotated decorators,
|
422
426
|
// and this can lead to a performance issue when walking the control
|
423
427
|
// flow graph if we need to evaluate every decorator.
|
424
|
-
if (!ParseTreeUtils.isNodeContainedWithinNodeType(node, 13 /* Decorator */)) {
|
428
|
+
if (!ParseTreeUtils.isNodeContainedWithinNodeType(node, 13 /* ParseNodeType.Decorator */)) {
|
425
429
|
// Skip if we're in an 'Annotated' annotation because this creates
|
426
430
|
// problems for "No Return" return type analysis when annotation
|
427
431
|
// evaluation is deferred.
|
@@ -430,29 +434,29 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
430
434
|
}
|
431
435
|
}
|
432
436
|
// Is this an manipulation of dunder all?
|
433
|
-
if (this._currentScope.type === 3 /* Module */ &&
|
434
|
-
node.leftExpression.nodeType === 35 /* MemberAccess */ &&
|
435
|
-
node.leftExpression.leftExpression.nodeType === 38 /* Name */ &&
|
437
|
+
if (this._currentScope.type === 3 /* ScopeType.Module */ &&
|
438
|
+
node.leftExpression.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
439
|
+
node.leftExpression.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
436
440
|
node.leftExpression.leftExpression.value === '__all__') {
|
437
441
|
let emitDunderAllWarning = true;
|
438
442
|
// Is this a call to "__all__.extend()"?
|
439
443
|
if (node.leftExpression.memberName.value === 'extend' && node.arguments.length === 1) {
|
440
444
|
const argExpr = node.arguments[0].valueExpression;
|
441
445
|
// Is this a call to "__all__.extend([<list>])"?
|
442
|
-
if (argExpr.nodeType === 31 /* List */) {
|
446
|
+
if (argExpr.nodeType === 31 /* ParseNodeType.List */) {
|
443
447
|
argExpr.entries.forEach((listEntryNode) => {
|
444
448
|
var _a, _b;
|
445
|
-
if (listEntryNode.nodeType === 48 /* StringList */ &&
|
449
|
+
if (listEntryNode.nodeType === 48 /* ParseNodeType.StringList */ &&
|
446
450
|
listEntryNode.strings.length === 1 &&
|
447
|
-
listEntryNode.strings[0].nodeType === 49 /* String */) {
|
451
|
+
listEntryNode.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
448
452
|
(_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.push(listEntryNode.strings[0].value);
|
449
453
|
(_b = this._dunderAllStringNodes) === null || _b === void 0 ? void 0 : _b.push(listEntryNode.strings[0]);
|
450
454
|
emitDunderAllWarning = false;
|
451
455
|
}
|
452
456
|
});
|
453
457
|
}
|
454
|
-
else if (argExpr.nodeType === 35 /* MemberAccess */ &&
|
455
|
-
argExpr.leftExpression.nodeType === 38 /* Name */ &&
|
458
|
+
else if (argExpr.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
459
|
+
argExpr.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
456
460
|
argExpr.memberName.value === '__all__') {
|
457
461
|
// Is this a call to "__all__.extend(<mod>.__all__)"?
|
458
462
|
const namesToAdd = this._getDunderAllNamesFromImport(argExpr.leftExpression.value);
|
@@ -468,9 +472,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
468
472
|
else if (node.leftExpression.memberName.value === 'remove' && node.arguments.length === 1) {
|
469
473
|
// Is this a call to "__all__.remove()"?
|
470
474
|
const argExpr = node.arguments[0].valueExpression;
|
471
|
-
if (argExpr.nodeType === 48 /* StringList */ &&
|
475
|
+
if (argExpr.nodeType === 48 /* ParseNodeType.StringList */ &&
|
472
476
|
argExpr.strings.length === 1 &&
|
473
|
-
argExpr.strings[0].nodeType === 49 /* String */ &&
|
477
|
+
argExpr.strings[0].nodeType === 49 /* ParseNodeType.String */ &&
|
474
478
|
this._dunderAllNames) {
|
475
479
|
this._dunderAllNames = this._dunderAllNames.filter((name) => name !== argExpr.strings[0].value);
|
476
480
|
this._dunderAllStringNodes = this._dunderAllStringNodes.filter((node) => node.value !== argExpr.strings[0].value);
|
@@ -480,9 +484,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
480
484
|
else if (node.leftExpression.memberName.value === 'append' && node.arguments.length === 1) {
|
481
485
|
// Is this a call to "__all__.append()"?
|
482
486
|
const argExpr = node.arguments[0].valueExpression;
|
483
|
-
if (argExpr.nodeType === 48 /* StringList */ &&
|
487
|
+
if (argExpr.nodeType === 48 /* ParseNodeType.StringList */ &&
|
484
488
|
argExpr.strings.length === 1 &&
|
485
|
-
argExpr.strings[0].nodeType === 49 /* String */) {
|
489
|
+
argExpr.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
486
490
|
(_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.push(argExpr.strings[0].value);
|
487
491
|
(_b = this._dunderAllStringNodes) === null || _b === void 0 ? void 0 : _b.push(argExpr.strings[0]);
|
488
492
|
emitDunderAllWarning = false;
|
@@ -503,9 +507,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
503
507
|
});
|
504
508
|
node.parameters.forEach((param) => {
|
505
509
|
const name = param.name;
|
506
|
-
const symbol = new symbol_1.Symbol(0 /* None */);
|
510
|
+
const symbol = new symbol_1.Symbol(0 /* SymbolFlags.None */);
|
507
511
|
const paramDeclaration = {
|
508
|
-
type: 3 /* TypeParameter */,
|
512
|
+
type: 3 /* DeclarationType.TypeParameter */,
|
509
513
|
node: param,
|
510
514
|
path: this._fileInfo.filePath,
|
511
515
|
range: (0, positionUtils_1.convertTextRangeToRange)(node, this._fileInfo.lines),
|
@@ -536,7 +540,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
536
540
|
this.walk(node.typeParameters);
|
537
541
|
}
|
538
542
|
const typeAliasDeclaration = {
|
539
|
-
type: 4 /* TypeAlias */,
|
543
|
+
type: 4 /* DeclarationType.TypeAlias */,
|
540
544
|
node,
|
541
545
|
path: this._fileInfo.filePath,
|
542
546
|
range: (0, positionUtils_1.convertTextRangeToRange)(node.name, this._fileInfo.lines),
|
@@ -571,11 +575,11 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
571
575
|
// If the assignment target base expression is potentially a
|
572
576
|
// TypedDict, add the base expression to the flow expressions set
|
573
577
|
// to accommodate TypedDict type narrowing.
|
574
|
-
if (node.leftExpression.nodeType === 24 /* Index */) {
|
578
|
+
if (node.leftExpression.nodeType === 24 /* ParseNodeType.Index */) {
|
575
579
|
const target = node.leftExpression;
|
576
580
|
if (target.items.length === 1 &&
|
577
581
|
!target.trailingComma &&
|
578
|
-
target.items[0].valueExpression.nodeType === 48 /* StringList */) {
|
582
|
+
target.items[0].valueExpression.nodeType === 48 /* ParseNodeType.StringList */) {
|
579
583
|
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(target.baseExpression)) {
|
580
584
|
const baseExprReferenceKey = (0, codeFlowTypes_1.createKeyForReference)(target.baseExpression);
|
581
585
|
this._currentScopeCodeFlowExpressions.add(baseExprReferenceKey);
|
@@ -589,7 +593,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
589
593
|
// or as class variables, not as local variables within a function.
|
590
594
|
isPossibleTypeAlias = false;
|
591
595
|
}
|
592
|
-
else if (node.rightExpression.nodeType === 9 /* Call */ && this._fileInfo.isTypingStubFile) {
|
596
|
+
else if (node.rightExpression.nodeType === 9 /* ParseNodeType.Call */ && this._fileInfo.isTypingStubFile) {
|
593
597
|
// Some special built-in types defined in typing.pyi use
|
594
598
|
// assignments of the form List = _Alias(). We don't want to
|
595
599
|
// treat these as type aliases.
|
@@ -603,19 +607,19 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
603
607
|
// If we didn't create assignment target flow nodes above, do so now.
|
604
608
|
this._createAssignmentTargetFlowNodes(node.leftExpression, /* walkTargets */ true, /* unbound */ false);
|
605
609
|
// Is this an assignment to dunder all?
|
606
|
-
if (this._currentScope.type === 3 /* Module */) {
|
607
|
-
if ((node.leftExpression.nodeType === 38 /* Name */ && node.leftExpression.value === '__all__') ||
|
608
|
-
(node.leftExpression.nodeType === 54 /* TypeAnnotation */ &&
|
609
|
-
node.leftExpression.valueExpression.nodeType === 38 /* Name */ &&
|
610
|
+
if (this._currentScope.type === 3 /* ScopeType.Module */) {
|
611
|
+
if ((node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ && node.leftExpression.value === '__all__') ||
|
612
|
+
(node.leftExpression.nodeType === 54 /* ParseNodeType.TypeAnnotation */ &&
|
613
|
+
node.leftExpression.valueExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
610
614
|
node.leftExpression.valueExpression.value === '__all__')) {
|
611
615
|
const expr = node.rightExpression;
|
612
616
|
this._dunderAllNames = [];
|
613
617
|
let emitDunderAllWarning = false;
|
614
|
-
if (expr.nodeType === 31 /* List */) {
|
618
|
+
if (expr.nodeType === 31 /* ParseNodeType.List */) {
|
615
619
|
expr.entries.forEach((listEntryNode) => {
|
616
|
-
if (listEntryNode.nodeType === 48 /* StringList */ &&
|
620
|
+
if (listEntryNode.nodeType === 48 /* ParseNodeType.StringList */ &&
|
617
621
|
listEntryNode.strings.length === 1 &&
|
618
|
-
listEntryNode.strings[0].nodeType === 49 /* String */) {
|
622
|
+
listEntryNode.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
619
623
|
this._dunderAllNames.push(listEntryNode.strings[0].value);
|
620
624
|
this._dunderAllStringNodes.push(listEntryNode.strings[0]);
|
621
625
|
}
|
@@ -624,11 +628,11 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
624
628
|
}
|
625
629
|
});
|
626
630
|
}
|
627
|
-
else if (expr.nodeType === 52 /* Tuple */) {
|
631
|
+
else if (expr.nodeType === 52 /* ParseNodeType.Tuple */) {
|
628
632
|
expr.expressions.forEach((tupleEntryNode) => {
|
629
|
-
if (tupleEntryNode.nodeType === 48 /* StringList */ &&
|
633
|
+
if (tupleEntryNode.nodeType === 48 /* ParseNodeType.StringList */ &&
|
630
634
|
tupleEntryNode.strings.length === 1 &&
|
631
|
-
tupleEntryNode.strings[0].nodeType === 49 /* String */) {
|
635
|
+
tupleEntryNode.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
632
636
|
this._dunderAllNames.push(tupleEntryNode.strings[0].value);
|
633
637
|
this._dunderAllStringNodes.push(tupleEntryNode.strings[0]);
|
634
638
|
}
|
@@ -647,22 +651,22 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
647
651
|
}
|
648
652
|
}
|
649
653
|
// Is this an assignment to dunder slots?
|
650
|
-
if (this._currentScope.type === 2 /* Class */) {
|
651
|
-
if ((node.leftExpression.nodeType === 38 /* Name */ && node.leftExpression.value === '__slots__') ||
|
652
|
-
(node.leftExpression.nodeType === 54 /* TypeAnnotation */ &&
|
653
|
-
node.leftExpression.valueExpression.nodeType === 38 /* Name */ &&
|
654
|
+
if (this._currentScope.type === 2 /* ScopeType.Class */) {
|
655
|
+
if ((node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ && node.leftExpression.value === '__slots__') ||
|
656
|
+
(node.leftExpression.nodeType === 54 /* ParseNodeType.TypeAnnotation */ &&
|
657
|
+
node.leftExpression.valueExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
654
658
|
node.leftExpression.valueExpression.value === '__slots__')) {
|
655
659
|
const expr = node.rightExpression;
|
656
660
|
this._dunderSlotsEntries = [];
|
657
661
|
let isExpressionUnderstood = true;
|
658
|
-
if (expr.nodeType === 48 /* StringList */) {
|
662
|
+
if (expr.nodeType === 48 /* ParseNodeType.StringList */) {
|
659
663
|
this._dunderSlotsEntries.push(expr);
|
660
664
|
}
|
661
|
-
else if (expr.nodeType === 31 /* List */) {
|
665
|
+
else if (expr.nodeType === 31 /* ParseNodeType.List */) {
|
662
666
|
expr.entries.forEach((listEntryNode) => {
|
663
|
-
if (listEntryNode.nodeType === 48 /* StringList */ &&
|
667
|
+
if (listEntryNode.nodeType === 48 /* ParseNodeType.StringList */ &&
|
664
668
|
listEntryNode.strings.length === 1 &&
|
665
|
-
listEntryNode.strings[0].nodeType === 49 /* String */) {
|
669
|
+
listEntryNode.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
666
670
|
this._dunderSlotsEntries.push(listEntryNode);
|
667
671
|
}
|
668
672
|
else {
|
@@ -670,11 +674,11 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
670
674
|
}
|
671
675
|
});
|
672
676
|
}
|
673
|
-
else if (expr.nodeType === 52 /* Tuple */) {
|
677
|
+
else if (expr.nodeType === 52 /* ParseNodeType.Tuple */) {
|
674
678
|
expr.expressions.forEach((tupleEntryNode) => {
|
675
|
-
if (tupleEntryNode.nodeType === 48 /* StringList */ &&
|
679
|
+
if (tupleEntryNode.nodeType === 48 /* ParseNodeType.StringList */ &&
|
676
680
|
tupleEntryNode.strings.length === 1 &&
|
677
|
-
tupleEntryNode.strings[0].nodeType === 49 /* String */) {
|
681
|
+
tupleEntryNode.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
678
682
|
this._dunderSlotsEntries.push(tupleEntryNode);
|
679
683
|
}
|
680
684
|
else {
|
@@ -735,27 +739,27 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
735
739
|
this._createAssignmentTargetFlowNodes(node.destExpression, /* walkTargets */ false, /* unbound */ false);
|
736
740
|
// Is this an assignment to dunder all of the form
|
737
741
|
// __all__ += <expression>?
|
738
|
-
if (node.operator === 1 /* AddEqual */ &&
|
739
|
-
this._currentScope.type === 3 /* Module */ &&
|
740
|
-
node.leftExpression.nodeType === 38 /* Name */ &&
|
742
|
+
if (node.operator === 1 /* OperatorType.AddEqual */ &&
|
743
|
+
this._currentScope.type === 3 /* ScopeType.Module */ &&
|
744
|
+
node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
741
745
|
node.leftExpression.value === '__all__') {
|
742
746
|
const expr = node.rightExpression;
|
743
747
|
let emitDunderAllWarning = true;
|
744
|
-
if (expr.nodeType === 31 /* List */) {
|
748
|
+
if (expr.nodeType === 31 /* ParseNodeType.List */) {
|
745
749
|
// Is this the form __all__ += ["a", "b"]?
|
746
750
|
expr.entries.forEach((listEntryNode) => {
|
747
751
|
var _a;
|
748
|
-
if (listEntryNode.nodeType === 48 /* StringList */ &&
|
752
|
+
if (listEntryNode.nodeType === 48 /* ParseNodeType.StringList */ &&
|
749
753
|
listEntryNode.strings.length === 1 &&
|
750
|
-
listEntryNode.strings[0].nodeType === 49 /* String */) {
|
754
|
+
listEntryNode.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
751
755
|
(_a = this._dunderAllNames) === null || _a === void 0 ? void 0 : _a.push(listEntryNode.strings[0].value);
|
752
756
|
this._dunderAllStringNodes.push(listEntryNode.strings[0]);
|
753
757
|
}
|
754
758
|
});
|
755
759
|
emitDunderAllWarning = false;
|
756
760
|
}
|
757
|
-
else if (expr.nodeType === 35 /* MemberAccess */ &&
|
758
|
-
expr.leftExpression.nodeType === 38 /* Name */ &&
|
761
|
+
else if (expr.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
762
|
+
expr.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
759
763
|
expr.memberName.value === '__all__') {
|
760
764
|
// Is this using the form "__all__ += <mod>.__all__"?
|
761
765
|
const namesToAdd = this._getDunderAllNamesFromImport(expr.leftExpression.value);
|
@@ -789,7 +793,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
789
793
|
}
|
790
794
|
// If this is an annotated variable assignment within a class body,
|
791
795
|
// we need to evaluate the type annotation first.
|
792
|
-
const bindVariableBeforeAnnotationEvaluation = ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* Assignment */ &&
|
796
|
+
const bindVariableBeforeAnnotationEvaluation = ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* ParseNodeType.Assignment */ &&
|
793
797
|
ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true) !== undefined;
|
794
798
|
if (!bindVariableBeforeAnnotationEvaluation) {
|
795
799
|
this.walk(node.typeAnnotation);
|
@@ -1009,7 +1013,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1009
1013
|
this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ true, /* unbound */ false);
|
1010
1014
|
if (symbol) {
|
1011
1015
|
const declaration = {
|
1012
|
-
type: 1 /* Variable */,
|
1016
|
+
type: 1 /* DeclarationType.Variable */,
|
1013
1017
|
node: node.name,
|
1014
1018
|
isConstant: (0, symbolNameUtils_1.isConstantName)(node.name.value),
|
1015
1019
|
inferredTypeSource: node,
|
@@ -1033,6 +1037,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1033
1037
|
return false;
|
1034
1038
|
}
|
1035
1039
|
visitRaise(node) {
|
1040
|
+
if (this._currentFlowNode) {
|
1041
|
+
this._addExceptTargets(this._currentFlowNode);
|
1042
|
+
}
|
1036
1043
|
if (this._targetFunctionDeclaration) {
|
1037
1044
|
if (!this._targetFunctionDeclaration.raiseStatements) {
|
1038
1045
|
this._targetFunctionDeclaration.raiseStatements = [];
|
@@ -1183,7 +1190,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1183
1190
|
// Allow if it's within a generator expression. Execution of
|
1184
1191
|
// generator expressions is deferred and therefore can be
|
1185
1192
|
// run within the context of an async function later.
|
1186
|
-
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 32 /* ListComprehension */) {
|
1193
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 32 /* ParseNodeType.ListComprehension */) {
|
1187
1194
|
this._addError(localize_1.Localizer.Diagnostic.awaitNotInAsync(), node);
|
1188
1195
|
}
|
1189
1196
|
}
|
@@ -1194,7 +1201,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1194
1201
|
node.nameList.forEach((name) => {
|
1195
1202
|
const nameValue = name.value;
|
1196
1203
|
// Is the binding inconsistent?
|
1197
|
-
if (this._currentScope.getBindingType(nameValue) === 0 /* Nonlocal */) {
|
1204
|
+
if (this._currentScope.getBindingType(nameValue) === 0 /* NameBindingType.Nonlocal */) {
|
1198
1205
|
this._addError(localize_1.Localizer.Diagnostic.nonLocalRedefinition().format({ name: nameValue }), name);
|
1199
1206
|
}
|
1200
1207
|
const valueWithScope = this._currentScope.lookUpSymbolRecursive(nameValue);
|
@@ -1205,7 +1212,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1205
1212
|
// Add it to the global scope if it's not already added.
|
1206
1213
|
this._bindNameToScope(globalScope, name);
|
1207
1214
|
if (this._currentScope !== globalScope) {
|
1208
|
-
this._currentScope.setBindingType(nameValue, 1 /* Global */);
|
1215
|
+
this._currentScope.setBindingType(nameValue, 1 /* NameBindingType.Global */);
|
1209
1216
|
}
|
1210
1217
|
});
|
1211
1218
|
return true;
|
@@ -1219,7 +1226,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1219
1226
|
node.nameList.forEach((name) => {
|
1220
1227
|
const nameValue = name.value;
|
1221
1228
|
// Is the binding inconsistent?
|
1222
|
-
if (this._currentScope.getBindingType(nameValue) === 1 /* Global */) {
|
1229
|
+
if (this._currentScope.getBindingType(nameValue) === 1 /* NameBindingType.Global */) {
|
1223
1230
|
this._addError(localize_1.Localizer.Diagnostic.globalRedefinition().format({ name: nameValue }), name);
|
1224
1231
|
}
|
1225
1232
|
const valueWithScope = this._currentScope.lookUpSymbolRecursive(nameValue);
|
@@ -1231,7 +1238,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1231
1238
|
this._addError(localize_1.Localizer.Diagnostic.nonLocalNoBinding().format({ name: nameValue }), name);
|
1232
1239
|
}
|
1233
1240
|
if (valueWithScope) {
|
1234
|
-
this._currentScope.setBindingType(nameValue, 0 /* Nonlocal */);
|
1241
|
+
this._currentScope.setBindingType(nameValue, 0 /* NameBindingType.Nonlocal */);
|
1235
1242
|
}
|
1236
1243
|
});
|
1237
1244
|
}
|
@@ -1256,7 +1263,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1256
1263
|
}
|
1257
1264
|
const symbol = this._bindNameToScope(this._currentScope, symbolNameNode);
|
1258
1265
|
if (symbol &&
|
1259
|
-
(this._currentScope.type === 3 /* Module */ || this._currentScope.type === 4 /* Builtin */) &&
|
1266
|
+
(this._currentScope.type === 3 /* ScopeType.Module */ || this._currentScope.type === 4 /* ScopeType.Builtin */) &&
|
1260
1267
|
(!node.alias ||
|
1261
1268
|
node.module.nameParts.length !== 1 ||
|
1262
1269
|
node.module.nameParts[0].value !== node.alias.value)) {
|
@@ -1347,7 +1354,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1347
1354
|
// alias it.
|
1348
1355
|
if (importedSymbol) {
|
1349
1356
|
const aliasDecl = {
|
1350
|
-
type: 8 /* Alias */,
|
1357
|
+
type: 8 /* DeclarationType.Alias */,
|
1351
1358
|
node,
|
1352
1359
|
path: resolvedPath,
|
1353
1360
|
loadSymbolsFromPath: true,
|
@@ -1367,7 +1374,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1367
1374
|
const implicitImport = importInfo.filteredImplicitImports.get(name);
|
1368
1375
|
if (implicitImport) {
|
1369
1376
|
const submoduleFallback = {
|
1370
|
-
type: 8 /* Alias */,
|
1377
|
+
type: 8 /* DeclarationType.Alias */,
|
1371
1378
|
node,
|
1372
1379
|
path: implicitImport.path,
|
1373
1380
|
loadSymbolsFromPath: true,
|
@@ -1377,7 +1384,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1377
1384
|
isInExceptSuite: this._isInExceptSuite,
|
1378
1385
|
};
|
1379
1386
|
const aliasDecl = {
|
1380
|
-
type: 8 /* Alias */,
|
1387
|
+
type: 8 /* DeclarationType.Alias */,
|
1381
1388
|
node,
|
1382
1389
|
path: resolvedPath,
|
1383
1390
|
loadSymbolsFromPath: true,
|
@@ -1422,8 +1429,8 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1422
1429
|
// All import statements of the form `from . import x` treat x
|
1423
1430
|
// as an externally-visible (not hidden) symbol.
|
1424
1431
|
if (node.module.nameParts.length > 0) {
|
1425
|
-
if (this._currentScope.type === 3 /* Module */ ||
|
1426
|
-
this._currentScope.type === 4 /* Builtin */) {
|
1432
|
+
if (this._currentScope.type === 3 /* ScopeType.Module */ ||
|
1433
|
+
this._currentScope.type === 4 /* ScopeType.Builtin */) {
|
1427
1434
|
if (!importSymbolNode.alias ||
|
1428
1435
|
importSymbolNode.alias.value !== importSymbolNode.name.value) {
|
1429
1436
|
if (this._fileInfo.isStubFile || this._fileInfo.isInPyTypedPackage) {
|
@@ -1445,7 +1452,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1445
1452
|
let loadSymbolsFromPath = true;
|
1446
1453
|
if (implicitImport) {
|
1447
1454
|
submoduleFallback = {
|
1448
|
-
type: 8 /* Alias */,
|
1455
|
+
type: 8 /* DeclarationType.Alias */,
|
1449
1456
|
node: importSymbolNode,
|
1450
1457
|
path: implicitImport.path,
|
1451
1458
|
loadSymbolsFromPath: true,
|
@@ -1469,7 +1476,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1469
1476
|
}
|
1470
1477
|
}
|
1471
1478
|
const aliasDecl = {
|
1472
|
-
type: 8 /* Alias */,
|
1479
|
+
type: 8 /* DeclarationType.Alias */,
|
1473
1480
|
node: importSymbolNode,
|
1474
1481
|
path: resolvedPath,
|
1475
1482
|
loadSymbolsFromPath,
|
@@ -1583,7 +1590,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1583
1590
|
return false;
|
1584
1591
|
}
|
1585
1592
|
visitUnaryOperation(node) {
|
1586
|
-
if (node.operator === 38 /* Not */ && this._currentFalseTarget && this._currentTrueTarget) {
|
1593
|
+
if (node.operator === 38 /* OperatorType.Not */ && this._currentFalseTarget && this._currentTrueTarget) {
|
1587
1594
|
// Swap the existing true/false targets.
|
1588
1595
|
this._bindConditional(node.expression, this._currentFalseTarget, this._currentTrueTarget);
|
1589
1596
|
}
|
@@ -1599,7 +1606,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1599
1606
|
return false;
|
1600
1607
|
}
|
1601
1608
|
visitBinaryOperation(node) {
|
1602
|
-
if (node.operator === 36 /* And */ || node.operator === 37 /* Or */) {
|
1609
|
+
if (node.operator === 36 /* OperatorType.And */ || node.operator === 37 /* OperatorType.Or */) {
|
1603
1610
|
let trueTarget = this._currentTrueTarget;
|
1604
1611
|
let falseTarget = this._currentFalseTarget;
|
1605
1612
|
let postRightLabel;
|
@@ -1608,7 +1615,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1608
1615
|
trueTarget = falseTarget = postRightLabel;
|
1609
1616
|
}
|
1610
1617
|
const preRightLabel = this._createBranchLabel();
|
1611
|
-
if (node.operator === 36 /* And */) {
|
1618
|
+
if (node.operator === 36 /* OperatorType.And */) {
|
1612
1619
|
this._bindConditional(node.leftExpression, preRightLabel, falseTarget);
|
1613
1620
|
}
|
1614
1621
|
else {
|
@@ -1634,10 +1641,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1634
1641
|
visitListComprehension(node) {
|
1635
1642
|
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
1636
1643
|
// The first iterable is executed outside of the comprehension scope.
|
1637
|
-
if (node.forIfNodes.length > 0 && node.forIfNodes[0].nodeType === 33 /* ListComprehensionFor */) {
|
1644
|
+
if (node.forIfNodes.length > 0 && node.forIfNodes[0].nodeType === 33 /* ParseNodeType.ListComprehensionFor */) {
|
1638
1645
|
this.walk(node.forIfNodes[0].iterableExpression);
|
1639
1646
|
}
|
1640
|
-
this._createNewScope(0 /* ListComprehension */, this._getNonClassParentScope(), () => {
|
1647
|
+
this._createNewScope(0 /* ScopeType.ListComprehension */, this._getNonClassParentScope(), () => {
|
1641
1648
|
var _a;
|
1642
1649
|
AnalyzerNodeInfo.setScope(node, this._currentScope);
|
1643
1650
|
const falseLabel = this._createBranchLabel();
|
@@ -1647,7 +1654,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1647
1654
|
for (let i = 0; i < node.forIfNodes.length; i++) {
|
1648
1655
|
const compr = node.forIfNodes[i];
|
1649
1656
|
const addedSymbols = new Map();
|
1650
|
-
if (compr.nodeType === 33 /* ListComprehensionFor */) {
|
1657
|
+
if (compr.nodeType === 33 /* ParseNodeType.ListComprehensionFor */) {
|
1651
1658
|
this._bindPossibleTupleNamedTarget(compr.targetExpression, addedSymbols);
|
1652
1659
|
this._addInferredTypeAssignmentForVariable(compr.targetExpression, compr);
|
1653
1660
|
// Async for is not allowed outside of an async function
|
@@ -1657,7 +1664,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1657
1664
|
// Allow if it's within a generator expression. Execution of
|
1658
1665
|
// generator expressions is deferred and therefore can be
|
1659
1666
|
// run within the context of an async function later.
|
1660
|
-
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 31 /* List */) {
|
1667
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 31 /* ParseNodeType.List */) {
|
1661
1668
|
this._addError(localize_1.Localizer.Diagnostic.asyncNotInAsyncFunction(), compr.asyncToken);
|
1662
1669
|
}
|
1663
1670
|
}
|
@@ -1666,7 +1673,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1666
1673
|
}
|
1667
1674
|
for (let i = 0; i < node.forIfNodes.length; i++) {
|
1668
1675
|
const compr = node.forIfNodes[i];
|
1669
|
-
if (compr.nodeType === 33 /* ListComprehensionFor */) {
|
1676
|
+
if (compr.nodeType === 33 /* ParseNodeType.ListComprehensionFor */) {
|
1670
1677
|
// We already walked the first iterable expression above,
|
1671
1678
|
// so skip it here.
|
1672
1679
|
if (i !== 0) {
|
@@ -1761,7 +1768,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1761
1768
|
this._createAssignmentTargetFlowNodes(node.target, /* walkTargets */ false, /* unbound */ false);
|
1762
1769
|
if (symbol) {
|
1763
1770
|
const declaration = {
|
1764
|
-
type: 1 /* Variable */,
|
1771
|
+
type: 1 /* DeclarationType.Variable */,
|
1765
1772
|
node: node.target,
|
1766
1773
|
isConstant: (0, symbolNameUtils_1.isConstantName)(node.target.value),
|
1767
1774
|
inferredTypeSource: node,
|
@@ -1796,7 +1803,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1796
1803
|
const entry = this._activeTypeParams.get(typeParamNode.name.value);
|
1797
1804
|
if (entry) {
|
1798
1805
|
const decls = entry.getDeclarations();
|
1799
|
-
(0, debug_1.assert)(decls && decls.length === 1 && decls[0].type === 3 /* TypeParameter */);
|
1806
|
+
(0, debug_1.assert)(decls && decls.length === 1 && decls[0].type === 3 /* DeclarationType.TypeParameter */);
|
1800
1807
|
if (decls[0].node === typeParamNode) {
|
1801
1808
|
this._activeTypeParams.delete(typeParamNode.name.value);
|
1802
1809
|
}
|
@@ -1807,13 +1814,13 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1807
1814
|
// We may not be able to use the current scope if it's a class scope.
|
1808
1815
|
// Walk up until we find a non-class scope instead.
|
1809
1816
|
let parentScope = this._currentScope;
|
1810
|
-
while (parentScope.type === 2 /* Class */) {
|
1817
|
+
while (parentScope.type === 2 /* ScopeType.Class */) {
|
1811
1818
|
parentScope = parentScope.parent;
|
1812
1819
|
}
|
1813
1820
|
return parentScope;
|
1814
1821
|
}
|
1815
1822
|
_addSlotsToCurrentScope(slotNameNodes) {
|
1816
|
-
(0, debug_1.assert)(this._currentScope.type === 2 /* Class */);
|
1823
|
+
(0, debug_1.assert)(this._currentScope.type === 2 /* ScopeType.Class */);
|
1817
1824
|
let slotsContainsDict = false;
|
1818
1825
|
for (const slotNameNode of slotNameNodes) {
|
1819
1826
|
const slotName = slotNameNode.strings[0].value;
|
@@ -1823,14 +1830,14 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1823
1830
|
}
|
1824
1831
|
let symbol = this._currentScope.lookUpSymbol(slotName);
|
1825
1832
|
if (!symbol) {
|
1826
|
-
symbol = this._currentScope.addSymbol(slotName, 1 /* InitiallyUnbound */ | 4 /* ClassMember */);
|
1833
|
+
symbol = this._currentScope.addSymbol(slotName, 1 /* SymbolFlags.InitiallyUnbound */ | 4 /* SymbolFlags.ClassMember */);
|
1827
1834
|
const honorPrivateNaming = this._fileInfo.diagnosticRuleSet.reportPrivateUsage !== 'none';
|
1828
1835
|
if ((0, symbolNameUtils_1.isPrivateOrProtectedName)(slotName) && honorPrivateNaming) {
|
1829
1836
|
symbol.setIsPrivateMember();
|
1830
1837
|
}
|
1831
1838
|
}
|
1832
1839
|
const declaration = {
|
1833
|
-
type: 1 /* Variable */,
|
1840
|
+
type: 1 /* DeclarationType.Variable */,
|
1834
1841
|
node: slotNameNode,
|
1835
1842
|
isConstant: (0, symbolNameUtils_1.isConstantName)(slotName),
|
1836
1843
|
isDefinedBySlots: true,
|
@@ -1850,10 +1857,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1850
1857
|
let prevNode;
|
1851
1858
|
let prevPrevNode;
|
1852
1859
|
while (curNode) {
|
1853
|
-
if (curNode.nodeType === 32 /* ListComprehension */) {
|
1860
|
+
if (curNode.nodeType === 32 /* ParseNodeType.ListComprehension */) {
|
1854
1861
|
if (ignoreOutermostIterable && curNode.forIfNodes.length > 0) {
|
1855
1862
|
const outermostCompr = curNode.forIfNodes[0];
|
1856
|
-
if (prevNode === outermostCompr && outermostCompr.nodeType === 33 /* ListComprehensionFor */) {
|
1863
|
+
if (prevNode === outermostCompr && outermostCompr.nodeType === 33 /* ParseNodeType.ListComprehensionFor */) {
|
1857
1864
|
if (prevPrevNode === outermostCompr.iterableExpression) {
|
1858
1865
|
return false;
|
1859
1866
|
}
|
@@ -1872,7 +1879,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1872
1879
|
this._createAssignmentTargetFlowNodes(target, /* walkTargets */ false, /* unbound */ false);
|
1873
1880
|
if (symbol) {
|
1874
1881
|
const declaration = {
|
1875
|
-
type: 1 /* Variable */,
|
1882
|
+
type: 1 /* DeclarationType.Variable */,
|
1876
1883
|
node: target,
|
1877
1884
|
isConstant: (0, symbolNameUtils_1.isConstantName)(target.value),
|
1878
1885
|
inferredTypeSource: target.parent,
|
@@ -1899,7 +1906,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1899
1906
|
return undefined;
|
1900
1907
|
}
|
1901
1908
|
// There should be only one declaration for the variable.
|
1902
|
-
const aliasDecl = varSymbol.getDeclarations().find((decl) => decl.type === 8 /* Alias */);
|
1909
|
+
const aliasDecl = varSymbol.getDeclarations().find((decl) => decl.type === 8 /* DeclarationType.Alias */);
|
1903
1910
|
const resolvedPath = (aliasDecl === null || aliasDecl === void 0 ? void 0 : aliasDecl.path) && aliasDecl.loadSymbolsFromPath
|
1904
1911
|
? aliasDecl.path
|
1905
1912
|
: ((_a = aliasDecl === null || aliasDecl === void 0 ? void 0 : aliasDecl.submoduleFallback) === null || _a === void 0 ? void 0 : _a.path) && aliasDecl.submoduleFallback.loadSymbolsFromPath
|
@@ -1939,7 +1946,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1939
1946
|
// python module loader.
|
1940
1947
|
const existingDecl = symbol
|
1941
1948
|
.getDeclarations()
|
1942
|
-
.find((decl) => decl.type === 8 /* Alias */ && decl.firstNamePart === firstNamePartValue);
|
1949
|
+
.find((decl) => decl.type === 8 /* DeclarationType.Alias */ && decl.firstNamePart === firstNamePartValue);
|
1943
1950
|
let newDecl;
|
1944
1951
|
let pathOfLastSubmodule;
|
1945
1952
|
if (importInfo && importInfo.isImportFound && !importInfo.isNativeLib && importInfo.resolvedPaths.length > 0) {
|
@@ -1954,7 +1961,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1954
1961
|
}
|
1955
1962
|
else if (isResolved) {
|
1956
1963
|
newDecl = {
|
1957
|
-
type: 8 /* Alias */,
|
1964
|
+
type: 8 /* DeclarationType.Alias */,
|
1958
1965
|
node,
|
1959
1966
|
path: pathOfLastSubmodule,
|
1960
1967
|
loadSymbolsFromPath: false,
|
@@ -1970,7 +1977,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1970
1977
|
// bogus path so it gets an unknown type (rather than an unbound type) at
|
1971
1978
|
// analysis time.
|
1972
1979
|
newDecl = {
|
1973
|
-
type: 8 /* Alias */,
|
1980
|
+
type: 8 /* DeclarationType.Alias */,
|
1974
1981
|
node,
|
1975
1982
|
path: pathOfLastSubmodule,
|
1976
1983
|
loadSymbolsFromPath: true,
|
@@ -2172,12 +2179,12 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2172
2179
|
// positive or negative case).
|
2173
2180
|
_bindNeverCondition(node, target, isPositiveTest) {
|
2174
2181
|
const expressionList = [];
|
2175
|
-
if (node.nodeType === 55 /* UnaryOperation */ && node.operator === 38 /* Not */) {
|
2182
|
+
if (node.nodeType === 55 /* ParseNodeType.UnaryOperation */ && node.operator === 38 /* OperatorType.Not */) {
|
2176
2183
|
this._bindNeverCondition(node.expression, target, !isPositiveTest);
|
2177
2184
|
}
|
2178
|
-
else if (node.nodeType === 7 /* BinaryOperation */ &&
|
2179
|
-
(node.operator === 36 /* And */ || node.operator === 37 /* Or */)) {
|
2180
|
-
let isAnd = node.operator === 36 /* And */;
|
2185
|
+
else if (node.nodeType === 7 /* ParseNodeType.BinaryOperation */ &&
|
2186
|
+
(node.operator === 36 /* OperatorType.And */ || node.operator === 37 /* OperatorType.Or */)) {
|
2187
|
+
let isAnd = node.operator === 36 /* OperatorType.And */;
|
2181
2188
|
if (isPositiveTest) {
|
2182
2189
|
isAnd = !isAnd;
|
2183
2190
|
}
|
@@ -2214,7 +2221,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2214
2221
|
// that is a name. This avoids complexities with composite expressions like
|
2215
2222
|
// member access or index expressions.
|
2216
2223
|
if (this._isNarrowingExpression(node, expressionList, /* neverNarrowingExpressions */ true)) {
|
2217
|
-
const filteredExprList = expressionList.filter((expr) => expr.nodeType === 38 /* Name */);
|
2224
|
+
const filteredExprList = expressionList.filter((expr) => expr.nodeType === 38 /* ParseNodeType.Name */);
|
2218
2225
|
if (filteredExprList.length > 0) {
|
2219
2226
|
this._currentFlowNode = this._createFlowConditional(isPositiveTest ? codeFlowTypes_1.FlowFlags.TrueNeverCondition : codeFlowTypes_1.FlowFlags.FalseNeverCondition, this._currentFlowNode, node);
|
2220
2227
|
}
|
@@ -2264,7 +2271,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2264
2271
|
this._currentScopeCodeFlowExpressions.add(referenceKey);
|
2265
2272
|
});
|
2266
2273
|
// Select the first name expression.
|
2267
|
-
const filteredExprList = expressionList.filter((expr) => expr.nodeType === 38 /* Name */);
|
2274
|
+
const filteredExprList = expressionList.filter((expr) => expr.nodeType === 38 /* ParseNodeType.Name */);
|
2268
2275
|
const conditionalFlowNode = {
|
2269
2276
|
flags,
|
2270
2277
|
id: this._getUniqueFlowNodeId(),
|
@@ -2278,11 +2285,11 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2278
2285
|
// Indicates whether the expression is a NOT, AND or OR expression.
|
2279
2286
|
_isLogicalExpression(expression) {
|
2280
2287
|
switch (expression.nodeType) {
|
2281
|
-
case 55 /* UnaryOperation */: {
|
2282
|
-
return expression.operator === 38 /* Not */;
|
2288
|
+
case 55 /* ParseNodeType.UnaryOperation */: {
|
2289
|
+
return expression.operator === 38 /* OperatorType.Not */;
|
2283
2290
|
}
|
2284
|
-
case 7 /* BinaryOperation */: {
|
2285
|
-
return expression.operator === 36 /* And */ || expression.operator === 37 /* Or */;
|
2291
|
+
case 7 /* ParseNodeType.BinaryOperation */: {
|
2292
|
+
return expression.operator === 36 /* OperatorType.And */ || expression.operator === 37 /* OperatorType.Or */;
|
2286
2293
|
}
|
2287
2294
|
}
|
2288
2295
|
return false;
|
@@ -2297,13 +2304,13 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2297
2304
|
// these) or something more complex (binary operator, call, etc.).
|
2298
2305
|
_isNarrowingExpression(expression, expressionList, filterForNeverNarrowing = false, isComplexExpression = false) {
|
2299
2306
|
switch (expression.nodeType) {
|
2300
|
-
case 38 /* Name */:
|
2301
|
-
case 35 /* MemberAccess */:
|
2302
|
-
case 24 /* Index */: {
|
2307
|
+
case 38 /* ParseNodeType.Name */:
|
2308
|
+
case 35 /* ParseNodeType.MemberAccess */:
|
2309
|
+
case 24 /* ParseNodeType.Index */: {
|
2303
2310
|
if (filterForNeverNarrowing) {
|
2304
2311
|
// Never narrowing doesn't support member access or index
|
2305
2312
|
// expressions.
|
2306
|
-
if (expression.nodeType !== 38 /* Name */) {
|
2313
|
+
if (expression.nodeType !== 38 /* ParseNodeType.Name */) {
|
2307
2314
|
return false;
|
2308
2315
|
}
|
2309
2316
|
// Never narrowing doesn't support simple names (falsy
|
@@ -2319,7 +2326,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2319
2326
|
// If the expression is a member access expression, add its
|
2320
2327
|
// leftExpression to the expression list because that expression
|
2321
2328
|
// can be narrowed based on the attribute type.
|
2322
|
-
if (expression.nodeType === 35 /* MemberAccess */) {
|
2329
|
+
if (expression.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
2323
2330
|
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(expression.leftExpression)) {
|
2324
2331
|
expressionList.push(expression.leftExpression);
|
2325
2332
|
}
|
@@ -2327,10 +2334,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2327
2334
|
// If the expression is an index expression with a supported
|
2328
2335
|
// subscript, add its baseExpression to the expression list because
|
2329
2336
|
// that expression can be narrowed.
|
2330
|
-
if (expression.nodeType === 24 /* Index */ &&
|
2337
|
+
if (expression.nodeType === 24 /* ParseNodeType.Index */ &&
|
2331
2338
|
expression.items.length === 1 &&
|
2332
2339
|
!expression.trailingComma &&
|
2333
|
-
expression.items[0].argumentCategory === 0 /* Simple */) {
|
2340
|
+
expression.items[0].argumentCategory === 0 /* ArgumentCategory.Simple */) {
|
2334
2341
|
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(expression.baseExpression)) {
|
2335
2342
|
expressionList.push(expression.baseExpression);
|
2336
2343
|
}
|
@@ -2340,30 +2347,30 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2340
2347
|
}
|
2341
2348
|
return false;
|
2342
2349
|
}
|
2343
|
-
case 4 /* AssignmentExpression */: {
|
2350
|
+
case 4 /* ParseNodeType.AssignmentExpression */: {
|
2344
2351
|
expressionList.push(expression.name);
|
2345
2352
|
this._isNarrowingExpression(expression.rightExpression, expressionList, filterForNeverNarrowing,
|
2346
2353
|
/* isComplexExpression */ true);
|
2347
2354
|
return true;
|
2348
2355
|
}
|
2349
|
-
case 7 /* BinaryOperation */: {
|
2350
|
-
const isOrIsNotOperator = expression.operator === 39 /* Is */ || expression.operator === 40 /* IsNot */;
|
2351
|
-
const equalsOrNotEqualsOperator = expression.operator === 12 /* Equals */ || expression.operator === 28 /* NotEquals */;
|
2356
|
+
case 7 /* ParseNodeType.BinaryOperation */: {
|
2357
|
+
const isOrIsNotOperator = expression.operator === 39 /* OperatorType.Is */ || expression.operator === 40 /* OperatorType.IsNot */;
|
2358
|
+
const equalsOrNotEqualsOperator = expression.operator === 12 /* OperatorType.Equals */ || expression.operator === 28 /* OperatorType.NotEquals */;
|
2352
2359
|
if (isOrIsNotOperator || equalsOrNotEqualsOperator) {
|
2353
2360
|
// Look for "X is None", "X is not None", "X == None", "X != None".
|
2354
2361
|
// These are commonly-used patterns used in control flow.
|
2355
|
-
if (expression.rightExpression.nodeType === 11 /* Constant */ &&
|
2356
|
-
expression.rightExpression.constType === 26 /* None */) {
|
2362
|
+
if (expression.rightExpression.nodeType === 11 /* ParseNodeType.Constant */ &&
|
2363
|
+
expression.rightExpression.constType === 26 /* KeywordType.None */) {
|
2357
2364
|
return this._isNarrowingExpression(expression.leftExpression, expressionList, filterForNeverNarrowing,
|
2358
2365
|
/* isComplexExpression */ true);
|
2359
2366
|
}
|
2360
2367
|
// Look for "type(X) is Y" or "type(X) is not Y".
|
2361
2368
|
if (isOrIsNotOperator &&
|
2362
|
-
expression.leftExpression.nodeType === 9 /* Call */ &&
|
2363
|
-
expression.leftExpression.leftExpression.nodeType === 38 /* Name */ &&
|
2369
|
+
expression.leftExpression.nodeType === 9 /* ParseNodeType.Call */ &&
|
2370
|
+
expression.leftExpression.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
2364
2371
|
expression.leftExpression.leftExpression.value === 'type' &&
|
2365
2372
|
expression.leftExpression.arguments.length === 1 &&
|
2366
|
-
expression.leftExpression.arguments[0].argumentCategory === 0 /* Simple */) {
|
2373
|
+
expression.leftExpression.arguments[0].argumentCategory === 0 /* ArgumentCategory.Simple */) {
|
2367
2374
|
return this._isNarrowingExpression(expression.leftExpression.arguments[0].valueExpression, expressionList, filterForNeverNarrowing,
|
2368
2375
|
/* isComplexExpression */ true);
|
2369
2376
|
}
|
@@ -2374,38 +2381,38 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2374
2381
|
return isLeftNarrowing;
|
2375
2382
|
}
|
2376
2383
|
// Look for "<string> in Y" or "<string> not in Y".
|
2377
|
-
if (expression.operator === 41 /* In */ || expression.operator === 42 /* NotIn */) {
|
2378
|
-
if (expression.leftExpression.nodeType === 48 /* StringList */ &&
|
2384
|
+
if (expression.operator === 41 /* OperatorType.In */ || expression.operator === 42 /* OperatorType.NotIn */) {
|
2385
|
+
if (expression.leftExpression.nodeType === 48 /* ParseNodeType.StringList */ &&
|
2379
2386
|
this._isNarrowingExpression(expression.rightExpression, expressionList, filterForNeverNarrowing,
|
2380
2387
|
/* isComplexExpression */ true)) {
|
2381
2388
|
return true;
|
2382
2389
|
}
|
2383
2390
|
}
|
2384
2391
|
// Look for "X in Y" or "X not in Y".
|
2385
|
-
if (expression.operator === 41 /* In */ || expression.operator === 42 /* NotIn */) {
|
2392
|
+
if (expression.operator === 41 /* OperatorType.In */ || expression.operator === 42 /* OperatorType.NotIn */) {
|
2386
2393
|
return this._isNarrowingExpression(expression.leftExpression, expressionList, filterForNeverNarrowing,
|
2387
2394
|
/* isComplexExpression */ true);
|
2388
2395
|
}
|
2389
2396
|
return false;
|
2390
2397
|
}
|
2391
|
-
case 55 /* UnaryOperation */: {
|
2392
|
-
return (expression.operator === 38 /* Not */ &&
|
2398
|
+
case 55 /* ParseNodeType.UnaryOperation */: {
|
2399
|
+
return (expression.operator === 38 /* OperatorType.Not */ &&
|
2393
2400
|
this._isNarrowingExpression(expression.expression, expressionList, filterForNeverNarrowing,
|
2394
2401
|
/* isComplexExpression */ false));
|
2395
2402
|
}
|
2396
|
-
case 5 /* AugmentedAssignment */: {
|
2403
|
+
case 5 /* ParseNodeType.AugmentedAssignment */: {
|
2397
2404
|
return this._isNarrowingExpression(expression.rightExpression, expressionList, filterForNeverNarrowing,
|
2398
2405
|
/* isComplexExpression */ true);
|
2399
2406
|
}
|
2400
|
-
case 9 /* Call */: {
|
2401
|
-
if (expression.leftExpression.nodeType === 38 /* Name */ &&
|
2407
|
+
case 9 /* ParseNodeType.Call */: {
|
2408
|
+
if (expression.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
2402
2409
|
(expression.leftExpression.value === 'isinstance' ||
|
2403
2410
|
expression.leftExpression.value === 'issubclass') &&
|
2404
2411
|
expression.arguments.length === 2) {
|
2405
2412
|
return this._isNarrowingExpression(expression.arguments[0].valueExpression, expressionList, filterForNeverNarrowing,
|
2406
2413
|
/* isComplexExpression */ true);
|
2407
2414
|
}
|
2408
|
-
if (expression.leftExpression.nodeType === 38 /* Name */ &&
|
2415
|
+
if (expression.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
2409
2416
|
expression.leftExpression.value === 'callable' &&
|
2410
2417
|
expression.arguments.length === 1) {
|
2411
2418
|
return this._isNarrowingExpression(expression.arguments[0].valueExpression, expressionList, filterForNeverNarrowing,
|
@@ -2427,42 +2434,42 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2427
2434
|
}
|
2428
2435
|
_createAssignmentTargetFlowNodes(target, walkTargets, unbound) {
|
2429
2436
|
switch (target.nodeType) {
|
2430
|
-
case 38 /* Name */:
|
2431
|
-
case 35 /* MemberAccess */: {
|
2437
|
+
case 38 /* ParseNodeType.Name */:
|
2438
|
+
case 35 /* ParseNodeType.MemberAccess */: {
|
2432
2439
|
this._createFlowAssignment(target, unbound);
|
2433
2440
|
if (walkTargets) {
|
2434
2441
|
this.walk(target);
|
2435
2442
|
}
|
2436
2443
|
break;
|
2437
2444
|
}
|
2438
|
-
case 24 /* Index */: {
|
2445
|
+
case 24 /* ParseNodeType.Index */: {
|
2439
2446
|
this._createFlowAssignment(target, unbound);
|
2440
2447
|
if (walkTargets) {
|
2441
2448
|
this.walk(target);
|
2442
2449
|
}
|
2443
2450
|
break;
|
2444
2451
|
}
|
2445
|
-
case 52 /* Tuple */: {
|
2452
|
+
case 52 /* ParseNodeType.Tuple */: {
|
2446
2453
|
target.expressions.forEach((expr) => {
|
2447
2454
|
this._createAssignmentTargetFlowNodes(expr, walkTargets, unbound);
|
2448
2455
|
});
|
2449
2456
|
break;
|
2450
2457
|
}
|
2451
|
-
case 54 /* TypeAnnotation */: {
|
2458
|
+
case 54 /* ParseNodeType.TypeAnnotation */: {
|
2452
2459
|
this._createAssignmentTargetFlowNodes(target.valueExpression, /* walkTargets */ false, unbound);
|
2453
2460
|
if (walkTargets) {
|
2454
2461
|
this.walk(target);
|
2455
2462
|
}
|
2456
2463
|
break;
|
2457
2464
|
}
|
2458
|
-
case 56 /* Unpack */: {
|
2465
|
+
case 56 /* ParseNodeType.Unpack */: {
|
2459
2466
|
this._createAssignmentTargetFlowNodes(target.expression, /* walkTargets */ false, unbound);
|
2460
2467
|
if (walkTargets) {
|
2461
2468
|
this.walk(target);
|
2462
2469
|
}
|
2463
2470
|
break;
|
2464
2471
|
}
|
2465
|
-
case 31 /* List */: {
|
2472
|
+
case 31 /* ParseNodeType.List */: {
|
2466
2473
|
target.entries.forEach((entry) => {
|
2467
2474
|
this._createAssignmentTargetFlowNodes(entry, walkTargets, unbound);
|
2468
2475
|
});
|
@@ -2501,7 +2508,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2501
2508
|
}
|
2502
2509
|
_createFlowAssignment(node, unbound = false) {
|
2503
2510
|
let targetSymbolId = symbol_1.indeterminateSymbolId;
|
2504
|
-
if (node.nodeType === 38 /* Name */) {
|
2511
|
+
if (node.nodeType === 38 /* ParseNodeType.Name */) {
|
2505
2512
|
const symbolWithScope = this._currentScope.lookUpSymbolRecursive(node.value);
|
2506
2513
|
(0, debug_1.assert)(symbolWithScope !== undefined);
|
2507
2514
|
targetSymbolId = symbolWithScope.symbol.id;
|
@@ -2522,7 +2529,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2522
2529
|
}
|
2523
2530
|
// Assume that an assignment to a member access expression
|
2524
2531
|
// can potentially generate an exception.
|
2525
|
-
if (node.nodeType === 35 /* MemberAccess */) {
|
2532
|
+
if (node.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
2526
2533
|
this._addExceptTargets(flowNode);
|
2527
2534
|
}
|
2528
2535
|
this._currentFlowNode = flowNode;
|
@@ -2611,7 +2618,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2611
2618
|
// Is this name already bound to a scope other than the local one?
|
2612
2619
|
const bindingType = this._currentScope.getBindingType(name);
|
2613
2620
|
if (bindingType !== undefined) {
|
2614
|
-
const scopeToUse = bindingType === 0 /* Nonlocal */
|
2621
|
+
const scopeToUse = bindingType === 0 /* NameBindingType.Nonlocal */
|
2615
2622
|
? this._currentScope.parent
|
2616
2623
|
: this._currentScope.getGlobalScope().scope;
|
2617
2624
|
const symbolWithScope = scopeToUse.lookUpSymbolRecursive(name);
|
@@ -2623,15 +2630,15 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2623
2630
|
// Don't overwrite an existing symbol.
|
2624
2631
|
let symbol = scope.lookUpSymbol(name);
|
2625
2632
|
if (!symbol) {
|
2626
|
-
symbol = scope.addSymbol(name, 1 /* InitiallyUnbound */ | 4 /* ClassMember */);
|
2627
|
-
if (this._currentScope.type === 3 /* Module */ || this._currentScope.type === 4 /* Builtin */) {
|
2633
|
+
symbol = scope.addSymbol(name, 1 /* SymbolFlags.InitiallyUnbound */ | 4 /* SymbolFlags.ClassMember */);
|
2634
|
+
if (this._currentScope.type === 3 /* ScopeType.Module */ || this._currentScope.type === 4 /* ScopeType.Builtin */) {
|
2628
2635
|
if ((0, symbolNameUtils_1.isPrivateOrProtectedName)(name)) {
|
2629
2636
|
if ((0, symbolNameUtils_1.isPrivateName)(name)) {
|
2630
2637
|
// Private names are obscured, so they are always externally hidden.
|
2631
2638
|
symbol.setIsExternallyHidden();
|
2632
2639
|
}
|
2633
2640
|
else if (this._fileInfo.isStubFile || this._fileInfo.isInPyTypedPackage) {
|
2634
|
-
if (this._currentScope.type === 4 /* Builtin */) {
|
2641
|
+
if (this._currentScope.type === 4 /* ScopeType.Builtin */) {
|
2635
2642
|
// Don't include private-named symbols in the builtin scope.
|
2636
2643
|
symbol.setIsExternallyHidden();
|
2637
2644
|
}
|
@@ -2654,27 +2661,27 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2654
2661
|
}
|
2655
2662
|
_bindPossibleTupleNamedTarget(target, addedSymbols) {
|
2656
2663
|
switch (target.nodeType) {
|
2657
|
-
case 38 /* Name */: {
|
2664
|
+
case 38 /* ParseNodeType.Name */: {
|
2658
2665
|
this._bindNameToScope(this._currentScope, target, addedSymbols);
|
2659
2666
|
break;
|
2660
2667
|
}
|
2661
|
-
case 52 /* Tuple */: {
|
2668
|
+
case 52 /* ParseNodeType.Tuple */: {
|
2662
2669
|
target.expressions.forEach((expr) => {
|
2663
2670
|
this._bindPossibleTupleNamedTarget(expr, addedSymbols);
|
2664
2671
|
});
|
2665
2672
|
break;
|
2666
2673
|
}
|
2667
|
-
case 31 /* List */: {
|
2674
|
+
case 31 /* ParseNodeType.List */: {
|
2668
2675
|
target.entries.forEach((expr) => {
|
2669
2676
|
this._bindPossibleTupleNamedTarget(expr, addedSymbols);
|
2670
2677
|
});
|
2671
2678
|
break;
|
2672
2679
|
}
|
2673
|
-
case 54 /* TypeAnnotation */: {
|
2680
|
+
case 54 /* ParseNodeType.TypeAnnotation */: {
|
2674
2681
|
this._bindPossibleTupleNamedTarget(target.valueExpression, addedSymbols);
|
2675
2682
|
break;
|
2676
2683
|
}
|
2677
|
-
case 56 /* Unpack */: {
|
2684
|
+
case 56 /* ParseNodeType.Unpack */: {
|
2678
2685
|
this._bindPossibleTupleNamedTarget(target.expression, addedSymbols);
|
2679
2686
|
break;
|
2680
2687
|
}
|
@@ -2684,7 +2691,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2684
2691
|
const symbol = this._addSymbolToCurrentScope(nameValue, /* isInitiallyUnbound */ false);
|
2685
2692
|
if (symbol) {
|
2686
2693
|
symbol.addDeclaration({
|
2687
|
-
type: 0 /* Intrinsic */,
|
2694
|
+
type: 0 /* DeclarationType.Intrinsic */,
|
2688
2695
|
node,
|
2689
2696
|
intrinsicType: type,
|
2690
2697
|
path: this._fileInfo.filePath,
|
@@ -2699,15 +2706,15 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2699
2706
|
_addSymbolToCurrentScope(nameValue, isInitiallyUnbound) {
|
2700
2707
|
let symbol = this._currentScope.lookUpSymbol(nameValue);
|
2701
2708
|
if (!symbol) {
|
2702
|
-
let symbolFlags = 0 /* None */;
|
2709
|
+
let symbolFlags = 0 /* SymbolFlags.None */;
|
2703
2710
|
if (isInitiallyUnbound) {
|
2704
|
-
symbolFlags |= 1 /* InitiallyUnbound */;
|
2711
|
+
symbolFlags |= 1 /* SymbolFlags.InitiallyUnbound */;
|
2705
2712
|
}
|
2706
|
-
if (this._currentScope.type === 2 /* Class */) {
|
2707
|
-
symbolFlags |= 4 /* ClassMember */;
|
2713
|
+
if (this._currentScope.type === 2 /* ScopeType.Class */) {
|
2714
|
+
symbolFlags |= 4 /* SymbolFlags.ClassMember */;
|
2708
2715
|
}
|
2709
2716
|
if (this._fileInfo.isStubFile && (0, symbolNameUtils_1.isPrivateOrProtectedName)(nameValue)) {
|
2710
|
-
symbolFlags |= 2 /* ExternallyHidden */;
|
2717
|
+
symbolFlags |= 2 /* SymbolFlags.ExternallyHidden */;
|
2711
2718
|
}
|
2712
2719
|
// Add the symbol. Assume that symbols with a default type source ID
|
2713
2720
|
// are "implicit" symbols added to the scope. These are not initially unbound.
|
@@ -2720,7 +2727,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2720
2727
|
const newScope = new scope_1.Scope(scopeType, parentScope);
|
2721
2728
|
this._currentScope = newScope;
|
2722
2729
|
// If this scope is an execution scope, allocate a new reference map.
|
2723
|
-
const isExecutionScope = scopeType === 4 /* Builtin */ || scopeType === 3 /* Module */ || scopeType === 1 /* Function */;
|
2730
|
+
const isExecutionScope = scopeType === 4 /* ScopeType.Builtin */ || scopeType === 3 /* ScopeType.Module */ || scopeType === 1 /* ScopeType.Function */;
|
2724
2731
|
const prevExpressions = this._currentScopeCodeFlowExpressions;
|
2725
2732
|
if (isExecutionScope) {
|
2726
2733
|
this._currentScopeCodeFlowExpressions = new Set();
|
@@ -2732,12 +2739,12 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2732
2739
|
}
|
2733
2740
|
_addInferredTypeAssignmentForVariable(target, source, isPossibleTypeAlias = false) {
|
2734
2741
|
switch (target.nodeType) {
|
2735
|
-
case 38 /* Name */: {
|
2742
|
+
case 38 /* ParseNodeType.Name */: {
|
2736
2743
|
const name = target;
|
2737
2744
|
const symbolWithScope = this._currentScope.lookUpSymbolRecursive(name.value);
|
2738
2745
|
if (symbolWithScope && symbolWithScope.symbol) {
|
2739
2746
|
const declaration = {
|
2740
|
-
type: 1 /* Variable */,
|
2747
|
+
type: 1 /* DeclarationType.Variable */,
|
2741
2748
|
node: target,
|
2742
2749
|
isConstant: (0, symbolNameUtils_1.isConstantName)(target.value),
|
2743
2750
|
inferredTypeSource: source,
|
@@ -2753,13 +2760,13 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2753
2760
|
}
|
2754
2761
|
break;
|
2755
2762
|
}
|
2756
|
-
case 35 /* MemberAccess */: {
|
2763
|
+
case 35 /* ParseNodeType.MemberAccess */: {
|
2757
2764
|
const memberAccessInfo = this._getMemberAccessInfo(target);
|
2758
2765
|
if (memberAccessInfo) {
|
2759
2766
|
const name = target.memberName;
|
2760
2767
|
let symbol = memberAccessInfo.classScope.lookUpSymbol(name.value);
|
2761
2768
|
if (!symbol) {
|
2762
|
-
symbol = memberAccessInfo.classScope.addSymbol(name.value, 1 /* InitiallyUnbound */);
|
2769
|
+
symbol = memberAccessInfo.classScope.addSymbol(name.value, 1 /* SymbolFlags.InitiallyUnbound */);
|
2763
2770
|
const honorPrivateNaming = this._fileInfo.diagnosticRuleSet.reportPrivateUsage !== 'none';
|
2764
2771
|
if ((0, symbolNameUtils_1.isPrivateOrProtectedName)(name.value) && honorPrivateNaming) {
|
2765
2772
|
symbol.setIsPrivateMember();
|
@@ -2773,7 +2780,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2773
2780
|
if (!symbol.isClassMember() ||
|
2774
2781
|
!symbol
|
2775
2782
|
.getDeclarations()
|
2776
|
-
.some((decl) => decl.type === 5 /* Function */ && decl.isMethod)) {
|
2783
|
+
.some((decl) => decl.type === 5 /* DeclarationType.Function */ && decl.isMethod)) {
|
2777
2784
|
symbol.setIsInstanceMember();
|
2778
2785
|
}
|
2779
2786
|
}
|
@@ -2781,7 +2788,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2781
2788
|
symbol.setIsClassMember();
|
2782
2789
|
}
|
2783
2790
|
const declaration = {
|
2784
|
-
type: 1 /* Variable */,
|
2791
|
+
type: 1 /* DeclarationType.Variable */,
|
2785
2792
|
node: target.memberName,
|
2786
2793
|
isConstant: (0, symbolNameUtils_1.isConstantName)(name.value),
|
2787
2794
|
inferredTypeSource: source,
|
@@ -2796,21 +2803,21 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2796
2803
|
}
|
2797
2804
|
break;
|
2798
2805
|
}
|
2799
|
-
case 52 /* Tuple */: {
|
2806
|
+
case 52 /* ParseNodeType.Tuple */: {
|
2800
2807
|
target.expressions.forEach((expr) => {
|
2801
2808
|
this._addInferredTypeAssignmentForVariable(expr, source);
|
2802
2809
|
});
|
2803
2810
|
break;
|
2804
2811
|
}
|
2805
|
-
case 54 /* TypeAnnotation */: {
|
2812
|
+
case 54 /* ParseNodeType.TypeAnnotation */: {
|
2806
2813
|
this._addInferredTypeAssignmentForVariable(target.valueExpression, source);
|
2807
2814
|
break;
|
2808
2815
|
}
|
2809
|
-
case 56 /* Unpack */: {
|
2816
|
+
case 56 /* ParseNodeType.Unpack */: {
|
2810
2817
|
this._addInferredTypeAssignmentForVariable(target.expression, source);
|
2811
2818
|
break;
|
2812
2819
|
}
|
2813
|
-
case 31 /* List */: {
|
2820
|
+
case 31 /* ParseNodeType.List */: {
|
2814
2821
|
target.entries.forEach((entry) => {
|
2815
2822
|
this._addInferredTypeAssignmentForVariable(entry, source);
|
2816
2823
|
});
|
@@ -2826,7 +2833,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2826
2833
|
var _a, _b, _c;
|
2827
2834
|
let declarationHandled = false;
|
2828
2835
|
switch (target.nodeType) {
|
2829
|
-
case 38 /* Name */: {
|
2836
|
+
case 38 /* ParseNodeType.Name */: {
|
2830
2837
|
const name = target;
|
2831
2838
|
const symbolWithScope = this._currentScope.lookUpSymbolRecursive(name.value);
|
2832
2839
|
if (symbolWithScope && symbolWithScope.symbol) {
|
@@ -2848,10 +2855,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2848
2855
|
// body should also be considered a ClassVar.
|
2849
2856
|
if (finalInfo.isFinal) {
|
2850
2857
|
const containingClass = ParseTreeUtils.getEnclosingClassOrFunction(target);
|
2851
|
-
if (containingClass && containingClass.nodeType === 10 /* Class */) {
|
2858
|
+
if (containingClass && containingClass.nodeType === 10 /* ParseNodeType.Class */) {
|
2852
2859
|
// Make sure it's part of an assignment.
|
2853
|
-
if (((_a = target.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* Assignment */ ||
|
2854
|
-
((_c = (_b = target.parent) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 3 /* Assignment */) {
|
2860
|
+
if (((_a = target.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* ParseNodeType.Assignment */ ||
|
2861
|
+
((_c = (_b = target.parent) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 3 /* ParseNodeType.Assignment */) {
|
2855
2862
|
classVarInfo = {
|
2856
2863
|
isClassVar: true,
|
2857
2864
|
classVarTypeNode: undefined,
|
@@ -2860,7 +2867,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2860
2867
|
}
|
2861
2868
|
}
|
2862
2869
|
const declaration = {
|
2863
|
-
type: 1 /* Variable */,
|
2870
|
+
type: 1 /* DeclarationType.Variable */,
|
2864
2871
|
node: target,
|
2865
2872
|
isConstant: (0, symbolNameUtils_1.isConstantName)(name.value),
|
2866
2873
|
isFinal: finalInfo.isFinal,
|
@@ -2880,14 +2887,14 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2880
2887
|
symbolWithScope.symbol.setIsInstanceMember();
|
2881
2888
|
}
|
2882
2889
|
// Look for an 'InitVar' either by itself or wrapped in an 'Annotated'.
|
2883
|
-
if (typeAnnotation.nodeType === 24 /* Index */) {
|
2890
|
+
if (typeAnnotation.nodeType === 24 /* ParseNodeType.Index */) {
|
2884
2891
|
if (this._isDataclassesAnnotation(typeAnnotation.baseExpression, 'InitVar')) {
|
2885
2892
|
symbolWithScope.symbol.setIsInitVar();
|
2886
2893
|
}
|
2887
2894
|
else if (this._isTypingAnnotation(typeAnnotation.baseExpression, 'Annotated') &&
|
2888
2895
|
typeAnnotation.items.length > 0) {
|
2889
2896
|
const item0Expr = typeAnnotation.items[0].valueExpression;
|
2890
|
-
if (item0Expr.nodeType === 24 /* Index */ &&
|
2897
|
+
if (item0Expr.nodeType === 24 /* ParseNodeType.Index */ &&
|
2891
2898
|
this._isDataclassesAnnotation(item0Expr.baseExpression, 'InitVar')) {
|
2892
2899
|
symbolWithScope.symbol.setIsInitVar();
|
2893
2900
|
}
|
@@ -2897,7 +2904,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2897
2904
|
declarationHandled = true;
|
2898
2905
|
break;
|
2899
2906
|
}
|
2900
|
-
case 35 /* MemberAccess */: {
|
2907
|
+
case 35 /* ParseNodeType.MemberAccess */: {
|
2901
2908
|
// We need to determine whether this expression is declaring a class or
|
2902
2909
|
// instance variable. This is difficult because python doesn't provide
|
2903
2910
|
// a keyword for accessing "this". Instead, it uses naming conventions
|
@@ -2910,7 +2917,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2910
2917
|
const name = target.memberName;
|
2911
2918
|
let symbol = memberAccessInfo.classScope.lookUpSymbol(name.value);
|
2912
2919
|
if (!symbol) {
|
2913
|
-
symbol = memberAccessInfo.classScope.addSymbol(name.value, 1 /* InitiallyUnbound */);
|
2920
|
+
symbol = memberAccessInfo.classScope.addSymbol(name.value, 1 /* SymbolFlags.InitiallyUnbound */);
|
2914
2921
|
const honorPrivateNaming = this._fileInfo.diagnosticRuleSet.reportPrivateUsage !== 'none';
|
2915
2922
|
if ((0, symbolNameUtils_1.isPrivateOrProtectedName)(name.value) && honorPrivateNaming) {
|
2916
2923
|
symbol.setIsPrivateMember();
|
@@ -2924,7 +2931,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2924
2931
|
}
|
2925
2932
|
const finalInfo = this._isAnnotationFinal(typeAnnotation);
|
2926
2933
|
const declaration = {
|
2927
|
-
type: 1 /* Variable */,
|
2934
|
+
type: 1 /* DeclarationType.Variable */,
|
2928
2935
|
node: target.memberName,
|
2929
2936
|
isConstant: (0, symbolNameUtils_1.isConstantName)(name.value),
|
2930
2937
|
isDefinedByMemberAccess: true,
|
@@ -2959,17 +2966,17 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2959
2966
|
_isKnownAnnotation(typeAnnotation, name, importAliases, symbolAliases) {
|
2960
2967
|
let annotationNode = typeAnnotation;
|
2961
2968
|
// Is this a quoted annotation?
|
2962
|
-
if (annotationNode.nodeType === 48 /* StringList */ && annotationNode.typeAnnotation) {
|
2969
|
+
if (annotationNode.nodeType === 48 /* ParseNodeType.StringList */ && annotationNode.typeAnnotation) {
|
2963
2970
|
annotationNode = annotationNode.typeAnnotation;
|
2964
2971
|
}
|
2965
|
-
if (annotationNode.nodeType === 38 /* Name */) {
|
2972
|
+
if (annotationNode.nodeType === 38 /* ParseNodeType.Name */) {
|
2966
2973
|
const alias = symbolAliases.get(annotationNode.value);
|
2967
2974
|
if (alias === name) {
|
2968
2975
|
return true;
|
2969
2976
|
}
|
2970
2977
|
}
|
2971
|
-
else if (annotationNode.nodeType === 35 /* MemberAccess */) {
|
2972
|
-
if (annotationNode.leftExpression.nodeType === 38 /* Name */ &&
|
2978
|
+
else if (annotationNode.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
2979
|
+
if (annotationNode.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
2973
2980
|
annotationNode.memberName.value === name) {
|
2974
2981
|
const baseName = annotationNode.leftExpression.value;
|
2975
2982
|
return importAliases.some((alias) => alias === baseName);
|
@@ -3000,11 +3007,11 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3000
3007
|
if (this._isTypingAnnotation(typeAnnotation, 'Final')) {
|
3001
3008
|
isFinal = true;
|
3002
3009
|
}
|
3003
|
-
else if (typeAnnotation.nodeType === 24 /* Index */ && typeAnnotation.items.length === 1) {
|
3010
|
+
else if (typeAnnotation.nodeType === 24 /* ParseNodeType.Index */ && typeAnnotation.items.length === 1) {
|
3004
3011
|
// Recursively call to see if the base expression is "Final".
|
3005
3012
|
const finalInfo = this._isAnnotationFinal(typeAnnotation.baseExpression);
|
3006
3013
|
if (finalInfo.isFinal &&
|
3007
|
-
typeAnnotation.items[0].argumentCategory === 0 /* Simple */ &&
|
3014
|
+
typeAnnotation.items[0].argumentCategory === 0 /* ArgumentCategory.Simple */ &&
|
3008
3015
|
!typeAnnotation.items[0].name &&
|
3009
3016
|
!typeAnnotation.trailingComma) {
|
3010
3017
|
isFinal = true;
|
@@ -3022,10 +3029,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3022
3029
|
let classVarTypeNode;
|
3023
3030
|
while (typeAnnotation) {
|
3024
3031
|
// Is this a quoted annotation?
|
3025
|
-
if (typeAnnotation.nodeType === 48 /* StringList */ && typeAnnotation.typeAnnotation) {
|
3032
|
+
if (typeAnnotation.nodeType === 48 /* ParseNodeType.StringList */ && typeAnnotation.typeAnnotation) {
|
3026
3033
|
typeAnnotation = typeAnnotation.typeAnnotation;
|
3027
3034
|
}
|
3028
|
-
if (typeAnnotation.nodeType === 24 /* Index */ &&
|
3035
|
+
if (typeAnnotation.nodeType === 24 /* ParseNodeType.Index */ &&
|
3029
3036
|
typeAnnotation.items.length > 0 &&
|
3030
3037
|
this._isTypingAnnotation(typeAnnotation.baseExpression, 'Annotated')) {
|
3031
3038
|
typeAnnotation = typeAnnotation.items[0].valueExpression;
|
@@ -3034,11 +3041,11 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3034
3041
|
isClassVar = true;
|
3035
3042
|
break;
|
3036
3043
|
}
|
3037
|
-
else if (typeAnnotation.nodeType === 24 /* Index */ && typeAnnotation.items.length === 1) {
|
3044
|
+
else if (typeAnnotation.nodeType === 24 /* ParseNodeType.Index */ && typeAnnotation.items.length === 1) {
|
3038
3045
|
// Recursively call to see if the base expression is "ClassVar".
|
3039
3046
|
const finalInfo = this._isAnnotationClassVar(typeAnnotation.baseExpression);
|
3040
3047
|
if (finalInfo.isClassVar &&
|
3041
|
-
typeAnnotation.items[0].argumentCategory === 0 /* Simple */ &&
|
3048
|
+
typeAnnotation.items[0].argumentCategory === 0 /* ArgumentCategory.Simple */ &&
|
3042
3049
|
!typeAnnotation.items[0].name &&
|
3043
3050
|
!typeAnnotation.trailingComma) {
|
3044
3051
|
isClassVar = true;
|
@@ -3058,7 +3065,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3058
3065
|
_getMemberAccessInfo(node) {
|
3059
3066
|
// We handle only simple names on the left-hand side of the expression,
|
3060
3067
|
// not calls, nested member accesses, index expressions, etc.
|
3061
|
-
if (node.leftExpression.nodeType !== 38 /* Name */) {
|
3068
|
+
if (node.leftExpression.nodeType !== 38 /* ParseNodeType.Name */) {
|
3062
3069
|
return undefined;
|
3063
3070
|
}
|
3064
3071
|
const leftSymbolName = node.leftExpression.value;
|
@@ -3100,7 +3107,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3100
3107
|
// a decorator that tells us otherwise.
|
3101
3108
|
isInstanceMember = true;
|
3102
3109
|
for (const decorator of methodNode.decorators) {
|
3103
|
-
if (decorator.expression.nodeType === 38 /* Name */) {
|
3110
|
+
if (decorator.expression.nodeType === 38 /* ParseNodeType.Name */) {
|
3104
3111
|
const decoratorName = decorator.expression.value;
|
3105
3112
|
if (decoratorName === 'staticmethod') {
|
3106
3113
|
// A static method doesn't have a "self" or "cls" parameter.
|
@@ -3152,16 +3159,16 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3152
3159
|
return false;
|
3153
3160
|
}
|
3154
3161
|
let annotationNode;
|
3155
|
-
if (node.nodeType === 54 /* TypeAnnotation */) {
|
3162
|
+
if (node.nodeType === 54 /* ParseNodeType.TypeAnnotation */) {
|
3156
3163
|
annotationNode = node;
|
3157
3164
|
}
|
3158
3165
|
else {
|
3159
|
-
if (node.leftExpression.nodeType !== 54 /* TypeAnnotation */) {
|
3166
|
+
if (node.leftExpression.nodeType !== 54 /* ParseNodeType.TypeAnnotation */) {
|
3160
3167
|
return false;
|
3161
3168
|
}
|
3162
3169
|
annotationNode = node.leftExpression;
|
3163
3170
|
}
|
3164
|
-
if (annotationNode.valueExpression.nodeType !== 38 /* Name */) {
|
3171
|
+
if (annotationNode.valueExpression.nodeType !== 38 /* ParseNodeType.Name */) {
|
3165
3172
|
return false;
|
3166
3173
|
}
|
3167
3174
|
const assignedNameNode = annotationNode.valueExpression;
|
@@ -3195,7 +3202,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3195
3202
|
const symbol = this._bindNameToScope(this._currentScope, annotationNode.valueExpression);
|
3196
3203
|
if (symbol) {
|
3197
3204
|
symbol.addDeclaration({
|
3198
|
-
type: 7 /* SpecialBuiltInClass */,
|
3205
|
+
type: 7 /* DeclarationType.SpecialBuiltInClass */,
|
3199
3206
|
node: annotationNode,
|
3200
3207
|
path: this._fileInfo.filePath,
|
3201
3208
|
range: (0, positionUtils_1.convertTextRangeToRange)(annotationNode, this._fileInfo.lines),
|
@@ -3233,7 +3240,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3233
3240
|
this._addError(localize_1.Localizer.Diagnostic.yieldOutsideFunction(), node);
|
3234
3241
|
}
|
3235
3242
|
}
|
3236
|
-
else if (functionNode.isAsync && node.nodeType === 61 /* YieldFrom */) {
|
3243
|
+
else if (functionNode.isAsync && node.nodeType === 61 /* ParseNodeType.YieldFrom */) {
|
3237
3244
|
// PEP 525 indicates that 'yield from' is not allowed in an
|
3238
3245
|
// async function.
|
3239
3246
|
this._addError(localize_1.Localizer.Diagnostic.yieldFromOutsideAsync(), node);
|
@@ -3337,7 +3344,7 @@ class DummyScopeGenerator extends parseTreeWalker_1.ParseTreeWalker {
|
|
3337
3344
|
this._currentScope = currentScope;
|
3338
3345
|
}
|
3339
3346
|
visitClass(node) {
|
3340
|
-
const newScope = this._createNewScope(2 /* Class */, () => {
|
3347
|
+
const newScope = this._createNewScope(2 /* ScopeType.Class */, () => {
|
3341
3348
|
this.walk(node.suite);
|
3342
3349
|
});
|
3343
3350
|
if (!AnalyzerNodeInfo.getScope(node)) {
|
@@ -3346,7 +3353,7 @@ class DummyScopeGenerator extends parseTreeWalker_1.ParseTreeWalker {
|
|
3346
3353
|
return false;
|
3347
3354
|
}
|
3348
3355
|
visitFunction(node) {
|
3349
|
-
const newScope = this._createNewScope(1 /* Function */, () => {
|
3356
|
+
const newScope = this._createNewScope(1 /* ScopeType.Function */, () => {
|
3350
3357
|
this.walk(node.suite);
|
3351
3358
|
});
|
3352
3359
|
if (!AnalyzerNodeInfo.getScope(node)) {
|