@zzzen/pyright-internal 1.1.255 → 1.2.0-dev.20220703
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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/analyzer/aliasDeclarationUtils.js +2 -2
- package/dist/analyzer/analyzerFileInfo.d.ts +1 -1
- package/dist/analyzer/analyzerNodeInfo.d.ts +4 -1
- package/dist/analyzer/analyzerNodeInfo.js +12 -1
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +1 -0
- package/dist/analyzer/backgroundAnalysisProgram.js +3 -0
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.d.ts +6 -1
- package/dist/analyzer/binder.js +142 -32
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +4 -1
- package/dist/analyzer/checker.js +144 -73
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowUtils.js +33 -0
- package/dist/analyzer/codeFlowUtils.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +6 -3
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/dataClasses.js +6 -4
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +18 -6
- package/dist/analyzer/declaration.js +25 -5
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/declarationUtils.d.ts +1 -1
- package/dist/analyzer/declarationUtils.js +19 -16
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/importResult.js +7 -0
- package/dist/analyzer/importResult.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +10 -1
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +1 -1
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/packageTypeReport.js +10 -1
- package/dist/analyzer/packageTypeReport.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +6 -6
- package/dist/analyzer/parseTreeUtils.d.ts +3 -3
- package/dist/analyzer/parseTreeUtils.js +27 -13
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.d.ts +4 -1
- package/dist/analyzer/parseTreeWalker.js +19 -1
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/program.d.ts +2 -1
- package/dist/analyzer/program.js +27 -23
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +2 -0
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.d.ts +0 -1
- package/dist/analyzer/protocols.js +4 -64
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/scope.js +22 -1
- package/dist/analyzer/scope.js.map +1 -1
- package/dist/analyzer/service.d.ts +20 -8
- package/dist/analyzer/service.js +39 -19
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.js +1 -1
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.d.ts +2 -0
- package/dist/analyzer/sourceFileInfoUtils.js +15 -0
- package/dist/analyzer/sourceFileInfoUtils.js.map +1 -0
- package/dist/analyzer/symbol.d.ts +3 -1
- package/dist/analyzer/symbol.js +39 -1
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +8 -4
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +11 -3
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +610 -208
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -1
- package/dist/analyzer/typeEvaluatorTypes.js +65 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeEvaluatorWithTracker.js +2 -0
- package/dist/analyzer/typeEvaluatorWithTracker.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +2 -0
- package/dist/analyzer/typeGuards.js +113 -69
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +27 -2
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.d.ts +4 -1
- package/dist/analyzer/typeStubWriter.js +36 -0
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.js +129 -33
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +2 -1
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +12 -4
- package/dist/analyzer/types.js +215 -6
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +1 -1
- package/dist/commands/commands.js +9 -0
- package/dist/commands/commands.js.map +1 -1
- package/dist/common/commandLineOptions.js +8 -1
- package/dist/common/commandLineOptions.js.map +1 -1
- package/dist/common/core.js +7 -1
- package/dist/common/core.js.map +1 -1
- package/dist/common/diagnostic.js +9 -1
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/host.js +7 -1
- package/dist/common/host.js.map +1 -1
- package/dist/common/pathUtils.d.ts +1 -0
- package/dist/common/pathUtils.js +34 -1
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/stringUtils.d.ts +1 -0
- package/dist/common/stringUtils.js +8 -1
- package/dist/common/stringUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +10 -3
- package/dist/languageServerBase.js +40 -14
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.js +3 -0
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/autoImporter.js +2 -1
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +9 -9
- package/dist/languageService/completionProvider.d.ts +2 -2
- package/dist/languageService/completionProvider.js +22 -18
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.js +3 -3
- package/dist/languageService/documentSymbolCollector.js +1 -1
- package/dist/languageService/documentSymbolProvider.js +10 -7
- package/dist/languageService/documentSymbolProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.js +19 -5
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/referencesProvider.js +8 -5
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +1 -1
- package/dist/localization/localize.d.ts +27 -0
- package/dist/localization/localize.js +16 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +18 -2
- package/dist/parser/parseNodes.d.ts +44 -5
- package/dist/parser/parseNodes.js +191 -4
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +3 -1
- package/dist/parser/parser.js +155 -24
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/stringTokenUtils.js +8 -1
- package/dist/parser/stringTokenUtils.js.map +1 -1
- package/dist/parser/tokenizer.js +4 -3
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/tokenizerTypes.d.ts +5 -3
- package/dist/parser/tokenizerTypes.js +157 -1
- package/dist/parser/tokenizerTypes.js.map +1 -1
- package/dist/pyright.js +6 -1
- package/dist/pyright.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +12 -9
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/checker.test.js +4 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/config.test.js +14 -13
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/debug.test.js +6 -0
- package/dist/tests/debug.test.js.map +1 -1
- package/dist/tests/fourslash/completions.autoimport.lib.alias.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.autoimport.lib.alias.fourslash.js +53 -0
- package/dist/tests/fourslash/completions.autoimport.lib.alias.fourslash.js.map +1 -0
- package/dist/tests/fourslash/fourslash.d.ts +16 -0
- package/dist/tests/fourslash/hover.class.docString.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.class.docString.fourslash.js +24 -0
- package/dist/tests/fourslash/hover.class.docString.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/fourSlashParser.js +6 -0
- package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
- package/dist/tests/harness/fourslash/fourSlashTypes.js +19 -1
- package/dist/tests/harness/fourslash/fourSlashTypes.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +9 -1
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.Consts.d.ts +1 -0
- package/dist/tests/harness/fourslash/testState.Consts.js +1 -0
- package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +4 -3
- package/dist/tests/harness/fourslash/testState.js +27 -11
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/pathValidation.js +25 -1
- package/dist/tests/harness/vfs/pathValidation.js.map +1 -1
- package/dist/tests/pathUtils.test.js +17 -0
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/testUtils.js +1 -1
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +9 -1
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +9 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +4 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.d.ts +1 -0
- package/dist/tests/typeEvaluator5.test.js +112 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -0
- package/dist/workspaceMap.d.ts +2 -1
- package/dist/workspaceMap.js +25 -3
- package/dist/workspaceMap.js.map +1 -1
- package/package.json +45 -45
- package/src/analyzer/aliasDeclarationUtils.ts +0 -169
- package/src/analyzer/analysis.ts +0 -92
- package/src/analyzer/analyzerFileInfo.ts +0 -56
- package/src/analyzer/analyzerNodeInfo.ts +0 -198
- package/src/analyzer/backgroundAnalysisProgram.ts +0 -311
- package/src/analyzer/binder.ts +0 -4081
- package/src/analyzer/checker.ts +0 -5507
- package/src/analyzer/circularDependency.ts +0 -52
- package/src/analyzer/codeFlowEngine.ts +0 -1548
- package/src/analyzer/codeFlowTypes.ts +0 -266
- package/src/analyzer/codeFlowUtils.ts +0 -436
- package/src/analyzer/commentUtils.ts +0 -174
- package/src/analyzer/constraintSolver.ts +0 -926
- package/src/analyzer/constructorTransform.ts +0 -317
- package/src/analyzer/dataClasses.ts +0 -999
- package/src/analyzer/declaration.ts +0 -252
- package/src/analyzer/declarationUtils.ts +0 -238
- package/src/analyzer/docStringConversion.ts +0 -850
- package/src/analyzer/docStringUtils.ts +0 -112
- package/src/analyzer/functionTransform.ts +0 -137
- package/src/analyzer/importResolver.ts +0 -2308
- package/src/analyzer/importResult.ts +0 -98
- package/src/analyzer/importStatementUtils.ts +0 -834
- package/src/analyzer/namedTuples.ts +0 -422
- package/src/analyzer/packageTypeReport.ts +0 -108
- package/src/analyzer/packageTypeVerifier.ts +0 -1466
- package/src/analyzer/parentDirectoryCache.ts +0 -88
- package/src/analyzer/parseTreeCleaner.ts +0 -35
- package/src/analyzer/parseTreeUtils.ts +0 -2165
- package/src/analyzer/parseTreeWalker.ts +0 -663
- package/src/analyzer/patternMatching.ts +0 -1356
- package/src/analyzer/program.ts +0 -2778
- package/src/analyzer/properties.ts +0 -534
- package/src/analyzer/protocols.ts +0 -660
- package/src/analyzer/pyTypedUtils.ts +0 -52
- package/src/analyzer/pythonPathUtils.ts +0 -201
- package/src/analyzer/scope.ts +0 -202
- package/src/analyzer/scopeUtils.ts +0 -81
- package/src/analyzer/service.ts +0 -1679
- package/src/analyzer/sourceFile.ts +0 -1401
- package/src/analyzer/sourceMapper.ts +0 -717
- package/src/analyzer/staticExpressions.ts +0 -308
- package/src/analyzer/symbol.ts +0 -249
- package/src/analyzer/symbolNameUtils.ts +0 -50
- package/src/analyzer/symbolUtils.ts +0 -49
- package/src/analyzer/testWalker.ts +0 -101
- package/src/analyzer/tracePrinter.ts +0 -264
- package/src/analyzer/typeCache.ts +0 -181
- package/src/analyzer/typeDocStringUtils.ts +0 -371
- package/src/analyzer/typeEvaluator.ts +0 -23395
- package/src/analyzer/typeEvaluatorTypes.ts +0 -452
- package/src/analyzer/typeEvaluatorWithTracker.ts +0 -161
- package/src/analyzer/typeGuards.ts +0 -1828
- package/src/analyzer/typePrinter.ts +0 -807
- package/src/analyzer/typeStubWriter.ts +0 -727
- package/src/analyzer/typeUtils.ts +0 -3126
- package/src/analyzer/typeVarContext.ts +0 -330
- package/src/analyzer/typedDicts.ts +0 -950
- package/src/analyzer/types.ts +0 -2857
- package/src/backgroundAnalysis.ts +0 -49
- package/src/backgroundAnalysisBase.ts +0 -606
- package/src/backgroundThreadBase.ts +0 -143
- package/src/commands/commandController.ts +0 -62
- package/src/commands/commandResult.ts +0 -21
- package/src/commands/commands.ts +0 -16
- package/src/commands/createTypeStub.ts +0 -56
- package/src/commands/quickActionCommand.ts +0 -40
- package/src/commands/restartServer.ts +0 -20
- package/src/common/cancellationUtils.ts +0 -71
- package/src/common/chokidarFileWatcherProvider.ts +0 -74
- package/src/common/collectionUtils.ts +0 -379
- package/src/common/commandLineOptions.ts +0 -132
- package/src/common/configOptions.ts +0 -1291
- package/src/common/console.ts +0 -201
- package/src/common/core.ts +0 -152
- package/src/common/crypto.ts +0 -60
- package/src/common/debug.ts +0 -144
- package/src/common/deferred.ts +0 -78
- package/src/common/diagnostic.ts +0 -191
- package/src/common/diagnosticRules.ts +0 -80
- package/src/common/diagnosticSink.ts +0 -150
- package/src/common/editAction.ts +0 -46
- package/src/common/extensibility.ts +0 -35
- package/src/common/extensions.ts +0 -21
- package/src/common/fileBasedCancellationUtils.ts +0 -274
- package/src/common/fileSystem.ts +0 -152
- package/src/common/fullAccessHost.ts +0 -203
- package/src/common/host.ts +0 -49
- package/src/common/logTracker.ts +0 -157
- package/src/common/lspUtils.ts +0 -18
- package/src/common/memUtils.ts +0 -36
- package/src/common/pathConsts.ts +0 -16
- package/src/common/pathUtils.ts +0 -987
- package/src/common/positionUtils.ts +0 -78
- package/src/common/progressReporter.ts +0 -53
- package/src/common/pythonVersion.ts +0 -74
- package/src/common/realFileSystem.ts +0 -433
- package/src/common/stringUtils.ts +0 -161
- package/src/common/textEditUtils.ts +0 -31
- package/src/common/textRange.ts +0 -225
- package/src/common/textRangeCollection.ts +0 -122
- package/src/common/timing.ts +0 -105
- package/src/common/uriParser.ts +0 -26
- package/src/common/workspaceEditUtils.ts +0 -100
- package/src/languageServerBase.ts +0 -1556
- package/src/languageService/analyzerServiceExecutor.ts +0 -144
- package/src/languageService/autoImporter.ts +0 -926
- package/src/languageService/callHierarchyProvider.ts +0 -476
- package/src/languageService/codeActionProvider.ts +0 -85
- package/src/languageService/completionProvider.ts +0 -3103
- package/src/languageService/definitionProvider.ts +0 -235
- package/src/languageService/documentHighlightProvider.ts +0 -61
- package/src/languageService/documentSymbolCollector.ts +0 -466
- package/src/languageService/documentSymbolProvider.ts +0 -466
- package/src/languageService/hoverProvider.ts +0 -499
- package/src/languageService/importAdder.ts +0 -437
- package/src/languageService/importSorter.ts +0 -196
- package/src/languageService/indentationUtils.ts +0 -813
- package/src/languageService/quickActions.ts +0 -113
- package/src/languageService/referencesProvider.ts +0 -316
- package/src/languageService/renameModuleProvider.ts +0 -1400
- package/src/languageService/signatureHelpProvider.ts +0 -227
- package/src/languageService/tooltipUtils.ts +0 -147
- package/src/localization/localize.ts +0 -1272
- package/src/localization/package.nls.de.json +0 -3
- package/src/localization/package.nls.en-us.json +0 -636
- package/src/localization/package.nls.es.json +0 -3
- package/src/localization/package.nls.fr.json +0 -3
- package/src/localization/package.nls.ja.json +0 -3
- package/src/localization/package.nls.ru.json +0 -3
- package/src/localization/package.nls.zh-cn.json +0 -3
- package/src/localization/package.nls.zh-tw.json +0 -3
- package/src/nodeMain.ts +0 -21
- package/src/nodeServer.ts +0 -30
- package/src/parser/characterStream.ts +0 -145
- package/src/parser/characters.ts +0 -285
- package/src/parser/parseNodes.ts +0 -2338
- package/src/parser/parser.ts +0 -4859
- package/src/parser/stringTokenUtils.ts +0 -564
- package/src/parser/tokenizer.ts +0 -1379
- package/src/parser/tokenizerTypes.ts +0 -420
- package/src/parser/unicode.ts +0 -2917
- package/src/pyright.ts +0 -824
- package/src/pyrightFileSystem.ts +0 -237
- package/src/readonlyAugmentedFileSystem.ts +0 -204
- package/src/server.ts +0 -298
- package/src/tests/chainedSourceFiles.test.ts +0 -183
- package/src/tests/checker.test.ts +0 -445
- package/src/tests/collectionUtils.test.ts +0 -178
- package/src/tests/common.test.ts +0 -117
- package/src/tests/config.test.ts +0 -291
- package/src/tests/debug.test.ts +0 -120
- package/src/tests/deferred.test.ts +0 -54
- package/src/tests/diagnosticOverrides.test.ts +0 -104
- package/src/tests/docStringConversion.test.ts +0 -823
- package/src/tests/docStringUtils.test.ts +0 -57
- package/src/tests/documentSymbolCollector.test.ts +0 -735
- package/src/tests/filesystem.test.ts +0 -215
- package/src/tests/fourSlashParser.test.ts +0 -330
- package/src/tests/fourSlashRunner.test.ts +0 -36
- package/src/tests/fourslash/completions.autoimport.Lib.Found.Type.fourslash.ts +0 -33
- package/src/tests/fourslash/completions.autoimport.Lib.Found.duplication.fourslash.ts +0 -47
- package/src/tests/fourslash/completions.autoimport.Lib.NotFound.fourslash.ts +0 -14
- package/src/tests/fourslash/completions.autoimport.disabled.fourslash.ts +0 -25
- package/src/tests/fourslash/completions.autoimport.duplicates.fourslash.ts +0 -36
- package/src/tests/fourslash/completions.autoimport.fourslash.ts +0 -29
- package/src/tests/fourslash/completions.autoimport.fromImport.fourslash.ts +0 -130
- package/src/tests/fourslash/completions.autoimport.plainText.fourslash.ts +0 -29
- package/src/tests/fourslash/completions.autoimport.shadow.fourslash.ts +0 -48
- package/src/tests/fourslash/completions.autoimport.submodule.fourslash.ts +0 -31
- package/src/tests/fourslash/completions.autoimport.topLevel.fourslash.ts +0 -57
- package/src/tests/fourslash/completions.builtinDocstrings.fourslash.ts +0 -117
- package/src/tests/fourslash/completions.builtinOverride.fourslash.ts +0 -22
- package/src/tests/fourslash/completions.call.stringLiteral.fourslash.ts +0 -55
- package/src/tests/fourslash/completions.call.typedDict.fourslash.ts +0 -247
- package/src/tests/fourslash/completions.call.typedDict.list.fourslash.ts +0 -163
- package/src/tests/fourslash/completions.call.typedDict.states.fourslash.ts +0 -135
- package/src/tests/fourslash/completions.classVariable.fourslash.ts +0 -37
- package/src/tests/fourslash/completions.comment.fourslash.ts +0 -28
- package/src/tests/fourslash/completions.declNames.class.fourslash.ts +0 -35
- package/src/tests/fourslash/completions.declNames.exception.fourslash.ts +0 -18
- package/src/tests/fourslash/completions.declNames.for.fourslash.ts +0 -30
- package/src/tests/fourslash/completions.declNames.importAlias.fourslash.ts +0 -15
- package/src/tests/fourslash/completions.declNames.lambda.fourslash.ts +0 -45
- package/src/tests/fourslash/completions.declNames.method.fourslash.ts +0 -71
- package/src/tests/fourslash/completions.declNames.overload.fourslash.ts +0 -156
- package/src/tests/fourslash/completions.declNames.topLevelOverload.fourslash.ts +0 -141
- package/src/tests/fourslash/completions.dictionary.keys.complex.fourslash.ts +0 -76
- package/src/tests/fourslash/completions.dictionary.keys.expression.fourslash.ts +0 -63
- package/src/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.ts +0 -161
- package/src/tests/fourslash/completions.dictionary.keys.simple.fourslash.ts +0 -151
- package/src/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.ts +0 -116
- package/src/tests/fourslash/completions.dictionary.keys.symbols.fourslash.ts +0 -53
- package/src/tests/fourslash/completions.enums.members.fourslash.ts +0 -44
- package/src/tests/fourslash/completions.excluded.fourslash.ts +0 -12
- package/src/tests/fourslash/completions.fourslash.ts +0 -51
- package/src/tests/fourslash/completions.fstring.fourslash.ts +0 -33
- package/src/tests/fourslash/completions.fstring.stringLiteral.fourslash.ts +0 -96
- package/src/tests/fourslash/completions.fuzzyMatching.fourslash.ts +0 -30
- package/src/tests/fourslash/completions.importDunderNames.fourslash.ts +0 -31
- package/src/tests/fourslash/completions.importSubmodule.fourslash.ts +0 -26
- package/src/tests/fourslash/completions.importsDuplicates.fourslash.ts +0 -23
- package/src/tests/fourslash/completions.inList.fourslash.ts +0 -33
- package/src/tests/fourslash/completions.included.fourslash.ts +0 -12
- package/src/tests/fourslash/completions.indexer.keys.getitem.fourslash.ts +0 -57
- package/src/tests/fourslash/completions.inherited.function.docFromStub.fourslash.ts +0 -28
- package/src/tests/fourslash/completions.inherited.overload.docFromScrWithStub.fourslash.ts +0 -52
- package/src/tests/fourslash/completions.inherited.overload.docFromStub.fourslash.ts +0 -53
- package/src/tests/fourslash/completions.inherited.property.docFromSrc.fourslash.ts +0 -104
- package/src/tests/fourslash/completions.inherited.property.docFromStub.fourslash.ts +0 -108
- package/src/tests/fourslash/completions.keywords.pythonVersion.fourslash.ts +0 -72
- package/src/tests/fourslash/completions.libCodeAndStub.fourslash.ts +0 -79
- package/src/tests/fourslash/completions.libCodeNoStub.fourslash.ts +0 -69
- package/src/tests/fourslash/completions.libStub.fourslash.ts +0 -69
- package/src/tests/fourslash/completions.literals.fourslash.ts +0 -33
- package/src/tests/fourslash/completions.localCode.fourslash.ts +0 -74
- package/src/tests/fourslash/completions.moduleContext.UnknownMemberOnInstance.fourslash.ts +0 -17
- package/src/tests/fourslash/completions.moduleContext.UnknownStaticFunctionOnClass.fourslash.ts +0 -57
- package/src/tests/fourslash/completions.moduleContext.libCodeNoStub.fourslash.ts +0 -30
- package/src/tests/fourslash/completions.overloads.fourslash.ts +0 -40
- package/src/tests/fourslash/completions.override.default.fourslash.ts +0 -47
- package/src/tests/fourslash/completions.override.default.importStub.ts +0 -50
- package/src/tests/fourslash/completions.override.default.imported.fourslash.ts +0 -61
- package/src/tests/fourslash/completions.override.default.stub.fourslash.ts +0 -47
- package/src/tests/fourslash/completions.override.fourslash.ts +0 -47
- package/src/tests/fourslash/completions.override.property.fourslash.ts +0 -31
- package/src/tests/fourslash/completions.override.property.stub.fourslash.ts +0 -31
- package/src/tests/fourslash/completions.override.staticAndClassmethod.fourslash.ts +0 -64
- package/src/tests/fourslash/completions.override.stub.fourslash.ts +0 -47
- package/src/tests/fourslash/completions.override2.fourslash.ts +0 -71
- package/src/tests/fourslash/completions.parameters.fourslash.ts +0 -23
- package/src/tests/fourslash/completions.params.fourslash.ts +0 -24
- package/src/tests/fourslash/completions.parentFolder.fourslash.ts +0 -17
- package/src/tests/fourslash/completions.parentFolders.fourslash.ts +0 -77
- package/src/tests/fourslash/completions.plainText.fourslash.ts +0 -34
- package/src/tests/fourslash/completions.private.fourslash.ts +0 -64
- package/src/tests/fourslash/completions.property.fourslash.ts +0 -28
- package/src/tests/fourslash/completions.propertyDocStrings.fourslash.ts +0 -64
- package/src/tests/fourslash/completions.self.fourslash.ts +0 -43
- package/src/tests/fourslash/completions.stringLiteral.escape.fourslash.ts +0 -71
- package/src/tests/fourslash/completions.stringLiteral.fourslash.ts +0 -79
- package/src/tests/fourslash/completions.typeAlias.fourslash.ts +0 -29
- package/src/tests/fourslash/completions.typeshed.fourslash.ts +0 -9
- package/src/tests/fourslash/completions.vardecls.fourslash.ts +0 -40
- package/src/tests/fourslash/completions.variableDocStrings.fourslash.ts +0 -69
- package/src/tests/fourslash/completions.wildcardimports.fourslash.ts +0 -116
- package/src/tests/fourslash/completions.with.fourslash.ts +0 -26
- package/src/tests/fourslash/diagnostics.missingModuleSource.fourslash.ts +0 -69
- package/src/tests/fourslash/findDefinitions.builtinClass.fourslash.ts +0 -29
- package/src/tests/fourslash/findDefinitions.classes.fourslash.ts +0 -101
- package/src/tests/fourslash/findDefinitions.definitionFilter.preferSource.fourslash.ts +0 -29
- package/src/tests/fourslash/findDefinitions.definitionFilter.preferSource.onlyStubs.ts +0 -24
- package/src/tests/fourslash/findDefinitions.definitionFilter.preferStub.fourslash.ts +0 -29
- package/src/tests/fourslash/findDefinitions.definitionFilter.preferStub.onlySource.fourslash.ts +0 -25
- package/src/tests/fourslash/findDefinitions.fields.fourslash.ts +0 -131
- package/src/tests/fourslash/findDefinitions.functions.fourslash.ts +0 -87
- package/src/tests/fourslash/findDefinitions.methods.fourslash.ts +0 -162
- package/src/tests/fourslash/findDefinitions.modules.fourslash.ts +0 -50
- package/src/tests/fourslash/findDefinitions.namespaceImport.fourslash.ts +0 -40
- package/src/tests/fourslash/findDefinitions.overloads.fourslash.ts +0 -223
- package/src/tests/fourslash/findDefinitions.parameters.fourslash.ts +0 -162
- package/src/tests/fourslash/findDefinitions.sourceAndStub.function.fourslash.ts +0 -26
- package/src/tests/fourslash/findDefinitions.sourceAndStub.innerClass.fourslash.ts +0 -32
- package/src/tests/fourslash/findDefinitions.sourceAndStub.innerClassMethod.fourslash.ts +0 -33
- package/src/tests/fourslash/findDefinitions.sourceAndStub.outerClass.fourslash.ts +0 -28
- package/src/tests/fourslash/findDefinitions.sourceAndStub.outerClassMethod.fourslash.ts +0 -29
- package/src/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadOnly.fourslash.ts +0 -31
- package/src/tests/fourslash/findDefinitions.sourceAndStub.outerClassPropertyReadWrite.fourslash.ts +0 -36
- package/src/tests/fourslash/findDefinitions.sourceOnly.class.fourslash.ts +0 -29
- package/src/tests/fourslash/findDefinitions.sourceOnly.function1.fourslash.ts +0 -28
- package/src/tests/fourslash/findDefinitions.sourceOnly.function2.fourslash.ts +0 -28
- package/src/tests/fourslash/findDefinitions.sourceOnly.relativeImport1.fourslash.ts +0 -22
- package/src/tests/fourslash/findDefinitions.sourceOnly.relativeImport2.fourslash.ts +0 -22
- package/src/tests/fourslash/findDefinitions.stubOnly.fourslash.ts +0 -61
- package/src/tests/fourslash/findDefinitions.stubPackages.fourslash.ts +0 -71
- package/src/tests/fourslash/findDefinitions.typedDict.keys.fourslash.ts +0 -99
- package/src/tests/fourslash/findDefinitions.variables.fourslash.ts +0 -88
- package/src/tests/fourslash/findDefinitions.wildcardimports.fourslash.ts +0 -117
- package/src/tests/fourslash/findTypeDefinitions.builtinClass.fourslash.ts +0 -26
- package/src/tests/fourslash/findTypeDefinitions.classes.fourslash.ts +0 -72
- package/src/tests/fourslash/findTypeDefinitions.unions.fourslash.ts +0 -26
- package/src/tests/fourslash/findallreferences.classPropertyReadWrite.ts +0 -39
- package/src/tests/fourslash/findallreferences.fourslash.ts +0 -34
- package/src/tests/fourslash/findallreferences.importalias.fourslash.ts +0 -34
- package/src/tests/fourslash/findallreferences.invokedFromLibrary.fourslash.ts +0 -52
- package/src/tests/fourslash/findallreferences.module.nested.fourslash.ts +0 -67
- package/src/tests/fourslash/findallreferences.modules.duplicated.fourslash.ts +0 -59
- package/src/tests/fourslash/findallreferences.modules.fourslash.ts +0 -46
- package/src/tests/fourslash/findallreferences.modules.shadow.fourslash.ts +0 -95
- package/src/tests/fourslash/findallreferences.openFiles.fourslash.ts +0 -37
- package/src/tests/fourslash/findallreferences.parameter.fourslash.ts +0 -24
- package/src/tests/fourslash/findallreferences.sourceAndStub.class.fourslash.ts +0 -33
- package/src/tests/fourslash/findallreferences.sourceAndStub.classMethod.fourslash.ts +0 -37
- package/src/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadOnly.fourslash.ts +0 -40
- package/src/tests/fourslash/findallreferences.sourceAndStub.classPropertyReadWrite.fourslash.skip.ts +0 -48
- package/src/tests/fourslash/findallreferences.sourceAndStub.function.fourslash.ts +0 -35
- package/src/tests/fourslash/findallreferences.variable.fourslash.ts +0 -24
- package/src/tests/fourslash/fourslash.ts +0 -411
- package/src/tests/fourslash/highlightreferences.attributes.fourslash.ts +0 -31
- package/src/tests/fourslash/hover.builtinDocstrings.fourslash.ts +0 -64
- package/src/tests/fourslash/hover.classNoInit.fourslash.ts +0 -14
- package/src/tests/fourslash/hover.docFromScr.stringFormat.fourslash.ts +0 -52
- package/src/tests/fourslash/hover.docFromSrc.fourslash.ts +0 -83
- package/src/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.ts +0 -26
- package/src/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.ts +0 -26
- package/src/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.ts +0 -23
- package/src/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.ts +0 -22
- package/src/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.ts +0 -46
- package/src/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.ts +0 -29
- package/src/tests/fourslash/hover.docFromSrc.typeshed.fourslash.ts +0 -20
- package/src/tests/fourslash/hover.docstring.links.fourslash.ts +0 -12
- package/src/tests/fourslash/hover.docstring.overloads.fourslash.ts +0 -41
- package/src/tests/fourslash/hover.docstring.split.fourslash.ts +0 -24
- package/src/tests/fourslash/hover.fourslash.ts +0 -20
- package/src/tests/fourslash/hover.import.django.view.fourslash.ts +0 -27
- package/src/tests/fourslash/hover.import.fourslash.ts +0 -11
- package/src/tests/fourslash/hover.inherited.docFromSrc.fourslash.ts +0 -63
- package/src/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.ts +0 -54
- package/src/tests/fourslash/hover.inherited.docFromStub.fourslash.ts +0 -42
- package/src/tests/fourslash/hover.inherited.overload.docFromSrcWithStub.fourslash.ts +0 -46
- package/src/tests/fourslash/hover.inherited.overload.docFromStub.fourslash.ts +0 -47
- package/src/tests/fourslash/hover.inherited.property.docFromSrcWithStub.fourslash.ts +0 -87
- package/src/tests/fourslash/hover.inherited.property.docFromStub.fourslash.ts +0 -91
- package/src/tests/fourslash/hover.init.fourslash.ts +0 -39
- package/src/tests/fourslash/hover.libCodeAndStub.fourslash.ts +0 -52
- package/src/tests/fourslash/hover.libCodeNoStub.fourslash.ts +0 -41
- package/src/tests/fourslash/hover.libStub.fourslash.ts +0 -41
- package/src/tests/fourslash/hover.optionalAliasParameter.fourslash.ts +0 -14
- package/src/tests/fourslash/hover.plainText.fourslash.ts +0 -21
- package/src/tests/fourslash/hover.typedDict.key.fourslash.ts +0 -51
- package/src/tests/fourslash/hover.variable.docString.fourslash.ts +0 -41
- package/src/tests/fourslash/hover.wildcardimports.fourslash.ts +0 -80
- package/src/tests/fourslash/import.publicSymbols.fourslash.ts +0 -65
- package/src/tests/fourslash/import.pytyped.dunderAll.fourslash.ts +0 -77
- package/src/tests/fourslash/import.pytyped.privateSymbols.fourslash.ts +0 -65
- package/src/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.ts +0 -38
- package/src/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.ts +0 -38
- package/src/tests/fourslash/import.wildcard.fourslash.ts +0 -27
- package/src/tests/fourslash/importnotresolved.fourslash.ts +0 -13
- package/src/tests/fourslash/missingModuleSource.disablingInStrictMode.fourslash.ts +0 -20
- package/src/tests/fourslash/missingModuleSource.fourslash.ts +0 -14
- package/src/tests/fourslash/missingTypeStub.codeAction.fourslash.ts +0 -33
- package/src/tests/fourslash/missingTypeStub.command.multipart.fourslash.ts +0 -48
- package/src/tests/fourslash/missingTypeStub.command.singlefile.fourslash.ts +0 -38
- package/src/tests/fourslash/missingTypeStub.command.singlepart.fourslash.ts +0 -38
- package/src/tests/fourslash/missingTypeStub.fourslash.ts +0 -20
- package/src/tests/fourslash/missingTypeStub.invokeCodeAction.fourslash.ts +0 -36
- package/src/tests/fourslash/noerrors.fourslash.ts +0 -9
- package/src/tests/fourslash/orderImports1.command.fourslash.ts +0 -20
- package/src/tests/fourslash/orderImports2.command.fourslash.ts +0 -24
- package/src/tests/fourslash/rename.externallyHidden.fourslash.ts +0 -24
- package/src/tests/fourslash/rename.externallyHidden.params.fourslash.ts +0 -24
- package/src/tests/fourslash/rename.fourslash.ts +0 -29
- package/src/tests/fourslash/rename.library.fourslash.ts +0 -29
- package/src/tests/fourslash/rename.library.sourceAndStub.fourslash.ts +0 -33
- package/src/tests/fourslash/rename.multipleDecl.fourslash.ts +0 -21
- package/src/tests/fourslash/rename.sourceAndStub.fourslash.ts +0 -37
- package/src/tests/fourslash/rename.string.excluded.fourslash.ts +0 -43
- package/src/tests/fourslash/rename.string.fourslash.ts +0 -26
- package/src/tests/fourslash/signature.builtinDocstrings.fourslash.ts +0 -63
- package/src/tests/fourslash/signature.complicated.fourslash.ts +0 -100
- package/src/tests/fourslash/signature.cornercases.fourslash.ts +0 -23
- package/src/tests/fourslash/signature.docstrings.fourslash.ts +0 -43
- package/src/tests/fourslash/signature.docstrings.overloaded.fourslash.ts +0 -50
- package/src/tests/fourslash/signature.docstrings.wildcardimports.fourslash.ts +0 -122
- package/src/tests/fourslash/signature.overload.fourslash.ts +0 -64
- package/src/tests/fourslash/signature.simple.fourslash.ts +0 -104
- package/src/tests/harness/fourslash/fourSlashParser.ts +0 -441
- package/src/tests/harness/fourslash/fourSlashTypes.ts +0 -134
- package/src/tests/harness/fourslash/runner.ts +0 -99
- package/src/tests/harness/fourslash/testLanguageService.ts +0 -142
- package/src/tests/harness/fourslash/testState.Consts.ts +0 -29
- package/src/tests/harness/fourslash/testState.ts +0 -1993
- package/src/tests/harness/testAccessHost.ts +0 -23
- package/src/tests/harness/testHost.ts +0 -177
- package/src/tests/harness/utils.ts +0 -355
- package/src/tests/harness/vfs/factory.ts +0 -199
- package/src/tests/harness/vfs/filesystem.ts +0 -1893
- package/src/tests/harness/vfs/pathValidation.ts +0 -154
- package/src/tests/importAdder.test.ts +0 -1361
- package/src/tests/importResolver.test.ts +0 -534
- package/src/tests/importStatementUtils.test.ts +0 -526
- package/src/tests/indentationUtils.ptvs.test.ts +0 -388
- package/src/tests/indentationUtils.reindent.test.ts +0 -403
- package/src/tests/indentationUtils.test.ts +0 -455
- package/src/tests/ipythonMode.test.ts +0 -365
- package/src/tests/localizer.test.ts +0 -47
- package/src/tests/parseTreeUtils.test.ts +0 -281
- package/src/tests/parser.test.ts +0 -99
- package/src/tests/pathUtils.test.ts +0 -321
- package/src/tests/pyrightFileSystem.test.ts +0 -183
- package/src/tests/renameModule.folder.test.ts +0 -261
- package/src/tests/renameModule.fromImports.test.ts +0 -952
- package/src/tests/renameModule.imports.test.ts +0 -450
- package/src/tests/renameModule.misc.test.ts +0 -765
- package/src/tests/renameModule.relativePath.test.ts +0 -277
- package/src/tests/renameModuleTestUtils.ts +0 -210
- package/src/tests/samples/abstractClass1.py +0 -51
- package/src/tests/samples/abstractClass2.py +0 -25
- package/src/tests/samples/abstractClass3.py +0 -30
- package/src/tests/samples/abstractClass4.py +0 -30
- package/src/tests/samples/abstractClass5.py +0 -42
- package/src/tests/samples/abstractClass6.py +0 -25
- package/src/tests/samples/abstractClass7.py +0 -22
- package/src/tests/samples/abstractClass8.py +0 -27
- package/src/tests/samples/annotated1.py +0 -72
- package/src/tests/samples/annotatedVar1.py +0 -22
- package/src/tests/samples/annotatedVar2.py +0 -28
- package/src/tests/samples/annotatedVar3.py +0 -54
- package/src/tests/samples/annotatedVar4.py +0 -24
- package/src/tests/samples/annotatedVar5.py +0 -37
- package/src/tests/samples/annotatedVar6.py +0 -22
- package/src/tests/samples/annotatedVar7.py +0 -13
- package/src/tests/samples/annotatedVar8.py +0 -29
- package/src/tests/samples/annotations1.py +0 -98
- package/src/tests/samples/annotations2.py +0 -33
- package/src/tests/samples/annotations3.py +0 -43
- package/src/tests/samples/annotations4.py +0 -54
- package/src/tests/samples/annotations5.py +0 -9
- package/src/tests/samples/annotations6.py +0 -29
- package/src/tests/samples/assert1.py +0 -22
- package/src/tests/samples/assertType1.py +0 -46
- package/src/tests/samples/assignment1.py +0 -58
- package/src/tests/samples/assignment10.py +0 -14
- package/src/tests/samples/assignment2.py +0 -40
- package/src/tests/samples/assignment3.py +0 -46
- package/src/tests/samples/assignment4.py +0 -20
- package/src/tests/samples/assignment5.py +0 -16
- package/src/tests/samples/assignment6.py +0 -25
- package/src/tests/samples/assignment7.py +0 -13
- package/src/tests/samples/assignment8.py +0 -40
- package/src/tests/samples/assignment9.py +0 -25
- package/src/tests/samples/assignmentExpr1.py +0 -23
- package/src/tests/samples/assignmentExpr2.py +0 -49
- package/src/tests/samples/assignmentExpr3.py +0 -27
- package/src/tests/samples/assignmentExpr4.py +0 -49
- package/src/tests/samples/assignmentExpr5.py +0 -15
- package/src/tests/samples/assignmentExpr6.py +0 -10
- package/src/tests/samples/assignmentExpr7.py +0 -13
- package/src/tests/samples/assignmentExpr8.py +0 -11
- package/src/tests/samples/assignmentExpr9.py +0 -28
- package/src/tests/samples/async1.py +0 -49
- package/src/tests/samples/augmentedAssignment1.py +0 -62
- package/src/tests/samples/augmentedAssignment2.py +0 -23
- package/src/tests/samples/augmentedAssignment3.py +0 -8
- package/src/tests/samples/await1.py +0 -23
- package/src/tests/samples/await2.py +0 -25
- package/src/tests/samples/badToken1.py +0 -6
- package/src/tests/samples/builtins1.py +0 -2
- package/src/tests/samples/call1.py +0 -93
- package/src/tests/samples/call2.py +0 -118
- package/src/tests/samples/call3.py +0 -168
- package/src/tests/samples/call4.py +0 -13
- package/src/tests/samples/call5.py +0 -95
- package/src/tests/samples/call6.py +0 -35
- package/src/tests/samples/call7.py +0 -57
- package/src/tests/samples/callSite1.py +0 -6
- package/src/tests/samples/callSite2.py +0 -12
- package/src/tests/samples/callable1.py +0 -53
- package/src/tests/samples/callable2.py +0 -58
- package/src/tests/samples/callable3.py +0 -28
- package/src/tests/samples/callable4.py +0 -32
- package/src/tests/samples/callable5.py +0 -40
- package/src/tests/samples/callable6.py +0 -83
- package/src/tests/samples/callbackProtocol1.py +0 -119
- package/src/tests/samples/callbackProtocol2.py +0 -29
- package/src/tests/samples/callbackProtocol3.py +0 -23
- package/src/tests/samples/callbackProtocol4.py +0 -73
- package/src/tests/samples/callbackProtocol5.py +0 -66
- package/src/tests/samples/callbackProtocol6.py +0 -66
- package/src/tests/samples/callbackProtocol7.py +0 -16
- package/src/tests/samples/callbackProtocol8.py +0 -16
- package/src/tests/samples/capturedVariable1.py +0 -106
- package/src/tests/samples/circular1.py +0 -16
- package/src/tests/samples/circular2.py +0 -38
- package/src/tests/samples/circularBaseClass.py +0 -17
- package/src/tests/samples/classGetItem1.py +0 -30
- package/src/tests/samples/classVar1.py +0 -41
- package/src/tests/samples/classVar2.py +0 -29
- package/src/tests/samples/classVar3.py +0 -46
- package/src/tests/samples/classVar4.py +0 -36
- package/src/tests/samples/classes1.py +0 -50
- package/src/tests/samples/classes3.py +0 -48
- package/src/tests/samples/classes4.py +0 -15
- package/src/tests/samples/classes5.py +0 -260
- package/src/tests/samples/classes6.py +0 -16
- package/src/tests/samples/classes7.py +0 -18
- package/src/tests/samples/classes8.py +0 -47
- package/src/tests/samples/codeFlow1.py +0 -65
- package/src/tests/samples/codeFlow2.py +0 -26
- package/src/tests/samples/codeFlow3.py +0 -8
- package/src/tests/samples/codeFlow4.py +0 -133
- package/src/tests/samples/codeFlow5.py +0 -10
- package/src/tests/samples/codeFlow6.py +0 -35
- package/src/tests/samples/codeFlow7.py +0 -35
- package/src/tests/samples/comparison1.py +0 -77
- package/src/tests/samples/comparison2.py +0 -37
- package/src/tests/samples/complex1.py +0 -17
- package/src/tests/samples/constant1.py +0 -40
- package/src/tests/samples/constants1.py +0 -64
- package/src/tests/samples/constructor1.py +0 -30
- package/src/tests/samples/constructor10.py +0 -19
- package/src/tests/samples/constructor11.py +0 -32
- package/src/tests/samples/constructor12.py +0 -20
- package/src/tests/samples/constructor13.py +0 -15
- package/src/tests/samples/constructor2.py +0 -180
- package/src/tests/samples/constructor3.py +0 -18
- package/src/tests/samples/constructor4.py +0 -25
- package/src/tests/samples/constructor5.py +0 -25
- package/src/tests/samples/constructor6.py +0 -70
- package/src/tests/samples/constructor7.py +0 -11
- package/src/tests/samples/constructor8.py +0 -99
- package/src/tests/samples/constructor9.py +0 -19
- package/src/tests/samples/coroutines1.py +0 -60
- package/src/tests/samples/coroutines2.py +0 -20
- package/src/tests/samples/coroutines3.py +0 -37
- package/src/tests/samples/dataclass1.py +0 -44
- package/src/tests/samples/dataclass10.py +0 -45
- package/src/tests/samples/dataclass11.py +0 -53
- package/src/tests/samples/dataclass12.py +0 -32
- package/src/tests/samples/dataclass13.py +0 -42
- package/src/tests/samples/dataclass14.py +0 -38
- package/src/tests/samples/dataclass15.py +0 -58
- package/src/tests/samples/dataclass16.py +0 -21
- package/src/tests/samples/dataclass17.py +0 -46
- package/src/tests/samples/dataclass18.py +0 -57
- package/src/tests/samples/dataclass19.py +0 -44
- package/src/tests/samples/dataclass2.py +0 -30
- package/src/tests/samples/dataclass20.py +0 -71
- package/src/tests/samples/dataclass21.py +0 -13
- package/src/tests/samples/dataclass3.py +0 -18
- package/src/tests/samples/dataclass4.py +0 -64
- package/src/tests/samples/dataclass5.py +0 -81
- package/src/tests/samples/dataclass6.py +0 -29
- package/src/tests/samples/dataclass7.py +0 -93
- package/src/tests/samples/dataclass8.py +0 -22
- package/src/tests/samples/dataclass9.py +0 -24
- package/src/tests/samples/dataclassPostInit1.py +0 -61
- package/src/tests/samples/dataclassTransform1.py +0 -71
- package/src/tests/samples/dataclassTransform2.py +0 -78
- package/src/tests/samples/dataclassTransform3.py +0 -83
- package/src/tests/samples/dataclassTransform4.py +0 -87
- package/src/tests/samples/decorator1.py +0 -20
- package/src/tests/samples/decorator2.py +0 -31
- package/src/tests/samples/decorator3.py +0 -27
- package/src/tests/samples/decorator4.py +0 -37
- package/src/tests/samples/decorator5.py +0 -29
- package/src/tests/samples/decorator6.py +0 -34
- package/src/tests/samples/defaultInitializer1.py +0 -26
- package/src/tests/samples/deprecated1.py +0 -37
- package/src/tests/samples/descriptor1.py +0 -134
- package/src/tests/samples/descriptor2.py +0 -29
- package/src/tests/samples/dictionary1.py +0 -42
- package/src/tests/samples/dictionary2.py +0 -14
- package/src/tests/samples/dictionary3.py +0 -30
- package/src/tests/samples/dictionary4.py +0 -106
- package/src/tests/samples/dunderAll1.py +0 -32
- package/src/tests/samples/dunderAll2.py +0 -16
- package/src/tests/samples/dunderAll3.pyi +0 -16
- package/src/tests/samples/duplicateDeclaration1.py +0 -115
- package/src/tests/samples/duplicateDeclaration2.py +0 -45
- package/src/tests/samples/duplicateImports1.py +0 -13
- package/src/tests/samples/ellipsis1.pyi +0 -48
- package/src/tests/samples/emptyContainers1.py +0 -89
- package/src/tests/samples/enums1.py +0 -52
- package/src/tests/samples/enums2.py +0 -15
- package/src/tests/samples/enums3.py +0 -24
- package/src/tests/samples/enums4.py +0 -23
- package/src/tests/samples/enums5.py +0 -16
- package/src/tests/samples/enums6.py +0 -33
- package/src/tests/samples/enums7.py +0 -54
- package/src/tests/samples/enums8.py +0 -14
- package/src/tests/samples/expressions1.py +0 -54
- package/src/tests/samples/expressions2.py +0 -29
- package/src/tests/samples/expressions3.py +0 -26
- package/src/tests/samples/expressions4.py +0 -23
- package/src/tests/samples/expressions5.py +0 -70
- package/src/tests/samples/expressions6.py +0 -14
- package/src/tests/samples/expressions7.py +0 -40
- package/src/tests/samples/expressions8.py +0 -26
- package/src/tests/samples/expressions9.py +0 -14
- package/src/tests/samples/final1.py +0 -14
- package/src/tests/samples/final2.py +0 -86
- package/src/tests/samples/final3.py +0 -179
- package/src/tests/samples/final4.pyi +0 -21
- package/src/tests/samples/final5.py +0 -18
- package/src/tests/samples/forLoop1.py +0 -88
- package/src/tests/samples/forLoop2.py +0 -48
- package/src/tests/samples/fstring1.py +0 -66
- package/src/tests/samples/fstring2.py +0 -12
- package/src/tests/samples/fstring3.py +0 -35
- package/src/tests/samples/fstring4.py +0 -17
- package/src/tests/samples/fstring5.py +0 -17
- package/src/tests/samples/fstring6.py +0 -14
- package/src/tests/samples/function1.py +0 -12
- package/src/tests/samples/function10.py +0 -20
- package/src/tests/samples/function11.py +0 -36
- package/src/tests/samples/function2.py +0 -7
- package/src/tests/samples/function3.py +0 -82
- package/src/tests/samples/function4.py +0 -13
- package/src/tests/samples/function6.py +0 -24
- package/src/tests/samples/function7.py +0 -13
- package/src/tests/samples/function8.py +0 -38
- package/src/tests/samples/function9.py +0 -75
- package/src/tests/samples/functionAnnotation1.py +0 -61
- package/src/tests/samples/functionAnnotation2.py +0 -26
- package/src/tests/samples/functionAnnotation3.py +0 -37
- package/src/tests/samples/functionAnnotation4.py +0 -22
- package/src/tests/samples/functionMember1.py +0 -18
- package/src/tests/samples/functionMember2.py +0 -45
- package/src/tests/samples/generators1.py +0 -122
- package/src/tests/samples/generators10.py +0 -18
- package/src/tests/samples/generators11.py +0 -27
- package/src/tests/samples/generators12.py +0 -25
- package/src/tests/samples/generators13.py +0 -65
- package/src/tests/samples/generators14.py +0 -19
- package/src/tests/samples/generators15.py +0 -26
- package/src/tests/samples/generators2.py +0 -31
- package/src/tests/samples/generators3.py +0 -42
- package/src/tests/samples/generators4.py +0 -33
- package/src/tests/samples/generators5.py +0 -24
- package/src/tests/samples/generators6.py +0 -14
- package/src/tests/samples/generators7.py +0 -18
- package/src/tests/samples/generators8.py +0 -12
- package/src/tests/samples/generators9.py +0 -19
- package/src/tests/samples/generic1.py +0 -41
- package/src/tests/samples/genericTypes1.py +0 -12
- package/src/tests/samples/genericTypes10.py +0 -38
- package/src/tests/samples/genericTypes11.py +0 -26
- package/src/tests/samples/genericTypes12.py +0 -14
- package/src/tests/samples/genericTypes13.py +0 -27
- package/src/tests/samples/genericTypes14.py +0 -22
- package/src/tests/samples/genericTypes15.py +0 -13
- package/src/tests/samples/genericTypes16.py +0 -15
- package/src/tests/samples/genericTypes17.py +0 -24
- package/src/tests/samples/genericTypes18.py +0 -135
- package/src/tests/samples/genericTypes19.py +0 -32
- package/src/tests/samples/genericTypes2.py +0 -40
- package/src/tests/samples/genericTypes20.py +0 -44
- package/src/tests/samples/genericTypes21.py +0 -29
- package/src/tests/samples/genericTypes22.py +0 -23
- package/src/tests/samples/genericTypes23.py +0 -27
- package/src/tests/samples/genericTypes24.py +0 -32
- package/src/tests/samples/genericTypes25.py +0 -37
- package/src/tests/samples/genericTypes26.py +0 -31
- package/src/tests/samples/genericTypes27.py +0 -14
- package/src/tests/samples/genericTypes28.py +0 -51
- package/src/tests/samples/genericTypes29.py +0 -24
- package/src/tests/samples/genericTypes3.py +0 -13
- package/src/tests/samples/genericTypes30.py +0 -32
- package/src/tests/samples/genericTypes31.py +0 -30
- package/src/tests/samples/genericTypes32.py +0 -25
- package/src/tests/samples/genericTypes33.py +0 -46
- package/src/tests/samples/genericTypes34.py +0 -54
- package/src/tests/samples/genericTypes35.py +0 -45
- package/src/tests/samples/genericTypes36.py +0 -35
- package/src/tests/samples/genericTypes37.py +0 -26
- package/src/tests/samples/genericTypes38.py +0 -15
- package/src/tests/samples/genericTypes39.py +0 -82
- package/src/tests/samples/genericTypes4.py +0 -37
- package/src/tests/samples/genericTypes40.py +0 -38
- package/src/tests/samples/genericTypes41.py +0 -16
- package/src/tests/samples/genericTypes42.py +0 -32
- package/src/tests/samples/genericTypes43.py +0 -24
- package/src/tests/samples/genericTypes44.py +0 -33
- package/src/tests/samples/genericTypes45.py +0 -43
- package/src/tests/samples/genericTypes46.py +0 -66
- package/src/tests/samples/genericTypes47.py +0 -39
- package/src/tests/samples/genericTypes48.py +0 -18
- package/src/tests/samples/genericTypes49.py +0 -41
- package/src/tests/samples/genericTypes5.py +0 -42
- package/src/tests/samples/genericTypes50.py +0 -62
- package/src/tests/samples/genericTypes51.py +0 -55
- package/src/tests/samples/genericTypes52.py +0 -34
- package/src/tests/samples/genericTypes53.py +0 -42
- package/src/tests/samples/genericTypes54.py +0 -31
- package/src/tests/samples/genericTypes55.py +0 -61
- package/src/tests/samples/genericTypes56.py +0 -19
- package/src/tests/samples/genericTypes57.py +0 -30
- package/src/tests/samples/genericTypes58.py +0 -52
- package/src/tests/samples/genericTypes59.py +0 -71
- package/src/tests/samples/genericTypes6.py +0 -49
- package/src/tests/samples/genericTypes60.py +0 -27
- package/src/tests/samples/genericTypes61.py +0 -34
- package/src/tests/samples/genericTypes62.py +0 -26
- package/src/tests/samples/genericTypes63.py +0 -32
- package/src/tests/samples/genericTypes64.py +0 -16
- package/src/tests/samples/genericTypes65.py +0 -15
- package/src/tests/samples/genericTypes66.py +0 -30
- package/src/tests/samples/genericTypes67.py +0 -57
- package/src/tests/samples/genericTypes68.py +0 -14
- package/src/tests/samples/genericTypes69.py +0 -45
- package/src/tests/samples/genericTypes7.py +0 -24
- package/src/tests/samples/genericTypes70.py +0 -31
- package/src/tests/samples/genericTypes71.py +0 -72
- package/src/tests/samples/genericTypes72.py +0 -24
- package/src/tests/samples/genericTypes73.py +0 -14
- package/src/tests/samples/genericTypes74.py +0 -23
- package/src/tests/samples/genericTypes75.py +0 -45
- package/src/tests/samples/genericTypes76.py +0 -107
- package/src/tests/samples/genericTypes77.py +0 -26
- package/src/tests/samples/genericTypes78.py +0 -23
- package/src/tests/samples/genericTypes79.py +0 -37
- package/src/tests/samples/genericTypes8.py +0 -26
- package/src/tests/samples/genericTypes80.py +0 -10
- package/src/tests/samples/genericTypes81.py +0 -32
- package/src/tests/samples/genericTypes82.py +0 -19
- package/src/tests/samples/genericTypes83.py +0 -28
- package/src/tests/samples/genericTypes84.py +0 -11
- package/src/tests/samples/genericTypes85.py +0 -20
- package/src/tests/samples/genericTypes86.py +0 -15
- package/src/tests/samples/genericTypes87.py +0 -21
- package/src/tests/samples/genericTypes88.py +0 -25
- package/src/tests/samples/genericTypes89.py +0 -17
- package/src/tests/samples/genericTypes9.py +0 -109
- package/src/tests/samples/genericTypes90.py +0 -12
- package/src/tests/samples/genericTypes91.py +0 -20
- package/src/tests/samples/import1.py +0 -7
- package/src/tests/samples/import10.py +0 -11
- package/src/tests/samples/import11.py +0 -11
- package/src/tests/samples/import12.py +0 -5
- package/src/tests/samples/import13.py +0 -6
- package/src/tests/samples/import14.py +0 -10
- package/src/tests/samples/import2.py +0 -27
- package/src/tests/samples/import3.py +0 -8
- package/src/tests/samples/import4.py +0 -15
- package/src/tests/samples/import5.py +0 -6
- package/src/tests/samples/import6.py +0 -17
- package/src/tests/samples/import7.py +0 -14
- package/src/tests/samples/import8.py +0 -7
- package/src/tests/samples/import9.py +0 -7
- package/src/tests/samples/inconsistentConstructor1.py +0 -23
- package/src/tests/samples/inconsistentSpaceTab1.py +0 -9
- package/src/tests/samples/inconsistentSpaceTab2.py +0 -10
- package/src/tests/samples/index1.py +0 -97
- package/src/tests/samples/inferredTypes1.py +0 -25
- package/src/tests/samples/initVar1.py +0 -23
- package/src/tests/samples/initsubclass1.py +0 -46
- package/src/tests/samples/initsubclass2.py +0 -16
- package/src/tests/samples/isinstance1.py +0 -57
- package/src/tests/samples/isinstance10.py +0 -15
- package/src/tests/samples/isinstance2.py +0 -28
- package/src/tests/samples/isinstance3.py +0 -59
- package/src/tests/samples/isinstance4.py +0 -57
- package/src/tests/samples/isinstance5.py +0 -8
- package/src/tests/samples/isinstance6.py +0 -19
- package/src/tests/samples/isinstance7.py +0 -42
- package/src/tests/samples/isinstance9.py +0 -26
- package/src/tests/samples/kwargsUnpack1.py +0 -116
- package/src/tests/samples/lambda1.py +0 -77
- package/src/tests/samples/lambda2.py +0 -26
- package/src/tests/samples/lambda3.py +0 -34
- package/src/tests/samples/lambda4.py +0 -70
- package/src/tests/samples/lambda5.py +0 -23
- package/src/tests/samples/lambda6.py +0 -15
- package/src/tests/samples/lines1.py +0 -14
- package/src/tests/samples/list1.py +0 -90
- package/src/tests/samples/listComprehension1.py +0 -45
- package/src/tests/samples/listComprehension2.py +0 -17
- package/src/tests/samples/listComprehension3.py +0 -12
- package/src/tests/samples/listComprehension4.py +0 -15
- package/src/tests/samples/listComprehension5.py +0 -20
- package/src/tests/samples/listComprehension6.py +0 -14
- package/src/tests/samples/listComprehension7.py +0 -15
- package/src/tests/samples/listComprehension8.py +0 -15
- package/src/tests/samples/literalString1.py +0 -43
- package/src/tests/samples/literals1.py +0 -48
- package/src/tests/samples/literals2.py +0 -30
- package/src/tests/samples/literals3.py +0 -40
- package/src/tests/samples/literals4.py +0 -10
- package/src/tests/samples/literals5.py +0 -28
- package/src/tests/samples/literals6.py +0 -90
- package/src/tests/samples/literals7.py +0 -38
- package/src/tests/samples/loops1.py +0 -45
- package/src/tests/samples/loops10.py +0 -11
- package/src/tests/samples/loops11.py +0 -22
- package/src/tests/samples/loops12.py +0 -18
- package/src/tests/samples/loops13.py +0 -13
- package/src/tests/samples/loops14.py +0 -22
- package/src/tests/samples/loops15.py +0 -22
- package/src/tests/samples/loops16.py +0 -322
- package/src/tests/samples/loops17.py +0 -9
- package/src/tests/samples/loops18.py +0 -23
- package/src/tests/samples/loops19.py +0 -14
- package/src/tests/samples/loops2.py +0 -25
- package/src/tests/samples/loops20.py +0 -41
- package/src/tests/samples/loops21.py +0 -18
- package/src/tests/samples/loops22.py +0 -21
- package/src/tests/samples/loops23.py +0 -16
- package/src/tests/samples/loops24.py +0 -12
- package/src/tests/samples/loops25.py +0 -45
- package/src/tests/samples/loops26.py +0 -12
- package/src/tests/samples/loops3.py +0 -11
- package/src/tests/samples/loops4.py +0 -17
- package/src/tests/samples/loops5.py +0 -14
- package/src/tests/samples/loops6.py +0 -25
- package/src/tests/samples/loops7.py +0 -14
- package/src/tests/samples/loops8.py +0 -17
- package/src/tests/samples/loops9.py +0 -25
- package/src/tests/samples/match1.py +0 -190
- package/src/tests/samples/match10.py +0 -67
- package/src/tests/samples/match2.py +0 -340
- package/src/tests/samples/match3.py +0 -364
- package/src/tests/samples/match4.py +0 -100
- package/src/tests/samples/match5.py +0 -70
- package/src/tests/samples/match6.py +0 -64
- package/src/tests/samples/match7.py +0 -65
- package/src/tests/samples/match8.py +0 -19
- package/src/tests/samples/match9.py +0 -53
- package/src/tests/samples/maxParseDepth1.py +0 -499
- package/src/tests/samples/maxParseDepth2.py +0 -16
- package/src/tests/samples/memberAccess1.py +0 -70
- package/src/tests/samples/memberAccess10.py +0 -65
- package/src/tests/samples/memberAccess11.py +0 -37
- package/src/tests/samples/memberAccess12.py +0 -36
- package/src/tests/samples/memberAccess13.py +0 -17
- package/src/tests/samples/memberAccess14.py +0 -63
- package/src/tests/samples/memberAccess15.py +0 -20
- package/src/tests/samples/memberAccess16.py +0 -12
- package/src/tests/samples/memberAccess17.py +0 -31
- package/src/tests/samples/memberAccess18.py +0 -31
- package/src/tests/samples/memberAccess2.py +0 -45
- package/src/tests/samples/memberAccess3.py +0 -64
- package/src/tests/samples/memberAccess4.py +0 -91
- package/src/tests/samples/memberAccess5.py +0 -26
- package/src/tests/samples/memberAccess6.py +0 -52
- package/src/tests/samples/memberAccess7.py +0 -36
- package/src/tests/samples/memberAccess8.py +0 -75
- package/src/tests/samples/memberAccess9.py +0 -11
- package/src/tests/samples/metaclass1.py +0 -7
- package/src/tests/samples/metaclass2.py +0 -35
- package/src/tests/samples/metaclass3.py +0 -43
- package/src/tests/samples/metaclass4.py +0 -26
- package/src/tests/samples/metaclass5.py +0 -33
- package/src/tests/samples/metaclass6.py +0 -15
- package/src/tests/samples/metaclass7.py +0 -38
- package/src/tests/samples/metaclass8.py +0 -20
- package/src/tests/samples/metaclass9.py +0 -77
- package/src/tests/samples/methodOverride1.py +0 -507
- package/src/tests/samples/methodOverride2.py +0 -74
- package/src/tests/samples/methodOverride3.py +0 -111
- package/src/tests/samples/methodOverride4.py +0 -36
- package/src/tests/samples/missingSuper1.py +0 -73
- package/src/tests/samples/module1.py +0 -13
- package/src/tests/samples/module2.py +0 -7
- package/src/tests/samples/mro1.py +0 -16
- package/src/tests/samples/mro2.py +0 -45
- package/src/tests/samples/mro3.py +0 -30
- package/src/tests/samples/mro4.py +0 -30
- package/src/tests/samples/nameBindings1.py +0 -48
- package/src/tests/samples/nameBindings2.py +0 -9
- package/src/tests/samples/nameBindings3.py +0 -36
- package/src/tests/samples/nameBindings4.py +0 -10
- package/src/tests/samples/nameBindings5.py +0 -53
- package/src/tests/samples/namedTuples1.py +0 -103
- package/src/tests/samples/namedTuples2.py +0 -56
- package/src/tests/samples/namedTuples3.py +0 -15
- package/src/tests/samples/namedTuples4.py +0 -24
- package/src/tests/samples/namedTuples5.py +0 -15
- package/src/tests/samples/namedTuples6.py +0 -31
- package/src/tests/samples/namedTuples7.py +0 -27
- package/src/tests/samples/never1.py +0 -12
- package/src/tests/samples/never2.py +0 -43
- package/src/tests/samples/newType1.py +0 -34
- package/src/tests/samples/newType2.py +0 -25
- package/src/tests/samples/newType3.py +0 -34
- package/src/tests/samples/newType4.py +0 -8
- package/src/tests/samples/none1.py +0 -29
- package/src/tests/samples/none2.py +0 -22
- package/src/tests/samples/noreturn1.py +0 -78
- package/src/tests/samples/noreturn2.py +0 -37
- package/src/tests/samples/noreturn3.py +0 -16
- package/src/tests/samples/noreturn4.py +0 -29
- package/src/tests/samples/operators1.py +0 -101
- package/src/tests/samples/operators2.py +0 -30
- package/src/tests/samples/operators3.py +0 -8
- package/src/tests/samples/operators4.py +0 -22
- package/src/tests/samples/operators5.py +0 -5
- package/src/tests/samples/operators6.py +0 -10
- package/src/tests/samples/operators7.py +0 -24
- package/src/tests/samples/operators8.py +0 -125
- package/src/tests/samples/optional1.py +0 -77
- package/src/tests/samples/optional2.py +0 -23
- package/src/tests/samples/overload1.py +0 -50
- package/src/tests/samples/overload10.py +0 -48
- package/src/tests/samples/overload2.py +0 -37
- package/src/tests/samples/overload3.py +0 -29
- package/src/tests/samples/overload4.py +0 -46
- package/src/tests/samples/overload5.py +0 -333
- package/src/tests/samples/overload6.py +0 -64
- package/src/tests/samples/overload7.py +0 -376
- package/src/tests/samples/overload8.py +0 -89
- package/src/tests/samples/overload9.py +0 -19
- package/src/tests/samples/package1/__init__.py +0 -3
- package/src/tests/samples/package1/psyche/pysche.py +0 -4
- package/src/tests/samples/package1/psyche.py +0 -4
- package/src/tests/samples/package1/sub/__init__.py +0 -5
- package/src/tests/samples/package1/sub.py +0 -4
- package/src/tests/samples/package1/sub.pyi +0 -2
- package/src/tests/samples/paramInference1.py +0 -27
- package/src/tests/samples/paramNames1.py +0 -39
- package/src/tests/samples/paramSpec1.py +0 -64
- package/src/tests/samples/paramSpec10.py +0 -57
- package/src/tests/samples/paramSpec11.py +0 -36
- package/src/tests/samples/paramSpec12.py +0 -88
- package/src/tests/samples/paramSpec13.py +0 -112
- package/src/tests/samples/paramSpec14.py +0 -30
- package/src/tests/samples/paramSpec15.py +0 -28
- package/src/tests/samples/paramSpec16.py +0 -28
- package/src/tests/samples/paramSpec17.py +0 -34
- package/src/tests/samples/paramSpec18.py +0 -43
- package/src/tests/samples/paramSpec19.py +0 -93
- package/src/tests/samples/paramSpec2.py +0 -29
- package/src/tests/samples/paramSpec20.py +0 -87
- package/src/tests/samples/paramSpec21.py +0 -58
- package/src/tests/samples/paramSpec22.py +0 -26
- package/src/tests/samples/paramSpec23.py +0 -21
- package/src/tests/samples/paramSpec24.py +0 -67
- package/src/tests/samples/paramSpec25.py +0 -36
- package/src/tests/samples/paramSpec26.py +0 -25
- package/src/tests/samples/paramSpec27.py +0 -57
- package/src/tests/samples/paramSpec28.py +0 -39
- package/src/tests/samples/paramSpec29.py +0 -37
- package/src/tests/samples/paramSpec3.py +0 -71
- package/src/tests/samples/paramSpec30.py +0 -49
- package/src/tests/samples/paramSpec31.py +0 -16
- package/src/tests/samples/paramSpec32.py +0 -57
- package/src/tests/samples/paramSpec33.py +0 -29
- package/src/tests/samples/paramSpec34.py +0 -29
- package/src/tests/samples/paramSpec35.py +0 -24
- package/src/tests/samples/paramSpec36.py +0 -43
- package/src/tests/samples/paramSpec37.py +0 -25
- package/src/tests/samples/paramSpec4.py +0 -109
- package/src/tests/samples/paramSpec5.py +0 -29
- package/src/tests/samples/paramSpec6.py +0 -17
- package/src/tests/samples/paramSpec7.py +0 -22
- package/src/tests/samples/paramSpec8.py +0 -45
- package/src/tests/samples/paramSpec9.py +0 -57
- package/src/tests/samples/paramType1.py +0 -71
- package/src/tests/samples/parameters1.py +0 -16
- package/src/tests/samples/partial1.py +0 -163
- package/src/tests/samples/partial2.py +0 -31
- package/src/tests/samples/private1.py +0 -55
- package/src/tests/samples/private2.py +0 -11
- package/src/tests/samples/project1/pyrightconfig.json +0 -5
- package/src/tests/samples/project1/sample1.py +0 -0
- package/src/tests/samples/project1/subfolder1/sample2.py +0 -0
- package/src/tests/samples/project1/subfolder1/subfolder1-1/sample3.py +0 -0
- package/src/tests/samples/project2/pyrightconfig.json +0 -3
- package/src/tests/samples/project3/pyrightconfig.json +0 -7
- package/src/tests/samples/project4/presentfile.py +0 -0
- package/src/tests/samples/project4/pyrightconfig.json +0 -11
- package/src/tests/samples/project4/subfolder/presentfile2.py +0 -0
- package/src/tests/samples/project4/subfolder/presentfile3.py +0 -0
- package/src/tests/samples/project5/pyrightconfig.json +0 -4
- package/src/tests/samples/project6/app1.py +0 -0
- package/src/tests/samples/project6/app2.py +0 -0
- package/src/tests/samples/project6/projectA/foo/__init__.py +0 -0
- package/src/tests/samples/project6/projectA/foo/bar/__init__.py +0 -0
- package/src/tests/samples/project6/projectB/foo/__init__.py +0 -0
- package/src/tests/samples/project6/projectB/foo/baz/__init__.py +0 -0
- package/src/tests/samples/project_src/src/module1.py +0 -0
- package/src/tests/samples/project_src_is_pkg/src/__init__.py +0 -0
- package/src/tests/samples/project_src_is_pkg/src/module1.py +0 -0
- package/src/tests/samples/project_src_with_config_extra_paths/pyrightconfig.json +0 -3
- package/src/tests/samples/project_src_with_config_extra_paths/src/module1.py +0 -0
- package/src/tests/samples/project_src_with_config_no_extra_paths/pyrightconfig.json +0 -2
- package/src/tests/samples/project_src_with_config_no_extra_paths/src/module1.py +0 -0
- package/src/tests/samples/project_src_with_extra_paths/src/_vendored/vendored1.py +0 -1
- package/src/tests/samples/project_src_with_extra_paths/src/module1.py +0 -2
- package/src/tests/samples/project_with_pyproject_toml/pyproject.toml +0 -7
- package/src/tests/samples/project_with_venv_auto_detect_exclude/myvenv/Lib/site-packages/library1.py +0 -0
- package/src/tests/samples/project_with_venv_auto_detect_exclude/myvenv/pyvenv.cfg +0 -0
- package/src/tests/samples/project_with_venv_auto_detect_exclude/pyrightconfig.json +0 -2
- package/src/tests/samples/project_with_venv_auto_detect_exclude/sample1.py +0 -0
- package/src/tests/samples/project_with_venv_auto_detect_exclude/subfolder1/sample2.py +0 -0
- package/src/tests/samples/project_with_venv_auto_detect_exclude/subfolder1/subfolder1-1/sample3.py +0 -0
- package/src/tests/samples/project_with_venv_auto_detect_include/excluded/excluded1.py +0 -0
- package/src/tests/samples/project_with_venv_auto_detect_include/myvenv/Lib/site-packages/library1.py +0 -0
- package/src/tests/samples/project_with_venv_auto_detect_include/myvenv/pyvenv.cfg +0 -0
- package/src/tests/samples/project_with_venv_auto_detect_include/pyrightconfig.json +0 -3
- package/src/tests/samples/project_with_venv_auto_detect_include/sample1.py +0 -0
- package/src/tests/samples/project_with_venv_auto_detect_include/subfolder1/sample2.py +0 -0
- package/src/tests/samples/project_with_venv_auto_detect_include/subfolder1/subfolder1-1/sample3.py +0 -0
- package/src/tests/samples/properties1.py +0 -64
- package/src/tests/samples/properties10.py +0 -19
- package/src/tests/samples/properties11.py +0 -45
- package/src/tests/samples/properties12.py +0 -23
- package/src/tests/samples/properties13.py +0 -15
- package/src/tests/samples/properties2.py +0 -34
- package/src/tests/samples/properties3.py +0 -93
- package/src/tests/samples/properties4.py +0 -17
- package/src/tests/samples/properties5.py +0 -29
- package/src/tests/samples/properties6.py +0 -35
- package/src/tests/samples/properties7.py +0 -30
- package/src/tests/samples/properties8.py +0 -26
- package/src/tests/samples/properties9.py +0 -24
- package/src/tests/samples/protocol1.py +0 -132
- package/src/tests/samples/protocol10.py +0 -36
- package/src/tests/samples/protocol11.py +0 -32
- package/src/tests/samples/protocol12.py +0 -12
- package/src/tests/samples/protocol13.py +0 -26
- package/src/tests/samples/protocol14.py +0 -27
- package/src/tests/samples/protocol15.py +0 -27
- package/src/tests/samples/protocol16.py +0 -22
- package/src/tests/samples/protocol17.py +0 -94
- package/src/tests/samples/protocol18.py +0 -27
- package/src/tests/samples/protocol19.py +0 -39
- package/src/tests/samples/protocol2.py +0 -38
- package/src/tests/samples/protocol20.py +0 -22
- package/src/tests/samples/protocol21.py +0 -26
- package/src/tests/samples/protocol22.py +0 -43
- package/src/tests/samples/protocol23.py +0 -41
- package/src/tests/samples/protocol24.py +0 -74
- package/src/tests/samples/protocol25.py +0 -31
- package/src/tests/samples/protocol26.py +0 -40
- package/src/tests/samples/protocol27.py +0 -76
- package/src/tests/samples/protocol28.py +0 -32
- package/src/tests/samples/protocol29.py +0 -26
- package/src/tests/samples/protocol3.py +0 -110
- package/src/tests/samples/protocol30.py +0 -30
- package/src/tests/samples/protocol31.py +0 -22
- package/src/tests/samples/protocol32.py +0 -67
- package/src/tests/samples/protocol33.py +0 -39
- package/src/tests/samples/protocol34.py +0 -21
- package/src/tests/samples/protocol4.py +0 -22
- package/src/tests/samples/protocol5.py +0 -25
- package/src/tests/samples/protocol6.py +0 -65
- package/src/tests/samples/protocol7.py +0 -24
- package/src/tests/samples/protocol8.py +0 -34
- package/src/tests/samples/protocol9.py +0 -35
- package/src/tests/samples/protocolModule1.py +0 -15
- package/src/tests/samples/protocolModule2.py +0 -83
- package/src/tests/samples/protocolModule3.py +0 -14
- package/src/tests/samples/protocolModule4.py +0 -26
- package/src/tests/samples/pseudoGeneric1.py +0 -20
- package/src/tests/samples/pyrightIgnore1.py +0 -11
- package/src/tests/samples/pyrightIgnore2.py +0 -24
- package/src/tests/samples/python2.py +0 -31
- package/src/tests/samples/recursiveTypeAlias1.py +0 -79
- package/src/tests/samples/recursiveTypeAlias2.py +0 -32
- package/src/tests/samples/recursiveTypeAlias3.py +0 -26
- package/src/tests/samples/recursiveTypeAlias4.py +0 -55
- package/src/tests/samples/recursiveTypeAlias5.pyi +0 -10
- package/src/tests/samples/recursiveTypeAlias6.py +0 -25
- package/src/tests/samples/recursiveTypeAlias7.py +0 -15
- package/src/tests/samples/recursiveTypeAlias8.py +0 -38
- package/src/tests/samples/recursiveTypeAlias9.py +0 -22
- package/src/tests/samples/required1.py +0 -47
- package/src/tests/samples/required2.py +0 -56
- package/src/tests/samples/required3.py +0 -22
- package/src/tests/samples/returnTypes1.py +0 -26
- package/src/tests/samples/revealedType1.py +0 -30
- package/src/tests/samples/sample1.py +0 -6
- package/src/tests/samples/self1.py +0 -93
- package/src/tests/samples/self2.py +0 -195
- package/src/tests/samples/self3.py +0 -9
- package/src/tests/samples/self4.py +0 -18
- package/src/tests/samples/self5.py +0 -26
- package/src/tests/samples/setComprehension1.py +0 -34
- package/src/tests/samples/slots1.py +0 -63
- package/src/tests/samples/slots2.py +0 -38
- package/src/tests/samples/slots3.py +0 -35
- package/src/tests/samples/specialization1.py +0 -78
- package/src/tests/samples/specialization2.py +0 -51
- package/src/tests/samples/staticExpressions1.py +0 -52
- package/src/tests/samples/strings1.py +0 -22
- package/src/tests/samples/subscript1.py +0 -74
- package/src/tests/samples/subscript2.py +0 -55
- package/src/tests/samples/subscript3.py +0 -135
- package/src/tests/samples/suiteExpectedColon1.py +0 -4
- package/src/tests/samples/suiteExpectedColon2.py +0 -2
- package/src/tests/samples/suiteExpectedColon3.py +0 -2
- package/src/tests/samples/super1.py +0 -57
- package/src/tests/samples/super2.py +0 -29
- package/src/tests/samples/super3.py +0 -10
- package/src/tests/samples/super4.py +0 -24
- package/src/tests/samples/super5.py +0 -28
- package/src/tests/samples/super6.py +0 -17
- package/src/tests/samples/super7.py +0 -52
- package/src/tests/samples/super8.py +0 -7
- package/src/tests/samples/super9.py +0 -36
- package/src/tests/samples/test_file1.py +0 -0
- package/src/tests/samples/threePartVersion1.py +0 -33
- package/src/tests/samples/totalOrdering1.py +0 -52
- package/src/tests/samples/tryExcept1.py +0 -39
- package/src/tests/samples/tryExcept10.py +0 -12
- package/src/tests/samples/tryExcept2.py +0 -16
- package/src/tests/samples/tryExcept3.py +0 -12
- package/src/tests/samples/tryExcept4.py +0 -28
- package/src/tests/samples/tryExcept5.py +0 -30
- package/src/tests/samples/tryExcept6.py +0 -27
- package/src/tests/samples/tryExcept7.py +0 -17
- package/src/tests/samples/tryExcept8.py +0 -69
- package/src/tests/samples/tryExcept9.py +0 -42
- package/src/tests/samples/tupleUnpack1.py +0 -63
- package/src/tests/samples/tupleUnpack2.py +0 -56
- package/src/tests/samples/tupleUnpack3.py +0 -28
- package/src/tests/samples/tuples1.py +0 -185
- package/src/tests/samples/tuples10.py +0 -30
- package/src/tests/samples/tuples11.py +0 -21
- package/src/tests/samples/tuples12.py +0 -31
- package/src/tests/samples/tuples13.py +0 -26
- package/src/tests/samples/tuples15.py +0 -16
- package/src/tests/samples/tuples16.py +0 -14
- package/src/tests/samples/tuples2.py +0 -23
- package/src/tests/samples/tuples3.py +0 -15
- package/src/tests/samples/tuples4.py +0 -21
- package/src/tests/samples/tuples5.py +0 -16
- package/src/tests/samples/tuples6.py +0 -56
- package/src/tests/samples/tuples7.py +0 -61
- package/src/tests/samples/tuples8.py +0 -98
- package/src/tests/samples/tuples9.py +0 -17
- package/src/tests/samples/typeAlias1.py +0 -37
- package/src/tests/samples/typeAlias10.py +0 -45
- package/src/tests/samples/typeAlias11.py +0 -37
- package/src/tests/samples/typeAlias12.py +0 -20
- package/src/tests/samples/typeAlias13.py +0 -53
- package/src/tests/samples/typeAlias14.py +0 -29
- package/src/tests/samples/typeAlias15.py +0 -24
- package/src/tests/samples/typeAlias16.py +0 -24
- package/src/tests/samples/typeAlias2.py +0 -26
- package/src/tests/samples/typeAlias3.py +0 -35
- package/src/tests/samples/typeAlias4.py +0 -68
- package/src/tests/samples/typeAlias5.py +0 -56
- package/src/tests/samples/typeAlias6.py +0 -51
- package/src/tests/samples/typeAlias7.py +0 -50
- package/src/tests/samples/typeAlias8.py +0 -24
- package/src/tests/samples/typeAlias9.py +0 -35
- package/src/tests/samples/typeGuard1.py +0 -68
- package/src/tests/samples/typeGuard2.py +0 -58
- package/src/tests/samples/typeGuard3.py +0 -98
- package/src/tests/samples/typeIgnore1.py +0 -10
- package/src/tests/samples/typeIgnore2.py +0 -20
- package/src/tests/samples/typeIgnore3.py +0 -22
- package/src/tests/samples/typeIgnore4.py +0 -10
- package/src/tests/samples/typeIgnore5.py +0 -7
- package/src/tests/samples/typeNarrowing1.py +0 -56
- package/src/tests/samples/typeNarrowing2.py +0 -14
- package/src/tests/samples/typeNarrowing3.py +0 -47
- package/src/tests/samples/typeNarrowing4.py +0 -24
- package/src/tests/samples/typeNarrowing5.py +0 -19
- package/src/tests/samples/typeNarrowing6.py +0 -27
- package/src/tests/samples/typeNarrowing7.py +0 -71
- package/src/tests/samples/typeNarrowingAssert1.py +0 -24
- package/src/tests/samples/typeNarrowingCallable1.py +0 -78
- package/src/tests/samples/typeNarrowingEnum1.py +0 -58
- package/src/tests/samples/typeNarrowingEnum2.py +0 -71
- package/src/tests/samples/typeNarrowingFalsy1.py +0 -50
- package/src/tests/samples/typeNarrowingIn1.py +0 -97
- package/src/tests/samples/typeNarrowingIsNone1.py +0 -56
- package/src/tests/samples/typeNarrowingIsNone2.py +0 -8
- package/src/tests/samples/typeNarrowingIsNoneTuple1.py +0 -42
- package/src/tests/samples/typeNarrowingIsNoneTuple2.py +0 -35
- package/src/tests/samples/typeNarrowingIsinstance1.py +0 -162
- package/src/tests/samples/typeNarrowingIsinstance2.py +0 -14
- package/src/tests/samples/typeNarrowingIsinstance3.py +0 -78
- package/src/tests/samples/typeNarrowingIsinstance4.py +0 -50
- package/src/tests/samples/typeNarrowingIsinstance5.py +0 -39
- package/src/tests/samples/typeNarrowingIsinstance6.py +0 -77
- package/src/tests/samples/typeNarrowingIsinstance7.py +0 -19
- package/src/tests/samples/typeNarrowingIsinstance8.py +0 -19
- package/src/tests/samples/typeNarrowingLiteral1.py +0 -35
- package/src/tests/samples/typeNarrowingLiteral2.py +0 -63
- package/src/tests/samples/typeNarrowingLiteralMember1.py +0 -140
- package/src/tests/samples/typeNarrowingLocalConst1.py +0 -136
- package/src/tests/samples/typeNarrowingNoneMember1.py +0 -102
- package/src/tests/samples/typeNarrowingTuple1.py +0 -23
- package/src/tests/samples/typeNarrowingTupleLength1.py +0 -47
- package/src/tests/samples/typeNarrowingTypeIs1.py +0 -95
- package/src/tests/samples/typeNarrowingTypedDict1.py +0 -99
- package/src/tests/samples/typeNarrowingTypedDict2.py +0 -35
- package/src/tests/samples/typeNarrowingTypedDict3.py +0 -45
- package/src/tests/samples/typePromotions1.py +0 -30
- package/src/tests/samples/typeVar1.py +0 -23
- package/src/tests/samples/typeVar10.py +0 -21
- package/src/tests/samples/typeVar11.py +0 -12
- package/src/tests/samples/typeVar2.py +0 -26
- package/src/tests/samples/typeVar3.py +0 -73
- package/src/tests/samples/typeVar4.py +0 -45
- package/src/tests/samples/typeVar5.py +0 -75
- package/src/tests/samples/typeVar6.py +0 -115
- package/src/tests/samples/typeVar7.py +0 -171
- package/src/tests/samples/typeVar8.py +0 -30
- package/src/tests/samples/typeVar9.py +0 -118
- package/src/tests/samples/typedDict1.py +0 -63
- package/src/tests/samples/typedDict10.py +0 -34
- package/src/tests/samples/typedDict11.py +0 -12
- package/src/tests/samples/typedDict12.py +0 -103
- package/src/tests/samples/typedDict13.py +0 -14
- package/src/tests/samples/typedDict14.py +0 -25
- package/src/tests/samples/typedDict15.py +0 -53
- package/src/tests/samples/typedDict16.py +0 -103
- package/src/tests/samples/typedDict17.py +0 -24
- package/src/tests/samples/typedDict18.py +0 -43
- package/src/tests/samples/typedDict2.py +0 -56
- package/src/tests/samples/typedDict3.py +0 -40
- package/src/tests/samples/typedDict4.py +0 -68
- package/src/tests/samples/typedDict5.py +0 -50
- package/src/tests/samples/typedDict6.py +0 -77
- package/src/tests/samples/typedDict7.py +0 -22
- package/src/tests/samples/typedDict8.py +0 -19
- package/src/tests/samples/typedDict9.py +0 -22
- package/src/tests/samples/unbound1.py +0 -18
- package/src/tests/samples/unbound2.py +0 -12
- package/src/tests/samples/unbound3.py +0 -13
- package/src/tests/samples/unbound4.py +0 -25
- package/src/tests/samples/unicode1.py +0 -39
- package/src/tests/samples/uninitializedVariable1.py +0 -27
- package/src/tests/samples/unions1.py +0 -79
- package/src/tests/samples/unions2.py +0 -15
- package/src/tests/samples/unions3.py +0 -48
- package/src/tests/samples/unions4.py +0 -20
- package/src/tests/samples/unions5.py +0 -43
- package/src/tests/samples/unnecessaryCast1.py +0 -13
- package/src/tests/samples/unnecessaryIsInstance1.py +0 -91
- package/src/tests/samples/unnecessaryIsSubclass1.py +0 -22
- package/src/tests/samples/unpack1.py +0 -56
- package/src/tests/samples/unpack2.py +0 -27
- package/src/tests/samples/unpack3.py +0 -16
- package/src/tests/samples/unpack4.py +0 -15
- package/src/tests/samples/unreachable1.py +0 -112
- package/src/tests/samples/unusedCallResult1.py +0 -67
- package/src/tests/samples/unusedCoroutine1.py +0 -23
- package/src/tests/samples/unusedExpression1.py +0 -34
- package/src/tests/samples/unusedVariable1.py +0 -21
- package/src/tests/samples/variadicTypeVar1.py +0 -51
- package/src/tests/samples/variadicTypeVar10.py +0 -65
- package/src/tests/samples/variadicTypeVar11.py +0 -72
- package/src/tests/samples/variadicTypeVar12.py +0 -26
- package/src/tests/samples/variadicTypeVar13.py +0 -35
- package/src/tests/samples/variadicTypeVar14.py +0 -72
- package/src/tests/samples/variadicTypeVar2.py +0 -63
- package/src/tests/samples/variadicTypeVar3.py +0 -86
- package/src/tests/samples/variadicTypeVar4.py +0 -71
- package/src/tests/samples/variadicTypeVar5.py +0 -131
- package/src/tests/samples/variadicTypeVar6.py +0 -78
- package/src/tests/samples/variadicTypeVar7.py +0 -59
- package/src/tests/samples/variadicTypeVar8.py +0 -116
- package/src/tests/samples/variadicTypeVar9.py +0 -38
- package/src/tests/samples/with1.py +0 -117
- package/src/tests/samples/with2.py +0 -63
- package/src/tests/samples/with3.py +0 -66
- package/src/tests/samples/with4.py +0 -24
- package/src/tests/samples/with5.py +0 -33
- package/src/tests/samples/zipfs/bad.egg +0 -1
- package/src/tests/samples/zipfs/bad.zip +0 -1
- package/src/tests/samples/zipfs/basic.egg +0 -0
- package/src/tests/samples/zipfs/basic.zip +0 -0
- package/src/tests/samples/zipfs/corrupt.egg +0 -0
- package/src/tests/samples/zipfs/corrupt.zip +0 -0
- package/src/tests/sourceFile.test.ts +0 -25
- package/src/tests/stringUtils.test.ts +0 -63
- package/src/tests/symbolNameUtils.test.ts +0 -77
- package/src/tests/testState.test.ts +0 -579
- package/src/tests/testUtils.ts +0 -251
- package/src/tests/tokenizer.test.ts +0 -1534
- package/src/tests/typeEvaluator1.test.ts +0 -1372
- package/src/tests/typeEvaluator2.test.ts +0 -1253
- package/src/tests/typeEvaluator3.test.ts +0 -1279
- package/src/tests/typeEvaluator4.test.ts +0 -1178
- package/src/tests/updateSymbolReference.test.ts +0 -1107
- package/src/tests/zipfs.test.ts +0 -116
- package/src/workspaceMap.ts +0 -76
@@ -1,3126 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* typeUtils.ts
|
3
|
-
* Copyright (c) Microsoft Corporation.
|
4
|
-
* Licensed under the MIT license.
|
5
|
-
* Author: Eric Traut
|
6
|
-
*
|
7
|
-
* Collection of functions that operate on Type objects.
|
8
|
-
*/
|
9
|
-
|
10
|
-
import { appendArray } from '../common/collectionUtils';
|
11
|
-
import { assert } from '../common/debug';
|
12
|
-
import { ParameterCategory } from '../parser/parseNodes';
|
13
|
-
import { DeclarationType } from './declaration';
|
14
|
-
import { Symbol, SymbolFlags, SymbolTable } from './symbol';
|
15
|
-
import { isDunderName } from './symbolNameUtils';
|
16
|
-
import { isTypedDictMemberAccessedThroughIndex } from './symbolUtils';
|
17
|
-
import {
|
18
|
-
AnyType,
|
19
|
-
ClassType,
|
20
|
-
combineTypes,
|
21
|
-
findSubtype,
|
22
|
-
FunctionParameter,
|
23
|
-
FunctionType,
|
24
|
-
FunctionTypeFlags,
|
25
|
-
isAny,
|
26
|
-
isAnyOrUnknown,
|
27
|
-
isClass,
|
28
|
-
isClassInstance,
|
29
|
-
isFunction,
|
30
|
-
isInstantiableClass,
|
31
|
-
isNever,
|
32
|
-
isNoneInstance,
|
33
|
-
isOverloadedFunction,
|
34
|
-
isParamSpec,
|
35
|
-
isTypeSame,
|
36
|
-
isTypeVar,
|
37
|
-
isUnbound,
|
38
|
-
isUnion,
|
39
|
-
isUnknown,
|
40
|
-
isUnpackedClass,
|
41
|
-
isVariadicTypeVar,
|
42
|
-
maxTypeRecursionCount,
|
43
|
-
ModuleType,
|
44
|
-
NeverType,
|
45
|
-
NoneType,
|
46
|
-
OverloadedFunctionType,
|
47
|
-
ParamSpecEntry,
|
48
|
-
ParamSpecValue,
|
49
|
-
SpecializedFunctionTypes,
|
50
|
-
TupleTypeArgument,
|
51
|
-
Type,
|
52
|
-
TypeBase,
|
53
|
-
TypeCategory,
|
54
|
-
TypeCondition,
|
55
|
-
TypeFlags,
|
56
|
-
TypeVarScopeId,
|
57
|
-
TypeVarType,
|
58
|
-
UnionType,
|
59
|
-
UnknownType,
|
60
|
-
WildcardTypeVarScopeId,
|
61
|
-
} from './types';
|
62
|
-
import { TypeVarContext } from './typeVarContext';
|
63
|
-
|
64
|
-
export interface ClassMember {
|
65
|
-
// Symbol
|
66
|
-
symbol: Symbol;
|
67
|
-
|
68
|
-
// Partially-specialized class that contains the class member
|
69
|
-
classType: ClassType | UnknownType;
|
70
|
-
|
71
|
-
// True if it is an instance or class member; it can be both a class and
|
72
|
-
// an instance member in cases where a class variable is overridden
|
73
|
-
// by an instance variable
|
74
|
-
isInstanceMember: boolean;
|
75
|
-
isClassMember: boolean;
|
76
|
-
|
77
|
-
// True if explicitly declared as "ClassVar" and therefore is
|
78
|
-
// a type violation if it is overwritten by an instance variable
|
79
|
-
isClassVar: boolean;
|
80
|
-
|
81
|
-
// True if member has declared type, false if inferred
|
82
|
-
isTypeDeclared: boolean;
|
83
|
-
|
84
|
-
// True if member lookup skipped an undeclared (inferred) type
|
85
|
-
// in a subclass before finding a declared type in a base class
|
86
|
-
skippedUndeclaredType: boolean;
|
87
|
-
}
|
88
|
-
|
89
|
-
export const enum ClassMemberLookupFlags {
|
90
|
-
Default = 0,
|
91
|
-
|
92
|
-
// By default, the original (derived) class is searched along
|
93
|
-
// with its base classes. If this flag is set, the original
|
94
|
-
// class is skipped and only the base classes are searched.
|
95
|
-
SkipOriginalClass = 1 << 0,
|
96
|
-
|
97
|
-
// By default, base classes are searched as well as the
|
98
|
-
// original (derived) class. If this flag is set, no recursion
|
99
|
-
// is performed.
|
100
|
-
SkipBaseClasses = 1 << 1,
|
101
|
-
|
102
|
-
// Skip the 'object' base class in particular.
|
103
|
-
SkipObjectBaseClass = 1 << 2,
|
104
|
-
|
105
|
-
// By default, both class and instance variables are searched.
|
106
|
-
// If this flag is set, the instance variables are skipped.
|
107
|
-
SkipInstanceVariables = 1 << 3,
|
108
|
-
|
109
|
-
// By default, the first symbol is returned even if it has only
|
110
|
-
// an inferred type associated with it. If this flag is set,
|
111
|
-
// the search looks only for symbols with declared types.
|
112
|
-
DeclaredTypesOnly = 1 << 4,
|
113
|
-
|
114
|
-
// Skip the 'type' base class in particular.
|
115
|
-
SkipTypeBaseClass = 1 << 5,
|
116
|
-
}
|
117
|
-
|
118
|
-
export const enum ClassIteratorFlags {
|
119
|
-
Default = 0,
|
120
|
-
|
121
|
-
// By default, the original (derived) class is searched along
|
122
|
-
// with its base classes. If this flag is set, the original
|
123
|
-
// class is skipped and only the base classes are searched.
|
124
|
-
SkipOriginalClass = 1 << 0,
|
125
|
-
|
126
|
-
// By default, base classes are searched as well as the
|
127
|
-
// original (derived) class. If this flag is set, no recursion
|
128
|
-
// is performed.
|
129
|
-
SkipBaseClasses = 1 << 1,
|
130
|
-
|
131
|
-
// Skip the 'object' base class in particular.
|
132
|
-
SkipObjectBaseClass = 1 << 2,
|
133
|
-
|
134
|
-
// Skip the 'type' base class in particular.
|
135
|
-
SkipTypeBaseClass = 1 << 3,
|
136
|
-
}
|
137
|
-
|
138
|
-
export const enum AssignTypeFlags {
|
139
|
-
Default = 0,
|
140
|
-
|
141
|
-
// Require invariance with respect to class matching? Normally
|
142
|
-
// subclasses are allowed.
|
143
|
-
EnforceInvariance = 1 << 0,
|
144
|
-
|
145
|
-
// The caller has swapped the source and dest types because
|
146
|
-
// the types are contravariant. Perform type var matching
|
147
|
-
// on dest type vars rather than source type var.
|
148
|
-
ReverseTypeVarMatching = 1 << 1,
|
149
|
-
|
150
|
-
// Normally invariant and contravariant TypeVars cannot be
|
151
|
-
// narrowed. This overrides the standard behavior.
|
152
|
-
AllowTypeVarNarrowing = 1 << 2,
|
153
|
-
|
154
|
-
// Normally type vars are treated as variables that need to
|
155
|
-
// be "solved". If this flag is set, they are treated as types
|
156
|
-
// that must match. It is used for overload consistency checking.
|
157
|
-
SkipSolveTypeVars = 1 << 3,
|
158
|
-
|
159
|
-
// If the dest is not Any but the src is Any, treat it
|
160
|
-
// as incompatible. Also, treat all source TypeVars as their
|
161
|
-
// concrete counterparts. This option is used for validating
|
162
|
-
// whether overload signatures overlap.
|
163
|
-
OverloadOverlapCheck = 1 << 4,
|
164
|
-
|
165
|
-
// For function types, skip the return type check.
|
166
|
-
SkipFunctionReturnTypeCheck = 1 << 5,
|
167
|
-
|
168
|
-
// Allow bool values to be assigned to TypeGuard[x] types.
|
169
|
-
AllowBoolTypeGuard = 1 << 6,
|
170
|
-
|
171
|
-
// In most cases, literals are stripped when assigning to a
|
172
|
-
// type variable. This overrides the standard behavior.
|
173
|
-
RetainLiteralsForTypeVar = 1 << 7,
|
174
|
-
|
175
|
-
// When validating the type of a self or cls parameter, allow
|
176
|
-
// a type mismatch. This is used in overload consistency validation
|
177
|
-
// because overloads can provide explicit type annotations for self
|
178
|
-
// or cls.
|
179
|
-
SkipSelfClsTypeCheck = 1 << 8,
|
180
|
-
|
181
|
-
// If an assignment is made to a TypeVar that is out of scope,
|
182
|
-
// do not generate an error. This is used for populating the
|
183
|
-
// typeVarContext when handling contravariant parameters in a callable.
|
184
|
-
IgnoreTypeVarScope = 1 << 9,
|
185
|
-
|
186
|
-
// We're initially populating the typeVarContext with an expected type,
|
187
|
-
// so TypeVars should match the specified type exactly rather than
|
188
|
-
// employing narrowing or widening, and don't strip literals.
|
189
|
-
PopulatingExpectedType = 1 << 10,
|
190
|
-
|
191
|
-
// We're comparing type compatibility of two distinct recursive types.
|
192
|
-
// This has the potential of recursing infinitely. This flag allows us
|
193
|
-
// to detect the recursion after the first level of checking.
|
194
|
-
SkipRecursiveTypeCheck = 1 << 11,
|
195
|
-
}
|
196
|
-
|
197
|
-
export enum ParameterSource {
|
198
|
-
PositionOnly,
|
199
|
-
PositionOrKeyword,
|
200
|
-
KeywordOnly,
|
201
|
-
}
|
202
|
-
|
203
|
-
export interface VirtualParameterDetails {
|
204
|
-
param: FunctionParameter;
|
205
|
-
type: Type;
|
206
|
-
defaultArgType?: Type | undefined;
|
207
|
-
index: number;
|
208
|
-
source: ParameterSource;
|
209
|
-
}
|
210
|
-
|
211
|
-
export interface ParameterListDetails {
|
212
|
-
// Virtual parameter list that refers to original parameters
|
213
|
-
params: VirtualParameterDetails[];
|
214
|
-
|
215
|
-
// Counts of virtual parameters
|
216
|
-
positionOnlyParamCount: number;
|
217
|
-
positionParamCount: number;
|
218
|
-
|
219
|
-
// Indexes into virtual parameter list
|
220
|
-
kwargsIndex?: number;
|
221
|
-
argsIndex?: number;
|
222
|
-
firstKeywordOnlyIndex?: number;
|
223
|
-
firstPositionOrKeywordIndex: number;
|
224
|
-
|
225
|
-
// Other information
|
226
|
-
hasUnpackedVariadicTypeVar: boolean;
|
227
|
-
hasUnpackedTypedDict: boolean;
|
228
|
-
}
|
229
|
-
|
230
|
-
// Examines the input parameters within a function signature and creates a
|
231
|
-
// "virtual list" of parameters, stripping out any markers and expanding
|
232
|
-
// any *args with unpacked tuples.
|
233
|
-
export function getParameterListDetails(type: FunctionType): ParameterListDetails {
|
234
|
-
const result: ParameterListDetails = {
|
235
|
-
firstPositionOrKeywordIndex: 0,
|
236
|
-
positionParamCount: 0,
|
237
|
-
positionOnlyParamCount: 0,
|
238
|
-
params: [],
|
239
|
-
hasUnpackedVariadicTypeVar: false,
|
240
|
-
hasUnpackedTypedDict: false,
|
241
|
-
};
|
242
|
-
|
243
|
-
let positionOnlyIndex = type.details.parameters.findIndex(
|
244
|
-
(p) => p.category === ParameterCategory.Simple && !p.name
|
245
|
-
);
|
246
|
-
|
247
|
-
// Handle the old (pre Python 3.8) way of specifying positional-only
|
248
|
-
// parameters by naming them with "__".
|
249
|
-
if (positionOnlyIndex < 0) {
|
250
|
-
for (let i = 0; i < type.details.parameters.length; i++) {
|
251
|
-
const p = type.details.parameters[i];
|
252
|
-
if (p.category !== ParameterCategory.Simple) {
|
253
|
-
break;
|
254
|
-
}
|
255
|
-
|
256
|
-
if (!p.name) {
|
257
|
-
break;
|
258
|
-
}
|
259
|
-
|
260
|
-
if (isDunderName(p.name) || !p.name.startsWith('__')) {
|
261
|
-
break;
|
262
|
-
}
|
263
|
-
|
264
|
-
positionOnlyIndex = i + 1;
|
265
|
-
}
|
266
|
-
}
|
267
|
-
|
268
|
-
if (positionOnlyIndex >= 0) {
|
269
|
-
result.firstPositionOrKeywordIndex = positionOnlyIndex;
|
270
|
-
}
|
271
|
-
|
272
|
-
for (let i = 0; i < positionOnlyIndex; i++) {
|
273
|
-
if (type.details.parameters[i].hasDefault) {
|
274
|
-
break;
|
275
|
-
}
|
276
|
-
|
277
|
-
result.positionOnlyParamCount++;
|
278
|
-
}
|
279
|
-
|
280
|
-
let sawKeywordOnlySeparator = false;
|
281
|
-
|
282
|
-
const addVirtualParameter = (
|
283
|
-
param: FunctionParameter,
|
284
|
-
index: number,
|
285
|
-
typeOverride?: Type,
|
286
|
-
defaultArgTypeOverride?: Type
|
287
|
-
) => {
|
288
|
-
if (param.name) {
|
289
|
-
let source: ParameterSource;
|
290
|
-
if (param.category === ParameterCategory.VarArgList) {
|
291
|
-
source = ParameterSource.PositionOnly;
|
292
|
-
} else if (sawKeywordOnlySeparator) {
|
293
|
-
source = ParameterSource.KeywordOnly;
|
294
|
-
} else if (positionOnlyIndex >= 0 && index < positionOnlyIndex) {
|
295
|
-
source = ParameterSource.PositionOnly;
|
296
|
-
} else {
|
297
|
-
source = ParameterSource.PositionOrKeyword;
|
298
|
-
}
|
299
|
-
|
300
|
-
result.params.push({
|
301
|
-
param,
|
302
|
-
index,
|
303
|
-
type: typeOverride ?? FunctionType.getEffectiveParameterType(type, index),
|
304
|
-
defaultArgType: defaultArgTypeOverride,
|
305
|
-
source,
|
306
|
-
});
|
307
|
-
}
|
308
|
-
};
|
309
|
-
|
310
|
-
type.details.parameters.forEach((param, index) => {
|
311
|
-
if (param.category === ParameterCategory.VarArgList) {
|
312
|
-
// If this is an unpacked tuple, expand the entries.
|
313
|
-
const paramType = FunctionType.getEffectiveParameterType(type, index);
|
314
|
-
if (param.name && isUnpackedClass(paramType) && paramType.tupleTypeArguments) {
|
315
|
-
paramType.tupleTypeArguments.forEach((tupleArg, index) => {
|
316
|
-
const category =
|
317
|
-
isVariadicTypeVar(tupleArg.type) || tupleArg.isUnbounded
|
318
|
-
? ParameterCategory.VarArgList
|
319
|
-
: ParameterCategory.Simple;
|
320
|
-
|
321
|
-
if (category === ParameterCategory.VarArgList) {
|
322
|
-
result.argsIndex = result.params.length;
|
323
|
-
}
|
324
|
-
|
325
|
-
if (isVariadicTypeVar(param.type)) {
|
326
|
-
result.hasUnpackedVariadicTypeVar = true;
|
327
|
-
}
|
328
|
-
|
329
|
-
addVirtualParameter(
|
330
|
-
{
|
331
|
-
category,
|
332
|
-
name: `${param.name}[${index.toString()}]`,
|
333
|
-
isNameSynthesized: true,
|
334
|
-
type: tupleArg.type,
|
335
|
-
hasDeclaredType: true,
|
336
|
-
},
|
337
|
-
index,
|
338
|
-
tupleArg.type
|
339
|
-
);
|
340
|
-
});
|
341
|
-
} else {
|
342
|
-
if (param.name && result.argsIndex === undefined) {
|
343
|
-
result.argsIndex = result.params.length;
|
344
|
-
|
345
|
-
if (isVariadicTypeVar(param.type)) {
|
346
|
-
result.hasUnpackedVariadicTypeVar = true;
|
347
|
-
}
|
348
|
-
}
|
349
|
-
|
350
|
-
// Normally, a VarArgList parameter (either named or as an unnamed separator)
|
351
|
-
// would signify the start of keyword-only parameters. However, we can construct
|
352
|
-
// callable signatures that defy this rule by using Callable and TypeVarTuples
|
353
|
-
// or unpacked tuples.
|
354
|
-
if (!sawKeywordOnlySeparator && (positionOnlyIndex < 0 || index >= positionOnlyIndex)) {
|
355
|
-
result.firstKeywordOnlyIndex = result.params.length;
|
356
|
-
if (param.name) {
|
357
|
-
result.firstKeywordOnlyIndex++;
|
358
|
-
}
|
359
|
-
sawKeywordOnlySeparator = true;
|
360
|
-
}
|
361
|
-
|
362
|
-
addVirtualParameter(param, index);
|
363
|
-
}
|
364
|
-
} else if (param.category === ParameterCategory.VarArgDictionary) {
|
365
|
-
sawKeywordOnlySeparator = true;
|
366
|
-
|
367
|
-
// Is this an unpacked TypedDict? If so, expand the entries.
|
368
|
-
if (isClassInstance(param.type) && isUnpackedClass(param.type) && param.type.details.typedDictEntries) {
|
369
|
-
if (result.firstKeywordOnlyIndex === undefined) {
|
370
|
-
result.firstKeywordOnlyIndex = result.params.length;
|
371
|
-
}
|
372
|
-
|
373
|
-
param.type.details.typedDictEntries.forEach((entry, name) => {
|
374
|
-
addVirtualParameter(
|
375
|
-
{
|
376
|
-
category: ParameterCategory.Simple,
|
377
|
-
name,
|
378
|
-
type: entry.valueType,
|
379
|
-
hasDeclaredType: true,
|
380
|
-
hasDefault: !entry.isRequired,
|
381
|
-
},
|
382
|
-
index,
|
383
|
-
entry.valueType
|
384
|
-
);
|
385
|
-
});
|
386
|
-
|
387
|
-
result.hasUnpackedTypedDict = true;
|
388
|
-
} else if (param.name) {
|
389
|
-
if (result.kwargsIndex === undefined) {
|
390
|
-
result.kwargsIndex = result.params.length;
|
391
|
-
}
|
392
|
-
|
393
|
-
if (result.firstKeywordOnlyIndex === undefined) {
|
394
|
-
result.firstKeywordOnlyIndex = result.params.length;
|
395
|
-
}
|
396
|
-
|
397
|
-
addVirtualParameter(param, index);
|
398
|
-
}
|
399
|
-
} else if (param.category === ParameterCategory.Simple) {
|
400
|
-
if (param.name && !sawKeywordOnlySeparator) {
|
401
|
-
result.positionParamCount++;
|
402
|
-
}
|
403
|
-
|
404
|
-
addVirtualParameter(
|
405
|
-
param,
|
406
|
-
index,
|
407
|
-
/* typeOverride */ undefined,
|
408
|
-
type.specializedTypes?.parameterDefaultArgs
|
409
|
-
? type.specializedTypes?.parameterDefaultArgs[index]
|
410
|
-
: undefined
|
411
|
-
);
|
412
|
-
}
|
413
|
-
});
|
414
|
-
|
415
|
-
return result;
|
416
|
-
}
|
417
|
-
|
418
|
-
export function isOptionalType(type: Type): boolean {
|
419
|
-
if (isUnion(type)) {
|
420
|
-
return findSubtype(type, (subtype) => isNoneInstance(subtype)) !== undefined;
|
421
|
-
}
|
422
|
-
|
423
|
-
return false;
|
424
|
-
}
|
425
|
-
|
426
|
-
// Calls a callback for each subtype and combines the results
|
427
|
-
// into a final type.
|
428
|
-
export function mapSubtypes(type: Type, callback: (type: Type) => Type | undefined): Type {
|
429
|
-
if (isUnion(type)) {
|
430
|
-
const newSubtypes: Type[] = [];
|
431
|
-
let typeChanged = false;
|
432
|
-
|
433
|
-
type.subtypes.forEach((subtype) => {
|
434
|
-
const transformedType = callback(subtype);
|
435
|
-
if (transformedType) {
|
436
|
-
if (transformedType !== subtype) {
|
437
|
-
newSubtypes.push(addConditionToType(transformedType, getTypeCondition(type)));
|
438
|
-
typeChanged = true;
|
439
|
-
} else {
|
440
|
-
newSubtypes.push(subtype);
|
441
|
-
}
|
442
|
-
} else {
|
443
|
-
typeChanged = true;
|
444
|
-
}
|
445
|
-
});
|
446
|
-
|
447
|
-
if (!typeChanged) {
|
448
|
-
return type;
|
449
|
-
}
|
450
|
-
|
451
|
-
const newType = combineTypes(newSubtypes);
|
452
|
-
|
453
|
-
// Do our best to retain type aliases.
|
454
|
-
if (newType.category === TypeCategory.Union) {
|
455
|
-
UnionType.addTypeAliasSource(newType, type);
|
456
|
-
}
|
457
|
-
return newType;
|
458
|
-
}
|
459
|
-
|
460
|
-
const transformedSubtype = callback(type);
|
461
|
-
if (!transformedSubtype) {
|
462
|
-
return NeverType.createNever();
|
463
|
-
}
|
464
|
-
return transformedSubtype;
|
465
|
-
}
|
466
|
-
|
467
|
-
export function doForEachSubtype(type: Type, callback: (type: Type, index: number) => void): void {
|
468
|
-
if (isUnion(type)) {
|
469
|
-
type.subtypes.forEach((subtype, index) => {
|
470
|
-
callback(subtype, index);
|
471
|
-
});
|
472
|
-
} else {
|
473
|
-
callback(type, 0);
|
474
|
-
}
|
475
|
-
}
|
476
|
-
|
477
|
-
// Determines if all of the types in the array are the same.
|
478
|
-
export function areTypesSame(types: Type[], ignorePseudoGeneric: boolean): boolean {
|
479
|
-
if (types.length < 2) {
|
480
|
-
return true;
|
481
|
-
}
|
482
|
-
|
483
|
-
for (let i = 1; i < types.length; i++) {
|
484
|
-
if (!isTypeSame(types[0], types[i], ignorePseudoGeneric)) {
|
485
|
-
return false;
|
486
|
-
}
|
487
|
-
}
|
488
|
-
|
489
|
-
return true;
|
490
|
-
}
|
491
|
-
|
492
|
-
// If either type is "Unknown" (versus Any), propagate the Unknown. Preserve
|
493
|
-
// the incomplete flag on the unknown if present. The caller should verify that
|
494
|
-
// one or the other type is Unknown or Any.
|
495
|
-
export function preserveUnknown(type1: Type, type2: Type): AnyType | UnknownType {
|
496
|
-
if (isUnknown(type1) && type1.isIncomplete) {
|
497
|
-
return type1;
|
498
|
-
} else if (isUnknown(type2) && type2.isIncomplete) {
|
499
|
-
return type2;
|
500
|
-
} else if (isUnknown(type1) || isUnknown(type2)) {
|
501
|
-
return UnknownType.create();
|
502
|
-
} else {
|
503
|
-
return AnyType.create();
|
504
|
-
}
|
505
|
-
}
|
506
|
-
|
507
|
-
// Determines whether the specified type is a type that can be
|
508
|
-
// combined with other types for a union.
|
509
|
-
export function isUnionableType(subtypes: Type[]): boolean {
|
510
|
-
let typeFlags = TypeFlags.Instance | TypeFlags.Instantiable;
|
511
|
-
|
512
|
-
for (const subtype of subtypes) {
|
513
|
-
typeFlags &= subtype.flags;
|
514
|
-
}
|
515
|
-
|
516
|
-
// All subtypes need to be instantiable. Some types (like Any
|
517
|
-
// and None) are both instances and instantiable. It's OK to
|
518
|
-
// include some of these, but at least one subtype needs to
|
519
|
-
// be definitively instantiable (not an instance).
|
520
|
-
return (typeFlags & TypeFlags.Instantiable) !== 0 && (typeFlags & TypeFlags.Instance) === 0;
|
521
|
-
}
|
522
|
-
|
523
|
-
export function derivesFromAnyOrUnknown(type: Type): boolean {
|
524
|
-
let anyOrUnknown = false;
|
525
|
-
|
526
|
-
doForEachSubtype(type, (subtype) => {
|
527
|
-
if (isAnyOrUnknown(type)) {
|
528
|
-
anyOrUnknown = true;
|
529
|
-
} else if (isInstantiableClass(subtype)) {
|
530
|
-
if (ClassType.hasUnknownBaseClass(subtype)) {
|
531
|
-
anyOrUnknown = true;
|
532
|
-
}
|
533
|
-
} else if (isClassInstance(subtype)) {
|
534
|
-
if (ClassType.hasUnknownBaseClass(subtype)) {
|
535
|
-
anyOrUnknown = true;
|
536
|
-
}
|
537
|
-
}
|
538
|
-
});
|
539
|
-
|
540
|
-
return anyOrUnknown;
|
541
|
-
}
|
542
|
-
|
543
|
-
export function getFullNameOfType(type: Type): string | undefined {
|
544
|
-
if (type.typeAliasInfo?.fullName) {
|
545
|
-
return type.typeAliasInfo.fullName;
|
546
|
-
}
|
547
|
-
|
548
|
-
switch (type.category) {
|
549
|
-
case TypeCategory.Any:
|
550
|
-
case TypeCategory.Unknown:
|
551
|
-
return 'typing.Any';
|
552
|
-
|
553
|
-
case TypeCategory.None:
|
554
|
-
return 'builtins.None';
|
555
|
-
|
556
|
-
case TypeCategory.Class:
|
557
|
-
return type.details.fullName;
|
558
|
-
|
559
|
-
case TypeCategory.Function:
|
560
|
-
return type.details.fullName;
|
561
|
-
|
562
|
-
case TypeCategory.Module:
|
563
|
-
return type.moduleName;
|
564
|
-
|
565
|
-
case TypeCategory.OverloadedFunction:
|
566
|
-
return type.overloads[0].details.fullName;
|
567
|
-
}
|
568
|
-
|
569
|
-
return undefined;
|
570
|
-
}
|
571
|
-
|
572
|
-
export function stripLiteralValue(type: Type): Type {
|
573
|
-
if (isClass(type)) {
|
574
|
-
if (type.literalValue !== undefined) {
|
575
|
-
type = ClassType.cloneWithLiteral(type, /* value */ undefined);
|
576
|
-
}
|
577
|
-
|
578
|
-
return type;
|
579
|
-
}
|
580
|
-
|
581
|
-
if (isUnion(type)) {
|
582
|
-
return mapSubtypes(type, (subtype) => {
|
583
|
-
return stripLiteralValue(subtype);
|
584
|
-
});
|
585
|
-
}
|
586
|
-
|
587
|
-
return type;
|
588
|
-
}
|
589
|
-
|
590
|
-
export function addConditionToType(type: Type, condition: TypeCondition[] | undefined): Type {
|
591
|
-
if (!condition) {
|
592
|
-
return type;
|
593
|
-
}
|
594
|
-
|
595
|
-
switch (type.category) {
|
596
|
-
case TypeCategory.Unbound:
|
597
|
-
case TypeCategory.Unknown:
|
598
|
-
case TypeCategory.Any:
|
599
|
-
case TypeCategory.Never:
|
600
|
-
case TypeCategory.Module:
|
601
|
-
case TypeCategory.TypeVar:
|
602
|
-
return type;
|
603
|
-
|
604
|
-
case TypeCategory.None:
|
605
|
-
case TypeCategory.Function:
|
606
|
-
return TypeBase.cloneForCondition(type, TypeCondition.combine(type.condition, condition));
|
607
|
-
|
608
|
-
case TypeCategory.OverloadedFunction:
|
609
|
-
return OverloadedFunctionType.create(
|
610
|
-
type.overloads.map((t) => addConditionToType(t, condition) as FunctionType)
|
611
|
-
);
|
612
|
-
|
613
|
-
case TypeCategory.Class:
|
614
|
-
return TypeBase.cloneForCondition(type, TypeCondition.combine(type.condition, condition));
|
615
|
-
|
616
|
-
case TypeCategory.Union:
|
617
|
-
return combineTypes(type.subtypes.map((t) => addConditionToType(t, condition)));
|
618
|
-
}
|
619
|
-
}
|
620
|
-
|
621
|
-
export function getTypeCondition(type: Type): TypeCondition[] | undefined {
|
622
|
-
switch (type.category) {
|
623
|
-
case TypeCategory.Unbound:
|
624
|
-
case TypeCategory.Unknown:
|
625
|
-
case TypeCategory.Any:
|
626
|
-
case TypeCategory.Never:
|
627
|
-
case TypeCategory.Module:
|
628
|
-
case TypeCategory.TypeVar:
|
629
|
-
case TypeCategory.OverloadedFunction:
|
630
|
-
case TypeCategory.Union:
|
631
|
-
return undefined;
|
632
|
-
|
633
|
-
case TypeCategory.None:
|
634
|
-
case TypeCategory.Class:
|
635
|
-
case TypeCategory.Function:
|
636
|
-
return type.condition;
|
637
|
-
}
|
638
|
-
}
|
639
|
-
|
640
|
-
// Indicates whether the specified type is a recursive type alias
|
641
|
-
// placeholder that has not yet been resolved.
|
642
|
-
export function isTypeAliasPlaceholder(type: Type): type is TypeVarType {
|
643
|
-
if (!isTypeVar(type)) {
|
644
|
-
return false;
|
645
|
-
}
|
646
|
-
|
647
|
-
return !!type.details.recursiveTypeAliasName && !type.details.boundType;
|
648
|
-
}
|
649
|
-
|
650
|
-
// Determines whether the type alias placeholder is used directly
|
651
|
-
// within the specified type. It's OK if it's used indirectly as
|
652
|
-
// a type argument.
|
653
|
-
export function isTypeAliasRecursive(typeAliasPlaceholder: TypeVarType, type: Type) {
|
654
|
-
if (type.category !== TypeCategory.Union) {
|
655
|
-
if (type === typeAliasPlaceholder) {
|
656
|
-
return true;
|
657
|
-
}
|
658
|
-
|
659
|
-
// Handle the specific case where the type alias directly refers to itself.
|
660
|
-
// In this case, the type will be unbound because it could not be resolved.
|
661
|
-
return (
|
662
|
-
isUnbound(type) &&
|
663
|
-
type.typeAliasInfo &&
|
664
|
-
type.typeAliasInfo.name === typeAliasPlaceholder.details.recursiveTypeAliasName
|
665
|
-
);
|
666
|
-
}
|
667
|
-
|
668
|
-
return findSubtype(type, (subtype) => isTypeSame(typeAliasPlaceholder, subtype)) !== undefined;
|
669
|
-
}
|
670
|
-
|
671
|
-
export function transformPossibleRecursiveTypeAlias(type: Type): Type;
|
672
|
-
export function transformPossibleRecursiveTypeAlias(type: Type | undefined): Type | undefined;
|
673
|
-
export function transformPossibleRecursiveTypeAlias(type: Type | undefined): Type | undefined {
|
674
|
-
if (type) {
|
675
|
-
if (isTypeVar(type) && type.details.recursiveTypeAliasName && type.details.boundType) {
|
676
|
-
const unspecializedType = TypeBase.isInstance(type)
|
677
|
-
? convertToInstance(type.details.boundType)
|
678
|
-
: type.details.boundType;
|
679
|
-
|
680
|
-
if (!type.typeAliasInfo?.typeArguments || !type.details.recursiveTypeParameters) {
|
681
|
-
return unspecializedType;
|
682
|
-
}
|
683
|
-
|
684
|
-
const typeVarContext = buildTypeVarContext(
|
685
|
-
type.details.recursiveTypeParameters,
|
686
|
-
type.typeAliasInfo.typeArguments,
|
687
|
-
getTypeVarScopeId(type)
|
688
|
-
);
|
689
|
-
return applySolvedTypeVars(unspecializedType, typeVarContext);
|
690
|
-
}
|
691
|
-
}
|
692
|
-
|
693
|
-
return type;
|
694
|
-
}
|
695
|
-
|
696
|
-
export function getTypeVarScopeId(type: Type): TypeVarScopeId | undefined {
|
697
|
-
if (isClass(type)) {
|
698
|
-
return type.details.typeVarScopeId;
|
699
|
-
}
|
700
|
-
|
701
|
-
if (isFunction(type)) {
|
702
|
-
return type.details.typeVarScopeId;
|
703
|
-
}
|
704
|
-
|
705
|
-
if (isTypeVar(type)) {
|
706
|
-
return type.scopeId;
|
707
|
-
}
|
708
|
-
|
709
|
-
return undefined;
|
710
|
-
}
|
711
|
-
|
712
|
-
// Determines whether the type derives from tuple. If so, it returns
|
713
|
-
// the specialized tuple type.
|
714
|
-
export function getSpecializedTupleType(type: Type): ClassType | undefined {
|
715
|
-
let classType: ClassType | undefined;
|
716
|
-
|
717
|
-
if (isInstantiableClass(type)) {
|
718
|
-
classType = type;
|
719
|
-
} else if (isClassInstance(type)) {
|
720
|
-
classType = ClassType.cloneAsInstantiable(type);
|
721
|
-
}
|
722
|
-
|
723
|
-
if (!classType) {
|
724
|
-
return undefined;
|
725
|
-
}
|
726
|
-
|
727
|
-
// See if this class derives from Tuple or tuple. If it does, we'll assume that it
|
728
|
-
// hasn't been overridden in a way that changes the behavior of the tuple class.
|
729
|
-
const tupleClass = classType.details.mro.find(
|
730
|
-
(mroClass) => isInstantiableClass(mroClass) && isTupleClass(mroClass)
|
731
|
-
);
|
732
|
-
if (!tupleClass || !isInstantiableClass(tupleClass)) {
|
733
|
-
return undefined;
|
734
|
-
}
|
735
|
-
|
736
|
-
if (ClassType.isSameGenericClass(classType, tupleClass)) {
|
737
|
-
return classType;
|
738
|
-
}
|
739
|
-
|
740
|
-
const typeVarContext = buildTypeVarContextFromSpecializedClass(classType);
|
741
|
-
return applySolvedTypeVars(tupleClass, typeVarContext) as ClassType;
|
742
|
-
}
|
743
|
-
|
744
|
-
export function isLiteralType(type: ClassType): boolean {
|
745
|
-
return TypeBase.isInstance(type) && type.literalValue !== undefined;
|
746
|
-
}
|
747
|
-
|
748
|
-
export function isLiteralTypeOrUnion(type: Type): boolean {
|
749
|
-
if (isClassInstance(type)) {
|
750
|
-
return type.literalValue !== undefined;
|
751
|
-
}
|
752
|
-
|
753
|
-
if (isUnion(type)) {
|
754
|
-
return !findSubtype(type, (subtype) => !isClassInstance(subtype) || subtype.literalValue === undefined);
|
755
|
-
}
|
756
|
-
|
757
|
-
return false;
|
758
|
-
}
|
759
|
-
|
760
|
-
export function containsLiteralType(type: Type, includeTypeArgs = false, recursionCount = 0): boolean {
|
761
|
-
if (recursionCount > maxTypeRecursionCount) {
|
762
|
-
return false;
|
763
|
-
}
|
764
|
-
recursionCount++;
|
765
|
-
|
766
|
-
if (isClassInstance(type) && isLiteralType(type)) {
|
767
|
-
return true;
|
768
|
-
}
|
769
|
-
|
770
|
-
if (includeTypeArgs && isClass(type)) {
|
771
|
-
const typeArgs = type.tupleTypeArguments?.map((t) => t.type) || type.typeArguments;
|
772
|
-
if (typeArgs) {
|
773
|
-
return typeArgs.some((typeArg) => containsLiteralType(typeArg, includeTypeArgs, recursionCount));
|
774
|
-
}
|
775
|
-
}
|
776
|
-
|
777
|
-
if (isUnion(type)) {
|
778
|
-
return type.subtypes.some((subtype) => containsLiteralType(subtype, includeTypeArgs, recursionCount));
|
779
|
-
}
|
780
|
-
|
781
|
-
if (isOverloadedFunction(type)) {
|
782
|
-
return type.overloads.some((overload) => containsLiteralType(overload, includeTypeArgs, recursionCount));
|
783
|
-
}
|
784
|
-
|
785
|
-
if (isFunction(type)) {
|
786
|
-
const returnType = FunctionType.getSpecializedReturnType(type);
|
787
|
-
if (returnType && containsLiteralType(returnType, includeTypeArgs, recursionCount)) {
|
788
|
-
return true;
|
789
|
-
}
|
790
|
-
|
791
|
-
for (let i = 0; i < type.details.parameters.length; i++) {
|
792
|
-
const paramType = FunctionType.getEffectiveParameterType(type, i);
|
793
|
-
if (containsLiteralType(paramType, includeTypeArgs, recursionCount)) {
|
794
|
-
return true;
|
795
|
-
}
|
796
|
-
}
|
797
|
-
}
|
798
|
-
|
799
|
-
return false;
|
800
|
-
}
|
801
|
-
|
802
|
-
// If all of the subtypes are literals with the same built-in class (e.g.
|
803
|
-
// all 'int' or all 'str'), this function returns the name of that type. If
|
804
|
-
// some of the subtypes are not literals or the literal classes don't match,
|
805
|
-
// it returns undefined.
|
806
|
-
export function getLiteralTypeClassName(type: Type): string | undefined {
|
807
|
-
if (isClassInstance(type)) {
|
808
|
-
if (type.literalValue !== undefined && ClassType.isBuiltIn(type)) {
|
809
|
-
return type.details.name;
|
810
|
-
}
|
811
|
-
return undefined;
|
812
|
-
}
|
813
|
-
|
814
|
-
if (isUnion(type)) {
|
815
|
-
let className: string | undefined;
|
816
|
-
let foundMismatch = false;
|
817
|
-
|
818
|
-
doForEachSubtype(type, (subtype) => {
|
819
|
-
const subtypeLiteralTypeName = getLiteralTypeClassName(subtype);
|
820
|
-
if (!subtypeLiteralTypeName) {
|
821
|
-
foundMismatch = true;
|
822
|
-
} else if (!className) {
|
823
|
-
className = subtypeLiteralTypeName;
|
824
|
-
}
|
825
|
-
});
|
826
|
-
|
827
|
-
return foundMismatch ? undefined : className;
|
828
|
-
}
|
829
|
-
|
830
|
-
return undefined;
|
831
|
-
}
|
832
|
-
|
833
|
-
export function getUnionSubtypeCount(type: Type): number {
|
834
|
-
if (isUnion(type)) {
|
835
|
-
return type.subtypes.length;
|
836
|
-
}
|
837
|
-
|
838
|
-
return 1;
|
839
|
-
}
|
840
|
-
|
841
|
-
export function isEllipsisType(type: Type): boolean {
|
842
|
-
return isAny(type) && type.isEllipsis;
|
843
|
-
}
|
844
|
-
|
845
|
-
export function isProperty(type: Type) {
|
846
|
-
return isClassInstance(type) && ClassType.isPropertyClass(type);
|
847
|
-
}
|
848
|
-
|
849
|
-
export function isDescriptorInstance(type: Type, requireSetter = false): boolean {
|
850
|
-
if (isUnion(type)) {
|
851
|
-
return type.subtypes.every((subtype) => isMaybeDescriptorInstance(subtype, requireSetter));
|
852
|
-
}
|
853
|
-
|
854
|
-
return isMaybeDescriptorInstance(type, requireSetter);
|
855
|
-
}
|
856
|
-
|
857
|
-
export function isMaybeDescriptorInstance(type: Type, requireSetter = false): boolean {
|
858
|
-
if (isUnion(type)) {
|
859
|
-
return type.subtypes.some((subtype) => isMaybeDescriptorInstance(subtype, requireSetter));
|
860
|
-
}
|
861
|
-
|
862
|
-
if (!isClassInstance(type)) {
|
863
|
-
return false;
|
864
|
-
}
|
865
|
-
|
866
|
-
if (!type.details.fields.has('__get__')) {
|
867
|
-
return false;
|
868
|
-
}
|
869
|
-
|
870
|
-
if (requireSetter && !type.details.fields.has('__set__')) {
|
871
|
-
return false;
|
872
|
-
}
|
873
|
-
|
874
|
-
return true;
|
875
|
-
}
|
876
|
-
|
877
|
-
export function isTupleClass(type: ClassType) {
|
878
|
-
return ClassType.isBuiltIn(type, 'tuple');
|
879
|
-
}
|
880
|
-
|
881
|
-
// Indicates whether the type is a tuple class of
|
882
|
-
// the form tuple[x, ...] where the number of elements
|
883
|
-
// in the tuple is unknown.
|
884
|
-
export function isUnboundedTupleClass(type: ClassType) {
|
885
|
-
return type.tupleTypeArguments && type.tupleTypeArguments.some((t) => t.isUnbounded);
|
886
|
-
}
|
887
|
-
|
888
|
-
// Partially specializes a type within the context of a specified
|
889
|
-
// (presumably specialized) class. Optionally specializes the `Self`
|
890
|
-
// type variables, replacing them with selfClass.
|
891
|
-
export function partiallySpecializeType(
|
892
|
-
type: Type,
|
893
|
-
contextClassType: ClassType,
|
894
|
-
selfClass?: ClassType,
|
895
|
-
typeClassType?: Type
|
896
|
-
): Type {
|
897
|
-
// If the context class is not specialized (or doesn't need specialization),
|
898
|
-
// then there's no need to do any more work.
|
899
|
-
if (ClassType.isUnspecialized(contextClassType)) {
|
900
|
-
return type;
|
901
|
-
}
|
902
|
-
|
903
|
-
// Partially specialize the type using the specialized class type vars.
|
904
|
-
const typeVarContext = buildTypeVarContextFromSpecializedClass(contextClassType, /* makeConcrete */ undefined);
|
905
|
-
|
906
|
-
if (selfClass) {
|
907
|
-
populateTypeVarContextForSelfType(typeVarContext, contextClassType, selfClass);
|
908
|
-
}
|
909
|
-
|
910
|
-
return applySolvedTypeVars(
|
911
|
-
type,
|
912
|
-
typeVarContext,
|
913
|
-
/* unknownIfNotFound */ undefined,
|
914
|
-
/* useNarrowBoundOnly */ undefined,
|
915
|
-
/* eliminateUnsolvedInUnions */ undefined,
|
916
|
-
typeClassType
|
917
|
-
);
|
918
|
-
}
|
919
|
-
|
920
|
-
export function populateTypeVarContextForSelfType(
|
921
|
-
typeVarContext: TypeVarContext,
|
922
|
-
contextClassType: ClassType,
|
923
|
-
selfClass: ClassType
|
924
|
-
) {
|
925
|
-
const synthesizedSelfTypeVar = synthesizeTypeVarForSelfCls(contextClassType, /* isClsParam */ false);
|
926
|
-
typeVarContext.setTypeVarType(synthesizedSelfTypeVar, convertToInstance(selfClass));
|
927
|
-
}
|
928
|
-
|
929
|
-
// Specializes a (potentially generic) type by substituting
|
930
|
-
// type variables from a type var map.
|
931
|
-
export function applySolvedTypeVars(
|
932
|
-
type: Type,
|
933
|
-
typeVarContext: TypeVarContext,
|
934
|
-
unknownIfNotFound = false,
|
935
|
-
useNarrowBoundOnly = false,
|
936
|
-
eliminateUnsolvedInUnions = false,
|
937
|
-
typeClassType?: Type
|
938
|
-
): Type {
|
939
|
-
// Use a shortcut if the typeVarContext is empty and no transform is necessary.
|
940
|
-
if (typeVarContext.isEmpty() && !unknownIfNotFound && !eliminateUnsolvedInUnions) {
|
941
|
-
return type;
|
942
|
-
}
|
943
|
-
|
944
|
-
const transformer = new ApplySolvedTypeVarsTransformer(
|
945
|
-
typeVarContext,
|
946
|
-
unknownIfNotFound,
|
947
|
-
useNarrowBoundOnly,
|
948
|
-
eliminateUnsolvedInUnions,
|
949
|
-
typeClassType
|
950
|
-
);
|
951
|
-
return transformer.apply(type);
|
952
|
-
}
|
953
|
-
|
954
|
-
// During bidirectional type inference for constructors, an "executed type"
|
955
|
-
// is used to prepopulate the type var map. This is problematic when the
|
956
|
-
// expected type uses TypeVars that are not part of the context of the
|
957
|
-
// class we are constructing. We'll replace these type variables with dummy
|
958
|
-
// type variables that are scoped to the appropriate context.
|
959
|
-
export function transformExpectedTypeForConstructor(
|
960
|
-
expectedType: Type,
|
961
|
-
typeVarContext: TypeVarContext,
|
962
|
-
liveTypeVarScopes: TypeVarScopeId[]
|
963
|
-
): Type | undefined {
|
964
|
-
const isTypeVarLive = (typeVar: TypeVarType) => liveTypeVarScopes.some((scopeId) => typeVar.scopeId === scopeId);
|
965
|
-
|
966
|
-
// Handle "naked TypeVars" (i.e. the expectedType is a TypeVar itself)
|
967
|
-
// specially. Return undefined to indicate that it's an out-of-scope
|
968
|
-
// TypeVar.
|
969
|
-
if (isTypeVar(expectedType)) {
|
970
|
-
if (isTypeVarLive(expectedType)) {
|
971
|
-
return expectedType;
|
972
|
-
}
|
973
|
-
|
974
|
-
return undefined;
|
975
|
-
}
|
976
|
-
|
977
|
-
const transformer = new ExpectedConstructorTypeTransformer(typeVarContext, liveTypeVarScopes);
|
978
|
-
return transformer.apply(expectedType);
|
979
|
-
}
|
980
|
-
|
981
|
-
// Given a protocol class, this function returns a set of all the
|
982
|
-
// symbols (indexed by symbol name) that are part of that protocol
|
983
|
-
// and its protocol parent classes. If a same-named symbol appears
|
984
|
-
// in a parent and a child, the child overrides the parent.
|
985
|
-
export function getProtocolSymbols(classType: ClassType) {
|
986
|
-
const symbolMap = new Map<string, ClassMember>();
|
987
|
-
|
988
|
-
if (ClassType.isProtocolClass(classType)) {
|
989
|
-
getProtocolSymbolsRecursive(classType, symbolMap);
|
990
|
-
}
|
991
|
-
|
992
|
-
return symbolMap;
|
993
|
-
}
|
994
|
-
|
995
|
-
function getProtocolSymbolsRecursive(classType: ClassType, symbolMap: Map<string, ClassMember>, recursionCount = 0) {
|
996
|
-
if (recursionCount > maxTypeRecursionCount) {
|
997
|
-
return;
|
998
|
-
}
|
999
|
-
|
1000
|
-
classType.details.baseClasses.forEach((baseClass) => {
|
1001
|
-
if (isClass(baseClass) && ClassType.isProtocolClass(baseClass)) {
|
1002
|
-
getProtocolSymbolsRecursive(baseClass, symbolMap, recursionCount + 1);
|
1003
|
-
}
|
1004
|
-
});
|
1005
|
-
|
1006
|
-
classType.details.fields.forEach((symbol, name) => {
|
1007
|
-
if (!symbol.isIgnoredForProtocolMatch()) {
|
1008
|
-
symbolMap.set(name, {
|
1009
|
-
symbol,
|
1010
|
-
classType,
|
1011
|
-
isInstanceMember: symbol.isInstanceMember(),
|
1012
|
-
isClassMember: symbol.isClassMember(),
|
1013
|
-
isClassVar: symbol.isClassVar(),
|
1014
|
-
isTypeDeclared: symbol.hasTypedDeclarations(),
|
1015
|
-
skippedUndeclaredType: false,
|
1016
|
-
});
|
1017
|
-
}
|
1018
|
-
});
|
1019
|
-
}
|
1020
|
-
|
1021
|
-
export function lookUpObjectMember(
|
1022
|
-
objectType: Type,
|
1023
|
-
memberName: string,
|
1024
|
-
flags = ClassMemberLookupFlags.Default
|
1025
|
-
): ClassMember | undefined {
|
1026
|
-
if (isClassInstance(objectType)) {
|
1027
|
-
return lookUpClassMember(objectType, memberName, flags);
|
1028
|
-
}
|
1029
|
-
|
1030
|
-
return undefined;
|
1031
|
-
}
|
1032
|
-
|
1033
|
-
// Looks up a member in a class using the multiple-inheritance rules
|
1034
|
-
// defined by Python.
|
1035
|
-
export function lookUpClassMember(
|
1036
|
-
classType: Type,
|
1037
|
-
memberName: string,
|
1038
|
-
flags = ClassMemberLookupFlags.Default
|
1039
|
-
): ClassMember | undefined {
|
1040
|
-
const memberItr = getClassMemberIterator(classType, memberName, flags);
|
1041
|
-
|
1042
|
-
return memberItr.next()?.value;
|
1043
|
-
}
|
1044
|
-
|
1045
|
-
// Iterates members in a class matching memberName using the multiple-inheritance rules.
|
1046
|
-
// For more details, see this note on method resolution
|
1047
|
-
// order: https://www.python.org/download/releases/2.3/mro/.
|
1048
|
-
// As it traverses the inheritance tree, it applies partial specialization
|
1049
|
-
// to the the base class and member. For example, if ClassA inherits from
|
1050
|
-
// ClassB[str] which inherits from Dict[_T1, int], a search for '__iter__'
|
1051
|
-
// would return a class type of Dict[str, int] and a symbolType of
|
1052
|
-
// (self) -> Iterator[str].
|
1053
|
-
export function* getClassMemberIterator(classType: Type, memberName: string, flags = ClassMemberLookupFlags.Default) {
|
1054
|
-
const declaredTypesOnly = (flags & ClassMemberLookupFlags.DeclaredTypesOnly) !== 0;
|
1055
|
-
let skippedUndeclaredType = false;
|
1056
|
-
|
1057
|
-
if (isClass(classType)) {
|
1058
|
-
let classFlags = ClassIteratorFlags.Default;
|
1059
|
-
if (flags & ClassMemberLookupFlags.SkipOriginalClass) {
|
1060
|
-
classFlags = classFlags | ClassIteratorFlags.SkipOriginalClass;
|
1061
|
-
}
|
1062
|
-
if (flags & ClassMemberLookupFlags.SkipBaseClasses) {
|
1063
|
-
classFlags = classFlags | ClassIteratorFlags.SkipBaseClasses;
|
1064
|
-
}
|
1065
|
-
if (flags & ClassMemberLookupFlags.SkipObjectBaseClass) {
|
1066
|
-
classFlags = classFlags | ClassIteratorFlags.SkipObjectBaseClass;
|
1067
|
-
}
|
1068
|
-
if (flags & ClassMemberLookupFlags.SkipTypeBaseClass) {
|
1069
|
-
classFlags = classFlags | ClassIteratorFlags.SkipTypeBaseClass;
|
1070
|
-
}
|
1071
|
-
|
1072
|
-
const classItr = getClassIterator(classType, classFlags);
|
1073
|
-
|
1074
|
-
for (const [mroClass, specializedMroClass] of classItr) {
|
1075
|
-
if (!isInstantiableClass(mroClass)) {
|
1076
|
-
if (!declaredTypesOnly) {
|
1077
|
-
// The class derives from an unknown type, so all bets are off
|
1078
|
-
// when trying to find a member. Return an unknown symbol.
|
1079
|
-
const cm: ClassMember = {
|
1080
|
-
symbol: Symbol.createWithType(SymbolFlags.None, UnknownType.create()),
|
1081
|
-
isInstanceMember: false,
|
1082
|
-
isClassMember: true,
|
1083
|
-
isClassVar: false,
|
1084
|
-
classType: UnknownType.create(),
|
1085
|
-
isTypeDeclared: false,
|
1086
|
-
skippedUndeclaredType: false,
|
1087
|
-
};
|
1088
|
-
yield cm;
|
1089
|
-
}
|
1090
|
-
continue;
|
1091
|
-
}
|
1092
|
-
|
1093
|
-
if (!isInstantiableClass(specializedMroClass)) {
|
1094
|
-
continue;
|
1095
|
-
}
|
1096
|
-
|
1097
|
-
const memberFields = specializedMroClass.details.fields;
|
1098
|
-
|
1099
|
-
// Look at instance members first if requested.
|
1100
|
-
if ((flags & ClassMemberLookupFlags.SkipInstanceVariables) === 0) {
|
1101
|
-
const symbol = memberFields.get(memberName);
|
1102
|
-
if (symbol && symbol.isInstanceMember()) {
|
1103
|
-
const hasDeclaredType = symbol.hasTypedDeclarations();
|
1104
|
-
if (!declaredTypesOnly || hasDeclaredType) {
|
1105
|
-
const cm: ClassMember = {
|
1106
|
-
symbol,
|
1107
|
-
isInstanceMember: true,
|
1108
|
-
isClassMember: symbol.isClassMember(),
|
1109
|
-
isClassVar: symbol.isClassVar(),
|
1110
|
-
classType: specializedMroClass,
|
1111
|
-
isTypeDeclared: hasDeclaredType,
|
1112
|
-
skippedUndeclaredType,
|
1113
|
-
};
|
1114
|
-
yield cm;
|
1115
|
-
} else {
|
1116
|
-
skippedUndeclaredType = true;
|
1117
|
-
}
|
1118
|
-
}
|
1119
|
-
}
|
1120
|
-
|
1121
|
-
// Next look at class members.
|
1122
|
-
const symbol = memberFields.get(memberName);
|
1123
|
-
if (symbol && symbol.isClassMember()) {
|
1124
|
-
const hasDeclaredType = symbol.hasTypedDeclarations();
|
1125
|
-
if (!declaredTypesOnly || hasDeclaredType) {
|
1126
|
-
let isInstanceMember = symbol.isInstanceMember();
|
1127
|
-
let isClassMember = true;
|
1128
|
-
|
1129
|
-
// For data classes and typed dicts, variables that are declared
|
1130
|
-
// within the class are treated as instance variables. This distinction
|
1131
|
-
// is important in cases where a variable is a callable type because
|
1132
|
-
// we don't want to bind it to the instance like we would for a
|
1133
|
-
// class member.
|
1134
|
-
const isDataclass = ClassType.isDataClass(specializedMroClass);
|
1135
|
-
const isTypedDict = ClassType.isTypedDictClass(specializedMroClass);
|
1136
|
-
if (isDataclass || isTypedDict) {
|
1137
|
-
const decls = symbol.getDeclarations();
|
1138
|
-
if (decls.length > 0 && decls[0].type === DeclarationType.Variable) {
|
1139
|
-
isInstanceMember = true;
|
1140
|
-
isClassMember = isDataclass;
|
1141
|
-
}
|
1142
|
-
}
|
1143
|
-
|
1144
|
-
const cm: ClassMember = {
|
1145
|
-
symbol,
|
1146
|
-
isInstanceMember,
|
1147
|
-
isClassMember,
|
1148
|
-
isClassVar: symbol.isClassVar(),
|
1149
|
-
classType: specializedMroClass,
|
1150
|
-
isTypeDeclared: hasDeclaredType,
|
1151
|
-
skippedUndeclaredType,
|
1152
|
-
};
|
1153
|
-
yield cm;
|
1154
|
-
} else {
|
1155
|
-
skippedUndeclaredType = true;
|
1156
|
-
}
|
1157
|
-
}
|
1158
|
-
}
|
1159
|
-
} else if (isAnyOrUnknown(classType)) {
|
1160
|
-
// The class derives from an unknown type, so all bets are off
|
1161
|
-
// when trying to find a member. Return an unknown symbol.
|
1162
|
-
const cm: ClassMember = {
|
1163
|
-
symbol: Symbol.createWithType(SymbolFlags.None, UnknownType.create()),
|
1164
|
-
isInstanceMember: false,
|
1165
|
-
isClassMember: true,
|
1166
|
-
isClassVar: false,
|
1167
|
-
classType: UnknownType.create(),
|
1168
|
-
isTypeDeclared: false,
|
1169
|
-
skippedUndeclaredType: false,
|
1170
|
-
};
|
1171
|
-
yield cm;
|
1172
|
-
}
|
1173
|
-
|
1174
|
-
return undefined;
|
1175
|
-
}
|
1176
|
-
|
1177
|
-
export function* getClassIterator(classType: Type, flags = ClassIteratorFlags.Default) {
|
1178
|
-
if (isClass(classType)) {
|
1179
|
-
let skipMroEntry = (flags & ClassIteratorFlags.SkipOriginalClass) !== 0;
|
1180
|
-
|
1181
|
-
for (const mroClass of classType.details.mro) {
|
1182
|
-
if (skipMroEntry) {
|
1183
|
-
skipMroEntry = false;
|
1184
|
-
continue;
|
1185
|
-
}
|
1186
|
-
|
1187
|
-
// If mroClass is an ancestor of classType, partially specialize
|
1188
|
-
// it in the context of classType.
|
1189
|
-
const specializedMroClass = partiallySpecializeType(mroClass, classType);
|
1190
|
-
|
1191
|
-
// Should we ignore members on the 'object' base class?
|
1192
|
-
if (flags & ClassIteratorFlags.SkipObjectBaseClass) {
|
1193
|
-
if (isInstantiableClass(specializedMroClass)) {
|
1194
|
-
if (ClassType.isBuiltIn(specializedMroClass, 'object')) {
|
1195
|
-
break;
|
1196
|
-
}
|
1197
|
-
}
|
1198
|
-
}
|
1199
|
-
|
1200
|
-
// Should we ignore members on the 'type' base class?
|
1201
|
-
if (flags & ClassIteratorFlags.SkipTypeBaseClass) {
|
1202
|
-
if (isInstantiableClass(specializedMroClass)) {
|
1203
|
-
if (ClassType.isBuiltIn(specializedMroClass, 'type')) {
|
1204
|
-
break;
|
1205
|
-
}
|
1206
|
-
}
|
1207
|
-
}
|
1208
|
-
|
1209
|
-
yield [mroClass, specializedMroClass];
|
1210
|
-
|
1211
|
-
if ((flags & ClassIteratorFlags.SkipBaseClasses) !== 0) {
|
1212
|
-
break;
|
1213
|
-
}
|
1214
|
-
}
|
1215
|
-
}
|
1216
|
-
|
1217
|
-
return undefined;
|
1218
|
-
}
|
1219
|
-
|
1220
|
-
export function getClassFieldsRecursive(classType: ClassType): Map<string, ClassMember> {
|
1221
|
-
const memberMap = new Map<string, ClassMember>();
|
1222
|
-
|
1223
|
-
// Evaluate the types of members from the end of the MRO to the beginning.
|
1224
|
-
for (let i = classType.details.mro.length - 1; i >= 0; i--) {
|
1225
|
-
const mroClass = partiallySpecializeType(classType.details.mro[i], classType);
|
1226
|
-
|
1227
|
-
// If this ancestor class is unknown, throw away all symbols
|
1228
|
-
// found so far because they could be overridden by the unknown class.
|
1229
|
-
if (!isClass(mroClass)) {
|
1230
|
-
memberMap.clear();
|
1231
|
-
continue;
|
1232
|
-
}
|
1233
|
-
|
1234
|
-
mroClass.details.fields.forEach((symbol, name) => {
|
1235
|
-
if (!symbol.isIgnoredForProtocolMatch() && symbol.hasTypedDeclarations()) {
|
1236
|
-
memberMap.set(name, {
|
1237
|
-
classType: mroClass,
|
1238
|
-
symbol,
|
1239
|
-
isInstanceMember: symbol.isInstanceMember(),
|
1240
|
-
isClassMember: symbol.isClassMember(),
|
1241
|
-
isClassVar: symbol.isClassVar(),
|
1242
|
-
isTypeDeclared: true,
|
1243
|
-
skippedUndeclaredType: false,
|
1244
|
-
});
|
1245
|
-
}
|
1246
|
-
});
|
1247
|
-
}
|
1248
|
-
|
1249
|
-
return memberMap;
|
1250
|
-
}
|
1251
|
-
|
1252
|
-
// Combines two lists of type var types, maintaining the combined order
|
1253
|
-
// but removing any duplicates.
|
1254
|
-
export function addTypeVarsToListIfUnique(list1: TypeVarType[], list2: TypeVarType[]) {
|
1255
|
-
for (const type2 of list2) {
|
1256
|
-
if (!list1.find((type1) => isTypeSame(convertToInstance(type1), convertToInstance(type2)))) {
|
1257
|
-
list1.push(type2);
|
1258
|
-
}
|
1259
|
-
}
|
1260
|
-
}
|
1261
|
-
|
1262
|
-
// Walks the type recursively (in a depth-first manner), finds all
|
1263
|
-
// type variables that are referenced, and returns an ordered list
|
1264
|
-
// of unique type variables. For example, if the type is
|
1265
|
-
// Union[List[Dict[_T1, _T2]], _T1, _T3], the result would be
|
1266
|
-
// [_T1, _T2, _T3].
|
1267
|
-
export function getTypeVarArgumentsRecursive(type: Type, recursionCount = 0): TypeVarType[] {
|
1268
|
-
if (recursionCount > maxTypeRecursionCount) {
|
1269
|
-
return [];
|
1270
|
-
}
|
1271
|
-
recursionCount++;
|
1272
|
-
|
1273
|
-
const getTypeVarsFromClass = (classType: ClassType) => {
|
1274
|
-
const combinedList: TypeVarType[] = [];
|
1275
|
-
if (classType.typeArguments) {
|
1276
|
-
classType.typeArguments.forEach((typeArg) => {
|
1277
|
-
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(typeArg, recursionCount));
|
1278
|
-
});
|
1279
|
-
}
|
1280
|
-
|
1281
|
-
return combinedList;
|
1282
|
-
};
|
1283
|
-
|
1284
|
-
if (type.typeAliasInfo?.typeArguments) {
|
1285
|
-
const combinedList: TypeVarType[] = [];
|
1286
|
-
|
1287
|
-
type.typeAliasInfo?.typeArguments.forEach((typeArg) => {
|
1288
|
-
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(typeArg, recursionCount));
|
1289
|
-
});
|
1290
|
-
|
1291
|
-
return combinedList;
|
1292
|
-
}
|
1293
|
-
|
1294
|
-
if (isTypeVar(type)) {
|
1295
|
-
// Don't return any recursive type alias placeholders.
|
1296
|
-
if (type.details.recursiveTypeAliasName) {
|
1297
|
-
return [];
|
1298
|
-
}
|
1299
|
-
|
1300
|
-
// Don't return any P.args or P.kwargs types.
|
1301
|
-
if (isParamSpec(type) && type.paramSpecAccess) {
|
1302
|
-
return [];
|
1303
|
-
}
|
1304
|
-
|
1305
|
-
return [TypeBase.isInstantiable(type) ? TypeVarType.cloneAsInstance(type) : type];
|
1306
|
-
}
|
1307
|
-
|
1308
|
-
if (isClass(type)) {
|
1309
|
-
return getTypeVarsFromClass(type);
|
1310
|
-
}
|
1311
|
-
|
1312
|
-
if (isUnion(type)) {
|
1313
|
-
const combinedList: TypeVarType[] = [];
|
1314
|
-
doForEachSubtype(type, (subtype) => {
|
1315
|
-
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(subtype, recursionCount));
|
1316
|
-
});
|
1317
|
-
return combinedList;
|
1318
|
-
}
|
1319
|
-
|
1320
|
-
if (isFunction(type)) {
|
1321
|
-
const combinedList: TypeVarType[] = [];
|
1322
|
-
|
1323
|
-
for (let i = 0; i < type.details.parameters.length; i++) {
|
1324
|
-
addTypeVarsToListIfUnique(
|
1325
|
-
combinedList,
|
1326
|
-
getTypeVarArgumentsRecursive(FunctionType.getEffectiveParameterType(type, i), recursionCount)
|
1327
|
-
);
|
1328
|
-
}
|
1329
|
-
|
1330
|
-
if (type.details.paramSpec) {
|
1331
|
-
addTypeVarsToListIfUnique(combinedList, [type.details.paramSpec]);
|
1332
|
-
}
|
1333
|
-
|
1334
|
-
const returnType = FunctionType.getSpecializedReturnType(type);
|
1335
|
-
if (returnType) {
|
1336
|
-
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(returnType, recursionCount));
|
1337
|
-
}
|
1338
|
-
|
1339
|
-
return combinedList;
|
1340
|
-
}
|
1341
|
-
|
1342
|
-
return [];
|
1343
|
-
}
|
1344
|
-
|
1345
|
-
// Creates a specialized version of the class, filling in any unspecified
|
1346
|
-
// type arguments with Unknown.
|
1347
|
-
export function specializeClassType(type: ClassType): ClassType {
|
1348
|
-
const typeVarContext = new TypeVarContext(getTypeVarScopeId(type));
|
1349
|
-
const typeParams = ClassType.getTypeParameters(type);
|
1350
|
-
|
1351
|
-
typeParams.forEach((typeParam) => {
|
1352
|
-
typeVarContext.setTypeVarType(typeParam, UnknownType.create());
|
1353
|
-
});
|
1354
|
-
|
1355
|
-
return applySolvedTypeVars(type, typeVarContext) as ClassType;
|
1356
|
-
}
|
1357
|
-
|
1358
|
-
// Recursively finds all of the type arguments and sets them
|
1359
|
-
// to the specified srcType.
|
1360
|
-
export function setTypeArgumentsRecursive(
|
1361
|
-
destType: Type,
|
1362
|
-
srcType: Type,
|
1363
|
-
typeVarContext: TypeVarContext,
|
1364
|
-
recursionCount = 0
|
1365
|
-
) {
|
1366
|
-
if (recursionCount > maxTypeRecursionCount) {
|
1367
|
-
return;
|
1368
|
-
}
|
1369
|
-
recursionCount++;
|
1370
|
-
|
1371
|
-
if (typeVarContext.isLocked()) {
|
1372
|
-
return;
|
1373
|
-
}
|
1374
|
-
|
1375
|
-
switch (destType.category) {
|
1376
|
-
case TypeCategory.Union:
|
1377
|
-
doForEachSubtype(destType, (subtype) => {
|
1378
|
-
setTypeArgumentsRecursive(subtype, srcType, typeVarContext, recursionCount);
|
1379
|
-
});
|
1380
|
-
break;
|
1381
|
-
|
1382
|
-
case TypeCategory.Class:
|
1383
|
-
if (destType.typeArguments) {
|
1384
|
-
destType.typeArguments.forEach((typeArg) => {
|
1385
|
-
setTypeArgumentsRecursive(typeArg, srcType, typeVarContext, recursionCount);
|
1386
|
-
});
|
1387
|
-
}
|
1388
|
-
if (destType.tupleTypeArguments) {
|
1389
|
-
destType.tupleTypeArguments.forEach((typeArg) => {
|
1390
|
-
setTypeArgumentsRecursive(typeArg.type, srcType, typeVarContext, recursionCount);
|
1391
|
-
});
|
1392
|
-
}
|
1393
|
-
break;
|
1394
|
-
|
1395
|
-
case TypeCategory.Function:
|
1396
|
-
if (destType.specializedTypes) {
|
1397
|
-
destType.specializedTypes.parameterTypes.forEach((paramType) => {
|
1398
|
-
setTypeArgumentsRecursive(paramType, srcType, typeVarContext, recursionCount);
|
1399
|
-
});
|
1400
|
-
if (destType.specializedTypes.returnType) {
|
1401
|
-
setTypeArgumentsRecursive(
|
1402
|
-
destType.specializedTypes.returnType,
|
1403
|
-
srcType,
|
1404
|
-
typeVarContext,
|
1405
|
-
recursionCount
|
1406
|
-
);
|
1407
|
-
}
|
1408
|
-
} else {
|
1409
|
-
destType.details.parameters.forEach((param) => {
|
1410
|
-
setTypeArgumentsRecursive(param.type, srcType, typeVarContext, recursionCount);
|
1411
|
-
});
|
1412
|
-
if (destType.details.declaredReturnType) {
|
1413
|
-
setTypeArgumentsRecursive(
|
1414
|
-
destType.details.declaredReturnType,
|
1415
|
-
srcType,
|
1416
|
-
typeVarContext,
|
1417
|
-
recursionCount
|
1418
|
-
);
|
1419
|
-
}
|
1420
|
-
|
1421
|
-
if (destType.details.paramSpec) {
|
1422
|
-
// Fill in an empty signature for a ParamSpec if the source is Any or Unknown.
|
1423
|
-
if (!typeVarContext.hasTypeVar(destType.details.paramSpec) && isAnyOrUnknown(srcType)) {
|
1424
|
-
typeVarContext.setParamSpec(destType.details.paramSpec, {
|
1425
|
-
flags: FunctionTypeFlags.None,
|
1426
|
-
parameters: FunctionType.getDefaultParameters(),
|
1427
|
-
typeVarScopeId: undefined,
|
1428
|
-
docString: undefined,
|
1429
|
-
paramSpec: undefined,
|
1430
|
-
});
|
1431
|
-
}
|
1432
|
-
}
|
1433
|
-
}
|
1434
|
-
break;
|
1435
|
-
|
1436
|
-
case TypeCategory.OverloadedFunction:
|
1437
|
-
destType.overloads.forEach((subtype) => {
|
1438
|
-
setTypeArgumentsRecursive(subtype, srcType, typeVarContext, recursionCount);
|
1439
|
-
});
|
1440
|
-
break;
|
1441
|
-
|
1442
|
-
case TypeCategory.TypeVar:
|
1443
|
-
if (!typeVarContext.hasTypeVar(destType)) {
|
1444
|
-
typeVarContext.setTypeVarType(destType, srcType);
|
1445
|
-
}
|
1446
|
-
break;
|
1447
|
-
}
|
1448
|
-
}
|
1449
|
-
|
1450
|
-
// Builds a mapping between type parameters and their specialized
|
1451
|
-
// types. For example, if the generic type is Dict[_T1, _T2] and the
|
1452
|
-
// specialized type is Dict[str, int], it returns a map that associates
|
1453
|
-
// _T1 with str and _T2 with int.
|
1454
|
-
export function buildTypeVarContextFromSpecializedClass(classType: ClassType, makeConcrete = true): TypeVarContext {
|
1455
|
-
const typeParameters = ClassType.getTypeParameters(classType);
|
1456
|
-
let typeArguments = classType.typeArguments;
|
1457
|
-
|
1458
|
-
// If there are no type arguments, we can either use the type variables
|
1459
|
-
// from the type parameters (keeping the type arguments generic) or
|
1460
|
-
// fill in concrete types.
|
1461
|
-
if (!typeArguments && !makeConcrete) {
|
1462
|
-
typeArguments = typeParameters;
|
1463
|
-
}
|
1464
|
-
|
1465
|
-
const typeVarContext = buildTypeVarContext(typeParameters, typeArguments, getTypeVarScopeId(classType));
|
1466
|
-
if (ClassType.isTupleClass(classType) && classType.tupleTypeArguments && typeParameters.length >= 1) {
|
1467
|
-
typeVarContext.setVariadicTypeVar(typeParameters[0], classType.tupleTypeArguments);
|
1468
|
-
}
|
1469
|
-
|
1470
|
-
return typeVarContext;
|
1471
|
-
}
|
1472
|
-
|
1473
|
-
export function buildTypeVarContext(
|
1474
|
-
typeParameters: TypeVarType[],
|
1475
|
-
typeArgs: Type[] | undefined,
|
1476
|
-
typeVarScopeId: TypeVarScopeId | undefined
|
1477
|
-
): TypeVarContext {
|
1478
|
-
const typeVarContext = new TypeVarContext(typeVarScopeId);
|
1479
|
-
typeParameters.forEach((typeParam, index) => {
|
1480
|
-
let typeArgType: Type;
|
1481
|
-
|
1482
|
-
if (typeArgs) {
|
1483
|
-
if (isParamSpec(typeParam)) {
|
1484
|
-
if (index < typeArgs.length) {
|
1485
|
-
typeArgType = typeArgs[index];
|
1486
|
-
if (isFunction(typeArgType) && FunctionType.isParamSpecValue(typeArgType)) {
|
1487
|
-
const paramSpecEntries: ParamSpecEntry[] = [];
|
1488
|
-
const typeArgFunctionType = typeArgType;
|
1489
|
-
typeArgType.details.parameters.forEach((param, paramIndex) => {
|
1490
|
-
paramSpecEntries.push({
|
1491
|
-
category: param.category,
|
1492
|
-
name: param.name,
|
1493
|
-
hasDefault: !!param.hasDefault,
|
1494
|
-
isNameSynthesized: param.isNameSynthesized,
|
1495
|
-
type: FunctionType.getEffectiveParameterType(typeArgFunctionType, paramIndex),
|
1496
|
-
});
|
1497
|
-
});
|
1498
|
-
typeVarContext.setParamSpec(typeParam, {
|
1499
|
-
parameters: paramSpecEntries,
|
1500
|
-
typeVarScopeId: typeArgType.details.typeVarScopeId,
|
1501
|
-
flags: typeArgType.details.flags,
|
1502
|
-
docString: typeArgType.details.docString,
|
1503
|
-
paramSpec: typeArgType.details.paramSpec,
|
1504
|
-
});
|
1505
|
-
} else if (isParamSpec(typeArgType)) {
|
1506
|
-
typeVarContext.setParamSpec(typeParam, {
|
1507
|
-
flags: FunctionTypeFlags.None,
|
1508
|
-
parameters: [],
|
1509
|
-
typeVarScopeId: undefined,
|
1510
|
-
docString: undefined,
|
1511
|
-
paramSpec: typeArgType,
|
1512
|
-
});
|
1513
|
-
} else if (isAnyOrUnknown(typeArgType)) {
|
1514
|
-
// Fill in an empty signature if the arg type is Any or Unknown.
|
1515
|
-
typeVarContext.setParamSpec(typeParam, {
|
1516
|
-
flags: FunctionTypeFlags.None,
|
1517
|
-
parameters: FunctionType.getDefaultParameters(),
|
1518
|
-
typeVarScopeId: undefined,
|
1519
|
-
docString: undefined,
|
1520
|
-
paramSpec: undefined,
|
1521
|
-
});
|
1522
|
-
}
|
1523
|
-
}
|
1524
|
-
} else {
|
1525
|
-
if (index >= typeArgs.length) {
|
1526
|
-
typeArgType = AnyType.create();
|
1527
|
-
} else {
|
1528
|
-
typeArgType = typeArgs[index];
|
1529
|
-
}
|
1530
|
-
|
1531
|
-
typeVarContext.setTypeVarType(typeParam, typeArgType, typeArgType, /* retainLiteral */ true);
|
1532
|
-
}
|
1533
|
-
}
|
1534
|
-
});
|
1535
|
-
|
1536
|
-
return typeVarContext;
|
1537
|
-
}
|
1538
|
-
|
1539
|
-
// Determines the specialized base class type that srcType derives from.
|
1540
|
-
export function specializeForBaseClass(srcType: ClassType, baseClass: ClassType): ClassType {
|
1541
|
-
const typeParams = ClassType.getTypeParameters(baseClass);
|
1542
|
-
|
1543
|
-
// If there are no type parameters for the specified base class,
|
1544
|
-
// no specialization is required.
|
1545
|
-
if (typeParams.length === 0) {
|
1546
|
-
return baseClass;
|
1547
|
-
}
|
1548
|
-
|
1549
|
-
const typeVarContext = buildTypeVarContextFromSpecializedClass(srcType);
|
1550
|
-
const specializedType = applySolvedTypeVars(baseClass, typeVarContext);
|
1551
|
-
assert(isInstantiableClass(specializedType));
|
1552
|
-
return specializedType as ClassType;
|
1553
|
-
}
|
1554
|
-
|
1555
|
-
// If ignoreUnknown is true, an unknown base class is ignored when
|
1556
|
-
// checking for derivation. If ignoreUnknown is false, a return value
|
1557
|
-
// of true is assumed.
|
1558
|
-
export function derivesFromClassRecursive(classType: ClassType, baseClassToFind: ClassType, ignoreUnknown: boolean) {
|
1559
|
-
if (ClassType.isSameGenericClass(classType, baseClassToFind)) {
|
1560
|
-
return true;
|
1561
|
-
}
|
1562
|
-
|
1563
|
-
for (const baseClass of classType.details.baseClasses) {
|
1564
|
-
if (isInstantiableClass(baseClass)) {
|
1565
|
-
if (derivesFromClassRecursive(baseClass, baseClassToFind, ignoreUnknown)) {
|
1566
|
-
return true;
|
1567
|
-
}
|
1568
|
-
} else if (!ignoreUnknown && isAnyOrUnknown(baseClass)) {
|
1569
|
-
// If the base class is unknown, we have to make a conservative assumption.
|
1570
|
-
return true;
|
1571
|
-
}
|
1572
|
-
}
|
1573
|
-
|
1574
|
-
return false;
|
1575
|
-
}
|
1576
|
-
|
1577
|
-
export function synthesizeTypeVarForSelfCls(classType: ClassType, isClsParam: boolean): TypeVarType {
|
1578
|
-
const selfType = TypeVarType.createInstance(`__type_of_self__`);
|
1579
|
-
const scopeId = getTypeVarScopeId(classType) ?? '';
|
1580
|
-
selfType.details.isSynthesized = true;
|
1581
|
-
selfType.details.isSynthesizedSelf = true;
|
1582
|
-
selfType.nameWithScope = TypeVarType.makeNameWithScope(selfType.details.name, scopeId);
|
1583
|
-
selfType.scopeId = scopeId;
|
1584
|
-
|
1585
|
-
const boundType = ClassType.cloneForSpecialization(
|
1586
|
-
classType,
|
1587
|
-
ClassType.getTypeParameters(classType),
|
1588
|
-
/* isTypeArgumentExplicit */ false,
|
1589
|
-
/* includeSubclasses */ true
|
1590
|
-
);
|
1591
|
-
|
1592
|
-
selfType.details.boundType = ClassType.cloneAsInstance(boundType);
|
1593
|
-
|
1594
|
-
return isClsParam ? TypeVarType.cloneAsInstantiable(selfType) : selfType;
|
1595
|
-
}
|
1596
|
-
|
1597
|
-
// Returns the declared "return" type (the type returned from a return statement)
|
1598
|
-
// if it was declared, or undefined otherwise.
|
1599
|
-
export function getDeclaredGeneratorReturnType(functionType: FunctionType): Type | undefined {
|
1600
|
-
const returnType = FunctionType.getSpecializedReturnType(functionType);
|
1601
|
-
if (returnType) {
|
1602
|
-
const generatorTypeArgs = getGeneratorTypeArgs(returnType);
|
1603
|
-
|
1604
|
-
if (generatorTypeArgs) {
|
1605
|
-
// The send type is the third type arg.
|
1606
|
-
return generatorTypeArgs.length >= 3 ? generatorTypeArgs[2] : UnknownType.create();
|
1607
|
-
}
|
1608
|
-
}
|
1609
|
-
|
1610
|
-
return undefined;
|
1611
|
-
}
|
1612
|
-
|
1613
|
-
// If the declared return type is a Generator, Iterable, Iterator or the async
|
1614
|
-
// counterparts, returns the yield type. If the type is invalid for a generator,
|
1615
|
-
// returns undefined.
|
1616
|
-
export function getGeneratorYieldType(declaredReturnType: Type, isAsync: boolean): Type | undefined {
|
1617
|
-
let isLegalGeneratorType = true;
|
1618
|
-
|
1619
|
-
const yieldType = mapSubtypes(declaredReturnType, (subtype) => {
|
1620
|
-
if (isAnyOrUnknown(subtype)) {
|
1621
|
-
return subtype;
|
1622
|
-
}
|
1623
|
-
|
1624
|
-
if (isClassInstance(subtype)) {
|
1625
|
-
const expectedClasses = [
|
1626
|
-
['AsyncIterable', 'Iterable'],
|
1627
|
-
['AsyncIterator', 'Iterator'],
|
1628
|
-
['AsyncGenerator', 'Generator'],
|
1629
|
-
['', 'AwaitableGenerator'],
|
1630
|
-
];
|
1631
|
-
|
1632
|
-
if (expectedClasses.some((classes) => ClassType.isBuiltIn(subtype, isAsync ? classes[0] : classes[1]))) {
|
1633
|
-
return subtype.typeArguments && subtype.typeArguments.length >= 1
|
1634
|
-
? subtype.typeArguments[0]
|
1635
|
-
: UnknownType.create();
|
1636
|
-
}
|
1637
|
-
}
|
1638
|
-
|
1639
|
-
isLegalGeneratorType = false;
|
1640
|
-
return undefined;
|
1641
|
-
});
|
1642
|
-
|
1643
|
-
return isLegalGeneratorType ? yieldType : undefined;
|
1644
|
-
}
|
1645
|
-
|
1646
|
-
export function isEffectivelyInstantiable(type: Type): boolean {
|
1647
|
-
if (TypeBase.isInstantiable(type)) {
|
1648
|
-
return true;
|
1649
|
-
}
|
1650
|
-
|
1651
|
-
// Handle the special case of 'type', which is instantiable.
|
1652
|
-
if (isClassInstance(type) && ClassType.isBuiltIn(type, 'type')) {
|
1653
|
-
return true;
|
1654
|
-
}
|
1655
|
-
|
1656
|
-
if (isUnion(type)) {
|
1657
|
-
return type.subtypes.every((subtype) => isEffectivelyInstantiable(subtype));
|
1658
|
-
}
|
1659
|
-
|
1660
|
-
return false;
|
1661
|
-
}
|
1662
|
-
|
1663
|
-
export function convertToInstance(type: Type): Type {
|
1664
|
-
let result = mapSubtypes(type, (subtype) => {
|
1665
|
-
switch (subtype.category) {
|
1666
|
-
case TypeCategory.Class: {
|
1667
|
-
// Handle Type[x] as a special case.
|
1668
|
-
if (ClassType.isBuiltIn(subtype, 'Type')) {
|
1669
|
-
if (!subtype.typeArguments || subtype.typeArguments.length < 1) {
|
1670
|
-
return UnknownType.create();
|
1671
|
-
} else {
|
1672
|
-
return convertToInstantiable(subtype.typeArguments[0]);
|
1673
|
-
}
|
1674
|
-
}
|
1675
|
-
|
1676
|
-
return ClassType.cloneAsInstance(subtype);
|
1677
|
-
}
|
1678
|
-
|
1679
|
-
case TypeCategory.None: {
|
1680
|
-
return NoneType.createInstance();
|
1681
|
-
}
|
1682
|
-
|
1683
|
-
case TypeCategory.Function: {
|
1684
|
-
if (TypeBase.isInstantiable(subtype)) {
|
1685
|
-
return FunctionType.cloneAsInstance(subtype);
|
1686
|
-
}
|
1687
|
-
break;
|
1688
|
-
}
|
1689
|
-
|
1690
|
-
case TypeCategory.TypeVar: {
|
1691
|
-
if (TypeBase.isInstantiable(subtype)) {
|
1692
|
-
return TypeVarType.cloneAsInstance(subtype);
|
1693
|
-
}
|
1694
|
-
break;
|
1695
|
-
}
|
1696
|
-
}
|
1697
|
-
|
1698
|
-
return subtype;
|
1699
|
-
});
|
1700
|
-
|
1701
|
-
// Copy over any type alias information.
|
1702
|
-
if (type.typeAliasInfo && type !== result) {
|
1703
|
-
result = TypeBase.cloneForTypeAlias(
|
1704
|
-
result,
|
1705
|
-
type.typeAliasInfo.name,
|
1706
|
-
type.typeAliasInfo.fullName,
|
1707
|
-
type.typeAliasInfo.typeVarScopeId,
|
1708
|
-
type.typeAliasInfo.typeParameters,
|
1709
|
-
type.typeAliasInfo.typeArguments
|
1710
|
-
);
|
1711
|
-
}
|
1712
|
-
|
1713
|
-
return result;
|
1714
|
-
}
|
1715
|
-
|
1716
|
-
export function convertToInstantiable(type: Type): Type {
|
1717
|
-
let result = mapSubtypes(type, (subtype) => {
|
1718
|
-
switch (subtype.category) {
|
1719
|
-
case TypeCategory.Class: {
|
1720
|
-
return ClassType.cloneAsInstantiable(subtype);
|
1721
|
-
}
|
1722
|
-
|
1723
|
-
case TypeCategory.None: {
|
1724
|
-
return NoneType.createType();
|
1725
|
-
}
|
1726
|
-
|
1727
|
-
case TypeCategory.Function: {
|
1728
|
-
return FunctionType.cloneAsInstantiable(subtype);
|
1729
|
-
}
|
1730
|
-
|
1731
|
-
case TypeCategory.TypeVar: {
|
1732
|
-
return TypeVarType.cloneAsInstantiable(subtype);
|
1733
|
-
}
|
1734
|
-
}
|
1735
|
-
|
1736
|
-
return subtype;
|
1737
|
-
});
|
1738
|
-
|
1739
|
-
// Copy over any type alias information.
|
1740
|
-
if (type.typeAliasInfo && type !== result) {
|
1741
|
-
result = TypeBase.cloneForTypeAlias(
|
1742
|
-
result,
|
1743
|
-
type.typeAliasInfo.name,
|
1744
|
-
type.typeAliasInfo.fullName,
|
1745
|
-
type.typeAliasInfo.typeVarScopeId,
|
1746
|
-
type.typeAliasInfo.typeParameters,
|
1747
|
-
type.typeAliasInfo.typeArguments
|
1748
|
-
);
|
1749
|
-
}
|
1750
|
-
|
1751
|
-
return result;
|
1752
|
-
}
|
1753
|
-
|
1754
|
-
export function getMembersForClass(classType: ClassType, symbolTable: SymbolTable, includeInstanceVars: boolean) {
|
1755
|
-
for (let i = 0; i < classType.details.mro.length; i++) {
|
1756
|
-
const mroClass = classType.details.mro[i];
|
1757
|
-
|
1758
|
-
if (isInstantiableClass(mroClass)) {
|
1759
|
-
// Add any new member variables from this class.
|
1760
|
-
const isClassTypedDict = ClassType.isTypedDictClass(mroClass);
|
1761
|
-
mroClass.details.fields.forEach((symbol, name) => {
|
1762
|
-
if (symbol.isClassMember() || (includeInstanceVars && symbol.isInstanceMember())) {
|
1763
|
-
if (!isClassTypedDict || !isTypedDictMemberAccessedThroughIndex(symbol)) {
|
1764
|
-
if (!symbol.isInitVar()) {
|
1765
|
-
const existingSymbol = symbolTable.get(name);
|
1766
|
-
|
1767
|
-
if (!existingSymbol) {
|
1768
|
-
symbolTable.set(name, symbol);
|
1769
|
-
} else if (!existingSymbol.hasTypedDeclarations() && symbol.hasTypedDeclarations()) {
|
1770
|
-
// If the existing symbol is unannotated but a parent class
|
1771
|
-
// has an annotation for the symbol, use the parent type instead.
|
1772
|
-
symbolTable.set(name, symbol);
|
1773
|
-
}
|
1774
|
-
}
|
1775
|
-
}
|
1776
|
-
}
|
1777
|
-
});
|
1778
|
-
}
|
1779
|
-
}
|
1780
|
-
|
1781
|
-
// Add members of the metaclass as well.
|
1782
|
-
if (!includeInstanceVars) {
|
1783
|
-
const metaclass = classType.details.effectiveMetaclass;
|
1784
|
-
if (metaclass && isInstantiableClass(metaclass)) {
|
1785
|
-
for (const mroClass of metaclass.details.mro) {
|
1786
|
-
if (isInstantiableClass(mroClass)) {
|
1787
|
-
mroClass.details.fields.forEach((symbol, name) => {
|
1788
|
-
const existingSymbol = symbolTable.get(name);
|
1789
|
-
|
1790
|
-
if (!existingSymbol) {
|
1791
|
-
symbolTable.set(name, symbol);
|
1792
|
-
} else if (!existingSymbol.hasTypedDeclarations() && symbol.hasTypedDeclarations()) {
|
1793
|
-
// If the existing symbol is unannotated but a parent class
|
1794
|
-
// has an annotation for the symbol, use the parent type instead.
|
1795
|
-
symbolTable.set(name, symbol);
|
1796
|
-
}
|
1797
|
-
});
|
1798
|
-
} else {
|
1799
|
-
break;
|
1800
|
-
}
|
1801
|
-
}
|
1802
|
-
}
|
1803
|
-
}
|
1804
|
-
}
|
1805
|
-
|
1806
|
-
export function getMembersForModule(moduleType: ModuleType, symbolTable: SymbolTable) {
|
1807
|
-
// Start with the loader fields. If there are any symbols of the
|
1808
|
-
// same name defined within the module, they will overwrite the
|
1809
|
-
// loader fields.
|
1810
|
-
if (moduleType.loaderFields) {
|
1811
|
-
moduleType.loaderFields.forEach((symbol, name) => {
|
1812
|
-
symbolTable.set(name, symbol);
|
1813
|
-
});
|
1814
|
-
}
|
1815
|
-
|
1816
|
-
moduleType.fields.forEach((symbol, name) => {
|
1817
|
-
symbolTable.set(name, symbol);
|
1818
|
-
});
|
1819
|
-
}
|
1820
|
-
|
1821
|
-
// Determines if the type is an Unknown or a union that contains an Unknown.
|
1822
|
-
// It does not look at type arguments.
|
1823
|
-
export function containsUnknown(type: Type) {
|
1824
|
-
let foundUnknown = false;
|
1825
|
-
|
1826
|
-
doForEachSubtype(type, (subtype) => {
|
1827
|
-
if (isUnknown(subtype)) {
|
1828
|
-
foundUnknown = true;
|
1829
|
-
}
|
1830
|
-
});
|
1831
|
-
|
1832
|
-
return foundUnknown;
|
1833
|
-
}
|
1834
|
-
|
1835
|
-
// Determines if any part of the type contains "Unknown", including any type arguments.
|
1836
|
-
export function isPartlyUnknown(type: Type, allowUnknownTypeArgsForClasses = false, recursionCount = 0): boolean {
|
1837
|
-
if (recursionCount > maxTypeRecursionCount) {
|
1838
|
-
return false;
|
1839
|
-
}
|
1840
|
-
recursionCount++;
|
1841
|
-
|
1842
|
-
if (isUnknown(type)) {
|
1843
|
-
return true;
|
1844
|
-
}
|
1845
|
-
|
1846
|
-
// If this is a generic type alias, see if any of its type arguments
|
1847
|
-
// are either unspecified or are partially known.
|
1848
|
-
if (type.typeAliasInfo?.typeArguments) {
|
1849
|
-
if (
|
1850
|
-
type.typeAliasInfo.typeArguments.some((typeArg) =>
|
1851
|
-
isPartlyUnknown(typeArg, allowUnknownTypeArgsForClasses, recursionCount)
|
1852
|
-
)
|
1853
|
-
) {
|
1854
|
-
return true;
|
1855
|
-
}
|
1856
|
-
}
|
1857
|
-
|
1858
|
-
// See if a union contains an unknown type.
|
1859
|
-
if (isUnion(type)) {
|
1860
|
-
return (
|
1861
|
-
findSubtype(type, (subtype) => isPartlyUnknown(subtype, allowUnknownTypeArgsForClasses, recursionCount)) !==
|
1862
|
-
undefined
|
1863
|
-
);
|
1864
|
-
}
|
1865
|
-
|
1866
|
-
// See if an object or class has an unknown type argument.
|
1867
|
-
if (isClass(type)) {
|
1868
|
-
if (TypeBase.isInstance(type)) {
|
1869
|
-
allowUnknownTypeArgsForClasses = false;
|
1870
|
-
}
|
1871
|
-
|
1872
|
-
if (!allowUnknownTypeArgsForClasses && !ClassType.isPseudoGenericClass(type)) {
|
1873
|
-
const typeArgs = type.tupleTypeArguments?.map((t) => t.type) || type.typeArguments;
|
1874
|
-
if (typeArgs) {
|
1875
|
-
for (const argType of typeArgs) {
|
1876
|
-
if (isPartlyUnknown(argType, allowUnknownTypeArgsForClasses, recursionCount)) {
|
1877
|
-
return true;
|
1878
|
-
}
|
1879
|
-
}
|
1880
|
-
}
|
1881
|
-
}
|
1882
|
-
|
1883
|
-
return false;
|
1884
|
-
}
|
1885
|
-
|
1886
|
-
// See if a function has an unknown type.
|
1887
|
-
if (isOverloadedFunction(type)) {
|
1888
|
-
return type.overloads.some((overload) => {
|
1889
|
-
return isPartlyUnknown(overload, false, recursionCount);
|
1890
|
-
});
|
1891
|
-
}
|
1892
|
-
|
1893
|
-
if (isFunction(type)) {
|
1894
|
-
for (let i = 0; i < type.details.parameters.length; i++) {
|
1895
|
-
// Ignore parameters such as "*" that have no name.
|
1896
|
-
if (type.details.parameters[i].name) {
|
1897
|
-
const paramType = FunctionType.getEffectiveParameterType(type, i);
|
1898
|
-
if (isPartlyUnknown(paramType, /* allowUnknownTypeArgsForClasses */ false, recursionCount)) {
|
1899
|
-
return true;
|
1900
|
-
}
|
1901
|
-
}
|
1902
|
-
}
|
1903
|
-
|
1904
|
-
if (
|
1905
|
-
type.details.declaredReturnType &&
|
1906
|
-
!FunctionType.isParamSpecValue(type) &&
|
1907
|
-
isPartlyUnknown(type.details.declaredReturnType, /* allowUnknownTypeArgsForClasses */ false, recursionCount)
|
1908
|
-
) {
|
1909
|
-
return true;
|
1910
|
-
}
|
1911
|
-
|
1912
|
-
return false;
|
1913
|
-
}
|
1914
|
-
|
1915
|
-
return false;
|
1916
|
-
}
|
1917
|
-
|
1918
|
-
// If the specified type is a generic class with a single type argument
|
1919
|
-
// that is a union, it "explodes" the class into a union of classes with
|
1920
|
-
// each element of the union - e.g. Foo[A | B] becomes Foo[A] | Foo[B].
|
1921
|
-
export function explodeGenericClass(classType: ClassType) {
|
1922
|
-
if (!classType.typeArguments || classType.typeArguments.length !== 1 || !isUnion(classType.typeArguments[0])) {
|
1923
|
-
return classType;
|
1924
|
-
}
|
1925
|
-
|
1926
|
-
return combineTypes(
|
1927
|
-
classType.typeArguments[0].subtypes.map((subtype) => {
|
1928
|
-
return ClassType.cloneForSpecialization(classType, [subtype], /* isTypeArgumentExplicit */ true);
|
1929
|
-
})
|
1930
|
-
);
|
1931
|
-
}
|
1932
|
-
|
1933
|
-
// If the type is a union of same-sized tuples, these are combined into
|
1934
|
-
// a single tuple with that size. Otherwise, returns undefined.
|
1935
|
-
export function combineSameSizedTuples(type: Type, tupleType: Type | undefined) {
|
1936
|
-
if (!tupleType || !isInstantiableClass(tupleType) || isUnboundedTupleClass(tupleType)) {
|
1937
|
-
return undefined;
|
1938
|
-
}
|
1939
|
-
|
1940
|
-
let tupleEntries: Type[][] | undefined;
|
1941
|
-
let isValid = true;
|
1942
|
-
|
1943
|
-
doForEachSubtype(type, (subtype) => {
|
1944
|
-
if (isClassInstance(subtype)) {
|
1945
|
-
let tupleClass: ClassType | undefined;
|
1946
|
-
if (isClass(subtype) && isTupleClass(subtype) && !isUnboundedTupleClass(subtype)) {
|
1947
|
-
tupleClass = subtype;
|
1948
|
-
}
|
1949
|
-
|
1950
|
-
if (!tupleClass) {
|
1951
|
-
// Look in the mro list to see if this subtype derives from a
|
1952
|
-
// tuple with a known size. This includes named tuples.
|
1953
|
-
tupleClass = subtype.details.mro.find(
|
1954
|
-
(mroClass) => isClass(mroClass) && isTupleClass(mroClass) && !isUnboundedTupleClass(mroClass)
|
1955
|
-
) as ClassType | undefined;
|
1956
|
-
}
|
1957
|
-
|
1958
|
-
if (tupleClass && isClass(tupleClass) && tupleClass.tupleTypeArguments) {
|
1959
|
-
if (tupleEntries) {
|
1960
|
-
if (tupleEntries.length === tupleClass.tupleTypeArguments.length) {
|
1961
|
-
tupleClass.tupleTypeArguments.forEach((entry, index) => {
|
1962
|
-
tupleEntries![index].push(entry.type);
|
1963
|
-
});
|
1964
|
-
} else {
|
1965
|
-
isValid = false;
|
1966
|
-
}
|
1967
|
-
} else {
|
1968
|
-
tupleEntries = tupleClass.tupleTypeArguments.map((entry) => [entry.type]);
|
1969
|
-
}
|
1970
|
-
} else {
|
1971
|
-
isValid = false;
|
1972
|
-
}
|
1973
|
-
} else {
|
1974
|
-
isValid = false;
|
1975
|
-
}
|
1976
|
-
});
|
1977
|
-
|
1978
|
-
if (!isValid || !tupleEntries) {
|
1979
|
-
return undefined;
|
1980
|
-
}
|
1981
|
-
|
1982
|
-
return convertToInstance(
|
1983
|
-
specializeTupleClass(
|
1984
|
-
tupleType,
|
1985
|
-
tupleEntries.map((entry) => {
|
1986
|
-
return { type: combineTypes(entry), isUnbounded: false };
|
1987
|
-
})
|
1988
|
-
)
|
1989
|
-
);
|
1990
|
-
}
|
1991
|
-
|
1992
|
-
// Tuples require special handling for specialization. This method computes
|
1993
|
-
// the "effective" type argument, which is a union of the variadic type
|
1994
|
-
// arguments. If stripLiterals is true, literal values are stripped when
|
1995
|
-
// computing the effective type args.
|
1996
|
-
export function specializeTupleClass(
|
1997
|
-
classType: ClassType,
|
1998
|
-
typeArgs: TupleTypeArgument[],
|
1999
|
-
isTypeArgumentExplicit = true,
|
2000
|
-
stripLiterals = true,
|
2001
|
-
isUnpackedTuple = false
|
2002
|
-
): ClassType {
|
2003
|
-
let combinedTupleType = combineTypes(typeArgs.map((t) => t.type));
|
2004
|
-
|
2005
|
-
if (stripLiterals) {
|
2006
|
-
combinedTupleType = stripLiteralValue(combinedTupleType);
|
2007
|
-
}
|
2008
|
-
|
2009
|
-
// An empty tuple has an effective type of Any.
|
2010
|
-
if (isNever(combinedTupleType)) {
|
2011
|
-
combinedTupleType = AnyType.create();
|
2012
|
-
}
|
2013
|
-
|
2014
|
-
const clonedClassType = ClassType.cloneForSpecialization(
|
2015
|
-
classType,
|
2016
|
-
[combinedTupleType],
|
2017
|
-
isTypeArgumentExplicit,
|
2018
|
-
/* includeSubclasses */ undefined,
|
2019
|
-
typeArgs
|
2020
|
-
);
|
2021
|
-
|
2022
|
-
if (isUnpackedTuple) {
|
2023
|
-
clonedClassType.isUnpacked = true;
|
2024
|
-
}
|
2025
|
-
|
2026
|
-
return clonedClassType;
|
2027
|
-
}
|
2028
|
-
|
2029
|
-
// If the type is a function or overloaded function that has a paramSpec
|
2030
|
-
// associated with it and P.args and P.kwargs at the end of the signature,
|
2031
|
-
// it removes these parameters from the function.
|
2032
|
-
export function removeParamSpecVariadicsFromSignature(type: FunctionType | OverloadedFunctionType) {
|
2033
|
-
if (isFunction(type)) {
|
2034
|
-
return removeParamSpecVariadicsFromFunction(type);
|
2035
|
-
}
|
2036
|
-
|
2037
|
-
const newOverloads: FunctionType[] = [];
|
2038
|
-
let newTypeNeeded = false;
|
2039
|
-
|
2040
|
-
for (const overload of type.overloads) {
|
2041
|
-
const newOverload = removeParamSpecVariadicsFromFunction(overload);
|
2042
|
-
newOverloads.push(newOverload);
|
2043
|
-
if (newOverload !== overload) {
|
2044
|
-
newTypeNeeded = true;
|
2045
|
-
}
|
2046
|
-
}
|
2047
|
-
|
2048
|
-
return newTypeNeeded ? OverloadedFunctionType.create(newOverloads) : type;
|
2049
|
-
}
|
2050
|
-
|
2051
|
-
export function removeParamSpecVariadicsFromFunction(type: FunctionType): FunctionType {
|
2052
|
-
const paramCount = type.details.parameters.length;
|
2053
|
-
if (paramCount < 2) {
|
2054
|
-
return type;
|
2055
|
-
}
|
2056
|
-
|
2057
|
-
const argsParam = type.details.parameters[paramCount - 2];
|
2058
|
-
const kwargsParam = type.details.parameters[paramCount - 1];
|
2059
|
-
|
2060
|
-
if (
|
2061
|
-
argsParam.category !== ParameterCategory.VarArgList ||
|
2062
|
-
kwargsParam.category !== ParameterCategory.VarArgDictionary ||
|
2063
|
-
!isParamSpec(argsParam.type) ||
|
2064
|
-
!isParamSpec(kwargsParam.type) ||
|
2065
|
-
!isTypeSame(argsParam.type, kwargsParam.type)
|
2066
|
-
) {
|
2067
|
-
return type;
|
2068
|
-
}
|
2069
|
-
|
2070
|
-
return FunctionType.cloneRemoveParamSpecVariadics(type, argsParam.type);
|
2071
|
-
}
|
2072
|
-
|
2073
|
-
function _expandVariadicUnpackedUnion(type: Type) {
|
2074
|
-
if (isClassInstance(type) && isTupleClass(type) && type.tupleTypeArguments && type.isUnpacked) {
|
2075
|
-
return combineTypes(type.tupleTypeArguments.map((t) => t.type));
|
2076
|
-
}
|
2077
|
-
|
2078
|
-
return type;
|
2079
|
-
}
|
2080
|
-
|
2081
|
-
// If the declared return type for the function is a Generator or AsyncGenerator,
|
2082
|
-
// returns the type arguments for the type.
|
2083
|
-
export function getGeneratorTypeArgs(returnType: Type): Type[] | undefined {
|
2084
|
-
if (isClassInstance(returnType)) {
|
2085
|
-
if (ClassType.isBuiltIn(returnType, ['Generator', 'AsyncGenerator'])) {
|
2086
|
-
return returnType.typeArguments;
|
2087
|
-
} else if (ClassType.isBuiltIn(returnType, 'AwaitableGenerator')) {
|
2088
|
-
// AwaitableGenerator has four type arguments, and the last 3
|
2089
|
-
// correspond to the generator.
|
2090
|
-
return returnType.typeArguments?.slice(1);
|
2091
|
-
}
|
2092
|
-
}
|
2093
|
-
|
2094
|
-
return undefined;
|
2095
|
-
}
|
2096
|
-
|
2097
|
-
export function requiresTypeArguments(classType: ClassType) {
|
2098
|
-
if (classType.details.typeParameters.length > 0) {
|
2099
|
-
// If there are type parameters, type arguments are needed.
|
2100
|
-
// The exception is if type parameters have been synthesized
|
2101
|
-
// for classes that have untyped constructors.
|
2102
|
-
return !classType.details.typeParameters[0].details.isSynthesized;
|
2103
|
-
}
|
2104
|
-
|
2105
|
-
// There are a few built-in special classes that require
|
2106
|
-
// type arguments even though typeParameters is empty.
|
2107
|
-
if (ClassType.isSpecialBuiltIn(classType)) {
|
2108
|
-
const specialClasses = [
|
2109
|
-
'Tuple',
|
2110
|
-
'Callable',
|
2111
|
-
'Generic',
|
2112
|
-
'Type',
|
2113
|
-
'Optional',
|
2114
|
-
'Union',
|
2115
|
-
'Literal',
|
2116
|
-
'Annotated',
|
2117
|
-
'TypeGuard',
|
2118
|
-
'StrictTypeGuard',
|
2119
|
-
];
|
2120
|
-
|
2121
|
-
if (specialClasses.some((t) => t === (classType.aliasName || classType.details.name))) {
|
2122
|
-
return true;
|
2123
|
-
}
|
2124
|
-
}
|
2125
|
-
|
2126
|
-
return false;
|
2127
|
-
}
|
2128
|
-
|
2129
|
-
export function requiresSpecialization(
|
2130
|
-
type: Type,
|
2131
|
-
ignorePseudoGeneric = false,
|
2132
|
-
ignoreSelf = false,
|
2133
|
-
recursionCount = 0
|
2134
|
-
): boolean {
|
2135
|
-
if (recursionCount > maxTypeRecursionCount) {
|
2136
|
-
return false;
|
2137
|
-
}
|
2138
|
-
recursionCount++;
|
2139
|
-
|
2140
|
-
switch (type.category) {
|
2141
|
-
case TypeCategory.Class: {
|
2142
|
-
if (ClassType.isPseudoGenericClass(type) && ignorePseudoGeneric) {
|
2143
|
-
return false;
|
2144
|
-
}
|
2145
|
-
|
2146
|
-
if (type.typeArguments) {
|
2147
|
-
return (
|
2148
|
-
type.typeArguments.find((typeArg) =>
|
2149
|
-
requiresSpecialization(typeArg, ignorePseudoGeneric, ignoreSelf, recursionCount)
|
2150
|
-
) !== undefined
|
2151
|
-
);
|
2152
|
-
}
|
2153
|
-
|
2154
|
-
return ClassType.getTypeParameters(type).length > 0;
|
2155
|
-
}
|
2156
|
-
|
2157
|
-
case TypeCategory.Function: {
|
2158
|
-
if (type.details.paramSpec) {
|
2159
|
-
return true;
|
2160
|
-
}
|
2161
|
-
|
2162
|
-
for (let i = 0; i < type.details.parameters.length; i++) {
|
2163
|
-
if (
|
2164
|
-
requiresSpecialization(
|
2165
|
-
FunctionType.getEffectiveParameterType(type, i),
|
2166
|
-
ignorePseudoGeneric,
|
2167
|
-
ignoreSelf,
|
2168
|
-
recursionCount
|
2169
|
-
)
|
2170
|
-
) {
|
2171
|
-
return true;
|
2172
|
-
}
|
2173
|
-
}
|
2174
|
-
|
2175
|
-
const declaredReturnType =
|
2176
|
-
type.specializedTypes && type.specializedTypes.returnType
|
2177
|
-
? type.specializedTypes.returnType
|
2178
|
-
: type.details.declaredReturnType;
|
2179
|
-
if (declaredReturnType) {
|
2180
|
-
if (requiresSpecialization(declaredReturnType, ignorePseudoGeneric, ignoreSelf, recursionCount)) {
|
2181
|
-
return true;
|
2182
|
-
}
|
2183
|
-
} else if (type.inferredReturnType) {
|
2184
|
-
if (requiresSpecialization(type.inferredReturnType, ignorePseudoGeneric, ignoreSelf, recursionCount)) {
|
2185
|
-
return true;
|
2186
|
-
}
|
2187
|
-
}
|
2188
|
-
|
2189
|
-
return false;
|
2190
|
-
}
|
2191
|
-
|
2192
|
-
case TypeCategory.OverloadedFunction: {
|
2193
|
-
return (
|
2194
|
-
type.overloads.find((overload) =>
|
2195
|
-
requiresSpecialization(overload, ignorePseudoGeneric, ignoreSelf, recursionCount)
|
2196
|
-
) !== undefined
|
2197
|
-
);
|
2198
|
-
}
|
2199
|
-
|
2200
|
-
case TypeCategory.Union: {
|
2201
|
-
return (
|
2202
|
-
findSubtype(type, (subtype) =>
|
2203
|
-
requiresSpecialization(subtype, ignorePseudoGeneric, ignoreSelf, recursionCount)
|
2204
|
-
) !== undefined
|
2205
|
-
);
|
2206
|
-
}
|
2207
|
-
|
2208
|
-
case TypeCategory.TypeVar: {
|
2209
|
-
// Most TypeVar types need to be specialized.
|
2210
|
-
if (!type.details.recursiveTypeAliasName) {
|
2211
|
-
if (type.details.isSynthesizedSelf && ignoreSelf) {
|
2212
|
-
return false;
|
2213
|
-
}
|
2214
|
-
|
2215
|
-
return true;
|
2216
|
-
}
|
2217
|
-
|
2218
|
-
// If this is a recursive type alias, it may need to be specialized
|
2219
|
-
// if it has generic type arguments.
|
2220
|
-
if (type.typeAliasInfo?.typeArguments) {
|
2221
|
-
return type.typeAliasInfo.typeArguments.some((typeArg) =>
|
2222
|
-
requiresSpecialization(typeArg, ignorePseudoGeneric, ignoreSelf, recursionCount)
|
2223
|
-
);
|
2224
|
-
}
|
2225
|
-
}
|
2226
|
-
}
|
2227
|
-
|
2228
|
-
return false;
|
2229
|
-
}
|
2230
|
-
|
2231
|
-
// Computes the method resolution ordering for a class whose base classes
|
2232
|
-
// have already been filled in. The algorithm for computing MRO is described
|
2233
|
-
// here: https://www.python.org/download/releases/2.3/mro/. It returns true
|
2234
|
-
// if an MRO was possible, false otherwise.
|
2235
|
-
export function computeMroLinearization(classType: ClassType): boolean {
|
2236
|
-
let isMroFound = true;
|
2237
|
-
|
2238
|
-
// Clear out any existing MRO information.
|
2239
|
-
classType.details.mro = [];
|
2240
|
-
|
2241
|
-
const filteredBaseClasses = classType.details.baseClasses.filter((baseClass, index) => {
|
2242
|
-
if (isInstantiableClass(baseClass)) {
|
2243
|
-
// Generic has some special-case logic (see description of __mro_entries__
|
2244
|
-
// in PEP 560) that we need to account for here.
|
2245
|
-
if (ClassType.isBuiltIn(baseClass, 'Generic')) {
|
2246
|
-
// If the class is a Protocol, the generic is ignored for the purposes
|
2247
|
-
// of computing the MRO.
|
2248
|
-
if (ClassType.isProtocolClass(classType)) {
|
2249
|
-
return false;
|
2250
|
-
}
|
2251
|
-
|
2252
|
-
// If the class contains any specialized generic classes after
|
2253
|
-
// the Generic base, the Generic base is ignored for purposes
|
2254
|
-
// of computing the MRO.
|
2255
|
-
if (
|
2256
|
-
classType.details.baseClasses.some((innerBaseClass, innerIndex) => {
|
2257
|
-
return (
|
2258
|
-
innerIndex > index &&
|
2259
|
-
isInstantiableClass(innerBaseClass) &&
|
2260
|
-
innerBaseClass.typeArguments &&
|
2261
|
-
innerBaseClass.isTypeArgumentExplicit
|
2262
|
-
);
|
2263
|
-
})
|
2264
|
-
) {
|
2265
|
-
return false;
|
2266
|
-
}
|
2267
|
-
}
|
2268
|
-
}
|
2269
|
-
|
2270
|
-
return true;
|
2271
|
-
});
|
2272
|
-
|
2273
|
-
// Construct the list of class lists that need to be merged.
|
2274
|
-
const classListsToMerge: Type[][] = [];
|
2275
|
-
|
2276
|
-
filteredBaseClasses.forEach((baseClass, index) => {
|
2277
|
-
if (isInstantiableClass(baseClass)) {
|
2278
|
-
const typeVarContext = buildTypeVarContextFromSpecializedClass(baseClass, /* makeConcrete */ false);
|
2279
|
-
classListsToMerge.push(
|
2280
|
-
baseClass.details.mro.map((mroClass) => {
|
2281
|
-
return applySolvedTypeVars(mroClass, typeVarContext);
|
2282
|
-
})
|
2283
|
-
);
|
2284
|
-
} else {
|
2285
|
-
classListsToMerge.push([baseClass]);
|
2286
|
-
}
|
2287
|
-
});
|
2288
|
-
|
2289
|
-
classListsToMerge.push(
|
2290
|
-
filteredBaseClasses.map((baseClass) => {
|
2291
|
-
const typeVarContext = buildTypeVarContextFromSpecializedClass(classType, /* makeConcrete */ false);
|
2292
|
-
return applySolvedTypeVars(baseClass, typeVarContext);
|
2293
|
-
})
|
2294
|
-
);
|
2295
|
-
|
2296
|
-
// The first class in the MRO is the class itself.
|
2297
|
-
const typeVarContext = buildTypeVarContextFromSpecializedClass(classType, /* makeConcrete */ false);
|
2298
|
-
classType.details.mro.push(applySolvedTypeVars(classType, typeVarContext));
|
2299
|
-
|
2300
|
-
// Helper function that returns true if the specified searchClass
|
2301
|
-
// is found in the "tail" (i.e. in elements 1 through n) of any
|
2302
|
-
// of the class lists.
|
2303
|
-
const isInTail = (searchClass: ClassType, classLists: Type[][]) => {
|
2304
|
-
return classLists.some((classList) => {
|
2305
|
-
return (
|
2306
|
-
classList.findIndex(
|
2307
|
-
(value) => isInstantiableClass(value) && ClassType.isSameGenericClass(value, searchClass)
|
2308
|
-
) > 0
|
2309
|
-
);
|
2310
|
-
});
|
2311
|
-
};
|
2312
|
-
|
2313
|
-
const filterClass = (classToFilter: ClassType, classLists: Type[][]) => {
|
2314
|
-
for (let i = 0; i < classLists.length; i++) {
|
2315
|
-
classLists[i] = classLists[i].filter(
|
2316
|
-
(value) => !isInstantiableClass(value) || !ClassType.isSameGenericClass(value, classToFilter)
|
2317
|
-
);
|
2318
|
-
}
|
2319
|
-
};
|
2320
|
-
|
2321
|
-
while (true) {
|
2322
|
-
let foundValidHead = false;
|
2323
|
-
let nonEmptyList: Type[] | undefined = undefined;
|
2324
|
-
|
2325
|
-
for (let i = 0; i < classListsToMerge.length; i++) {
|
2326
|
-
const classList = classListsToMerge[i];
|
2327
|
-
|
2328
|
-
if (classList.length > 0) {
|
2329
|
-
if (nonEmptyList === undefined) {
|
2330
|
-
nonEmptyList = classList;
|
2331
|
-
}
|
2332
|
-
|
2333
|
-
if (!isInstantiableClass(classList[0])) {
|
2334
|
-
foundValidHead = true;
|
2335
|
-
classType.details.mro.push(classList[0]);
|
2336
|
-
classList.shift();
|
2337
|
-
break;
|
2338
|
-
} else if (!isInTail(classList[0], classListsToMerge)) {
|
2339
|
-
foundValidHead = true;
|
2340
|
-
classType.details.mro.push(classList[0]);
|
2341
|
-
filterClass(classList[0], classListsToMerge);
|
2342
|
-
break;
|
2343
|
-
}
|
2344
|
-
}
|
2345
|
-
}
|
2346
|
-
|
2347
|
-
// If all lists are empty, we are done.
|
2348
|
-
if (!nonEmptyList) {
|
2349
|
-
break;
|
2350
|
-
}
|
2351
|
-
|
2352
|
-
// We made it all the way through the list of class lists without
|
2353
|
-
// finding a valid head, but there is at least one list that's not
|
2354
|
-
// yet empty. This means there's no valid MRO order.
|
2355
|
-
if (!foundValidHead) {
|
2356
|
-
isMroFound = false;
|
2357
|
-
|
2358
|
-
// Handle the situation by pull the head off the first empty list.
|
2359
|
-
// This allows us to make forward progress.
|
2360
|
-
if (!isInstantiableClass(nonEmptyList[0])) {
|
2361
|
-
classType.details.mro.push(nonEmptyList[0]);
|
2362
|
-
nonEmptyList.shift();
|
2363
|
-
} else {
|
2364
|
-
classType.details.mro.push(nonEmptyList[0]);
|
2365
|
-
filterClass(nonEmptyList[0], classListsToMerge);
|
2366
|
-
}
|
2367
|
-
}
|
2368
|
-
}
|
2369
|
-
|
2370
|
-
return isMroFound;
|
2371
|
-
}
|
2372
|
-
|
2373
|
-
// Returns zero or more unique module names that point to the place(s)
|
2374
|
-
// where the type is declared. Unions, for example, can result in more
|
2375
|
-
// than one result. Type arguments are not included.
|
2376
|
-
export function getDeclaringModulesForType(type: Type): string[] {
|
2377
|
-
const moduleList: string[] = [];
|
2378
|
-
addDeclaringModuleNamesForType(type, moduleList);
|
2379
|
-
return moduleList;
|
2380
|
-
}
|
2381
|
-
|
2382
|
-
function addDeclaringModuleNamesForType(type: Type, moduleList: string[], recursionCount = 0) {
|
2383
|
-
if (recursionCount > maxTypeRecursionCount) {
|
2384
|
-
return;
|
2385
|
-
}
|
2386
|
-
recursionCount++;
|
2387
|
-
|
2388
|
-
const addIfUnique = (moduleName: string) => {
|
2389
|
-
if (moduleName && !moduleList.some((n) => n === moduleName)) {
|
2390
|
-
moduleList.push(moduleName);
|
2391
|
-
}
|
2392
|
-
};
|
2393
|
-
|
2394
|
-
switch (type.category) {
|
2395
|
-
case TypeCategory.Class: {
|
2396
|
-
addIfUnique(type.details.moduleName);
|
2397
|
-
break;
|
2398
|
-
}
|
2399
|
-
|
2400
|
-
case TypeCategory.Function: {
|
2401
|
-
addIfUnique(type.details.moduleName);
|
2402
|
-
break;
|
2403
|
-
}
|
2404
|
-
|
2405
|
-
case TypeCategory.OverloadedFunction: {
|
2406
|
-
type.overloads.forEach((overload) => {
|
2407
|
-
addDeclaringModuleNamesForType(overload, moduleList, recursionCount);
|
2408
|
-
});
|
2409
|
-
break;
|
2410
|
-
}
|
2411
|
-
|
2412
|
-
case TypeCategory.Union: {
|
2413
|
-
doForEachSubtype(type, (subtype) => {
|
2414
|
-
addDeclaringModuleNamesForType(subtype, moduleList, recursionCount);
|
2415
|
-
});
|
2416
|
-
break;
|
2417
|
-
}
|
2418
|
-
|
2419
|
-
case TypeCategory.Module: {
|
2420
|
-
addIfUnique(type.moduleName);
|
2421
|
-
break;
|
2422
|
-
}
|
2423
|
-
}
|
2424
|
-
}
|
2425
|
-
|
2426
|
-
export function convertParamSpecValueToType(paramSpecEntry: ParamSpecValue, omitParamSpec = false): Type {
|
2427
|
-
let hasParameters = paramSpecEntry.parameters.length > 0;
|
2428
|
-
|
2429
|
-
if (paramSpecEntry.parameters.length === 1) {
|
2430
|
-
// If the ParamSpec has a position-only separator as its only parameter,
|
2431
|
-
// treat it as though there are no parameters.
|
2432
|
-
const onlyParam = paramSpecEntry.parameters[0];
|
2433
|
-
if (onlyParam.category === ParameterCategory.Simple && !onlyParam.name) {
|
2434
|
-
hasParameters = false;
|
2435
|
-
}
|
2436
|
-
}
|
2437
|
-
|
2438
|
-
if (hasParameters || !paramSpecEntry.paramSpec || omitParamSpec) {
|
2439
|
-
// Create a function type from the param spec entries.
|
2440
|
-
const functionType = FunctionType.createInstance(
|
2441
|
-
'',
|
2442
|
-
'',
|
2443
|
-
'',
|
2444
|
-
FunctionTypeFlags.ParamSpecValue | paramSpecEntry.flags
|
2445
|
-
);
|
2446
|
-
|
2447
|
-
paramSpecEntry.parameters.forEach((entry) => {
|
2448
|
-
FunctionType.addParameter(functionType, {
|
2449
|
-
category: entry.category,
|
2450
|
-
name: entry.name,
|
2451
|
-
hasDefault: entry.hasDefault,
|
2452
|
-
isNameSynthesized: entry.isNameSynthesized,
|
2453
|
-
hasDeclaredType: true,
|
2454
|
-
type: entry.type,
|
2455
|
-
});
|
2456
|
-
});
|
2457
|
-
|
2458
|
-
if (!omitParamSpec) {
|
2459
|
-
functionType.details.paramSpec = paramSpecEntry.paramSpec;
|
2460
|
-
}
|
2461
|
-
functionType.details.docString = paramSpecEntry.docString;
|
2462
|
-
|
2463
|
-
return functionType;
|
2464
|
-
}
|
2465
|
-
|
2466
|
-
return paramSpecEntry.paramSpec;
|
2467
|
-
}
|
2468
|
-
|
2469
|
-
// Recursively walks a type and calls a callback for each TypeVar, allowing
|
2470
|
-
// it to be replaced with something else.
|
2471
|
-
class TypeVarTransformer {
|
2472
|
-
private _isTransformingTypeArg = false;
|
2473
|
-
private _pendingTypeVarTransformations = new Set<string>();
|
2474
|
-
|
2475
|
-
apply(type: Type, recursionCount = 0): Type {
|
2476
|
-
if (recursionCount > maxTypeRecursionCount) {
|
2477
|
-
return type;
|
2478
|
-
}
|
2479
|
-
recursionCount++;
|
2480
|
-
|
2481
|
-
type = this._transformGenericTypeAlias(type, recursionCount);
|
2482
|
-
|
2483
|
-
// Shortcut the operation if possible.
|
2484
|
-
if (!requiresSpecialization(type)) {
|
2485
|
-
return type;
|
2486
|
-
}
|
2487
|
-
|
2488
|
-
if (isAnyOrUnknown(type)) {
|
2489
|
-
return type;
|
2490
|
-
}
|
2491
|
-
|
2492
|
-
if (isNoneInstance(type)) {
|
2493
|
-
return type;
|
2494
|
-
}
|
2495
|
-
|
2496
|
-
if (isTypeVar(type)) {
|
2497
|
-
// Handle recursive type aliases specially. In particular,
|
2498
|
-
// we need to specialize type arguments for generic recursive
|
2499
|
-
// type aliases.
|
2500
|
-
if (type.details.recursiveTypeAliasName) {
|
2501
|
-
if (!type.typeAliasInfo?.typeArguments) {
|
2502
|
-
return type;
|
2503
|
-
}
|
2504
|
-
|
2505
|
-
let requiresUpdate = false;
|
2506
|
-
const typeArgs = type.typeAliasInfo.typeArguments.map((typeArg) => {
|
2507
|
-
const replacementType = this.apply(typeArg, recursionCount);
|
2508
|
-
if (replacementType !== typeArg) {
|
2509
|
-
requiresUpdate = true;
|
2510
|
-
}
|
2511
|
-
return replacementType;
|
2512
|
-
});
|
2513
|
-
|
2514
|
-
if (requiresUpdate) {
|
2515
|
-
return TypeBase.cloneForTypeAlias(
|
2516
|
-
type,
|
2517
|
-
type.typeAliasInfo.name,
|
2518
|
-
type.typeAliasInfo.fullName,
|
2519
|
-
type.typeAliasInfo.typeVarScopeId,
|
2520
|
-
type.typeAliasInfo.typeParameters,
|
2521
|
-
typeArgs
|
2522
|
-
);
|
2523
|
-
}
|
2524
|
-
|
2525
|
-
return type;
|
2526
|
-
}
|
2527
|
-
|
2528
|
-
let replacementType: Type = type;
|
2529
|
-
|
2530
|
-
// Recursively transform the results, but ensure that we don't replace the
|
2531
|
-
// same type variable recursively by setting it in the
|
2532
|
-
// _pendingTypeVarTransformations set.
|
2533
|
-
const typeVarName = TypeVarType.getNameWithScope(type);
|
2534
|
-
if (!this._pendingTypeVarTransformations.has(typeVarName)) {
|
2535
|
-
replacementType = this.transformTypeVar(type);
|
2536
|
-
|
2537
|
-
if (!this._isTransformingTypeArg) {
|
2538
|
-
this._pendingTypeVarTransformations.add(typeVarName);
|
2539
|
-
replacementType = this.apply(replacementType, recursionCount);
|
2540
|
-
this._pendingTypeVarTransformations.delete(typeVarName);
|
2541
|
-
}
|
2542
|
-
|
2543
|
-
// If we're transforming a variadic type variable that was in a union,
|
2544
|
-
// expand the union types.
|
2545
|
-
if (isVariadicTypeVar(type) && type.isVariadicInUnion) {
|
2546
|
-
replacementType = _expandVariadicUnpackedUnion(replacementType);
|
2547
|
-
}
|
2548
|
-
}
|
2549
|
-
|
2550
|
-
return replacementType;
|
2551
|
-
}
|
2552
|
-
|
2553
|
-
if (isUnion(type)) {
|
2554
|
-
const newUnionType = mapSubtypes(type, (subtype) => {
|
2555
|
-
let transformedType: Type = this.apply(subtype, recursionCount);
|
2556
|
-
|
2557
|
-
// If we're transforming a variadic type variable within a union,
|
2558
|
-
// combine the individual types within the variadic type variable.
|
2559
|
-
if (isVariadicTypeVar(subtype) && !isVariadicTypeVar(transformedType)) {
|
2560
|
-
const subtypesToCombine: Type[] = [];
|
2561
|
-
doForEachSubtype(transformedType, (transformedSubtype) => {
|
2562
|
-
subtypesToCombine.push(_expandVariadicUnpackedUnion(transformedSubtype));
|
2563
|
-
});
|
2564
|
-
|
2565
|
-
transformedType = combineTypes(subtypesToCombine);
|
2566
|
-
}
|
2567
|
-
|
2568
|
-
if (this.transformUnionSubtype) {
|
2569
|
-
return this.transformUnionSubtype(subtype, transformedType);
|
2570
|
-
}
|
2571
|
-
|
2572
|
-
return transformedType;
|
2573
|
-
});
|
2574
|
-
|
2575
|
-
return !isNever(newUnionType) ? newUnionType : UnknownType.create();
|
2576
|
-
}
|
2577
|
-
|
2578
|
-
if (isClass(type)) {
|
2579
|
-
return this._transformTypeVarsInClassType(type, recursionCount);
|
2580
|
-
}
|
2581
|
-
|
2582
|
-
if (isFunction(type)) {
|
2583
|
-
return this._transformTypeVarsInFunctionType(type, recursionCount);
|
2584
|
-
}
|
2585
|
-
|
2586
|
-
if (isOverloadedFunction(type)) {
|
2587
|
-
let requiresUpdate = false;
|
2588
|
-
|
2589
|
-
// Specialize each of the functions in the overload.
|
2590
|
-
const newOverloads: FunctionType[] = [];
|
2591
|
-
type.overloads.forEach((entry) => {
|
2592
|
-
const replacementType = this._transformTypeVarsInFunctionType(entry, recursionCount);
|
2593
|
-
newOverloads.push(replacementType);
|
2594
|
-
if (replacementType !== entry) {
|
2595
|
-
requiresUpdate = true;
|
2596
|
-
}
|
2597
|
-
});
|
2598
|
-
|
2599
|
-
// Construct a new overload with the specialized function types.
|
2600
|
-
return requiresUpdate ? OverloadedFunctionType.create(newOverloads) : type;
|
2601
|
-
}
|
2602
|
-
|
2603
|
-
return type;
|
2604
|
-
}
|
2605
|
-
|
2606
|
-
transformTypeVar(typeVar: TypeVarType): Type {
|
2607
|
-
return typeVar;
|
2608
|
-
}
|
2609
|
-
|
2610
|
-
transformVariadicTypeVar(paramSpec: TypeVarType): TupleTypeArgument[] | undefined {
|
2611
|
-
return undefined;
|
2612
|
-
}
|
2613
|
-
|
2614
|
-
transformParamSpec(paramSpec: TypeVarType): ParamSpecValue | undefined {
|
2615
|
-
return undefined;
|
2616
|
-
}
|
2617
|
-
|
2618
|
-
transformUnionSubtype(preTransform: Type, postTransform: Type): Type | undefined {
|
2619
|
-
return postTransform;
|
2620
|
-
}
|
2621
|
-
|
2622
|
-
private _transformGenericTypeAlias(type: Type, recursionCount: number) {
|
2623
|
-
if (!type.typeAliasInfo || !type.typeAliasInfo.typeParameters || !type.typeAliasInfo.typeArguments) {
|
2624
|
-
return type;
|
2625
|
-
}
|
2626
|
-
|
2627
|
-
let requiresUpdate = false;
|
2628
|
-
const newTypeArgs = type.typeAliasInfo.typeArguments.map((typeArg) => {
|
2629
|
-
const updatedType = this.apply(typeArg, recursionCount);
|
2630
|
-
if (type !== updatedType) {
|
2631
|
-
requiresUpdate = true;
|
2632
|
-
}
|
2633
|
-
return updatedType;
|
2634
|
-
});
|
2635
|
-
|
2636
|
-
return requiresUpdate
|
2637
|
-
? TypeBase.cloneForTypeAlias(
|
2638
|
-
type,
|
2639
|
-
type.typeAliasInfo.name,
|
2640
|
-
type.typeAliasInfo.fullName,
|
2641
|
-
type.typeAliasInfo.typeVarScopeId,
|
2642
|
-
type.typeAliasInfo.typeParameters,
|
2643
|
-
newTypeArgs
|
2644
|
-
)
|
2645
|
-
: type;
|
2646
|
-
}
|
2647
|
-
|
2648
|
-
private _transformTypeVarsInClassType(classType: ClassType, recursionCount: number): ClassType {
|
2649
|
-
// Handle the common case where the class has no type parameters.
|
2650
|
-
if (ClassType.getTypeParameters(classType).length === 0 && !ClassType.isSpecialBuiltIn(classType)) {
|
2651
|
-
return classType;
|
2652
|
-
}
|
2653
|
-
|
2654
|
-
let newTypeArgs: Type[] = [];
|
2655
|
-
let newVariadicTypeArgs: TupleTypeArgument[] | undefined;
|
2656
|
-
let specializationNeeded = false;
|
2657
|
-
const typeParams = ClassType.getTypeParameters(classType);
|
2658
|
-
|
2659
|
-
const transformParamSpec = (paramSpec: TypeVarType) => {
|
2660
|
-
const paramSpecValue = this.transformParamSpec(paramSpec);
|
2661
|
-
if (paramSpecValue) {
|
2662
|
-
specializationNeeded = true;
|
2663
|
-
return convertParamSpecValueToType(paramSpecValue);
|
2664
|
-
} else {
|
2665
|
-
return paramSpec;
|
2666
|
-
}
|
2667
|
-
};
|
2668
|
-
|
2669
|
-
const wasTransformingTypeArg = this._isTransformingTypeArg;
|
2670
|
-
this._isTransformingTypeArg = true;
|
2671
|
-
|
2672
|
-
// If type args were previously provided, specialize them.
|
2673
|
-
if (classType.typeArguments) {
|
2674
|
-
newTypeArgs = classType.typeArguments.map((oldTypeArgType) => {
|
2675
|
-
if (isTypeVar(oldTypeArgType) && oldTypeArgType.details.isParamSpec) {
|
2676
|
-
return transformParamSpec(oldTypeArgType);
|
2677
|
-
}
|
2678
|
-
|
2679
|
-
let newTypeArgType = this.apply(oldTypeArgType, recursionCount);
|
2680
|
-
if (newTypeArgType !== oldTypeArgType) {
|
2681
|
-
specializationNeeded = true;
|
2682
|
-
|
2683
|
-
// If this was a variadic type variable that was part of a union
|
2684
|
-
// (e.g. Union[Unpack[Vs]]), expand the subtypes into a union here.
|
2685
|
-
if (
|
2686
|
-
isTypeVar(oldTypeArgType) &&
|
2687
|
-
isVariadicTypeVar(oldTypeArgType) &&
|
2688
|
-
oldTypeArgType.isVariadicInUnion
|
2689
|
-
) {
|
2690
|
-
newTypeArgType = _expandVariadicUnpackedUnion(newTypeArgType);
|
2691
|
-
}
|
2692
|
-
}
|
2693
|
-
return newTypeArgType;
|
2694
|
-
});
|
2695
|
-
} else {
|
2696
|
-
typeParams.forEach((typeParam) => {
|
2697
|
-
let replacementType: Type = typeParam;
|
2698
|
-
|
2699
|
-
if (typeParam.details.isParamSpec) {
|
2700
|
-
replacementType = transformParamSpec(typeParam);
|
2701
|
-
if (replacementType !== typeParam) {
|
2702
|
-
specializationNeeded = true;
|
2703
|
-
}
|
2704
|
-
} else {
|
2705
|
-
const typeParamName = TypeVarType.getNameWithScope(typeParam);
|
2706
|
-
if (!this._pendingTypeVarTransformations.has(typeParamName)) {
|
2707
|
-
replacementType = this.transformTypeVar(typeParam);
|
2708
|
-
|
2709
|
-
if (replacementType !== typeParam) {
|
2710
|
-
if (!this._isTransformingTypeArg) {
|
2711
|
-
this._pendingTypeVarTransformations.add(typeParamName);
|
2712
|
-
replacementType = this.apply(replacementType, recursionCount);
|
2713
|
-
this._pendingTypeVarTransformations.delete(typeParamName);
|
2714
|
-
}
|
2715
|
-
|
2716
|
-
specializationNeeded = true;
|
2717
|
-
}
|
2718
|
-
}
|
2719
|
-
}
|
2720
|
-
|
2721
|
-
newTypeArgs.push(replacementType);
|
2722
|
-
});
|
2723
|
-
}
|
2724
|
-
|
2725
|
-
if (ClassType.isTupleClass(classType)) {
|
2726
|
-
if (classType.tupleTypeArguments) {
|
2727
|
-
newVariadicTypeArgs = [];
|
2728
|
-
classType.tupleTypeArguments.forEach((oldTypeArgType) => {
|
2729
|
-
const newTypeArgType = this.apply(oldTypeArgType.type, recursionCount);
|
2730
|
-
|
2731
|
-
if (newTypeArgType !== oldTypeArgType.type) {
|
2732
|
-
specializationNeeded = true;
|
2733
|
-
}
|
2734
|
-
|
2735
|
-
if (
|
2736
|
-
isVariadicTypeVar(oldTypeArgType.type) &&
|
2737
|
-
isClassInstance(newTypeArgType) &&
|
2738
|
-
isTupleClass(newTypeArgType) &&
|
2739
|
-
newTypeArgType.tupleTypeArguments
|
2740
|
-
) {
|
2741
|
-
appendArray(newVariadicTypeArgs!, newTypeArgType.tupleTypeArguments);
|
2742
|
-
} else {
|
2743
|
-
newVariadicTypeArgs!.push({ type: newTypeArgType, isUnbounded: oldTypeArgType.isUnbounded });
|
2744
|
-
}
|
2745
|
-
});
|
2746
|
-
} else if (typeParams.length > 0) {
|
2747
|
-
newVariadicTypeArgs = this.transformVariadicTypeVar(typeParams[0]);
|
2748
|
-
if (newVariadicTypeArgs) {
|
2749
|
-
specializationNeeded = true;
|
2750
|
-
}
|
2751
|
-
}
|
2752
|
-
}
|
2753
|
-
|
2754
|
-
this._isTransformingTypeArg = wasTransformingTypeArg;
|
2755
|
-
|
2756
|
-
// If specialization wasn't needed, don't allocate a new class.
|
2757
|
-
if (!specializationNeeded) {
|
2758
|
-
return classType;
|
2759
|
-
}
|
2760
|
-
|
2761
|
-
return ClassType.cloneForSpecialization(
|
2762
|
-
classType,
|
2763
|
-
newTypeArgs,
|
2764
|
-
/* isTypeArgumentExplicit */ true,
|
2765
|
-
/* includeSubclasses */ undefined,
|
2766
|
-
newVariadicTypeArgs
|
2767
|
-
);
|
2768
|
-
}
|
2769
|
-
|
2770
|
-
private _transformTypeVarsInFunctionType(sourceType: FunctionType, recursionCount: number): FunctionType {
|
2771
|
-
let functionType = sourceType;
|
2772
|
-
|
2773
|
-
// Handle functions with a parameter specification in a special manner.
|
2774
|
-
if (functionType.details.paramSpec) {
|
2775
|
-
const paramSpec = this.transformParamSpec(functionType.details.paramSpec);
|
2776
|
-
if (paramSpec) {
|
2777
|
-
functionType = FunctionType.cloneForParamSpec(functionType, paramSpec);
|
2778
|
-
}
|
2779
|
-
}
|
2780
|
-
|
2781
|
-
const declaredReturnType = FunctionType.getSpecializedReturnType(functionType);
|
2782
|
-
const specializedReturnType = declaredReturnType ? this.apply(declaredReturnType, recursionCount) : undefined;
|
2783
|
-
let typesRequiredSpecialization = declaredReturnType !== specializedReturnType;
|
2784
|
-
|
2785
|
-
const specializedParameters: SpecializedFunctionTypes = {
|
2786
|
-
parameterTypes: [],
|
2787
|
-
returnType: specializedReturnType,
|
2788
|
-
};
|
2789
|
-
|
2790
|
-
// Does this function end with *args: P.args, **args: P.kwargs? If so, we'll
|
2791
|
-
// modify the function and replace these parameters with the signature captured
|
2792
|
-
// by the ParamSpec.
|
2793
|
-
if (functionType.details.parameters.length >= 2) {
|
2794
|
-
const argsParam = functionType.details.parameters[functionType.details.parameters.length - 2];
|
2795
|
-
const kwargsParam = functionType.details.parameters[functionType.details.parameters.length - 1];
|
2796
|
-
const argsParamType = FunctionType.getEffectiveParameterType(
|
2797
|
-
functionType,
|
2798
|
-
functionType.details.parameters.length - 2
|
2799
|
-
);
|
2800
|
-
const kwargsParamType = FunctionType.getEffectiveParameterType(
|
2801
|
-
functionType,
|
2802
|
-
functionType.details.parameters.length - 1
|
2803
|
-
);
|
2804
|
-
|
2805
|
-
if (
|
2806
|
-
argsParam.category === ParameterCategory.VarArgList &&
|
2807
|
-
kwargsParam.category === ParameterCategory.VarArgDictionary &&
|
2808
|
-
isParamSpec(argsParamType) &&
|
2809
|
-
isParamSpec(kwargsParamType) &&
|
2810
|
-
isTypeSame(argsParamType, kwargsParamType)
|
2811
|
-
) {
|
2812
|
-
const paramSpecType = this.transformParamSpec(argsParamType);
|
2813
|
-
if (paramSpecType) {
|
2814
|
-
if (
|
2815
|
-
paramSpecType.parameters.length > 0 ||
|
2816
|
-
paramSpecType.paramSpec === undefined ||
|
2817
|
-
!isTypeSame(argsParamType, paramSpecType.paramSpec)
|
2818
|
-
) {
|
2819
|
-
functionType = FunctionType.cloneForParamSpecApplication(functionType, paramSpecType);
|
2820
|
-
}
|
2821
|
-
}
|
2822
|
-
}
|
2823
|
-
}
|
2824
|
-
|
2825
|
-
let variadicParamIndex: number | undefined;
|
2826
|
-
let variadicTypesToUnpack: TupleTypeArgument[] | undefined;
|
2827
|
-
const specializedDefaultArgs: (Type | undefined)[] = [];
|
2828
|
-
|
2829
|
-
for (let i = 0; i < functionType.details.parameters.length; i++) {
|
2830
|
-
const paramType = FunctionType.getEffectiveParameterType(functionType, i);
|
2831
|
-
const specializedType = this.apply(paramType, recursionCount);
|
2832
|
-
specializedParameters.parameterTypes.push(specializedType);
|
2833
|
-
|
2834
|
-
// Do we need to specialize the default argument type for this parameter?
|
2835
|
-
let defaultArgType = FunctionType.getEffectiveParameterDefaultArgType(functionType, i);
|
2836
|
-
if (defaultArgType) {
|
2837
|
-
const specializedArgType = this.apply(defaultArgType, recursionCount);
|
2838
|
-
if (specializedArgType !== defaultArgType) {
|
2839
|
-
defaultArgType = specializedArgType;
|
2840
|
-
typesRequiredSpecialization = true;
|
2841
|
-
}
|
2842
|
-
}
|
2843
|
-
specializedDefaultArgs.push(defaultArgType);
|
2844
|
-
|
2845
|
-
if (
|
2846
|
-
variadicParamIndex === undefined &&
|
2847
|
-
isVariadicTypeVar(paramType) &&
|
2848
|
-
functionType.details.parameters[i].category === ParameterCategory.VarArgList
|
2849
|
-
) {
|
2850
|
-
variadicParamIndex = i;
|
2851
|
-
|
2852
|
-
if (isClassInstance(specializedType) && isTupleClass(specializedType) && specializedType.isUnpacked) {
|
2853
|
-
variadicTypesToUnpack = specializedType.tupleTypeArguments;
|
2854
|
-
}
|
2855
|
-
}
|
2856
|
-
|
2857
|
-
if (paramType !== specializedType) {
|
2858
|
-
typesRequiredSpecialization = true;
|
2859
|
-
}
|
2860
|
-
}
|
2861
|
-
|
2862
|
-
if (!typesRequiredSpecialization) {
|
2863
|
-
return functionType;
|
2864
|
-
}
|
2865
|
-
|
2866
|
-
let specializedInferredReturnType: Type | undefined;
|
2867
|
-
if (functionType.inferredReturnType) {
|
2868
|
-
specializedInferredReturnType = this.apply(functionType.inferredReturnType, recursionCount);
|
2869
|
-
}
|
2870
|
-
|
2871
|
-
if (specializedDefaultArgs.some((t) => t !== undefined)) {
|
2872
|
-
specializedParameters.parameterDefaultArgs = specializedDefaultArgs;
|
2873
|
-
}
|
2874
|
-
|
2875
|
-
// If there was no unpacked variadic type variable, we're done.
|
2876
|
-
if (!variadicTypesToUnpack) {
|
2877
|
-
return FunctionType.cloneForSpecialization(
|
2878
|
-
functionType,
|
2879
|
-
specializedParameters,
|
2880
|
-
specializedInferredReturnType
|
2881
|
-
);
|
2882
|
-
}
|
2883
|
-
|
2884
|
-
// Unpack the tuple and synthesize a new function in the process.
|
2885
|
-
const newFunctionType = FunctionType.createSynthesizedInstance('');
|
2886
|
-
let insertKeywordOnlySeparator = false;
|
2887
|
-
let swallowPositionOnlySeparator = false;
|
2888
|
-
|
2889
|
-
specializedParameters.parameterTypes.forEach((paramType, index) => {
|
2890
|
-
if (index === variadicParamIndex) {
|
2891
|
-
let sawUnboundedEntry = false;
|
2892
|
-
|
2893
|
-
// Unpack the tuple into individual parameters.
|
2894
|
-
variadicTypesToUnpack!.forEach((unpackedType) => {
|
2895
|
-
FunctionType.addParameter(newFunctionType, {
|
2896
|
-
category: unpackedType.isUnbounded ? ParameterCategory.VarArgList : ParameterCategory.Simple,
|
2897
|
-
name: `__p${newFunctionType.details.parameters.length}`,
|
2898
|
-
isNameSynthesized: true,
|
2899
|
-
type: unpackedType.type,
|
2900
|
-
hasDeclaredType: true,
|
2901
|
-
});
|
2902
|
-
|
2903
|
-
if (unpackedType.isUnbounded) {
|
2904
|
-
sawUnboundedEntry = true;
|
2905
|
-
}
|
2906
|
-
});
|
2907
|
-
|
2908
|
-
if (sawUnboundedEntry) {
|
2909
|
-
swallowPositionOnlySeparator = true;
|
2910
|
-
} else {
|
2911
|
-
insertKeywordOnlySeparator = true;
|
2912
|
-
}
|
2913
|
-
} else {
|
2914
|
-
const param = { ...functionType.details.parameters[index] };
|
2915
|
-
|
2916
|
-
if (param.category === ParameterCategory.VarArgList && !param.name) {
|
2917
|
-
insertKeywordOnlySeparator = false;
|
2918
|
-
} else if (param.category === ParameterCategory.VarArgDictionary) {
|
2919
|
-
insertKeywordOnlySeparator = false;
|
2920
|
-
}
|
2921
|
-
|
2922
|
-
// Insert a keyword-only separator parameter if we previously
|
2923
|
-
// unpacked a variadic TypeVar.
|
2924
|
-
if (param.category === ParameterCategory.Simple && param.name && insertKeywordOnlySeparator) {
|
2925
|
-
FunctionType.addParameter(newFunctionType, {
|
2926
|
-
category: ParameterCategory.VarArgList,
|
2927
|
-
type: UnknownType.create(),
|
2928
|
-
});
|
2929
|
-
insertKeywordOnlySeparator = false;
|
2930
|
-
}
|
2931
|
-
|
2932
|
-
param.type = paramType;
|
2933
|
-
if (param.name && param.isNameSynthesized) {
|
2934
|
-
param.name = `__p${newFunctionType.details.parameters.length}`;
|
2935
|
-
}
|
2936
|
-
|
2937
|
-
if (param.category !== ParameterCategory.Simple || param.name || !swallowPositionOnlySeparator) {
|
2938
|
-
FunctionType.addParameter(newFunctionType, param);
|
2939
|
-
}
|
2940
|
-
}
|
2941
|
-
});
|
2942
|
-
|
2943
|
-
newFunctionType.details.declaredReturnType = specializedParameters.returnType;
|
2944
|
-
|
2945
|
-
return newFunctionType;
|
2946
|
-
}
|
2947
|
-
}
|
2948
|
-
|
2949
|
-
// Specializes a (potentially generic) type by substituting
|
2950
|
-
// type variables from a type var map.
|
2951
|
-
class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
2952
|
-
constructor(
|
2953
|
-
private _typeVarContext: TypeVarContext,
|
2954
|
-
private _unknownIfNotFound = false,
|
2955
|
-
private _useNarrowBoundOnly = false,
|
2956
|
-
private _eliminateUnsolvedInUnions = false,
|
2957
|
-
private _typeClassType?: Type
|
2958
|
-
) {
|
2959
|
-
super();
|
2960
|
-
}
|
2961
|
-
|
2962
|
-
override transformTypeVar(typeVar: TypeVarType) {
|
2963
|
-
// If the type variable is unrelated to the scopes we're solving,
|
2964
|
-
// don't transform that type variable.
|
2965
|
-
if (typeVar.scopeId && this._typeVarContext.hasSolveForScope(typeVar.scopeId)) {
|
2966
|
-
let replacement = this._typeVarContext.getTypeVarType(typeVar, this._useNarrowBoundOnly);
|
2967
|
-
|
2968
|
-
// If there was no narrow bound but there is a wide bound that
|
2969
|
-
// contains literals, we'll use the wide bound even if "useNarrowBoundOnly"
|
2970
|
-
// is specified.
|
2971
|
-
if (!replacement && this._useNarrowBoundOnly) {
|
2972
|
-
const wideType = this._typeVarContext.getTypeVarType(typeVar);
|
2973
|
-
if (wideType) {
|
2974
|
-
if (containsLiteralType(wideType, /* includeTypeArgs */ true)) {
|
2975
|
-
replacement = wideType;
|
2976
|
-
}
|
2977
|
-
}
|
2978
|
-
}
|
2979
|
-
|
2980
|
-
if (replacement) {
|
2981
|
-
if (TypeBase.isInstantiable(typeVar)) {
|
2982
|
-
if (
|
2983
|
-
isAnyOrUnknown(replacement) &&
|
2984
|
-
this._typeClassType &&
|
2985
|
-
isInstantiableClass(this._typeClassType)
|
2986
|
-
) {
|
2987
|
-
replacement = ClassType.cloneForSpecialization(
|
2988
|
-
ClassType.cloneAsInstance(this._typeClassType),
|
2989
|
-
[replacement],
|
2990
|
-
/* isTypeArgumentExplicit */ true
|
2991
|
-
);
|
2992
|
-
} else {
|
2993
|
-
replacement = convertToInstantiable(replacement);
|
2994
|
-
}
|
2995
|
-
}
|
2996
|
-
return replacement;
|
2997
|
-
}
|
2998
|
-
|
2999
|
-
// If this typeVar is in scope for what we're solving but the type
|
3000
|
-
// var map doesn't contain any entry for it, replace with Unknown.
|
3001
|
-
if (this._unknownIfNotFound && !this._typeVarContext.hasSolveForScope(WildcardTypeVarScopeId)) {
|
3002
|
-
return UnknownType.create();
|
3003
|
-
}
|
3004
|
-
}
|
3005
|
-
|
3006
|
-
return typeVar;
|
3007
|
-
}
|
3008
|
-
|
3009
|
-
override transformUnionSubtype(preTransform: Type, postTransform: Type): Type | undefined {
|
3010
|
-
// If a union contains unsolved TypeVars within scope, eliminate them
|
3011
|
-
// unless this results in an empty union. This elimination is needed
|
3012
|
-
// in cases where TypeVars can go unsolved due to unions in parameter
|
3013
|
-
// annotations, like this:
|
3014
|
-
// def test(x: Union[str, T]) -> Union[str, T]
|
3015
|
-
if (this._eliminateUnsolvedInUnions) {
|
3016
|
-
if (
|
3017
|
-
isTypeVar(preTransform) &&
|
3018
|
-
preTransform.scopeId !== undefined &&
|
3019
|
-
this._typeVarContext.hasSolveForScope(preTransform.scopeId)
|
3020
|
-
) {
|
3021
|
-
// If the TypeVar was not transformed, then it was unsolved,
|
3022
|
-
// and we'll eliminate it.
|
3023
|
-
if (preTransform === postTransform) {
|
3024
|
-
return undefined;
|
3025
|
-
}
|
3026
|
-
|
3027
|
-
// If _unknownIfNotFound is true, the postTransform type will
|
3028
|
-
// be Unknown, which we want to eliminate.
|
3029
|
-
if (isUnknown(postTransform) && this._unknownIfNotFound) {
|
3030
|
-
return undefined;
|
3031
|
-
}
|
3032
|
-
}
|
3033
|
-
}
|
3034
|
-
|
3035
|
-
return postTransform;
|
3036
|
-
}
|
3037
|
-
|
3038
|
-
override transformVariadicTypeVar(typeVar: TypeVarType) {
|
3039
|
-
if (!typeVar.scopeId || !this._typeVarContext.hasSolveForScope(typeVar.scopeId)) {
|
3040
|
-
return undefined;
|
3041
|
-
}
|
3042
|
-
|
3043
|
-
return this._typeVarContext.getVariadicTypeVar(typeVar);
|
3044
|
-
}
|
3045
|
-
|
3046
|
-
override transformParamSpec(paramSpec: TypeVarType) {
|
3047
|
-
if (!paramSpec.scopeId || !this._typeVarContext.hasSolveForScope(paramSpec.scopeId)) {
|
3048
|
-
return undefined;
|
3049
|
-
}
|
3050
|
-
|
3051
|
-
const transformedParamSpec = this._typeVarContext.getParamSpec(paramSpec);
|
3052
|
-
if (transformedParamSpec) {
|
3053
|
-
return transformedParamSpec;
|
3054
|
-
}
|
3055
|
-
|
3056
|
-
if (this._unknownIfNotFound && !this._typeVarContext.hasSolveForScope(WildcardTypeVarScopeId)) {
|
3057
|
-
// Convert to the ParamSpec equivalent of "Unknown".
|
3058
|
-
const paramSpecValue: ParamSpecValue = {
|
3059
|
-
flags: FunctionTypeFlags.None,
|
3060
|
-
parameters: FunctionType.getDefaultParameters(/* useUnknown */ true),
|
3061
|
-
typeVarScopeId: undefined,
|
3062
|
-
docString: undefined,
|
3063
|
-
paramSpec: undefined,
|
3064
|
-
};
|
3065
|
-
|
3066
|
-
return paramSpecValue;
|
3067
|
-
}
|
3068
|
-
|
3069
|
-
return undefined;
|
3070
|
-
}
|
3071
|
-
}
|
3072
|
-
|
3073
|
-
class ExpectedConstructorTypeTransformer extends TypeVarTransformer {
|
3074
|
-
static synthesizedTypeVarIndexForExpectedType = 1;
|
3075
|
-
|
3076
|
-
dummyScopeId = '__expected_type_scope_id';
|
3077
|
-
dummyTypeVarPrefix = '__expected_type_';
|
3078
|
-
|
3079
|
-
constructor(private _typeVarContext: TypeVarContext, private _liveTypeVarScopes: TypeVarScopeId[]) {
|
3080
|
-
super();
|
3081
|
-
|
3082
|
-
this._typeVarContext.addSolveForScope(this.dummyScopeId);
|
3083
|
-
}
|
3084
|
-
|
3085
|
-
private _isTypeVarLive(typeVar: TypeVarType) {
|
3086
|
-
return this._liveTypeVarScopes.some((scopeId) => typeVar.scopeId === scopeId);
|
3087
|
-
}
|
3088
|
-
|
3089
|
-
private _createDummyTypeVar(prevTypeVar: TypeVarType) {
|
3090
|
-
// If we previously synthesized this dummy type var, just return it.
|
3091
|
-
if (prevTypeVar.details.isSynthesized && prevTypeVar.details.name.startsWith(this.dummyTypeVarPrefix)) {
|
3092
|
-
return prevTypeVar;
|
3093
|
-
}
|
3094
|
-
|
3095
|
-
const isInstance = TypeBase.isInstance(prevTypeVar);
|
3096
|
-
let newTypeVar = TypeVarType.createInstance(
|
3097
|
-
`__expected_type_${ExpectedConstructorTypeTransformer.synthesizedTypeVarIndexForExpectedType}`
|
3098
|
-
);
|
3099
|
-
newTypeVar.details.isSynthesized = true;
|
3100
|
-
newTypeVar.scopeId = this.dummyScopeId;
|
3101
|
-
newTypeVar.nameWithScope = TypeVarType.makeNameWithScope(newTypeVar.details.name, this.dummyScopeId);
|
3102
|
-
if (!isInstance) {
|
3103
|
-
newTypeVar = convertToInstantiable(newTypeVar) as TypeVarType;
|
3104
|
-
}
|
3105
|
-
|
3106
|
-
// If the original TypeVar was bound or constrained, make the replacement as well.
|
3107
|
-
newTypeVar.details.boundType = prevTypeVar.details.boundType;
|
3108
|
-
newTypeVar.details.constraints = prevTypeVar.details.constraints;
|
3109
|
-
|
3110
|
-
// Also copy the variance.
|
3111
|
-
newTypeVar.details.variance = prevTypeVar.details.variance;
|
3112
|
-
|
3113
|
-
ExpectedConstructorTypeTransformer.synthesizedTypeVarIndexForExpectedType++;
|
3114
|
-
return newTypeVar;
|
3115
|
-
}
|
3116
|
-
|
3117
|
-
override transformTypeVar(typeVar: TypeVarType) {
|
3118
|
-
// If the type variable is unrelated to the scopes we're solving,
|
3119
|
-
// don't transform that type variable.
|
3120
|
-
if (this._isTypeVarLive(typeVar)) {
|
3121
|
-
return typeVar;
|
3122
|
-
}
|
3123
|
-
|
3124
|
-
return this._createDummyTypeVar(typeVar);
|
3125
|
-
}
|
3126
|
-
}
|