@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/checker.js
CHANGED
@@ -14,7 +14,11 @@
|
|
14
14
|
*/
|
15
15
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
16
16
|
if (k2 === undefined) k2 = k;
|
17
|
-
Object.
|
17
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
18
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
19
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
20
|
+
}
|
21
|
+
Object.defineProperty(o, k2, desc);
|
18
22
|
}) : (function(o, m, k, k2) {
|
19
23
|
if (k2 === undefined) k2 = k;
|
20
24
|
o[k2] = m[k];
|
@@ -216,14 +220,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
216
220
|
// Report any unknown or missing parameter types.
|
217
221
|
node.parameters.forEach((param, index) => {
|
218
222
|
if (param.name) {
|
219
|
-
if (param.category === 0 /* Simple */ && index >= paramDetails.positionOnlyParamCount) {
|
223
|
+
if (param.category === 0 /* ParameterCategory.Simple */ && index >= paramDetails.positionOnlyParamCount) {
|
220
224
|
keywordNames.add(param.name.value);
|
221
225
|
}
|
222
226
|
// Determine whether this is a P.args parameter.
|
223
|
-
if (param.category === 1 /* ArgsList */) {
|
227
|
+
if (param.category === 1 /* ParameterCategory.ArgsList */) {
|
224
228
|
const annotationExpr = param.typeAnnotation || param.typeAnnotationComment;
|
225
229
|
if (annotationExpr &&
|
226
|
-
annotationExpr.nodeType === 35 /* MemberAccess */ &&
|
230
|
+
annotationExpr.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
227
231
|
annotationExpr.memberName.value === 'args') {
|
228
232
|
const baseType = this._evaluator.getType(annotationExpr.leftExpression);
|
229
233
|
if (baseType && (0, types_1.isTypeVar)(baseType) && baseType.details.isParamSpec) {
|
@@ -231,11 +235,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
231
235
|
}
|
232
236
|
}
|
233
237
|
}
|
234
|
-
else if (param.category === 2 /* KwargsDict */) {
|
238
|
+
else if (param.category === 2 /* ParameterCategory.KwargsDict */) {
|
235
239
|
sawParamSpecArgs = false;
|
236
240
|
}
|
237
241
|
}
|
238
|
-
if (param.name && param.category === 0 /* Simple */ && sawParamSpecArgs) {
|
242
|
+
if (param.name && param.category === 0 /* ParameterCategory.Simple */ && sawParamSpecArgs) {
|
239
243
|
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.namedParamAfterParamSpecArgs().format({ name: param.name.value }), param.name);
|
240
244
|
}
|
241
245
|
// Allow unknown and missing param types if the param is named '_'.
|
@@ -297,7 +301,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
297
301
|
// Check for invalid use of ParamSpec P.args and P.kwargs.
|
298
302
|
const paramSpecParams = functionTypeResult.functionType.details.parameters.filter((param) => {
|
299
303
|
if (param.typeAnnotation && (0, types_1.isTypeVar)(param.type) && (0, types_1.isParamSpec)(param.type)) {
|
300
|
-
if (param.category !== 0 /* Simple */ && param.name && param.type.paramSpecAccess) {
|
304
|
+
if (param.category !== 0 /* ParameterCategory.Simple */ && param.name && param.type.paramSpecAccess) {
|
301
305
|
return true;
|
302
306
|
}
|
303
307
|
}
|
@@ -335,7 +339,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
335
339
|
const exemptMethods = ['__init__', '__new__'];
|
336
340
|
if (containingClassNode &&
|
337
341
|
(0, types_1.isTypeVar)(paramType) &&
|
338
|
-
paramType.details.declaredVariance === 3 /* Covariant */ &&
|
342
|
+
paramType.details.declaredVariance === 3 /* Variance.Covariant */ &&
|
339
343
|
!paramType.details.isSynthesized &&
|
340
344
|
!exemptMethods.some((name) => name === functionTypeResult.functionType.details.name)) {
|
341
345
|
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramTypeCovariant(), annotationNode);
|
@@ -381,13 +385,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
381
385
|
this._validateTypeGuardFunction(node, functionTypeResult.functionType, containingClassNode !== undefined);
|
382
386
|
this._validateFunctionTypeVarUsage(node, functionTypeResult);
|
383
387
|
this._validateGeneratorReturnType(node, functionTypeResult.functionType);
|
388
|
+
this._reportDeprecatedClassProperty(node, functionTypeResult);
|
384
389
|
}
|
385
390
|
// If we're at the module level within a stub file, report a diagnostic
|
386
391
|
// if there is a '__getattr__' function defined when in strict mode.
|
387
392
|
// This signifies an incomplete stub file that obscures type errors.
|
388
393
|
if (this._fileInfo.isStubFile && node.name.value === '__getattr__') {
|
389
394
|
const scope = (0, scopeUtils_1.getScopeForNode)(node);
|
390
|
-
if ((scope === null || scope === void 0 ? void 0 : scope.type) === 3 /* Module */) {
|
395
|
+
if ((scope === null || scope === void 0 ? void 0 : scope.type) === 3 /* ScopeType.Module */) {
|
391
396
|
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportIncompleteStub, diagnosticRules_1.DiagnosticRule.reportIncompleteStub, localize_1.Localizer.Diagnostic.stubUsesGetAttr(), node.name);
|
392
397
|
}
|
393
398
|
}
|
@@ -408,6 +413,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
408
413
|
}
|
409
414
|
}
|
410
415
|
}
|
416
|
+
this._validateOverloadAttributeConsistency(node, functionTypeResult.decoratedType);
|
411
417
|
}
|
412
418
|
return false;
|
413
419
|
}
|
@@ -449,8 +455,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
449
455
|
this._validateStandardCollectionInstantiation(node);
|
450
456
|
if (this._fileInfo.diagnosticRuleSet.reportUnusedCallResult !== 'none' ||
|
451
457
|
this._fileInfo.diagnosticRuleSet.reportUnusedCoroutine !== 'none') {
|
452
|
-
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 47 /* StatementList */) {
|
453
|
-
const isRevealTypeCall = node.leftExpression.nodeType === 38 /* Name */ && node.leftExpression.value === 'reveal_type';
|
458
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 47 /* ParseNodeType.StatementList */) {
|
459
|
+
const isRevealTypeCall = node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ && node.leftExpression.value === 'reveal_type';
|
454
460
|
const returnType = this._evaluator.getType(node);
|
455
461
|
if (!isRevealTypeCall && returnType && this._isTypeValidForUnusedValueTest(returnType)) {
|
456
462
|
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnusedCallResult, diagnosticRules_1.DiagnosticRule.reportUnusedCallResult, localize_1.Localizer.Diagnostic.unusedCallResult().format({
|
@@ -467,8 +473,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
467
473
|
visitAwait(node) {
|
468
474
|
var _a;
|
469
475
|
if (this._fileInfo.diagnosticRuleSet.reportUnusedCallResult !== 'none') {
|
470
|
-
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 47 /* StatementList */ &&
|
471
|
-
node.expression.nodeType === 9 /* Call */) {
|
476
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 47 /* ParseNodeType.StatementList */ &&
|
477
|
+
node.expression.nodeType === 9 /* ParseNodeType.Call */) {
|
472
478
|
const returnType = this._evaluator.getType(node);
|
473
479
|
if (returnType && this._isTypeValidForUnusedValueTest(returnType)) {
|
474
480
|
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnusedCallResult, diagnosticRules_1.DiagnosticRule.reportUnusedCallResult, localize_1.Localizer.Diagnostic.unusedCallResult().format({
|
@@ -527,7 +533,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
527
533
|
return true;
|
528
534
|
}
|
529
535
|
visitReturn(node) {
|
530
|
-
var _a, _b;
|
536
|
+
var _a, _b, _c, _d, _e;
|
531
537
|
let returnTypeResult;
|
532
538
|
const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(node);
|
533
539
|
const declaredReturnType = enclosingFunctionNode
|
@@ -545,7 +551,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
545
551
|
// at runtime in this case.
|
546
552
|
if ((enclosingFunctionNode === null || enclosingFunctionNode === void 0 ? void 0 : enclosingFunctionNode.isAsync) && node.returnExpression) {
|
547
553
|
const functionDecl = AnalyzerNodeInfo.getDeclaration(enclosingFunctionNode);
|
548
|
-
if ((functionDecl === null || functionDecl === void 0 ? void 0 : functionDecl.type) === 5 /* Function */ && functionDecl.isGenerator) {
|
554
|
+
if ((functionDecl === null || functionDecl === void 0 ? void 0 : functionDecl.type) === 5 /* DeclarationType.Function */ && functionDecl.isGenerator) {
|
549
555
|
this._evaluator.addError(localize_1.Localizer.Diagnostic.returnInAsyncGenerator(), node.returnExpression);
|
550
556
|
}
|
551
557
|
}
|
@@ -558,7 +564,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
558
564
|
let diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
559
565
|
let returnTypeMatches = false;
|
560
566
|
if (this._evaluator.assignType(declaredReturnType, returnTypeResult.type, diagAddendum, new typeVarContext_1.TypeVarContext(),
|
561
|
-
/* srcTypeVarContext */ undefined, 64 /* AllowBoolTypeGuard */)) {
|
567
|
+
/* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.AllowBoolTypeGuard */)) {
|
562
568
|
returnTypeMatches = true;
|
563
569
|
}
|
564
570
|
else {
|
@@ -581,7 +587,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
581
587
|
const adjustedReturnType = (0, typeUtils_1.applySolvedTypeVars)(declaredReturnType, typeVarContext);
|
582
588
|
if (this._evaluator.assignType(adjustedReturnType, returnTypeResult.type, diagAddendum,
|
583
589
|
/* destTypeVarContext */ undefined,
|
584
|
-
/* srcTypeVarContext */ undefined, 64 /* AllowBoolTypeGuard */)) {
|
590
|
+
/* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.AllowBoolTypeGuard */)) {
|
585
591
|
returnTypeMatches = true;
|
586
592
|
}
|
587
593
|
}
|
@@ -596,17 +602,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
596
602
|
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.returnTypeMismatch().format({
|
597
603
|
exprType: this._evaluator.printType(returnTypeResult.type),
|
598
604
|
returnType: this._evaluator.printType(declaredReturnType),
|
599
|
-
}) + diagAddendum.getString(), node.returnExpression ?
|
605
|
+
}) + diagAddendum.getString(), (_b = node.returnExpression) !== null && _b !== void 0 ? _b : node, (_c = returnTypeResult.expectedTypeDiagAddendum) === null || _c === void 0 ? void 0 : _c.getEffectiveTextRange());
|
600
606
|
}
|
601
607
|
}
|
602
608
|
}
|
603
609
|
if ((0, types_1.isUnknown)(returnTypeResult.type)) {
|
604
|
-
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, localize_1.Localizer.Diagnostic.returnTypeUnknown(), node.returnExpression);
|
610
|
+
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, localize_1.Localizer.Diagnostic.returnTypeUnknown(), (_d = node.returnExpression) !== null && _d !== void 0 ? _d : node);
|
605
611
|
}
|
606
612
|
else if ((0, typeUtils_1.isPartlyUnknown)(returnTypeResult.type)) {
|
607
613
|
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, localize_1.Localizer.Diagnostic.returnTypePartiallyUnknown().format({
|
608
614
|
returnType: this._evaluator.printType(returnTypeResult.type, { expandTypeAlias: true }),
|
609
|
-
}), node.returnExpression);
|
615
|
+
}), (_e = node.returnExpression) !== null && _e !== void 0 ? _e : node);
|
610
616
|
}
|
611
617
|
}
|
612
618
|
return true;
|
@@ -719,14 +725,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
719
725
|
}
|
720
726
|
}
|
721
727
|
// If this isn't a class or global scope, explicit type aliases are not allowed.
|
722
|
-
if (node.leftExpression.nodeType === 54 /* TypeAnnotation */) {
|
728
|
+
if (node.leftExpression.nodeType === 54 /* ParseNodeType.TypeAnnotation */) {
|
723
729
|
const annotationType = this._evaluator.getTypeOfAnnotation(node.leftExpression.typeAnnotation);
|
724
730
|
if ((0, types_1.isClassInstance)(annotationType) && types_1.ClassType.isBuiltIn(annotationType, 'TypeAlias')) {
|
725
731
|
const scope = (0, scopeUtils_1.getScopeForNode)(node);
|
726
732
|
if (scope) {
|
727
|
-
if (scope.type !== 2 /* Class */ &&
|
728
|
-
scope.type !== 3 /* Module */ &&
|
729
|
-
scope.type !== 4 /* Builtin */) {
|
733
|
+
if (scope.type !== 2 /* ScopeType.Class */ &&
|
734
|
+
scope.type !== 3 /* ScopeType.Module */ &&
|
735
|
+
scope.type !== 4 /* ScopeType.Builtin */) {
|
730
736
|
this._evaluator.addError(localize_1.Localizer.Diagnostic.typeAliasNotInModuleOrClass(), node.leftExpression.typeAnnotation);
|
731
737
|
}
|
732
738
|
}
|
@@ -756,7 +762,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
756
762
|
const tupleLength = subtype.tupleTypeArguments.length;
|
757
763
|
if (node.items.length === 1 &&
|
758
764
|
!node.trailingComma &&
|
759
|
-
node.items[0].argumentCategory === 0 /* Simple */ &&
|
765
|
+
node.items[0].argumentCategory === 0 /* ArgumentCategory.Simple */ &&
|
760
766
|
!node.items[0].name) {
|
761
767
|
const subscriptType = this._evaluator.getType(node.items[0].valueExpression);
|
762
768
|
if (subscriptType &&
|
@@ -779,23 +785,23 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
779
785
|
return true;
|
780
786
|
}
|
781
787
|
visitBinaryOperation(node) {
|
782
|
-
if (node.operator === 36 /* And */ || node.operator === 37 /* Or */) {
|
788
|
+
if (node.operator === 36 /* OperatorType.And */ || node.operator === 37 /* OperatorType.Or */) {
|
783
789
|
this._validateConditionalIsBool(node.leftExpression);
|
784
790
|
this._validateConditionalIsBool(node.rightExpression);
|
785
791
|
}
|
786
|
-
if (node.operator === 12 /* Equals */ || node.operator === 28 /* NotEquals */) {
|
792
|
+
if (node.operator === 12 /* OperatorType.Equals */ || node.operator === 28 /* OperatorType.NotEquals */) {
|
787
793
|
// Don't apply this rule if it's within an assert.
|
788
794
|
if (!ParseTreeUtils.isWithinAssertExpression(node)) {
|
789
795
|
this._validateComparisonTypes(node);
|
790
796
|
}
|
791
797
|
}
|
792
|
-
else if (node.operator === 39 /* Is */ || node.operator === 40 /* IsNot */) {
|
798
|
+
else if (node.operator === 39 /* OperatorType.Is */ || node.operator === 40 /* OperatorType.IsNot */) {
|
793
799
|
// Don't apply this rule if it's within an assert.
|
794
800
|
if (!ParseTreeUtils.isWithinAssertExpression(node)) {
|
795
801
|
this._validateComparisonTypesForIsOperator(node);
|
796
802
|
}
|
797
803
|
}
|
798
|
-
else if (node.operator === 41 /* In */ || node.operator === 42 /* NotIn */) {
|
804
|
+
else if (node.operator === 41 /* OperatorType.In */ || node.operator === 42 /* OperatorType.NotIn */) {
|
799
805
|
// Don't apply this rule if it's within an assert.
|
800
806
|
if (!ParseTreeUtils.isWithinAssertExpression(node)) {
|
801
807
|
this._validateContainmentTypes(node);
|
@@ -817,7 +823,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
817
823
|
return true;
|
818
824
|
}
|
819
825
|
visitUnaryOperation(node) {
|
820
|
-
if (node.operator === 38 /* Not */) {
|
826
|
+
if (node.operator === 38 /* OperatorType.Not */) {
|
821
827
|
this._validateConditionalIsBool(node.expression);
|
822
828
|
}
|
823
829
|
this._evaluator.getType(node);
|
@@ -837,22 +843,22 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
837
843
|
if (this._fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_12) {
|
838
844
|
let curNode = node;
|
839
845
|
while (curNode) {
|
840
|
-
if (curNode.nodeType === 27 /* FormatString */) {
|
846
|
+
if (curNode.nodeType === 27 /* ParseNodeType.FormatString */) {
|
841
847
|
fStringContainers.push(curNode);
|
842
848
|
}
|
843
849
|
curNode = curNode.parent;
|
844
850
|
}
|
845
851
|
}
|
846
852
|
for (const stringNode of node.strings) {
|
847
|
-
const stringTokens = stringNode.nodeType === 49 /* String */ ? [stringNode.token] : stringNode.middleTokens;
|
853
|
+
const stringTokens = stringNode.nodeType === 49 /* ParseNodeType.String */ ? [stringNode.token] : stringNode.middleTokens;
|
848
854
|
stringTokens.forEach((token) => {
|
849
855
|
const unescapedResult = (0, stringTokenUtils_1.getUnescapedString)(token);
|
850
856
|
let start = token.start;
|
851
|
-
if (token.type === 5 /* String */) {
|
857
|
+
if (token.type === 5 /* TokenType.String */) {
|
852
858
|
start += token.prefixLength + token.quoteMarkLength;
|
853
859
|
}
|
854
860
|
unescapedResult.unescapeErrors.forEach((error) => {
|
855
|
-
if (error.errorType === 0 /* InvalidEscapeSequence */) {
|
861
|
+
if (error.errorType === 0 /* UnescapeErrorType.InvalidEscapeSequence */) {
|
856
862
|
this._evaluator.addDiagnosticForTextRange(this._fileInfo, this._fileInfo.diagnosticRuleSet.reportInvalidStringEscapeSequence, diagnosticRules_1.DiagnosticRule.reportInvalidStringEscapeSequence, localize_1.Localizer.Diagnostic.stringUnsupportedEscape(), { start: start + error.offset, length: error.length });
|
857
863
|
}
|
858
864
|
});
|
@@ -867,7 +873,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
867
873
|
// Prior to Python 3.12, it was not allowed to nest strings that
|
868
874
|
// used the same quote scheme within an f-string.
|
869
875
|
if (fStringContainers.length > 0) {
|
870
|
-
const quoteTypeMask = 1 /* SingleQuote */ | 2 /* DoubleQuote */ | 4 /* Triplicate */;
|
876
|
+
const quoteTypeMask = 1 /* StringTokenFlags.SingleQuote */ | 2 /* StringTokenFlags.DoubleQuote */ | 4 /* StringTokenFlags.Triplicate */;
|
871
877
|
if (fStringContainers.some((fStringContainer) => (fStringContainer.token.flags & quoteTypeMask) === (stringNode.token.flags & quoteTypeMask))) {
|
872
878
|
this._evaluator.addError(localize_1.Localizer.Diagnostic.formatStringNestedQuote(), stringNode);
|
873
879
|
}
|
@@ -966,7 +972,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
966
972
|
const importInfo = AnalyzerNodeInfo.getImportInfo(node.module);
|
967
973
|
if (importInfo &&
|
968
974
|
importInfo.isImportFound &&
|
969
|
-
importInfo.importType !== 2 /* Local */ &&
|
975
|
+
importInfo.importType !== 2 /* ImportType.Local */ &&
|
970
976
|
!this._fileInfo.isStubFile) {
|
971
977
|
this._evaluator.addDiagnosticForTextRange(this._fileInfo, this._fileInfo.diagnosticRuleSet.reportWildcardImportFromLibrary, diagnosticRules_1.DiagnosticRule.reportWildcardImportFromLibrary, localize_1.Localizer.Diagnostic.wildcardLibraryImport(), node.wildcardToken || node);
|
972
978
|
}
|
@@ -999,7 +1005,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
999
1005
|
break;
|
1000
1006
|
}
|
1001
1007
|
let isImportFromTyping = false;
|
1002
|
-
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 22 /* ImportFrom */) {
|
1008
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 22 /* ParseNodeType.ImportFrom */) {
|
1003
1009
|
if (node.parent.module.leadingDots === 0 && node.parent.module.nameParts.length === 1) {
|
1004
1010
|
if (node.parent.module.nameParts[0].value === 'typing') {
|
1005
1011
|
isImportFromTyping = true;
|
@@ -1026,6 +1032,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1026
1032
|
visitTypeParameter(node) {
|
1027
1033
|
return false;
|
1028
1034
|
}
|
1035
|
+
visitTypeAlias(node) {
|
1036
|
+
const scope = (0, scopeUtils_1.getScopeForNode)(node);
|
1037
|
+
if (scope) {
|
1038
|
+
if (scope.type !== 2 /* ScopeType.Class */ && scope.type !== 3 /* ScopeType.Module */ && scope.type !== 4 /* ScopeType.Builtin */) {
|
1039
|
+
this._evaluator.addError(localize_1.Localizer.Diagnostic.typeAliasStatementBadScope(), node.name);
|
1040
|
+
}
|
1041
|
+
}
|
1042
|
+
return true;
|
1043
|
+
}
|
1029
1044
|
visitTypeAnnotation(node) {
|
1030
1045
|
this._evaluator.getType(node.typeAnnotation);
|
1031
1046
|
return true;
|
@@ -1074,7 +1089,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1074
1089
|
_addMissingModuleSourceDiagnosticIfNeeded(importResult, node) {
|
1075
1090
|
if (importResult.isNativeLib ||
|
1076
1091
|
!importResult.isStubFile ||
|
1077
|
-
importResult.importType === 0 /* BuiltIn */ ||
|
1092
|
+
importResult.importType === 0 /* ImportType.BuiltIn */ ||
|
1078
1093
|
!importResult.nonStubImportResult ||
|
1079
1094
|
importResult.nonStubImportResult.isImportFound) {
|
1080
1095
|
return;
|
@@ -1124,15 +1139,15 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1124
1139
|
}
|
1125
1140
|
}
|
1126
1141
|
_reportUnnecessaryConditionExpression(expression) {
|
1127
|
-
if (expression.nodeType === 7 /* BinaryOperation */) {
|
1128
|
-
if (expression.operator === 36 /* And */ || expression.operator === 37 /* Or */) {
|
1142
|
+
if (expression.nodeType === 7 /* ParseNodeType.BinaryOperation */) {
|
1143
|
+
if (expression.operator === 36 /* OperatorType.And */ || expression.operator === 37 /* OperatorType.Or */) {
|
1129
1144
|
this._reportUnnecessaryConditionExpression(expression.leftExpression);
|
1130
1145
|
this._reportUnnecessaryConditionExpression(expression.rightExpression);
|
1131
1146
|
}
|
1132
1147
|
return;
|
1133
1148
|
}
|
1134
|
-
else if (expression.nodeType === 55 /* UnaryOperation */) {
|
1135
|
-
if (expression.operator === 38 /* Not */) {
|
1149
|
+
else if (expression.nodeType === 55 /* ParseNodeType.UnaryOperation */) {
|
1150
|
+
if (expression.operator === 38 /* OperatorType.Not */) {
|
1136
1151
|
this._reportUnnecessaryConditionExpression(expression.expression);
|
1137
1152
|
}
|
1138
1153
|
return;
|
@@ -1162,30 +1177,30 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1162
1177
|
return;
|
1163
1178
|
}
|
1164
1179
|
const simpleExpressionTypes = [
|
1165
|
-
55 /* UnaryOperation */,
|
1166
|
-
7 /* BinaryOperation */,
|
1167
|
-
40 /* Number */,
|
1168
|
-
11 /* Constant */,
|
1169
|
-
38 /* Name */,
|
1170
|
-
52 /* Tuple */,
|
1180
|
+
55 /* ParseNodeType.UnaryOperation */,
|
1181
|
+
7 /* ParseNodeType.BinaryOperation */,
|
1182
|
+
40 /* ParseNodeType.Number */,
|
1183
|
+
11 /* ParseNodeType.Constant */,
|
1184
|
+
38 /* ParseNodeType.Name */,
|
1185
|
+
52 /* ParseNodeType.Tuple */,
|
1171
1186
|
];
|
1172
1187
|
let reportAsUnused = false;
|
1173
1188
|
if (simpleExpressionTypes.some((nodeType) => nodeType === node.nodeType)) {
|
1174
1189
|
reportAsUnused = true;
|
1175
1190
|
}
|
1176
|
-
else if (node.nodeType === 31 /* List */ ||
|
1177
|
-
node.nodeType === 45 /* Set */ ||
|
1178
|
-
node.nodeType === 15 /* Dictionary */) {
|
1191
|
+
else if (node.nodeType === 31 /* ParseNodeType.List */ ||
|
1192
|
+
node.nodeType === 45 /* ParseNodeType.Set */ ||
|
1193
|
+
node.nodeType === 15 /* ParseNodeType.Dictionary */) {
|
1179
1194
|
// Exclude comprehensions.
|
1180
|
-
if (!node.entries.some((entry) => entry.nodeType === 32 /* ListComprehension */)) {
|
1195
|
+
if (!node.entries.some((entry) => entry.nodeType === 32 /* ParseNodeType.ListComprehension */)) {
|
1181
1196
|
reportAsUnused = true;
|
1182
1197
|
}
|
1183
1198
|
}
|
1184
1199
|
if (reportAsUnused &&
|
1185
1200
|
this._fileInfo.ipythonMode === sourceFile_1.IPythonMode.CellDocs &&
|
1186
|
-
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 47 /* StatementList */ &&
|
1201
|
+
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 47 /* ParseNodeType.StatementList */ &&
|
1187
1202
|
node.parent.statements[node.parent.statements.length - 1] === node &&
|
1188
|
-
((_b = node.parent.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 36 /* Module */ &&
|
1203
|
+
((_b = node.parent.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 36 /* ParseNodeType.Module */ &&
|
1189
1204
|
node.parent.parent.statements[node.parent.parent.statements.length - 1] === node.parent) {
|
1190
1205
|
// Exclude an expression at the end of a notebook cell, as that is treated as
|
1191
1206
|
// the cell's value.
|
@@ -1262,7 +1277,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1262
1277
|
const narrowedType = (0, typeGuards_1.narrowTypeForContainerElementType)(this._evaluator, leftType, this._evaluator.makeTopLevelTypeVarsConcrete(elementType));
|
1263
1278
|
if ((0, types_1.isNever)(narrowedType)) {
|
1264
1279
|
const getMessage = () => {
|
1265
|
-
return node.operator === 41 /* In */
|
1280
|
+
return node.operator === 41 /* OperatorType.In */
|
1266
1281
|
? localize_1.Localizer.Diagnostic.containmentAlwaysFalse()
|
1267
1282
|
: localize_1.Localizer.Diagnostic.containmentAlwaysTrue();
|
1268
1283
|
};
|
@@ -1291,7 +1306,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1291
1306
|
}
|
1292
1307
|
});
|
1293
1308
|
const getMessage = () => {
|
1294
|
-
return node.operator === 39 /* Is */
|
1309
|
+
return node.operator === 39 /* OperatorType.Is */
|
1295
1310
|
? localize_1.Localizer.Diagnostic.comparisonAlwaysFalse()
|
1296
1311
|
: localize_1.Localizer.Diagnostic.comparisonAlwaysTrue();
|
1297
1312
|
};
|
@@ -1307,7 +1322,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1307
1322
|
_validateComparisonTypes(node) {
|
1308
1323
|
let rightExpression = node.rightExpression;
|
1309
1324
|
// Check for chained comparisons.
|
1310
|
-
if (rightExpression.nodeType === 7 /* BinaryOperation */ &&
|
1325
|
+
if (rightExpression.nodeType === 7 /* ParseNodeType.BinaryOperation */ &&
|
1311
1326
|
!rightExpression.parenthesized &&
|
1312
1327
|
ParseTreeUtils.operatorSupportsChaining(rightExpression.operator)) {
|
1313
1328
|
// Use the left side of the right expression for comparison purposes.
|
@@ -1322,7 +1337,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1322
1337
|
return;
|
1323
1338
|
}
|
1324
1339
|
const getMessage = () => {
|
1325
|
-
return node.operator === 12 /* Equals */
|
1340
|
+
return node.operator === 12 /* OperatorType.Equals */
|
1326
1341
|
? localize_1.Localizer.Diagnostic.comparisonAlwaysFalse()
|
1327
1342
|
: localize_1.Localizer.Diagnostic.comparisonAlwaysTrue();
|
1328
1343
|
};
|
@@ -1408,7 +1423,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1408
1423
|
// Does the class have an operator overload for eq?
|
1409
1424
|
const metaclass = leftType.details.effectiveMetaclass;
|
1410
1425
|
if (metaclass && (0, types_1.isClass)(metaclass)) {
|
1411
|
-
if ((0, typeUtils_1.lookUpClassMember)(metaclass, '__eq__', 4 /* SkipObjectBaseClass */)) {
|
1426
|
+
if ((0, typeUtils_1.lookUpClassMember)(metaclass, '__eq__', 4 /* MemberAccessFlags.SkipObjectBaseClass */)) {
|
1412
1427
|
return true;
|
1413
1428
|
}
|
1414
1429
|
}
|
@@ -1433,7 +1448,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1433
1448
|
}
|
1434
1449
|
}
|
1435
1450
|
// Does the class have an operator overload for eq?
|
1436
|
-
const eqMethod = (0, typeUtils_1.lookUpClassMember)(types_1.ClassType.cloneAsInstantiable(leftType), '__eq__', 4 /* SkipObjectBaseClass */);
|
1451
|
+
const eqMethod = (0, typeUtils_1.lookUpClassMember)(types_1.ClassType.cloneAsInstantiable(leftType), '__eq__', 4 /* MemberAccessFlags.SkipObjectBaseClass */);
|
1437
1452
|
if (eqMethod) {
|
1438
1453
|
// If this is a synthesized method for a dataclass, we can assume
|
1439
1454
|
// that other dataclass types will not be comparable.
|
@@ -1509,7 +1524,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1509
1524
|
let constructorClass;
|
1510
1525
|
if (types_1.FunctionType.isInstanceMethod(type) && node.name.value === '__init__') {
|
1511
1526
|
const containingClassNode = ParseTreeUtils.getEnclosingClassOrFunction(node);
|
1512
|
-
if (containingClassNode && containingClassNode.nodeType === 10 /* Class */) {
|
1527
|
+
if (containingClassNode && containingClassNode.nodeType === 10 /* ParseNodeType.Class */) {
|
1513
1528
|
const classType = this._evaluator.getTypeOfClass(containingClassNode);
|
1514
1529
|
if (classType && (0, types_1.isClass)(classType.classType)) {
|
1515
1530
|
constructorClass = classType.classType;
|
@@ -1523,14 +1538,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1523
1538
|
if (nameType && (0, types_1.isTypeVar)(nameType) && !nameType.details.isSynthesizedSelf) {
|
1524
1539
|
// Does this name refer to a TypeVar that is scoped to this function?
|
1525
1540
|
if (nameType.scopeId === ParseTreeUtils.getScopeIdForNode(node)) {
|
1526
|
-
// We exempt constrained TypeVars,
|
1541
|
+
// We exempt constrained TypeVars, TypeVars that are type arguments of
|
1527
1542
|
// other types, and ParamSpecs. There are legitimate uses for singleton
|
1528
1543
|
// instances in these particular cases.
|
1529
1544
|
let isExempt = nameType.details.constraints.length > 0 ||
|
1530
1545
|
!!nameType.details.defaultType ||
|
1531
|
-
(exemptBoundTypeVar &&
|
1532
|
-
nameType.details.boundType !== undefined &&
|
1533
|
-
subscriptIndex !== undefined) ||
|
1546
|
+
(exemptBoundTypeVar && subscriptIndex !== undefined) ||
|
1534
1547
|
(0, types_1.isParamSpec)(nameType);
|
1535
1548
|
if (!isExempt && baseExpression && subscriptIndex !== undefined) {
|
1536
1549
|
// Is this a type argument for a generic type alias? If so,
|
@@ -1544,10 +1557,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1544
1557
|
}
|
1545
1558
|
}
|
1546
1559
|
const existingEntry = localTypeVarUsage.get(nameType.details.name);
|
1547
|
-
const isParamTypeWithEllipsisUsage = ((_a = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.defaultValue) === null || _a === void 0 ? void 0 : _a.nodeType) === 18 /* Ellipsis */;
|
1560
|
+
const isParamTypeWithEllipsisUsage = ((_a = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.defaultValue) === null || _a === void 0 ? void 0 : _a.nodeType) === 18 /* ParseNodeType.Ellipsis */;
|
1548
1561
|
if (!existingEntry) {
|
1549
1562
|
localTypeVarUsage.set(nameType.details.name, {
|
1550
1563
|
nodes: [nameNode],
|
1564
|
+
typeVar: nameType,
|
1551
1565
|
paramTypeUsageCount: curParamNode !== undefined ? 1 : 0,
|
1552
1566
|
paramTypeWithEllipsisUsageCount: isParamTypeWithEllipsisUsage ? 1 : 0,
|
1553
1567
|
returnTypeUsageCount: curParamNode === undefined ? 1 : 0,
|
@@ -1575,10 +1589,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1575
1589
|
// this constructor method?
|
1576
1590
|
if (constructorClass && nameType.scopeId === constructorClass.details.typeVarScopeId) {
|
1577
1591
|
const existingEntry = classTypeVarUsage.get(nameType.details.name);
|
1578
|
-
const isParamTypeWithEllipsisUsage = ((_d = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.defaultValue) === null || _d === void 0 ? void 0 : _d.nodeType) === 18 /* Ellipsis */;
|
1592
|
+
const isParamTypeWithEllipsisUsage = ((_d = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.defaultValue) === null || _d === void 0 ? void 0 : _d.nodeType) === 18 /* ParseNodeType.Ellipsis */;
|
1579
1593
|
const isExempt = !!nameType.details.defaultType;
|
1580
1594
|
if (!existingEntry) {
|
1581
1595
|
classTypeVarUsage.set(nameType.details.name, {
|
1596
|
+
typeVar: nameType,
|
1582
1597
|
nodes: [nameNode],
|
1583
1598
|
paramTypeUsageCount: curParamNode !== undefined ? 1 : 0,
|
1584
1599
|
paramTypeWithEllipsisUsageCount: isParamTypeWithEllipsisUsage ? 1 : 0,
|
@@ -1622,9 +1637,23 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1622
1637
|
var _a;
|
1623
1638
|
// Report error for local type variable that appears only once.
|
1624
1639
|
if (usage.nodes.length === 1 && !usage.isExempt) {
|
1640
|
+
let altTypeText;
|
1641
|
+
if (usage.typeVar.details.isVariadic) {
|
1642
|
+
altTypeText = '"tuple[object, ...]"';
|
1643
|
+
}
|
1644
|
+
else if (usage.typeVar.details.boundType) {
|
1645
|
+
altTypeText = `"${this._evaluator.printType((0, typeUtils_1.convertToInstance)(usage.typeVar.details.boundType))}"`;
|
1646
|
+
}
|
1647
|
+
else {
|
1648
|
+
altTypeText = '"object"';
|
1649
|
+
}
|
1650
|
+
const diag = new diagnostic_1.DiagnosticAddendum();
|
1651
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeVarUnnecessarySuggestion().format({
|
1652
|
+
type: altTypeText,
|
1653
|
+
}));
|
1625
1654
|
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportInvalidTypeVarUse, diagnosticRules_1.DiagnosticRule.reportInvalidTypeVarUse, localize_1.Localizer.Diagnostic.typeVarUsedOnlyOnce().format({
|
1626
1655
|
name: usage.nodes[0].value,
|
1627
|
-
}), usage.nodes[0]);
|
1656
|
+
}) + diag.getString(), usage.nodes[0]);
|
1628
1657
|
}
|
1629
1658
|
// Report error for local type variable that appears in return type
|
1630
1659
|
// (but not as a top-level TypeVar within a union) and appears only
|
@@ -1673,6 +1702,31 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1673
1702
|
}
|
1674
1703
|
});
|
1675
1704
|
}
|
1705
|
+
// Validates that overloads use @staticmethod and @classmethod consistently.
|
1706
|
+
_validateOverloadAttributeConsistency(node, functionType) {
|
1707
|
+
var _a, _b, _c, _d, _e, _f;
|
1708
|
+
let staticMethodCount = 0;
|
1709
|
+
let classMethodCount = 0;
|
1710
|
+
functionType.overloads.forEach((overload) => {
|
1711
|
+
if (types_1.FunctionType.isStaticMethod(overload)) {
|
1712
|
+
staticMethodCount++;
|
1713
|
+
}
|
1714
|
+
if (types_1.FunctionType.isClassMethod(overload)) {
|
1715
|
+
classMethodCount++;
|
1716
|
+
}
|
1717
|
+
});
|
1718
|
+
if (staticMethodCount > 0 && staticMethodCount < functionType.overloads.length) {
|
1719
|
+
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.overloadStaticMethodInconsistent().format({
|
1720
|
+
name: node.name.value,
|
1721
|
+
}), (_c = (_b = (_a = functionType.overloads[0]) === null || _a === void 0 ? void 0 : _a.details.declaration) === null || _b === void 0 ? void 0 : _b.node.name) !== null && _c !== void 0 ? _c : node.name);
|
1722
|
+
}
|
1723
|
+
if (classMethodCount > 0 && classMethodCount < functionType.overloads.length) {
|
1724
|
+
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.overloadClassMethodInconsistent().format({
|
1725
|
+
name: node.name.value,
|
1726
|
+
}), (_f = (_e = (_d = functionType.overloads[0]) === null || _d === void 0 ? void 0 : _d.details.declaration) === null || _e === void 0 ? void 0 : _e.node.name) !== null && _f !== void 0 ? _f : node.name);
|
1727
|
+
}
|
1728
|
+
}
|
1729
|
+
// Validates that overloads do not overlap with inconsistent return results.
|
1676
1730
|
_validateOverloadConsistency(node, functionType, prevOverloads) {
|
1677
1731
|
for (let i = 0; i < prevOverloads.length; i++) {
|
1678
1732
|
const prevOverload = prevOverloads[i];
|
@@ -1694,7 +1748,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1694
1748
|
returnType &&
|
1695
1749
|
!this._evaluator.assignType(returnType, prevReturnType,
|
1696
1750
|
/* diag */ undefined, new typeVarContext_1.TypeVarContext(),
|
1697
|
-
/* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */ | 512 /* IgnoreTypeVarScope */)) {
|
1751
|
+
/* srcTypeVarContext */ undefined, 8 /* AssignTypeFlags.SkipSolveTypeVars */ | 512 /* AssignTypeFlags.IgnoreTypeVarScope */)) {
|
1698
1752
|
const altNode = this._findNodeForOverload(node, prevOverload);
|
1699
1753
|
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportOverlappingOverload, diagnosticRules_1.DiagnosticRule.reportOverlappingOverload, localize_1.Localizer.Diagnostic.overloadReturnTypeMismatch().format({
|
1700
1754
|
name: node.name.value,
|
@@ -1715,7 +1769,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1715
1769
|
return undefined;
|
1716
1770
|
}
|
1717
1771
|
for (const decl of decls) {
|
1718
|
-
if (decl.type === 5 /* Function */) {
|
1772
|
+
if (decl.type === 5 /* DeclarationType.Function */) {
|
1719
1773
|
const functionType = this._evaluator.getTypeOfFunction(decl.node);
|
1720
1774
|
if ((functionType === null || functionType === void 0 ? void 0 : functionType.functionType) === overloadType) {
|
1721
1775
|
return decl.node;
|
@@ -1735,22 +1789,22 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1735
1789
|
}
|
1736
1790
|
return this._evaluator.assignType(functionType, prevOverload,
|
1737
1791
|
/* diag */ undefined, new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(functionType)),
|
1738
|
-
/* srcTypeVarContext */ undefined, 32 /* SkipFunctionReturnTypeCheck */ | 16 /* OverloadOverlapCheck */);
|
1792
|
+
/* srcTypeVarContext */ undefined, 32 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */ | 16 /* AssignTypeFlags.OverloadOverlapCheck */);
|
1739
1793
|
}
|
1740
1794
|
_isLegalOverloadImplementation(overload, implementation, diag) {
|
1741
1795
|
var _a;
|
1742
1796
|
const implTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(implementation));
|
1743
1797
|
const overloadTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overload));
|
1744
1798
|
// First check the parameters to see if they are assignable.
|
1745
|
-
let isLegal = this._evaluator.assignType(overload, implementation, diag, overloadTypeVarContext, implTypeVarContext, 32 /* SkipFunctionReturnTypeCheck */ |
|
1746
|
-
2 /* ReverseTypeVarMatching */ |
|
1747
|
-
256 /* SkipSelfClsTypeCheck */);
|
1799
|
+
let isLegal = this._evaluator.assignType(overload, implementation, diag, overloadTypeVarContext, implTypeVarContext, 32 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */ |
|
1800
|
+
2 /* AssignTypeFlags.ReverseTypeVarMatching */ |
|
1801
|
+
256 /* AssignTypeFlags.SkipSelfClsTypeCheck */);
|
1748
1802
|
// Now check the return types.
|
1749
1803
|
const overloadReturnType = (_a = overload.details.declaredReturnType) !== null && _a !== void 0 ? _a : this._evaluator.getFunctionInferredReturnType(overload);
|
1750
1804
|
const implementationReturnType = (0, typeUtils_1.applySolvedTypeVars)(implementation.details.declaredReturnType || this._evaluator.getFunctionInferredReturnType(implementation), implTypeVarContext);
|
1751
1805
|
const returnDiag = new diagnostic_1.DiagnosticAddendum();
|
1752
1806
|
if (!(0, types_1.isNever)(overloadReturnType) &&
|
1753
|
-
!this._evaluator.assignType(implementationReturnType, overloadReturnType, returnDiag.createAddendum(), implTypeVarContext, overloadTypeVarContext, 8 /* SkipSolveTypeVars */)) {
|
1807
|
+
!this._evaluator.assignType(implementationReturnType, overloadReturnType, returnDiag.createAddendum(), implTypeVarContext, overloadTypeVarContext, 8 /* AssignTypeFlags.SkipSolveTypeVars */)) {
|
1754
1808
|
returnDiag.addMessage(localize_1.Localizer.DiagnosticAddendum.functionReturnTypeMismatch().format({
|
1755
1809
|
sourceType: this._evaluator.printType(overloadReturnType),
|
1756
1810
|
destType: this._evaluator.printType(implementationReturnType),
|
@@ -1786,72 +1840,72 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1786
1840
|
}
|
1787
1841
|
_validateStubStatement(statement) {
|
1788
1842
|
switch (statement.nodeType) {
|
1789
|
-
case 19 /* If */:
|
1790
|
-
case 28 /* Function */:
|
1791
|
-
case 10 /* Class */:
|
1792
|
-
case 0 /* Error */: {
|
1843
|
+
case 19 /* ParseNodeType.If */:
|
1844
|
+
case 28 /* ParseNodeType.Function */:
|
1845
|
+
case 10 /* ParseNodeType.Class */:
|
1846
|
+
case 0 /* ParseNodeType.Error */: {
|
1793
1847
|
// These are allowed in a stub file.
|
1794
1848
|
break;
|
1795
1849
|
}
|
1796
|
-
case 57 /* While */:
|
1797
|
-
case 26 /* For */:
|
1798
|
-
case 53 /* Try */:
|
1799
|
-
case 58 /* With */: {
|
1850
|
+
case 57 /* ParseNodeType.While */:
|
1851
|
+
case 26 /* ParseNodeType.For */:
|
1852
|
+
case 53 /* ParseNodeType.Try */:
|
1853
|
+
case 58 /* ParseNodeType.With */: {
|
1800
1854
|
// These are not allowed.
|
1801
1855
|
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportInvalidStubStatement, diagnosticRules_1.DiagnosticRule.reportInvalidStubStatement, localize_1.Localizer.Diagnostic.invalidStubStatement(), statement);
|
1802
1856
|
break;
|
1803
1857
|
}
|
1804
|
-
case 47 /* StatementList */: {
|
1858
|
+
case 47 /* ParseNodeType.StatementList */: {
|
1805
1859
|
for (const substatement of statement.statements) {
|
1806
1860
|
let isValid = true;
|
1807
1861
|
switch (substatement.nodeType) {
|
1808
|
-
case 2 /* Assert */:
|
1809
|
-
case 4 /* AssignmentExpression */:
|
1810
|
-
case 6 /* Await */:
|
1811
|
-
case 7 /* BinaryOperation */:
|
1812
|
-
case 11 /* Constant */:
|
1813
|
-
case 14 /* Del */:
|
1814
|
-
case 15 /* Dictionary */:
|
1815
|
-
case 24 /* Index */:
|
1816
|
-
case 26 /* For */:
|
1817
|
-
case 27 /* FormatString */:
|
1818
|
-
case 29 /* Global */:
|
1819
|
-
case 30 /* Lambda */:
|
1820
|
-
case 31 /* List */:
|
1821
|
-
case 35 /* MemberAccess */:
|
1822
|
-
case 38 /* Name */:
|
1823
|
-
case 39 /* Nonlocal */:
|
1824
|
-
case 40 /* Number */:
|
1825
|
-
case 43 /* Raise */:
|
1826
|
-
case 44 /* Return */:
|
1827
|
-
case 45 /* Set */:
|
1828
|
-
case 46 /* Slice */:
|
1829
|
-
case 51 /* Ternary */:
|
1830
|
-
case 52 /* Tuple */:
|
1831
|
-
case 53 /* Try */:
|
1832
|
-
case 55 /* UnaryOperation */:
|
1833
|
-
case 56 /* Unpack */:
|
1834
|
-
case 57 /* While */:
|
1835
|
-
case 58 /* With */:
|
1836
|
-
case 59 /* WithItem */:
|
1837
|
-
case 60 /* Yield */:
|
1838
|
-
case 61 /* YieldFrom */: {
|
1862
|
+
case 2 /* ParseNodeType.Assert */:
|
1863
|
+
case 4 /* ParseNodeType.AssignmentExpression */:
|
1864
|
+
case 6 /* ParseNodeType.Await */:
|
1865
|
+
case 7 /* ParseNodeType.BinaryOperation */:
|
1866
|
+
case 11 /* ParseNodeType.Constant */:
|
1867
|
+
case 14 /* ParseNodeType.Del */:
|
1868
|
+
case 15 /* ParseNodeType.Dictionary */:
|
1869
|
+
case 24 /* ParseNodeType.Index */:
|
1870
|
+
case 26 /* ParseNodeType.For */:
|
1871
|
+
case 27 /* ParseNodeType.FormatString */:
|
1872
|
+
case 29 /* ParseNodeType.Global */:
|
1873
|
+
case 30 /* ParseNodeType.Lambda */:
|
1874
|
+
case 31 /* ParseNodeType.List */:
|
1875
|
+
case 35 /* ParseNodeType.MemberAccess */:
|
1876
|
+
case 38 /* ParseNodeType.Name */:
|
1877
|
+
case 39 /* ParseNodeType.Nonlocal */:
|
1878
|
+
case 40 /* ParseNodeType.Number */:
|
1879
|
+
case 43 /* ParseNodeType.Raise */:
|
1880
|
+
case 44 /* ParseNodeType.Return */:
|
1881
|
+
case 45 /* ParseNodeType.Set */:
|
1882
|
+
case 46 /* ParseNodeType.Slice */:
|
1883
|
+
case 51 /* ParseNodeType.Ternary */:
|
1884
|
+
case 52 /* ParseNodeType.Tuple */:
|
1885
|
+
case 53 /* ParseNodeType.Try */:
|
1886
|
+
case 55 /* ParseNodeType.UnaryOperation */:
|
1887
|
+
case 56 /* ParseNodeType.Unpack */:
|
1888
|
+
case 57 /* ParseNodeType.While */:
|
1889
|
+
case 58 /* ParseNodeType.With */:
|
1890
|
+
case 59 /* ParseNodeType.WithItem */:
|
1891
|
+
case 60 /* ParseNodeType.Yield */:
|
1892
|
+
case 61 /* ParseNodeType.YieldFrom */: {
|
1839
1893
|
isValid = false;
|
1840
1894
|
break;
|
1841
1895
|
}
|
1842
|
-
case 5 /* AugmentedAssignment */: {
|
1896
|
+
case 5 /* ParseNodeType.AugmentedAssignment */: {
|
1843
1897
|
// Exempt __all__ manipulations.
|
1844
1898
|
isValid =
|
1845
|
-
substatement.operator === 1 /* AddEqual */ &&
|
1846
|
-
substatement.leftExpression.nodeType === 38 /* Name */ &&
|
1899
|
+
substatement.operator === 1 /* OperatorType.AddEqual */ &&
|
1900
|
+
substatement.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
1847
1901
|
substatement.leftExpression.value === '__all__';
|
1848
1902
|
break;
|
1849
1903
|
}
|
1850
|
-
case 9 /* Call */: {
|
1904
|
+
case 9 /* ParseNodeType.Call */: {
|
1851
1905
|
// Exempt __all__ manipulations.
|
1852
1906
|
isValid =
|
1853
|
-
substatement.leftExpression.nodeType === 35 /* MemberAccess */ &&
|
1854
|
-
substatement.leftExpression.leftExpression.nodeType === 38 /* Name */ &&
|
1907
|
+
substatement.leftExpression.nodeType === 35 /* ParseNodeType.MemberAccess */ &&
|
1908
|
+
substatement.leftExpression.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
1855
1909
|
substatement.leftExpression.leftExpression.value === '__all__';
|
1856
1910
|
break;
|
1857
1911
|
}
|
@@ -1966,7 +2020,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1966
2020
|
const typedDecls = symbol.getTypedDeclarations();
|
1967
2021
|
if (typedDecls.length >= 1) {
|
1968
2022
|
const primaryDecl = typedDecls[0];
|
1969
|
-
if (primaryDecl.type === 5 /* Function */) {
|
2023
|
+
if (primaryDecl.type === 5 /* DeclarationType.Function */) {
|
1970
2024
|
const type = this._evaluator.getEffectiveTypeOfSymbol(symbol);
|
1971
2025
|
const overloadedFunctions = (0, types_1.isOverloadedFunction)(type)
|
1972
2026
|
? types_1.OverloadedFunctionType.getOverloads(type)
|
@@ -1990,7 +2044,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
1990
2044
|
if (!implementationFunction) {
|
1991
2045
|
let exemptMissingImplementation = false;
|
1992
2046
|
const containingClassNode = ParseTreeUtils.getEnclosingClassOrFunction(primaryDecl.node);
|
1993
|
-
if (containingClassNode && containingClassNode.nodeType === 10 /* Class */) {
|
2047
|
+
if (containingClassNode && containingClassNode.nodeType === 10 /* ParseNodeType.Class */) {
|
1994
2048
|
const classType = this._evaluator.getTypeOfClass(containingClassNode);
|
1995
2049
|
if (classType) {
|
1996
2050
|
if (types_1.ClassType.isProtocolClass(classType.classType)) {
|
@@ -2048,13 +2102,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2048
2102
|
}
|
2049
2103
|
sawFinal = true;
|
2050
2104
|
}
|
2051
|
-
if (decl.type === 1 /* Variable */ && decl.inferredTypeSource) {
|
2105
|
+
if (decl.type === 1 /* DeclarationType.Variable */ && decl.inferredTypeSource) {
|
2052
2106
|
if (sawAssignment) {
|
2053
2107
|
// We check for assignment of Final instance and class variables
|
2054
2108
|
// the type evaluator because we need to take into account whether
|
2055
2109
|
// the assignment is within an `__init__` method, so ignore class
|
2056
2110
|
// scopes here.
|
2057
|
-
if (scopeType !== 2 /* Class */) {
|
2111
|
+
if (scopeType !== 2 /* ScopeType.Class */) {
|
2058
2112
|
this._evaluator.addError(localize_1.Localizer.Diagnostic.finalReassigned().format({ name }), decl.node);
|
2059
2113
|
}
|
2060
2114
|
}
|
@@ -2063,7 +2117,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2063
2117
|
});
|
2064
2118
|
// If it's not a stub file, an assignment must be provided.
|
2065
2119
|
if (!sawAssignment && !this._fileInfo.isStubFile) {
|
2066
|
-
const firstDecl = decls.find((decl) => decl.type === 1 /* Variable */ && decl.isFinal);
|
2120
|
+
const firstDecl = decls.find((decl) => decl.type === 1 /* DeclarationType.Variable */ && decl.isFinal);
|
2067
2121
|
if (firstDecl) {
|
2068
2122
|
// Is this an instance variable declared within a dataclass? If so, it
|
2069
2123
|
// is implicitly initialized by the synthesized `__init__` method and
|
@@ -2122,10 +2176,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2122
2176
|
let otherDecls = symbol.getDeclarations().filter((decl) => decl !== primaryDecl);
|
2123
2177
|
// If it's a function, we can skip any other declarations
|
2124
2178
|
// that are overloads or property setters/deleters.
|
2125
|
-
if (primaryDecl.type === 5 /* Function */) {
|
2179
|
+
if (primaryDecl.type === 5 /* DeclarationType.Function */) {
|
2126
2180
|
const primaryDeclTypeInfo = this._evaluator.getTypeOfFunction(primaryDecl.node);
|
2127
2181
|
otherDecls = otherDecls.filter((decl) => {
|
2128
|
-
if (decl.type !== 5 /* Function */) {
|
2182
|
+
if (decl.type !== 5 /* DeclarationType.Function */) {
|
2129
2183
|
return true;
|
2130
2184
|
}
|
2131
2185
|
const funcTypeInfo = this._evaluator.getTypeOfFunction(decl.node);
|
@@ -2153,7 +2207,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2153
2207
|
return;
|
2154
2208
|
}
|
2155
2209
|
let primaryDeclInfo;
|
2156
|
-
if (primaryDecl.type === 5 /* Function */) {
|
2210
|
+
if (primaryDecl.type === 5 /* DeclarationType.Function */) {
|
2157
2211
|
if (primaryDecl.isMethod) {
|
2158
2212
|
primaryDeclInfo = localize_1.Localizer.DiagnosticAddendum.seeMethodDeclaration();
|
2159
2213
|
}
|
@@ -2161,16 +2215,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2161
2215
|
primaryDeclInfo = localize_1.Localizer.DiagnosticAddendum.seeFunctionDeclaration();
|
2162
2216
|
}
|
2163
2217
|
}
|
2164
|
-
else if (primaryDecl.type === 6 /* Class */) {
|
2218
|
+
else if (primaryDecl.type === 6 /* DeclarationType.Class */) {
|
2165
2219
|
primaryDeclInfo = localize_1.Localizer.DiagnosticAddendum.seeClassDeclaration();
|
2166
2220
|
}
|
2167
|
-
else if (primaryDecl.type === 2 /* Parameter */) {
|
2221
|
+
else if (primaryDecl.type === 2 /* DeclarationType.Parameter */) {
|
2168
2222
|
primaryDeclInfo = localize_1.Localizer.DiagnosticAddendum.seeParameterDeclaration();
|
2169
2223
|
}
|
2170
|
-
else if (primaryDecl.type === 1 /* Variable */) {
|
2224
|
+
else if (primaryDecl.type === 1 /* DeclarationType.Variable */) {
|
2171
2225
|
primaryDeclInfo = localize_1.Localizer.DiagnosticAddendum.seeVariableDeclaration();
|
2172
2226
|
}
|
2173
|
-
else if (primaryDecl.type === 4 /* TypeAlias */) {
|
2227
|
+
else if (primaryDecl.type === 4 /* DeclarationType.TypeAlias */) {
|
2174
2228
|
primaryDeclInfo = localize_1.Localizer.DiagnosticAddendum.seeTypeAliasDeclaration();
|
2175
2229
|
}
|
2176
2230
|
else {
|
@@ -2179,16 +2233,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2179
2233
|
const addPrimaryDeclInfo = (diag) => {
|
2180
2234
|
if (diag) {
|
2181
2235
|
let primaryDeclNode;
|
2182
|
-
if (primaryDecl.type === 5 /* Function */ || primaryDecl.type === 6 /* Class */) {
|
2236
|
+
if (primaryDecl.type === 5 /* DeclarationType.Function */ || primaryDecl.type === 6 /* DeclarationType.Class */) {
|
2183
2237
|
primaryDeclNode = primaryDecl.node.name;
|
2184
2238
|
}
|
2185
|
-
else if (primaryDecl.type === 1 /* Variable */) {
|
2186
|
-
if (primaryDecl.node.nodeType === 38 /* Name */) {
|
2239
|
+
else if (primaryDecl.type === 1 /* DeclarationType.Variable */) {
|
2240
|
+
if (primaryDecl.node.nodeType === 38 /* ParseNodeType.Name */) {
|
2187
2241
|
primaryDeclNode = primaryDecl.node;
|
2188
2242
|
}
|
2189
2243
|
}
|
2190
|
-
else if (primaryDecl.type === 2 /* Parameter */ ||
|
2191
|
-
primaryDecl.type === 3 /* TypeParameter */) {
|
2244
|
+
else if (primaryDecl.type === 2 /* DeclarationType.Parameter */ ||
|
2245
|
+
primaryDecl.type === 3 /* DeclarationType.TypeParameter */) {
|
2192
2246
|
if (primaryDecl.node.name) {
|
2193
2247
|
primaryDeclNode = primaryDecl.node.name;
|
2194
2248
|
}
|
@@ -2199,9 +2253,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2199
2253
|
}
|
2200
2254
|
};
|
2201
2255
|
for (const otherDecl of otherDecls) {
|
2202
|
-
if (otherDecl.type === 6 /* Class */) {
|
2256
|
+
if (otherDecl.type === 6 /* DeclarationType.Class */) {
|
2203
2257
|
let duplicateIsOk = false;
|
2204
|
-
if (primaryDecl.type === 3 /* TypeParameter */) {
|
2258
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParameter */) {
|
2205
2259
|
// The error will be reported elsewhere if a type parameter is
|
2206
2260
|
// involved, so don't report it here.
|
2207
2261
|
duplicateIsOk = true;
|
@@ -2211,7 +2265,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2211
2265
|
addPrimaryDeclInfo(diag);
|
2212
2266
|
}
|
2213
2267
|
}
|
2214
|
-
else if (otherDecl.type === 5 /* Function */) {
|
2268
|
+
else if (otherDecl.type === 5 /* DeclarationType.Function */) {
|
2215
2269
|
const primaryType = (_a = this._evaluator.getTypeForDeclaration(primaryDecl)) === null || _a === void 0 ? void 0 : _a.type;
|
2216
2270
|
let duplicateIsOk = false;
|
2217
2271
|
// If the return type has not yet been inferred, do so now.
|
@@ -2234,7 +2288,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2234
2288
|
if (!isInSameStatementList && primaryType && otherType && (0, types_1.isTypeSame)(primaryType, otherType)) {
|
2235
2289
|
duplicateIsOk = true;
|
2236
2290
|
}
|
2237
|
-
if (primaryDecl.type === 3 /* TypeParameter */) {
|
2291
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParameter */) {
|
2238
2292
|
// The error will be reported elsewhere if a type parameter is
|
2239
2293
|
// involved, so don't report it here.
|
2240
2294
|
duplicateIsOk = true;
|
@@ -2246,10 +2300,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2246
2300
|
addPrimaryDeclInfo(diag);
|
2247
2301
|
}
|
2248
2302
|
}
|
2249
|
-
else if (otherDecl.type === 2 /* Parameter */) {
|
2303
|
+
else if (otherDecl.type === 2 /* DeclarationType.Parameter */) {
|
2250
2304
|
if (otherDecl.node.name) {
|
2251
2305
|
let duplicateIsOk = false;
|
2252
|
-
if (primaryDecl.type === 3 /* TypeParameter */) {
|
2306
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParameter */) {
|
2253
2307
|
// The error will be reported elsewhere if a type parameter is
|
2254
2308
|
// involved, so don't report it here.
|
2255
2309
|
duplicateIsOk = true;
|
@@ -2261,17 +2315,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2261
2315
|
}
|
2262
2316
|
}
|
2263
2317
|
}
|
2264
|
-
else if (otherDecl.type === 1 /* Variable */) {
|
2318
|
+
else if (otherDecl.type === 1 /* DeclarationType.Variable */) {
|
2265
2319
|
const primaryType = (_c = this._evaluator.getTypeForDeclaration(primaryDecl)) === null || _c === void 0 ? void 0 : _c.type;
|
2266
2320
|
if (otherDecl.typeAnnotationNode) {
|
2267
|
-
if (otherDecl.node.nodeType === 38 /* Name */) {
|
2321
|
+
if (otherDecl.node.nodeType === 38 /* ParseNodeType.Name */) {
|
2268
2322
|
let duplicateIsOk = false;
|
2269
2323
|
// It's OK if they both have the same declared type.
|
2270
2324
|
const otherType = (_d = this._evaluator.getTypeForDeclaration(otherDecl)) === null || _d === void 0 ? void 0 : _d.type;
|
2271
2325
|
if (primaryType && otherType && (0, types_1.isTypeSame)(primaryType, otherType)) {
|
2272
2326
|
duplicateIsOk = true;
|
2273
2327
|
}
|
2274
|
-
if (primaryDecl.type === 3 /* TypeParameter */) {
|
2328
|
+
if (primaryDecl.type === 3 /* DeclarationType.TypeParameter */) {
|
2275
2329
|
// The error will be reported elsewhere if a type parameter is
|
2276
2330
|
// involved, so don't report it here.
|
2277
2331
|
duplicateIsOk = true;
|
@@ -2283,7 +2337,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2283
2337
|
}
|
2284
2338
|
}
|
2285
2339
|
}
|
2286
|
-
else if (otherDecl.type === 4 /* TypeAlias */) {
|
2340
|
+
else if (otherDecl.type === 4 /* DeclarationType.TypeAlias */) {
|
2287
2341
|
const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.obscuredTypeAliasDeclaration().format({ name }), otherDecl.node.name);
|
2288
2342
|
addPrimaryDeclInfo(diag);
|
2289
2343
|
}
|
@@ -2319,10 +2373,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2319
2373
|
let message;
|
2320
2374
|
let rule;
|
2321
2375
|
switch (decl.type) {
|
2322
|
-
case 8 /* Alias */:
|
2376
|
+
case 8 /* DeclarationType.Alias */:
|
2323
2377
|
diagnosticLevel = this._fileInfo.diagnosticRuleSet.reportUnusedImport;
|
2324
2378
|
rule = diagnosticRules_1.DiagnosticRule.reportUnusedImport;
|
2325
|
-
if (decl.node.nodeType === 21 /* ImportAs */) {
|
2379
|
+
if (decl.node.nodeType === 21 /* ParseNodeType.ImportAs */) {
|
2326
2380
|
if (decl.node.alias) {
|
2327
2381
|
// For statements of the form "import x as x", don't mark "x" as unaccessed
|
2328
2382
|
// because it's assumed to be re-exported.
|
@@ -2338,13 +2392,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2338
2392
|
const multipartName = nameParts.map((np) => np.value).join('.');
|
2339
2393
|
let textRange = { start: nameParts[0].start, length: nameParts[0].length };
|
2340
2394
|
textRange = textRange_1.TextRange.extend(textRange, nameParts[nameParts.length - 1]);
|
2341
|
-
this._fileInfo.diagnosticSink.addUnusedCodeWithTextRange(localize_1.Localizer.Diagnostic.unaccessedSymbol().format({ name: multipartName }), textRange, { action: "pyright.unusedImport" /* unusedImport */ });
|
2395
|
+
this._fileInfo.diagnosticSink.addUnusedCodeWithTextRange(localize_1.Localizer.Diagnostic.unaccessedSymbol().format({ name: multipartName }), textRange, { action: "pyright.unusedImport" /* Commands.unusedImport */ });
|
2342
2396
|
this._evaluator.addDiagnosticForTextRange(this._fileInfo, this._fileInfo.diagnosticRuleSet.reportUnusedImport, diagnosticRules_1.DiagnosticRule.reportUnusedImport, localize_1.Localizer.Diagnostic.unaccessedImport().format({ name: multipartName }), textRange);
|
2343
2397
|
return;
|
2344
2398
|
}
|
2345
2399
|
}
|
2346
2400
|
}
|
2347
|
-
else if (decl.node.nodeType === 23 /* ImportFromAs */) {
|
2401
|
+
else if (decl.node.nodeType === 23 /* ParseNodeType.ImportFromAs */) {
|
2348
2402
|
const importFrom = decl.node.parent;
|
2349
2403
|
// For statements of the form "from y import x as x", don't mark "x" as
|
2350
2404
|
// unaccessed because it's assumed to be re-exported.
|
@@ -2360,9 +2414,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2360
2414
|
message = localize_1.Localizer.Diagnostic.unaccessedImport().format({ name: nameNode.value });
|
2361
2415
|
}
|
2362
2416
|
break;
|
2363
|
-
case 4 /* TypeAlias */:
|
2364
|
-
case 1 /* Variable */:
|
2365
|
-
case 2 /* Parameter */:
|
2417
|
+
case 4 /* DeclarationType.TypeAlias */:
|
2418
|
+
case 1 /* DeclarationType.Variable */:
|
2419
|
+
case 2 /* DeclarationType.Parameter */:
|
2366
2420
|
if (!isPrivate) {
|
2367
2421
|
return;
|
2368
2422
|
}
|
@@ -2372,7 +2426,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2372
2426
|
return;
|
2373
2427
|
}
|
2374
2428
|
diagnosticLevel = this._fileInfo.diagnosticRuleSet.reportUnusedVariable;
|
2375
|
-
if (decl.node.nodeType === 38 /* Name */) {
|
2429
|
+
if (decl.node.nodeType === 38 /* ParseNodeType.Name */) {
|
2376
2430
|
nameNode = decl.node;
|
2377
2431
|
// Don't emit a diagnostic if the name starts with an underscore.
|
2378
2432
|
// This indicates that the variable is unused.
|
@@ -2380,7 +2434,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2380
2434
|
diagnosticLevel = 'none';
|
2381
2435
|
}
|
2382
2436
|
}
|
2383
|
-
else if (decl.node.nodeType === 41 /* Parameter */) {
|
2437
|
+
else if (decl.node.nodeType === 41 /* ParseNodeType.Parameter */) {
|
2384
2438
|
nameNode = decl.node.name;
|
2385
2439
|
// Don't emit a diagnostic for unused parameters or type parameters.
|
2386
2440
|
diagnosticLevel = 'none';
|
@@ -2390,7 +2444,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2390
2444
|
message = localize_1.Localizer.Diagnostic.unaccessedVariable().format({ name: nameNode.value });
|
2391
2445
|
}
|
2392
2446
|
break;
|
2393
|
-
case 6 /* Class */:
|
2447
|
+
case 6 /* DeclarationType.Class */:
|
2394
2448
|
if (!isPrivate) {
|
2395
2449
|
return;
|
2396
2450
|
}
|
@@ -2404,7 +2458,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2404
2458
|
rule = diagnosticRules_1.DiagnosticRule.reportUnusedClass;
|
2405
2459
|
message = localize_1.Localizer.Diagnostic.unaccessedClass().format({ name: nameNode.value });
|
2406
2460
|
break;
|
2407
|
-
case 5 /* Function */:
|
2461
|
+
case 5 /* DeclarationType.Function */:
|
2408
2462
|
if (!isPrivate) {
|
2409
2463
|
return;
|
2410
2464
|
}
|
@@ -2418,18 +2472,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2418
2472
|
rule = diagnosticRules_1.DiagnosticRule.reportUnusedFunction;
|
2419
2473
|
message = localize_1.Localizer.Diagnostic.unaccessedFunction().format({ name: nameNode.value });
|
2420
2474
|
break;
|
2421
|
-
case 3 /* TypeParameter */:
|
2475
|
+
case 3 /* DeclarationType.TypeParameter */:
|
2422
2476
|
// Never report a diagnostic for an unused TypeParameter.
|
2423
2477
|
diagnosticLevel = 'none';
|
2424
2478
|
nameNode = decl.node.name;
|
2425
2479
|
break;
|
2426
|
-
case 0 /* Intrinsic */:
|
2427
|
-
case 7 /* SpecialBuiltInClass */:
|
2480
|
+
case 0 /* DeclarationType.Intrinsic */:
|
2481
|
+
case 7 /* DeclarationType.SpecialBuiltInClass */:
|
2428
2482
|
return;
|
2429
2483
|
default:
|
2430
2484
|
(0, debug_1.assertNever)(decl);
|
2431
2485
|
}
|
2432
|
-
const action = rule === diagnosticRules_1.DiagnosticRule.reportUnusedImport ? { action: "pyright.unusedImport" /* unusedImport */ } : undefined;
|
2486
|
+
const action = rule === diagnosticRules_1.DiagnosticRule.reportUnusedImport ? { action: "pyright.unusedImport" /* Commands.unusedImport */ } : undefined;
|
2433
2487
|
if (nameNode) {
|
2434
2488
|
this._fileInfo.diagnosticSink.addUnusedCodeWithTextRange(localize_1.Localizer.Diagnostic.unaccessedSymbol().format({ name: nameNode.value }), nameNode, action);
|
2435
2489
|
if (rule !== undefined && message) {
|
@@ -2441,7 +2495,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2441
2495
|
// common source of programming errors. Also validates that arguments passed
|
2442
2496
|
// to isinstance or issubclass won't generate exceptions.
|
2443
2497
|
_validateIsInstanceCall(node) {
|
2444
|
-
if (node.leftExpression.nodeType !== 38 /* Name */ ||
|
2498
|
+
if (node.leftExpression.nodeType !== 38 /* ParseNodeType.Name */ ||
|
2445
2499
|
(node.leftExpression.value !== 'isinstance' && node.leftExpression.value !== 'issubclass') ||
|
2446
2500
|
node.arguments.length !== 2) {
|
2447
2501
|
return;
|
@@ -2487,7 +2541,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2487
2541
|
// it's unnecessary.
|
2488
2542
|
let curNode = node;
|
2489
2543
|
while (curNode) {
|
2490
|
-
if (curNode.nodeType === 2 /* Assert */) {
|
2544
|
+
if (curNode.nodeType === 2 /* ParseNodeType.Assert */) {
|
2491
2545
|
return;
|
2492
2546
|
}
|
2493
2547
|
curNode = curNode.parent;
|
@@ -2651,11 +2705,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2651
2705
|
subtype = this._evaluator.makeTopLevelTypeVarsConcrete(subtype);
|
2652
2706
|
subtype = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(subtype);
|
2653
2707
|
switch (subtype.category) {
|
2654
|
-
case 2 /* Any */:
|
2655
|
-
case 1 /* Unknown */:
|
2656
|
-
case 0 /* Unbound */:
|
2708
|
+
case 2 /* TypeCategory.Any */:
|
2709
|
+
case 1 /* TypeCategory.Unknown */:
|
2710
|
+
case 0 /* TypeCategory.Unbound */:
|
2657
2711
|
break;
|
2658
|
-
case 6 /* Class */:
|
2712
|
+
case 6 /* TypeCategory.Class */:
|
2659
2713
|
if ((0, typeUtils_1.isNoneInstance)(subtype)) {
|
2660
2714
|
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.noneNotAllowed());
|
2661
2715
|
isSupported = false;
|
@@ -2676,13 +2730,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2676
2730
|
isSupported = false;
|
2677
2731
|
}
|
2678
2732
|
break;
|
2679
|
-
case 4 /* Function */:
|
2733
|
+
case 4 /* TypeCategory.Function */:
|
2680
2734
|
if (!types_1.TypeBase.isInstantiable(subtype) || subtype.isCallableWithTypeArgs) {
|
2681
2735
|
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.genericClassNotAllowed());
|
2682
2736
|
isSupported = false;
|
2683
2737
|
}
|
2684
2738
|
break;
|
2685
|
-
case 9 /* TypeVar */:
|
2739
|
+
case 9 /* TypeCategory.TypeVar */:
|
2686
2740
|
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeVarNotAllowed());
|
2687
2741
|
isSupported = false;
|
2688
2742
|
break;
|
@@ -2693,7 +2747,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2693
2747
|
_isSymbolPrivate(nameValue, scopeType) {
|
2694
2748
|
// All variables within the scope of a function or a list
|
2695
2749
|
// comprehension are considered private.
|
2696
|
-
if (scopeType === 1 /* Function */ || scopeType === 0 /* ListComprehension */) {
|
2750
|
+
if (scopeType === 1 /* ScopeType.Function */ || scopeType === 0 /* ScopeType.ListComprehension */) {
|
2697
2751
|
return true;
|
2698
2752
|
}
|
2699
2753
|
// See if the symbol is private.
|
@@ -2702,11 +2756,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2702
2756
|
}
|
2703
2757
|
if (SymbolNameUtils.isProtectedName(nameValue)) {
|
2704
2758
|
// Protected names outside of a class scope are considered private.
|
2705
|
-
const isClassScope = scopeType === 2 /* Class */;
|
2759
|
+
const isClassScope = scopeType === 2 /* ScopeType.Class */;
|
2706
2760
|
return !isClassScope;
|
2707
2761
|
}
|
2708
2762
|
return false;
|
2709
2763
|
}
|
2764
|
+
_reportDeprecatedClassProperty(node, functionTypeResult) {
|
2765
|
+
if (!(0, types_1.isClassInstance)(functionTypeResult.decoratedType) ||
|
2766
|
+
!types_1.ClassType.isClassProperty(functionTypeResult.decoratedType)) {
|
2767
|
+
return;
|
2768
|
+
}
|
2769
|
+
this._reportDeprecatedDiagnostic(node.name, localize_1.Localizer.Diagnostic.classPropertyDeprecated());
|
2770
|
+
}
|
2710
2771
|
_reportDeprecatedUseForMemberAccess(node, info) {
|
2711
2772
|
let errorMessage;
|
2712
2773
|
if (info.accessType === 'property') {
|
@@ -2744,7 +2805,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2744
2805
|
let deprecatedMessage;
|
2745
2806
|
function getDeprecatedMessageForFunction(functionType) {
|
2746
2807
|
if (functionType.details.declaration &&
|
2747
|
-
functionType.details.declaration.node.nodeType === 28 /* Function */) {
|
2808
|
+
functionType.details.declaration.node.nodeType === 28 /* ParseNodeType.Function */) {
|
2748
2809
|
const containingClass = ParseTreeUtils.getEnclosingClass(functionType.details.declaration.node,
|
2749
2810
|
/* stopAtFunction */ true);
|
2750
2811
|
if (containingClass) {
|
@@ -2901,7 +2962,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2901
2962
|
// Add a quick action that renames the file.
|
2902
2963
|
if (diag) {
|
2903
2964
|
const renameAction = {
|
2904
|
-
action: "renameShadowedFile" /* RenameShadowedFileAction */,
|
2965
|
+
action: "renameShadowedFile" /* ActionKind.RenameShadowedFileAction */,
|
2905
2966
|
oldFile: this._fileInfo.filePath,
|
2906
2967
|
newFile: this._sourceMapper.getNextFileName(this._fileInfo.filePath),
|
2907
2968
|
};
|
@@ -2915,8 +2976,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2915
2976
|
return;
|
2916
2977
|
}
|
2917
2978
|
// Skip this check for relative imports.
|
2918
|
-
const nodeModule = node.nodeType === 23 /* ImportFromAs */
|
2919
|
-
? ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 22 /* ImportFrom */
|
2979
|
+
const nodeModule = node.nodeType === 23 /* ParseNodeType.ImportFromAs */
|
2980
|
+
? ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 22 /* ParseNodeType.ImportFrom */
|
2920
2981
|
? (_b = node.parent) === null || _b === void 0 ? void 0 : _b.module
|
2921
2982
|
: undefined
|
2922
2983
|
: node.module;
|
@@ -2924,9 +2985,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2924
2985
|
return;
|
2925
2986
|
}
|
2926
2987
|
// Otherwise use the name to determine if a match for a stdlib module.
|
2927
|
-
const namePartNodes = node.nodeType === 21 /* ImportAs */
|
2988
|
+
const namePartNodes = node.nodeType === 21 /* ParseNodeType.ImportAs */
|
2928
2989
|
? node.module.nameParts
|
2929
|
-
: node.nodeType === 23 /* ImportFromAs */
|
2990
|
+
: node.nodeType === 23 /* ParseNodeType.ImportFromAs */
|
2930
2991
|
? [node.name]
|
2931
2992
|
: node.module.nameParts;
|
2932
2993
|
const nameParts = namePartNodes.map((n) => n.value);
|
@@ -2952,7 +3013,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2952
3013
|
// Add a quick action that renames the file.
|
2953
3014
|
if (diag) {
|
2954
3015
|
const renameAction = {
|
2955
|
-
action: "renameShadowedFile" /* RenameShadowedFileAction */,
|
3016
|
+
action: "renameShadowedFile" /* ActionKind.RenameShadowedFileAction */,
|
2956
3017
|
oldFile: p,
|
2957
3018
|
newFile: this._sourceMapper.getNextFileName(p),
|
2958
3019
|
};
|
@@ -2972,7 +3033,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2972
3033
|
return;
|
2973
3034
|
}
|
2974
3035
|
// Ignore privates in named arguments.
|
2975
|
-
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 1 /* Argument */ && node.parent.name === node) {
|
3036
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 1 /* ParseNodeType.Argument */ && node.parent.name === node) {
|
2976
3037
|
return;
|
2977
3038
|
}
|
2978
3039
|
const nameValue = node.value;
|
@@ -2988,7 +3049,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2988
3049
|
if (!primaryDeclaration || primaryDeclaration.node === node) {
|
2989
3050
|
return;
|
2990
3051
|
}
|
2991
|
-
if (primaryDeclaration.type === 8 /* Alias */) {
|
3052
|
+
if (primaryDeclaration.type === 8 /* DeclarationType.Alias */) {
|
2992
3053
|
// If this symbol is an import alias (i.e. it's a local name rather than the
|
2993
3054
|
// original imported name), skip the private check.
|
2994
3055
|
if (primaryDeclaration.usesLocalName) {
|
@@ -3084,12 +3145,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3084
3145
|
};
|
3085
3146
|
suiteNode.statements.forEach((statement) => {
|
3086
3147
|
if (!AnalyzerNodeInfo.isCodeUnreachable(statement)) {
|
3087
|
-
if (statement.nodeType === 47 /* StatementList */) {
|
3148
|
+
if (statement.nodeType === 47 /* ParseNodeType.StatementList */) {
|
3088
3149
|
for (const substatement of statement.statements) {
|
3089
|
-
if (substatement.nodeType !== 54 /* TypeAnnotation */ &&
|
3090
|
-
substatement.nodeType !== 18 /* Ellipsis */ &&
|
3091
|
-
substatement.nodeType !== 48 /* StringList */ &&
|
3092
|
-
substatement.nodeType !== 42 /* Pass */) {
|
3150
|
+
if (substatement.nodeType !== 54 /* ParseNodeType.TypeAnnotation */ &&
|
3151
|
+
substatement.nodeType !== 18 /* ParseNodeType.Ellipsis */ &&
|
3152
|
+
substatement.nodeType !== 48 /* ParseNodeType.StringList */ &&
|
3153
|
+
substatement.nodeType !== 42 /* ParseNodeType.Pass */) {
|
3093
3154
|
emitBadStatementError(substatement);
|
3094
3155
|
}
|
3095
3156
|
}
|
@@ -3207,7 +3268,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3207
3268
|
_validateReturnTypeIsNotContravariant(returnType, errorNode) {
|
3208
3269
|
let isContraTypeVar = false;
|
3209
3270
|
(0, typeUtils_1.doForEachSubtype)(returnType, (subtype) => {
|
3210
|
-
if ((0, types_1.isTypeVar)(subtype) && subtype.details.declaredVariance === 4 /* Contravariant */) {
|
3271
|
+
if ((0, types_1.isTypeVar)(subtype) && subtype.details.declaredVariance === 4 /* Variance.Contravariant */) {
|
3211
3272
|
isContraTypeVar = true;
|
3212
3273
|
}
|
3213
3274
|
});
|
@@ -3229,7 +3290,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3229
3290
|
// as Final in parent classes.
|
3230
3291
|
_validateFinalMemberOverrides(classType) {
|
3231
3292
|
classType.details.fields.forEach((localSymbol, name) => {
|
3232
|
-
const parentSymbol = (0, typeUtils_1.lookUpClassMember)(classType, name, 1 /* SkipOriginalClass */);
|
3293
|
+
const parentSymbol = (0, typeUtils_1.lookUpClassMember)(classType, name, 1 /* MemberAccessFlags.SkipOriginalClass */);
|
3233
3294
|
if (parentSymbol &&
|
3234
3295
|
(0, types_1.isInstantiableClass)(parentSymbol.classType) &&
|
3235
3296
|
this._evaluator.isFinalVariable(parentSymbol.symbol) &&
|
@@ -3252,7 +3313,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3252
3313
|
return;
|
3253
3314
|
}
|
3254
3315
|
const decls = symbol.getDeclarations();
|
3255
|
-
if (decls.length >= 2 && decls[0].type === 1 /* Variable */) {
|
3316
|
+
if (decls.length >= 2 && decls[0].type === 1 /* DeclarationType.Variable */) {
|
3256
3317
|
const symbolType = this._evaluator.getEffectiveTypeOfSymbol(symbol);
|
3257
3318
|
// Is this symbol a literal instance of the enum class?
|
3258
3319
|
if ((0, types_1.isClassInstance)(symbolType) &&
|
@@ -3263,14 +3324,21 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3263
3324
|
}
|
3264
3325
|
});
|
3265
3326
|
}
|
3266
|
-
// If a non-protocol class explicitly inherits from a protocol class
|
3267
|
-
// verifies that any class or instance
|
3268
|
-
// in the protocol class are implemented in
|
3269
|
-
//
|
3327
|
+
// If a non-protocol class explicitly inherits from a protocol class and does
|
3328
|
+
// not explicit derive from ABC, this method verifies that any class or instance
|
3329
|
+
// variables declared but not assigned in the protocol class are implemented in
|
3330
|
+
// the subclass. It also checks that any empty functions declared in the protocol
|
3331
|
+
// are implemented in the subclass.
|
3270
3332
|
_validateProtocolCompatibility(classType, errorNode) {
|
3271
3333
|
if (types_1.ClassType.isProtocolClass(classType)) {
|
3272
3334
|
return;
|
3273
3335
|
}
|
3336
|
+
// If a class derives from ABC, exempt it from this check. This is used for
|
3337
|
+
// mixins that derive from a protocol but do not directly implement all
|
3338
|
+
// of the protocol's methods.
|
3339
|
+
if (classType.details.mro.some((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isBuiltIn(mroClass, 'ABC'))) {
|
3340
|
+
return;
|
3341
|
+
}
|
3274
3342
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
3275
3343
|
const isSymbolImplemented = (name) => {
|
3276
3344
|
return classType.details.mro.some((mroClass) => {
|
@@ -3287,10 +3355,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3287
3355
|
if (decls.length === 0 || !(0, types_1.isClass)(member.classType)) {
|
3288
3356
|
return;
|
3289
3357
|
}
|
3290
|
-
if (decls[0].type === 1 /* Variable */) {
|
3358
|
+
if (decls[0].type === 1 /* DeclarationType.Variable */) {
|
3291
3359
|
// If none of the declarations involve assignments, assume it's
|
3292
3360
|
// not implemented in the protocol.
|
3293
|
-
if (!decls.some((decl) => decl.type === 1 /* Variable */ && !!decl.inferredTypeSource)) {
|
3361
|
+
if (!decls.some((decl) => decl.type === 1 /* DeclarationType.Variable */ && !!decl.inferredTypeSource)) {
|
3294
3362
|
// This is a variable declaration that is not implemented in the
|
3295
3363
|
// protocol base class. Make sure it's implemented in the derived class.
|
3296
3364
|
if (!isSymbolImplemented(name)) {
|
@@ -3301,8 +3369,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3301
3369
|
}
|
3302
3370
|
}
|
3303
3371
|
}
|
3304
|
-
else if (decls[0].type === 5 /* Function */) {
|
3305
|
-
if (decls.every((decl) => decl.type !== 5 /* Function */ || ParseTreeUtils.isSuiteEmpty(decl.node.suite))) {
|
3372
|
+
else if (decls[0].type === 5 /* DeclarationType.Function */) {
|
3373
|
+
if (decls.every((decl) => decl.type !== 5 /* DeclarationType.Function */ || ParseTreeUtils.isSuiteEmpty(decl.node.suite))) {
|
3306
3374
|
if ((0, pathUtils_1.getFileExtension)(decls[0].path).toLowerCase() !== '.pyi') {
|
3307
3375
|
if (!isSymbolImplemented(name)) {
|
3308
3376
|
diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.missingProtocolMember().format({
|
@@ -3325,7 +3393,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3325
3393
|
if (!types_1.ClassType.isDataClass(classType)) {
|
3326
3394
|
return;
|
3327
3395
|
}
|
3328
|
-
const postInitMember = (0, typeUtils_1.lookUpClassMember)(classType, '__post_init__', 2 /* SkipBaseClasses */ | 64 /* DeclaredTypesOnly */);
|
3396
|
+
const postInitMember = (0, typeUtils_1.lookUpClassMember)(classType, '__post_init__', 2 /* MemberAccessFlags.SkipBaseClasses */ | 64 /* MemberAccessFlags.DeclaredTypesOnly */);
|
3329
3397
|
// If there's no __post_init__ method, there's nothing to check.
|
3330
3398
|
if (!postInitMember) {
|
3331
3399
|
return;
|
@@ -3448,7 +3516,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3448
3516
|
// variables. We need to make sure these are initialized.
|
3449
3517
|
const abstractSymbols = new Map();
|
3450
3518
|
if (types_1.ClassType.isFinal(classType)) {
|
3451
|
-
(0, typeUtils_1.getProtocolSymbolsRecursive)(classType, abstractSymbols, 1024 /* SupportsAbstractMethods */);
|
3519
|
+
(0, typeUtils_1.getProtocolSymbolsRecursive)(classType, abstractSymbols, 1024 /* ClassTypeFlags.SupportsAbstractMethods */);
|
3452
3520
|
}
|
3453
3521
|
classType.details.fields.forEach((localSymbol, name) => {
|
3454
3522
|
abstractSymbols.delete(name);
|
@@ -3465,14 +3533,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3465
3533
|
if (!containingClass) {
|
3466
3534
|
return true;
|
3467
3535
|
}
|
3468
|
-
if (containingClass.nodeType === 10 /* Class */) {
|
3536
|
+
if (containingClass.nodeType === 10 /* ParseNodeType.Class */) {
|
3469
3537
|
// If this is part of an assignment statement, assume it has been
|
3470
3538
|
// initialized as a class variable.
|
3471
|
-
if (((_a = decl.node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* Assignment */) {
|
3539
|
+
if (((_a = decl.node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* ParseNodeType.Assignment */) {
|
3472
3540
|
return true;
|
3473
3541
|
}
|
3474
|
-
if (((_b = decl.node.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 54 /* TypeAnnotation */ &&
|
3475
|
-
((_c = decl.node.parent.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 3 /* Assignment */) {
|
3542
|
+
if (((_b = decl.node.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 54 /* ParseNodeType.TypeAnnotation */ &&
|
3543
|
+
((_c = decl.node.parent.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 3 /* ParseNodeType.Assignment */) {
|
3476
3544
|
return true;
|
3477
3545
|
}
|
3478
3546
|
// If this is part of a dataclass or a class handled by a dataclass_transform,
|
@@ -3496,7 +3564,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3496
3564
|
}
|
3497
3565
|
// If the symbol is declared by its parent, we can assume it
|
3498
3566
|
// is initialized there.
|
3499
|
-
const parentSymbol = (0, typeUtils_1.lookUpClassMember)(classType, name, 1 /* SkipOriginalClass */);
|
3567
|
+
const parentSymbol = (0, typeUtils_1.lookUpClassMember)(classType, name, 1 /* MemberAccessFlags.SkipOriginalClass */);
|
3500
3568
|
if (parentSymbol) {
|
3501
3569
|
return;
|
3502
3570
|
}
|
@@ -3511,10 +3579,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3511
3579
|
if (decls.length === 0 || !(0, types_1.isClass)(member.classType)) {
|
3512
3580
|
return;
|
3513
3581
|
}
|
3514
|
-
if (decls[0].type === 1 /* Variable */) {
|
3582
|
+
if (decls[0].type === 1 /* DeclarationType.Variable */) {
|
3515
3583
|
// If none of the declarations involve assignments, assume it's
|
3516
3584
|
// not implemented in the protocol.
|
3517
|
-
if (!decls.some((decl) => decl.type === 1 /* Variable */ && !!decl.inferredTypeSource)) {
|
3585
|
+
if (!decls.some((decl) => decl.type === 1 /* DeclarationType.Variable */ && !!decl.inferredTypeSource)) {
|
3518
3586
|
// This is a variable declaration that is not implemented in the
|
3519
3587
|
// protocol base class. Make sure it's implemented in the derived class.
|
3520
3588
|
diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.uninitializedAbstractVariable().format({
|
@@ -3552,7 +3620,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3552
3620
|
return;
|
3553
3621
|
}
|
3554
3622
|
// Skip type variables with auto-variance.
|
3555
|
-
if (param.details.declaredVariance === 0 /* Auto */) {
|
3623
|
+
if (param.details.declaredVariance === 0 /* Variance.Auto */) {
|
3556
3624
|
return;
|
3557
3625
|
}
|
3558
3626
|
// Replace all type arguments with a dummy type except for the
|
@@ -3575,26 +3643,26 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3575
3643
|
const isDestSubtypeOfSrc = this._evaluator.assignClassToSelf(srcType, destType);
|
3576
3644
|
let expectedVariance;
|
3577
3645
|
if (isDestSubtypeOfSrc) {
|
3578
|
-
expectedVariance = 3 /* Covariant */;
|
3646
|
+
expectedVariance = 3 /* Variance.Covariant */;
|
3579
3647
|
}
|
3580
3648
|
else {
|
3581
3649
|
const isSrcSubtypeOfDest = this._evaluator.assignClassToSelf(destType, srcType);
|
3582
3650
|
if (isSrcSubtypeOfDest) {
|
3583
|
-
expectedVariance = 4 /* Contravariant */;
|
3651
|
+
expectedVariance = 4 /* Variance.Contravariant */;
|
3584
3652
|
}
|
3585
3653
|
else {
|
3586
|
-
expectedVariance = 2 /* Invariant */;
|
3654
|
+
expectedVariance = 2 /* Variance.Invariant */;
|
3587
3655
|
}
|
3588
3656
|
}
|
3589
3657
|
if (expectedVariance !== classType.details.typeParameters[paramIndex].details.declaredVariance) {
|
3590
3658
|
let message;
|
3591
|
-
if (expectedVariance === 3 /* Covariant */) {
|
3659
|
+
if (expectedVariance === 3 /* Variance.Covariant */) {
|
3592
3660
|
message = localize_1.Localizer.Diagnostic.protocolVarianceCovariant().format({
|
3593
3661
|
variable: param.details.name,
|
3594
3662
|
class: classType.details.name,
|
3595
3663
|
});
|
3596
3664
|
}
|
3597
|
-
else if (expectedVariance === 4 /* Contravariant */) {
|
3665
|
+
else if (expectedVariance === 4 /* Variance.Contravariant */) {
|
3598
3666
|
message = localize_1.Localizer.Diagnostic.protocolVarianceContravariant().format({
|
3599
3667
|
variable: param.details.name,
|
3600
3668
|
class: classType.details.name,
|
@@ -3624,13 +3692,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3624
3692
|
}
|
3625
3693
|
classType.details.fields.forEach((symbol, name) => {
|
3626
3694
|
const decls = symbol.getDeclarations();
|
3627
|
-
const isDefinedBySlots = decls.some((decl) => decl.type === 1 /* Variable */ && decl.isDefinedBySlots);
|
3695
|
+
const isDefinedBySlots = decls.some((decl) => decl.type === 1 /* DeclarationType.Variable */ && decl.isDefinedBySlots);
|
3628
3696
|
if (isDefinedBySlots) {
|
3629
3697
|
decls.forEach((decl) => {
|
3630
|
-
if (decl.type === 1 /* Variable */ &&
|
3698
|
+
if (decl.type === 1 /* DeclarationType.Variable */ &&
|
3631
3699
|
!decl.isDefinedBySlots &&
|
3632
3700
|
!decl.isDefinedByMemberAccess) {
|
3633
|
-
if (decl.node.nodeType === 38 /* Name */ && ParseTreeUtils.isWriteAccess(decl.node)) {
|
3701
|
+
if (decl.node.nodeType === 38 /* ParseNodeType.Name */ && ParseTreeUtils.isWriteAccess(decl.node)) {
|
3634
3702
|
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.slotsClassVarConflict().format({ name }), decl.node);
|
3635
3703
|
}
|
3636
3704
|
}
|
@@ -3696,25 +3764,25 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3696
3764
|
// often has an *args and/or **kwargs. We'll also set the ParamSpecValue
|
3697
3765
|
// because we don't care about the return type for this check.
|
3698
3766
|
initMemberType = types_1.FunctionType.cloneWithNewFlags(initMemberType, initMemberType.details.flags |
|
3699
|
-
32768 /* SkipArgsKwargsCompatibilityCheck */ |
|
3700
|
-
65536 /* ParamSpecValue */);
|
3767
|
+
32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */ |
|
3768
|
+
65536 /* FunctionTypeFlags.ParamSpecValue */);
|
3701
3769
|
newMemberType = types_1.FunctionType.cloneWithNewFlags(newMemberType, initMemberType.details.flags |
|
3702
|
-
32768 /* SkipArgsKwargsCompatibilityCheck */ |
|
3703
|
-
65536 /* ParamSpecValue */);
|
3770
|
+
32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */ |
|
3771
|
+
65536 /* FunctionTypeFlags.ParamSpecValue */);
|
3704
3772
|
if (!this._evaluator.assignType(newMemberType, initMemberType,
|
3705
3773
|
/* diag */ undefined,
|
3706
3774
|
/* destTypeVarContext */ undefined,
|
3707
|
-
/* srcTypeVarContext */ undefined, 32 /* SkipFunctionReturnTypeCheck */) ||
|
3775
|
+
/* srcTypeVarContext */ undefined, 32 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */) ||
|
3708
3776
|
!this._evaluator.assignType(initMemberType, newMemberType,
|
3709
3777
|
/* diag */ undefined,
|
3710
3778
|
/* destTypeVarContext */ undefined,
|
3711
|
-
/* srcTypeVarContext */ undefined, 32 /* SkipFunctionReturnTypeCheck */)) {
|
3779
|
+
/* srcTypeVarContext */ undefined, 32 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */)) {
|
3712
3780
|
const displayOnInit = types_1.ClassType.isSameGenericClass(initMethodResult.classType, classType);
|
3713
3781
|
const initDecl = initMemberType.details.declaration;
|
3714
3782
|
const newDecl = newMemberType.details.declaration;
|
3715
3783
|
if (initDecl && newDecl) {
|
3716
3784
|
const mainDecl = displayOnInit ? initDecl : newDecl;
|
3717
|
-
const mainDeclNode = mainDecl.node.nodeType === 28 /* Function */ ? mainDecl.node.name : mainDecl.node;
|
3785
|
+
const mainDeclNode = mainDecl.node.nodeType === 28 /* ParseNodeType.Function */ ? mainDecl.node.name : mainDecl.node;
|
3718
3786
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
3719
3787
|
const initSignature = this._evaluator.printType(initMemberType);
|
3720
3788
|
const newSignature = this._evaluator.printType(newMemberType);
|
@@ -3897,7 +3965,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3897
3965
|
/* baseClass */ undefined, diagAddendum,
|
3898
3966
|
/* enforceParamNameMatch */ true)) {
|
3899
3967
|
const decl = overrideFunction.details.declaration;
|
3900
|
-
if (decl && decl.type === 5 /* Function */) {
|
3968
|
+
if (decl && decl.type === 5 /* DeclarationType.Function */) {
|
3901
3969
|
diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportIncompatibleMethodOverride, diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.Localizer.Diagnostic.baseClassMethodTypeIncompatible().format({
|
3902
3970
|
classType: childClassType.details.name,
|
3903
3971
|
name: memberName,
|
@@ -3929,12 +3997,63 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3929
3997
|
// If the child class overrides this symbol with its own type, make sure
|
3930
3998
|
// the override is compatible with the overridden symbol. Otherwise use the
|
3931
3999
|
// override type.
|
3932
|
-
|
4000
|
+
// Verify that the override type is assignable to (same or narrower than)
|
4001
|
+
// the declared type of the base symbol.
|
4002
|
+
const primaryDecl = (0, symbolUtils_1.getLastTypedDeclaredForSymbol)(overriddenClassAndSymbol.symbol);
|
4003
|
+
let isInvariant = (primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* DeclarationType.Variable */ && !primaryDecl.isFinal;
|
4004
|
+
// If the entry is a member of a frozen dataclass, it is immutable,
|
4005
|
+
// so it does not need to be invariant.
|
4006
|
+
if (types_1.ClassType.isFrozenDataClass(overriddenClassAndSymbol.classType) &&
|
4007
|
+
overriddenClassAndSymbol.classType.details.dataClassEntries) {
|
4008
|
+
const dataclassEntry = overriddenClassAndSymbol.classType.details.dataClassEntries.find((entry) => entry.name === memberName);
|
4009
|
+
if (dataclassEntry) {
|
4010
|
+
isInvariant = false;
|
4011
|
+
}
|
4012
|
+
}
|
4013
|
+
let overriddenTDEntry;
|
4014
|
+
if (overriddenClassAndSymbol.classType.details.typedDictEntries) {
|
4015
|
+
overriddenTDEntry = overriddenClassAndSymbol.classType.details.typedDictEntries.get(memberName);
|
4016
|
+
if (overriddenTDEntry === null || overriddenTDEntry === void 0 ? void 0 : overriddenTDEntry.isReadOnly) {
|
4017
|
+
isInvariant = false;
|
4018
|
+
}
|
4019
|
+
}
|
4020
|
+
let overrideTDEntry;
|
4021
|
+
if (overrideClassAndSymbol.classType.details.typedDictEntries) {
|
4022
|
+
overrideTDEntry = overrideClassAndSymbol.classType.details.typedDictEntries.get(memberName);
|
4023
|
+
}
|
4024
|
+
if (!this._evaluator.assignType(overriddenType, childOverrideType !== null && childOverrideType !== void 0 ? childOverrideType : overrideType,
|
4025
|
+
/* diag */ undefined,
|
4026
|
+
/* destTypeVarContext */ undefined,
|
4027
|
+
/* srcTypeVarContext */ undefined, isInvariant ? 1 /* AssignTypeFlags.EnforceInvariance */ : 0 /* AssignTypeFlags.Default */)) {
|
3933
4028
|
diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportIncompatibleVariableOverride, diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.Localizer.Diagnostic.baseClassVariableTypeIncompatible().format({
|
3934
4029
|
classType: childClassType.details.name,
|
3935
4030
|
name: memberName,
|
3936
4031
|
}), errorNode);
|
3937
4032
|
}
|
4033
|
+
else if (overriddenTDEntry && overrideTDEntry) {
|
4034
|
+
let isRequiredCompatible;
|
4035
|
+
let isReadOnlyCompatible = true;
|
4036
|
+
// If both classes are TypedDicts and they both define this field,
|
4037
|
+
// make sure the attributes are compatible.
|
4038
|
+
if (overriddenTDEntry.isReadOnly) {
|
4039
|
+
isRequiredCompatible = overrideTDEntry.isRequired || !overriddenTDEntry.isRequired;
|
4040
|
+
}
|
4041
|
+
else {
|
4042
|
+
isReadOnlyCompatible = !overrideTDEntry.isReadOnly;
|
4043
|
+
isRequiredCompatible = overrideTDEntry.isRequired === overriddenTDEntry.isRequired;
|
4044
|
+
}
|
4045
|
+
if (!isRequiredCompatible) {
|
4046
|
+
const message = overrideTDEntry.isRequired
|
4047
|
+
? localize_1.Localizer.Diagnostic.typedDictFieldRequiredRedefinition
|
4048
|
+
: localize_1.Localizer.Diagnostic.typedDictFieldNotRequiredRedefinition;
|
4049
|
+
diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportIncompatibleVariableOverride, diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, message().format({ name: memberName }), errorNode);
|
4050
|
+
}
|
4051
|
+
else if (!isReadOnlyCompatible) {
|
4052
|
+
diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportIncompatibleVariableOverride, diagnosticRules_1.DiagnosticRule.reportIncompatibleVariableOverride, localize_1.Localizer.Diagnostic.typedDictFieldReadOnlyRedefinition().format({
|
4053
|
+
name: memberName,
|
4054
|
+
}), errorNode);
|
4055
|
+
}
|
4056
|
+
}
|
3938
4057
|
}
|
3939
4058
|
}
|
3940
4059
|
}
|
@@ -3983,7 +4102,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3983
4102
|
continue;
|
3984
4103
|
}
|
3985
4104
|
(0, debug_1.assert)((0, types_1.isClass)(mroBaseClass));
|
3986
|
-
const baseClassAndSymbol = (0, typeUtils_1.lookUpClassMember)(mroBaseClass, name, 0 /* Default */);
|
4105
|
+
const baseClassAndSymbol = (0, typeUtils_1.lookUpClassMember)(mroBaseClass, name, 0 /* MemberAccessFlags.Default */);
|
3987
4106
|
if (!baseClassAndSymbol) {
|
3988
4107
|
continue;
|
3989
4108
|
}
|
@@ -4013,8 +4132,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4013
4132
|
overrideFunction = types_1.OverloadedFunctionType.getImplementation(overrideType);
|
4014
4133
|
}
|
4015
4134
|
else if ((0, types_1.isClassInstance)(overrideType) && types_1.ClassType.isPropertyClass(overrideType)) {
|
4016
|
-
if (overrideType.
|
4017
|
-
overrideFunction = overrideType.
|
4135
|
+
if (overrideType.fgetInfo) {
|
4136
|
+
overrideFunction = overrideType.fgetInfo.methodType;
|
4018
4137
|
}
|
4019
4138
|
}
|
4020
4139
|
if (!(overrideFunction === null || overrideFunction === void 0 ? void 0 : overrideFunction.details.declaration) || types_1.FunctionType.isOverridden(overrideFunction)) {
|
@@ -4047,8 +4166,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4047
4166
|
overrideFunction = types_1.OverloadedFunctionType.getImplementation(overrideType);
|
4048
4167
|
}
|
4049
4168
|
else if ((0, types_1.isClassInstance)(overrideType) && types_1.ClassType.isPropertyClass(overrideType)) {
|
4050
|
-
if (overrideType.
|
4051
|
-
overrideFunction = overrideType.
|
4169
|
+
if (overrideType.fgetInfo) {
|
4170
|
+
overrideFunction = overrideType.fgetInfo.methodType;
|
4052
4171
|
}
|
4053
4172
|
}
|
4054
4173
|
if (!(overrideFunction === null || overrideFunction === void 0 ? void 0 : overrideFunction.details.declaration) || !types_1.FunctionType.isOverridden(overrideFunction)) {
|
@@ -4108,7 +4227,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4108
4227
|
const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportIncompatibleMethodOverride, diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.Localizer.Diagnostic.incompatibleMethodOverride().format({
|
4109
4228
|
name: memberName,
|
4110
4229
|
className: baseClass.details.name,
|
4111
|
-
}) + diagAddendum.getString(), decl.type === 5 /* Function */ ? decl.node.name : decl.node);
|
4230
|
+
}) + diagAddendum.getString(), decl.type === 5 /* DeclarationType.Function */ ? decl.node.name : decl.node);
|
4112
4231
|
const origDecl = (0, symbolUtils_1.getLastTypedDeclaredForSymbol)(baseClassAndSymbol.symbol);
|
4113
4232
|
if (diag && origDecl) {
|
4114
4233
|
diag.addRelatedInfo(localize_1.Localizer.DiagnosticAddendum.overriddenMethod(), origDecl.path, origDecl.range);
|
@@ -4120,7 +4239,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4120
4239
|
// Private names (starting with double underscore) are exempt from this check.
|
4121
4240
|
if (!SymbolNameUtils.isPrivateName(memberName) && types_1.FunctionType.isFinal(baseType)) {
|
4122
4241
|
const decl = (0, symbolUtils_1.getLastTypedDeclaredForSymbol)(overrideSymbol);
|
4123
|
-
if (decl && decl.type === 5 /* Function */) {
|
4242
|
+
if (decl && decl.type === 5 /* DeclarationType.Function */) {
|
4124
4243
|
const diag = this._evaluator.addError(localize_1.Localizer.Diagnostic.finalMethodOverride().format({
|
4125
4244
|
name: memberName,
|
4126
4245
|
className: baseClass.details.name,
|
@@ -4168,9 +4287,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4168
4287
|
else {
|
4169
4288
|
const baseClassType = baseClass;
|
4170
4289
|
const propMethodInfo = [
|
4171
|
-
['fget', (c) => c.
|
4172
|
-
['fset', (c) => c.
|
4173
|
-
['fdel', (c) => c.
|
4290
|
+
['fget', (c) => { var _a; return (_a = c.fgetInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4291
|
+
['fset', (c) => { var _a; return (_a = c.fsetInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4292
|
+
['fdel', (c) => { var _a; return (_a = c.fdelInfo) === null || _a === void 0 ? void 0 : _a.methodType; }],
|
4174
4293
|
];
|
4175
4294
|
propMethodInfo.forEach((info) => {
|
4176
4295
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
@@ -4206,7 +4325,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4206
4325
|
name: methodName,
|
4207
4326
|
}));
|
4208
4327
|
const decl = subclassMethodType.details.declaration;
|
4209
|
-
if (decl && decl.type === 5 /* Function */) {
|
4328
|
+
if (decl && decl.type === 5 /* DeclarationType.Function */) {
|
4210
4329
|
const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportIncompatibleMethodOverride, diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.Localizer.Diagnostic.propertyOverridden().format({
|
4211
4330
|
name: memberName,
|
4212
4331
|
className: baseClassType.details.name,
|
@@ -4234,7 +4353,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4234
4353
|
const primaryDecl = decls[0];
|
4235
4354
|
// Verify that the override type is assignable to (same or narrower than)
|
4236
4355
|
// the declared type of the base symbol.
|
4237
|
-
let isInvariant = (primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* Variable */ && !primaryDecl.isFinal;
|
4356
|
+
let isInvariant = (primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* DeclarationType.Variable */ && !primaryDecl.isFinal;
|
4238
4357
|
// If the entry is a member of a frozen dataclass, it is immutable,
|
4239
4358
|
// so it does not need to be invariant.
|
4240
4359
|
if (types_1.ClassType.isFrozenDataClass(baseClass) && baseClass.details.dataClassEntries) {
|
@@ -4243,10 +4362,21 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4243
4362
|
isInvariant = false;
|
4244
4363
|
}
|
4245
4364
|
}
|
4365
|
+
let overriddenTDEntry;
|
4366
|
+
if (baseClass.details.typedDictEntries) {
|
4367
|
+
overriddenTDEntry = baseClass.details.typedDictEntries.get(memberName);
|
4368
|
+
if (overriddenTDEntry === null || overriddenTDEntry === void 0 ? void 0 : overriddenTDEntry.isReadOnly) {
|
4369
|
+
isInvariant = false;
|
4370
|
+
}
|
4371
|
+
}
|
4372
|
+
let overrideTDEntry;
|
4373
|
+
if (childClassType.details.typedDictEntries) {
|
4374
|
+
overrideTDEntry = childClassType.details.typedDictEntries.get(memberName);
|
4375
|
+
}
|
4246
4376
|
let diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4247
4377
|
if (!this._evaluator.assignType(baseType, overrideType, diagAddendum,
|
4248
4378
|
/* destTypeVarContext */ undefined,
|
4249
|
-
/* srcTypeVarContext */ undefined, isInvariant ? 1 /* EnforceInvariance */ : 0 /* Default */)) {
|
4379
|
+
/* srcTypeVarContext */ undefined, isInvariant ? 1 /* AssignTypeFlags.EnforceInvariance */ : 0 /* AssignTypeFlags.Default */)) {
|
4250
4380
|
if (isInvariant) {
|
4251
4381
|
diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4252
4382
|
diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideIsInvariant());
|
@@ -4264,6 +4394,31 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4264
4394
|
diag.addRelatedInfo(localize_1.Localizer.DiagnosticAddendum.overriddenSymbol(), origDecl.path, origDecl.range);
|
4265
4395
|
}
|
4266
4396
|
}
|
4397
|
+
else if (overriddenTDEntry && overrideTDEntry) {
|
4398
|
+
// Make sure the required/not-required attribute is compatible.
|
4399
|
+
let isRequiredCompatible = true;
|
4400
|
+
if (overriddenTDEntry.isReadOnly) {
|
4401
|
+
// If the read-only flag is set, a not-required field can be overridden
|
4402
|
+
// by a required field, but not vice versa.
|
4403
|
+
isRequiredCompatible = overrideTDEntry.isRequired || !overriddenTDEntry.isRequired;
|
4404
|
+
}
|
4405
|
+
else {
|
4406
|
+
isRequiredCompatible = overrideTDEntry.isRequired === overriddenTDEntry.isRequired;
|
4407
|
+
}
|
4408
|
+
if (!isRequiredCompatible) {
|
4409
|
+
const message = overrideTDEntry.isRequired
|
4410
|
+
? localize_1.Localizer.Diagnostic.typedDictFieldRequiredRedefinition
|
4411
|
+
: localize_1.Localizer.Diagnostic.typedDictFieldNotRequiredRedefinition;
|
4412
|
+
this._evaluator.addDiagnostic(AnalyzerNodeInfo.getFileInfo(lastDecl.node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message().format({ name: memberName }), lastDecl.node);
|
4413
|
+
}
|
4414
|
+
// Make sure that the derived class isn't marking a previously writable
|
4415
|
+
// entry as read-only.
|
4416
|
+
if (!overriddenTDEntry.isReadOnly && overrideTDEntry.isReadOnly) {
|
4417
|
+
this._evaluator.addDiagnostic(AnalyzerNodeInfo.getFileInfo(lastDecl.node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typedDictFieldReadOnlyRedefinition().format({
|
4418
|
+
name: memberName,
|
4419
|
+
}), lastDecl.node);
|
4420
|
+
}
|
4421
|
+
}
|
4267
4422
|
// Verify that there is not a Final mismatch.
|
4268
4423
|
const isBaseVarFinal = this._evaluator.isFinalVariable(baseClassAndSymbol.symbol);
|
4269
4424
|
const overrideFinalVarDecl = decls.find((d) => this._evaluator.isFinalVariableDeclaration(d));
|
@@ -4289,7 +4444,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4289
4444
|
}
|
4290
4445
|
// If the subclass is declaring an inner class, we'll consider that
|
4291
4446
|
// to be a ClassVar.
|
4292
|
-
if (overrideSymbol.getTypedDeclarations().every((decl) => decl.type === 6 /* Class */)) {
|
4447
|
+
if (overrideSymbol.getTypedDeclarations().every((decl) => decl.type === 6 /* DeclarationType.Class */)) {
|
4293
4448
|
isClassVar = true;
|
4294
4449
|
}
|
4295
4450
|
}
|
@@ -4379,7 +4534,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4379
4534
|
if (node.parameters[0].name) {
|
4380
4535
|
paramName = node.parameters[0].name.value;
|
4381
4536
|
}
|
4382
|
-
if (node.parameters[0].category !== 0 /* Simple */) {
|
4537
|
+
if (node.parameters[0].category !== 0 /* ParameterCategory.Simple */) {
|
4383
4538
|
firstParamIsSimple = false;
|
4384
4539
|
}
|
4385
4540
|
}
|
@@ -4425,9 +4580,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4425
4580
|
// it could be combined with other classes in a multi-inheritance
|
4426
4581
|
// situation that effectively adds new superclasses that we don't know
|
4427
4582
|
// about statically.
|
4428
|
-
let effectiveFlags = 16 /* SkipInstanceMembers */ | 1 /* SkipOriginalClass */;
|
4583
|
+
let effectiveFlags = 16 /* MemberAccessFlags.SkipInstanceMembers */ | 1 /* MemberAccessFlags.SkipOriginalClass */;
|
4429
4584
|
if (types_1.ClassType.isFinal(classType)) {
|
4430
|
-
effectiveFlags |= 4 /* SkipObjectBaseClass */;
|
4585
|
+
effectiveFlags |= 4 /* MemberAccessFlags.SkipObjectBaseClass */;
|
4431
4586
|
}
|
4432
4587
|
const methodMember = (0, typeUtils_1.lookUpClassMember)(classType, methodType.details.name, effectiveFlags);
|
4433
4588
|
if (!methodMember) {
|
@@ -4437,13 +4592,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4437
4592
|
// Now scan the implementation of the method to determine whether
|
4438
4593
|
// super().<method> has been called for all of the required base classes.
|
4439
4594
|
const callNodeWalker = new ParseTreeUtils.CallNodeWalker((node) => {
|
4440
|
-
if (node.leftExpression.nodeType === 35 /* MemberAccess */) {
|
4595
|
+
if (node.leftExpression.nodeType === 35 /* ParseNodeType.MemberAccess */) {
|
4441
4596
|
// Is it accessing the method by the same name?
|
4442
4597
|
if (node.leftExpression.memberName.value === methodType.details.name) {
|
4443
4598
|
const memberBaseExpr = node.leftExpression.leftExpression;
|
4444
4599
|
// Is it a "super" call?
|
4445
|
-
if (memberBaseExpr.nodeType === 9 /* Call */ &&
|
4446
|
-
memberBaseExpr.leftExpression.nodeType === 38 /* Name */ &&
|
4600
|
+
if (memberBaseExpr.nodeType === 9 /* ParseNodeType.Call */ &&
|
4601
|
+
memberBaseExpr.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
4447
4602
|
memberBaseExpr.leftExpression.value === 'super') {
|
4448
4603
|
foundCallOfMember = true;
|
4449
4604
|
}
|
@@ -4493,7 +4648,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4493
4648
|
return;
|
4494
4649
|
}
|
4495
4650
|
// If the method starts with a `*args: P.args`, skip the check.
|
4496
|
-
if (paramInfo.category === 1 /* ArgsList */ &&
|
4651
|
+
if (paramInfo.category === 1 /* ParameterCategory.ArgsList */ &&
|
4497
4652
|
(0, types_1.isParamSpec)(paramInfo.type) &&
|
4498
4653
|
paramInfo.type.paramSpecAccess === 'args') {
|
4499
4654
|
return;
|
@@ -4645,7 +4800,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4645
4800
|
const importStatements = (0, importStatementUtils_1.getTopLevelImports)(this._moduleNode);
|
4646
4801
|
const importModuleMap = new Map();
|
4647
4802
|
importStatements.orderedImports.forEach((importStatement) => {
|
4648
|
-
if (importStatement.node.nodeType === 22 /* ImportFrom */) {
|
4803
|
+
if (importStatement.node.nodeType === 22 /* ParseNodeType.ImportFrom */) {
|
4649
4804
|
const symbolMap = new Map();
|
4650
4805
|
importStatement.node.imports.forEach((importFromAs) => {
|
4651
4806
|
// Ignore duplicates if they're aliased.
|
@@ -4678,7 +4833,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4678
4833
|
const regionComments = (0, regions_1.getRegionComments)(this._parseResults);
|
4679
4834
|
const regionStack = [];
|
4680
4835
|
regionComments.forEach((regionComment) => {
|
4681
|
-
if (regionComment.type === 0 /* Region */) {
|
4836
|
+
if (regionComment.type === 0 /* RegionCommentType.Region */) {
|
4682
4837
|
regionStack.push(regionComment);
|
4683
4838
|
}
|
4684
4839
|
else {
|