@zzzen/pyright-internal 1.2.0-dev.20260816 → 1.2.0-dev.20260823
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 +119 -24
- package/dist/analyzer/analyzerNodeInfo.js +408 -89
- package/dist/analyzer/analyzerNodeInfo.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 +55 -34
- 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/dataClasses.d.ts +5 -4
- package/dist/analyzer/dataClasses.js +21 -56
- 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 +235 -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 +2 -1
- package/dist/analyzer/sentinel.js +2 -3
- package/dist/analyzer/sentinel.js.map +1 -1
- package/dist/analyzer/service.js +28 -10
- 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 +73 -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 +326 -198
- 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 +26 -25
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +12 -9
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.js +3 -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/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 -0
- 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/languageService/analyzerServiceExecutor.js +2 -1
- 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 +11 -0
- package/dist/localization/package.nls.de.json +11 -0
- package/dist/localization/package.nls.en-us.json +5 -0
- package/dist/localization/package.nls.es.json +11 -0
- package/dist/localization/package.nls.fr.json +11 -0
- package/dist/localization/package.nls.it.json +11 -0
- package/dist/localization/package.nls.ja.json +11 -0
- package/dist/localization/package.nls.ko.json +11 -0
- package/dist/localization/package.nls.pl.json +11 -0
- package/dist/localization/package.nls.pt-br.json +11 -0
- package/dist/localization/package.nls.qps-ploc.json +11 -0
- package/dist/localization/package.nls.ru.json +11 -0
- package/dist/localization/package.nls.tr.json +11 -0
- package/dist/localization/package.nls.zh-cn.json +12 -1
- package/dist/localization/package.nls.zh-tw.json +13 -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/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 +113 -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 -6
- 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.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/pyrightFileSystem.test.js +41 -0
- package/dist/tests/pyrightFileSystem.test.js.map +1 -1
- package/dist/tests/service.test.js +77 -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/typeEvaluator1.test.js +24 -3
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +4 -0
- package/dist/tests/typeEvaluator4.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/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/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
|
@@ -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) {
|
|
@@ -2419,7 +2436,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2419
2436
|
return getTypeOfModule(node, symbolName, ['_typeshed']);
|
|
2420
2437
|
}
|
|
2421
2438
|
function getTypeOfModule(node, symbolName, nameParts) {
|
|
2422
|
-
const fileInfo =
|
|
2439
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2423
2440
|
const lookupResult = importLookup({ nameParts, importingFileUri: fileInfo.fileUri });
|
|
2424
2441
|
if (!lookupResult) {
|
|
2425
2442
|
return undefined;
|
|
@@ -2431,8 +2448,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2431
2448
|
return getEffectiveTypeOfSymbol(symbol);
|
|
2432
2449
|
}
|
|
2433
2450
|
function checkCodeFlowTooComplex(node) {
|
|
2434
|
-
const scopeNode = node.nodeType === 31 /* ParseNodeType.Function */ ? node : ParseTreeUtils.getExecutionScopeNode(node);
|
|
2435
|
-
const codeComplexity =
|
|
2451
|
+
const scopeNode = node.nodeType === 31 /* ParseNodeType.Function */ ? node : ParseTreeUtils.getExecutionScopeNode(node, nodeInfo);
|
|
2452
|
+
const codeComplexity = nodeInfo.getCodeFlowComplexity(scopeNode);
|
|
2436
2453
|
if (codeComplexity > exports.maxCodeComplexity) {
|
|
2437
2454
|
let errorRange = scopeNode;
|
|
2438
2455
|
if (scopeNode.nodeType === 31 /* ParseNodeType.Function */) {
|
|
@@ -2441,7 +2458,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2441
2458
|
else if (scopeNode.nodeType === 36 /* ParseNodeType.Module */) {
|
|
2442
2459
|
errorRange = { start: 0, length: 0 };
|
|
2443
2460
|
}
|
|
2444
|
-
const fileInfo =
|
|
2461
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2445
2462
|
addDiagnosticForTextRange(fileInfo, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.codeTooComplexToAnalyze(), errorRange);
|
|
2446
2463
|
return true;
|
|
2447
2464
|
}
|
|
@@ -2457,18 +2474,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2457
2474
|
if (checkCodeFlowTooComplex(node)) {
|
|
2458
2475
|
return typeEvaluatorTypes_1.Reachability.Reachable;
|
|
2459
2476
|
}
|
|
2460
|
-
const flowNode =
|
|
2477
|
+
const flowNode = nodeInfo.getFlowNode(node);
|
|
2461
2478
|
if (!flowNode) {
|
|
2462
2479
|
if (node.parent) {
|
|
2463
2480
|
return getNodeReachability(node.parent, sourceNode);
|
|
2464
2481
|
}
|
|
2465
2482
|
return typeEvaluatorTypes_1.Reachability.UnreachableStructural;
|
|
2466
2483
|
}
|
|
2467
|
-
const sourceFlowNode = sourceNode ?
|
|
2484
|
+
const sourceFlowNode = sourceNode ? nodeInfo.getFlowNode(sourceNode) : undefined;
|
|
2468
2485
|
return codeFlowEngine.getFlowNodeReachability(flowNode, sourceFlowNode);
|
|
2469
2486
|
}
|
|
2470
2487
|
function getAfterNodeReachability(node) {
|
|
2471
|
-
const returnFlowNode =
|
|
2488
|
+
const returnFlowNode = nodeInfo.getAfterFlowNode(node);
|
|
2472
2489
|
if (!returnFlowNode) {
|
|
2473
2490
|
return typeEvaluatorTypes_1.Reachability.UnreachableStructural;
|
|
2474
2491
|
}
|
|
@@ -2479,7 +2496,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2479
2496
|
if (reachability !== typeEvaluatorTypes_1.Reachability.Reachable) {
|
|
2480
2497
|
return reachability;
|
|
2481
2498
|
}
|
|
2482
|
-
const executionScopeNode = ParseTreeUtils.getExecutionScopeNode(node);
|
|
2499
|
+
const executionScopeNode = ParseTreeUtils.getExecutionScopeNode(node, nodeInfo);
|
|
2483
2500
|
if (!isFlowNodeReachableUsingNeverNarrowing(executionScopeNode, returnFlowNode)) {
|
|
2484
2501
|
return typeEvaluatorTypes_1.Reachability.UnreachableByAnalysis;
|
|
2485
2502
|
}
|
|
@@ -2502,8 +2519,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2502
2519
|
if (checkCodeFlowTooComplex(sourceNode)) {
|
|
2503
2520
|
return true;
|
|
2504
2521
|
}
|
|
2505
|
-
const sourceFlowNode =
|
|
2506
|
-
const sinkFlowNode =
|
|
2522
|
+
const sourceFlowNode = nodeInfo.getFlowNode(sourceNode);
|
|
2523
|
+
const sinkFlowNode = nodeInfo.getFlowNode(sinkNode);
|
|
2507
2524
|
if (!sourceFlowNode || !sinkFlowNode) {
|
|
2508
2525
|
return false;
|
|
2509
2526
|
}
|
|
@@ -2521,7 +2538,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2521
2538
|
return;
|
|
2522
2539
|
}
|
|
2523
2540
|
if (!isDiagnosticSuppressedForNode(node)) {
|
|
2524
|
-
const fileInfo =
|
|
2541
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2525
2542
|
const reportTypeReachability = fileInfo.diagnosticRuleSet.enableReachabilityAnalysis;
|
|
2526
2543
|
if (reachability === typeEvaluatorTypes_1.Reachability.UnreachableStructural ||
|
|
2527
2544
|
reachability === typeEvaluatorTypes_1.Reachability.UnreachableStaticCondition ||
|
|
@@ -2536,7 +2553,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2536
2553
|
}
|
|
2537
2554
|
function addDeprecated(message, node) {
|
|
2538
2555
|
if (!isDiagnosticSuppressedForNode(node)) {
|
|
2539
|
-
const fileInfo =
|
|
2556
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2540
2557
|
fileInfo.diagnosticSink.addDeprecatedWithTextRange(message, node);
|
|
2541
2558
|
}
|
|
2542
2559
|
}
|
|
@@ -2549,7 +2566,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2549
2566
|
return undefined;
|
|
2550
2567
|
}
|
|
2551
2568
|
if (isNodeReachable(node)) {
|
|
2552
|
-
const fileInfo =
|
|
2569
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2553
2570
|
return fileInfo.diagnosticSink.addDiagnosticWithTextRange(diagLevel, message, range ?? node);
|
|
2554
2571
|
}
|
|
2555
2572
|
return undefined;
|
|
@@ -2574,7 +2591,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2574
2591
|
return suppressedEntries.every((entry) => !entry.suppressedDiags);
|
|
2575
2592
|
}
|
|
2576
2593
|
function addDiagnostic(rule, message, node, range) {
|
|
2577
|
-
const fileInfo =
|
|
2594
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2578
2595
|
const diagLevel = fileInfo.diagnosticRuleSet[rule];
|
|
2579
2596
|
if (diagLevel === 'none') {
|
|
2580
2597
|
return undefined;
|
|
@@ -2582,7 +2599,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2582
2599
|
const containingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
|
2583
2600
|
if (containingFunction) {
|
|
2584
2601
|
// Should we suppress this diagnostic because it's within an unannotated function?
|
|
2585
|
-
const fileInfo =
|
|
2602
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2586
2603
|
if (!fileInfo.diagnosticRuleSet.analyzeUnannotatedFunctions) {
|
|
2587
2604
|
// Is the target node within the body of the function? If so, suppress the diagnostic.
|
|
2588
2605
|
if (ParseTreeUtils.isUnannotatedFunction(containingFunction) &&
|
|
@@ -2592,7 +2609,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2592
2609
|
}
|
|
2593
2610
|
// Should we suppress this diagnostic because it's within a no_type_check function?
|
|
2594
2611
|
const containingClassNode = ParseTreeUtils.getEnclosingClass(containingFunction, /* stopAtFunction */ true);
|
|
2595
|
-
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, containingFunction, !!containingClassNode);
|
|
2612
|
+
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, containingFunction, !!containingClassNode, nodeInfo);
|
|
2596
2613
|
if ((functionInfo.flags & 524288 /* FunctionTypeFlags.NoTypeCheck */) !== 0) {
|
|
2597
2614
|
return undefined;
|
|
2598
2615
|
}
|
|
@@ -2624,7 +2641,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2624
2641
|
}
|
|
2625
2642
|
const declarations = symbolWithScope.symbol.getDeclarations();
|
|
2626
2643
|
let declaredType = getDeclaredTypeOfSymbol(symbolWithScope.symbol)?.type;
|
|
2627
|
-
const fileInfo =
|
|
2644
|
+
const fileInfo = nodeInfo.getFileInfo(nameNode);
|
|
2628
2645
|
// If this is a class scope and there is no type declared for this class variable,
|
|
2629
2646
|
// see if a parent class has a type declared.
|
|
2630
2647
|
if (declaredType === undefined && symbolWithScope.scope.type === 3 /* ScopeType.Class */) {
|
|
@@ -2644,7 +2661,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2644
2661
|
const isTypeAlias = !!declaredType && (0, types_1.isClassInstance)(declaredType) && types_1.ClassType.isBuiltIn(declaredType, 'TypeAlias');
|
|
2645
2662
|
if (declaredType && !isTypeAlias) {
|
|
2646
2663
|
let diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
|
2647
|
-
const liveScopeIds =
|
|
2664
|
+
const liveScopeIds = getTypeVarScopesForNode(nameNode);
|
|
2648
2665
|
const boundDeclaredType = (0, typeUtils_1.makeTypeVarsBound)(declaredType, liveScopeIds);
|
|
2649
2666
|
const srcType = (0, typeUtils_1.makeTypeVarsBound)(typeResult.type, liveScopeIds);
|
|
2650
2667
|
if (!assignType(boundDeclaredType, srcType, diagAddendum)) {
|
|
@@ -2670,7 +2687,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2670
2687
|
// appears to be a constant, use the strict source type. If it's a member
|
|
2671
2688
|
// variable that can be overridden by a child class, use the more general
|
|
2672
2689
|
// version by stripping off the literal and TypeForm.
|
|
2673
|
-
const scope =
|
|
2690
|
+
const scope = getScopeForNode(nameNode);
|
|
2674
2691
|
if (scope?.type === 3 /* ScopeType.Class */) {
|
|
2675
2692
|
if (types_1.TypeBase.isInstance(destType) &&
|
|
2676
2693
|
!(0, symbolNameUtils_1.isConstantName)(nameValue) &&
|
|
@@ -2768,7 +2785,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
2768
2785
|
}
|
|
2769
2786
|
function assignTypeToMemberVariable(node, typeResult, isInstanceMember, srcExprNode) {
|
|
2770
2787
|
const memberName = node.d.member.d.value;
|
|
2771
|
-
const fileInfo =
|
|
2788
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
2772
2789
|
const classDef = ParseTreeUtils.getEnclosingClass(node);
|
|
2773
2790
|
if (!classDef) {
|
|
2774
2791
|
return;
|
|
@@ -3174,8 +3191,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3174
3191
|
return type;
|
|
3175
3192
|
}
|
|
3176
3193
|
function markNamesAccessed(node, names) {
|
|
3177
|
-
const fileInfo =
|
|
3178
|
-
const scope =
|
|
3194
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
3195
|
+
const scope = getScopeForNode(node);
|
|
3179
3196
|
if (scope) {
|
|
3180
3197
|
names.forEach((symbolName) => {
|
|
3181
3198
|
const symbolInScope = scope.lookUpSymbolRecursive(symbolName);
|
|
@@ -3400,7 +3417,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3400
3417
|
}
|
|
3401
3418
|
}
|
|
3402
3419
|
function getTypeOfName(node, flags) {
|
|
3403
|
-
const fileInfo =
|
|
3420
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
3404
3421
|
const name = node.d.value;
|
|
3405
3422
|
let symbol;
|
|
3406
3423
|
let type;
|
|
@@ -3611,7 +3628,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3611
3628
|
}
|
|
3612
3629
|
if ((0, types_1.isTypeVar)(type) && type.priv.scopeId && !type.shared.isSynthesized) {
|
|
3613
3630
|
if (!(0, types_1.isTypeVarTuple)(type) || !type.priv.isInUnion) {
|
|
3614
|
-
const liveScopeIds =
|
|
3631
|
+
const liveScopeIds = getTypeVarScopesForNode(node);
|
|
3615
3632
|
type = types_1.TypeBase.cloneWithTypeForm(type, (0, typeUtils_1.convertToInstance)((0, typeUtils_1.makeTypeVarsBound)(type, liveScopeIds)));
|
|
3616
3633
|
}
|
|
3617
3634
|
}
|
|
@@ -3660,7 +3677,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3660
3677
|
return type;
|
|
3661
3678
|
}
|
|
3662
3679
|
// Disable for assignments in the typings.pyi file, since it defines special forms.
|
|
3663
|
-
const fileInfo =
|
|
3680
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
3664
3681
|
if (fileInfo.isTypingStubFile) {
|
|
3665
3682
|
return type;
|
|
3666
3683
|
}
|
|
@@ -3723,28 +3740,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3723
3740
|
// If the symbol is modified in scopes other than the one in which it is
|
|
3724
3741
|
// declared (e.g. through a nonlocal or global binding), it is not eligible
|
|
3725
3742
|
// for code flow analysis.
|
|
3726
|
-
if (!decls.every((decl) => decl.type === 2 /* DeclarationType.Param */ ||
|
|
3727
|
-
ScopeUtils.getScopeForNode(decl.node) === symbolWithScope.scope)) {
|
|
3743
|
+
if (!decls.every((decl) => decl.type === 2 /* DeclarationType.Param */ || getScopeForNode(decl.node) === symbolWithScope.scope)) {
|
|
3728
3744
|
return undefined;
|
|
3729
3745
|
}
|
|
3730
3746
|
// If the symbol is a non-final variable in the global scope, it is not
|
|
3731
3747
|
// eligible because it could be modified by other modules.
|
|
3732
3748
|
if (!decls.every((decl) => decl.type !== 1 /* DeclarationType.Variable */ ||
|
|
3733
3749
|
decl.isFinal ||
|
|
3734
|
-
|
|
3750
|
+
getScopeForNode(decl.node)?.type !== 4 /* ScopeType.Module */)) {
|
|
3735
3751
|
return undefined;
|
|
3736
3752
|
}
|
|
3737
3753
|
// If the symbol is a variable captured by an inner function
|
|
3738
3754
|
// or lambda, see if we can infer the type from the outer scope.
|
|
3739
|
-
const scopeHierarchy =
|
|
3755
|
+
const scopeHierarchy = getScopeHierarchy(node, symbolWithScope.scope);
|
|
3740
3756
|
if (scopeHierarchy && scopeHierarchy.length >= 2) {
|
|
3741
3757
|
// Find the parse node associated with the scope that is just inside of the
|
|
3742
3758
|
// scope that declares the captured variable.
|
|
3743
|
-
const innerScopeNode =
|
|
3759
|
+
const innerScopeNode = findTopNodeInScope(node, scopeHierarchy[scopeHierarchy.length - 2]);
|
|
3744
3760
|
if (innerScopeNode?.nodeType === 31 /* ParseNodeType.Function */ ||
|
|
3745
3761
|
innerScopeNode?.nodeType === 33 /* ParseNodeType.Lambda */ ||
|
|
3746
3762
|
innerScopeNode?.nodeType === 10 /* ParseNodeType.Class */) {
|
|
3747
|
-
const innerScopeCodeFlowNode =
|
|
3763
|
+
const innerScopeCodeFlowNode = nodeInfo.getFlowNode(innerScopeNode);
|
|
3748
3764
|
if (innerScopeCodeFlowNode) {
|
|
3749
3765
|
// See if any of the assignments of the symbol are reachable
|
|
3750
3766
|
// from this node. If so, we cannot apply any narrowing because
|
|
@@ -3755,7 +3771,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3755
3771
|
if (decl.type === 2 /* DeclarationType.Param */) {
|
|
3756
3772
|
return true;
|
|
3757
3773
|
}
|
|
3758
|
-
const declCodeFlowNode =
|
|
3774
|
+
const declCodeFlowNode = nodeInfo.getFlowNode(decl.node);
|
|
3759
3775
|
if (!declCodeFlowNode) {
|
|
3760
3776
|
return false;
|
|
3761
3777
|
}
|
|
@@ -3874,7 +3890,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3874
3890
|
container: enclosingScope.d.name.d.value,
|
|
3875
3891
|
}), node);
|
|
3876
3892
|
}
|
|
3877
|
-
const scopeIdToAssign =
|
|
3893
|
+
const scopeIdToAssign = getScopeIdForNode(enclosingScope);
|
|
3878
3894
|
return types_1.TypeVarType.cloneForScopeId(type, scopeIdToAssign, enclosingScope.d.name.d.value, enclosingScope.nodeType === 31 /* ParseNodeType.Function */ ? 1 /* TypeVarScopeType.Function */ : 0 /* TypeVarScopeType.Class */);
|
|
3879
3895
|
}
|
|
3880
3896
|
if ((flags & 4096 /* EvalFlags.AllowTypeVarWithoutScopeId */) === 0) {
|
|
@@ -3899,7 +3915,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
3899
3915
|
}
|
|
3900
3916
|
const enclosingClass = ParseTreeUtils.getEnclosingClass(node);
|
|
3901
3917
|
if (enclosingClass) {
|
|
3902
|
-
const liveTypeVarScopeIds =
|
|
3918
|
+
const liveTypeVarScopeIds = getTypeVarScopesForNode(enclosingClass);
|
|
3903
3919
|
if (!liveTypeVarScopeIds.includes(scopeId)) {
|
|
3904
3920
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarInvalidForMemberVariable().format({
|
|
3905
3921
|
name: types_1.TypeVarType.getReadableName(type),
|
|
@@ -4120,7 +4136,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4120
4136
|
}
|
|
4121
4137
|
}
|
|
4122
4138
|
if (!skipPartialUnknownCheck) {
|
|
4123
|
-
reportPossibleUnknownAssignment(
|
|
4139
|
+
reportPossibleUnknownAssignment(nodeInfo.getFileInfo(node).diagnosticRuleSet.reportUnknownMemberType, diagnosticRules_1.DiagnosticRule.reportUnknownMemberType, node.d.member, typeResult.type, node,
|
|
4124
4140
|
/* ignoreEmptyContainers */ false);
|
|
4125
4141
|
}
|
|
4126
4142
|
// Cache the type information in the member name node.
|
|
@@ -4131,7 +4147,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4131
4147
|
let baseType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(baseTypeResult.type);
|
|
4132
4148
|
const memberName = node.d.member.d.value;
|
|
4133
4149
|
let diag = new diagnostic_1.DiagnosticAddendum();
|
|
4134
|
-
const fileInfo =
|
|
4150
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
4135
4151
|
let type;
|
|
4136
4152
|
let narrowedTypeForSet;
|
|
4137
4153
|
let typeErrors = false;
|
|
@@ -4223,7 +4239,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4223
4239
|
(0, types_1.isClass)(prefetched.functionClass)) {
|
|
4224
4240
|
baseType = types_1.ClassType.cloneAsInstance(prefetched.functionClass);
|
|
4225
4241
|
}
|
|
4226
|
-
const enumMemberResult = (0, enums_1.getTypeOfEnumMember)(evaluatorInterface, node, baseType, memberName, isIncomplete);
|
|
4242
|
+
const enumMemberResult = (0, enums_1.getTypeOfEnumMember)(evaluatorInterface, node, baseType, memberName, isIncomplete, nodeInfo);
|
|
4227
4243
|
if (enumMemberResult) {
|
|
4228
4244
|
if (usage.method === 'get') {
|
|
4229
4245
|
typeResult = enumMemberResult;
|
|
@@ -4573,7 +4589,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4573
4589
|
if (errorNode &&
|
|
4574
4590
|
(0, types_1.isInstantiableClass)(memberInfo.classType) &&
|
|
4575
4591
|
types_1.ClassType.isSameGenericClass(memberInfo.classType, isAccessedThroughObject ? types_1.ClassType.cloneAsInstantiable(classType) : classType)) {
|
|
4576
|
-
setSymbolAccessed(
|
|
4592
|
+
setSymbolAccessed(nodeInfo.getFileInfo(errorNode), memberInfo.symbol, errorNode);
|
|
4577
4593
|
}
|
|
4578
4594
|
// Special-case `__init_subclass` and `__class_getitem__` because
|
|
4579
4595
|
// these are always treated as class methods even if they're not
|
|
@@ -5081,13 +5097,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
5081
5097
|
// they don't result in runtime exceptions when used in this manner.
|
|
5082
5098
|
let skipSubscriptCheck = (flags & 32768 /* EvalFlags.VarTypeAnnotation */) !== 0;
|
|
5083
5099
|
if (skipSubscriptCheck) {
|
|
5084
|
-
const scopeNode = ParseTreeUtils.getExecutionScopeNode(node);
|
|
5100
|
+
const scopeNode = ParseTreeUtils.getExecutionScopeNode(node, nodeInfo);
|
|
5085
5101
|
if (scopeNode?.nodeType === 36 /* ParseNodeType.Module */) {
|
|
5086
5102
|
skipSubscriptCheck = false;
|
|
5087
5103
|
}
|
|
5088
5104
|
}
|
|
5089
5105
|
if (!skipSubscriptCheck) {
|
|
5090
|
-
const fileInfo =
|
|
5106
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
5091
5107
|
if ((0, types_1.isInstantiableClass)(baseTypeResult.type) &&
|
|
5092
5108
|
types_1.ClassType.isBuiltIn(baseTypeResult.type) &&
|
|
5093
5109
|
!baseTypeResult.type.priv.aliasName) {
|
|
@@ -5636,7 +5652,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
5636
5652
|
const isFinalAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'Final');
|
|
5637
5653
|
const isClassVarAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'ClassVar');
|
|
5638
5654
|
// This feature is currently experimental.
|
|
5639
|
-
const supportsTypedDictTypeArg =
|
|
5655
|
+
const supportsTypedDictTypeArg = nodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures &&
|
|
5640
5656
|
types_1.ClassType.isBuiltIn(concreteSubtype, 'TypedDict');
|
|
5641
5657
|
let typeArgs = getTypeArgs(node, flags, {
|
|
5642
5658
|
isAnnotatedClass,
|
|
@@ -6056,7 +6072,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6056
6072
|
// treated as a type. The others can be regular (non-type) objects.
|
|
6057
6073
|
adjFlags =
|
|
6058
6074
|
32 /* EvalFlags.NoParamSpec */ | 64 /* EvalFlags.NoTypeVarTuple */ | 2 /* EvalFlags.NoSpecialize */ | 131072 /* EvalFlags.NoClassVar */;
|
|
6059
|
-
if ((0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(
|
|
6075
|
+
if ((0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(nodeInfo.getFileInfo(node))) {
|
|
6060
6076
|
adjFlags |= 4 /* EvalFlags.ForwardRefs */;
|
|
6061
6077
|
}
|
|
6062
6078
|
typeResult = {
|
|
@@ -6146,7 +6162,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6146
6162
|
function getTypeArg(node, flags, supportsDictExpression) {
|
|
6147
6163
|
let typeResult;
|
|
6148
6164
|
let adjustedFlags = flags | 128 /* EvalFlags.InstantiableType */ | 1 /* EvalFlags.ConvertEllipsisToAny */ | 8 /* EvalFlags.StrLiteralAsType */;
|
|
6149
|
-
const fileInfo =
|
|
6165
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
6150
6166
|
if (fileInfo.isStubFile) {
|
|
6151
6167
|
adjustedFlags |= 4 /* EvalFlags.ForwardRefs */;
|
|
6152
6168
|
}
|
|
@@ -6163,7 +6179,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6163
6179
|
}
|
|
6164
6180
|
else if (node.nodeType === 18 /* ParseNodeType.Dictionary */ && supportsDictExpression) {
|
|
6165
6181
|
const inlinedTypeDict = prefetched?.typedDictClass && (0, types_1.isInstantiableClass)(prefetched.typedDictClass)
|
|
6166
|
-
? (0, typedDicts_1.createTypedDictTypeInlined)(evaluatorInterface, node, prefetched.typedDictClass)
|
|
6182
|
+
? (0, typedDicts_1.createTypedDictTypeInlined)(evaluatorInterface, node, prefetched.typedDictClass, nodeInfo)
|
|
6167
6183
|
: undefined;
|
|
6168
6184
|
const keyTypeFallback = prefetched?.strClass && (0, types_1.isInstantiableClass)(prefetched.strClass)
|
|
6169
6185
|
? prefetched.strClass
|
|
@@ -6329,7 +6345,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6329
6345
|
// have invalid type parameters.
|
|
6330
6346
|
const isCyclicalTypeVarCall = (0, types_1.isInstantiableClass)(baseTypeResult.type) &&
|
|
6331
6347
|
types_1.ClassType.isBuiltIn(baseTypeResult.type, 'TypeVar') &&
|
|
6332
|
-
|
|
6348
|
+
nodeInfo.getFileInfo(node).isTypingStubFile;
|
|
6333
6349
|
const isTypeFormCall = (0, types_1.isInstantiableClass)(baseTypeResult.type) && isTypeFormClass(baseTypeResult.type);
|
|
6334
6350
|
if (!isCyclicalTypeVarCall && !isTypeFormCall) {
|
|
6335
6351
|
argList.forEach((arg) => {
|
|
@@ -6694,7 +6710,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6694
6710
|
let curNode = node;
|
|
6695
6711
|
let scope;
|
|
6696
6712
|
while (curNode) {
|
|
6697
|
-
scope =
|
|
6713
|
+
scope = getScopeForNode(curNode);
|
|
6698
6714
|
// Stop when we get a valid scope that's not a list comprehension
|
|
6699
6715
|
// scope. That includes lambdas, functions, classes, and modules.
|
|
6700
6716
|
if (scope && scope.type !== 1 /* ScopeType.Comprehension */) {
|
|
@@ -6726,7 +6742,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6726
6742
|
if (node.d.args.length > 2) {
|
|
6727
6743
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.superCallArgCount(), node.d.args[2]);
|
|
6728
6744
|
}
|
|
6729
|
-
const enclosingFunction = ParseTreeUtils.getEnclosingFunctionEvaluationScope(node);
|
|
6745
|
+
const enclosingFunction = ParseTreeUtils.getEnclosingFunctionEvaluationScope(node, nodeInfo);
|
|
6730
6746
|
const enclosingClass = enclosingFunction ? ParseTreeUtils.getEnclosingClass(enclosingFunction) : undefined;
|
|
6731
6747
|
const enclosingClassType = enclosingClass ? getTypeOfClass(enclosingClass)?.classType : undefined;
|
|
6732
6748
|
// Determine which class the "super" call is applied to. If
|
|
@@ -6748,7 +6764,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6748
6764
|
// This results in a runtime exception.
|
|
6749
6765
|
if (enclosingFunction) {
|
|
6750
6766
|
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, enclosingFunction,
|
|
6751
|
-
/* isInClass */ true);
|
|
6767
|
+
/* isInClass */ true, nodeInfo);
|
|
6752
6768
|
if ((functionInfo?.flags & 4 /* FunctionTypeFlags.StaticMethod */) !== 0) {
|
|
6753
6769
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.superCallZeroArgFormStaticMethod(), node.d.leftExpr);
|
|
6754
6770
|
}
|
|
@@ -6815,7 +6831,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
6815
6831
|
if (methodType.shared.parameters.length > 0 &&
|
|
6816
6832
|
types_1.FunctionParam.isTypeDeclared(methodType.shared.parameters[0])) {
|
|
6817
6833
|
let paramType = types_1.FunctionType.getParamType(methodType, 0);
|
|
6818
|
-
const liveScopeIds =
|
|
6834
|
+
const liveScopeIds = getTypeVarScopesForNode(node);
|
|
6819
6835
|
paramType = (0, typeUtils_1.makeTypeVarsBound)(paramType, liveScopeIds);
|
|
6820
6836
|
implicitBindToType = makeTopLevelTypeVarsConcrete(paramType);
|
|
6821
6837
|
}
|
|
@@ -7894,7 +7910,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7894
7910
|
if (types_1.FunctionType.isBuiltIn(type, 'namedtuple')) {
|
|
7895
7911
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUntypedNamedTuple, localize_1.LocMessage.namedTupleNoTypes(), errorNode);
|
|
7896
7912
|
const result = {
|
|
7897
|
-
returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList,
|
|
7913
|
+
returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList,
|
|
7914
|
+
/* includesTypes */ false, nodeInfo),
|
|
7898
7915
|
};
|
|
7899
7916
|
validateArgs(errorNode, argList, { type: type }, constraints, skipUnknownArgCheck, inferenceContext);
|
|
7900
7917
|
return result;
|
|
@@ -7968,18 +7985,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7968
7985
|
return undefined;
|
|
7969
7986
|
}
|
|
7970
7987
|
let isAbstract = false;
|
|
7971
|
-
const lastFunctionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, lastDecl.node,
|
|
7988
|
+
const lastFunctionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, lastDecl.node,
|
|
7989
|
+
/* isInClass */ true, nodeInfo);
|
|
7972
7990
|
if ((lastFunctionInfo.flags & 8 /* FunctionTypeFlags.AbstractMethod */) !== 0) {
|
|
7973
7991
|
isAbstract = true;
|
|
7974
7992
|
}
|
|
7975
|
-
const isStubFile =
|
|
7993
|
+
const isStubFile = nodeInfo.getFileInfo(lastDecl.node).isStubFile;
|
|
7976
7994
|
// In an overloaded method, the first overload can also be marked abstract.
|
|
7977
7995
|
// In stub files, there is no implementation, so this is the only way to mark
|
|
7978
7996
|
// an overloaded method as abstract.
|
|
7979
7997
|
const firstDecl = symbol.getDeclarations()[0];
|
|
7980
7998
|
let firstFunctionInfo;
|
|
7981
7999
|
if (firstDecl !== lastDecl && firstDecl.type === 5 /* DeclarationType.Function */) {
|
|
7982
|
-
firstFunctionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, firstDecl.node,
|
|
8000
|
+
firstFunctionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, firstDecl.node,
|
|
8001
|
+
/* isInClass */ true, nodeInfo);
|
|
7983
8002
|
if ((firstFunctionInfo.flags & 8 /* FunctionTypeFlags.AbstractMethod */) !== 0) {
|
|
7984
8003
|
isAbstract = true;
|
|
7985
8004
|
}
|
|
@@ -8129,7 +8148,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
8129
8148
|
}
|
|
8130
8149
|
if (className === 'NamedTuple') {
|
|
8131
8150
|
const result = {
|
|
8132
|
-
returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList,
|
|
8151
|
+
returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList,
|
|
8152
|
+
/* includesTypes */ true, nodeInfo),
|
|
8133
8153
|
};
|
|
8134
8154
|
const initTypeResult = (0, constructors_1.getBoundInitMethod)(evaluatorInterface, errorNode, types_1.ClassType.cloneAsInstance(expandedCallType),
|
|
8135
8155
|
/* diag */ undefined, 0 /* MemberAccessFlags.Default */);
|
|
@@ -8147,14 +8167,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
8147
8167
|
if (expandedCallType.shared.fullName === 'builtins.sentinel' ||
|
|
8148
8168
|
expandedCallType.shared.fullName === 'typing_extensions.sentinel' ||
|
|
8149
8169
|
expandedCallType.shared.fullName === 'typing_extensions.Sentinel') {
|
|
8150
|
-
return { returnType: (0, sentinel_1.createSentinelType)(evaluatorInterface, errorNode, argList) };
|
|
8170
|
+
return { returnType: (0, sentinel_1.createSentinelType)(evaluatorInterface, errorNode, argList, nodeInfo) };
|
|
8151
8171
|
}
|
|
8152
8172
|
if (types_1.ClassType.isSpecialFormClass(expandedCallType)) {
|
|
8153
8173
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.typeNotIntantiable().format({ type: className }), errorNode);
|
|
8154
8174
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true };
|
|
8155
8175
|
}
|
|
8156
8176
|
if (className === 'TypedDict') {
|
|
8157
|
-
return {
|
|
8177
|
+
return {
|
|
8178
|
+
returnType: (0, typedDicts_1.createTypedDictType)(evaluatorInterface, errorNode, expandedCallType, argList, nodeInfo),
|
|
8179
|
+
};
|
|
8158
8180
|
}
|
|
8159
8181
|
if (className === 'auto' && argList.length === 0) {
|
|
8160
8182
|
return { returnType: (0, enums_1.getEnumAutoValueType)(evaluatorInterface, errorNode) };
|
|
@@ -8165,9 +8187,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
8165
8187
|
expandedCallType.shared.effectiveMetaclass &&
|
|
8166
8188
|
(0, types_1.isClass)(expandedCallType.shared.effectiveMetaclass) &&
|
|
8167
8189
|
(0, enums_1.isEnumMetaclass)(expandedCallType.shared.effectiveMetaclass) &&
|
|
8168
|
-
!(0, enums_1.isEnumClassWithMembers)(evaluatorInterface, expandedCallType)) {
|
|
8190
|
+
!(0, enums_1.isEnumClassWithMembers)(evaluatorInterface, expandedCallType, nodeInfo)) {
|
|
8169
8191
|
return {
|
|
8170
|
-
returnType: (0, enums_1.createEnumType)(evaluatorInterface, errorNode, expandedCallType, argList) ??
|
|
8192
|
+
returnType: (0, enums_1.createEnumType)(evaluatorInterface, errorNode, expandedCallType, argList, nodeInfo) ??
|
|
8171
8193
|
(0, typeUtils_1.convertToInstance)(unexpandedCallType),
|
|
8172
8194
|
};
|
|
8173
8195
|
}
|
|
@@ -8241,7 +8263,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
8241
8263
|
newClassName = firstArgType.priv.literalValue;
|
|
8242
8264
|
}
|
|
8243
8265
|
}
|
|
8244
|
-
const newClassType = types_1.ClassType.createInstantiable(newClassName, '', '',
|
|
8266
|
+
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));
|
|
8245
8267
|
newClassType.shared.baseClasses.push(getBuiltInType(errorNode, 'object'));
|
|
8246
8268
|
newClassType.shared.effectiveMetaclass = expandedCallType;
|
|
8247
8269
|
newClassType.shared.declaration = returnType.shared.declaration;
|
|
@@ -8285,7 +8307,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
8285
8307
|
}
|
|
8286
8308
|
// Verify that the cast is necessary.
|
|
8287
8309
|
let castToType = getTypeOfArgExpectingType(argList[0], { typeExpression: true }).type;
|
|
8288
|
-
const liveScopeIds =
|
|
8310
|
+
const liveScopeIds = getTypeVarScopesForNode(errorNode);
|
|
8289
8311
|
castToType = (0, typeUtils_1.makeTypeVarsBound)(castToType, liveScopeIds);
|
|
8290
8312
|
let castFromType = getTypeOfArg(argList[1], /* inferenceContext */ undefined).type;
|
|
8291
8313
|
if (castFromType.props?.specialForm) {
|
|
@@ -9262,7 +9284,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9262
9284
|
return validateArgTypesWithExpectedType(errorNode, matchResults, constraints, skipUnknownArgCheck, expectedType, returnType);
|
|
9263
9285
|
}
|
|
9264
9286
|
function validateArgTypesWithExpectedType(errorNode, matchResults, constraints, skipUnknownArgCheck = false, expectedType, returnType) {
|
|
9265
|
-
const liveTypeVarScopes =
|
|
9287
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(errorNode);
|
|
9266
9288
|
let assignFlags = 2048 /* AssignTypeFlags.PopulateExpectedType */;
|
|
9267
9289
|
if ((0, typeUtils_1.containsLiteralType)(expectedType, /* includeTypeArgs */ true)) {
|
|
9268
9290
|
assignFlags |= 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
|
@@ -9483,7 +9505,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9483
9505
|
if ((0, types_1.isUnpackedClass)(specializedReturnType)) {
|
|
9484
9506
|
specializedReturnType = types_1.ClassType.cloneForPacked(specializedReturnType);
|
|
9485
9507
|
}
|
|
9486
|
-
const liveTypeVarScopes =
|
|
9508
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(errorNode);
|
|
9487
9509
|
specializedReturnType = adjustCallableReturnType(errorNode, specializedReturnType, liveTypeVarScopes);
|
|
9488
9510
|
if (specializedInitSelfType) {
|
|
9489
9511
|
specializedInitSelfType = solveAndApplyConstraints(specializedInitSelfType, constraints);
|
|
@@ -9546,7 +9568,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9546
9568
|
// Create a new scope ID based on the caller's position. This
|
|
9547
9569
|
// will guarantee uniqueness. If another caller uses the same
|
|
9548
9570
|
// call and arguments, the type vars will not conflict.
|
|
9549
|
-
const newScopeId =
|
|
9571
|
+
const newScopeId = getScopeIdForNode(callNode);
|
|
9550
9572
|
const solution = new constraintSolution_1.ConstraintSolution();
|
|
9551
9573
|
const newTypeParams = typeParams.map((typeVar) => {
|
|
9552
9574
|
const newTypeParam = types_1.TypeVarType.cloneForScopeId(typeVar, newScopeId, typeVar.priv.scopeName, 1 /* TypeVarScopeType.Function */);
|
|
@@ -9818,7 +9840,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9818
9840
|
if (!options?.skipReportError) {
|
|
9819
9841
|
// Mismatching parameter types are common in untyped code; don't bother spending time
|
|
9820
9842
|
// printing types if the diagnostic is disabled.
|
|
9821
|
-
const fileInfo =
|
|
9843
|
+
const fileInfo = nodeInfo.getFileInfo(argParam.errorNode);
|
|
9822
9844
|
if (fileInfo.diagnosticRuleSet.reportArgumentType !== 'none' &&
|
|
9823
9845
|
!canSkipDiagnosticForNode(argParam.errorNode) &&
|
|
9824
9846
|
!isTypeIncomplete) {
|
|
@@ -9870,7 +9892,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9870
9892
|
}
|
|
9871
9893
|
if (!options.skipUnknownArgCheck) {
|
|
9872
9894
|
const simplifiedType = makeTopLevelTypeVarsConcrete((0, types_1.removeUnbound)(argType));
|
|
9873
|
-
const fileInfo =
|
|
9895
|
+
const fileInfo = nodeInfo.getFileInfo(argParam.errorNode);
|
|
9874
9896
|
function getDiagAddendum() {
|
|
9875
9897
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
|
9876
9898
|
if (argParam.paramName) {
|
|
@@ -9993,7 +10015,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9993
10015
|
}).type;
|
|
9994
10016
|
typeVar.shared.defaultType = (0, typeUtils_1.convertToInstance)(argType);
|
|
9995
10017
|
typeVar.shared.isDefaultExplicit = true;
|
|
9996
|
-
const fileInfo =
|
|
10018
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
9997
10019
|
if (!fileInfo.isStubFile &&
|
|
9998
10020
|
pythonVersion_1.PythonVersion.isLessThan(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_13) &&
|
|
9999
10021
|
classType.shared.moduleName !== 'typing_extensions') {
|
|
@@ -10099,7 +10121,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10099
10121
|
typeVar.shared.isDefaultExplicit = true;
|
|
10100
10122
|
}
|
|
10101
10123
|
}
|
|
10102
|
-
const fileInfo =
|
|
10124
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
10103
10125
|
if (!fileInfo.isStubFile &&
|
|
10104
10126
|
pythonVersion_1.PythonVersion.isLessThan(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_13) &&
|
|
10105
10127
|
classType.shared.moduleName !== 'typing_extensions') {
|
|
@@ -10160,7 +10182,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10160
10182
|
paramSpec.shared.isDefaultExplicit = true;
|
|
10161
10183
|
}
|
|
10162
10184
|
}
|
|
10163
|
-
const fileInfo =
|
|
10185
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
10164
10186
|
if (!fileInfo.isStubFile &&
|
|
10165
10187
|
pythonVersion_1.PythonVersion.isLessThan(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_13) &&
|
|
10166
10188
|
classType.shared.moduleName !== 'typing_extensions') {
|
|
@@ -10239,7 +10261,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10239
10261
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeMustBeAssigned(), errorNode);
|
|
10240
10262
|
return undefined;
|
|
10241
10263
|
}
|
|
10242
|
-
const scope =
|
|
10264
|
+
const scope = getScopeForNode(errorNode);
|
|
10243
10265
|
if (scope) {
|
|
10244
10266
|
if (scope.type !== 3 /* ScopeType.Class */ && scope.type !== 4 /* ScopeType.Module */ && scope.type !== 5 /* ScopeType.Builtin */) {
|
|
10245
10267
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeBadScope(), errorNode.parent.d.leftExpr);
|
|
@@ -10300,7 +10322,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10300
10322
|
isTypeParamListValid = false;
|
|
10301
10323
|
}
|
|
10302
10324
|
else {
|
|
10303
|
-
entryType = types_1.TypeVarType.cloneForScopeId(entryType,
|
|
10325
|
+
entryType = types_1.TypeVarType.cloneForScopeId(entryType, getScopeIdForNode(nameNode), nameNode.d.value, 2 /* TypeVarScopeType.TypeAlias */);
|
|
10304
10326
|
}
|
|
10305
10327
|
typeParams.push(entryType);
|
|
10306
10328
|
}
|
|
@@ -10346,7 +10368,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10346
10368
|
// in the Python specification: The static type checker will treat
|
|
10347
10369
|
// the new type as if it were a subclass of the original type.
|
|
10348
10370
|
function createNewType(errorNode, argList) {
|
|
10349
|
-
const fileInfo =
|
|
10371
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
10350
10372
|
let className = '';
|
|
10351
10373
|
if (argList.length !== 2) {
|
|
10352
10374
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.newTypeParamCount(), errorNode);
|
|
@@ -10415,7 +10437,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10415
10437
|
}
|
|
10416
10438
|
// Implements the semantics of the multi-parameter variant of the "type" call.
|
|
10417
10439
|
function createClassFromMetaclass(errorNode, argList, metaclass) {
|
|
10418
|
-
const fileInfo =
|
|
10440
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
10419
10441
|
const arg0Type = getTypeOfArg(argList[0], /* inferenceContext */ undefined).type;
|
|
10420
10442
|
if (!(0, types_1.isClassInstance)(arg0Type) || !types_1.ClassType.isBuiltIn(arg0Type, 'str')) {
|
|
10421
10443
|
return undefined;
|
|
@@ -10663,7 +10685,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10663
10685
|
return undefined;
|
|
10664
10686
|
}
|
|
10665
10687
|
const dictConstraints = new constraintTracker_1.ConstraintTracker();
|
|
10666
|
-
if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictConstraints,
|
|
10688
|
+
if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictConstraints, getTypeVarScopesForNode(node), node.start)) {
|
|
10667
10689
|
return undefined;
|
|
10668
10690
|
}
|
|
10669
10691
|
const specializedDict = solveAndApplyConstraints(types_1.ClassType.cloneAsInstantiable(builtInDict), dictConstraints);
|
|
@@ -10728,7 +10750,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10728
10750
|
const keyTypes = keyTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, !hasExpectedType)));
|
|
10729
10751
|
const valueTypes = valueTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, !hasExpectedType)));
|
|
10730
10752
|
if (keyTypes.length > 0) {
|
|
10731
|
-
if (
|
|
10753
|
+
if (nodeInfo.getFileInfo(node).diagnosticRuleSet.strictDictionaryInference || hasExpectedType) {
|
|
10732
10754
|
keyType = (0, types_1.combineTypes)(keyTypes);
|
|
10733
10755
|
}
|
|
10734
10756
|
else {
|
|
@@ -10744,7 +10766,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10744
10766
|
// are the same type, we'll assume that all values in this dictionary should
|
|
10745
10767
|
// be the same.
|
|
10746
10768
|
if (valueTypes.length > 0) {
|
|
10747
|
-
if (
|
|
10769
|
+
if (nodeInfo.getFileInfo(node).diagnosticRuleSet.strictDictionaryInference || hasExpectedType) {
|
|
10748
10770
|
valueType = (0, types_1.combineTypes)(valueTypes);
|
|
10749
10771
|
}
|
|
10750
10772
|
else {
|
|
@@ -10804,7 +10826,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10804
10826
|
let effectiveValueType = expectedTypedDictEntries.knownItems.get(keyType.priv.literalValue)?.valueType ??
|
|
10805
10827
|
expectedTypedDictEntries.extraItems?.valueType;
|
|
10806
10828
|
if (effectiveValueType) {
|
|
10807
|
-
const liveTypeVarScopes =
|
|
10829
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(node);
|
|
10808
10830
|
effectiveValueType = (0, typeUtils_1.transformExpectedType)(effectiveValueType, liveTypeVarScopes, node.start);
|
|
10809
10831
|
}
|
|
10810
10832
|
entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
|
|
@@ -10813,7 +10835,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
10813
10835
|
else {
|
|
10814
10836
|
let effectiveValueType = expectedValueType ?? (forceStrictInference ? types_1.NeverType.createNever() : undefined);
|
|
10815
10837
|
if (effectiveValueType) {
|
|
10816
|
-
const liveTypeVarScopes =
|
|
10838
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(node);
|
|
10817
10839
|
effectiveValueType = (0, typeUtils_1.transformExpectedType)(effectiveValueType, liveTypeVarScopes, node.start);
|
|
10818
10840
|
}
|
|
10819
10841
|
entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
|
|
@@ -11070,7 +11092,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11070
11092
|
return undefined;
|
|
11071
11093
|
}
|
|
11072
11094
|
const constraints = new constraintTracker_1.ConstraintTracker();
|
|
11073
|
-
if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(expectedClassType), inferenceContext.expectedType, constraints,
|
|
11095
|
+
if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(expectedClassType), inferenceContext.expectedType, constraints, getTypeVarScopesForNode(node), node.start)) {
|
|
11074
11096
|
return undefined;
|
|
11075
11097
|
}
|
|
11076
11098
|
const specializedListOrSet = solveAndApplyConstraints(expectedClassType, constraints);
|
|
@@ -11112,7 +11134,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11112
11134
|
entryTypes = entryTypes.map((t) => stripLiteralValue(t));
|
|
11113
11135
|
let inferredEntryType = hasExpectedType ? types_1.AnyType.create() : types_1.UnknownType.create();
|
|
11114
11136
|
if (entryTypes.length > 0) {
|
|
11115
|
-
const fileInfo =
|
|
11137
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
11116
11138
|
// If there was an expected type or we're using strict list inference,
|
|
11117
11139
|
// combine the types into a union.
|
|
11118
11140
|
if ((builtInClassName === 'list' && fileInfo.diagnosticRuleSet.strictListInference) ||
|
|
@@ -11205,7 +11227,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11205
11227
|
if (functionTypeInfo) {
|
|
11206
11228
|
let returnType = types_1.FunctionType.getEffectiveReturnType(functionTypeInfo.functionType);
|
|
11207
11229
|
if (returnType) {
|
|
11208
|
-
const liveScopeIds =
|
|
11230
|
+
const liveScopeIds = getTypeVarScopesForNode(node);
|
|
11209
11231
|
returnType = (0, typeUtils_1.makeTypeVarsBound)(returnType, liveScopeIds);
|
|
11210
11232
|
expectedYieldType = (0, typeUtils_1.getGeneratorYieldType)(returnType, !!enclosingFunction.d.isAsync);
|
|
11211
11233
|
const generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(returnType);
|
|
@@ -11287,13 +11309,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11287
11309
|
let expectedReturnType;
|
|
11288
11310
|
let expectedParamDetails;
|
|
11289
11311
|
if (expectedType) {
|
|
11290
|
-
const liveTypeVarScopes =
|
|
11312
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(node);
|
|
11291
11313
|
expectedType = (0, typeUtils_1.transformExpectedType)(expectedType, liveTypeVarScopes, node.start);
|
|
11292
11314
|
expectedParamDetails = (0, parameterUtils_1.getParamListDetails)(expectedType);
|
|
11293
11315
|
expectedReturnType = getEffectiveReturnType(expectedType);
|
|
11294
11316
|
}
|
|
11295
11317
|
let functionType = types_1.FunctionType.createInstance('', '', '', 131072 /* FunctionTypeFlags.PartiallyEvaluated */);
|
|
11296
|
-
functionType.shared.typeVarScopeId =
|
|
11318
|
+
functionType.shared.typeVarScopeId = getScopeIdForNode(node);
|
|
11297
11319
|
return (0, cancellationUtils_1.invalidateTypeCacheIfCanceled)(() => {
|
|
11298
11320
|
// Pre-cache the incomplete function type in case the evaluation of the
|
|
11299
11321
|
// lambda depends on itself.
|
|
@@ -11655,7 +11677,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
11655
11677
|
let isValidTypeForm = true;
|
|
11656
11678
|
types_1.TypeBase.setSpecialForm(functionType, types_1.ClassType.cloneAsInstance(classType));
|
|
11657
11679
|
functionType.shared.declaredReturnType = types_1.UnknownType.create();
|
|
11658
|
-
functionType.shared.typeVarScopeId =
|
|
11680
|
+
functionType.shared.typeVarScopeId = getScopeIdForNode(errorNode);
|
|
11659
11681
|
if (typeArgs && typeArgs.length > 0) {
|
|
11660
11682
|
functionType.priv.isCallableWithTypeArgs = true;
|
|
11661
11683
|
if (typeArgs[0].typeList) {
|
|
@@ -12034,7 +12056,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12034
12056
|
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(errorNode);
|
|
12035
12057
|
if (enclosingFunction) {
|
|
12036
12058
|
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, enclosingFunction,
|
|
12037
|
-
/* isInClass */ true);
|
|
12059
|
+
/* isInClass */ true, nodeInfo);
|
|
12038
12060
|
const isInnerFunction = !!ParseTreeUtils.getEnclosingFunction(enclosingFunction);
|
|
12039
12061
|
if (!isInnerFunction) {
|
|
12040
12062
|
// Check for static methods.
|
|
@@ -12388,7 +12410,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12388
12410
|
}
|
|
12389
12411
|
// Unpacks the index expression for a "Union[X, Y, Z]" type annotation.
|
|
12390
12412
|
function createUnionType(classType, errorNode, typeArgs, flags) {
|
|
12391
|
-
const fileInfo =
|
|
12413
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
12392
12414
|
const types = [];
|
|
12393
12415
|
let allowSingleTypeArg = false;
|
|
12394
12416
|
let isValidTypeForm = true;
|
|
@@ -12571,7 +12593,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12571
12593
|
return typeAlias;
|
|
12572
12594
|
}
|
|
12573
12595
|
function createSpecialBuiltInClass(node, assignedName, aliasMapEntry) {
|
|
12574
|
-
const fileInfo =
|
|
12596
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
12575
12597
|
let specialClassType = types_1.ClassType.createInstantiable(assignedName, ParseTreeUtils.getClassFullName(node, fileInfo.moduleName, assignedName), fileInfo.moduleName, fileInfo.fileUri, 1 /* ClassTypeFlags.BuiltIn */ | 2 /* ClassTypeFlags.SpecialBuiltIn */,
|
|
12576
12598
|
/* typeSourceId */ 0,
|
|
12577
12599
|
/* declaredMetaclass */ undefined,
|
|
@@ -12586,12 +12608,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12586
12608
|
// specified in the alias map entry.
|
|
12587
12609
|
if (aliasMapEntry.typeParamVariance !== undefined) {
|
|
12588
12610
|
let typeParam = types_1.TypeVarType.createInstance('T');
|
|
12589
|
-
typeParam = types_1.TypeVarType.cloneForScopeId(typeParam,
|
|
12611
|
+
typeParam = types_1.TypeVarType.cloneForScopeId(typeParam, getScopeIdForNode(node), assignedName, 0 /* TypeVarScopeType.Class */);
|
|
12590
12612
|
typeParam.shared.declaredVariance = aliasMapEntry.typeParamVariance;
|
|
12591
12613
|
specialClassType.shared.typeParams.push(typeParam);
|
|
12592
12614
|
}
|
|
12593
|
-
const specialBuiltInClassDeclaration = (
|
|
12594
|
-
(node.parent ?
|
|
12615
|
+
const specialBuiltInClassDeclaration = (nodeInfo.getDeclaration(node) ??
|
|
12616
|
+
(node.parent ? nodeInfo.getDeclaration(node.parent) : undefined));
|
|
12595
12617
|
specialClassType.shared.declaration = specialBuiltInClassDeclaration;
|
|
12596
12618
|
if (fileInfo.isTypingExtensionsStubFile) {
|
|
12597
12619
|
specialClassType.shared.flags |= 4096 /* ClassTypeFlags.TypingExtensionClass */;
|
|
@@ -12782,7 +12804,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12782
12804
|
}
|
|
12783
12805
|
}
|
|
12784
12806
|
function evaluateTypesForAssignmentStatement(node) {
|
|
12785
|
-
const fileInfo =
|
|
12807
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
12786
12808
|
// If the entire statement has already been evaluated, don't
|
|
12787
12809
|
// re-evaluate it.
|
|
12788
12810
|
if (isTypeCached(node)) {
|
|
@@ -12874,7 +12896,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12874
12896
|
declaredType = getDeclaredTypeForExpression(node.d.leftExpr, { method: 'set' });
|
|
12875
12897
|
}
|
|
12876
12898
|
if (declaredType) {
|
|
12877
|
-
const liveTypeVarScopes =
|
|
12899
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(node);
|
|
12878
12900
|
declaredType = (0, typeUtils_1.makeTypeVarsBound)(declaredType, liveTypeVarScopes);
|
|
12879
12901
|
}
|
|
12880
12902
|
const srcTypeResult = getTypeOfExpression(node.d.rightExpr, flags, (0, typeUtils_1.makeInferenceContext)(declaredType));
|
|
@@ -12928,8 +12950,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12928
12950
|
function synthesizeTypeAliasPlaceholder(nameNode, isTypeAliasType = false) {
|
|
12929
12951
|
const placeholder = types_1.TypeVarType.createInstantiable(`__type_alias_${nameNode.d.value}`);
|
|
12930
12952
|
placeholder.shared.isSynthesized = true;
|
|
12931
|
-
const typeVarScopeId =
|
|
12932
|
-
const fileInfo =
|
|
12953
|
+
const typeVarScopeId = getScopeIdForNode(nameNode);
|
|
12954
|
+
const fileInfo = nodeInfo.getFileInfo(nameNode);
|
|
12933
12955
|
placeholder.shared.recursiveAlias = {
|
|
12934
12956
|
name: nameNode.d.value,
|
|
12935
12957
|
fullName: ParseTreeUtils.getClassFullName(nameNode, fileInfo.moduleName, nameNode.d.value),
|
|
@@ -12968,9 +12990,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
12968
12990
|
// Write the type to the type cache to support recursive type alias definitions.
|
|
12969
12991
|
writeTypeCache(nameNode, { type: typeAliasTypeVar }, /* flags */ undefined);
|
|
12970
12992
|
// Set a partial type to handle recursive (self-referential) type aliases.
|
|
12971
|
-
const scope =
|
|
12993
|
+
const scope = getScopeForNode(declNode);
|
|
12972
12994
|
const typeAliasSymbol = scope?.lookUpSymbolRecursive(nameNode.d.value);
|
|
12973
|
-
const typeAliasDecl =
|
|
12995
|
+
const typeAliasDecl = nodeInfo.getDeclaration(declNode);
|
|
12974
12996
|
if (typeAliasDecl && typeAliasSymbol) {
|
|
12975
12997
|
setSymbolResolutionPartialType(typeAliasSymbol.symbol, typeAliasDecl, typeAliasTypeVar);
|
|
12976
12998
|
}
|
|
@@ -13038,7 +13060,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13038
13060
|
const className = `<subclass of ${printType((0, typeUtils_1.convertToInstance)(type1), {
|
|
13039
13061
|
omitTypeArgsIfUnknown: true,
|
|
13040
13062
|
})} and ${printType((0, typeUtils_1.convertToInstance)(type2), { omitTypeArgsIfUnknown: true })}>`;
|
|
13041
|
-
const fileInfo =
|
|
13063
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
13042
13064
|
// The effective metaclass of the intersection is the narrower of the two metaclasses.
|
|
13043
13065
|
let effectiveMetaclass = type1.shared.effectiveMetaclass;
|
|
13044
13066
|
if (type2.shared.effectiveMetaclass) {
|
|
@@ -13073,8 +13095,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13073
13095
|
};
|
|
13074
13096
|
}
|
|
13075
13097
|
// The type wasn't cached, so we need to create a new one.
|
|
13076
|
-
const scope =
|
|
13077
|
-
const fileInfo =
|
|
13098
|
+
const scope = getScopeForNode(node);
|
|
13099
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
13078
13100
|
let classFlags = 0 /* ClassTypeFlags.None */;
|
|
13079
13101
|
if (scope?.type === 5 /* ScopeType.Builtin */ ||
|
|
13080
13102
|
fileInfo.isTypingStubFile ||
|
|
@@ -13098,7 +13120,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13098
13120
|
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
13121
|
/* declaredMetaclass */ undefined,
|
|
13100
13122
|
/* effectiveMetaclass */ undefined, ParseTreeUtils.getDocString(node.d.suite.d.statements));
|
|
13101
|
-
classType.shared.typeVarScopeId =
|
|
13123
|
+
classType.shared.typeVarScopeId = getScopeIdForNode(node);
|
|
13102
13124
|
// Is this a special type that supports type promotions according to PEP 484?
|
|
13103
13125
|
if (typePromotions.has(classType.shared.fullName)) {
|
|
13104
13126
|
classType.priv.includePromotions = true;
|
|
@@ -13108,7 +13130,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13108
13130
|
// to allow these to be resolved.
|
|
13109
13131
|
const classSymbol = scope?.lookUpSymbol(node.d.name.d.value);
|
|
13110
13132
|
let classDecl;
|
|
13111
|
-
const decl =
|
|
13133
|
+
const decl = nodeInfo.getDeclaration(node);
|
|
13112
13134
|
if (decl) {
|
|
13113
13135
|
classDecl = decl;
|
|
13114
13136
|
}
|
|
@@ -13451,7 +13473,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13451
13473
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.methodOrdering(), node.d.name);
|
|
13452
13474
|
}
|
|
13453
13475
|
// The scope for this class becomes the "fields" for the corresponding type.
|
|
13454
|
-
const innerScope =
|
|
13476
|
+
const innerScope = getScopeForNode(node.d.suite);
|
|
13455
13477
|
classType.shared.fields = innerScope?.symbolTable
|
|
13456
13478
|
? new Map(innerScope.symbolTable)
|
|
13457
13479
|
: new Map();
|
|
@@ -13496,9 +13518,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13496
13518
|
classType.shared.typeParams = genericParams.map((param) => {
|
|
13497
13519
|
const typeVar = types_1.TypeVarType.createInstance(getPseudoGenericTypeVarName(param.d.name.d.value));
|
|
13498
13520
|
typeVar.shared.isSynthesized = true;
|
|
13499
|
-
typeVar.priv.scopeId =
|
|
13521
|
+
typeVar.priv.scopeId = getScopeIdForNode(initDeclNode);
|
|
13500
13522
|
typeVar.shared.boundType = types_1.UnknownType.create();
|
|
13501
|
-
return types_1.TypeVarType.cloneForScopeId(typeVar,
|
|
13523
|
+
return types_1.TypeVarType.cloneForScopeId(typeVar, getScopeIdForNode(node), node.d.name.d.value, 0 /* TypeVarScopeType.Class */);
|
|
13502
13524
|
});
|
|
13503
13525
|
}
|
|
13504
13526
|
}
|
|
@@ -13542,7 +13564,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13542
13564
|
}
|
|
13543
13565
|
const effectiveMetaclass = computeEffectiveMetaclass(classType, node.d.name);
|
|
13544
13566
|
const enumMemberSetMayBeDynamicallyModified = types_1.ClassType.isEnumClass(classType) &&
|
|
13545
|
-
(
|
|
13567
|
+
(nodeInfo.getScope(node)?.hasPotentiallyDynamicSymbolTable ||
|
|
13546
13568
|
classType.shared.mro.some((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isEnumMemberSetMayBeDynamicallyModified(mroClass)));
|
|
13547
13569
|
if (enumMemberSetMayBeDynamicallyModified) {
|
|
13548
13570
|
classType.shared.flags |= 67108864 /* ClassTypeFlags.EnumMemberSetMayBeDynamicallyModified */;
|
|
@@ -13565,7 +13587,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13565
13587
|
let foundUnknown = false;
|
|
13566
13588
|
for (let i = node.d.decorators.length - 1; i >= 0; i--) {
|
|
13567
13589
|
const decorator = node.d.decorators[i];
|
|
13568
|
-
const newDecoratedType = useSignatureTracker(node.parent ?? node, () => (0, decorators_1.applyClassDecorator)(evaluatorInterface, decoratedType, classType, decorator));
|
|
13590
|
+
const newDecoratedType = useSignatureTracker(node.parent ?? node, () => (0, decorators_1.applyClassDecorator)(evaluatorInterface, decoratedType, classType, decorator, nodeInfo));
|
|
13569
13591
|
const unknownOrAny = (0, typeUtils_1.containsAnyOrUnknown)(newDecoratedType, /* recurse */ false);
|
|
13570
13592
|
if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
|
|
13571
13593
|
// Report this error only on the first unknown type.
|
|
@@ -13596,7 +13618,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13596
13618
|
}
|
|
13597
13619
|
}
|
|
13598
13620
|
if (dataClassBehaviors) {
|
|
13599
|
-
(0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, node.d.name, classType, initSubclassArgs, dataClassBehaviors);
|
|
13621
|
+
(0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, node.d.name, classType, initSubclassArgs, dataClassBehaviors, nodeInfo);
|
|
13600
13622
|
}
|
|
13601
13623
|
// Run any deferred class completions that depend on this class.
|
|
13602
13624
|
runDeferredClassCompletions(classType);
|
|
@@ -13620,7 +13642,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13620
13642
|
if (foundInvalidBaseClass) {
|
|
13621
13643
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictBaseClass() + diag.getString(), node.d.name);
|
|
13622
13644
|
}
|
|
13623
|
-
(0, typedDicts_1.synthesizeTypedDictClassMethods)(evaluatorInterface, node, classType);
|
|
13645
|
+
(0, typedDicts_1.synthesizeTypedDictClassMethods)(evaluatorInterface, node, classType, nodeInfo);
|
|
13624
13646
|
}
|
|
13625
13647
|
// Synthesize dataclass methods.
|
|
13626
13648
|
if (types_1.ClassType.isDataClass(classType) || isNamedTupleSubclass) {
|
|
@@ -13641,7 +13663,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13641
13663
|
if (hashSymbol && hashSymbol.isClassMember() && !hashSymbol.getSynthesizedType()) {
|
|
13642
13664
|
skipSynthesizeHash = true;
|
|
13643
13665
|
}
|
|
13644
|
-
const synthesizeMethods = () => (0, dataClasses_1.synthesizeDataClassMethods)(evaluatorInterface, node, classType, isNamedTupleSubclass, skipSynthesizedInit, hasExistingInitMethod, skipSynthesizeHash);
|
|
13666
|
+
const synthesizeMethods = () => (0, dataClasses_1.synthesizeDataClassMethods)(evaluatorInterface, node, classType, isNamedTupleSubclass, skipSynthesizedInit, hasExistingInitMethod, skipSynthesizeHash, nodeInfo);
|
|
13645
13667
|
// If this is a NamedTuple subclass, immediately synthesize dataclass methods
|
|
13646
13668
|
// because we also need to update the MRO classes in this case. For regular
|
|
13647
13669
|
// dataclasses, we'll defer the method synthesis to avoid circular dependencies.
|
|
@@ -13805,7 +13827,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
13805
13827
|
}
|
|
13806
13828
|
function evaluateTypeParamList(node) {
|
|
13807
13829
|
const paramTypes = [];
|
|
13808
|
-
const typeParamScope =
|
|
13830
|
+
const typeParamScope = nodeInfo.getScope(node);
|
|
13809
13831
|
node.d.params.forEach((param) => {
|
|
13810
13832
|
const paramSymbol = typeParamScope?.symbolTable.get(param.d.name.d.value);
|
|
13811
13833
|
if (!paramSymbol) {
|
|
@@ -14091,7 +14113,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14091
14113
|
const decorator = node.d.decorators[i];
|
|
14092
14114
|
const newDecoratedType = useSignatureTracker(node.parent ?? node, () => {
|
|
14093
14115
|
(0, debug_1.assert)(decoratedType !== undefined);
|
|
14094
|
-
return (0, decorators_1.applyFunctionDecorator)(evaluatorInterface, decoratedType, functionType, decorator, node);
|
|
14116
|
+
return (0, decorators_1.applyFunctionDecorator)(evaluatorInterface, decoratedType, functionType, decorator, node, nodeInfo);
|
|
14095
14117
|
});
|
|
14096
14118
|
const unknownOrAny = (0, typeUtils_1.containsAnyOrUnknown)(newDecoratedType, /* recurse */ false);
|
|
14097
14119
|
if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
|
|
@@ -14116,7 +14138,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14116
14138
|
});
|
|
14117
14139
|
}
|
|
14118
14140
|
}
|
|
14119
|
-
decoratedType = (0, decorators_1.addOverloadsToFunctionType)(evaluatorInterface, node, decoratedType);
|
|
14141
|
+
decoratedType = (0, decorators_1.addOverloadsToFunctionType)(evaluatorInterface, node, decoratedType, nodeInfo);
|
|
14120
14142
|
writeTypeCache(node, { type: decoratedType }, 0 /* EvalFlags.None */);
|
|
14121
14143
|
// Now that the decorator has been applied, we can clear the
|
|
14122
14144
|
// "partially evaluated" flag.
|
|
@@ -14126,14 +14148,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14126
14148
|
// Evaluates the type of a "def" statement without applying an async
|
|
14127
14149
|
// modifier or any decorators.
|
|
14128
14150
|
function getTypeOfFunctionPredecorated(node) {
|
|
14129
|
-
const fileInfo =
|
|
14151
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
14130
14152
|
// Is this type already cached?
|
|
14131
14153
|
const cachedFunctionType = readTypeCache(node.d.name, 0 /* EvalFlags.None */);
|
|
14132
14154
|
if (cachedFunctionType && (0, types_1.isFunction)(cachedFunctionType)) {
|
|
14133
14155
|
return cachedFunctionType;
|
|
14134
14156
|
}
|
|
14135
14157
|
let functionDecl;
|
|
14136
|
-
const decl =
|
|
14158
|
+
const decl = nodeInfo.getDeclaration(node);
|
|
14137
14159
|
if (decl) {
|
|
14138
14160
|
functionDecl = decl;
|
|
14139
14161
|
}
|
|
@@ -14144,7 +14166,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14144
14166
|
if (containingClassNode) {
|
|
14145
14167
|
containingClassType = getTypeOfClass(containingClassNode)?.classType;
|
|
14146
14168
|
}
|
|
14147
|
-
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, node, !!containingClassNode);
|
|
14169
|
+
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, node, !!containingClassNode, nodeInfo);
|
|
14148
14170
|
let functionFlags = functionInfo.flags;
|
|
14149
14171
|
if (functionDecl?.isGenerator) {
|
|
14150
14172
|
functionFlags |= 16 /* FunctionTypeFlags.Generator */;
|
|
@@ -14159,12 +14181,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14159
14181
|
functionFlags |= 512 /* FunctionTypeFlags.Async */;
|
|
14160
14182
|
}
|
|
14161
14183
|
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 =
|
|
14184
|
+
functionType.shared.typeVarScopeId = getScopeIdForNode(node);
|
|
14163
14185
|
functionType.shared.deprecatedMessage = functionInfo.deprecationMessage;
|
|
14164
14186
|
functionType.shared.methodClass = containingClassType;
|
|
14165
14187
|
if (node.d.name.d.value === '__init__' || node.d.name.d.value === '__new__') {
|
|
14166
14188
|
if (containingClassNode) {
|
|
14167
|
-
functionType.priv.constructorTypeVarScopeId =
|
|
14189
|
+
functionType.priv.constructorTypeVarScopeId = getScopeIdForNode(containingClassNode);
|
|
14168
14190
|
}
|
|
14169
14191
|
}
|
|
14170
14192
|
if (fileInfo.isBuiltInStubFile || fileInfo.isTypingStubFile || fileInfo.isTypingExtensionsStubFile) {
|
|
@@ -14173,7 +14195,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14173
14195
|
}
|
|
14174
14196
|
functionType.shared.declaration = functionDecl;
|
|
14175
14197
|
// Allow recursion by caching and registering the partially-constructed function type.
|
|
14176
|
-
const scope =
|
|
14198
|
+
const scope = getScopeForNode(node);
|
|
14177
14199
|
const functionSymbol = scope?.lookUpSymbolRecursive(node.d.name.d.value);
|
|
14178
14200
|
if (functionDecl && functionSymbol) {
|
|
14179
14201
|
setSymbolResolutionPartialType(functionSymbol.symbol, functionDecl, functionType);
|
|
@@ -14372,7 +14394,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14372
14394
|
types_1.FunctionType.addPositionOnlyParamSeparator(functionType);
|
|
14373
14395
|
}
|
|
14374
14396
|
// Update the types for the nodes associated with the parameters.
|
|
14375
|
-
const scopeIds =
|
|
14397
|
+
const scopeIds = getTypeVarScopesForNode(node);
|
|
14376
14398
|
paramTypes.forEach((paramType, index) => {
|
|
14377
14399
|
const paramNameNode = node.d.params[index].d.name;
|
|
14378
14400
|
if (paramNameNode) {
|
|
@@ -14456,7 +14478,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14456
14478
|
const symbolWithScope = lookUpSymbolRecursive(param.d.name, param.d.name.d.value,
|
|
14457
14479
|
/* honorCodeFlow */ false);
|
|
14458
14480
|
if (symbolWithScope) {
|
|
14459
|
-
setSymbolAccessed(
|
|
14481
|
+
setSymbolAccessed(nodeInfo.getFileInfo(param), symbolWithScope.symbol, param.d.name);
|
|
14460
14482
|
}
|
|
14461
14483
|
}
|
|
14462
14484
|
}
|
|
@@ -14468,7 +14490,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14468
14490
|
if (param.d.defaultValue?.nodeType === 14 /* ParseNodeType.Constant */ &&
|
|
14469
14491
|
param.d.defaultValue.d.constType === 27 /* KeywordType.None */ &&
|
|
14470
14492
|
!(0, typeUtils_1.isOptionalType)(type) &&
|
|
14471
|
-
!
|
|
14493
|
+
!nodeInfo.getFileInfo(param).diagnosticRuleSet.strictParameterNoneValue) {
|
|
14472
14494
|
return (0, types_1.combineTypes)([type, getNoneType()]);
|
|
14473
14495
|
}
|
|
14474
14496
|
return type;
|
|
@@ -14506,7 +14528,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14506
14528
|
if ((0, typeUtils_1.requiresSpecialization)(inferredParamType) && (0, types_1.isClass)(baseClassMemberInfo.classType)) {
|
|
14507
14529
|
const scopeIds = (0, typeUtils_1.getTypeVarScopeIds)(baseClassMemberInfo.classType);
|
|
14508
14530
|
const solution = (0, typeUtils_1.buildSolutionFromSpecializedClass)(baseClassMemberInfo.classType);
|
|
14509
|
-
scopeIds.push(
|
|
14531
|
+
scopeIds.push(getScopeIdForNode(baseClassMethodNode));
|
|
14510
14532
|
// Replace any unsolved TypeVars with Unknown (including all function-scoped TypeVars).
|
|
14511
14533
|
inferredParamType = (0, typeUtils_1.applySolvedTypeVars)(inferredParamType, solution, {
|
|
14512
14534
|
replaceUnsolved: {
|
|
@@ -14515,7 +14537,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14515
14537
|
},
|
|
14516
14538
|
});
|
|
14517
14539
|
}
|
|
14518
|
-
const fileInfo =
|
|
14540
|
+
const fileInfo = nodeInfo.getFileInfo(functionNode);
|
|
14519
14541
|
if (fileInfo.isInPyTypedPackage && !fileInfo.isStubFile) {
|
|
14520
14542
|
inferredParamType = types_1.TypeBase.cloneForAmbiguousType(inferredParamType);
|
|
14521
14543
|
}
|
|
@@ -14567,7 +14589,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14567
14589
|
}
|
|
14568
14590
|
}
|
|
14569
14591
|
if (inferredParamType) {
|
|
14570
|
-
const fileInfo =
|
|
14592
|
+
const fileInfo = nodeInfo.getFileInfo(paramValueExpr);
|
|
14571
14593
|
if (fileInfo.isInPyTypedPackage && !fileInfo.isStubFile) {
|
|
14572
14594
|
inferredParamType = types_1.TypeBase.cloneForAmbiguousType(inferredParamType);
|
|
14573
14595
|
}
|
|
@@ -14698,14 +14720,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14698
14720
|
functionRecursionMap.set(node.id, recursionEntry);
|
|
14699
14721
|
try {
|
|
14700
14722
|
let functionDecl;
|
|
14701
|
-
const decl =
|
|
14723
|
+
const decl = nodeInfo.getDeclaration(node);
|
|
14702
14724
|
if (decl) {
|
|
14703
14725
|
functionDecl = decl;
|
|
14704
14726
|
}
|
|
14705
14727
|
const functionNeverReturns = !isAfterNodeReachable(node);
|
|
14706
14728
|
const implicitlyReturnsNone = isAfterNodeReachable(node.d.suite);
|
|
14707
14729
|
// Infer the return type based on all of the return statements in the function's body.
|
|
14708
|
-
if (
|
|
14730
|
+
if (nodeInfo.getFileInfo(node).isStubFile) {
|
|
14709
14731
|
// If a return type annotation is missing in a stub file, assume
|
|
14710
14732
|
// it's an "unknown" type. In normal source files, we can infer the
|
|
14711
14733
|
// type from the implementation.
|
|
@@ -14850,7 +14872,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
14850
14872
|
// cases, we can get very deep stacks when inferring return types
|
|
14851
14873
|
// within untyped code.
|
|
14852
14874
|
if (err?.message === 'Maximum call stack size exceeded') {
|
|
14853
|
-
const fileInfo =
|
|
14875
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
14854
14876
|
console.error(`Overflowed stack when inferring return type for function: ${node.d.name.d.value} in file ${fileInfo.fileUri.toUserVisibleString()}`);
|
|
14855
14877
|
return;
|
|
14856
14878
|
}
|
|
@@ -15081,7 +15103,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15081
15103
|
return;
|
|
15082
15104
|
}
|
|
15083
15105
|
const aliasNode = node.d.alias || node.d.name;
|
|
15084
|
-
const fileInfo =
|
|
15106
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
15085
15107
|
// If this is a redundant form of an import, assume it is an intentional
|
|
15086
15108
|
// export and mark the symbol as accessed.
|
|
15087
15109
|
if (node.d.alias?.d.value === node.d.name.d.value) {
|
|
@@ -15103,7 +15125,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15103
15125
|
const parentNode = node.parent;
|
|
15104
15126
|
(0, debug_1.assert)(parentNode && parentNode.nodeType === 25 /* ParseNodeType.ImportFrom */);
|
|
15105
15127
|
(0, debug_1.assert)(!parentNode.d.isWildcardImport);
|
|
15106
|
-
const importInfo =
|
|
15128
|
+
const importInfo = nodeInfo.getImportInfo(parentNode.d.module);
|
|
15107
15129
|
if (importInfo && importInfo.isImportFound && !importInfo.isNativeLib) {
|
|
15108
15130
|
const resolvedPath = importInfo.resolvedUris[importInfo.resolvedUris.length - 1];
|
|
15109
15131
|
const importLookupInfo = importLookup(resolvedPath);
|
|
@@ -15151,7 +15173,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15151
15173
|
for (const caseStatement of node.d.cases) {
|
|
15152
15174
|
if (!caseStatement.d.guardExpr) {
|
|
15153
15175
|
subjectType = (0, patternMatching_1.narrowTypeBasedOnPattern)(evaluatorInterface, subjectType, caseStatement.d.pattern,
|
|
15154
|
-
/* isPositiveTest */ false);
|
|
15176
|
+
/* isPositiveTest */ false, nodeInfo);
|
|
15155
15177
|
}
|
|
15156
15178
|
}
|
|
15157
15179
|
writeTypeCache(node, { type: subjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* EvalFlags.None */);
|
|
@@ -15164,7 +15186,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15164
15186
|
(0, debug_1.fail)('Expected parent of case statement to be match statement');
|
|
15165
15187
|
return;
|
|
15166
15188
|
}
|
|
15167
|
-
const fileInfo =
|
|
15189
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
15168
15190
|
const subjectTypeResult = getTypeOfExpression(node.parent.d.expr);
|
|
15169
15191
|
let subjectType = subjectTypeResult.type;
|
|
15170
15192
|
// Apply negative narrowing for each of the cases prior to the current one
|
|
@@ -15173,17 +15195,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15173
15195
|
if (caseStatement === node) {
|
|
15174
15196
|
if (fileInfo.diagnosticRuleSet.reportUnnecessaryComparison !== 'none') {
|
|
15175
15197
|
if (!subjectTypeResult.isIncomplete) {
|
|
15176
|
-
(0, patternMatching_1.checkForUnusedPattern)(evaluatorInterface, node.d.pattern, subjectType);
|
|
15198
|
+
(0, patternMatching_1.checkForUnusedPattern)(evaluatorInterface, node.d.pattern, subjectType, nodeInfo);
|
|
15177
15199
|
}
|
|
15178
15200
|
}
|
|
15179
15201
|
break;
|
|
15180
15202
|
}
|
|
15181
15203
|
if (!caseStatement.d.guardExpr) {
|
|
15182
15204
|
subjectType = (0, patternMatching_1.narrowTypeBasedOnPattern)(evaluatorInterface, subjectType, caseStatement.d.pattern,
|
|
15183
|
-
/* isPositiveTest */ false);
|
|
15205
|
+
/* isPositiveTest */ false, nodeInfo);
|
|
15184
15206
|
}
|
|
15185
15207
|
}
|
|
15186
|
-
const narrowedSubjectType = (0, patternMatching_1.assignTypeToPatternTargets)(evaluatorInterface, subjectType, !!subjectTypeResult.isIncomplete, node.d.pattern);
|
|
15208
|
+
const narrowedSubjectType = (0, patternMatching_1.assignTypeToPatternTargets)(evaluatorInterface, subjectType, !!subjectTypeResult.isIncomplete, node.d.pattern, nodeInfo);
|
|
15187
15209
|
writeTypeCache(node, { type: narrowedSubjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* EvalFlags.None */);
|
|
15188
15210
|
}
|
|
15189
15211
|
function evaluateTypesForImportFrom(node) {
|
|
@@ -15193,7 +15215,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15193
15215
|
if (node.d.isWildcardImport) {
|
|
15194
15216
|
// Write back a dummy type so we don't evaluate this node again.
|
|
15195
15217
|
writeTypeCache(node, { type: types_1.AnyType.create() }, 0 /* EvalFlags.None */);
|
|
15196
|
-
const flowNode =
|
|
15218
|
+
const flowNode = nodeInfo.getFlowNode(node);
|
|
15197
15219
|
if (flowNode && (flowNode.flags & codeFlowTypes_1.FlowFlags.WildcardImport) !== 0) {
|
|
15198
15220
|
const wildcardFlowNode = flowNode;
|
|
15199
15221
|
wildcardFlowNode.names.forEach((name) => {
|
|
@@ -15278,7 +15300,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15278
15300
|
return undefined;
|
|
15279
15301
|
}
|
|
15280
15302
|
(0, debug_1.assert)(aliasDecl.type === 8 /* DeclarationType.Alias */);
|
|
15281
|
-
const fileInfo =
|
|
15303
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
15282
15304
|
// Try to resolve the alias while honoring external visibility.
|
|
15283
15305
|
const resolvedAliasInfo = resolveAliasDeclarationWithInfo(aliasDecl, /* resolveLocalNames */ true, {
|
|
15284
15306
|
allowExternallyHiddenAccess: fileInfo.isStubFile,
|
|
@@ -15561,7 +15583,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15561
15583
|
? getDeclaredReturnType(enclosingFunctionNode)
|
|
15562
15584
|
: undefined;
|
|
15563
15585
|
if (declaredReturnType) {
|
|
15564
|
-
const liveScopeIds =
|
|
15586
|
+
const liveScopeIds = getTypeVarScopesForNode(node);
|
|
15565
15587
|
declaredReturnType = (0, typeUtils_1.makeTypeVarsBound)(declaredReturnType, liveScopeIds);
|
|
15566
15588
|
}
|
|
15567
15589
|
getTypeOfExpression(parent.d.expr, 0 /* EvalFlags.None */, (0, typeUtils_1.makeInferenceContext)(declaredReturnType));
|
|
@@ -15609,7 +15631,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15609
15631
|
if (typeAnnotation) {
|
|
15610
15632
|
const param = functionNode.d.params[paramIndex];
|
|
15611
15633
|
let annotatedType = getTypeOfParamAnnotation(typeAnnotation, functionNode.d.params[paramIndex].d.category);
|
|
15612
|
-
const liveTypeVarScopes =
|
|
15634
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(param);
|
|
15613
15635
|
annotatedType = (0, typeUtils_1.makeTypeVarsBound)(annotatedType, liveTypeVarScopes);
|
|
15614
15636
|
const adjType = transformVariadicParamType(node, node.d.category, adjustParamAnnotatedType(param, annotatedType));
|
|
15615
15637
|
writeTypeCache(node.d.name, { type: adjType }, 0 /* EvalFlags.None */);
|
|
@@ -15631,9 +15653,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15631
15653
|
// infer the type of the parameter from a method of the same name in
|
|
15632
15654
|
// a parent class if it has an annotated type.
|
|
15633
15655
|
const functionFlags = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, functionNode,
|
|
15634
|
-
/* isInClass */ true).flags;
|
|
15656
|
+
/* isInClass */ true, nodeInfo).flags;
|
|
15635
15657
|
let inferredParamType = inferParamType(functionNode, functionFlags, paramIndex, classInfo?.classType) ?? types_1.UnknownType.create();
|
|
15636
|
-
const liveTypeVarScopes =
|
|
15658
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(node);
|
|
15637
15659
|
inferredParamType = (0, typeUtils_1.makeTypeVarsBound)(inferredParamType, liveTypeVarScopes);
|
|
15638
15660
|
writeTypeCache(node.d.name, { type: transformVariadicParamType(node, node.d.category, inferredParamType) }, 0 /* EvalFlags.None */);
|
|
15639
15661
|
}
|
|
@@ -15809,8 +15831,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15809
15831
|
function getFlowTypeOfReference(reference, startNode, options) {
|
|
15810
15832
|
// See if this execution scope requires code flow for this reference expression.
|
|
15811
15833
|
const referenceKey = (0, codeFlowTypes_1.createKeyForReference)(reference);
|
|
15812
|
-
const executionNode = ParseTreeUtils.getExecutionScopeNode(startNode?.parent ?? reference);
|
|
15813
|
-
const codeFlowExpressions =
|
|
15834
|
+
const executionNode = ParseTreeUtils.getExecutionScopeNode(startNode?.parent ?? reference, nodeInfo);
|
|
15835
|
+
const codeFlowExpressions = nodeInfo.getCodeFlowExpressions(executionNode);
|
|
15814
15836
|
if (!codeFlowExpressions ||
|
|
15815
15837
|
(!codeFlowExpressions.has(referenceKey) && !codeFlowExpressions.has(codeFlowTypes_1.wildcardImportReferenceKey))) {
|
|
15816
15838
|
return codeFlowEngine_1.FlowNodeTypeResult.create(/* type */ undefined, /* isIncomplete */ false);
|
|
@@ -15834,7 +15856,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15834
15856
|
else {
|
|
15835
15857
|
analyzer = getCodeFlowAnalyzerForNode(executionNode, options?.typeAtStart);
|
|
15836
15858
|
}
|
|
15837
|
-
const flowNode =
|
|
15859
|
+
const flowNode = nodeInfo.getFlowNode(startNode ?? reference);
|
|
15838
15860
|
if (flowNode === undefined) {
|
|
15839
15861
|
return codeFlowEngine_1.FlowNodeTypeResult.create(/* type */ undefined, /* isIncomplete */ false);
|
|
15840
15862
|
}
|
|
@@ -15901,8 +15923,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15901
15923
|
if ((flags &
|
|
15902
15924
|
(67108864 /* EvalFlags.NoNonTypeSpecialForms */ | 256 /* EvalFlags.TypeExpression */ | 1073741824 /* EvalFlags.TypeFormArg */)) !==
|
|
15903
15925
|
0) {
|
|
15904
|
-
const isInlinedTypedDict =
|
|
15905
|
-
!!typeArgs;
|
|
15926
|
+
const isInlinedTypedDict = nodeInfo.getFileInfo(errorNode).diagnosticRuleSet.enableExperimentalFeatures && !!typeArgs;
|
|
15906
15927
|
if (!isInlinedTypedDict) {
|
|
15907
15928
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typedDictNotAllowed(), errorNode);
|
|
15908
15929
|
}
|
|
@@ -15974,10 +15995,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
15974
15995
|
}
|
|
15975
15996
|
}
|
|
15976
15997
|
}
|
|
15977
|
-
const fileInfo =
|
|
15998
|
+
const fileInfo = nodeInfo.getFileInfo(errorNode);
|
|
15978
15999
|
if (fileInfo.isStubFile ||
|
|
15979
16000
|
pythonVersion_1.PythonVersion.isGreaterOrEqualTo(fileInfo.executionEnvironment.pythonVersion, pythonVersion_1.pythonVersion3_9) ||
|
|
15980
|
-
(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(
|
|
16001
|
+
(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(nodeInfo.getFileInfo(errorNode)) ||
|
|
15981
16002
|
(flags & 4 /* EvalFlags.ForwardRefs */) !== 0) {
|
|
15982
16003
|
// Handle "type" specially, since it needs to act like "Type"
|
|
15983
16004
|
// in Python 3.9 and newer.
|
|
@@ -16294,7 +16315,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16294
16315
|
if (options?.enforceClassTypeVarScope) {
|
|
16295
16316
|
flags |= -2147483648 /* EvalFlags.EnforceClassTypeVarScope */;
|
|
16296
16317
|
}
|
|
16297
|
-
const fileInfo =
|
|
16318
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
16298
16319
|
if (((0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(fileInfo) || options?.forwardRefs) && !options?.runtimeTypeExpression) {
|
|
16299
16320
|
flags |= 4 /* EvalFlags.ForwardRefs */;
|
|
16300
16321
|
}
|
|
@@ -16349,7 +16370,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16349
16370
|
return getTypeOfExpression(node, flags);
|
|
16350
16371
|
}
|
|
16351
16372
|
function getBuiltInType(node, name) {
|
|
16352
|
-
const scope =
|
|
16373
|
+
const scope = getScopeForNode(node);
|
|
16353
16374
|
if (scope) {
|
|
16354
16375
|
const builtInScope = ScopeUtils.getBuiltInScope(scope);
|
|
16355
16376
|
const nameType = builtInScope.lookUpSymbol(name);
|
|
@@ -16371,8 +16392,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16371
16392
|
return nameType;
|
|
16372
16393
|
}
|
|
16373
16394
|
function lookUpSymbolRecursive(node, name, honorCodeFlow, preferGlobalScope = false) {
|
|
16374
|
-
const scopeNodeInfo = ParseTreeUtils.getEvaluationScopeNode(node);
|
|
16375
|
-
const scope =
|
|
16395
|
+
const scopeNodeInfo = ParseTreeUtils.getEvaluationScopeNode(node, nodeInfo);
|
|
16396
|
+
const scope = nodeInfo.getScope(scopeNodeInfo.node);
|
|
16376
16397
|
let symbolWithScope = scope?.lookUpSymbolRecursive(name, {
|
|
16377
16398
|
useProxyScope: !!scopeNodeInfo.useProxyScope,
|
|
16378
16399
|
useChainedModuleLevelScopes: !!scopeNodeInfo.useChainedModuleLevelScopes,
|
|
@@ -16391,20 +16412,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16391
16412
|
const reachableDecl = symbolWithScope.symbol.getDeclarations().find((decl) => {
|
|
16392
16413
|
if (decl.type !== 8 /* DeclarationType.Alias */ && decl.type !== 0 /* DeclarationType.Intrinsic */) {
|
|
16393
16414
|
// Determine if the declaration is in the same execution scope as the "usageNode" node.
|
|
16394
|
-
let usageScopeNode = ParseTreeUtils.getExecutionScopeNode(node);
|
|
16415
|
+
let usageScopeNode = ParseTreeUtils.getExecutionScopeNode(node, nodeInfo);
|
|
16395
16416
|
const declNode = decl.type === 6 /* DeclarationType.Class */ ||
|
|
16396
16417
|
decl.type === 5 /* DeclarationType.Function */ ||
|
|
16397
16418
|
decl.type === 4 /* DeclarationType.TypeAlias */
|
|
16398
16419
|
? decl.node.d.name
|
|
16399
16420
|
: decl.node;
|
|
16400
|
-
const declScopeNode = ParseTreeUtils.getExecutionScopeNode(declNode);
|
|
16421
|
+
const declScopeNode = ParseTreeUtils.getExecutionScopeNode(declNode, nodeInfo);
|
|
16401
16422
|
// If this is a type parameter scope, it will be a proxy for its
|
|
16402
16423
|
// containing scope, so we need to use that instead.
|
|
16403
|
-
const usageScope =
|
|
16424
|
+
const usageScope = nodeInfo.getScope(usageScopeNode);
|
|
16404
16425
|
if (usageScope?.proxy) {
|
|
16405
|
-
const typeParamScope =
|
|
16426
|
+
const typeParamScope = nodeInfo.getScope(usageScopeNode);
|
|
16406
16427
|
if (!typeParamScope?.symbolTable.has(name) && usageScopeNode.parent) {
|
|
16407
|
-
usageScopeNode = ParseTreeUtils.getExecutionScopeNode(usageScopeNode.parent);
|
|
16428
|
+
usageScopeNode = ParseTreeUtils.getExecutionScopeNode(usageScopeNode.parent, nodeInfo);
|
|
16408
16429
|
}
|
|
16409
16430
|
}
|
|
16410
16431
|
if (usageScopeNode === declScopeNode) {
|
|
@@ -16412,7 +16433,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16412
16433
|
// If there was no control flow path from the usage back
|
|
16413
16434
|
// to the source, see if the usage node is reachable by
|
|
16414
16435
|
// any path.
|
|
16415
|
-
const flowNode =
|
|
16436
|
+
const flowNode = nodeInfo.getFlowNode(node);
|
|
16416
16437
|
const isReachable = flowNode &&
|
|
16417
16438
|
codeFlowEngine.getFlowNodeReachability(flowNode,
|
|
16418
16439
|
/* sourceFlowNode */ undefined,
|
|
@@ -16588,7 +16609,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16588
16609
|
const functionDecl = type.shared.declaration;
|
|
16589
16610
|
if (functionDecl.type === 5 /* DeclarationType.Function */) {
|
|
16590
16611
|
const functionNode = functionDecl.node;
|
|
16591
|
-
const functionScope =
|
|
16612
|
+
const functionScope = nodeInfo.getScope(functionNode);
|
|
16592
16613
|
if (functionScope) {
|
|
16593
16614
|
const paramSymbol = functionScope.lookUpSymbol(paramName);
|
|
16594
16615
|
if (paramSymbol) {
|
|
@@ -16609,6 +16630,48 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16609
16630
|
}
|
|
16610
16631
|
return undefined;
|
|
16611
16632
|
}
|
|
16633
|
+
// functools.partial(func, kw=value) forwards keyword arguments to the wrapped callable, but
|
|
16634
|
+
// partial's own signature absorbs them through **kwargs, so they don't resolve to a declaration.
|
|
16635
|
+
// Resolve the keyword against the wrapped callable (the first positional argument) instead so IDE
|
|
16636
|
+
// features like go-to-definition and rename bind to the underlying parameter. Returns true when
|
|
16637
|
+
// baseType is functools.partial, so the caller suppresses the default keyword-argument handling.
|
|
16638
|
+
function _tryAddPartialKeywordParamDecls(baseType, callNode, paramName, decls) {
|
|
16639
|
+
if (!(0, types_1.isInstantiableClass)(baseType) || baseType.shared.fullName !== 'functools.partial') {
|
|
16640
|
+
return false;
|
|
16641
|
+
}
|
|
16642
|
+
const wrappedArg = callNode.d.args.find((arg) => arg.d.argCategory === 0 /* ArgCategory.Simple */ && !arg.d.name);
|
|
16643
|
+
if (!wrappedArg) {
|
|
16644
|
+
return true;
|
|
16645
|
+
}
|
|
16646
|
+
const wrappedType = getType(wrappedArg.d.valueExpr);
|
|
16647
|
+
if (!wrappedType) {
|
|
16648
|
+
return true;
|
|
16649
|
+
}
|
|
16650
|
+
if ((0, types_1.isFunction)(wrappedType)) {
|
|
16651
|
+
const paramDecl = getDeclarationFromKeywordParam(wrappedType, paramName);
|
|
16652
|
+
if (paramDecl) {
|
|
16653
|
+
decls.push(paramDecl);
|
|
16654
|
+
}
|
|
16655
|
+
}
|
|
16656
|
+
else if ((0, types_1.isOverloaded)(wrappedType)) {
|
|
16657
|
+
types_1.OverloadedType.getOverloads(wrappedType).forEach((f) => {
|
|
16658
|
+
const paramDecl = getDeclarationFromKeywordParam(f, paramName);
|
|
16659
|
+
if (paramDecl) {
|
|
16660
|
+
decls.push(paramDecl);
|
|
16661
|
+
}
|
|
16662
|
+
});
|
|
16663
|
+
}
|
|
16664
|
+
else if ((0, types_1.isInstantiableClass)(wrappedType)) {
|
|
16665
|
+
const initMethodType = (0, constructors_1.getBoundInitMethod)(evaluatorInterface, wrappedArg.d.valueExpr, types_1.ClassType.cloneAsInstance(wrappedType))?.type;
|
|
16666
|
+
if (initMethodType && (0, types_1.isFunction)(initMethodType)) {
|
|
16667
|
+
const paramDecl = getDeclarationFromKeywordParam(initMethodType, paramName);
|
|
16668
|
+
if (paramDecl) {
|
|
16669
|
+
decls.push(paramDecl);
|
|
16670
|
+
}
|
|
16671
|
+
}
|
|
16672
|
+
}
|
|
16673
|
+
return true;
|
|
16674
|
+
}
|
|
16612
16675
|
function _shouldFallBackToClassEntryForKeywordArg(baseType, paramName) {
|
|
16613
16676
|
return (types_1.ClassType.isDataClass(baseType) ||
|
|
16614
16677
|
types_1.ClassType.isTypedDictClass(baseType) ||
|
|
@@ -16675,7 +16738,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16675
16738
|
return undefined;
|
|
16676
16739
|
}
|
|
16677
16740
|
function getDeclInfoForNameNode(node, skipUnreachableCode = true) {
|
|
16678
|
-
if (skipUnreachableCode &&
|
|
16741
|
+
if (skipUnreachableCode && nodeInfo.isCodeUnreachable(node)) {
|
|
16679
16742
|
return undefined;
|
|
16680
16743
|
}
|
|
16681
16744
|
const decls = [];
|
|
@@ -16685,7 +16748,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16685
16748
|
// since the non-aliased name is not in the symbol table.
|
|
16686
16749
|
const alias = getAliasFromImport(node);
|
|
16687
16750
|
if (alias) {
|
|
16688
|
-
const scope =
|
|
16751
|
+
const scope = getScopeForNode(node);
|
|
16689
16752
|
if (scope) {
|
|
16690
16753
|
// Look up the alias symbol.
|
|
16691
16754
|
const symbolInScope = scope.lookUpSymbolRecursive(alias.d.value);
|
|
@@ -16751,7 +16814,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16751
16814
|
}
|
|
16752
16815
|
else if (node.parent && node.parent.nodeType === 37 /* ParseNodeType.ModuleName */) {
|
|
16753
16816
|
const namePartIndex = node.parent.d.nameParts.findIndex((part) => part === node);
|
|
16754
|
-
const importInfo =
|
|
16817
|
+
const importInfo = nodeInfo.getImportInfo(node.parent);
|
|
16755
16818
|
if (namePartIndex >= 0 &&
|
|
16756
16819
|
importInfo &&
|
|
16757
16820
|
!importInfo.isNativeLib &&
|
|
@@ -16773,7 +16836,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16773
16836
|
if (argNode.parent?.nodeType === 9 /* ParseNodeType.Call */) {
|
|
16774
16837
|
const baseType = getType(argNode.parent.d.leftExpr);
|
|
16775
16838
|
if (baseType) {
|
|
16776
|
-
if ((
|
|
16839
|
+
if (_tryAddPartialKeywordParamDecls(baseType, argNode.parent, paramName, decls)) {
|
|
16840
|
+
// functools.partial keyword args are resolved against the wrapped callable.
|
|
16841
|
+
}
|
|
16842
|
+
else if ((0, types_1.isFunction)(baseType) && baseType.shared.declaration) {
|
|
16777
16843
|
const paramDecl = getDeclarationFromKeywordParam(baseType, paramName);
|
|
16778
16844
|
if (paramDecl) {
|
|
16779
16845
|
decls.push(paramDecl);
|
|
@@ -16817,10 +16883,45 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16817
16883
|
}
|
|
16818
16884
|
}
|
|
16819
16885
|
}
|
|
16886
|
+
else if (node.parent &&
|
|
16887
|
+
node.parent.nodeType === 74 /* ParseNodeType.PatternClassArgument */ &&
|
|
16888
|
+
node === node.parent.d.name &&
|
|
16889
|
+
node.parent.parent?.nodeType === 68 /* ParseNodeType.PatternClass */) {
|
|
16890
|
+
// The target node is the keyword name in a class pattern argument
|
|
16891
|
+
// (e.g. `case Foo(prop=...)`). Map it to the corresponding class member
|
|
16892
|
+
// declaration so that find-all-references and rename bind to the attribute.
|
|
16893
|
+
// Only the keyword (left of `=`) is handled here; the capture target on the
|
|
16894
|
+
// right (e.g. the second `prop` in `case Foo(prop=prop)`) is a separate local
|
|
16895
|
+
// binding that is resolved through the normal name-lookup path.
|
|
16896
|
+
const memberName = node.d.value;
|
|
16897
|
+
let classType = getType(node.parent.parent.d.className);
|
|
16898
|
+
if (classType) {
|
|
16899
|
+
classType = makeTopLevelTypeVarsConcrete(classType);
|
|
16900
|
+
(0, typeUtils_1.doForEachSubtype)(classType, (subtype) => {
|
|
16901
|
+
subtype = makeTopLevelTypeVarsConcrete(subtype);
|
|
16902
|
+
// The class name in a class pattern usually evaluates to an instantiable class,
|
|
16903
|
+
// but analysis can still yield Unknown/Any (e.g. an unresolved class name), so
|
|
16904
|
+
// the isInstantiableClass gate skips those subtypes rather than assuming
|
|
16905
|
+
// every subtype is a class.
|
|
16906
|
+
if ((0, types_1.isInstantiableClass)(subtype)) {
|
|
16907
|
+
// Try to find a member that has a declared type. If so, that
|
|
16908
|
+
// overrides any inferred types.
|
|
16909
|
+
let member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName, 64 /* MemberAccessFlags.DeclaredTypesOnly */);
|
|
16910
|
+
if (!member) {
|
|
16911
|
+
member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName);
|
|
16912
|
+
}
|
|
16913
|
+
if (member) {
|
|
16914
|
+
_addSymbolDeclInfo(member.symbol, decls, synthesizedTypes,
|
|
16915
|
+
/* preferTypedDeclarations */ true);
|
|
16916
|
+
}
|
|
16917
|
+
}
|
|
16918
|
+
});
|
|
16919
|
+
}
|
|
16920
|
+
}
|
|
16820
16921
|
else {
|
|
16821
|
-
const fileInfo =
|
|
16922
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
16822
16923
|
// Determine if this node is within a quoted type annotation.
|
|
16823
|
-
const isWithinTypeAnnotation = ParseTreeUtils.isWithinTypeAnnotation(node, !(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(
|
|
16924
|
+
const isWithinTypeAnnotation = ParseTreeUtils.isWithinTypeAnnotation(node, !(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(nodeInfo.getFileInfo(node)), nodeInfo);
|
|
16824
16925
|
// Determine if this is part of a "type" statement.
|
|
16825
16926
|
const isWithinTypeAliasStatement = !!ParseTreeUtils.getParentNodeOfType(node, 77 /* ParseNodeType.TypeAlias */);
|
|
16826
16927
|
const allowForwardReferences = isWithinTypeAnnotation || isWithinTypeAliasStatement || fileInfo.isStubFile;
|
|
@@ -16908,7 +17009,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16908
17009
|
}
|
|
16909
17010
|
if (typeAnnotationNode) {
|
|
16910
17011
|
let declaredType = getTypeOfParamAnnotation(typeAnnotationNode, declaration.node.d.category);
|
|
16911
|
-
const liveTypeVarScopes =
|
|
17012
|
+
const liveTypeVarScopes = getTypeVarScopesForNode(declaration.node);
|
|
16912
17013
|
declaredType = (0, typeUtils_1.makeTypeVarsBound)(declaredType, liveTypeVarScopes);
|
|
16913
17014
|
return {
|
|
16914
17015
|
type: transformVariadicParamType(declaration.node, declaration.node.d.category, adjustParamAnnotatedType(declaration.node, declaredType)),
|
|
@@ -16956,9 +17057,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
16956
17057
|
if (declaration.isDefinedByMemberAccess) {
|
|
16957
17058
|
const enclosingClass = ParseTreeUtils.getEnclosingClass(declaration.node);
|
|
16958
17059
|
if (enclosingClass) {
|
|
16959
|
-
declaredType = (0, typeUtils_1.makeTypeVarsFree)(declaredType, [
|
|
16960
|
-
ParseTreeUtils.getScopeIdForNode(enclosingClass),
|
|
16961
|
-
]);
|
|
17060
|
+
declaredType = (0, typeUtils_1.makeTypeVarsFree)(declaredType, [getScopeIdForNode(enclosingClass)]);
|
|
16962
17061
|
}
|
|
16963
17062
|
}
|
|
16964
17063
|
if ((0, types_1.isClassInstance)(declaredType) && types_1.ClassType.isBuiltIn(declaredType, 'TypeAlias')) {
|
|
@@ -17103,7 +17202,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17103
17202
|
typeVar.shared.declaredVariance =
|
|
17104
17203
|
(0, types_1.isParamSpec)(typeVar) || (0, types_1.isTypeVarTuple)(typeVar) ? 2 /* Variance.Invariant */ : 0 /* Variance.Auto */;
|
|
17105
17204
|
}
|
|
17106
|
-
typeVar = types_1.TypeVarType.cloneForScopeId(typeVar,
|
|
17205
|
+
typeVar = types_1.TypeVarType.cloneForScopeId(typeVar, getScopeIdForNode(scopeNode.nodeType === 77 /* ParseNodeType.TypeAlias */ ? scopeNode.d.name : scopeNode), scopeNode.d.name.d.value, scopeType);
|
|
17107
17206
|
}
|
|
17108
17207
|
writeTypeCache(node, { type: typeVar }, /* flags */ undefined);
|
|
17109
17208
|
writeTypeCache(node.d.name, { type: typeVar }, /* flags */ undefined);
|
|
@@ -17111,7 +17210,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17111
17210
|
}
|
|
17112
17211
|
function getInferredTypeOfDeclaration(symbol, decl) {
|
|
17113
17212
|
const resolvedDecl = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
|
|
17114
|
-
allowExternallyHiddenAccess:
|
|
17213
|
+
allowExternallyHiddenAccess: nodeInfo.getFileInfo(decl.node).isStubFile,
|
|
17115
17214
|
});
|
|
17116
17215
|
// We couldn't resolve the alias. Substitute an unknown
|
|
17117
17216
|
// type in this case.
|
|
@@ -17197,7 +17296,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17197
17296
|
}
|
|
17198
17297
|
// If this is part of a "py.typed" package, don't fall back on type inference
|
|
17199
17298
|
// unless it's marked Final, is a constant, or is a declared type alias.
|
|
17200
|
-
const fileInfo =
|
|
17299
|
+
const fileInfo = nodeInfo.getFileInfo(resolvedDecl.node);
|
|
17201
17300
|
let isUnambiguousType = !fileInfo.isInPyTypedPackage || fileInfo.isStubFile;
|
|
17202
17301
|
// If this is a py.typed package, determine if this is a case where an unannotated
|
|
17203
17302
|
// variable is considered "unambiguous" because all type checkers are almost
|
|
@@ -17409,7 +17508,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17409
17508
|
if (decl.type === 1 /* DeclarationType.Variable */) {
|
|
17410
17509
|
// Exempt typing.pyi and typingExtensions.pyi, which use variables to
|
|
17411
17510
|
// define some special forms.
|
|
17412
|
-
const fileInfo =
|
|
17511
|
+
const fileInfo = nodeInfo.getFileInfo(decl.node);
|
|
17413
17512
|
if (!fileInfo.isTypingStubFile && !fileInfo.isTypingExtensionsStubFile) {
|
|
17414
17513
|
return true;
|
|
17415
17514
|
}
|
|
@@ -17473,7 +17572,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17473
17572
|
let sawExplicitTypeAlias = false;
|
|
17474
17573
|
decls.forEach((decl, index) => {
|
|
17475
17574
|
const resolvedDecl = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
|
|
17476
|
-
allowExternallyHiddenAccess:
|
|
17575
|
+
allowExternallyHiddenAccess: nodeInfo.getFileInfo(decl.node).isStubFile,
|
|
17477
17576
|
}) ?? decl;
|
|
17478
17577
|
if (!isPossibleTypeAliasDeclaration(resolvedDecl) && !isExplicitTypeAliasDeclaration(resolvedDecl)) {
|
|
17479
17578
|
includesIllegalTypeAliasDecl = true;
|
|
@@ -17504,8 +17603,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17504
17603
|
// Is the declaration in the same execution scope as the "usageNode" node?
|
|
17505
17604
|
// If so, we can skip it because code flow analysis will allow us
|
|
17506
17605
|
// to determine the type in this context.
|
|
17507
|
-
const usageScope = ParseTreeUtils.getExecutionScopeNode(usageNode);
|
|
17508
|
-
const declScope = ParseTreeUtils.getExecutionScopeNode(decl.node);
|
|
17606
|
+
const usageScope = ParseTreeUtils.getExecutionScopeNode(usageNode, nodeInfo);
|
|
17607
|
+
const declScope = ParseTreeUtils.getExecutionScopeNode(decl.node, nodeInfo);
|
|
17509
17608
|
if (usageScope === declScope) {
|
|
17510
17609
|
// Skip declarations that appear after the usage in the source.
|
|
17511
17610
|
// Such declarations are typically only reached via loop back-edges,
|
|
@@ -17693,8 +17792,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17693
17792
|
const filteredTypedDecls = typedDecls.filter((decl) => {
|
|
17694
17793
|
if (decl.type !== 8 /* DeclarationType.Alias */) {
|
|
17695
17794
|
// 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);
|
|
17795
|
+
const usageScope = ParseTreeUtils.getExecutionScopeNode(usageNode, nodeInfo);
|
|
17796
|
+
const declScope = ParseTreeUtils.getExecutionScopeNode(decl.node, nodeInfo);
|
|
17698
17797
|
if (usageScope === declScope) {
|
|
17699
17798
|
// For typed declarations we use the precise flow-graph reachability
|
|
17700
17799
|
// check rather than a simple position comparison, because typed decls
|
|
@@ -17780,7 +17879,35 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17780
17879
|
function getEffectiveReturnTypeResult(type, options) {
|
|
17781
17880
|
const specializedReturnType = types_1.FunctionType.getEffectiveReturnType(type, /* includeInferred */ false);
|
|
17782
17881
|
if (specializedReturnType && !(0, types_1.isUnknown)(specializedReturnType)) {
|
|
17783
|
-
return
|
|
17882
|
+
// A partially-unknown *inferred* return type (e.g. `Foo | Unknown`) can be
|
|
17883
|
+
// cached on a specialized/bound copy of an unannotated function. Because
|
|
17884
|
+
// `isUnknown` matches only a fully-unknown type, such a partial type would
|
|
17885
|
+
// otherwise short-circuit here and prevent call-site return-type inference
|
|
17886
|
+
// from ever running (e.g. an unannotated factory whose body narrows a
|
|
17887
|
+
// parameter-derived local with `isinstance`). When a call site is available,
|
|
17888
|
+
// fall through so the argument types can refine the inferred return type.
|
|
17889
|
+
//
|
|
17890
|
+
// NOTE: This gate intentionally mirrors a subset of the downstream call-site
|
|
17891
|
+
// refinement guard in `_getInferredReturnTypeResult` (search `isPartlyUnknown(returnType)`),
|
|
17892
|
+
// but tests the cached *specialized* return type here rather than the freshly-inferred
|
|
17893
|
+
// one, and omits the `!isStubDefinition`/`!isPyTypedDefinition`/`!isIncomplete`
|
|
17894
|
+
// conjuncts (not yet known at this point). Keep the two in sync if either is edited.
|
|
17895
|
+
const canRefineWithCallSite = options?.callSiteInfo !== undefined &&
|
|
17896
|
+
!type.shared.declaredReturnType &&
|
|
17897
|
+
types_1.FunctionType.hasUnannotatedParams(type) &&
|
|
17898
|
+
(0, typeUtils_1.isPartlyUnknown)(specializedReturnType);
|
|
17899
|
+
if (!canRefineWithCallSite) {
|
|
17900
|
+
return { type: specializedReturnType };
|
|
17901
|
+
}
|
|
17902
|
+
// Refine the cached partly-unknown return type using the call site. If the
|
|
17903
|
+
// refinement comes back incomplete -- e.g. a self- or mutually-recursive
|
|
17904
|
+
// factory whose base case returns the isinstance-narrowed local -- fall back
|
|
17905
|
+
// to the already-cached specialized return type rather than propagating the
|
|
17906
|
+
// incomplete result. The cached type is already correct in that case, and
|
|
17907
|
+
// propagating `isIncomplete` would suppress caller-side diagnostics that only
|
|
17908
|
+
// fire on a complete type (for example, `reveal_type`).
|
|
17909
|
+
const refinedResult = getInferredReturnTypeResult(type, options?.callSiteInfo);
|
|
17910
|
+
return refinedResult.isIncomplete ? { type: specializedReturnType } : refinedResult;
|
|
17784
17911
|
}
|
|
17785
17912
|
return getInferredReturnTypeResult(type, options?.callSiteInfo);
|
|
17786
17913
|
}
|
|
@@ -17819,11 +17946,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17819
17946
|
}
|
|
17820
17947
|
else if (type.shared.declaration) {
|
|
17821
17948
|
const functionNode = type.shared.declaration.node;
|
|
17822
|
-
const skipUnannotatedFunction = !
|
|
17949
|
+
const skipUnannotatedFunction = !nodeInfo.getFileInfo(functionNode).diagnosticRuleSet.analyzeUnannotatedFunctions &&
|
|
17823
17950
|
ParseTreeUtils.isUnannotatedFunction(functionNode);
|
|
17824
17951
|
// Skip return type inference if we are in "skip unannotated function" mode.
|
|
17825
17952
|
if (!skipUnannotatedFunction && !checkCodeFlowTooComplex(functionNode.d.suite)) {
|
|
17826
|
-
const codeFlowComplexity =
|
|
17953
|
+
const codeFlowComplexity = nodeInfo.getCodeFlowComplexity(functionNode);
|
|
17827
17954
|
// For very complex functions that have no annotated parameter types,
|
|
17828
17955
|
// don't attempt to infer the return type because it can be extremely
|
|
17829
17956
|
// expensive.
|
|
@@ -17887,7 +18014,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17887
18014
|
returnType = contextualReturnType;
|
|
17888
18015
|
if (type.shared.declaration?.node) {
|
|
17889
18016
|
// Externalize any TypeVars that appear in the type.
|
|
17890
|
-
const liveScopeIds =
|
|
18017
|
+
const liveScopeIds = getTypeVarScopesForNode(type.shared.declaration.node);
|
|
17891
18018
|
returnType = (0, typeUtils_1.makeTypeVarsFree)(returnType, liveScopeIds);
|
|
17892
18019
|
}
|
|
17893
18020
|
}
|
|
@@ -17902,7 +18029,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
17902
18029
|
return undefined;
|
|
17903
18030
|
}
|
|
17904
18031
|
const functionNode = type.shared.declaration.node;
|
|
17905
|
-
const codeFlowComplexity =
|
|
18032
|
+
const codeFlowComplexity = nodeInfo.getCodeFlowComplexity(functionNode);
|
|
17906
18033
|
if (codeFlowComplexity >= maxReturnCallSiteTypeInferenceCodeFlowComplexity) {
|
|
17907
18034
|
return undefined;
|
|
17908
18035
|
}
|
|
@@ -21386,7 +21513,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21386
21513
|
// expression tree because we don't want to mutate the latter; the
|
|
21387
21514
|
// expression tree created by this function is therefore used only temporarily.
|
|
21388
21515
|
function parseStringAsTypeAnnotation(node, reportErrors) {
|
|
21389
|
-
const fileInfo =
|
|
21516
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
21390
21517
|
const parser = new parser_1.Parser();
|
|
21391
21518
|
const textValue = node.d.strings[0].d.value;
|
|
21392
21519
|
// Determine the offset within the file where the string
|
|
@@ -21404,14 +21531,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21404
21531
|
parseOptions.pythonVersion = fileInfo.executionEnvironment.pythonVersion;
|
|
21405
21532
|
parseOptions.reportErrorsForParsedStringContents = true;
|
|
21406
21533
|
const parseResults = parser.parseTextExpression(dummyFileContents, valueOffset, textValue.length, parseOptions, 0 /* ParseTextMode.Expression */,
|
|
21407
|
-
/* initialParenDepth */ undefined, fileInfo.typingSymbolAliases);
|
|
21534
|
+
/* initialParenDepth */ undefined, fileInfo.typingSymbolAliases, node.a);
|
|
21408
21535
|
if (parseResults.parseTree) {
|
|
21409
21536
|
// If there are errors but we are not reporting them, return
|
|
21410
21537
|
// undefined to indicate that the parse failed.
|
|
21411
21538
|
if (!reportErrors && parseResults.diagnostics.length > 0) {
|
|
21412
21539
|
return undefined;
|
|
21413
21540
|
}
|
|
21414
|
-
const fileInfo =
|
|
21541
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
21415
21542
|
parseResults.diagnostics.forEach((diag) => {
|
|
21416
21543
|
fileInfo.diagnosticSink.addDiagnosticWithTextRange('error', diag.message, node);
|
|
21417
21544
|
});
|
|
@@ -21419,7 +21546,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21419
21546
|
// Optionally add the new subtree to the parse tree so it can
|
|
21420
21547
|
// participate in language server operations like find and replace.
|
|
21421
21548
|
if (reportErrors) {
|
|
21422
|
-
node.
|
|
21549
|
+
nodeInfo.setStringAnnotation(node, parseResults.parseTree, parseResults.stringAnnotations);
|
|
21423
21550
|
}
|
|
21424
21551
|
return parseResults.parseTree;
|
|
21425
21552
|
}
|
|
@@ -21429,7 +21556,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21429
21556
|
// var can be "narrowed" to a single one of its constraints based on isinstance
|
|
21430
21557
|
// checks within the code flow.
|
|
21431
21558
|
function narrowConstrainedTypeVar(node, typeVar) {
|
|
21432
|
-
const flowNode =
|
|
21559
|
+
const flowNode = nodeInfo.getFlowNode(node);
|
|
21433
21560
|
if (!flowNode) {
|
|
21434
21561
|
return undefined;
|
|
21435
21562
|
}
|
|
@@ -21439,7 +21566,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21439
21566
|
return ' '.repeat(printExpressionSpaceCount);
|
|
21440
21567
|
}
|
|
21441
21568
|
function getLineNum(node) {
|
|
21442
|
-
const fileInfo =
|
|
21569
|
+
const fileInfo = nodeInfo.getFileInfo(node);
|
|
21443
21570
|
const range = (0, positionUtils_1.convertOffsetsToRange)(node.start, node.start + node.length, fileInfo.lines);
|
|
21444
21571
|
return (range.start.line + 1).toString();
|
|
21445
21572
|
}
|
|
@@ -21450,6 +21577,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21450
21577
|
const getInferredReturnTypeResult = wrapWithLogger(_getInferredReturnTypeResult);
|
|
21451
21578
|
const evaluatorInterface = {
|
|
21452
21579
|
runWithCancellationToken,
|
|
21580
|
+
getAnalyzerNodeInfoReader: () => nodeInfo,
|
|
21453
21581
|
getType,
|
|
21454
21582
|
getTypeResult,
|
|
21455
21583
|
getTypeResultForDecorator,
|
|
@@ -21560,7 +21688,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
21560
21688
|
checkForCancellation,
|
|
21561
21689
|
printControlFlowGraph,
|
|
21562
21690
|
};
|
|
21563
|
-
const codeFlowEngine = (0, codeFlowEngine_1.getCodeFlowEngine)(evaluatorInterface, speculativeTypeTracker);
|
|
21691
|
+
const codeFlowEngine = (0, codeFlowEngine_1.getCodeFlowEngine)(evaluatorInterface, speculativeTypeTracker, nodeInfo);
|
|
21564
21692
|
return evaluatorInterface;
|
|
21565
21693
|
}
|
|
21566
21694
|
//# sourceMappingURL=typeEvaluator.js.map
|