@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
|
@@ -196,6 +196,7 @@ const printExpressionTypes = false;
|
|
|
196
196
|
// long analysis times. This number has been tuned empirically.
|
|
197
197
|
exports.maxCodeComplexity = 768;
|
|
198
198
|
function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
199
|
+
const nodeInfo = AnalyzerNodeInfo.createAnalyzerNodeInfoAccessor(evaluatorOptions.nodeInfoReader);
|
|
199
200
|
const symbolResolutionStack = [];
|
|
200
201
|
const speculativeTypeTracker = new typeCacheUtils_1.SpeculativeTypeTracker();
|
|
201
202
|
const suppressedNodeStack = [];
|
|
@@ -216,6 +217,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
216
217
|
let returnTypeInferenceTypeFormTypeCache;
|
|
217
218
|
const signatureTrackerStack = [];
|
|
218
219
|
let prefetched;
|
|
220
|
+
function getScopeForNode(node) {
|
|
221
|
+
return ScopeUtils.getScopeForNode(node, nodeInfo);
|
|
222
|
+
}
|
|
223
|
+
function getScopeHierarchy(node, stopScope) {
|
|
224
|
+
return ScopeUtils.getScopeHierarchy(node, stopScope, nodeInfo);
|
|
225
|
+
}
|
|
226
|
+
function findTopNodeInScope(node, scope) {
|
|
227
|
+
return ScopeUtils.findTopNodeInScope(node, scope, nodeInfo);
|
|
228
|
+
}
|
|
229
|
+
function getScopeIdForNode(node) {
|
|
230
|
+
return ParseTreeUtils.getScopeIdForNode(node, nodeInfo);
|
|
231
|
+
}
|
|
232
|
+
function getTypeVarScopesForNode(node) {
|
|
233
|
+
return ParseTreeUtils.getTypeVarScopesForNode(node, nodeInfo);
|
|
234
|
+
}
|
|
219
235
|
function runWithCancellationToken(token, callback) {
|
|
220
236
|
// Save the current token and restore it after the callback to support nested calls
|
|
221
237
|
const oldToken = cancellationToken;
|
|
@@ -328,7 +344,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
328
344
|
if (flags !== undefined) {
|
|
329
345
|
const expectedFlags = cacheEntry.flags;
|
|
330
346
|
if (expectedFlags !== undefined && flags !== expectedFlags) {
|
|
331
|
-
const fileInfo =
|
|
347
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
332
348
|
const position = (0, positionUtils_1.convertOffsetToPosition)(node.start, fileInfo.lines);
|
|
333
349
|
const message = `Type cache flag mismatch for node type ${node.nodeType} ` +
|
|
334
350
|
`(parent ${node.parent?.nodeType ?? 'none'}): ` +
|
|
@@ -573,7 +589,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
573
589
|
// Some of these types have cyclical dependencies on each other,
|
|
574
590
|
// so don't re-enter this block once we start executing it.
|
|
575
591
|
prefetched = {};
|
|
576
|
-
const fileInfo =
|
|
592
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
577
593
|
prefetched.objectClass = getBuiltInType(node, 'object');
|
|
578
594
|
prefetched.typeClass = getBuiltInType(node, 'type');
|
|
579
595
|
prefetched.functionClass = getTypesType(node, 'FunctionType') ?? getBuiltInType(node, 'function');
|
|
@@ -686,7 +702,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
686
702
|
typeResult.type.priv.includePromotions &&
|
|
687
703
|
!typeResult.type.priv.includeSubclasses &&
|
|
688
704
|
types_1.ClassType.isBuiltIn(typeResult.type, 'bytes')) {
|
|
689
|
-
if (
|
|
705
|
+
if (nodeInfo.getFileInfo(node).diagnosticRuleSet.disableBytesTypePromotions) {
|
|
690
706
|
typeResult = {
|
|
691
707
|
...typeResult,
|
|
692
708
|
type: types_1.ClassType.cloneRemoveTypePromotions(typeResult.type),
|
|
@@ -753,7 +769,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
753
769
|
break;
|
|
754
770
|
}
|
|
755
771
|
case 52 /* ParseNodeType.Tuple */: {
|
|
756
|
-
typeResult = (0, tuples_1.getTypeOfTuple)(evaluatorInterface, node, flags, inferenceContext);
|
|
772
|
+
typeResult = (0, tuples_1.getTypeOfTuple)(evaluatorInterface, node, flags, inferenceContext, nodeInfo);
|
|
757
773
|
break;
|
|
758
774
|
}
|
|
759
775
|
case 14 /* ParseNodeType.Constant */: {
|
|
@@ -788,7 +804,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
788
804
|
if (expectingInstantiable && node.d.operator !== 6 /* OperatorType.BitwiseOr */) {
|
|
789
805
|
effectiveFlags &= ~128 /* EvalFlags.InstantiableType */;
|
|
790
806
|
}
|
|
791
|
-
typeResult = (0, operations_1.getTypeOfBinaryOperation)(evaluatorInterface, node, effectiveFlags, inferenceContext);
|
|
807
|
+
typeResult = (0, operations_1.getTypeOfBinaryOperation)(evaluatorInterface, node, effectiveFlags, inferenceContext, nodeInfo);
|
|
792
808
|
break;
|
|
793
809
|
}
|
|
794
810
|
case 5 /* ParseNodeType.AugmentedAssignment */: {
|
|
@@ -809,7 +825,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
809
825
|
break;
|
|
810
826
|
}
|
|
811
827
|
case 51 /* ParseNodeType.Ternary */: {
|
|
812
|
-
typeResult = (0, operations_1.getTypeOfTernaryOperation)(evaluatorInterface, node, flags, inferenceContext);
|
|
828
|
+
typeResult = (0, operations_1.getTypeOfTernaryOperation)(evaluatorInterface, node, flags, inferenceContext, nodeInfo);
|
|
813
829
|
break;
|
|
814
830
|
}
|
|
815
831
|
case 11 /* ParseNodeType.Comprehension */: {
|
|
@@ -911,7 +927,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
911
927
|
name = type.shared.name;
|
|
912
928
|
}
|
|
913
929
|
if (isTypeCheckingOnly) {
|
|
914
|
-
const fileInfo =
|
|
930
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
915
931
|
if (!fileInfo.isStubFile) {
|
|
916
932
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeCheckOnly().format({ name }), node);
|
|
917
933
|
}
|
|
@@ -1145,8 +1161,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1145
1161
|
if ((flags & 16777216 /* EvalFlags.ParsesStringLiteral */) === 0) {
|
|
1146
1162
|
updatedFlags |= 524288 /* EvalFlags.NotParsed */;
|
|
1147
1163
|
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1164
|
+
const annotation = nodeInfo.getStringAnnotation(node);
|
|
1165
|
+
if (annotation && (flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
|
1166
|
+
return getTypeOfExpression(annotation, updatedFlags);
|
|
1150
1167
|
}
|
|
1151
1168
|
if (node.d.strings.length === 1) {
|
|
1152
1169
|
const tokenFlags = node.d.strings[0].d.token.flags;
|
|
@@ -1286,7 +1303,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
1286
1303
|
});
|
|
1287
1304
|
}
|
|
1288
1305
|
function getTypeOfAnnotation(node, options) {
|
|
1289
|
-
const fileInfo =
|
|
1306
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
1290
1307
|
// Special-case the typing.pyi file, which contains some special
|
|
1291
1308
|
// types that the type analyzer needs to interpret differently.
|
|
1292
1309
|
if (fileInfo.isTypingStubFile || fileInfo.isTypingExtensionsStubFile) {
|
|
@@ -2243,9 +2260,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2243
2260
|
}
|
|
2244
2261
|
const iterReturnType = getTypeOfMagicMethodCall(subtype, iterMethodName, [], errorNode)?.type;
|
|
2245
2262
|
if (!iterReturnType) {
|
|
2246
|
-
// There was no __iter__.
|
|
2247
|
-
//
|
|
2263
|
+
// There was no callable __iter__. The legacy sequence protocol
|
|
2264
|
+
// falls back to __getitem__, but CPython does that only when
|
|
2265
|
+
// __iter__ is missing. An explicit `__iter__ = None` (or any
|
|
2266
|
+
// non-callable __iter__) makes the object not iterable.
|
|
2267
|
+
let hasExplicitIterMember = false;
|
|
2248
2268
|
if (!isAsync && (0, types_1.isClassInstance)(subtype)) {
|
|
2269
|
+
hasExplicitIterMember = !!(0, typeUtils_1.lookUpObjectMember)(subtype, iterMethodName, 16 /* MemberAccessFlags.SkipInstanceMembers */ |
|
|
2270
|
+
512 /* MemberAccessFlags.SkipAttributeAccessOverride */ |
|
|
2271
|
+
4 /* MemberAccessFlags.SkipObjectBaseClass */);
|
|
2272
|
+
}
|
|
2273
|
+
if (!isAsync && (0, types_1.isClassInstance)(subtype) && !hasExplicitIterMember) {
|
|
2249
2274
|
const getItemReturnType = getTypeOfMagicMethodCall(subtype, '__getitem__', [
|
|
2250
2275
|
{
|
|
2251
2276
|
type: prefetched?.intClass && (0, types_1.isInstantiableClass)(prefetched.intClass)
|
|
@@ -2419,7 +2444,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2419
2444
|
return getTypeOfModule(node, symbolName, ['_typeshed']);
|
|
2420
2445
|
}
|
|
2421
2446
|
function getTypeOfModule(node, symbolName, nameParts) {
|
|
2422
|
-
const fileInfo =
|
|
2447
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2423
2448
|
const lookupResult = importLookup({ nameParts, importingFileUri: fileInfo.fileUri });
|
|
2424
2449
|
if (!lookupResult) {
|
|
2425
2450
|
return undefined;
|
|
@@ -2431,8 +2456,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2431
2456
|
return getEffectiveTypeOfSymbol(symbol);
|
|
2432
2457
|
}
|
|
2433
2458
|
function checkCodeFlowTooComplex(node) {
|
|
2434
|
-
const scopeNode = node.nodeType === 31 /* ParseNodeType.Function */ ? node : ParseTreeUtils.getExecutionScopeNode(node);
|
|
2435
|
-
const codeComplexity =
|
|
2459
|
+
const scopeNode = node.nodeType === 31 /* ParseNodeType.Function */ ? node : ParseTreeUtils.getExecutionScopeNode(node, nodeInfo);
|
|
2460
|
+
const codeComplexity = nodeInfo.getCodeFlowComplexity(scopeNode);
|
|
2436
2461
|
if (codeComplexity > exports.maxCodeComplexity) {
|
|
2437
2462
|
let errorRange = scopeNode;
|
|
2438
2463
|
if (scopeNode.nodeType === 31 /* ParseNodeType.Function */) {
|
|
@@ -2441,7 +2466,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2441
2466
|
else if (scopeNode.nodeType === 36 /* ParseNodeType.Module */) {
|
|
2442
2467
|
errorRange = { start: 0, length: 0 };
|
|
2443
2468
|
}
|
|
2444
|
-
const fileInfo =
|
|
2469
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2445
2470
|
addDiagnosticForTextRange(fileInfo, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.codeTooComplexToAnalyze(), errorRange);
|
|
2446
2471
|
return true;
|
|
2447
2472
|
}
|
|
@@ -2457,18 +2482,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2457
2482
|
if (checkCodeFlowTooComplex(node)) {
|
|
2458
2483
|
return typeEvaluatorTypes_1.Reachability.Reachable;
|
|
2459
2484
|
}
|
|
2460
|
-
const flowNode =
|
|
2485
|
+
const flowNode = nodeInfo.getFlowNode(node);
|
|
2461
2486
|
if (!flowNode) {
|
|
2462
2487
|
if (node.parent) {
|
|
2463
2488
|
return getNodeReachability(node.parent, sourceNode);
|
|
2464
2489
|
}
|
|
2465
2490
|
return typeEvaluatorTypes_1.Reachability.UnreachableStructural;
|
|
2466
2491
|
}
|
|
2467
|
-
const sourceFlowNode = sourceNode ?
|
|
2492
|
+
const sourceFlowNode = sourceNode ? nodeInfo.getFlowNode(sourceNode) : undefined;
|
|
2468
2493
|
return codeFlowEngine.getFlowNodeReachability(flowNode, sourceFlowNode);
|
|
2469
2494
|
}
|
|
2470
2495
|
function getAfterNodeReachability(node) {
|
|
2471
|
-
const returnFlowNode =
|
|
2496
|
+
const returnFlowNode = nodeInfo.getAfterFlowNode(node);
|
|
2472
2497
|
if (!returnFlowNode) {
|
|
2473
2498
|
return typeEvaluatorTypes_1.Reachability.UnreachableStructural;
|
|
2474
2499
|
}
|
|
@@ -2479,7 +2504,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2479
2504
|
if (reachability !== typeEvaluatorTypes_1.Reachability.Reachable) {
|
|
2480
2505
|
return reachability;
|
|
2481
2506
|
}
|
|
2482
|
-
const executionScopeNode = ParseTreeUtils.getExecutionScopeNode(node);
|
|
2507
|
+
const executionScopeNode = ParseTreeUtils.getExecutionScopeNode(node, nodeInfo);
|
|
2483
2508
|
if (!isFlowNodeReachableUsingNeverNarrowing(executionScopeNode, returnFlowNode)) {
|
|
2484
2509
|
return typeEvaluatorTypes_1.Reachability.UnreachableByAnalysis;
|
|
2485
2510
|
}
|
|
@@ -2502,8 +2527,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2502
2527
|
if (checkCodeFlowTooComplex(sourceNode)) {
|
|
2503
2528
|
return true;
|
|
2504
2529
|
}
|
|
2505
|
-
const sourceFlowNode =
|
|
2506
|
-
const sinkFlowNode =
|
|
2530
|
+
const sourceFlowNode = nodeInfo.getFlowNode(sourceNode);
|
|
2531
|
+
const sinkFlowNode = nodeInfo.getFlowNode(sinkNode);
|
|
2507
2532
|
if (!sourceFlowNode || !sinkFlowNode) {
|
|
2508
2533
|
return false;
|
|
2509
2534
|
}
|
|
@@ -2521,7 +2546,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2521
2546
|
return;
|
|
2522
2547
|
}
|
|
2523
2548
|
if (!isDiagnosticSuppressedForNode(node)) {
|
|
2524
|
-
const fileInfo =
|
|
2549
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2525
2550
|
const reportTypeReachability = fileInfo.diagnosticRuleSet.enableReachabilityAnalysis;
|
|
2526
2551
|
if (reachability === typeEvaluatorTypes_1.Reachability.UnreachableStructural ||
|
|
2527
2552
|
reachability === typeEvaluatorTypes_1.Reachability.UnreachableStaticCondition ||
|
|
@@ -2536,7 +2561,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2536
2561
|
}
|
|
2537
2562
|
function addDeprecated(message, node) {
|
|
2538
2563
|
if (!isDiagnosticSuppressedForNode(node)) {
|
|
2539
|
-
const fileInfo =
|
|
2564
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2540
2565
|
fileInfo.diagnosticSink.addDeprecatedWithTextRange(message, node);
|
|
2541
2566
|
}
|
|
2542
2567
|
}
|
|
@@ -2549,7 +2574,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2549
2574
|
return undefined;
|
|
2550
2575
|
}
|
|
2551
2576
|
if (isNodeReachable(node)) {
|
|
2552
|
-
const fileInfo =
|
|
2577
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2553
2578
|
return fileInfo.diagnosticSink.addDiagnosticWithTextRange(diagLevel, message, range ?? node);
|
|
2554
2579
|
}
|
|
2555
2580
|
return undefined;
|
|
@@ -2574,7 +2599,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2574
2599
|
return suppressedEntries.every((entry) => !entry.suppressedDiags);
|
|
2575
2600
|
}
|
|
2576
2601
|
function addDiagnostic(rule, message, node, range) {
|
|
2577
|
-
const fileInfo =
|
|
2602
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2578
2603
|
const diagLevel = fileInfo.diagnosticRuleSet[rule];
|
|
2579
2604
|
if (diagLevel === 'none') {
|
|
2580
2605
|
return undefined;
|
|
@@ -2582,7 +2607,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2582
2607
|
const containingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
|
2583
2608
|
if (containingFunction) {
|
|
2584
2609
|
// Should we suppress this diagnostic because it's within an unannotated function?
|
|
2585
|
-
const fileInfo =
|
|
2610
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2586
2611
|
if (!fileInfo.diagnosticRuleSet.analyzeUnannotatedFunctions) {
|
|
2587
2612
|
// Is the target node within the body of the function? If so, suppress the diagnostic.
|
|
2588
2613
|
if (ParseTreeUtils.isUnannotatedFunction(containingFunction) &&
|
|
@@ -2592,7 +2617,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2592
2617
|
}
|
|
2593
2618
|
// Should we suppress this diagnostic because it's within a no_type_check function?
|
|
2594
2619
|
const containingClassNode = ParseTreeUtils.getEnclosingClass(containingFunction, /* stopAtFunction */ true);
|
|
2595
|
-
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, containingFunction, !!containingClassNode);
|
|
2620
|
+
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, containingFunction, !!containingClassNode, nodeInfo);
|
|
2596
2621
|
if ((functionInfo.flags & 524288 /* FunctionTypeFlags.NoTypeCheck */) !== 0) {
|
|
2597
2622
|
return undefined;
|
|
2598
2623
|
}
|
|
@@ -2624,7 +2649,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2624
2649
|
}
|
|
2625
2650
|
const declarations = symbolWithScope.symbol.getDeclarations();
|
|
2626
2651
|
let declaredType = getDeclaredTypeOfSymbol(symbolWithScope.symbol)?.type;
|
|
2627
|
-
const fileInfo =
|
|
2652
|
+
const fileInfo = nodeInfo.getFileInfo(nameNode);
|
|
2628
2653
|
// If this is a class scope and there is no type declared for this class variable,
|
|
2629
2654
|
// see if a parent class has a type declared.
|
|
2630
2655
|
if (declaredType === undefined && symbolWithScope.scope.type === 3 /* ScopeType.Class */) {
|
|
@@ -2644,7 +2669,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2644
2669
|
const isTypeAlias = !!declaredType && (0, types_1.isClassInstance)(declaredType) && types_1.ClassType.isBuiltIn(declaredType, 'TypeAlias');
|
|
2645
2670
|
if (declaredType && !isTypeAlias) {
|
|
2646
2671
|
let diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
|
2647
|
-
const liveScopeIds =
|
|
2672
|
+
const liveScopeIds = getTypeVarScopesForNode(nameNode);
|
|
2648
2673
|
const boundDeclaredType = (0, typeUtils_1.makeTypeVarsBound)(declaredType, liveScopeIds);
|
|
2649
2674
|
const srcType = (0, typeUtils_1.makeTypeVarsBound)(typeResult.type, liveScopeIds);
|
|
2650
2675
|
if (!assignType(boundDeclaredType, srcType, diagAddendum)) {
|
|
@@ -2670,7 +2695,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2670
2695
|
// appears to be a constant, use the strict source type. If it's a member
|
|
2671
2696
|
// variable that can be overridden by a child class, use the more general
|
|
2672
2697
|
// version by stripping off the literal and TypeForm.
|
|
2673
|
-
const scope =
|
|
2698
|
+
const scope = getScopeForNode(nameNode);
|
|
2674
2699
|
if (scope?.type === 3 /* ScopeType.Class */) {
|
|
2675
2700
|
if (types_1.TypeBase.isInstance(destType) &&
|
|
2676
2701
|
!(0, symbolNameUtils_1.isConstantName)(nameValue) &&
|
|
@@ -2768,7 +2793,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2768
2793
|
}
|
|
2769
2794
|
function assignTypeToMemberVariable(node, typeResult, isInstanceMember, srcExprNode) {
|
|
2770
2795
|
const memberName = node.d.member.d.value;
|
|
2771
|
-
const fileInfo =
|
|
2796
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2772
2797
|
const classDef = ParseTreeUtils.getEnclosingClass(node);
|
|
2773
2798
|
if (!classDef) {
|
|
2774
2799
|
return;
|
|
@@ -3174,8 +3199,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3174
3199
|
return type;
|
|
3175
3200
|
}
|
|
3176
3201
|
function markNamesAccessed(node, names) {
|
|
3177
|
-
const fileInfo =
|
|
3178
|
-
const scope =
|
|
3202
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
3203
|
+
const scope = getScopeForNode(node);
|
|
3179
3204
|
if (scope) {
|
|
3180
3205
|
names.forEach((symbolName) => {
|
|
3181
3206
|
const symbolInScope = scope.lookUpSymbolRecursive(symbolName);
|
|
@@ -3400,7 +3425,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3400
3425
|
}
|
|
3401
3426
|
}
|
|
3402
3427
|
function getTypeOfName(node, flags) {
|
|
3403
|
-
const fileInfo =
|
|
3428
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
3404
3429
|
const name = node.d.value;
|
|
3405
3430
|
let symbol;
|
|
3406
3431
|
let type;
|
|
@@ -3611,7 +3636,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3611
3636
|
}
|
|
3612
3637
|
if ((0, types_1.isTypeVar)(type) && type.priv.scopeId && !type.shared.isSynthesized) {
|
|
3613
3638
|
if (!(0, types_1.isTypeVarTuple)(type) || !type.priv.isInUnion) {
|
|
3614
|
-
const liveScopeIds =
|
|
3639
|
+
const liveScopeIds = getTypeVarScopesForNode(node);
|
|
3615
3640
|
type = types_1.TypeBase.cloneWithTypeForm(type, (0, typeUtils_1.convertToInstance)((0, typeUtils_1.makeTypeVarsBound)(type, liveScopeIds)));
|
|
3616
3641
|
}
|
|
3617
3642
|
}
|
|
@@ -3660,7 +3685,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3660
3685
|
return type;
|
|
3661
3686
|
}
|
|
3662
3687
|
// Disable for assignments in the typings.pyi file, since it defines special forms.
|
|
3663
|
-
const fileInfo =
|
|
3688
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
3664
3689
|
if (fileInfo.isTypingStubFile) {
|
|
3665
3690
|
return type;
|
|
3666
3691
|
}
|
|
@@ -3723,28 +3748,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3723
3748
|
// If the symbol is modified in scopes other than the one in which it is
|
|
3724
3749
|
// declared (e.g. through a nonlocal or global binding), it is not eligible
|
|
3725
3750
|
// for code flow analysis.
|
|
3726
|
-
if (!decls.every((decl) => decl.type === 2 /* DeclarationType.Param */ ||
|
|
3727
|
-
ScopeUtils.getScopeForNode(decl.node) === symbolWithScope.scope)) {
|
|
3751
|
+
if (!decls.every((decl) => decl.type === 2 /* DeclarationType.Param */ || getScopeForNode(decl.node) === symbolWithScope.scope)) {
|
|
3728
3752
|
return undefined;
|
|
3729
3753
|
}
|
|
3730
3754
|
// If the symbol is a non-final variable in the global scope, it is not
|
|
3731
3755
|
// eligible because it could be modified by other modules.
|
|
3732
3756
|
if (!decls.every((decl) => decl.type !== 1 /* DeclarationType.Variable */ ||
|
|
3733
3757
|
decl.isFinal ||
|
|
3734
|
-
|
|
3758
|
+
getScopeForNode(decl.node)?.type !== 4 /* ScopeType.Module */)) {
|
|
3735
3759
|
return undefined;
|
|
3736
3760
|
}
|
|
3737
3761
|
// If the symbol is a variable captured by an inner function
|
|
3738
3762
|
// or lambda, see if we can infer the type from the outer scope.
|
|
3739
|
-
const scopeHierarchy =
|
|
3763
|
+
const scopeHierarchy = getScopeHierarchy(node, symbolWithScope.scope);
|
|
3740
3764
|
if (scopeHierarchy && scopeHierarchy.length >= 2) {
|
|
3741
3765
|
// Find the parse node associated with the scope that is just inside of the
|
|
3742
3766
|
// scope that declares the captured variable.
|
|
3743
|
-
const innerScopeNode =
|
|
3767
|
+
const innerScopeNode = findTopNodeInScope(node, scopeHierarchy[scopeHierarchy.length - 2]);
|
|
3744
3768
|
if (innerScopeNode?.nodeType === 31 /* ParseNodeType.Function */ ||
|
|
3745
3769
|
innerScopeNode?.nodeType === 33 /* ParseNodeType.Lambda */ ||
|
|
3746
3770
|
innerScopeNode?.nodeType === 10 /* ParseNodeType.Class */) {
|
|
3747
|
-
const innerScopeCodeFlowNode =
|
|
3771
|
+
const innerScopeCodeFlowNode = nodeInfo.getFlowNode(innerScopeNode);
|
|
3748
3772
|
if (innerScopeCodeFlowNode) {
|
|
3749
3773
|
// See if any of the assignments of the symbol are reachable
|
|
3750
3774
|
// from this node. If so, we cannot apply any narrowing because
|
|
@@ -3755,7 +3779,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3755
3779
|
if (decl.type === 2 /* DeclarationType.Param */) {
|
|
3756
3780
|
return true;
|
|
3757
3781
|
}
|
|
3758
|
-
const declCodeFlowNode =
|
|
3782
|
+
const declCodeFlowNode = nodeInfo.getFlowNode(decl.node);
|
|
3759
3783
|
if (!declCodeFlowNode) {
|
|
3760
3784
|
return false;
|
|
3761
3785
|
}
|
|
@@ -3874,7 +3898,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3874
3898
|
container: enclosingScope.d.name.d.value,
|
|
3875
3899
|
}), node);
|
|
3876
3900
|
}
|
|
3877
|
-
const scopeIdToAssign =
|
|
3901
|
+
const scopeIdToAssign = getScopeIdForNode(enclosingScope);
|
|
3878
3902
|
return types_1.TypeVarType.cloneForScopeId(type, scopeIdToAssign, enclosingScope.d.name.d.value, enclosingScope.nodeType === 31 /* ParseNodeType.Function */ ? 1 /* TypeVarScopeType.Function */ : 0 /* TypeVarScopeType.Class */);
|
|
3879
3903
|
}
|
|
3880
3904
|
if ((flags & 4096 /* EvalFlags.AllowTypeVarWithoutScopeId */) === 0) {
|
|
@@ -3899,7 +3923,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3899
3923
|
}
|
|
3900
3924
|
const enclosingClass = ParseTreeUtils.getEnclosingClass(node);
|
|
3901
3925
|
if (enclosingClass) {
|
|
3902
|
-
const liveTypeVarScopeIds =
|
|
3926
|
+
const liveTypeVarScopeIds = getTypeVarScopesForNode(enclosingClass);
|
|
3903
3927
|
if (!liveTypeVarScopeIds.includes(scopeId)) {
|
|
3904
3928
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarInvalidForMemberVariable().format({
|
|
3905
3929
|
name: types_1.TypeVarType.getReadableName(type),
|
|
@@ -4120,7 +4144,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4120
4144
|
}
|
|
4121
4145
|
}
|
|
4122
4146
|
if (!skipPartialUnknownCheck) {
|
|
4123
|
-
reportPossibleUnknownAssignment(
|
|
4147
|
+
reportPossibleUnknownAssignment(nodeInfo.getFileInfo(node).diagnosticRuleSet.reportUnknownMemberType, diagnosticRules_1.DiagnosticRule.reportUnknownMemberType, node.d.member, typeResult.type, node,
|
|
4124
4148
|
/* ignoreEmptyContainers */ false);
|
|
4125
4149
|
}
|
|
4126
4150
|
// Cache the type information in the member name node.
|
|
@@ -4131,7 +4155,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4131
4155
|
let baseType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(baseTypeResult.type);
|
|
4132
4156
|
const memberName = node.d.member.d.value;
|
|
4133
4157
|
let diag = new diagnostic_1.DiagnosticAddendum();
|
|
4134
|
-
const fileInfo =
|
|
4158
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
4135
4159
|
let type;
|
|
4136
4160
|
let narrowedTypeForSet;
|
|
4137
4161
|
let typeErrors = false;
|
|
@@ -4223,7 +4247,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4223
4247
|
(0, types_1.isClass)(prefetched.functionClass)) {
|
|
4224
4248
|
baseType = types_1.ClassType.cloneAsInstance(prefetched.functionClass);
|
|
4225
4249
|
}
|
|
4226
|
-
const enumMemberResult = (0, enums_1.getTypeOfEnumMember)(evaluatorInterface, node, baseType, memberName, isIncomplete);
|
|
4250
|
+
const enumMemberResult = (0, enums_1.getTypeOfEnumMember)(evaluatorInterface, node, baseType, memberName, isIncomplete, nodeInfo);
|
|
4227
4251
|
if (enumMemberResult) {
|
|
4228
4252
|
if (usage.method === 'get') {
|
|
4229
4253
|
typeResult = enumMemberResult;
|
|
@@ -4573,7 +4597,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4573
4597
|
if (errorNode &&
|
|
4574
4598
|
(0, types_1.isInstantiableClass)(memberInfo.classType) &&
|
|
4575
4599
|
types_1.ClassType.isSameGenericClass(memberInfo.classType, isAccessedThroughObject ? types_1.ClassType.cloneAsInstantiable(classType) : classType)) {
|
|
4576
|
-
setSymbolAccessed(
|
|
4600
|
+
setSymbolAccessed(nodeInfo.getFileInfo(errorNode), memberInfo.symbol, errorNode);
|
|
4577
4601
|
}
|
|
4578
4602
|
// Special-case `__init_subclass` and `__class_getitem__` because
|
|
4579
4603
|
// these are always treated as class methods even if they're not
|
|
@@ -5081,13 +5105,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
5081
5105
|
// they don't result in runtime exceptions when used in this manner.
|
|
5082
5106
|
let skipSubscriptCheck = (flags & 32768 /* EvalFlags.VarTypeAnnotation */) !== 0;
|
|
5083
5107
|
if (skipSubscriptCheck) {
|
|
5084
|
-
const scopeNode = ParseTreeUtils.getExecutionScopeNode(node);
|
|
5108
|
+
const scopeNode = ParseTreeUtils.getExecutionScopeNode(node, nodeInfo);
|
|
5085
5109
|
if (scopeNode?.nodeType === 36 /* ParseNodeType.Module */) {
|
|
5086
5110
|
skipSubscriptCheck = false;
|
|
5087
5111
|
}
|
|
5088
5112
|
}
|
|
5089
5113
|
if (!skipSubscriptCheck) {
|
|
5090
|
-
const fileInfo =
|
|
5114
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
5091
5115
|
if ((0, types_1.isInstantiableClass)(baseTypeResult.type) &&
|
|
5092
5116
|
types_1.ClassType.isBuiltIn(baseTypeResult.type) &&
|
|
5093
5117
|
!baseTypeResult.type.priv.aliasName) {
|
|
@@ -5636,7 +5660,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
5636
5660
|
const isFinalAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'Final');
|
|
5637
5661
|
const isClassVarAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'ClassVar');
|
|
5638
5662
|
// This feature is currently experimental.
|
|
5639
|
-
const supportsTypedDictTypeArg =
|
|
5663
|
+
const supportsTypedDictTypeArg = nodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures &&
|
|
5640
5664
|
types_1.ClassType.isBuiltIn(concreteSubtype, 'TypedDict');
|
|
5641
5665
|
let typeArgs = getTypeArgs(node, flags, {
|
|
5642
5666
|
isAnnotatedClass,
|
|
@@ -6056,7 +6080,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6056
6080
|
// treated as a type. The others can be regular (non-type) objects.
|
|
6057
6081
|
adjFlags =
|
|
6058
6082
|
32 /* EvalFlags.NoParamSpec */ | 64 /* EvalFlags.NoTypeVarTuple */ | 2 /* EvalFlags.NoSpecialize */ | 131072 /* EvalFlags.NoClassVar */;
|
|
6059
|
-
if ((0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(
|
|
6083
|
+
if ((0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(nodeInfo.getFileInfo(node))) {
|
|
6060
6084
|
adjFlags |= 4 /* EvalFlags.ForwardRefs */;
|
|
6061
6085
|
}
|
|
6062
6086
|
typeResult = {
|
|
@@ -6146,7 +6170,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6146
6170
|
function getTypeArg(node, flags, supportsDictExpression) {
|
|
6147
6171
|
let typeResult;
|
|
6148
6172
|
let adjustedFlags = flags | 128 /* EvalFlags.InstantiableType */ | 1 /* EvalFlags.ConvertEllipsisToAny */ | 8 /* EvalFlags.StrLiteralAsType */;
|
|
6149
|
-
const fileInfo =
|
|
6173
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
6150
6174
|
if (fileInfo.isStubFile) {
|
|
6151
6175
|
adjustedFlags |= 4 /* EvalFlags.ForwardRefs */;
|
|
6152
6176
|
}
|
|
@@ -6163,7 +6187,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6163
6187
|
}
|
|
6164
6188
|
else if (node.nodeType === 18 /* ParseNodeType.Dictionary */ && supportsDictExpression) {
|
|
6165
6189
|
const inlinedTypeDict = prefetched?.typedDictClass && (0, types_1.isInstantiableClass)(prefetched.typedDictClass)
|
|
6166
|
-
? (0, typedDicts_1.createTypedDictTypeInlined)(evaluatorInterface, node, prefetched.typedDictClass)
|
|
6190
|
+
? (0, typedDicts_1.createTypedDictTypeInlined)(evaluatorInterface, node, prefetched.typedDictClass, nodeInfo)
|
|
6167
6191
|
: undefined;
|
|
6168
6192
|
const keyTypeFallback = prefetched?.strClass && (0, types_1.isInstantiableClass)(prefetched.strClass)
|
|
6169
6193
|
? prefetched.strClass
|
|
@@ -6329,7 +6353,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6329
6353
|
// have invalid type parameters.
|
|
6330
6354
|
const isCyclicalTypeVarCall = (0, types_1.isInstantiableClass)(baseTypeResult.type) &&
|
|
6331
6355
|
types_1.ClassType.isBuiltIn(baseTypeResult.type, 'TypeVar') &&
|
|
6332
|
-
|
|
6356
|
+
nodeInfo.getFileInfo(node).isTypingStubFile;
|
|
6333
6357
|
const isTypeFormCall = (0, types_1.isInstantiableClass)(baseTypeResult.type) && isTypeFormClass(baseTypeResult.type);
|
|
6334
6358
|
if (!isCyclicalTypeVarCall && !isTypeFormCall) {
|
|
6335
6359
|
argList.forEach((arg) => {
|
|
@@ -6694,7 +6718,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6694
6718
|
let curNode = node;
|
|
6695
6719
|
let scope;
|
|
6696
6720
|
while (curNode) {
|
|
6697
|
-
scope =
|
|
6721
|
+
scope = getScopeForNode(curNode);
|
|
6698
6722
|
// Stop when we get a valid scope that's not a list comprehension
|
|
6699
6723
|
// scope. That includes lambdas, functions, classes, and modules.
|
|
6700
6724
|
if (scope && scope.type !== 1 /* ScopeType.Comprehension */) {
|
|
@@ -6726,7 +6750,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6726
6750
|
if (node.d.args.length > 2) {
|
|
6727
6751
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.superCallArgCount(), node.d.args[2]);
|
|
6728
6752
|
}
|
|
6729
|
-
const enclosingFunction = ParseTreeUtils.getEnclosingFunctionEvaluationScope(node);
|
|
6753
|
+
const enclosingFunction = ParseTreeUtils.getEnclosingFunctionEvaluationScope(node, nodeInfo);
|
|
6730
6754
|
const enclosingClass = enclosingFunction ? ParseTreeUtils.getEnclosingClass(enclosingFunction) : undefined;
|
|
6731
6755
|
const enclosingClassType = enclosingClass ? getTypeOfClass(enclosingClass)?.classType : undefined;
|
|
6732
6756
|
// Determine which class the "super" call is applied to. If
|
|
@@ -6748,7 +6772,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6748
6772
|
// This results in a runtime exception.
|
|
6749
6773
|
if (enclosingFunction) {
|
|
6750
6774
|
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, enclosingFunction,
|
|
6751
|
-
/* isInClass */ true);
|
|
6775
|
+
/* isInClass */ true, nodeInfo);
|
|
6752
6776
|
if ((functionInfo?.flags & 4 /* FunctionTypeFlags.StaticMethod */) !== 0) {
|
|
6753
6777
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.superCallZeroArgFormStaticMethod(), node.d.leftExpr);
|
|
6754
6778
|
}
|
|
@@ -6815,7 +6839,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6815
6839
|
if (methodType.shared.parameters.length > 0 &&
|
|
6816
6840
|
types_1.FunctionParam.isTypeDeclared(methodType.shared.parameters[0])) {
|
|
6817
6841
|
let paramType = types_1.FunctionType.getParamType(methodType, 0);
|
|
6818
|
-
const liveScopeIds =
|
|
6842
|
+
const liveScopeIds = getTypeVarScopesForNode(node);
|
|
6819
6843
|
paramType = (0, typeUtils_1.makeTypeVarsBound)(paramType, liveScopeIds);
|
|
6820
6844
|
implicitBindToType = makeTopLevelTypeVarsConcrete(paramType);
|
|
6821
6845
|
}
|
|
@@ -7894,7 +7918,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7894
7918
|
if (types_1.FunctionType.isBuiltIn(type, 'namedtuple')) {
|
|
7895
7919
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUntypedNamedTuple, localize_1.LocMessage.namedTupleNoTypes(), errorNode);
|
|
7896
7920
|
const result = {
|
|
7897
|
-
returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList,
|
|
7921
|
+
returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList,
|
|
7922
|
+
/* includesTypes */ false, nodeInfo),
|
|
7898
7923
|
};
|
|
7899
7924
|
validateArgs(errorNode, argList, { type: type }, constraints, skipUnknownArgCheck, inferenceContext);
|
|
7900
7925
|
return result;
|
|
@@ -7968,18 +7993,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7968
7993
|
return undefined;
|
|
7969
7994
|
}
|
|
7970
7995
|
let isAbstract = false;
|
|
7971
|
-
const lastFunctionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, lastDecl.node,
|
|
7996
|
+
const lastFunctionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, lastDecl.node,
|
|
7997
|
+
/* isInClass */ true, nodeInfo);
|
|
7972
7998
|
if ((lastFunctionInfo.flags & 8 /* FunctionTypeFlags.AbstractMethod */) !== 0) {
|
|
7973
7999
|
isAbstract = true;
|
|
7974
8000
|
}
|
|
7975
|
-
const isStubFile =
|
|
8001
|
+
const isStubFile = nodeInfo.getFileInfo(lastDecl.node).isStubFile;
|
|
7976
8002
|
// In an overloaded method, the first overload can also be marked abstract.
|
|
7977
8003
|
// In stub files, there is no implementation, so this is the only way to mark
|
|
7978
8004
|
// an overloaded method as abstract.
|
|
7979
8005
|
const firstDecl = symbol.getDeclarations()[0];
|
|
7980
8006
|
let firstFunctionInfo;
|
|
7981
8007
|
if (firstDecl !== lastDecl && firstDecl.type === 5 /* DeclarationType.Function */) {
|
|
7982
|
-
firstFunctionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, firstDecl.node,
|
|
8008
|
+
firstFunctionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, firstDecl.node,
|
|
8009
|
+
/* isInClass */ true, nodeInfo);
|
|
7983
8010
|
if ((firstFunctionInfo.flags & 8 /* FunctionTypeFlags.AbstractMethod */) !== 0) {
|
|
7984
8011
|
isAbstract = true;
|
|
7985
8012
|
}
|
|
@@ -8129,7 +8156,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
8129
8156
|
}
|
|
8130
8157
|
if (className === 'NamedTuple') {
|
|
8131
8158
|
const result = {
|
|
8132
|
-
returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList,
|
|
8159
|
+
returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList,
|
|
8160
|
+
/* includesTypes */ true, nodeInfo),
|
|
8133
8161
|
};
|
|
8134
8162
|
const initTypeResult = (0, constructors_1.getBoundInitMethod)(evaluatorInterface, errorNode, types_1.ClassType.cloneAsInstance(expandedCallType),
|
|
8135
8163
|
/* diag */ undefined, 0 /* MemberAccessFlags.Default */);
|
|
@@ -8147,14 +8175,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
8147
8175
|
if (expandedCallType.shared.fullName === 'builtins.sentinel' ||
|
|
8148
8176
|
expandedCallType.shared.fullName === 'typing_extensions.sentinel' ||
|
|
8149
8177
|
expandedCallType.shared.fullName === 'typing_extensions.Sentinel') {
|
|
8150
|
-
return {
|
|
8178
|
+
return {
|
|
8179
|
+
returnType: (0, sentinel_1.createSentinelType)(evaluatorInterface, errorNode, argList, expandedCallType, nodeInfo),
|
|
8180
|
+
};
|
|
8151
8181
|
}
|
|
8152
8182
|
if (types_1.ClassType.isSpecialFormClass(expandedCallType)) {
|
|
8153
8183
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.typeNotIntantiable().format({ type: className }), errorNode);
|
|
8154
8184
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true };
|
|
8155
8185
|
}
|
|
8156
8186
|
if (className === 'TypedDict') {
|
|
8157
|
-
return {
|
|
8187
|
+
return {
|
|
8188
|
+
returnType: (0, typedDicts_1.createTypedDictType)(evaluatorInterface, errorNode, expandedCallType, argList, nodeInfo),
|
|
8189
|
+
};
|
|
8158
8190
|
}
|
|
8159
8191
|
if (className === 'auto' && argList.length === 0) {
|
|
8160
8192
|
return { returnType: (0, enums_1.getEnumAutoValueType)(evaluatorInterface, errorNode) };
|
|
@@ -8165,9 +8197,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
8165
8197
|
expandedCallType.shared.effectiveMetaclass &&
|
|
8166
8198
|
(0, types_1.isClass)(expandedCallType.shared.effectiveMetaclass) &&
|
|
8167
8199
|
(0, enums_1.isEnumMetaclass)(expandedCallType.shared.effectiveMetaclass) &&
|
|
8168
|
-
!(0, enums_1.isEnumClassWithMembers)(evaluatorInterface, expandedCallType)) {
|
|
8200
|
+
!(0, enums_1.isEnumClassWithMembers)(evaluatorInterface, expandedCallType, nodeInfo)) {
|
|
8169
8201
|
return {
|
|
8170
|
-
returnType: (0, enums_1.createEnumType)(evaluatorInterface, errorNode, expandedCallType, argList) ??
|
|
8202
|
+
returnType: (0, enums_1.createEnumType)(evaluatorInterface, errorNode, expandedCallType, argList, nodeInfo) ??
|
|
8171
8203
|
(0, typeUtils_1.convertToInstance)(unexpandedCallType),
|
|
8172
8204
|
};
|
|
8173
8205
|
}
|
|
@@ -8211,6 +8243,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
8211
8243
|
const overloadsUsedForCall = constructorResult.overloadsUsedForCall;
|
|
8212
8244
|
const argumentErrors = constructorResult.argumentErrors;
|
|
8213
8245
|
const isTypeIncomplete = constructorResult.isTypeIncomplete;
|
|
8246
|
+
const usesBuiltInTypeNew = overloadsUsedForCall?.some((overload) => types_1.FunctionType.isBuiltIn(overload, 'builtins.type.__new__'));
|
|
8214
8247
|
let returnType = constructorResult.returnType;
|
|
8215
8248
|
// If the expandedCallType originated from a TypeVar, convert
|
|
8216
8249
|
// the constructed type back to the TypeVar. For example, if
|
|
@@ -8241,11 +8274,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
8241
8274
|
newClassName = firstArgType.priv.literalValue;
|
|
8242
8275
|
}
|
|
8243
8276
|
}
|
|
8244
|
-
const newClassType = types_1.ClassType.createInstantiable(newClassName, '', '',
|
|
8245
|
-
|
|
8277
|
+
const newClassType = types_1.ClassType.createInstantiable(newClassName, '', '', nodeInfo.getFileInfo(errorNode).fileUri, 0 /* ClassTypeFlags.None */, ParseTreeUtils.getTypeSourceId(errorNode), types_1.ClassType.cloneAsInstantiable(returnType), types_1.ClassType.cloneAsInstantiable(returnType));
|
|
8278
|
+
if (usesBuiltInTypeNew && argList.length >= 2) {
|
|
8279
|
+
const baseTupleType = getTypeOfArg(argList[1], /* inferenceContext */ undefined).type;
|
|
8280
|
+
if ((0, types_1.isClassInstance)(baseTupleType)) {
|
|
8281
|
+
const baseClasses = getBaseClassesFromTypeCall(baseTupleType);
|
|
8282
|
+
if (baseClasses) {
|
|
8283
|
+
newClassType.shared.baseClasses.push(...baseClasses);
|
|
8284
|
+
}
|
|
8285
|
+
}
|
|
8286
|
+
}
|
|
8287
|
+
if (newClassType.shared.baseClasses.length === 0) {
|
|
8288
|
+
newClassType.shared.baseClasses.push(getBuiltInType(errorNode, 'object'));
|
|
8289
|
+
}
|
|
8246
8290
|
newClassType.shared.effectiveMetaclass = expandedCallType;
|
|
8247
8291
|
newClassType.shared.declaration = returnType.shared.declaration;
|
|
8248
|
-
(0, typeUtils_1.computeMroLinearization)(newClassType)
|
|
8292
|
+
if (!(0, typeUtils_1.computeMroLinearization)(newClassType)) {
|
|
8293
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.methodOrdering(), errorNode);
|
|
8294
|
+
}
|
|
8249
8295
|
returnType = newClassType;
|
|
8250
8296
|
}
|
|
8251
8297
|
return { returnType, overloadsUsedForCall, argumentErrors, isTypeIncomplete };
|
|
@@ -8285,7 +8331,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
8285
8331
|
}
|
|
8286
8332
|
// Verify that the cast is necessary.
|
|
8287
8333
|
let castToType = getTypeOfArgExpectingType(argList[0], { typeExpression: true }).type;
|
|
8288
|
-
const liveScopeIds =
|
|
8334
|
+
const liveScopeIds = getTypeVarScopesForNode(errorNode);
|
|
8289
8335
|
castToType = (0, typeUtils_1.makeTypeVarsBound)(castToType, liveScopeIds);
|
|
8290
8336
|
let castFromType = getTypeOfArg(argList[1], /* inferenceContext */ undefined).type;
|
|
8291
8337
|
if (castFromType.props?.specialForm) {
|
|
@@ -9262,7 +9308,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9262
9308
|
return validateArgTypesWithExpectedType(errorNode, matchResults, constraints, skipUnknownArgCheck, expectedType, returnType);
|
|
9263
9309
|
}
|
|
9264
9310
|
function validateArgTypesWithExpectedType(errorNode, matchResults, constraints, skipUnknownArgCheck = false, expectedType, returnType) {
|
|
9265
|
-
const liveTypeVarScopes =
|
|
9311
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(errorNode);
|
|
9266
9312
|
let assignFlags = 2048 /* AssignTypeFlags.PopulateExpectedType */;
|
|
9267
9313
|
if ((0, typeUtils_1.containsLiteralType)(expectedType, /* includeTypeArgs */ true)) {
|
|
9268
9314
|
assignFlags |= 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
|
@@ -9483,7 +9529,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9483
9529
|
if ((0, types_1.isUnpackedClass)(specializedReturnType)) {
|
|
9484
9530
|
specializedReturnType = types_1.ClassType.cloneForPacked(specializedReturnType);
|
|
9485
9531
|
}
|
|
9486
|
-
const liveTypeVarScopes =
|
|
9532
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(errorNode);
|
|
9487
9533
|
specializedReturnType = adjustCallableReturnType(errorNode, specializedReturnType, liveTypeVarScopes);
|
|
9488
9534
|
if (specializedInitSelfType) {
|
|
9489
9535
|
specializedInitSelfType = solveAndApplyConstraints(specializedInitSelfType, constraints);
|
|
@@ -9546,7 +9592,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9546
9592
|
// Create a new scope ID based on the caller's position. This
|
|
9547
9593
|
// will guarantee uniqueness. If another caller uses the same
|
|
9548
9594
|
// call and arguments, the type vars will not conflict.
|
|
9549
|
-
const newScopeId =
|
|
9595
|
+
const newScopeId = getScopeIdForNode(callNode);
|
|
9550
9596
|
const solution = new constraintSolution_1.ConstraintSolution();
|
|
9551
9597
|
const newTypeParams = typeParams.map((typeVar) => {
|
|
9552
9598
|
const newTypeParam = types_1.TypeVarType.cloneForScopeId(typeVar, newScopeId, typeVar.priv.scopeName, 1 /* TypeVarScopeType.Function */);
|
|
@@ -9818,7 +9864,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9818
9864
|
if (!options?.skipReportError) {
|
|
9819
9865
|
// Mismatching parameter types are common in untyped code; don't bother spending time
|
|
9820
9866
|
// printing types if the diagnostic is disabled.
|
|
9821
|
-
const fileInfo =
|
|
9867
|
+
const fileInfo = nodeInfo.getFileInfo(argParam.errorNode);
|
|
9822
9868
|
if (fileInfo.diagnosticRuleSet.reportArgumentType !== 'none' &&
|
|
9823
9869
|
!canSkipDiagnosticForNode(argParam.errorNode) &&
|
|
9824
9870
|
!isTypeIncomplete) {
|
|
@@ -9870,7 +9916,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9870
9916
|
}
|
|
9871
9917
|
if (!options.skipUnknownArgCheck) {
|
|
9872
9918
|
const simplifiedType = makeTopLevelTypeVarsConcrete((0, types_1.removeUnbound)(argType));
|
|
9873
|
-
const fileInfo =
|
|
9919
|
+
const fileInfo = nodeInfo.getFileInfo(argParam.errorNode);
|
|
9874
9920
|
function getDiagAddendum() {
|
|
9875
9921
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
|
9876
9922
|
if (argParam.paramName) {
|
|
@@ -9993,7 +10039,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9993
10039
|
}).type;
|
|
9994
10040
|
typeVar.shared.defaultType = (0, typeUtils_1.convertToInstance)(argType);
|
|
9995
10041
|
typeVar.shared.isDefaultExplicit = true;
|
|
9996
|
-
const fileInfo =
|
|
10042
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
9997
10043
|
if (!fileInfo.isStubFile &&
|
|
9998
10044
|
pythonVersion_1.PythonVersion.isLessThan(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_13) &&
|
|
9999
10045
|
classType.shared.moduleName !== 'typing_extensions') {
|
|
@@ -10099,7 +10145,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10099
10145
|
typeVar.shared.isDefaultExplicit = true;
|
|
10100
10146
|
}
|
|
10101
10147
|
}
|
|
10102
|
-
const fileInfo =
|
|
10148
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
10103
10149
|
if (!fileInfo.isStubFile &&
|
|
10104
10150
|
pythonVersion_1.PythonVersion.isLessThan(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_13) &&
|
|
10105
10151
|
classType.shared.moduleName !== 'typing_extensions') {
|
|
@@ -10160,7 +10206,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10160
10206
|
paramSpec.shared.isDefaultExplicit = true;
|
|
10161
10207
|
}
|
|
10162
10208
|
}
|
|
10163
|
-
const fileInfo =
|
|
10209
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
10164
10210
|
if (!fileInfo.isStubFile &&
|
|
10165
10211
|
pythonVersion_1.PythonVersion.isLessThan(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_13) &&
|
|
10166
10212
|
classType.shared.moduleName !== 'typing_extensions') {
|
|
@@ -10239,7 +10285,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10239
10285
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeMustBeAssigned(), errorNode);
|
|
10240
10286
|
return undefined;
|
|
10241
10287
|
}
|
|
10242
|
-
const scope =
|
|
10288
|
+
const scope = getScopeForNode(errorNode);
|
|
10243
10289
|
if (scope) {
|
|
10244
10290
|
if (scope.type !== 3 /* ScopeType.Class */ && scope.type !== 4 /* ScopeType.Module */ && scope.type !== 5 /* ScopeType.Builtin */) {
|
|
10245
10291
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeBadScope(), errorNode.parent.d.leftExpr);
|
|
@@ -10300,7 +10346,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10300
10346
|
isTypeParamListValid = false;
|
|
10301
10347
|
}
|
|
10302
10348
|
else {
|
|
10303
|
-
entryType = types_1.TypeVarType.cloneForScopeId(entryType,
|
|
10349
|
+
entryType = types_1.TypeVarType.cloneForScopeId(entryType, getScopeIdForNode(nameNode), nameNode.d.value, 2 /* TypeVarScopeType.TypeAlias */);
|
|
10304
10350
|
}
|
|
10305
10351
|
typeParams.push(entryType);
|
|
10306
10352
|
}
|
|
@@ -10346,7 +10392,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10346
10392
|
// in the Python specification: The static type checker will treat
|
|
10347
10393
|
// the new type as if it were a subclass of the original type.
|
|
10348
10394
|
function createNewType(errorNode, argList) {
|
|
10349
|
-
const fileInfo =
|
|
10395
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
10350
10396
|
let className = '';
|
|
10351
10397
|
if (argList.length !== 2) {
|
|
10352
10398
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.newTypeParamCount(), errorNode);
|
|
@@ -10413,29 +10459,33 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10413
10459
|
}
|
|
10414
10460
|
return classType;
|
|
10415
10461
|
}
|
|
10462
|
+
function getBaseClassesFromTypeCall(baseTupleType) {
|
|
10463
|
+
if (!(0, typeUtils_1.isTupleClass)(baseTupleType) || baseTupleType.priv.tupleTypeArgs === undefined) {
|
|
10464
|
+
return undefined;
|
|
10465
|
+
}
|
|
10466
|
+
return baseTupleType.priv.tupleTypeArgs.map((typeArg) => {
|
|
10467
|
+
const specializedType = makeTopLevelTypeVarsConcrete(typeArg.type);
|
|
10468
|
+
return (0, typeUtils_1.isEffectivelyInstantiable)(specializedType) ? specializedType : types_1.UnknownType.create();
|
|
10469
|
+
});
|
|
10470
|
+
}
|
|
10416
10471
|
// Implements the semantics of the multi-parameter variant of the "type" call.
|
|
10417
10472
|
function createClassFromMetaclass(errorNode, argList, metaclass) {
|
|
10418
|
-
const fileInfo =
|
|
10473
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
10419
10474
|
const arg0Type = getTypeOfArg(argList[0], /* inferenceContext */ undefined).type;
|
|
10420
10475
|
if (!(0, types_1.isClassInstance)(arg0Type) || !types_1.ClassType.isBuiltIn(arg0Type, 'str')) {
|
|
10421
10476
|
return undefined;
|
|
10422
10477
|
}
|
|
10423
10478
|
const className = arg0Type.priv.literalValue || '_';
|
|
10424
|
-
const
|
|
10425
|
-
|
|
10426
|
-
if (!(0, types_1.isClassInstance)(arg1Type) || !(0, typeUtils_1.isTupleClass)(arg1Type) || arg1Type.priv.tupleTypeArgs === undefined) {
|
|
10479
|
+
const baseTupleType = getTypeOfArg(argList[1], /* inferenceContext */ undefined).type;
|
|
10480
|
+
if (!(0, types_1.isClassInstance)(baseTupleType)) {
|
|
10427
10481
|
return undefined;
|
|
10428
10482
|
}
|
|
10429
|
-
const
|
|
10430
|
-
|
|
10431
|
-
|
|
10432
|
-
|
|
10433
|
-
|
|
10434
|
-
|
|
10435
|
-
else {
|
|
10436
|
-
classType.shared.baseClasses.push(types_1.UnknownType.create());
|
|
10437
|
-
}
|
|
10438
|
-
});
|
|
10483
|
+
const baseClasses = getBaseClassesFromTypeCall(baseTupleType);
|
|
10484
|
+
if (!baseClasses) {
|
|
10485
|
+
return undefined;
|
|
10486
|
+
}
|
|
10487
|
+
const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 4194304 /* ClassTypeFlags.ValidTypeAliasClass */, ParseTreeUtils.getTypeSourceId(errorNode), metaclass, baseTupleType.shared.effectiveMetaclass);
|
|
10488
|
+
classType.shared.baseClasses.push(...baseClasses);
|
|
10439
10489
|
if (!(0, typeUtils_1.computeMroLinearization)(classType)) {
|
|
10440
10490
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.methodOrdering(), errorNode);
|
|
10441
10491
|
}
|
|
@@ -10663,7 +10713,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10663
10713
|
return undefined;
|
|
10664
10714
|
}
|
|
10665
10715
|
const dictConstraints = new constraintTracker_1.ConstraintTracker();
|
|
10666
|
-
if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictConstraints,
|
|
10716
|
+
if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictConstraints, getTypeVarScopesForNode(node), node.start)) {
|
|
10667
10717
|
return undefined;
|
|
10668
10718
|
}
|
|
10669
10719
|
const specializedDict = solveAndApplyConstraints(types_1.ClassType.cloneAsInstantiable(builtInDict), dictConstraints);
|
|
@@ -10728,7 +10778,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10728
10778
|
const keyTypes = keyTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, !hasExpectedType)));
|
|
10729
10779
|
const valueTypes = valueTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, !hasExpectedType)));
|
|
10730
10780
|
if (keyTypes.length > 0) {
|
|
10731
|
-
if (
|
|
10781
|
+
if (nodeInfo.getFileInfo(node).diagnosticRuleSet.strictDictionaryInference || hasExpectedType) {
|
|
10732
10782
|
keyType = (0, types_1.combineTypes)(keyTypes);
|
|
10733
10783
|
}
|
|
10734
10784
|
else {
|
|
@@ -10744,7 +10794,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10744
10794
|
// are the same type, we'll assume that all values in this dictionary should
|
|
10745
10795
|
// be the same.
|
|
10746
10796
|
if (valueTypes.length > 0) {
|
|
10747
|
-
if (
|
|
10797
|
+
if (nodeInfo.getFileInfo(node).diagnosticRuleSet.strictDictionaryInference || hasExpectedType) {
|
|
10748
10798
|
valueType = (0, types_1.combineTypes)(valueTypes);
|
|
10749
10799
|
}
|
|
10750
10800
|
else {
|
|
@@ -10804,7 +10854,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10804
10854
|
let effectiveValueType = expectedTypedDictEntries.knownItems.get(keyType.priv.literalValue)?.valueType ??
|
|
10805
10855
|
expectedTypedDictEntries.extraItems?.valueType;
|
|
10806
10856
|
if (effectiveValueType) {
|
|
10807
|
-
const liveTypeVarScopes =
|
|
10857
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(node);
|
|
10808
10858
|
effectiveValueType = (0, typeUtils_1.transformExpectedType)(effectiveValueType, liveTypeVarScopes, node.start);
|
|
10809
10859
|
}
|
|
10810
10860
|
entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
|
|
@@ -10813,7 +10863,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10813
10863
|
else {
|
|
10814
10864
|
let effectiveValueType = expectedValueType ?? (forceStrictInference ? types_1.NeverType.createNever() : undefined);
|
|
10815
10865
|
if (effectiveValueType) {
|
|
10816
|
-
const liveTypeVarScopes =
|
|
10866
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(node);
|
|
10817
10867
|
effectiveValueType = (0, typeUtils_1.transformExpectedType)(effectiveValueType, liveTypeVarScopes, node.start);
|
|
10818
10868
|
}
|
|
10819
10869
|
entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
|
|
@@ -11070,7 +11120,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11070
11120
|
return undefined;
|
|
11071
11121
|
}
|
|
11072
11122
|
const constraints = new constraintTracker_1.ConstraintTracker();
|
|
11073
|
-
if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(expectedClassType), inferenceContext.expectedType, constraints,
|
|
11123
|
+
if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(expectedClassType), inferenceContext.expectedType, constraints, getTypeVarScopesForNode(node), node.start)) {
|
|
11074
11124
|
return undefined;
|
|
11075
11125
|
}
|
|
11076
11126
|
const specializedListOrSet = solveAndApplyConstraints(expectedClassType, constraints);
|
|
@@ -11112,7 +11162,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11112
11162
|
entryTypes = entryTypes.map((t) => stripLiteralValue(t));
|
|
11113
11163
|
let inferredEntryType = hasExpectedType ? types_1.AnyType.create() : types_1.UnknownType.create();
|
|
11114
11164
|
if (entryTypes.length > 0) {
|
|
11115
|
-
const fileInfo =
|
|
11165
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
11116
11166
|
// If there was an expected type or we're using strict list inference,
|
|
11117
11167
|
// combine the types into a union.
|
|
11118
11168
|
if ((builtInClassName === 'list' && fileInfo.diagnosticRuleSet.strictListInference) ||
|
|
@@ -11205,7 +11255,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11205
11255
|
if (functionTypeInfo) {
|
|
11206
11256
|
let returnType = types_1.FunctionType.getEffectiveReturnType(functionTypeInfo.functionType);
|
|
11207
11257
|
if (returnType) {
|
|
11208
|
-
const liveScopeIds =
|
|
11258
|
+
const liveScopeIds = getTypeVarScopesForNode(node);
|
|
11209
11259
|
returnType = (0, typeUtils_1.makeTypeVarsBound)(returnType, liveScopeIds);
|
|
11210
11260
|
expectedYieldType = (0, typeUtils_1.getGeneratorYieldType)(returnType, !!enclosingFunction.d.isAsync);
|
|
11211
11261
|
const generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(returnType);
|
|
@@ -11287,13 +11337,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11287
11337
|
let expectedReturnType;
|
|
11288
11338
|
let expectedParamDetails;
|
|
11289
11339
|
if (expectedType) {
|
|
11290
|
-
const liveTypeVarScopes =
|
|
11340
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(node);
|
|
11291
11341
|
expectedType = (0, typeUtils_1.transformExpectedType)(expectedType, liveTypeVarScopes, node.start);
|
|
11292
11342
|
expectedParamDetails = (0, parameterUtils_1.getParamListDetails)(expectedType);
|
|
11293
11343
|
expectedReturnType = getEffectiveReturnType(expectedType);
|
|
11294
11344
|
}
|
|
11295
11345
|
let functionType = types_1.FunctionType.createInstance('', '', '', 131072 /* FunctionTypeFlags.PartiallyEvaluated */);
|
|
11296
|
-
functionType.shared.typeVarScopeId =
|
|
11346
|
+
functionType.shared.typeVarScopeId = getScopeIdForNode(node);
|
|
11297
11347
|
return (0, cancellationUtils_1.invalidateTypeCacheIfCanceled)(() => {
|
|
11298
11348
|
// Pre-cache the incomplete function type in case the evaluation of the
|
|
11299
11349
|
// lambda depends on itself.
|
|
@@ -11655,7 +11705,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11655
11705
|
let isValidTypeForm = true;
|
|
11656
11706
|
types_1.TypeBase.setSpecialForm(functionType, types_1.ClassType.cloneAsInstance(classType));
|
|
11657
11707
|
functionType.shared.declaredReturnType = types_1.UnknownType.create();
|
|
11658
|
-
functionType.shared.typeVarScopeId =
|
|
11708
|
+
functionType.shared.typeVarScopeId = getScopeIdForNode(errorNode);
|
|
11659
11709
|
if (typeArgs && typeArgs.length > 0) {
|
|
11660
11710
|
functionType.priv.isCallableWithTypeArgs = true;
|
|
11661
11711
|
if (typeArgs[0].typeList) {
|
|
@@ -12034,7 +12084,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12034
12084
|
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(errorNode);
|
|
12035
12085
|
if (enclosingFunction) {
|
|
12036
12086
|
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, enclosingFunction,
|
|
12037
|
-
/* isInClass */ true);
|
|
12087
|
+
/* isInClass */ true, nodeInfo);
|
|
12038
12088
|
const isInnerFunction = !!ParseTreeUtils.getEnclosingFunction(enclosingFunction);
|
|
12039
12089
|
if (!isInnerFunction) {
|
|
12040
12090
|
// Check for static methods.
|
|
@@ -12388,7 +12438,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12388
12438
|
}
|
|
12389
12439
|
// Unpacks the index expression for a "Union[X, Y, Z]" type annotation.
|
|
12390
12440
|
function createUnionType(classType, errorNode, typeArgs, flags) {
|
|
12391
|
-
const fileInfo =
|
|
12441
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
12392
12442
|
const types = [];
|
|
12393
12443
|
let allowSingleTypeArg = false;
|
|
12394
12444
|
let isValidTypeForm = true;
|
|
@@ -12571,7 +12621,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12571
12621
|
return typeAlias;
|
|
12572
12622
|
}
|
|
12573
12623
|
function createSpecialBuiltInClass(node, assignedName, aliasMapEntry) {
|
|
12574
|
-
const fileInfo =
|
|
12624
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
12575
12625
|
let specialClassType = types_1.ClassType.createInstantiable(assignedName, ParseTreeUtils.getClassFullName(node, fileInfo.moduleName, assignedName), fileInfo.moduleName, fileInfo.fileUri, 1 /* ClassTypeFlags.BuiltIn */ | 2 /* ClassTypeFlags.SpecialBuiltIn */,
|
|
12576
12626
|
/* typeSourceId */ 0,
|
|
12577
12627
|
/* declaredMetaclass */ undefined,
|
|
@@ -12586,12 +12636,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12586
12636
|
// specified in the alias map entry.
|
|
12587
12637
|
if (aliasMapEntry.typeParamVariance !== undefined) {
|
|
12588
12638
|
let typeParam = types_1.TypeVarType.createInstance('T');
|
|
12589
|
-
typeParam = types_1.TypeVarType.cloneForScopeId(typeParam,
|
|
12639
|
+
typeParam = types_1.TypeVarType.cloneForScopeId(typeParam, getScopeIdForNode(node), assignedName, 0 /* TypeVarScopeType.Class */);
|
|
12590
12640
|
typeParam.shared.declaredVariance = aliasMapEntry.typeParamVariance;
|
|
12591
12641
|
specialClassType.shared.typeParams.push(typeParam);
|
|
12592
12642
|
}
|
|
12593
|
-
const specialBuiltInClassDeclaration = (
|
|
12594
|
-
(node.parent ?
|
|
12643
|
+
const specialBuiltInClassDeclaration = (nodeInfo.getDeclaration(node) ??
|
|
12644
|
+
(node.parent ? nodeInfo.getDeclaration(node.parent) : undefined));
|
|
12595
12645
|
specialClassType.shared.declaration = specialBuiltInClassDeclaration;
|
|
12596
12646
|
if (fileInfo.isTypingExtensionsStubFile) {
|
|
12597
12647
|
specialClassType.shared.flags |= 4096 /* ClassTypeFlags.TypingExtensionClass */;
|
|
@@ -12782,7 +12832,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12782
12832
|
}
|
|
12783
12833
|
}
|
|
12784
12834
|
function evaluateTypesForAssignmentStatement(node) {
|
|
12785
|
-
const fileInfo =
|
|
12835
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
12786
12836
|
// If the entire statement has already been evaluated, don't
|
|
12787
12837
|
// re-evaluate it.
|
|
12788
12838
|
if (isTypeCached(node)) {
|
|
@@ -12874,7 +12924,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12874
12924
|
declaredType = getDeclaredTypeForExpression(node.d.leftExpr, { method: 'set' });
|
|
12875
12925
|
}
|
|
12876
12926
|
if (declaredType) {
|
|
12877
|
-
const liveTypeVarScopes =
|
|
12927
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(node);
|
|
12878
12928
|
declaredType = (0, typeUtils_1.makeTypeVarsBound)(declaredType, liveTypeVarScopes);
|
|
12879
12929
|
}
|
|
12880
12930
|
const srcTypeResult = getTypeOfExpression(node.d.rightExpr, flags, (0, typeUtils_1.makeInferenceContext)(declaredType));
|
|
@@ -12928,8 +12978,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12928
12978
|
function synthesizeTypeAliasPlaceholder(nameNode, isTypeAliasType = false) {
|
|
12929
12979
|
const placeholder = types_1.TypeVarType.createInstantiable(`__type_alias_${nameNode.d.value}`);
|
|
12930
12980
|
placeholder.shared.isSynthesized = true;
|
|
12931
|
-
const typeVarScopeId =
|
|
12932
|
-
const fileInfo =
|
|
12981
|
+
const typeVarScopeId = getScopeIdForNode(nameNode);
|
|
12982
|
+
const fileInfo = nodeInfo.getFileInfo(nameNode);
|
|
12933
12983
|
placeholder.shared.recursiveAlias = {
|
|
12934
12984
|
name: nameNode.d.value,
|
|
12935
12985
|
fullName: ParseTreeUtils.getClassFullName(nameNode, fileInfo.moduleName, nameNode.d.value),
|
|
@@ -12968,9 +13018,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12968
13018
|
// Write the type to the type cache to support recursive type alias definitions.
|
|
12969
13019
|
writeTypeCache(nameNode, { type: typeAliasTypeVar }, /* flags */ undefined);
|
|
12970
13020
|
// Set a partial type to handle recursive (self-referential) type aliases.
|
|
12971
|
-
const scope =
|
|
13021
|
+
const scope = getScopeForNode(declNode);
|
|
12972
13022
|
const typeAliasSymbol = scope?.lookUpSymbolRecursive(nameNode.d.value);
|
|
12973
|
-
const typeAliasDecl =
|
|
13023
|
+
const typeAliasDecl = nodeInfo.getDeclaration(declNode);
|
|
12974
13024
|
if (typeAliasDecl && typeAliasSymbol) {
|
|
12975
13025
|
setSymbolResolutionPartialType(typeAliasSymbol.symbol, typeAliasDecl, typeAliasTypeVar);
|
|
12976
13026
|
}
|
|
@@ -13038,7 +13088,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13038
13088
|
const className = `<subclass of ${printType((0, typeUtils_1.convertToInstance)(type1), {
|
|
13039
13089
|
omitTypeArgsIfUnknown: true,
|
|
13040
13090
|
})} and ${printType((0, typeUtils_1.convertToInstance)(type2), { omitTypeArgsIfUnknown: true })}>`;
|
|
13041
|
-
const fileInfo =
|
|
13091
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
13042
13092
|
// The effective metaclass of the intersection is the narrower of the two metaclasses.
|
|
13043
13093
|
let effectiveMetaclass = type1.shared.effectiveMetaclass;
|
|
13044
13094
|
if (type2.shared.effectiveMetaclass) {
|
|
@@ -13073,8 +13123,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13073
13123
|
};
|
|
13074
13124
|
}
|
|
13075
13125
|
// The type wasn't cached, so we need to create a new one.
|
|
13076
|
-
const scope =
|
|
13077
|
-
const fileInfo =
|
|
13126
|
+
const scope = getScopeForNode(node);
|
|
13127
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
13078
13128
|
let classFlags = 0 /* ClassTypeFlags.None */;
|
|
13079
13129
|
if (scope?.type === 5 /* ScopeType.Builtin */ ||
|
|
13080
13130
|
fileInfo.isTypingStubFile ||
|
|
@@ -13098,7 +13148,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13098
13148
|
const classType = types_1.ClassType.createInstantiable(node.d.name.d.value, ParseTreeUtils.getClassFullName(node, fileInfo.moduleName, node.d.name.d.value), fileInfo.moduleName, fileInfo.fileUri, classFlags, ParseTreeUtils.getTypeSourceId(node),
|
|
13099
13149
|
/* declaredMetaclass */ undefined,
|
|
13100
13150
|
/* effectiveMetaclass */ undefined, ParseTreeUtils.getDocString(node.d.suite.d.statements));
|
|
13101
|
-
classType.shared.typeVarScopeId =
|
|
13151
|
+
classType.shared.typeVarScopeId = getScopeIdForNode(node);
|
|
13102
13152
|
// Is this a special type that supports type promotions according to PEP 484?
|
|
13103
13153
|
if (typePromotions.has(classType.shared.fullName)) {
|
|
13104
13154
|
classType.priv.includePromotions = true;
|
|
@@ -13108,7 +13158,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13108
13158
|
// to allow these to be resolved.
|
|
13109
13159
|
const classSymbol = scope?.lookUpSymbol(node.d.name.d.value);
|
|
13110
13160
|
let classDecl;
|
|
13111
|
-
const decl =
|
|
13161
|
+
const decl = nodeInfo.getDeclaration(node);
|
|
13112
13162
|
if (decl) {
|
|
13113
13163
|
classDecl = decl;
|
|
13114
13164
|
}
|
|
@@ -13451,7 +13501,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13451
13501
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.methodOrdering(), node.d.name);
|
|
13452
13502
|
}
|
|
13453
13503
|
// The scope for this class becomes the "fields" for the corresponding type.
|
|
13454
|
-
const innerScope =
|
|
13504
|
+
const innerScope = getScopeForNode(node.d.suite);
|
|
13455
13505
|
classType.shared.fields = innerScope?.symbolTable
|
|
13456
13506
|
? new Map(innerScope.symbolTable)
|
|
13457
13507
|
: new Map();
|
|
@@ -13496,9 +13546,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13496
13546
|
classType.shared.typeParams = genericParams.map((param) => {
|
|
13497
13547
|
const typeVar = types_1.TypeVarType.createInstance(getPseudoGenericTypeVarName(param.d.name.d.value));
|
|
13498
13548
|
typeVar.shared.isSynthesized = true;
|
|
13499
|
-
typeVar.priv.scopeId =
|
|
13549
|
+
typeVar.priv.scopeId = getScopeIdForNode(initDeclNode);
|
|
13500
13550
|
typeVar.shared.boundType = types_1.UnknownType.create();
|
|
13501
|
-
return types_1.TypeVarType.cloneForScopeId(typeVar,
|
|
13551
|
+
return types_1.TypeVarType.cloneForScopeId(typeVar, getScopeIdForNode(node), node.d.name.d.value, 0 /* TypeVarScopeType.Class */);
|
|
13502
13552
|
});
|
|
13503
13553
|
}
|
|
13504
13554
|
}
|
|
@@ -13542,7 +13592,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13542
13592
|
}
|
|
13543
13593
|
const effectiveMetaclass = computeEffectiveMetaclass(classType, node.d.name);
|
|
13544
13594
|
const enumMemberSetMayBeDynamicallyModified = types_1.ClassType.isEnumClass(classType) &&
|
|
13545
|
-
(
|
|
13595
|
+
(nodeInfo.getScope(node)?.hasPotentiallyDynamicSymbolTable ||
|
|
13546
13596
|
classType.shared.mro.some((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isEnumMemberSetMayBeDynamicallyModified(mroClass)));
|
|
13547
13597
|
if (enumMemberSetMayBeDynamicallyModified) {
|
|
13548
13598
|
classType.shared.flags |= 67108864 /* ClassTypeFlags.EnumMemberSetMayBeDynamicallyModified */;
|
|
@@ -13565,7 +13615,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13565
13615
|
let foundUnknown = false;
|
|
13566
13616
|
for (let i = node.d.decorators.length - 1; i >= 0; i--) {
|
|
13567
13617
|
const decorator = node.d.decorators[i];
|
|
13568
|
-
const newDecoratedType = useSignatureTracker(node.parent ?? node, () => (0, decorators_1.applyClassDecorator)(evaluatorInterface, decoratedType, classType, decorator));
|
|
13618
|
+
const newDecoratedType = useSignatureTracker(node.parent ?? node, () => (0, decorators_1.applyClassDecorator)(evaluatorInterface, decoratedType, classType, decorator, nodeInfo));
|
|
13569
13619
|
const unknownOrAny = (0, typeUtils_1.containsAnyOrUnknown)(newDecoratedType, /* recurse */ false);
|
|
13570
13620
|
if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
|
|
13571
13621
|
// Report this error only on the first unknown type.
|
|
@@ -13596,7 +13646,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13596
13646
|
}
|
|
13597
13647
|
}
|
|
13598
13648
|
if (dataClassBehaviors) {
|
|
13599
|
-
(0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, node.d.name, classType, initSubclassArgs, dataClassBehaviors);
|
|
13649
|
+
(0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, node.d.name, classType, initSubclassArgs, dataClassBehaviors, nodeInfo);
|
|
13600
13650
|
}
|
|
13601
13651
|
// Run any deferred class completions that depend on this class.
|
|
13602
13652
|
runDeferredClassCompletions(classType);
|
|
@@ -13620,7 +13670,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13620
13670
|
if (foundInvalidBaseClass) {
|
|
13621
13671
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictBaseClass() + diag.getString(), node.d.name);
|
|
13622
13672
|
}
|
|
13623
|
-
(0, typedDicts_1.synthesizeTypedDictClassMethods)(evaluatorInterface, node, classType);
|
|
13673
|
+
(0, typedDicts_1.synthesizeTypedDictClassMethods)(evaluatorInterface, node, classType, nodeInfo);
|
|
13624
13674
|
}
|
|
13625
13675
|
// Synthesize dataclass methods.
|
|
13626
13676
|
if (types_1.ClassType.isDataClass(classType) || isNamedTupleSubclass) {
|
|
@@ -13641,7 +13691,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13641
13691
|
if (hashSymbol && hashSymbol.isClassMember() && !hashSymbol.getSynthesizedType()) {
|
|
13642
13692
|
skipSynthesizeHash = true;
|
|
13643
13693
|
}
|
|
13644
|
-
const synthesizeMethods = () => (0, dataClasses_1.synthesizeDataClassMethods)(evaluatorInterface, node, classType, isNamedTupleSubclass, skipSynthesizedInit, hasExistingInitMethod, skipSynthesizeHash);
|
|
13694
|
+
const synthesizeMethods = () => (0, dataClasses_1.synthesizeDataClassMethods)(evaluatorInterface, node, classType, isNamedTupleSubclass, skipSynthesizedInit, hasExistingInitMethod, skipSynthesizeHash, nodeInfo);
|
|
13645
13695
|
// If this is a NamedTuple subclass, immediately synthesize dataclass methods
|
|
13646
13696
|
// because we also need to update the MRO classes in this case. For regular
|
|
13647
13697
|
// dataclasses, we'll defer the method synthesis to avoid circular dependencies.
|
|
@@ -13805,7 +13855,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13805
13855
|
}
|
|
13806
13856
|
function evaluateTypeParamList(node) {
|
|
13807
13857
|
const paramTypes = [];
|
|
13808
|
-
const typeParamScope =
|
|
13858
|
+
const typeParamScope = nodeInfo.getScope(node);
|
|
13809
13859
|
node.d.params.forEach((param) => {
|
|
13810
13860
|
const paramSymbol = typeParamScope?.symbolTable.get(param.d.name.d.value);
|
|
13811
13861
|
if (!paramSymbol) {
|
|
@@ -14091,7 +14141,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14091
14141
|
const decorator = node.d.decorators[i];
|
|
14092
14142
|
const newDecoratedType = useSignatureTracker(node.parent ?? node, () => {
|
|
14093
14143
|
(0, debug_1.assert)(decoratedType !== undefined);
|
|
14094
|
-
return (0, decorators_1.applyFunctionDecorator)(evaluatorInterface, decoratedType, functionType, decorator, node);
|
|
14144
|
+
return (0, decorators_1.applyFunctionDecorator)(evaluatorInterface, decoratedType, functionType, decorator, node, nodeInfo);
|
|
14095
14145
|
});
|
|
14096
14146
|
const unknownOrAny = (0, typeUtils_1.containsAnyOrUnknown)(newDecoratedType, /* recurse */ false);
|
|
14097
14147
|
if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
|
|
@@ -14116,7 +14166,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14116
14166
|
});
|
|
14117
14167
|
}
|
|
14118
14168
|
}
|
|
14119
|
-
decoratedType = (0, decorators_1.addOverloadsToFunctionType)(evaluatorInterface, node, decoratedType);
|
|
14169
|
+
decoratedType = (0, decorators_1.addOverloadsToFunctionType)(evaluatorInterface, node, decoratedType, nodeInfo);
|
|
14120
14170
|
writeTypeCache(node, { type: decoratedType }, 0 /* EvalFlags.None */);
|
|
14121
14171
|
// Now that the decorator has been applied, we can clear the
|
|
14122
14172
|
// "partially evaluated" flag.
|
|
@@ -14126,14 +14176,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14126
14176
|
// Evaluates the type of a "def" statement without applying an async
|
|
14127
14177
|
// modifier or any decorators.
|
|
14128
14178
|
function getTypeOfFunctionPredecorated(node) {
|
|
14129
|
-
const fileInfo =
|
|
14179
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
14130
14180
|
// Is this type already cached?
|
|
14131
14181
|
const cachedFunctionType = readTypeCache(node.d.name, 0 /* EvalFlags.None */);
|
|
14132
14182
|
if (cachedFunctionType && (0, types_1.isFunction)(cachedFunctionType)) {
|
|
14133
14183
|
return cachedFunctionType;
|
|
14134
14184
|
}
|
|
14135
14185
|
let functionDecl;
|
|
14136
|
-
const decl =
|
|
14186
|
+
const decl = nodeInfo.getDeclaration(node);
|
|
14137
14187
|
if (decl) {
|
|
14138
14188
|
functionDecl = decl;
|
|
14139
14189
|
}
|
|
@@ -14144,7 +14194,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14144
14194
|
if (containingClassNode) {
|
|
14145
14195
|
containingClassType = getTypeOfClass(containingClassNode)?.classType;
|
|
14146
14196
|
}
|
|
14147
|
-
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, node, !!containingClassNode);
|
|
14197
|
+
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, node, !!containingClassNode, nodeInfo);
|
|
14148
14198
|
let functionFlags = functionInfo.flags;
|
|
14149
14199
|
if (functionDecl?.isGenerator) {
|
|
14150
14200
|
functionFlags |= 16 /* FunctionTypeFlags.Generator */;
|
|
@@ -14159,12 +14209,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14159
14209
|
functionFlags |= 512 /* FunctionTypeFlags.Async */;
|
|
14160
14210
|
}
|
|
14161
14211
|
const functionType = types_1.FunctionType.createInstance(node.d.name.d.value, getFunctionFullName(node, fileInfo.moduleName, node.d.name.d.value), fileInfo.moduleName, functionFlags | 131072 /* FunctionTypeFlags.PartiallyEvaluated */, ParseTreeUtils.getDocString(node.d.suite.d.statements));
|
|
14162
|
-
functionType.shared.typeVarScopeId =
|
|
14212
|
+
functionType.shared.typeVarScopeId = getScopeIdForNode(node);
|
|
14163
14213
|
functionType.shared.deprecatedMessage = functionInfo.deprecationMessage;
|
|
14164
14214
|
functionType.shared.methodClass = containingClassType;
|
|
14165
14215
|
if (node.d.name.d.value === '__init__' || node.d.name.d.value === '__new__') {
|
|
14166
14216
|
if (containingClassNode) {
|
|
14167
|
-
functionType.priv.constructorTypeVarScopeId =
|
|
14217
|
+
functionType.priv.constructorTypeVarScopeId = getScopeIdForNode(containingClassNode);
|
|
14168
14218
|
}
|
|
14169
14219
|
}
|
|
14170
14220
|
if (fileInfo.isBuiltInStubFile || fileInfo.isTypingStubFile || fileInfo.isTypingExtensionsStubFile) {
|
|
@@ -14173,7 +14223,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14173
14223
|
}
|
|
14174
14224
|
functionType.shared.declaration = functionDecl;
|
|
14175
14225
|
// Allow recursion by caching and registering the partially-constructed function type.
|
|
14176
|
-
const scope =
|
|
14226
|
+
const scope = getScopeForNode(node);
|
|
14177
14227
|
const functionSymbol = scope?.lookUpSymbolRecursive(node.d.name.d.value);
|
|
14178
14228
|
if (functionDecl && functionSymbol) {
|
|
14179
14229
|
setSymbolResolutionPartialType(functionSymbol.symbol, functionDecl, functionType);
|
|
@@ -14372,7 +14422,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14372
14422
|
types_1.FunctionType.addPositionOnlyParamSeparator(functionType);
|
|
14373
14423
|
}
|
|
14374
14424
|
// Update the types for the nodes associated with the parameters.
|
|
14375
|
-
const scopeIds =
|
|
14425
|
+
const scopeIds = getTypeVarScopesForNode(node);
|
|
14376
14426
|
paramTypes.forEach((paramType, index) => {
|
|
14377
14427
|
const paramNameNode = node.d.params[index].d.name;
|
|
14378
14428
|
if (paramNameNode) {
|
|
@@ -14456,7 +14506,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14456
14506
|
const symbolWithScope = lookUpSymbolRecursive(param.d.name, param.d.name.d.value,
|
|
14457
14507
|
/* honorCodeFlow */ false);
|
|
14458
14508
|
if (symbolWithScope) {
|
|
14459
|
-
setSymbolAccessed(
|
|
14509
|
+
setSymbolAccessed(nodeInfo.getFileInfo(param), symbolWithScope.symbol, param.d.name);
|
|
14460
14510
|
}
|
|
14461
14511
|
}
|
|
14462
14512
|
}
|
|
@@ -14468,7 +14518,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14468
14518
|
if (param.d.defaultValue?.nodeType === 14 /* ParseNodeType.Constant */ &&
|
|
14469
14519
|
param.d.defaultValue.d.constType === 27 /* KeywordType.None */ &&
|
|
14470
14520
|
!(0, typeUtils_1.isOptionalType)(type) &&
|
|
14471
|
-
!
|
|
14521
|
+
!nodeInfo.getFileInfo(param).diagnosticRuleSet.strictParameterNoneValue) {
|
|
14472
14522
|
return (0, types_1.combineTypes)([type, getNoneType()]);
|
|
14473
14523
|
}
|
|
14474
14524
|
return type;
|
|
@@ -14506,7 +14556,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14506
14556
|
if ((0, typeUtils_1.requiresSpecialization)(inferredParamType) && (0, types_1.isClass)(baseClassMemberInfo.classType)) {
|
|
14507
14557
|
const scopeIds = (0, typeUtils_1.getTypeVarScopeIds)(baseClassMemberInfo.classType);
|
|
14508
14558
|
const solution = (0, typeUtils_1.buildSolutionFromSpecializedClass)(baseClassMemberInfo.classType);
|
|
14509
|
-
scopeIds.push(
|
|
14559
|
+
scopeIds.push(getScopeIdForNode(baseClassMethodNode));
|
|
14510
14560
|
// Replace any unsolved TypeVars with Unknown (including all function-scoped TypeVars).
|
|
14511
14561
|
inferredParamType = (0, typeUtils_1.applySolvedTypeVars)(inferredParamType, solution, {
|
|
14512
14562
|
replaceUnsolved: {
|
|
@@ -14515,7 +14565,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14515
14565
|
},
|
|
14516
14566
|
});
|
|
14517
14567
|
}
|
|
14518
|
-
const fileInfo =
|
|
14568
|
+
const fileInfo = nodeInfo.getFileInfo(functionNode);
|
|
14519
14569
|
if (fileInfo.isInPyTypedPackage && !fileInfo.isStubFile) {
|
|
14520
14570
|
inferredParamType = types_1.TypeBase.cloneForAmbiguousType(inferredParamType);
|
|
14521
14571
|
}
|
|
@@ -14567,7 +14617,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14567
14617
|
}
|
|
14568
14618
|
}
|
|
14569
14619
|
if (inferredParamType) {
|
|
14570
|
-
const fileInfo =
|
|
14620
|
+
const fileInfo = nodeInfo.getFileInfo(paramValueExpr);
|
|
14571
14621
|
if (fileInfo.isInPyTypedPackage && !fileInfo.isStubFile) {
|
|
14572
14622
|
inferredParamType = types_1.TypeBase.cloneForAmbiguousType(inferredParamType);
|
|
14573
14623
|
}
|
|
@@ -14698,14 +14748,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14698
14748
|
functionRecursionMap.set(node.id, recursionEntry);
|
|
14699
14749
|
try {
|
|
14700
14750
|
let functionDecl;
|
|
14701
|
-
const decl =
|
|
14751
|
+
const decl = nodeInfo.getDeclaration(node);
|
|
14702
14752
|
if (decl) {
|
|
14703
14753
|
functionDecl = decl;
|
|
14704
14754
|
}
|
|
14705
14755
|
const functionNeverReturns = !isAfterNodeReachable(node);
|
|
14706
14756
|
const implicitlyReturnsNone = isAfterNodeReachable(node.d.suite);
|
|
14707
14757
|
// Infer the return type based on all of the return statements in the function's body.
|
|
14708
|
-
if (
|
|
14758
|
+
if (nodeInfo.getFileInfo(node).isStubFile) {
|
|
14709
14759
|
// If a return type annotation is missing in a stub file, assume
|
|
14710
14760
|
// it's an "unknown" type. In normal source files, we can infer the
|
|
14711
14761
|
// type from the implementation.
|
|
@@ -14850,7 +14900,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14850
14900
|
// cases, we can get very deep stacks when inferring return types
|
|
14851
14901
|
// within untyped code.
|
|
14852
14902
|
if (err?.message === 'Maximum call stack size exceeded') {
|
|
14853
|
-
const fileInfo =
|
|
14903
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
14854
14904
|
console.error(`Overflowed stack when inferring return type for function: ${node.d.name.d.value} in file ${fileInfo.fileUri.toUserVisibleString()}`);
|
|
14855
14905
|
return;
|
|
14856
14906
|
}
|
|
@@ -15081,7 +15131,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15081
15131
|
return;
|
|
15082
15132
|
}
|
|
15083
15133
|
const aliasNode = node.d.alias || node.d.name;
|
|
15084
|
-
const fileInfo =
|
|
15134
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
15085
15135
|
// If this is a redundant form of an import, assume it is an intentional
|
|
15086
15136
|
// export and mark the symbol as accessed.
|
|
15087
15137
|
if (node.d.alias?.d.value === node.d.name.d.value) {
|
|
@@ -15103,7 +15153,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15103
15153
|
const parentNode = node.parent;
|
|
15104
15154
|
(0, debug_1.assert)(parentNode && parentNode.nodeType === 25 /* ParseNodeType.ImportFrom */);
|
|
15105
15155
|
(0, debug_1.assert)(!parentNode.d.isWildcardImport);
|
|
15106
|
-
const importInfo =
|
|
15156
|
+
const importInfo = nodeInfo.getImportInfo(parentNode.d.module);
|
|
15107
15157
|
if (importInfo && importInfo.isImportFound && !importInfo.isNativeLib) {
|
|
15108
15158
|
const resolvedPath = importInfo.resolvedUris[importInfo.resolvedUris.length - 1];
|
|
15109
15159
|
const importLookupInfo = importLookup(resolvedPath);
|
|
@@ -15151,7 +15201,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15151
15201
|
for (const caseStatement of node.d.cases) {
|
|
15152
15202
|
if (!caseStatement.d.guardExpr) {
|
|
15153
15203
|
subjectType = (0, patternMatching_1.narrowTypeBasedOnPattern)(evaluatorInterface, subjectType, caseStatement.d.pattern,
|
|
15154
|
-
/* isPositiveTest */ false);
|
|
15204
|
+
/* isPositiveTest */ false, nodeInfo);
|
|
15155
15205
|
}
|
|
15156
15206
|
}
|
|
15157
15207
|
writeTypeCache(node, { type: subjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* EvalFlags.None */);
|
|
@@ -15164,7 +15214,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15164
15214
|
(0, debug_1.fail)('Expected parent of case statement to be match statement');
|
|
15165
15215
|
return;
|
|
15166
15216
|
}
|
|
15167
|
-
const fileInfo =
|
|
15217
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
15168
15218
|
const subjectTypeResult = getTypeOfExpression(node.parent.d.expr);
|
|
15169
15219
|
let subjectType = subjectTypeResult.type;
|
|
15170
15220
|
// Apply negative narrowing for each of the cases prior to the current one
|
|
@@ -15173,17 +15223,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15173
15223
|
if (caseStatement === node) {
|
|
15174
15224
|
if (fileInfo.diagnosticRuleSet.reportUnnecessaryComparison !== 'none') {
|
|
15175
15225
|
if (!subjectTypeResult.isIncomplete) {
|
|
15176
|
-
(0, patternMatching_1.checkForUnusedPattern)(evaluatorInterface, node.d.pattern, subjectType);
|
|
15226
|
+
(0, patternMatching_1.checkForUnusedPattern)(evaluatorInterface, node.d.pattern, subjectType, nodeInfo);
|
|
15177
15227
|
}
|
|
15178
15228
|
}
|
|
15179
15229
|
break;
|
|
15180
15230
|
}
|
|
15181
15231
|
if (!caseStatement.d.guardExpr) {
|
|
15182
15232
|
subjectType = (0, patternMatching_1.narrowTypeBasedOnPattern)(evaluatorInterface, subjectType, caseStatement.d.pattern,
|
|
15183
|
-
/* isPositiveTest */ false);
|
|
15233
|
+
/* isPositiveTest */ false, nodeInfo);
|
|
15184
15234
|
}
|
|
15185
15235
|
}
|
|
15186
|
-
const narrowedSubjectType = (0, patternMatching_1.assignTypeToPatternTargets)(evaluatorInterface, subjectType, !!subjectTypeResult.isIncomplete, node.d.pattern);
|
|
15236
|
+
const narrowedSubjectType = (0, patternMatching_1.assignTypeToPatternTargets)(evaluatorInterface, subjectType, !!subjectTypeResult.isIncomplete, node.d.pattern, nodeInfo);
|
|
15187
15237
|
writeTypeCache(node, { type: narrowedSubjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* EvalFlags.None */);
|
|
15188
15238
|
}
|
|
15189
15239
|
function evaluateTypesForImportFrom(node) {
|
|
@@ -15193,7 +15243,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15193
15243
|
if (node.d.isWildcardImport) {
|
|
15194
15244
|
// Write back a dummy type so we don't evaluate this node again.
|
|
15195
15245
|
writeTypeCache(node, { type: types_1.AnyType.create() }, 0 /* EvalFlags.None */);
|
|
15196
|
-
const flowNode =
|
|
15246
|
+
const flowNode = nodeInfo.getFlowNode(node);
|
|
15197
15247
|
if (flowNode && (flowNode.flags & codeFlowTypes_1.FlowFlags.WildcardImport) !== 0) {
|
|
15198
15248
|
const wildcardFlowNode = flowNode;
|
|
15199
15249
|
wildcardFlowNode.names.forEach((name) => {
|
|
@@ -15278,7 +15328,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15278
15328
|
return undefined;
|
|
15279
15329
|
}
|
|
15280
15330
|
(0, debug_1.assert)(aliasDecl.type === 8 /* DeclarationType.Alias */);
|
|
15281
|
-
const fileInfo =
|
|
15331
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
15282
15332
|
// Try to resolve the alias while honoring external visibility.
|
|
15283
15333
|
const resolvedAliasInfo = resolveAliasDeclarationWithInfo(aliasDecl, /* resolveLocalNames */ true, {
|
|
15284
15334
|
allowExternallyHiddenAccess: fileInfo.isStubFile,
|
|
@@ -15561,7 +15611,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15561
15611
|
? getDeclaredReturnType(enclosingFunctionNode)
|
|
15562
15612
|
: undefined;
|
|
15563
15613
|
if (declaredReturnType) {
|
|
15564
|
-
const liveScopeIds =
|
|
15614
|
+
const liveScopeIds = getTypeVarScopesForNode(node);
|
|
15565
15615
|
declaredReturnType = (0, typeUtils_1.makeTypeVarsBound)(declaredReturnType, liveScopeIds);
|
|
15566
15616
|
}
|
|
15567
15617
|
getTypeOfExpression(parent.d.expr, 0 /* EvalFlags.None */, (0, typeUtils_1.makeInferenceContext)(declaredReturnType));
|
|
@@ -15609,7 +15659,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15609
15659
|
if (typeAnnotation) {
|
|
15610
15660
|
const param = functionNode.d.params[paramIndex];
|
|
15611
15661
|
let annotatedType = getTypeOfParamAnnotation(typeAnnotation, functionNode.d.params[paramIndex].d.category);
|
|
15612
|
-
const liveTypeVarScopes =
|
|
15662
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(param);
|
|
15613
15663
|
annotatedType = (0, typeUtils_1.makeTypeVarsBound)(annotatedType, liveTypeVarScopes);
|
|
15614
15664
|
const adjType = transformVariadicParamType(node, node.d.category, adjustParamAnnotatedType(param, annotatedType));
|
|
15615
15665
|
writeTypeCache(node.d.name, { type: adjType }, 0 /* EvalFlags.None */);
|
|
@@ -15631,9 +15681,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15631
15681
|
// infer the type of the parameter from a method of the same name in
|
|
15632
15682
|
// a parent class if it has an annotated type.
|
|
15633
15683
|
const functionFlags = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, functionNode,
|
|
15634
|
-
/* isInClass */ true).flags;
|
|
15684
|
+
/* isInClass */ true, nodeInfo).flags;
|
|
15635
15685
|
let inferredParamType = inferParamType(functionNode, functionFlags, paramIndex, classInfo?.classType) ?? types_1.UnknownType.create();
|
|
15636
|
-
const liveTypeVarScopes =
|
|
15686
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(node);
|
|
15637
15687
|
inferredParamType = (0, typeUtils_1.makeTypeVarsBound)(inferredParamType, liveTypeVarScopes);
|
|
15638
15688
|
writeTypeCache(node.d.name, { type: transformVariadicParamType(node, node.d.category, inferredParamType) }, 0 /* EvalFlags.None */);
|
|
15639
15689
|
}
|
|
@@ -15809,8 +15859,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15809
15859
|
function getFlowTypeOfReference(reference, startNode, options) {
|
|
15810
15860
|
// See if this execution scope requires code flow for this reference expression.
|
|
15811
15861
|
const referenceKey = (0, codeFlowTypes_1.createKeyForReference)(reference);
|
|
15812
|
-
const executionNode = ParseTreeUtils.getExecutionScopeNode(startNode?.parent ?? reference);
|
|
15813
|
-
const codeFlowExpressions =
|
|
15862
|
+
const executionNode = ParseTreeUtils.getExecutionScopeNode(startNode?.parent ?? reference, nodeInfo);
|
|
15863
|
+
const codeFlowExpressions = nodeInfo.getCodeFlowExpressions(executionNode);
|
|
15814
15864
|
if (!codeFlowExpressions ||
|
|
15815
15865
|
(!codeFlowExpressions.has(referenceKey) && !codeFlowExpressions.has(codeFlowTypes_1.wildcardImportReferenceKey))) {
|
|
15816
15866
|
return codeFlowEngine_1.FlowNodeTypeResult.create(/* type */ undefined, /* isIncomplete */ false);
|
|
@@ -15834,7 +15884,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15834
15884
|
else {
|
|
15835
15885
|
analyzer = getCodeFlowAnalyzerForNode(executionNode, options?.typeAtStart);
|
|
15836
15886
|
}
|
|
15837
|
-
const flowNode =
|
|
15887
|
+
const flowNode = nodeInfo.getFlowNode(startNode ?? reference);
|
|
15838
15888
|
if (flowNode === undefined) {
|
|
15839
15889
|
return codeFlowEngine_1.FlowNodeTypeResult.create(/* type */ undefined, /* isIncomplete */ false);
|
|
15840
15890
|
}
|
|
@@ -15901,8 +15951,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15901
15951
|
if ((flags &
|
|
15902
15952
|
(67108864 /* EvalFlags.NoNonTypeSpecialForms */ | 256 /* EvalFlags.TypeExpression */ | 1073741824 /* EvalFlags.TypeFormArg */)) !==
|
|
15903
15953
|
0) {
|
|
15904
|
-
const isInlinedTypedDict =
|
|
15905
|
-
!!typeArgs;
|
|
15954
|
+
const isInlinedTypedDict = nodeInfo.getFileInfo(errorNode).diagnosticRuleSet.enableExperimentalFeatures && !!typeArgs;
|
|
15906
15955
|
if (!isInlinedTypedDict) {
|
|
15907
15956
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typedDictNotAllowed(), errorNode);
|
|
15908
15957
|
}
|
|
@@ -15974,10 +16023,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15974
16023
|
}
|
|
15975
16024
|
}
|
|
15976
16025
|
}
|
|
15977
|
-
const fileInfo =
|
|
16026
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
15978
16027
|
if (fileInfo.isStubFile ||
|
|
15979
16028
|
pythonVersion_1.PythonVersion.isGreaterOrEqualTo(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_9) ||
|
|
15980
|
-
(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(
|
|
16029
|
+
(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(nodeInfo.getFileInfo(errorNode)) ||
|
|
15981
16030
|
(flags & 4 /* EvalFlags.ForwardRefs */) !== 0) {
|
|
15982
16031
|
// Handle "type" specially, since it needs to act like "Type"
|
|
15983
16032
|
// in Python 3.9 and newer.
|
|
@@ -16294,7 +16343,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16294
16343
|
if (options?.enforceClassTypeVarScope) {
|
|
16295
16344
|
flags |= -2147483648 /* EvalFlags.EnforceClassTypeVarScope */;
|
|
16296
16345
|
}
|
|
16297
|
-
const fileInfo =
|
|
16346
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
16298
16347
|
if (((0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(fileInfo) || options?.forwardRefs) && !options?.runtimeTypeExpression) {
|
|
16299
16348
|
flags |= 4 /* EvalFlags.ForwardRefs */;
|
|
16300
16349
|
}
|
|
@@ -16349,7 +16398,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16349
16398
|
return getTypeOfExpression(node, flags);
|
|
16350
16399
|
}
|
|
16351
16400
|
function getBuiltInType(node, name) {
|
|
16352
|
-
const scope =
|
|
16401
|
+
const scope = getScopeForNode(node);
|
|
16353
16402
|
if (scope) {
|
|
16354
16403
|
const builtInScope = ScopeUtils.getBuiltInScope(scope);
|
|
16355
16404
|
const nameType = builtInScope.lookUpSymbol(name);
|
|
@@ -16371,8 +16420,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16371
16420
|
return nameType;
|
|
16372
16421
|
}
|
|
16373
16422
|
function lookUpSymbolRecursive(node, name, honorCodeFlow, preferGlobalScope = false) {
|
|
16374
|
-
const scopeNodeInfo = ParseTreeUtils.getEvaluationScopeNode(node);
|
|
16375
|
-
const scope =
|
|
16423
|
+
const scopeNodeInfo = ParseTreeUtils.getEvaluationScopeNode(node, nodeInfo);
|
|
16424
|
+
const scope = nodeInfo.getScope(scopeNodeInfo.node);
|
|
16376
16425
|
let symbolWithScope = scope?.lookUpSymbolRecursive(name, {
|
|
16377
16426
|
useProxyScope: !!scopeNodeInfo.useProxyScope,
|
|
16378
16427
|
useChainedModuleLevelScopes: !!scopeNodeInfo.useChainedModuleLevelScopes,
|
|
@@ -16391,20 +16440,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16391
16440
|
const reachableDecl = symbolWithScope.symbol.getDeclarations().find((decl) => {
|
|
16392
16441
|
if (decl.type !== 8 /* DeclarationType.Alias */ && decl.type !== 0 /* DeclarationType.Intrinsic */) {
|
|
16393
16442
|
// Determine if the declaration is in the same execution scope as the "usageNode" node.
|
|
16394
|
-
let usageScopeNode = ParseTreeUtils.getExecutionScopeNode(node);
|
|
16443
|
+
let usageScopeNode = ParseTreeUtils.getExecutionScopeNode(node, nodeInfo);
|
|
16395
16444
|
const declNode = decl.type === 6 /* DeclarationType.Class */ ||
|
|
16396
16445
|
decl.type === 5 /* DeclarationType.Function */ ||
|
|
16397
16446
|
decl.type === 4 /* DeclarationType.TypeAlias */
|
|
16398
16447
|
? decl.node.d.name
|
|
16399
16448
|
: decl.node;
|
|
16400
|
-
const declScopeNode = ParseTreeUtils.getExecutionScopeNode(declNode);
|
|
16449
|
+
const declScopeNode = ParseTreeUtils.getExecutionScopeNode(declNode, nodeInfo);
|
|
16401
16450
|
// If this is a type parameter scope, it will be a proxy for its
|
|
16402
16451
|
// containing scope, so we need to use that instead.
|
|
16403
|
-
const usageScope =
|
|
16452
|
+
const usageScope = nodeInfo.getScope(usageScopeNode);
|
|
16404
16453
|
if (usageScope?.proxy) {
|
|
16405
|
-
const typeParamScope =
|
|
16454
|
+
const typeParamScope = nodeInfo.getScope(usageScopeNode);
|
|
16406
16455
|
if (!typeParamScope?.symbolTable.has(name) && usageScopeNode.parent) {
|
|
16407
|
-
usageScopeNode = ParseTreeUtils.getExecutionScopeNode(usageScopeNode.parent);
|
|
16456
|
+
usageScopeNode = ParseTreeUtils.getExecutionScopeNode(usageScopeNode.parent, nodeInfo);
|
|
16408
16457
|
}
|
|
16409
16458
|
}
|
|
16410
16459
|
if (usageScopeNode === declScopeNode) {
|
|
@@ -16412,7 +16461,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16412
16461
|
// If there was no control flow path from the usage back
|
|
16413
16462
|
// to the source, see if the usage node is reachable by
|
|
16414
16463
|
// any path.
|
|
16415
|
-
const flowNode =
|
|
16464
|
+
const flowNode = nodeInfo.getFlowNode(node);
|
|
16416
16465
|
const isReachable = flowNode &&
|
|
16417
16466
|
codeFlowEngine.getFlowNodeReachability(flowNode,
|
|
16418
16467
|
/* sourceFlowNode */ undefined,
|
|
@@ -16588,7 +16637,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16588
16637
|
const functionDecl = type.shared.declaration;
|
|
16589
16638
|
if (functionDecl.type === 5 /* DeclarationType.Function */) {
|
|
16590
16639
|
const functionNode = functionDecl.node;
|
|
16591
|
-
const functionScope =
|
|
16640
|
+
const functionScope = nodeInfo.getScope(functionNode);
|
|
16592
16641
|
if (functionScope) {
|
|
16593
16642
|
const paramSymbol = functionScope.lookUpSymbol(paramName);
|
|
16594
16643
|
if (paramSymbol) {
|
|
@@ -16609,6 +16658,48 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16609
16658
|
}
|
|
16610
16659
|
return undefined;
|
|
16611
16660
|
}
|
|
16661
|
+
// functools.partial(func, kw=value) forwards keyword arguments to the wrapped callable, but
|
|
16662
|
+
// partial's own signature absorbs them through **kwargs, so they don't resolve to a declaration.
|
|
16663
|
+
// Resolve the keyword against the wrapped callable (the first positional argument) instead so IDE
|
|
16664
|
+
// features like go-to-definition and rename bind to the underlying parameter. Returns true when
|
|
16665
|
+
// baseType is functools.partial, so the caller suppresses the default keyword-argument handling.
|
|
16666
|
+
function _tryAddPartialKeywordParamDecls(baseType, callNode, paramName, decls) {
|
|
16667
|
+
if (!(0, types_1.isInstantiableClass)(baseType) || baseType.shared.fullName !== 'functools.partial') {
|
|
16668
|
+
return false;
|
|
16669
|
+
}
|
|
16670
|
+
const wrappedArg = callNode.d.args.find((arg) => arg.d.argCategory === 0 /* ArgCategory.Simple */ && !arg.d.name);
|
|
16671
|
+
if (!wrappedArg) {
|
|
16672
|
+
return true;
|
|
16673
|
+
}
|
|
16674
|
+
const wrappedType = getType(wrappedArg.d.valueExpr);
|
|
16675
|
+
if (!wrappedType) {
|
|
16676
|
+
return true;
|
|
16677
|
+
}
|
|
16678
|
+
if ((0, types_1.isFunction)(wrappedType)) {
|
|
16679
|
+
const paramDecl = getDeclarationFromKeywordParam(wrappedType, paramName);
|
|
16680
|
+
if (paramDecl) {
|
|
16681
|
+
decls.push(paramDecl);
|
|
16682
|
+
}
|
|
16683
|
+
}
|
|
16684
|
+
else if ((0, types_1.isOverloaded)(wrappedType)) {
|
|
16685
|
+
types_1.OverloadedType.getOverloads(wrappedType).forEach((f) => {
|
|
16686
|
+
const paramDecl = getDeclarationFromKeywordParam(f, paramName);
|
|
16687
|
+
if (paramDecl) {
|
|
16688
|
+
decls.push(paramDecl);
|
|
16689
|
+
}
|
|
16690
|
+
});
|
|
16691
|
+
}
|
|
16692
|
+
else if ((0, types_1.isInstantiableClass)(wrappedType)) {
|
|
16693
|
+
const initMethodType = (0, constructors_1.getBoundInitMethod)(evaluatorInterface, wrappedArg.d.valueExpr, types_1.ClassType.cloneAsInstance(wrappedType))?.type;
|
|
16694
|
+
if (initMethodType && (0, types_1.isFunction)(initMethodType)) {
|
|
16695
|
+
const paramDecl = getDeclarationFromKeywordParam(initMethodType, paramName);
|
|
16696
|
+
if (paramDecl) {
|
|
16697
|
+
decls.push(paramDecl);
|
|
16698
|
+
}
|
|
16699
|
+
}
|
|
16700
|
+
}
|
|
16701
|
+
return true;
|
|
16702
|
+
}
|
|
16612
16703
|
function _shouldFallBackToClassEntryForKeywordArg(baseType, paramName) {
|
|
16613
16704
|
return (types_1.ClassType.isDataClass(baseType) ||
|
|
16614
16705
|
types_1.ClassType.isTypedDictClass(baseType) ||
|
|
@@ -16675,7 +16766,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16675
16766
|
return undefined;
|
|
16676
16767
|
}
|
|
16677
16768
|
function getDeclInfoForNameNode(node, skipUnreachableCode = true) {
|
|
16678
|
-
if (skipUnreachableCode &&
|
|
16769
|
+
if (skipUnreachableCode && nodeInfo.isCodeUnreachable(node)) {
|
|
16679
16770
|
return undefined;
|
|
16680
16771
|
}
|
|
16681
16772
|
const decls = [];
|
|
@@ -16685,7 +16776,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16685
16776
|
// since the non-aliased name is not in the symbol table.
|
|
16686
16777
|
const alias = getAliasFromImport(node);
|
|
16687
16778
|
if (alias) {
|
|
16688
|
-
const scope =
|
|
16779
|
+
const scope = getScopeForNode(node);
|
|
16689
16780
|
if (scope) {
|
|
16690
16781
|
// Look up the alias symbol.
|
|
16691
16782
|
const symbolInScope = scope.lookUpSymbolRecursive(alias.d.value);
|
|
@@ -16751,7 +16842,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16751
16842
|
}
|
|
16752
16843
|
else if (node.parent && node.parent.nodeType === 37 /* ParseNodeType.ModuleName */) {
|
|
16753
16844
|
const namePartIndex = node.parent.d.nameParts.findIndex((part) => part === node);
|
|
16754
|
-
const importInfo =
|
|
16845
|
+
const importInfo = nodeInfo.getImportInfo(node.parent);
|
|
16755
16846
|
if (namePartIndex >= 0 &&
|
|
16756
16847
|
importInfo &&
|
|
16757
16848
|
!importInfo.isNativeLib &&
|
|
@@ -16773,7 +16864,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16773
16864
|
if (argNode.parent?.nodeType === 9 /* ParseNodeType.Call */) {
|
|
16774
16865
|
const baseType = getType(argNode.parent.d.leftExpr);
|
|
16775
16866
|
if (baseType) {
|
|
16776
|
-
if ((
|
|
16867
|
+
if (_tryAddPartialKeywordParamDecls(baseType, argNode.parent, paramName, decls)) {
|
|
16868
|
+
// functools.partial keyword args are resolved against the wrapped callable.
|
|
16869
|
+
}
|
|
16870
|
+
else if ((0, types_1.isFunction)(baseType) && baseType.shared.declaration) {
|
|
16777
16871
|
const paramDecl = getDeclarationFromKeywordParam(baseType, paramName);
|
|
16778
16872
|
if (paramDecl) {
|
|
16779
16873
|
decls.push(paramDecl);
|
|
@@ -16817,10 +16911,45 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16817
16911
|
}
|
|
16818
16912
|
}
|
|
16819
16913
|
}
|
|
16914
|
+
else if (node.parent &&
|
|
16915
|
+
node.parent.nodeType === 74 /* ParseNodeType.PatternClassArgument */ &&
|
|
16916
|
+
node === node.parent.d.name &&
|
|
16917
|
+
node.parent.parent?.nodeType === 68 /* ParseNodeType.PatternClass */) {
|
|
16918
|
+
// The target node is the keyword name in a class pattern argument
|
|
16919
|
+
// (e.g. `case Foo(prop=...)`). Map it to the corresponding class member
|
|
16920
|
+
// declaration so that find-all-references and rename bind to the attribute.
|
|
16921
|
+
// Only the keyword (left of `=`) is handled here; the capture target on the
|
|
16922
|
+
// right (e.g. the second `prop` in `case Foo(prop=prop)`) is a separate local
|
|
16923
|
+
// binding that is resolved through the normal name-lookup path.
|
|
16924
|
+
const memberName = node.d.value;
|
|
16925
|
+
let classType = getType(node.parent.parent.d.className);
|
|
16926
|
+
if (classType) {
|
|
16927
|
+
classType = makeTopLevelTypeVarsConcrete(classType);
|
|
16928
|
+
(0, typeUtils_1.doForEachSubtype)(classType, (subtype) => {
|
|
16929
|
+
subtype = makeTopLevelTypeVarsConcrete(subtype);
|
|
16930
|
+
// The class name in a class pattern usually evaluates to an instantiable class,
|
|
16931
|
+
// but analysis can still yield Unknown/Any (e.g. an unresolved class name), so
|
|
16932
|
+
// the isInstantiableClass gate skips those subtypes rather than assuming
|
|
16933
|
+
// every subtype is a class.
|
|
16934
|
+
if ((0, types_1.isInstantiableClass)(subtype)) {
|
|
16935
|
+
// Try to find a member that has a declared type. If so, that
|
|
16936
|
+
// overrides any inferred types.
|
|
16937
|
+
let member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName, 64 /* MemberAccessFlags.DeclaredTypesOnly */);
|
|
16938
|
+
if (!member) {
|
|
16939
|
+
member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName);
|
|
16940
|
+
}
|
|
16941
|
+
if (member) {
|
|
16942
|
+
_addSymbolDeclInfo(member.symbol, decls, synthesizedTypes,
|
|
16943
|
+
/* preferTypedDeclarations */ true);
|
|
16944
|
+
}
|
|
16945
|
+
}
|
|
16946
|
+
});
|
|
16947
|
+
}
|
|
16948
|
+
}
|
|
16820
16949
|
else {
|
|
16821
|
-
const fileInfo =
|
|
16950
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
16822
16951
|
// Determine if this node is within a quoted type annotation.
|
|
16823
|
-
const isWithinTypeAnnotation = ParseTreeUtils.isWithinTypeAnnotation(node, !(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(
|
|
16952
|
+
const isWithinTypeAnnotation = ParseTreeUtils.isWithinTypeAnnotation(node, !(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(nodeInfo.getFileInfo(node)), nodeInfo);
|
|
16824
16953
|
// Determine if this is part of a "type" statement.
|
|
16825
16954
|
const isWithinTypeAliasStatement = !!ParseTreeUtils.getParentNodeOfType(node, 77 /* ParseNodeType.TypeAlias */);
|
|
16826
16955
|
const allowForwardReferences = isWithinTypeAnnotation || isWithinTypeAliasStatement || fileInfo.isStubFile;
|
|
@@ -16908,7 +17037,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16908
17037
|
}
|
|
16909
17038
|
if (typeAnnotationNode) {
|
|
16910
17039
|
let declaredType = getTypeOfParamAnnotation(typeAnnotationNode, declaration.node.d.category);
|
|
16911
|
-
const liveTypeVarScopes =
|
|
17040
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(declaration.node);
|
|
16912
17041
|
declaredType = (0, typeUtils_1.makeTypeVarsBound)(declaredType, liveTypeVarScopes);
|
|
16913
17042
|
return {
|
|
16914
17043
|
type: transformVariadicParamType(declaration.node, declaration.node.d.category, adjustParamAnnotatedType(declaration.node, declaredType)),
|
|
@@ -16956,9 +17085,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16956
17085
|
if (declaration.isDefinedByMemberAccess) {
|
|
16957
17086
|
const enclosingClass = ParseTreeUtils.getEnclosingClass(declaration.node);
|
|
16958
17087
|
if (enclosingClass) {
|
|
16959
|
-
declaredType = (0, typeUtils_1.makeTypeVarsFree)(declaredType, [
|
|
16960
|
-
ParseTreeUtils.getScopeIdForNode(enclosingClass),
|
|
16961
|
-
]);
|
|
17088
|
+
declaredType = (0, typeUtils_1.makeTypeVarsFree)(declaredType, [getScopeIdForNode(enclosingClass)]);
|
|
16962
17089
|
}
|
|
16963
17090
|
}
|
|
16964
17091
|
if ((0, types_1.isClassInstance)(declaredType) && types_1.ClassType.isBuiltIn(declaredType, 'TypeAlias')) {
|
|
@@ -17103,7 +17230,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17103
17230
|
typeVar.shared.declaredVariance =
|
|
17104
17231
|
(0, types_1.isParamSpec)(typeVar) || (0, types_1.isTypeVarTuple)(typeVar) ? 2 /* Variance.Invariant */ : 0 /* Variance.Auto */;
|
|
17105
17232
|
}
|
|
17106
|
-
typeVar = types_1.TypeVarType.cloneForScopeId(typeVar,
|
|
17233
|
+
typeVar = types_1.TypeVarType.cloneForScopeId(typeVar, getScopeIdForNode(scopeNode.nodeType === 77 /* ParseNodeType.TypeAlias */ ? scopeNode.d.name : scopeNode), scopeNode.d.name.d.value, scopeType);
|
|
17107
17234
|
}
|
|
17108
17235
|
writeTypeCache(node, { type: typeVar }, /* flags */ undefined);
|
|
17109
17236
|
writeTypeCache(node.d.name, { type: typeVar }, /* flags */ undefined);
|
|
@@ -17111,7 +17238,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17111
17238
|
}
|
|
17112
17239
|
function getInferredTypeOfDeclaration(symbol, decl) {
|
|
17113
17240
|
const resolvedDecl = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
|
|
17114
|
-
allowExternallyHiddenAccess:
|
|
17241
|
+
allowExternallyHiddenAccess: nodeInfo.getFileInfo(decl.node).isStubFile,
|
|
17115
17242
|
});
|
|
17116
17243
|
// We couldn't resolve the alias. Substitute an unknown
|
|
17117
17244
|
// type in this case.
|
|
@@ -17197,7 +17324,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17197
17324
|
}
|
|
17198
17325
|
// If this is part of a "py.typed" package, don't fall back on type inference
|
|
17199
17326
|
// unless it's marked Final, is a constant, or is a declared type alias.
|
|
17200
|
-
const fileInfo =
|
|
17327
|
+
const fileInfo = nodeInfo.getFileInfo(resolvedDecl.node);
|
|
17201
17328
|
let isUnambiguousType = !fileInfo.isInPyTypedPackage || fileInfo.isStubFile;
|
|
17202
17329
|
// If this is a py.typed package, determine if this is a case where an unannotated
|
|
17203
17330
|
// variable is considered "unambiguous" because all type checkers are almost
|
|
@@ -17409,7 +17536,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17409
17536
|
if (decl.type === 1 /* DeclarationType.Variable */) {
|
|
17410
17537
|
// Exempt typing.pyi and typingExtensions.pyi, which use variables to
|
|
17411
17538
|
// define some special forms.
|
|
17412
|
-
const fileInfo =
|
|
17539
|
+
const fileInfo = nodeInfo.getFileInfo(decl.node);
|
|
17413
17540
|
if (!fileInfo.isTypingStubFile && !fileInfo.isTypingExtensionsStubFile) {
|
|
17414
17541
|
return true;
|
|
17415
17542
|
}
|
|
@@ -17473,7 +17600,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17473
17600
|
let sawExplicitTypeAlias = false;
|
|
17474
17601
|
decls.forEach((decl, index) => {
|
|
17475
17602
|
const resolvedDecl = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
|
|
17476
|
-
allowExternallyHiddenAccess:
|
|
17603
|
+
allowExternallyHiddenAccess: nodeInfo.getFileInfo(decl.node).isStubFile,
|
|
17477
17604
|
}) ?? decl;
|
|
17478
17605
|
if (!isPossibleTypeAliasDeclaration(resolvedDecl) && !isExplicitTypeAliasDeclaration(resolvedDecl)) {
|
|
17479
17606
|
includesIllegalTypeAliasDecl = true;
|
|
@@ -17504,8 +17631,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17504
17631
|
// Is the declaration in the same execution scope as the "usageNode" node?
|
|
17505
17632
|
// If so, we can skip it because code flow analysis will allow us
|
|
17506
17633
|
// to determine the type in this context.
|
|
17507
|
-
const usageScope = ParseTreeUtils.getExecutionScopeNode(usageNode);
|
|
17508
|
-
const declScope = ParseTreeUtils.getExecutionScopeNode(decl.node);
|
|
17634
|
+
const usageScope = ParseTreeUtils.getExecutionScopeNode(usageNode, nodeInfo);
|
|
17635
|
+
const declScope = ParseTreeUtils.getExecutionScopeNode(decl.node, nodeInfo);
|
|
17509
17636
|
if (usageScope === declScope) {
|
|
17510
17637
|
// Skip declarations that appear after the usage in the source.
|
|
17511
17638
|
// Such declarations are typically only reached via loop back-edges,
|
|
@@ -17693,8 +17820,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17693
17820
|
const filteredTypedDecls = typedDecls.filter((decl) => {
|
|
17694
17821
|
if (decl.type !== 8 /* DeclarationType.Alias */) {
|
|
17695
17822
|
// Is the declaration in the same execution scope as the "usageNode" node?
|
|
17696
|
-
const usageScope = ParseTreeUtils.getExecutionScopeNode(usageNode);
|
|
17697
|
-
const declScope = ParseTreeUtils.getExecutionScopeNode(decl.node);
|
|
17823
|
+
const usageScope = ParseTreeUtils.getExecutionScopeNode(usageNode, nodeInfo);
|
|
17824
|
+
const declScope = ParseTreeUtils.getExecutionScopeNode(decl.node, nodeInfo);
|
|
17698
17825
|
if (usageScope === declScope) {
|
|
17699
17826
|
// For typed declarations we use the precise flow-graph reachability
|
|
17700
17827
|
// check rather than a simple position comparison, because typed decls
|
|
@@ -17780,7 +17907,35 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17780
17907
|
function getEffectiveReturnTypeResult(type, options) {
|
|
17781
17908
|
const specializedReturnType = types_1.FunctionType.getEffectiveReturnType(type, /* includeInferred */ false);
|
|
17782
17909
|
if (specializedReturnType && !(0, types_1.isUnknown)(specializedReturnType)) {
|
|
17783
|
-
return
|
|
17910
|
+
// A partially-unknown *inferred* return type (e.g. `Foo | Unknown`) can be
|
|
17911
|
+
// cached on a specialized/bound copy of an unannotated function. Because
|
|
17912
|
+
// `isUnknown` matches only a fully-unknown type, such a partial type would
|
|
17913
|
+
// otherwise short-circuit here and prevent call-site return-type inference
|
|
17914
|
+
// from ever running (e.g. an unannotated factory whose body narrows a
|
|
17915
|
+
// parameter-derived local with `isinstance`). When a call site is available,
|
|
17916
|
+
// fall through so the argument types can refine the inferred return type.
|
|
17917
|
+
//
|
|
17918
|
+
// NOTE: This gate intentionally mirrors a subset of the downstream call-site
|
|
17919
|
+
// refinement guard in `_getInferredReturnTypeResult` (search `isPartlyUnknown(returnType)`),
|
|
17920
|
+
// but tests the cached *specialized* return type here rather than the freshly-inferred
|
|
17921
|
+
// one, and omits the `!isStubDefinition`/`!isPyTypedDefinition`/`!isIncomplete`
|
|
17922
|
+
// conjuncts (not yet known at this point). Keep the two in sync if either is edited.
|
|
17923
|
+
const canRefineWithCallSite = options?.callSiteInfo !== undefined &&
|
|
17924
|
+
!type.shared.declaredReturnType &&
|
|
17925
|
+
types_1.FunctionType.hasUnannotatedParams(type) &&
|
|
17926
|
+
(0, typeUtils_1.isPartlyUnknown)(specializedReturnType);
|
|
17927
|
+
if (!canRefineWithCallSite) {
|
|
17928
|
+
return { type: specializedReturnType };
|
|
17929
|
+
}
|
|
17930
|
+
// Refine the cached partly-unknown return type using the call site. If the
|
|
17931
|
+
// refinement comes back incomplete -- e.g. a self- or mutually-recursive
|
|
17932
|
+
// factory whose base case returns the isinstance-narrowed local -- fall back
|
|
17933
|
+
// to the already-cached specialized return type rather than propagating the
|
|
17934
|
+
// incomplete result. The cached type is already correct in that case, and
|
|
17935
|
+
// propagating `isIncomplete` would suppress caller-side diagnostics that only
|
|
17936
|
+
// fire on a complete type (for example, `reveal_type`).
|
|
17937
|
+
const refinedResult = getInferredReturnTypeResult(type, options?.callSiteInfo);
|
|
17938
|
+
return refinedResult.isIncomplete ? { type: specializedReturnType } : refinedResult;
|
|
17784
17939
|
}
|
|
17785
17940
|
return getInferredReturnTypeResult(type, options?.callSiteInfo);
|
|
17786
17941
|
}
|
|
@@ -17819,11 +17974,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17819
17974
|
}
|
|
17820
17975
|
else if (type.shared.declaration) {
|
|
17821
17976
|
const functionNode = type.shared.declaration.node;
|
|
17822
|
-
const skipUnannotatedFunction = !
|
|
17977
|
+
const skipUnannotatedFunction = !nodeInfo.getFileInfo(functionNode).diagnosticRuleSet.analyzeUnannotatedFunctions &&
|
|
17823
17978
|
ParseTreeUtils.isUnannotatedFunction(functionNode);
|
|
17824
17979
|
// Skip return type inference if we are in "skip unannotated function" mode.
|
|
17825
17980
|
if (!skipUnannotatedFunction && !checkCodeFlowTooComplex(functionNode.d.suite)) {
|
|
17826
|
-
const codeFlowComplexity =
|
|
17981
|
+
const codeFlowComplexity = nodeInfo.getCodeFlowComplexity(functionNode);
|
|
17827
17982
|
// For very complex functions that have no annotated parameter types,
|
|
17828
17983
|
// don't attempt to infer the return type because it can be extremely
|
|
17829
17984
|
// expensive.
|
|
@@ -17887,7 +18042,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17887
18042
|
returnType = contextualReturnType;
|
|
17888
18043
|
if (type.shared.declaration?.node) {
|
|
17889
18044
|
// Externalize any TypeVars that appear in the type.
|
|
17890
|
-
const liveScopeIds =
|
|
18045
|
+
const liveScopeIds = getTypeVarScopesForNode(type.shared.declaration.node);
|
|
17891
18046
|
returnType = (0, typeUtils_1.makeTypeVarsFree)(returnType, liveScopeIds);
|
|
17892
18047
|
}
|
|
17893
18048
|
}
|
|
@@ -17902,7 +18057,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17902
18057
|
return undefined;
|
|
17903
18058
|
}
|
|
17904
18059
|
const functionNode = type.shared.declaration.node;
|
|
17905
|
-
const codeFlowComplexity =
|
|
18060
|
+
const codeFlowComplexity = nodeInfo.getCodeFlowComplexity(functionNode);
|
|
17906
18061
|
if (codeFlowComplexity >= maxReturnCallSiteTypeInferenceCodeFlowComplexity) {
|
|
17907
18062
|
return undefined;
|
|
17908
18063
|
}
|
|
@@ -19928,6 +20083,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
19928
20083
|
srcDetails.positionOnlyParamCount = Math.max(0, srcDetails.params.findIndex((p) => p.kind !== parameterUtils_1.ParamKind.Positional || p.param.category !== 0 /* ParamCategory.Simple */ || !!p.defaultType));
|
|
19929
20084
|
}
|
|
19930
20085
|
}
|
|
20086
|
+
// Determines whether the source's variadic **kwargs keyword parameter
|
|
20087
|
+
// is assignable to the keyword form of a destination positional-or-keyword
|
|
20088
|
+
// parameter.
|
|
20089
|
+
function assignNamedParam(destDetails, srcDetails, paramIndex, diag, constraints, flags, recursionCount) {
|
|
20090
|
+
const destParam = destDetails.params[paramIndex];
|
|
20091
|
+
if (srcDetails.kwargsIndex === undefined) {
|
|
20092
|
+
diag?.addMessage(localize_1.LocAddendum.namedParamMissingInSource().format({
|
|
20093
|
+
name: destParam.param.name ?? '',
|
|
20094
|
+
}));
|
|
20095
|
+
return false;
|
|
20096
|
+
}
|
|
20097
|
+
else if (!assignParam(destParam.type, srcDetails.params[srcDetails.kwargsIndex].type, paramIndex, diag?.createAddendum(), constraints, flags, recursionCount)) {
|
|
20098
|
+
return (flags & 32 /* AssignTypeFlags.PartialOverloadOverlap */) !== 0;
|
|
20099
|
+
}
|
|
20100
|
+
else {
|
|
20101
|
+
return true;
|
|
20102
|
+
}
|
|
20103
|
+
}
|
|
19931
20104
|
function assignFunction(destType, srcType, diag, constraints, flags, recursionCount) {
|
|
19932
20105
|
let canAssign = true;
|
|
19933
20106
|
const checkReturnType = (flags & 64 /* AssignTypeFlags.SkipReturnTypeCheck */) === 0;
|
|
@@ -20039,14 +20212,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
20039
20212
|
else if (destParam.kind !== parameterUtils_1.ParamKind.Positional &&
|
|
20040
20213
|
destParam.kind !== parameterUtils_1.ParamKind.ExpandedArgs &&
|
|
20041
20214
|
srcParam.kind === parameterUtils_1.ParamKind.Positional &&
|
|
20042
|
-
srcParamDetails.kwargsIndex === undefined &&
|
|
20043
20215
|
!srcParamDetails.params.some((p) => p.kind === parameterUtils_1.ParamKind.Keyword &&
|
|
20044
20216
|
p.param.category === 0 /* ParamCategory.Simple */ &&
|
|
20045
20217
|
p.param.name === destParam.param.name)) {
|
|
20046
|
-
|
|
20047
|
-
|
|
20048
|
-
}
|
|
20049
|
-
canAssign = false;
|
|
20218
|
+
if (!assignNamedParam(destParamDetails, srcParamDetails, paramIndex, diag, constraints, flags, recursionCount)) {
|
|
20219
|
+
canAssign = false;
|
|
20220
|
+
}
|
|
20050
20221
|
}
|
|
20051
20222
|
}
|
|
20052
20223
|
if (!types_1.FunctionType.isGradualCallableForm(destType) &&
|
|
@@ -20132,13 +20303,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
20132
20303
|
canAssign = false;
|
|
20133
20304
|
}
|
|
20134
20305
|
const destParamKind = destParamDetails.params[paramIndex].kind;
|
|
20135
|
-
if (destParamKind !== parameterUtils_1.ParamKind.Positional &&
|
|
20136
|
-
|
|
20137
|
-
|
|
20138
|
-
|
|
20139
|
-
name: destParamDetails.params[paramIndex].param.name ?? '',
|
|
20140
|
-
}));
|
|
20141
|
-
canAssign = false;
|
|
20306
|
+
if (destParamKind !== parameterUtils_1.ParamKind.Positional && destParamKind !== parameterUtils_1.ParamKind.ExpandedArgs) {
|
|
20307
|
+
if (!assignNamedParam(destParamDetails, srcParamDetails, paramIndex, diag, constraints, flags, recursionCount)) {
|
|
20308
|
+
canAssign = false;
|
|
20309
|
+
}
|
|
20142
20310
|
}
|
|
20143
20311
|
}
|
|
20144
20312
|
}
|
|
@@ -20232,7 +20400,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
20232
20400
|
srcParamInfo.kind === parameterUtils_1.ParamKind.Positional) {
|
|
20233
20401
|
return;
|
|
20234
20402
|
}
|
|
20235
|
-
const destParamInfo = destParamMap.get(srcParamInfo.param.name)
|
|
20403
|
+
const destParamInfo = destParamMap.get(srcParamInfo.param.name) ??
|
|
20404
|
+
destParamDetails.params.find((paramInfo) => paramInfo.param.name === srcParamInfo.param.name &&
|
|
20405
|
+
paramInfo.kind === parameterUtils_1.ParamKind.Standard &&
|
|
20406
|
+
paramInfo.param.category === 0 /* ParamCategory.Simple */);
|
|
20236
20407
|
const paramDiag = diag?.createAddendum();
|
|
20237
20408
|
const srcParamType = srcParamInfo.type;
|
|
20238
20409
|
if (!destParamInfo) {
|
|
@@ -20263,6 +20434,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
20263
20434
|
}
|
|
20264
20435
|
return;
|
|
20265
20436
|
}
|
|
20437
|
+
// A keyword-only source parameter was matched to a positional-or-keyword
|
|
20438
|
+
// dest parameter. The dest parameter can be called positionally, but a
|
|
20439
|
+
// keyword-only source parameter with no default would be left unsatisfied.
|
|
20440
|
+
if (destParamInfo.kind === parameterUtils_1.ParamKind.Standard &&
|
|
20441
|
+
srcParamInfo.kind === parameterUtils_1.ParamKind.Keyword &&
|
|
20442
|
+
!srcParamInfo.defaultType) {
|
|
20443
|
+
if ((flags & 32 /* AssignTypeFlags.PartialOverloadOverlap */) === 0) {
|
|
20444
|
+
paramDiag?.addMessage(localize_1.LocAddendum.functionParamDefaultMissing().format({
|
|
20445
|
+
name: srcParamInfo.param.name,
|
|
20446
|
+
}));
|
|
20447
|
+
canAssign = false;
|
|
20448
|
+
return;
|
|
20449
|
+
}
|
|
20450
|
+
}
|
|
20266
20451
|
// If we're performing a partial overload match and both the source
|
|
20267
20452
|
// and dest parameters provide defaults, assume that there could
|
|
20268
20453
|
// be a match.
|
|
@@ -20285,7 +20470,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
20285
20470
|
destType: printType(srcParamType),
|
|
20286
20471
|
}));
|
|
20287
20472
|
}
|
|
20288
|
-
|
|
20473
|
+
if (destParamInfo.kind !== parameterUtils_1.ParamKind.Standard ||
|
|
20474
|
+
(flags & 32 /* AssignTypeFlags.PartialOverloadOverlap */) === 0) {
|
|
20475
|
+
canAssign = false;
|
|
20476
|
+
}
|
|
20289
20477
|
}
|
|
20290
20478
|
if (destParamInfo.defaultType && !srcParamInfo.defaultType) {
|
|
20291
20479
|
diag?.createAddendum().addMessage(localize_1.LocAddendum.functionParamDefaultMissing().format({
|
|
@@ -21386,7 +21574,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21386
21574
|
// expression tree because we don't want to mutate the latter; the
|
|
21387
21575
|
// expression tree created by this function is therefore used only temporarily.
|
|
21388
21576
|
function parseStringAsTypeAnnotation(node, reportErrors) {
|
|
21389
|
-
const fileInfo =
|
|
21577
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
21390
21578
|
const parser = new parser_1.Parser();
|
|
21391
21579
|
const textValue = node.d.strings[0].d.value;
|
|
21392
21580
|
// Determine the offset within the file where the string
|
|
@@ -21404,14 +21592,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21404
21592
|
parseOptions.pythonVersion = fileInfo.executionEnvironment.pythonVersion;
|
|
21405
21593
|
parseOptions.reportErrorsForParsedStringContents = true;
|
|
21406
21594
|
const parseResults = parser.parseTextExpression(dummyFileContents, valueOffset, textValue.length, parseOptions, 0 /* ParseTextMode.Expression */,
|
|
21407
|
-
/* initialParenDepth */ undefined, fileInfo.typingSymbolAliases);
|
|
21595
|
+
/* initialParenDepth */ undefined, fileInfo.typingSymbolAliases, node.a);
|
|
21408
21596
|
if (parseResults.parseTree) {
|
|
21409
21597
|
// If there are errors but we are not reporting them, return
|
|
21410
21598
|
// undefined to indicate that the parse failed.
|
|
21411
21599
|
if (!reportErrors && parseResults.diagnostics.length > 0) {
|
|
21412
21600
|
return undefined;
|
|
21413
21601
|
}
|
|
21414
|
-
const fileInfo =
|
|
21602
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
21415
21603
|
parseResults.diagnostics.forEach((diag) => {
|
|
21416
21604
|
fileInfo.diagnosticSink.addDiagnosticWithTextRange('error', diag.message, node);
|
|
21417
21605
|
});
|
|
@@ -21419,7 +21607,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21419
21607
|
// Optionally add the new subtree to the parse tree so it can
|
|
21420
21608
|
// participate in language server operations like find and replace.
|
|
21421
21609
|
if (reportErrors) {
|
|
21422
|
-
node.
|
|
21610
|
+
nodeInfo.setStringAnnotation(node, parseResults.parseTree, parseResults.stringAnnotations);
|
|
21423
21611
|
}
|
|
21424
21612
|
return parseResults.parseTree;
|
|
21425
21613
|
}
|
|
@@ -21429,7 +21617,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21429
21617
|
// var can be "narrowed" to a single one of its constraints based on isinstance
|
|
21430
21618
|
// checks within the code flow.
|
|
21431
21619
|
function narrowConstrainedTypeVar(node, typeVar) {
|
|
21432
|
-
const flowNode =
|
|
21620
|
+
const flowNode = nodeInfo.getFlowNode(node);
|
|
21433
21621
|
if (!flowNode) {
|
|
21434
21622
|
return undefined;
|
|
21435
21623
|
}
|
|
@@ -21439,7 +21627,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21439
21627
|
return ' '.repeat(printExpressionSpaceCount);
|
|
21440
21628
|
}
|
|
21441
21629
|
function getLineNum(node) {
|
|
21442
|
-
const fileInfo =
|
|
21630
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
21443
21631
|
const range = (0, positionUtils_1.convertOffsetsToRange)(node.start, node.start + node.length, fileInfo.lines);
|
|
21444
21632
|
return (range.start.line + 1).toString();
|
|
21445
21633
|
}
|
|
@@ -21450,6 +21638,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21450
21638
|
const getInferredReturnTypeResult = wrapWithLogger(_getInferredReturnTypeResult);
|
|
21451
21639
|
const evaluatorInterface = {
|
|
21452
21640
|
runWithCancellationToken,
|
|
21641
|
+
getAnalyzerNodeInfoReader: () => nodeInfo,
|
|
21453
21642
|
getType,
|
|
21454
21643
|
getTypeResult,
|
|
21455
21644
|
getTypeResultForDecorator,
|
|
@@ -21560,7 +21749,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21560
21749
|
checkForCancellation,
|
|
21561
21750
|
printControlFlowGraph,
|
|
21562
21751
|
};
|
|
21563
|
-
const codeFlowEngine = (0, codeFlowEngine_1.getCodeFlowEngine)(evaluatorInterface, speculativeTypeTracker);
|
|
21752
|
+
const codeFlowEngine = (0, codeFlowEngine_1.getCodeFlowEngine)(evaluatorInterface, speculativeTypeTracker, nodeInfo);
|
|
21564
21753
|
return evaluatorInterface;
|
|
21565
21754
|
}
|
|
21566
21755
|
//# sourceMappingURL=typeEvaluator.js.map
|