@zzzen/pyright-internal 1.2.0-dev.20260816 → 1.2.0-dev.20260830
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/analyzerNodeInfo.d.ts +123 -24
- package/dist/analyzer/analyzerNodeInfo.js +429 -89
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +2 -1
- package/dist/analyzer/backgroundAnalysisProgram.js +4 -8
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.d.ts +6 -3
- package/dist/analyzer/binder.js +70 -69
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +4 -2
- package/dist/analyzer/checker.js +86 -59
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +2 -1
- package/dist/analyzer/codeFlowEngine.js +12 -10
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowUtils.d.ts +2 -1
- package/dist/analyzer/codeFlowUtils.js +2 -3
- package/dist/analyzer/codeFlowUtils.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +8 -0
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/dataClasses.d.ts +5 -4
- package/dist/analyzer/dataClasses.js +30 -59
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.d.ts +2 -1
- package/dist/analyzer/declarationUtils.js +2 -2
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.d.ts +5 -4
- package/dist/analyzer/decorators.js +20 -21
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.d.ts +5 -4
- package/dist/analyzer/enums.js +11 -10
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +1 -1
- package/dist/analyzer/importResolver.js +5 -3
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.d.ts +3 -1
- package/dist/analyzer/importStatementUtils.js +14 -7
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.d.ts +2 -1
- package/dist/analyzer/namedTuples.js +3 -4
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.d.ts +3 -2
- package/dist/analyzer/operations.js +8 -8
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +2 -2
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +13 -11
- package/dist/analyzer/parseTreeUtils.js +62 -36
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.d.ts +7 -2
- package/dist/analyzer/parseTreeWalker.js +29 -175
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.d.ts +4 -3
- package/dist/analyzer/patternMatching.js +47 -43
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +12 -0
- package/dist/analyzer/program.js +238 -29
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.d.ts +4 -3
- package/dist/analyzer/properties.js +7 -8
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +14 -2
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/scopeUtils.d.ts +4 -3
- package/dist/analyzer/scopeUtils.js +8 -8
- package/dist/analyzer/scopeUtils.js.map +1 -1
- package/dist/analyzer/sentinel.d.ts +3 -2
- package/dist/analyzer/sentinel.js +4 -5
- package/dist/analyzer/sentinel.js.map +1 -1
- package/dist/analyzer/service.d.ts +5 -10
- package/dist/analyzer/service.js +36 -96
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceEnumerator.d.ts +5 -0
- package/dist/analyzer/sourceEnumerator.js +57 -3
- package/dist/analyzer/sourceEnumerator.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +12 -6
- package/dist/analyzer/sourceFile.js +74 -50
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.d.ts +1 -0
- package/dist/analyzer/sourceFileInfoUtils.js +8 -0
- package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
- package/dist/analyzer/sourceMapper.d.ts +4 -1
- package/dist/analyzer/sourceMapper.js +14 -8
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/testWalker.js +2 -1
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/tracePrinter.d.ts +2 -1
- package/dist/analyzer/tracePrinter.js +2 -2
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/tuples.d.ts +3 -2
- package/dist/analyzer/tuples.js +5 -5
- package/dist/analyzer/tuples.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.d.ts +5 -7
- package/dist/analyzer/typeDocStringUtils.js +229 -132
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +2 -0
- package/dist/analyzer/typeEvaluator.js +418 -229
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -0
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +3 -2
- package/dist/analyzer/typeGuards.js +159 -35
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeStubGeneration.d.ts +64 -0
- package/dist/analyzer/typeStubGeneration.js +226 -0
- package/dist/analyzer/typeStubGeneration.js.map +1 -0
- package/dist/analyzer/typeStubMessages.d.ts +4 -0
- package/dist/analyzer/typeStubMessages.js +25 -0
- package/dist/analyzer/typeStubMessages.js.map +1 -0
- package/dist/analyzer/typeStubOutput.d.ts +9 -0
- package/dist/analyzer/typeStubOutput.js +52 -0
- package/dist/analyzer/typeStubOutput.js.map +1 -0
- package/dist/analyzer/typeStubRenderer.d.ts +5 -0
- package/dist/analyzer/{typeStubWriter.js → typeStubRenderer.js} +20 -99
- package/dist/analyzer/typeStubRenderer.js.map +1 -0
- package/dist/analyzer/typeUtils.d.ts +1 -0
- package/dist/analyzer/typeUtils.js +115 -1
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +4 -3
- package/dist/analyzer/typedDicts.js +15 -14
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +2 -0
- package/dist/analyzer/types.js +84 -58
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +5 -4
- package/dist/backgroundAnalysisBase.js +11 -19
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/commands/createTypeStub.d.ts +2 -6
- package/dist/commands/createTypeStub.js +14 -27
- package/dist/commands/createTypeStub.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/collectionUtils.js +15 -6
- package/dist/common/collectionUtils.js.map +1 -1
- package/dist/common/commandLineOptions.d.ts +1 -1
- package/dist/common/commandLineOptions.js.map +1 -1
- package/dist/common/configOptions.d.ts +4 -1
- package/dist/common/configOptions.js +68 -12
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/envVarUtils.d.ts +1 -0
- package/dist/common/envVarUtils.js +41 -10
- package/dist/common/envVarUtils.js.map +1 -1
- package/dist/common/extensibility.d.ts +3 -1
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/extraPathGlob.d.ts +12 -0
- package/dist/common/extraPathGlob.js +315 -0
- package/dist/common/extraPathGlob.js.map +1 -0
- package/dist/common/host.d.ts +2 -0
- package/dist/common/host.js.map +1 -1
- package/dist/common/languageServerInterface.d.ts +2 -1
- package/dist/common/languageServerInterface.js.map +1 -1
- package/dist/common/pathConsts.d.ts +1 -0
- package/dist/common/pathConsts.js +11 -1
- package/dist/common/pathConsts.js.map +1 -1
- package/dist/common/processUtils.d.ts +4 -2
- package/dist/common/processUtils.js +3 -0
- package/dist/common/processUtils.js.map +1 -1
- package/dist/common/stringUtils.d.ts +6 -0
- package/dist/common/stringUtils.js +87 -5
- package/dist/common/stringUtils.js.map +1 -1
- package/dist/common/textEditTracker.d.ts +3 -1
- package/dist/common/textEditTracker.js +8 -6
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/common/textRangeCollection.d.ts +1 -0
- package/dist/common/textRangeCollection.js +32 -1
- package/dist/common/textRangeCollection.js.map +1 -1
- package/dist/common/uri/uriUtils.d.ts +3 -0
- package/dist/common/uri/uriUtils.js +65 -15
- package/dist/common/uri/uriUtils.js.map +1 -1
- package/dist/fileSystemMapping.d.ts +10 -0
- package/dist/fileSystemMapping.js +176 -0
- package/dist/fileSystemMapping.js.map +1 -0
- package/dist/languageServerBase.d.ts +1 -1
- package/dist/languageServerBase.js +2 -2
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.d.ts +1 -3
- package/dist/languageService/analyzerServiceExecutor.js +10 -29
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +1 -0
- package/dist/languageService/autoImporter.js +32 -5
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.d.ts +7 -0
- package/dist/languageService/callHierarchyProvider.js +97 -11
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +30 -8
- package/dist/languageService/completionProvider.js +298 -93
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.js +7 -6
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentHighlightProvider.js +2 -1
- package/dist/languageService/documentHighlightProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.d.ts +3 -1
- package/dist/languageService/documentSymbolCollector.js +78 -14
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/documentSymbolProvider.js +3 -2
- package/dist/languageService/documentSymbolProvider.js.map +1 -1
- package/dist/languageService/fileWatcherDynamicFeature.js +28 -1
- package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +2 -1
- package/dist/languageService/hoverProvider.js +48 -16
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importSorter.d.ts +3 -1
- package/dist/languageService/importSorter.js +4 -2
- package/dist/languageService/importSorter.js.map +1 -1
- package/dist/languageService/importStatementCandidates.js +4 -2
- package/dist/languageService/importStatementCandidates.js.map +1 -1
- package/dist/languageService/quickActions.js +2 -1
- package/dist/languageService/quickActions.js.map +1 -1
- package/dist/languageService/referencesProvider.js +12 -5
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.d.ts +3 -0
- package/dist/languageService/signatureHelpProvider.js +56 -18
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.d.ts +2 -1
- package/dist/languageService/symbolIndexer.js +7 -7
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/languageService/tooltipUtils.d.ts +1 -1
- package/dist/languageService/tooltipUtils.js +103 -35
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.js +3 -2
- package/dist/languageService/workspaceSymbolProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +6 -0
- package/dist/localization/localize.js +10 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +15 -0
- package/dist/localization/package.nls.de.json +15 -0
- package/dist/localization/package.nls.en-us.json +5 -0
- package/dist/localization/package.nls.es.json +15 -0
- package/dist/localization/package.nls.fr.json +15 -0
- package/dist/localization/package.nls.it.json +15 -0
- package/dist/localization/package.nls.ja.json +15 -0
- package/dist/localization/package.nls.ko.json +15 -0
- package/dist/localization/package.nls.pl.json +15 -0
- package/dist/localization/package.nls.pt-br.json +15 -0
- package/dist/localization/package.nls.qps-ploc.json +15 -0
- package/dist/localization/package.nls.ru.json +15 -0
- package/dist/localization/package.nls.tr.json +15 -0
- package/dist/localization/package.nls.zh-cn.json +16 -1
- package/dist/localization/package.nls.zh-tw.json +17 -2
- package/dist/parser/parseNodes.d.ts +85 -80
- package/dist/parser/parseNodes.js +182 -159
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parseTreeUtils.d.ts +3 -0
- package/dist/parser/parseTreeUtils.js +209 -0
- package/dist/parser/parseTreeUtils.js.map +1 -0
- package/dist/parser/parser.d.ts +16 -6
- package/dist/parser/parser.js +210 -144
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/stringAnnotationInfo.d.ts +16 -0
- package/dist/parser/stringAnnotationInfo.js +26 -0
- package/dist/parser/stringAnnotationInfo.js.map +1 -0
- package/dist/pyright.js +30 -17
- package/dist/pyright.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +2 -9
- package/dist/readonlyAugmentedFileSystem.js +17 -144
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.js +2 -2
- package/dist/server.js.map +1 -1
- package/dist/tests/analyzerNodeInfo.test.d.ts +1 -0
- package/dist/tests/analyzerNodeInfo.test.js +145 -0
- package/dist/tests/analyzerNodeInfo.test.js.map +1 -0
- package/dist/tests/collectionUtils.test.js +46 -0
- package/dist/tests/collectionUtils.test.js.map +1 -1
- package/dist/tests/completions.test.js +34 -0
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/config.test.js +131 -7
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/extraPathGlob.test.d.ts +1 -0
- package/dist/tests/extraPathGlob.test.js +434 -0
- package/dist/tests/extraPathGlob.test.js.map +1 -0
- package/dist/tests/fileSystemMapping.test.d.ts +1 -0
- package/dist/tests/fileSystemMapping.test.js +458 -0
- package/dist/tests/fileSystemMapping.test.js.map +1 -0
- package/dist/tests/fourslash/completions.call.typedDict.fourslash.js +23 -0
- package/dist/tests/fourslash/completions.call.typedDict.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.call.typedDict.list.fourslash.js +14 -0
- package/dist/tests/fourslash/completions.call.typedDict.list.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.call.typedDict.states.fourslash.js +7 -0
- package/dist/tests/fourslash/completions.call.typedDict.states.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.callSite.isinstanceNarrowing.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.callSite.isinstanceNarrowing.fourslash.js +41 -0
- package/dist/tests/fourslash/completions.callSite.isinstanceNarrowing.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js +2 -0
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js +5 -0
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.stringLiteral.fourslash.js +4 -0
- package/dist/tests/fourslash/completions.stringLiteral.fourslash.js.map +1 -1
- package/dist/tests/fourslash/findallreferences.protocolMemberVariable.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findallreferences.protocolMemberVariable.fourslash.js +48 -0
- package/dist/tests/fourslash/findallreferences.protocolMemberVariable.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js +0 -1
- package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js +8 -2
- package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js +5 -2
- package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js.map +1 -1
- package/dist/tests/fourslash/signature.docstrings.overloaded.fourslash.js +2 -2
- package/dist/tests/fourslash/signature.docstrings.overloaded.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +1 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/hoverProvider.test.js +38 -0
- package/dist/tests/hoverProvider.test.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +6 -3
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/ipythonMode.test.js +38 -0
- package/dist/tests/ipythonMode.test.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +88 -0
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/parser.test.js +60 -3
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/positionUtils.test.js +23 -0
- package/dist/tests/positionUtils.test.js.map +1 -1
- package/dist/tests/pyrightCli.test.d.ts +1 -0
- package/dist/tests/pyrightCli.test.js +205 -0
- package/dist/tests/pyrightCli.test.js.map +1 -0
- package/dist/tests/pyrightFileSystem.test.js +41 -0
- package/dist/tests/pyrightFileSystem.test.js.map +1 -1
- package/dist/tests/service.test.js +183 -0
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/sourceEnumeratorSymlink.test.d.ts +1 -0
- package/dist/tests/sourceEnumeratorSymlink.test.js +203 -0
- package/dist/tests/sourceEnumeratorSymlink.test.js.map +1 -0
- package/dist/tests/stringUtils.test.js +84 -0
- package/dist/tests/stringUtils.test.js.map +1 -1
- package/dist/tests/symlinkAliasInvalidation.test.d.ts +1 -0
- package/dist/tests/symlinkAliasInvalidation.test.js +471 -0
- package/dist/tests/symlinkAliasInvalidation.test.js.map +1 -0
- package/dist/tests/testUtils.d.ts +2 -0
- package/dist/tests/testUtils.js +7 -1
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/textEditUtil.test.js +2 -2
- package/dist/tests/textEditUtil.test.js.map +1 -1
- package/dist/tests/textRangeCollection.test.d.ts +1 -0
- package/dist/tests/textRangeCollection.test.js +137 -0
- package/dist/tests/textRangeCollection.test.js.map +1 -0
- package/dist/tests/typeEquality.test.d.ts +1 -0
- package/dist/tests/typeEquality.test.js +95 -0
- package/dist/tests/typeEquality.test.js.map +1 -0
- package/dist/tests/typeEvaluator1.test.js +24 -3
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +8 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +8 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +1 -1
- package/dist/tests/typeEvaluator6.test.js +5 -1
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +4 -0
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +4 -0
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/dist/tests/typeServer/typeCache.test.d.ts +1 -0
- package/dist/tests/typeServer/typeCache.test.js +69 -0
- package/dist/tests/typeServer/typeCache.test.js.map +1 -0
- package/dist/tests/typeServer/typeServer.virtualFileRedirect.test.js +18 -0
- package/dist/tests/typeServer/typeServer.virtualFileRedirect.test.js.map +1 -1
- package/dist/tests/typeStubGeneration.test.d.ts +1 -0
- package/dist/tests/typeStubGeneration.test.js +397 -0
- package/dist/tests/typeStubGeneration.test.js.map +1 -0
- package/dist/tests/typeStubOutput.test.d.ts +1 -0
- package/dist/tests/typeStubOutput.test.js +136 -0
- package/dist/tests/typeStubOutput.test.js.map +1 -0
- package/dist/tests/typeUtils.test.d.ts +1 -0
- package/dist/tests/typeUtils.test.js +133 -0
- package/dist/tests/typeUtils.test.js.map +1 -0
- package/dist/tests/uri.test.js +51 -0
- package/dist/tests/uri.test.js.map +1 -1
- package/dist/typeServer/notebookDocumentHandler.d.ts +9 -2
- package/dist/typeServer/notebookDocumentHandler.js +16 -6
- package/dist/typeServer/notebookDocumentHandler.js.map +1 -1
- package/dist/typeServer/programWrapper.d.ts +1 -0
- package/dist/typeServer/programWrapper.js +28 -15
- package/dist/typeServer/programWrapper.js.map +1 -1
- package/dist/typeServer/protocol/tspSupplemental.d.ts +1 -1
- package/dist/typeServer/protocol/tspSupplemental.js +2 -2
- package/dist/typeServer/server.d.ts +13 -2
- package/dist/typeServer/server.js +36 -23
- package/dist/typeServer/server.js.map +1 -1
- package/dist/typeServer/typeCache.d.ts +8 -4
- package/dist/typeServer/typeCache.js +33 -5
- package/dist/typeServer/typeCache.js.map +1 -1
- package/dist/typeServer/typeEvalUtils.d.ts +2 -1
- package/dist/typeServer/typeEvalUtils.js +7 -3
- package/dist/typeServer/typeEvalUtils.js.map +1 -1
- package/dist/typeServer/typeGuards.js +3 -4
- package/dist/typeServer/typeGuards.js.map +1 -1
- package/dist/typeServer/typeServerFileSystem.d.ts +10 -9
- package/dist/typeServer/typeServerFileSystem.js +16 -12
- package/dist/typeServer/typeServerFileSystem.js.map +1 -1
- package/package.json +7 -5
- package/dist/analyzer/parseTreeCleaner.d.ts +0 -8
- package/dist/analyzer/parseTreeCleaner.js +0 -65
- package/dist/analyzer/parseTreeCleaner.js.map +0 -1
- package/dist/analyzer/typeStubWriter.d.ts +0 -17
- package/dist/analyzer/typeStubWriter.js.map +0 -1
|
@@ -5,6 +5,7 @@ import { DiagnosticRule } from '../common/diagnosticRules';
|
|
|
5
5
|
import { TextRange } from '../common/textRange';
|
|
6
6
|
import { ArgCategory, ArgumentNode, CallNode, CaseNode, ClassNode, DecoratorNode, ExpressionNode, FunctionNode, MatchNode, NameNode, ParamCategory, ParameterNode, ParseNode, StringNode } from '../parser/parseNodes';
|
|
7
7
|
import { AnalyzerFileInfo } from './analyzerFileInfo';
|
|
8
|
+
import { AnalyzerNodeInfoReader } from './analyzerNodeInfo';
|
|
8
9
|
import { CodeFlowReferenceExpressionNode, FlowNode } from './codeFlowTypes';
|
|
9
10
|
import { ConstraintTracker } from './constraintTracker';
|
|
10
11
|
import { Declaration } from './declaration';
|
|
@@ -308,6 +309,7 @@ export declare const enum AssignTypeFlags {
|
|
|
308
309
|
export interface TypeEvaluator {
|
|
309
310
|
runWithCancellationToken<T>(token: CancellationToken, callback: () => T): T;
|
|
310
311
|
runWithCancellationToken<T>(token: CancellationToken, callback: () => Promise<T>): Promise<T>;
|
|
312
|
+
getAnalyzerNodeInfoReader: () => AnalyzerNodeInfoReader;
|
|
311
313
|
getType: (node: ExpressionNode) => Type | undefined;
|
|
312
314
|
getTypeResult: (node: ExpressionNode) => TypeResult | undefined;
|
|
313
315
|
getTypeResultForDecorator: (node: DecoratorNode) => TypeResult | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeEvaluatorTypes.js","sourceRoot":"","sources":["../../../../../src/analyzer/typeEvaluatorTypes.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;
|
|
1
|
+
{"version":3,"file":"typeEvaluatorTypes.js","sourceRoot":"","sources":["../../../../../src/analyzer/typeEvaluatorTypes.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ExpressionNode } from '../parser/parseNodes';
|
|
2
|
+
import { AnalyzerNodeInfoAccessor } from './analyzerNodeInfo';
|
|
2
3
|
import { TypeEvaluator } from './typeEvaluatorTypes';
|
|
3
4
|
import { AnyType, ClassType, FunctionType, OverloadedType, Type, TypeVarType, UnknownType } from './types';
|
|
4
5
|
export interface TypeNarrowingResult {
|
|
@@ -6,9 +7,9 @@ export interface TypeNarrowingResult {
|
|
|
6
7
|
isIncomplete: boolean;
|
|
7
8
|
}
|
|
8
9
|
export type TypeNarrowingCallback = (type: Type) => TypeNarrowingResult | undefined;
|
|
9
|
-
export declare function getTypeNarrowingCallback(evaluator: TypeEvaluator, reference: ExpressionNode, testExpression: ExpressionNode, isPositiveTest: boolean, recursionCount?: number): TypeNarrowingCallback | undefined;
|
|
10
|
+
export declare function getTypeNarrowingCallback(evaluator: TypeEvaluator, reference: ExpressionNode, testExpression: ExpressionNode, isPositiveTest: boolean, nodeInfo: AnalyzerNodeInfoAccessor, recursionCount?: number): TypeNarrowingCallback | undefined;
|
|
10
11
|
export declare function getIsInstanceClassTypes(evaluator: TypeEvaluator, argType: Type): (ClassType | TypeVarType | FunctionType)[] | undefined;
|
|
11
|
-
export declare function narrowTypeForInstanceOrSubclass(evaluator: TypeEvaluator, type: Type, filterTypes: Type[], isInstanceCheck: boolean, isTypeIsCheck: boolean, isPositiveTest: boolean, errorNode: ExpressionNode): import("./types").UnboundType | UnknownType | AnyType | FunctionType | OverloadedType | ClassType | import("./types").ModuleType | TypeVarType | import("./types").NeverType | import("./types").UnionType;
|
|
12
|
+
export declare function narrowTypeForInstanceOrSubclass(evaluator: TypeEvaluator, type: Type, filterTypes: Type[], isInstanceCheck: boolean, isTypeIsCheck: boolean, isPositiveTest: boolean, errorNode: ExpressionNode, nodeInfo: AnalyzerNodeInfoAccessor): import("./types").UnboundType | UnknownType | AnyType | FunctionType | OverloadedType | ClassType | import("./types").ModuleType | TypeVarType | import("./types").NeverType | import("./types").UnionType;
|
|
12
13
|
export declare function getElementTypeForContainerNarrowing(containerType: Type): Type | undefined;
|
|
13
14
|
export declare function narrowTypeForContainerElementType(evaluator: TypeEvaluator, referenceType: Type, elementType: Type): Type;
|
|
14
15
|
export declare function narrowTypeForDiscriminatedDictEntryComparison(evaluator: TypeEvaluator, referenceType: Type, indexLiteralType: ClassType, literalType: Type, isPositiveTest: boolean): Type;
|
|
@@ -68,13 +68,13 @@ const typeUtils_1 = require("./typeUtils");
|
|
|
68
68
|
// can be used to narrow the type described by the reference expression.
|
|
69
69
|
// If the specified flow node is not associated with the test expression,
|
|
70
70
|
// it returns undefined.
|
|
71
|
-
function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositiveTest, recursionCount = 0) {
|
|
71
|
+
function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositiveTest, nodeInfo, recursionCount = 0) {
|
|
72
72
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
|
73
73
|
return undefined;
|
|
74
74
|
}
|
|
75
75
|
recursionCount++;
|
|
76
76
|
if (testExpression.nodeType === 4 /* ParseNodeType.AssignmentExpression */) {
|
|
77
|
-
return getTypeNarrowingCallbackForAssignmentExpression(evaluator, reference, testExpression, isPositiveTest, recursionCount);
|
|
77
|
+
return getTypeNarrowingCallbackForAssignmentExpression(evaluator, reference, testExpression, isPositiveTest, nodeInfo, recursionCount);
|
|
78
78
|
}
|
|
79
79
|
if (testExpression.nodeType === 7 /* ParseNodeType.BinaryOperation */) {
|
|
80
80
|
const isOrIsNotOperator = testExpression.d.operator === 39 /* OperatorType.Is */ || testExpression.d.operator === 40 /* OperatorType.IsNot */;
|
|
@@ -422,7 +422,7 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
|
422
422
|
return (type) => {
|
|
423
423
|
return {
|
|
424
424
|
type: narrowTypeForInstanceOrSubclass(evaluator, type, classTypeList, isInstanceCheck,
|
|
425
|
-
/* isTypeIsCheck */ false, isPositiveTest, testExpression),
|
|
425
|
+
/* isTypeIsCheck */ false, isPositiveTest, testExpression, nodeInfo),
|
|
426
426
|
isIncomplete,
|
|
427
427
|
};
|
|
428
428
|
};
|
|
@@ -462,9 +462,23 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
|
462
462
|
// Does this look like it's a custom type guard function?
|
|
463
463
|
let isPossiblyTypeGuard = false;
|
|
464
464
|
const isFunctionReturnTypeGuard = (type) => {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
465
|
+
const returnType = type.shared.declaredReturnType;
|
|
466
|
+
if (!returnType) {
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
if ((0, types_1.isClassInstance)(returnType)) {
|
|
470
|
+
return types_1.ClassType.isBuiltIn(returnType, ['TypeGuard', 'TypeIs']);
|
|
471
|
+
}
|
|
472
|
+
if ((0, types_1.isUnion)(returnType)) {
|
|
473
|
+
let isAllGuards = true;
|
|
474
|
+
(0, typeUtils_1.doForEachSubtype)(returnType, (subtype) => {
|
|
475
|
+
if (!(0, types_1.isClassInstance)(subtype) || !types_1.ClassType.isBuiltIn(subtype, ['TypeGuard', 'TypeIs'])) {
|
|
476
|
+
isAllGuards = false;
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
return isAllGuards;
|
|
480
|
+
}
|
|
481
|
+
return false;
|
|
468
482
|
};
|
|
469
483
|
const callTypeResult = evaluator.getTypeOfExpression(testExpression.d.leftExpr, 2 /* EvalFlags.CallBaseDefaults */);
|
|
470
484
|
const callType = callTypeResult.type;
|
|
@@ -482,16 +496,42 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
|
482
496
|
// Evaluate the type guard call expression.
|
|
483
497
|
const functionReturnTypeResult = evaluator.getTypeOfExpression(testExpression);
|
|
484
498
|
const functionReturnType = functionReturnTypeResult.type;
|
|
499
|
+
let typeGuardType;
|
|
500
|
+
let isStrictTypeGuard = false;
|
|
485
501
|
if ((0, types_1.isClassInstance)(functionReturnType) &&
|
|
486
502
|
types_1.ClassType.isBuiltIn(functionReturnType, ['TypeGuard', 'TypeIs']) &&
|
|
487
503
|
functionReturnType.priv.typeArgs &&
|
|
488
504
|
functionReturnType.priv.typeArgs.length > 0) {
|
|
489
|
-
|
|
490
|
-
|
|
505
|
+
isStrictTypeGuard = types_1.ClassType.isBuiltIn(functionReturnType, 'TypeIs');
|
|
506
|
+
typeGuardType = functionReturnType.priv.typeArgs[0];
|
|
507
|
+
}
|
|
508
|
+
else if ((0, types_1.isUnion)(functionReturnType)) {
|
|
509
|
+
const typeGuardSubtypes = [];
|
|
510
|
+
let isAllGuards = true;
|
|
511
|
+
(0, typeUtils_1.doForEachSubtype)(functionReturnType, (subtype) => {
|
|
512
|
+
if ((0, types_1.isClassInstance)(subtype) &&
|
|
513
|
+
types_1.ClassType.isBuiltIn(subtype, ['TypeGuard', 'TypeIs']) &&
|
|
514
|
+
subtype.priv.typeArgs &&
|
|
515
|
+
subtype.priv.typeArgs.length > 0) {
|
|
516
|
+
typeGuardSubtypes.push(subtype);
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
isAllGuards = false;
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
if (isAllGuards && typeGuardSubtypes.length > 0) {
|
|
523
|
+
// A union of type guards cannot be strict in the negative case because at runtime
|
|
524
|
+
// only one arm of the overload/union is selected. Treating it as strict would
|
|
525
|
+
// unsoundly eliminate types in the negative branch.
|
|
526
|
+
isStrictTypeGuard = false;
|
|
527
|
+
typeGuardType = (0, types_1.combineTypes)(typeGuardSubtypes.map((subtype) => subtype.priv.typeArgs[0]));
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
if (typeGuardType) {
|
|
491
531
|
const isIncomplete = !!callTypeResult.isIncomplete || !!functionReturnTypeResult.isIncomplete;
|
|
492
532
|
return (type) => {
|
|
493
533
|
return {
|
|
494
|
-
type: narrowTypeForUserDefinedTypeGuard(evaluator, type, typeGuardType, isPositiveTest, isStrictTypeGuard, testExpression),
|
|
534
|
+
type: narrowTypeForUserDefinedTypeGuard(evaluator, type, typeGuardType, isPositiveTest, isStrictTypeGuard, testExpression, nodeInfo),
|
|
495
535
|
isIncomplete,
|
|
496
536
|
};
|
|
497
537
|
};
|
|
@@ -510,7 +550,7 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
|
510
550
|
}
|
|
511
551
|
// Is this a reference to an aliased conditional expression (a local variable
|
|
512
552
|
// that was assigned a value that can inform type narrowing of the reference expression)?
|
|
513
|
-
const narrowingCallback = getTypeNarrowingCallbackForAliasedCondition(evaluator, reference, testExpression, isPositiveTest, recursionCount);
|
|
553
|
+
const narrowingCallback = getTypeNarrowingCallbackForAliasedCondition(evaluator, reference, testExpression, isPositiveTest, nodeInfo, recursionCount);
|
|
514
554
|
if (narrowingCallback) {
|
|
515
555
|
return narrowingCallback;
|
|
516
556
|
}
|
|
@@ -520,12 +560,12 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
|
|
|
520
560
|
if (reference.nodeType === 38 /* ParseNodeType.Name */) {
|
|
521
561
|
if (testExpression.nodeType === 55 /* ParseNodeType.UnaryOperation */ &&
|
|
522
562
|
testExpression.d.operator === 38 /* OperatorType.Not */) {
|
|
523
|
-
return getTypeNarrowingCallback(evaluator, reference, testExpression.d.expr, !isPositiveTest, recursionCount);
|
|
563
|
+
return getTypeNarrowingCallback(evaluator, reference, testExpression.d.expr, !isPositiveTest, nodeInfo, recursionCount);
|
|
524
564
|
}
|
|
525
565
|
}
|
|
526
566
|
return undefined;
|
|
527
567
|
}
|
|
528
|
-
function getTypeNarrowingCallbackForAliasedCondition(evaluator, reference, testExpression, isPositiveTest, recursionCount) {
|
|
568
|
+
function getTypeNarrowingCallbackForAliasedCondition(evaluator, reference, testExpression, isPositiveTest, nodeInfo, recursionCount) {
|
|
529
569
|
if (testExpression.nodeType !== 38 /* ParseNodeType.Name */ ||
|
|
530
570
|
reference.nodeType !== 38 /* ParseNodeType.Name */ ||
|
|
531
571
|
testExpression === reference) {
|
|
@@ -571,13 +611,14 @@ function getTypeNarrowingCallbackForAliasedCondition(evaluator, reference, testE
|
|
|
571
611
|
if (!initNode || ParseTreeUtils.isNodeContainedWithin(testExpression, initNode) || !(0, parseNodes_1.isExpressionNode)(initNode)) {
|
|
572
612
|
return undefined;
|
|
573
613
|
}
|
|
574
|
-
return getTypeNarrowingCallback(evaluator, reference, initNode, isPositiveTest, recursionCount);
|
|
614
|
+
return getTypeNarrowingCallback(evaluator, reference, initNode, isPositiveTest, nodeInfo, recursionCount);
|
|
575
615
|
}
|
|
576
616
|
// Determines whether the symbol is a local variable or parameter within
|
|
577
617
|
// the current scope. If requireUnique is true, there can be only one
|
|
578
618
|
// declaration (assignment) of the symbol, otherwise it is rejected.
|
|
579
619
|
function getDeclsForLocalVar(evaluator, name, reachableFrom, requireUnique) {
|
|
580
|
-
const
|
|
620
|
+
const nodeInfo = (0, analyzerNodeInfo_1.getInfoReader)(evaluator);
|
|
621
|
+
const scope = (0, scopeUtils_1.getScopeForNode)(name, nodeInfo);
|
|
581
622
|
if (scope?.type !== 2 /* ScopeType.Function */ && scope?.type !== 4 /* ScopeType.Module */) {
|
|
582
623
|
return undefined;
|
|
583
624
|
}
|
|
@@ -598,7 +639,7 @@ function getDeclsForLocalVar(evaluator, name, reachableFrom, requireUnique) {
|
|
|
598
639
|
let prevDeclScope;
|
|
599
640
|
if (decls.some((decl) => {
|
|
600
641
|
const nodeToConsider = decl.type === 2 /* DeclarationType.Param */ ? decl.node.d.name : decl.node;
|
|
601
|
-
const declScopeNode = ParseTreeUtils.getExecutionScopeNode(nodeToConsider);
|
|
642
|
+
const declScopeNode = ParseTreeUtils.getExecutionScopeNode(nodeToConsider, nodeInfo);
|
|
602
643
|
if (prevDeclScope && declScopeNode !== prevDeclScope) {
|
|
603
644
|
return true;
|
|
604
645
|
}
|
|
@@ -610,11 +651,11 @@ function getDeclsForLocalVar(evaluator, name, reachableFrom, requireUnique) {
|
|
|
610
651
|
const reachableDecls = decls.filter((decl) => evaluator.isNodeReachable(reachableFrom, decl.node));
|
|
611
652
|
return reachableDecls.length > 0 ? reachableDecls : undefined;
|
|
612
653
|
}
|
|
613
|
-
function getTypeNarrowingCallbackForAssignmentExpression(evaluator, reference, testExpression, isPositiveTest, recursionCount) {
|
|
614
|
-
return (getTypeNarrowingCallback(evaluator, reference, testExpression.d.rightExpr, isPositiveTest, recursionCount) ??
|
|
615
|
-
getTypeNarrowingCallback(evaluator, reference, testExpression.d.name, isPositiveTest, recursionCount));
|
|
654
|
+
function getTypeNarrowingCallbackForAssignmentExpression(evaluator, reference, testExpression, isPositiveTest, nodeInfo, recursionCount) {
|
|
655
|
+
return (getTypeNarrowingCallback(evaluator, reference, testExpression.d.rightExpr, isPositiveTest, nodeInfo, recursionCount) ??
|
|
656
|
+
getTypeNarrowingCallback(evaluator, reference, testExpression.d.name, isPositiveTest, nodeInfo, recursionCount));
|
|
616
657
|
}
|
|
617
|
-
function narrowTypeForUserDefinedTypeGuard(evaluator, type, typeGuardType, isPositiveTest, isStrictTypeGuard, errorNode) {
|
|
658
|
+
function narrowTypeForUserDefinedTypeGuard(evaluator, type, typeGuardType, isPositiveTest, isStrictTypeGuard, errorNode, nodeInfo) {
|
|
618
659
|
// For non-strict type guards, always narrow to the typeGuardType
|
|
619
660
|
// in the positive case and don't narrow in the negative case.
|
|
620
661
|
if (!isStrictTypeGuard) {
|
|
@@ -636,7 +677,7 @@ function narrowTypeForUserDefinedTypeGuard(evaluator, type, typeGuardType, isPos
|
|
|
636
677
|
});
|
|
637
678
|
return narrowTypeForInstanceOrSubclass(evaluator, type, filterTypes,
|
|
638
679
|
/* isInstanceCheck */ true,
|
|
639
|
-
/* isTypeIsCheck */ true, isPositiveTest, errorNode);
|
|
680
|
+
/* isTypeIsCheck */ true, isPositiveTest, errorNode, nodeInfo);
|
|
640
681
|
}
|
|
641
682
|
// Narrow the type based on whether the subtype can be true or false.
|
|
642
683
|
function narrowTypeForTruthiness(evaluator, type, isPositiveTest) {
|
|
@@ -896,18 +937,18 @@ function getIsInstanceClassTypes(evaluator, argType) {
|
|
|
896
937
|
});
|
|
897
938
|
return foundNonClassType ? undefined : classTypeList;
|
|
898
939
|
}
|
|
899
|
-
function narrowTypeForInstanceOrSubclass(evaluator, type, filterTypes, isInstanceCheck, isTypeIsCheck, isPositiveTest, errorNode) {
|
|
940
|
+
function narrowTypeForInstanceOrSubclass(evaluator, type, filterTypes, isInstanceCheck, isTypeIsCheck, isPositiveTest, errorNode, nodeInfo) {
|
|
900
941
|
// First try with intersection types disallowed.
|
|
901
942
|
const narrowedType = narrowTypeForInstanceOrSubclassInternal(evaluator, type, filterTypes, isInstanceCheck, isTypeIsCheck, isPositiveTest,
|
|
902
|
-
/* allowIntersections */ false, errorNode);
|
|
943
|
+
/* allowIntersections */ false, errorNode, nodeInfo);
|
|
903
944
|
if (!(0, types_1.isNever)(narrowedType)) {
|
|
904
945
|
return narrowedType;
|
|
905
946
|
}
|
|
906
947
|
// Try again with intersection types allowed.
|
|
907
948
|
return narrowTypeForInstanceOrSubclassInternal(evaluator, type, filterTypes, isInstanceCheck, isTypeIsCheck, isPositiveTest,
|
|
908
|
-
/* allowIntersections */ true, errorNode);
|
|
949
|
+
/* allowIntersections */ true, errorNode, nodeInfo);
|
|
909
950
|
}
|
|
910
|
-
function narrowTypeForInstanceOrSubclassInternal(evaluator, type, filterTypes, isInstanceCheck, isTypeIsCheck, isPositiveTest, allowIntersections, errorNode) {
|
|
951
|
+
function narrowTypeForInstanceOrSubclassInternal(evaluator, type, filterTypes, isInstanceCheck, isTypeIsCheck, isPositiveTest, allowIntersections, errorNode, nodeInfo) {
|
|
911
952
|
const result = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
|
912
953
|
let adjSubtype = subtype;
|
|
913
954
|
let resultRequiresAdj = false;
|
|
@@ -925,7 +966,7 @@ function narrowTypeForInstanceOrSubclassInternal(evaluator, type, filterTypes, i
|
|
|
925
966
|
}
|
|
926
967
|
}
|
|
927
968
|
}
|
|
928
|
-
const narrowedResult = narrowTypeForInstance(evaluator, adjSubtype, adjFilterTypes, isTypeIsCheck, isPositiveTest, allowIntersections, errorNode);
|
|
969
|
+
const narrowedResult = narrowTypeForInstance(evaluator, adjSubtype, adjFilterTypes, isTypeIsCheck, isPositiveTest, allowIntersections, errorNode, nodeInfo);
|
|
929
970
|
if (!resultRequiresAdj) {
|
|
930
971
|
return narrowedResult;
|
|
931
972
|
}
|
|
@@ -943,7 +984,7 @@ function narrowTypeForInstanceOrSubclassInternal(evaluator, type, filterTypes, i
|
|
|
943
984
|
// type of expression "x" is "Mammal" and the test expression is
|
|
944
985
|
// "isinstance(x, Cow)", (assuming "Cow" is a subclass of "Mammal"), we can
|
|
945
986
|
// narrow x to "Cow".
|
|
946
|
-
function narrowTypeForInstance(evaluator, type, filterTypes, isTypeIsCheck, isPositiveTest, allowIntersections, errorNode) {
|
|
987
|
+
function narrowTypeForInstance(evaluator, type, filterTypes, isTypeIsCheck, isPositiveTest, allowIntersections, errorNode, nodeInfo) {
|
|
947
988
|
let expandedTypes = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
|
948
989
|
return (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(subtype);
|
|
949
990
|
});
|
|
@@ -955,7 +996,7 @@ function narrowTypeForInstance(evaluator, type, filterTypes, isTypeIsCheck, isPo
|
|
|
955
996
|
}
|
|
956
997
|
// If this is an isinstance or issubclass check, the type variables
|
|
957
998
|
// should be converted to "free" type variables.
|
|
958
|
-
return (0, typeUtils_1.makeTypeVarsFree)(varType, ParseTreeUtils.getTypeVarScopesForNode(errorNode));
|
|
999
|
+
return (0, typeUtils_1.makeTypeVarsFree)(varType, ParseTreeUtils.getTypeVarScopesForNode(errorNode, nodeInfo));
|
|
959
1000
|
};
|
|
960
1001
|
// Filters the varType by the parameters of the isinstance
|
|
961
1002
|
// and returns the list of types the varType could be after
|
|
@@ -1001,7 +1042,7 @@ function narrowTypeForInstance(evaluator, type, filterTypes, isTypeIsCheck, isPo
|
|
|
1001
1042
|
// bound to free type variables. We'll retain the bound type
|
|
1002
1043
|
// variables for TypeIs checks.
|
|
1003
1044
|
if (!isTypeIsCheck) {
|
|
1004
|
-
runtimeVarType = (0, typeUtils_1.makeTypeVarsFree)(runtimeVarType, ParseTreeUtils.getTypeVarScopesForNode(errorNode));
|
|
1045
|
+
runtimeVarType = (0, typeUtils_1.makeTypeVarsFree)(runtimeVarType, ParseTreeUtils.getTypeVarScopesForNode(errorNode, nodeInfo));
|
|
1005
1046
|
}
|
|
1006
1047
|
// If the value is a TypedDict, convert it into its runtime form,
|
|
1007
1048
|
// which is a dict[str, Any].
|
|
@@ -1189,7 +1230,7 @@ function narrowTypeForInstance(evaluator, type, filterTypes, isTypeIsCheck, isPo
|
|
|
1189
1230
|
// two type is a subclass that is callable. We'll synthesize a
|
|
1190
1231
|
// new intersection type.
|
|
1191
1232
|
const className = `<callable subtype of ${concreteVarType.shared.name}>`;
|
|
1192
|
-
const fileInfo =
|
|
1233
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
1193
1234
|
let newClassType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 0 /* ClassTypeFlags.None */, ParseTreeUtils.getTypeSourceId(errorNode),
|
|
1194
1235
|
/* declaredMetaclass */ undefined, concreteVarType.shared.effectiveMetaclass, concreteVarType.shared.docString);
|
|
1195
1236
|
newClassType.shared.baseClasses = [concreteVarType];
|
|
@@ -1571,7 +1612,8 @@ function narrowTypeForTypedDictKey(evaluator, referenceType, literalKey, isPosit
|
|
|
1571
1612
|
}
|
|
1572
1613
|
if ((0, types_1.isClassInstance)(subtype) && types_1.ClassType.isTypedDictClass(subtype)) {
|
|
1573
1614
|
const entries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluator, subtype, /* allowNarrowed */ true);
|
|
1574
|
-
const
|
|
1615
|
+
const knownEntry = entries.knownItems.get(literalKey.priv.literalValue);
|
|
1616
|
+
const tdEntry = knownEntry ?? entries.extraItems;
|
|
1575
1617
|
if (isPositiveTest) {
|
|
1576
1618
|
// The code that is commented out below implements the behavior that is technically
|
|
1577
1619
|
// correct, but until we PEP 728 is ratified and we have a way to express "extra items"
|
|
@@ -1612,7 +1654,14 @@ function narrowTypeForTypedDictKey(evaluator, referenceType, literalKey, isPosit
|
|
|
1612
1654
|
return types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForNarrowedTypedDictEntries(types_1.ClassType.cloneAsInstantiable(subtype), newNarrowedEntriesMap));
|
|
1613
1655
|
}
|
|
1614
1656
|
else {
|
|
1615
|
-
|
|
1657
|
+
if (!knownEntry) {
|
|
1658
|
+
// The key is not one of the known items, so it can be supplied
|
|
1659
|
+
// only through an "extra items" entry, which says nothing about
|
|
1660
|
+
// whether this particular key is present. Its absence is therefore
|
|
1661
|
+
// consistent with the type, and the subtype cannot be eliminated.
|
|
1662
|
+
return subtype;
|
|
1663
|
+
}
|
|
1664
|
+
return knownEntry.isRequired || knownEntry.isProvided ? undefined : subtype;
|
|
1616
1665
|
}
|
|
1617
1666
|
}
|
|
1618
1667
|
return subtype;
|
|
@@ -1894,6 +1943,52 @@ function isFilterSuperclass(varType, concreteVarType, filterType, concreteFilter
|
|
|
1894
1943
|
}
|
|
1895
1944
|
return false;
|
|
1896
1945
|
}
|
|
1946
|
+
// Determines whether the specified class is an enum class whose members derive
|
|
1947
|
+
// from a primitive type (e.g. IntEnum or StrEnum). Members of such classes
|
|
1948
|
+
// compare equal to their underlying primitive value at runtime.
|
|
1949
|
+
function isPrimitiveBackedEnumClass(classType) {
|
|
1950
|
+
if (!types_1.ClassType.isEnumClass(classType)) {
|
|
1951
|
+
return false;
|
|
1952
|
+
}
|
|
1953
|
+
return (0, typeUtils_1.derivesFromStdlibClass)(classType, 'int') || (0, typeUtils_1.derivesFromStdlibClass)(classType, 'str');
|
|
1954
|
+
}
|
|
1955
|
+
// Determines whether enumType is a primitive-backed enum class and primitiveType
|
|
1956
|
+
// is the primitive type (int or str) from which it derives.
|
|
1957
|
+
function isPrimitiveBackedEnumAndPrimitive(enumType, primitiveType) {
|
|
1958
|
+
if (types_1.ClassType.isEnumClass(primitiveType) || !isPrimitiveBackedEnumClass(enumType)) {
|
|
1959
|
+
return false;
|
|
1960
|
+
}
|
|
1961
|
+
// Exclude bool, which derives from int but whose literal values are distinct
|
|
1962
|
+
// from the corresponding int literals.
|
|
1963
|
+
if (types_1.ClassType.isBuiltIn(primitiveType, 'int')) {
|
|
1964
|
+
return (0, typeUtils_1.derivesFromStdlibClass)(enumType, 'int');
|
|
1965
|
+
}
|
|
1966
|
+
if (types_1.ClassType.isBuiltIn(primitiveType, 'str')) {
|
|
1967
|
+
return (0, typeUtils_1.derivesFromStdlibClass)(enumType, 'str');
|
|
1968
|
+
}
|
|
1969
|
+
return false;
|
|
1970
|
+
}
|
|
1971
|
+
// If the specified type is a literal member of a primitive-backed enum class,
|
|
1972
|
+
// returns the corresponding primitive literal type. Otherwise returns the type
|
|
1973
|
+
// unmodified.
|
|
1974
|
+
function unwrapPrimitiveBackedEnumLiteral(classType) {
|
|
1975
|
+
const literalValue = classType.priv.literalValue;
|
|
1976
|
+
if (!(literalValue instanceof types_1.EnumLiteral) || !isPrimitiveBackedEnumClass(classType)) {
|
|
1977
|
+
return classType;
|
|
1978
|
+
}
|
|
1979
|
+
const itemType = literalValue.itemType;
|
|
1980
|
+
if ((0, types_1.isClassInstance)(itemType) && itemType.priv.literalValue !== undefined) {
|
|
1981
|
+
return itemType;
|
|
1982
|
+
}
|
|
1983
|
+
return classType;
|
|
1984
|
+
}
|
|
1985
|
+
// Determines whether two literal types compare equal using the `==` operator at
|
|
1986
|
+
// runtime. This differs from ClassType.isLiteralValueSame only for members of
|
|
1987
|
+
// primitive-backed enum classes, which compare equal to their underlying
|
|
1988
|
+
// primitive values.
|
|
1989
|
+
function isLiteralValueEqualAtRuntime(type1, type2) {
|
|
1990
|
+
return types_1.ClassType.isLiteralValueSame(unwrapPrimitiveBackedEnumLiteral(type1), unwrapPrimitiveBackedEnumLiteral(type2));
|
|
1991
|
+
}
|
|
1897
1992
|
// Attempts to narrow a type (make it more constrained) based on a comparison
|
|
1898
1993
|
// (equal or not equal) to a literal value. It also handles "is" or "is not"
|
|
1899
1994
|
// operators if isIsOperator is true.
|
|
@@ -1906,9 +2001,20 @@ function narrowTypeForLiteralComparison(evaluator, referenceType, literalType, i
|
|
|
1906
2001
|
}
|
|
1907
2002
|
return subtype;
|
|
1908
2003
|
}
|
|
1909
|
-
|
|
2004
|
+
// Determine whether this is a comparison between a primitive-backed enum
|
|
2005
|
+
// (e.g. IntEnum or StrEnum) and its underlying primitive type. Such a
|
|
2006
|
+
// comparison can be used for narrowing because the enum member compares
|
|
2007
|
+
// equal to its underlying primitive value at runtime.
|
|
2008
|
+
const isPrimitiveBackedEnumComparison = !isIsOperator &&
|
|
2009
|
+
(0, types_1.isClassInstance)(subtype) &&
|
|
2010
|
+
(isPrimitiveBackedEnumAndPrimitive(subtype, literalType) ||
|
|
2011
|
+
isPrimitiveBackedEnumAndPrimitive(literalType, subtype));
|
|
2012
|
+
if ((0, types_1.isClassInstance)(subtype) &&
|
|
2013
|
+
(types_1.ClassType.isSameGenericClass(literalType, subtype) || isPrimitiveBackedEnumComparison)) {
|
|
1910
2014
|
if (subtype.priv.literalValue !== undefined) {
|
|
1911
|
-
const literalValueMatches =
|
|
2015
|
+
const literalValueMatches = isPrimitiveBackedEnumComparison
|
|
2016
|
+
? isLiteralValueEqualAtRuntime(subtype, literalType)
|
|
2017
|
+
: types_1.ClassType.isLiteralValueSame(subtype, literalType);
|
|
1912
2018
|
if (isPositiveTest) {
|
|
1913
2019
|
return literalValueMatches ? subtype : undefined;
|
|
1914
2020
|
}
|
|
@@ -1920,13 +2026,31 @@ function narrowTypeForLiteralComparison(evaluator, referenceType, literalType, i
|
|
|
1920
2026
|
return literalValueMatches && (isSingleton || !isIsOperator) ? undefined : subtype;
|
|
1921
2027
|
}
|
|
1922
2028
|
if (isPositiveTest) {
|
|
2029
|
+
if (isPrimitiveBackedEnumComparison) {
|
|
2030
|
+
// If the reference type is the enum, attempt to find the member
|
|
2031
|
+
// whose value matches the primitive literal. If no member can be
|
|
2032
|
+
// identified (e.g. for an IntFlag class, whose members cannot be
|
|
2033
|
+
// enumerated), retain the reference type rather than narrowing it
|
|
2034
|
+
// to the primitive literal type.
|
|
2035
|
+
if (types_1.ClassType.isEnumClass(subtype)) {
|
|
2036
|
+
const allLiteralTypes = enumerateLiteralsForType(evaluator, subtype);
|
|
2037
|
+
const match = allLiteralTypes?.find((type) => isLiteralValueEqualAtRuntime(type, literalType));
|
|
2038
|
+
return match ?? subtype;
|
|
2039
|
+
}
|
|
2040
|
+
// The reference type is the primitive type, so narrowing it to the
|
|
2041
|
+
// enum literal would lose its (potentially derived) class. Retain
|
|
2042
|
+
// the reference type instead.
|
|
2043
|
+
return subtype;
|
|
2044
|
+
}
|
|
1923
2045
|
return literalType;
|
|
1924
2046
|
}
|
|
1925
2047
|
// If we're able to enumerate all possible literal values
|
|
1926
2048
|
// (for bool or enum), we can eliminate all others in a negative test.
|
|
1927
2049
|
const allLiteralTypes = enumerateLiteralsForType(evaluator, subtype);
|
|
1928
2050
|
if (allLiteralTypes && allLiteralTypes.length > 0) {
|
|
1929
|
-
return (0, types_1.combineTypes)(allLiteralTypes.filter((type) =>
|
|
2051
|
+
return (0, types_1.combineTypes)(allLiteralTypes.filter((type) => isPrimitiveBackedEnumComparison
|
|
2052
|
+
? !isLiteralValueEqualAtRuntime(type, literalType)
|
|
2053
|
+
: !types_1.ClassType.isLiteralValueSame(type, literalType)));
|
|
1930
2054
|
}
|
|
1931
2055
|
return subtype;
|
|
1932
2056
|
}
|
|
@@ -1967,7 +2091,7 @@ function enumerateLiteralsForType(evaluator, type) {
|
|
|
1967
2091
|
fields.forEach((symbol, name) => {
|
|
1968
2092
|
if (!symbol.isIgnoredForProtocolMatch()) {
|
|
1969
2093
|
let symbolType = evaluator.getEffectiveTypeOfSymbol(symbol);
|
|
1970
|
-
symbolType = (0, enums_1.transformTypeForEnumMember)(evaluator, type, name) ?? symbolType;
|
|
2094
|
+
symbolType = (0, enums_1.transformTypeForEnumMember)(evaluator, type, name, (0, analyzerNodeInfo_1.getInfoReader)(evaluator)) ?? symbolType;
|
|
1971
2095
|
if ((0, types_1.isClassInstance)(symbolType) &&
|
|
1972
2096
|
types_1.ClassType.isSameGenericClass(type, symbolType) &&
|
|
1973
2097
|
symbolType.priv.literalValue !== undefined) {
|