@zzzen/pyright-internal 1.2.0-dev.20230101 → 1.2.0-dev.20230108
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/checker.js +17 -11
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +19 -4
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +2 -1
- package/dist/analyzer/importResolver.js +18 -3
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/patternMatching.js +2 -2
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +1 -0
- package/dist/analyzer/program.js +41 -20
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/regions.js +14 -5
- package/dist/analyzer/regions.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +1 -1
- package/dist/analyzer/sourceMapper.d.ts +2 -2
- package/dist/analyzer/sourceMapper.js +14 -5
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/typeCacheUtils.d.ts +1 -3
- package/dist/analyzer/typeCacheUtils.js +4 -8
- package/dist/analyzer/typeCacheUtils.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.d.ts +2 -1
- package/dist/analyzer/typeDocStringUtils.js +18 -7
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +116 -110
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -1
- package/dist/analyzer/typeGuards.d.ts +5 -1
- package/dist/analyzer/typeGuards.js +180 -43
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +1 -0
- package/dist/analyzer/typeUtils.js +5 -1
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/commands/quickActionCommand.js +1 -1
- package/dist/commands/quickActionCommand.js.map +1 -1
- package/dist/common/collectionUtils.d.ts +1 -0
- package/dist/common/collectionUtils.js +9 -1
- package/dist/common/collectionUtils.js.map +1 -1
- package/dist/common/textEditUtils.d.ts +3 -2
- package/dist/common/textEditUtils.js +11 -10
- package/dist/common/textEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +1 -1
- package/dist/languageService/completionProvider.d.ts +3 -0
- package/dist/languageService/completionProvider.js +212 -159
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +0 -1
- package/dist/languageService/hoverProvider.js +7 -20
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/indentationUtils.js +1 -1
- package/dist/languageService/indentationUtils.js.map +1 -1
- package/dist/languageService/tooltipUtils.d.ts +5 -1
- package/dist/languageService/tooltipUtils.js +28 -4
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/tests/completions.test.d.ts +1 -0
- package/dist/tests/completions.test.js +331 -0
- package/dist/tests/completions.test.js.map +1 -0
- package/dist/tests/filesystem.test.js +11 -0
- package/dist/tests/filesystem.test.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/harness/vfs/filesystem.d.ts +2 -2
- package/dist/tests/harness/vfs/filesystem.js +5 -1
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/hoverProvider.test.d.ts +1 -0
- package/dist/tests/hoverProvider.test.js +247 -0
- package/dist/tests/hoverProvider.test.js.map +1 -0
- package/dist/tests/indentationUtils.ptvs.test.js +1 -1
- package/dist/tests/indentationUtils.test.js +4 -4
- package/dist/tests/typeEvaluator1.test.js +16 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +5 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +4 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +4 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +6 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/workspaceMap.js +1 -3
- package/dist/workspaceMap.js.map +1 -1
- package/package.json +6 -6
@@ -282,16 +282,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
282
282
|
effectiveTypeCache = new Map();
|
283
283
|
expectedTypeCache = new Map();
|
284
284
|
}
|
285
|
-
function isTypeCached(node) {
|
286
|
-
let cachedType;
|
287
|
-
if (returnTypeInferenceTypeCache && isNodeInReturnTypeInferenceContext(node)) {
|
288
|
-
cachedType = returnTypeInferenceTypeCache.get(node.id);
|
289
|
-
}
|
290
|
-
else {
|
291
|
-
cachedType = typeCache.get(node.id);
|
292
|
-
}
|
293
|
-
return cachedType !== undefined && !cachedType.isIncomplete;
|
294
|
-
}
|
295
285
|
function readTypeCacheEntry(node) {
|
296
286
|
// Should we use a temporary cache associated with a contextual
|
297
287
|
// analysis of a function, contextualized based on call-site argument types?
|
@@ -302,10 +292,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
302
292
|
return typeCache.get(node.id);
|
303
293
|
}
|
304
294
|
}
|
295
|
+
function isTypeCached(node) {
|
296
|
+
const cachedEntry = readTypeCacheEntry(node);
|
297
|
+
return cachedEntry !== undefined && !cachedEntry.typeResult.isIncomplete;
|
298
|
+
}
|
305
299
|
function readTypeCache(node, flags) {
|
306
300
|
var _a, _b;
|
307
301
|
const cacheEntry = readTypeCacheEntry(node);
|
308
|
-
if (!cacheEntry || cacheEntry.isIncomplete) {
|
302
|
+
if (!cacheEntry || cacheEntry.typeResult.isIncomplete) {
|
309
303
|
return undefined;
|
310
304
|
}
|
311
305
|
if (evaluatorOptions.verifyTypeCacheEvaluatorFlags || verifyTypeCacheEvaluatorFlags) {
|
@@ -327,22 +321,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
327
321
|
}
|
328
322
|
}
|
329
323
|
}
|
330
|
-
return cacheEntry.type;
|
324
|
+
return cacheEntry.typeResult.type;
|
331
325
|
}
|
332
|
-
function writeTypeCache(node,
|
326
|
+
function writeTypeCache(node, typeResult, flags, expectedType, allowSpeculativeCaching = false) {
|
333
327
|
// Should we use a temporary cache associated with a contextual
|
334
328
|
// analysis of a function, contextualized based on call-site argument types?
|
335
329
|
const typeCacheToUse = returnTypeInferenceTypeCache && isNodeInReturnTypeInferenceContext(node)
|
336
330
|
? returnTypeInferenceTypeCache
|
337
331
|
: typeCache;
|
338
|
-
typeCacheToUse.set(node.id, {
|
332
|
+
typeCacheToUse.set(node.id, { typeResult, flags });
|
339
333
|
// If the entry is located within a part of the parse tree that is currently being
|
340
334
|
// "speculatively" evaluated, track it so we delete the cached entry when we leave
|
341
335
|
// this speculative context.
|
342
336
|
if (speculativeTypeTracker.isSpeculative(node)) {
|
343
337
|
speculativeTypeTracker.trackEntry(typeCacheToUse, node.id);
|
344
|
-
if (allowSpeculativeCaching) {
|
345
|
-
speculativeTypeTracker.addSpeculativeType(node,
|
338
|
+
if (allowSpeculativeCaching && !typeResult.isIncomplete) {
|
339
|
+
speculativeTypeTracker.addSpeculativeType(node, typeResult, expectedType);
|
346
340
|
}
|
347
341
|
}
|
348
342
|
}
|
@@ -353,7 +347,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
353
347
|
typeCacheToUse.delete(node.id);
|
354
348
|
}
|
355
349
|
function setTypeForNode(node, type = types_1.UnknownType.create(), flags = 0 /* None */) {
|
356
|
-
writeTypeCache(node, type, flags
|
350
|
+
writeTypeCache(node, { type }, flags);
|
357
351
|
}
|
358
352
|
function setAsymmetricDescriptorAssignment(node) {
|
359
353
|
if (speculativeTypeTracker.isSpeculative(/* node */ undefined)) {
|
@@ -435,6 +429,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
435
429
|
evaluateTypesForExpressionInContext(node);
|
436
430
|
})) === null || _a === void 0 ? void 0 : _a.type;
|
437
431
|
}
|
432
|
+
function getTypeResult(node) {
|
433
|
+
return evaluateTypeForSubnode(node, () => {
|
434
|
+
evaluateTypesForExpressionInContext(node);
|
435
|
+
});
|
436
|
+
}
|
438
437
|
// Reads the type of the node from the cache.
|
439
438
|
function getCachedType(node) {
|
440
439
|
return readTypeCache(node, 0 /* None */);
|
@@ -496,12 +495,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
496
495
|
function getTypeOfExpression(node, flags = 0 /* None */, expectedType) {
|
497
496
|
var _a;
|
498
497
|
// Is this type already cached?
|
499
|
-
const
|
500
|
-
if (
|
498
|
+
const cacheEntry = readTypeCacheEntry(node);
|
499
|
+
if (cacheEntry && !cacheEntry.typeResult.isIncomplete) {
|
501
500
|
if (printExpressionTypes) {
|
502
|
-
console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Cached ${printType(
|
501
|
+
console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Cached ${printType(cacheEntry.typeResult.type)} ${cacheEntry.typeResult.typeErrors ? ' Errors' : ''}`);
|
503
502
|
}
|
504
|
-
return
|
503
|
+
return cacheEntry.typeResult;
|
505
504
|
}
|
506
505
|
else {
|
507
506
|
// Is it cached in the speculative type cache?
|
@@ -510,7 +509,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
510
509
|
if (printExpressionTypes) {
|
511
510
|
console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Speculative ${printType(cachedTypeResult.type)}`);
|
512
511
|
}
|
513
|
-
return
|
512
|
+
return cachedTypeResult;
|
514
513
|
}
|
515
514
|
}
|
516
515
|
if (printExpressionTypes) {
|
@@ -695,8 +694,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
695
694
|
typeResult.type.details.illegalRecursionDetected = true;
|
696
695
|
}
|
697
696
|
}
|
698
|
-
writeTypeCache(node, typeResult
|
699
|
-
/* allowSpeculativeCaching */ true);
|
697
|
+
writeTypeCache(node, typeResult, flags, expectedType, /* allowSpeculativeCaching */ true);
|
700
698
|
if (expectedType && !(0, types_1.isAnyOrUnknown)(expectedType) && !(0, types_1.isNever)(expectedType)) {
|
701
699
|
expectedTypeCache.set(node.id, expectedType);
|
702
700
|
if (!typeResult.isIncomplete && !typeResult.expectedTypeDiagAddendum) {
|
@@ -2087,7 +2085,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2087
2085
|
if (!isTypeIncomplete) {
|
2088
2086
|
reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, nameNode, destType, nameNode, ignoreEmptyContainers);
|
2089
2087
|
}
|
2090
|
-
writeTypeCache(nameNode, destType, 0 /* None
|
2088
|
+
writeTypeCache(nameNode, { type: destType, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
2091
2089
|
}
|
2092
2090
|
function assignTypeToMemberAccessNode(target, type, isTypeIncomplete, srcExpr, expectedTypeDiagAddendum) {
|
2093
2091
|
const baseTypeResult = getTypeOfExpression(target.leftExpression, 2 /* DoNotSpecialize */);
|
@@ -2131,8 +2129,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2131
2129
|
if (setTypeResult.isAsymmetricDescriptor) {
|
2132
2130
|
setAsymmetricDescriptorAssignment(target);
|
2133
2131
|
}
|
2134
|
-
writeTypeCache(target.memberName, type, 0 /* None
|
2135
|
-
writeTypeCache(target, type, 0 /* None
|
2132
|
+
writeTypeCache(target.memberName, { type, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
2133
|
+
writeTypeCache(target, { type, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
2136
2134
|
}
|
2137
2135
|
function assignTypeToMemberVariable(node, srcType, isTypeIncomplete, isInstanceMember, srcExprNode) {
|
2138
2136
|
const memberName = node.memberName.value;
|
@@ -2307,7 +2305,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2307
2305
|
const targetType = typeList.length === 0 ? types_1.UnknownType.create() : (0, types_1.combineTypes)(typeList);
|
2308
2306
|
assignTypeToExpression(expr, targetType, isTypeIncomplete, srcExpr, /* ignoreEmptyContainers */ true);
|
2309
2307
|
});
|
2310
|
-
writeTypeCache(target, type, 0 /* None
|
2308
|
+
writeTypeCache(target, { type, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
2311
2309
|
}
|
2312
2310
|
// Replaces all of the top-level TypeVars (as opposed to TypeVars
|
2313
2311
|
// used as type arguments in other types) with their concrete form.
|
@@ -2534,7 +2532,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2534
2532
|
setErrorNode: srcExpr,
|
2535
2533
|
setExpectedTypeDiag: expectedTypeDiagAddendum,
|
2536
2534
|
}, 0 /* None */);
|
2537
|
-
writeTypeCache(target, type, 0 /* None
|
2535
|
+
writeTypeCache(target, { type, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
2538
2536
|
break;
|
2539
2537
|
}
|
2540
2538
|
case 31 /* List */:
|
@@ -2657,14 +2655,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2657
2655
|
case 35 /* MemberAccess */: {
|
2658
2656
|
const baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /* DoNotSpecialize */);
|
2659
2657
|
const memberType = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* None */);
|
2660
|
-
writeTypeCache(node.memberName, memberType.type, 0 /* None
|
2661
|
-
writeTypeCache(node, memberType.type, 0 /* None
|
2658
|
+
writeTypeCache(node.memberName, { type: memberType.type }, 0 /* None */);
|
2659
|
+
writeTypeCache(node, { type: memberType.type }, 0 /* None */);
|
2662
2660
|
break;
|
2663
2661
|
}
|
2664
2662
|
case 24 /* Index */: {
|
2665
2663
|
const baseTypeResult = getTypeOfExpression(node.baseExpression, 2 /* DoNotSpecialize */);
|
2666
2664
|
getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* None */);
|
2667
|
-
writeTypeCache(node, types_1.UnboundType.create(), 0 /* None
|
2665
|
+
writeTypeCache(node, { type: types_1.UnboundType.create() }, 0 /* None */);
|
2668
2666
|
break;
|
2669
2667
|
}
|
2670
2668
|
case 52 /* Tuple */: {
|
@@ -3037,7 +3035,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3037
3035
|
if (enclosingScope) {
|
3038
3036
|
// If the enclosing scope is using type parameter syntax, traditional
|
3039
3037
|
// type variables can't be used in this context.
|
3040
|
-
if (enclosingScope.typeParameters
|
3038
|
+
if (enclosingScope.typeParameters &&
|
3039
|
+
!enclosingScope.typeParameters.parameters.some((param) => param.name.value === type.details.name)) {
|
3041
3040
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeParameterNotDeclared().format({
|
3042
3041
|
name: type.details.name,
|
3043
3042
|
container: enclosingScope.name.value,
|
@@ -3273,8 +3272,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3273
3272
|
const typeResult = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'get' }, flags | 2 /* DoNotSpecialize */);
|
3274
3273
|
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(node)) {
|
3275
3274
|
// Before performing code flow analysis, update the cache to prevent recursion.
|
3276
|
-
writeTypeCache(node, typeResult
|
3277
|
-
writeTypeCache(node.memberName, typeResult
|
3275
|
+
writeTypeCache(node, { ...typeResult, isIncomplete: true }, flags);
|
3276
|
+
writeTypeCache(node.memberName, { ...typeResult, isIncomplete: true }, flags);
|
3278
3277
|
// If the type is initially unbound, see if there's a parent class that
|
3279
3278
|
// potentially initialized the value.
|
3280
3279
|
let typeAtStart = typeResult.type;
|
@@ -3314,7 +3313,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3314
3313
|
typeResult.isIncomplete = true;
|
3315
3314
|
}
|
3316
3315
|
// Cache the type information in the member name node.
|
3317
|
-
writeTypeCache(node.memberName, typeResult
|
3316
|
+
writeTypeCache(node.memberName, typeResult, flags);
|
3318
3317
|
return typeResult;
|
3319
3318
|
}
|
3320
3319
|
function getTypeOfMemberAccessWithBaseType(node, baseTypeResult, usage, flags) {
|
@@ -3687,7 +3686,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3687
3686
|
}
|
3688
3687
|
}
|
3689
3688
|
// Don't include variables within typed dict classes.
|
3690
|
-
if (types_1.ClassType.isTypedDictClass(classType)) {
|
3689
|
+
if ((0, types_1.isClass)(memberInfo.classType) && types_1.ClassType.isTypedDictClass(memberInfo.classType)) {
|
3691
3690
|
const typedDecls = memberInfo.symbol.getTypedDeclarations();
|
3692
3691
|
if (typedDecls.length > 0 && typedDecls[0].type === 1 /* Variable */) {
|
3693
3692
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.memberUnknown().format({ name: memberName }));
|
@@ -4193,7 +4192,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4193
4192
|
});
|
4194
4193
|
if (baseTypeSupportsIndexNarrowing) {
|
4195
4194
|
// Before performing code flow analysis, update the cache to prevent recursion.
|
4196
|
-
writeTypeCache(node, indexTypeResult
|
4195
|
+
writeTypeCache(node, indexTypeResult, flags);
|
4197
4196
|
// See if we can refine the type based on code flow analysis.
|
4198
4197
|
const codeFlowTypeResult = getFlowTypeOfReference(node, symbol_1.indeterminateSymbolId, indexTypeResult.type,
|
4199
4198
|
/* startNode */ undefined, {
|
@@ -5505,7 +5504,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5505
5504
|
isTypeIncomplete = true;
|
5506
5505
|
}
|
5507
5506
|
return {
|
5508
|
-
argumentErrors:
|
5507
|
+
argumentErrors: finalCallResult.argumentErrors,
|
5509
5508
|
isArgumentAnyOrUnknown: finalCallResult.isArgumentAnyOrUnknown,
|
5510
5509
|
returnType: (0, types_1.combineTypes)(returnTypes),
|
5511
5510
|
isTypeIncomplete,
|
@@ -5649,7 +5648,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5649
5648
|
// Replace the result with an unknown type since we don't know
|
5650
5649
|
// what overload should have been used.
|
5651
5650
|
result.returnType = types_1.UnknownType.create();
|
5652
|
-
return result;
|
5651
|
+
return { ...result, argumentErrors: true };
|
5653
5652
|
}
|
5654
5653
|
return { argumentErrors: true, isTypeIncomplete: false };
|
5655
5654
|
}
|
@@ -5927,10 +5926,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5927
5926
|
useSpeculativeMode(errorNode, () => {
|
5928
5927
|
callResult = validateCallArguments(errorNode, argList, { type: constructorMethodType }, typeVarContext.clone(), skipUnknownArgCheck);
|
5929
5928
|
});
|
5930
|
-
if (!
|
5929
|
+
if (!callResult.argumentErrors) {
|
5931
5930
|
// Call validateCallArguments again, this time without speculative
|
5932
5931
|
// mode, so any errors are reported.
|
5933
|
-
|
5932
|
+
callResult = validateCallArguments(errorNode, argList, { type: constructorMethodType }, typeVarContext, skipUnknownArgCheck);
|
5934
5933
|
if (callResult.isTypeIncomplete) {
|
5935
5934
|
isTypeIncomplete = true;
|
5936
5935
|
}
|
@@ -7372,6 +7371,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7372
7371
|
}
|
7373
7372
|
let specializedReturnType = (0, typeUtils_1.addConditionToType)((0, typeUtils_1.applySolvedTypeVars)(returnType, typeVarContext, {
|
7374
7373
|
unknownIfNotFound,
|
7374
|
+
useUnknownOverDefault: skipUnknownArgCheck,
|
7375
7375
|
eliminateUnsolvedInUnions,
|
7376
7376
|
}), typeCondition);
|
7377
7377
|
// If the final return type is an unpacked tuple, turn it into a normal (unpacked) tuple.
|
@@ -7591,7 +7591,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7591
7591
|
if (argParam.argument &&
|
7592
7592
|
argParam.argument.name &&
|
7593
7593
|
!speculativeTypeTracker.isSpeculative(argParam.errorNode)) {
|
7594
|
-
writeTypeCache(argParam.argument.name, expectedType || argType, 0 /* None
|
7594
|
+
writeTypeCache(argParam.argument.name, { type: expectedType || argType, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
7595
7595
|
}
|
7596
7596
|
}
|
7597
7597
|
else {
|
@@ -7997,7 +7997,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7997
7997
|
});
|
7998
7998
|
// Update the type cache so we don't attempt to re-evaluate this node.
|
7999
7999
|
// The type doesn't matter, so use Any.
|
8000
|
-
writeTypeCache(node, types_1.AnyType.create(), /* flags */ undefined
|
8000
|
+
writeTypeCache(node, { type: types_1.AnyType.create() }, /* flags */ undefined);
|
8001
8001
|
return functionType;
|
8002
8002
|
}
|
8003
8003
|
else {
|
@@ -8297,7 +8297,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8297
8297
|
else if (node.operator === 6 /* BitwiseOr */) {
|
8298
8298
|
// If this is a bitwise or ("|"), use the type of the left operand. This allows
|
8299
8299
|
// us to support the case where a TypedDict is being updated with a dict expression.
|
8300
|
-
|
8300
|
+
if ((0, types_1.isClassInstance)(leftType) && types_1.ClassType.isTypedDictClass(leftType)) {
|
8301
|
+
expectedOperandType = leftType;
|
8302
|
+
}
|
8301
8303
|
}
|
8302
8304
|
}
|
8303
8305
|
const rightTypeResult = getTypeOfExpression(rightExpression, flags, expectedOperandType);
|
@@ -9431,7 +9433,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9431
9433
|
functionType.details.typeVarScopeId = getScopeIdForNode(node);
|
9432
9434
|
// Pre-cache the incomplete function type in case the evaluation of the
|
9433
9435
|
// lambda depends on itself.
|
9434
|
-
writeTypeCache(node, functionType,
|
9436
|
+
writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /* None */);
|
9435
9437
|
let expectedFunctionTypes = [];
|
9436
9438
|
if (expectedType) {
|
9437
9439
|
(0, typeUtils_1.mapSubtypes)(expectedType, (subtype) => {
|
@@ -9468,8 +9470,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9468
9470
|
paramType = types_1.FunctionType.getEffectiveParameterType(expectedFunctionType, index);
|
9469
9471
|
}
|
9470
9472
|
if (param.name) {
|
9471
|
-
writeTypeCache(param.name, transformVariadicParamType(node, param.category, paramType), 0 /* None
|
9472
|
-
/* isIncomplete */ false);
|
9473
|
+
writeTypeCache(param.name, { type: transformVariadicParamType(node, param.category, paramType) }, 0 /* None */);
|
9473
9474
|
}
|
9474
9475
|
if (param.defaultValue) {
|
9475
9476
|
// Evaluate the default value if it's present.
|
@@ -9534,8 +9535,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9534
9535
|
if (speculativeTypeTracker.isSpeculative(node)) {
|
9535
9536
|
useSpeculativeMode(node.expression, () => {
|
9536
9537
|
inferLambdaReturnType();
|
9537
|
-
}
|
9538
|
-
/* allowCacheRetention */ false);
|
9538
|
+
});
|
9539
9539
|
}
|
9540
9540
|
else {
|
9541
9541
|
inferLambdaReturnType();
|
@@ -10559,7 +10559,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10559
10559
|
specialType.details.baseClasses.push(strClassType !== null && strClassType !== void 0 ? strClassType : types_1.AnyType.create());
|
10560
10560
|
(0, typeUtils_1.computeMroLinearization)(specialType);
|
10561
10561
|
}
|
10562
|
-
writeTypeCache(node, specialType, 0 /* None
|
10562
|
+
writeTypeCache(node, { type: specialType }, 0 /* None */);
|
10563
10563
|
return specialType;
|
10564
10564
|
}
|
10565
10565
|
return undefined;
|
@@ -10639,7 +10639,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10639
10639
|
if (fileInfo.isTypingStubFile || fileInfo.isTypingExtensionsStubFile) {
|
10640
10640
|
rightHandType = handleTypingStubAssignment(node);
|
10641
10641
|
if (rightHandType) {
|
10642
|
-
writeTypeCache(node.rightExpression, rightHandType, 0 /* None
|
10642
|
+
writeTypeCache(node.rightExpression, { type: rightHandType }, 0 /* None */);
|
10643
10643
|
}
|
10644
10644
|
}
|
10645
10645
|
if (!rightHandType) {
|
@@ -10677,14 +10677,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10677
10677
|
typeAliasTypeVar.details.recursiveTypeAliasScopeId = scopeId;
|
10678
10678
|
typeAliasTypeVar.scopeId = scopeId;
|
10679
10679
|
// Write the type back to the type cache. It will be replaced below.
|
10680
|
-
writeTypeCache(node, typeAliasTypeVar, /* flags */ undefined
|
10681
|
-
writeTypeCache(node.leftExpression, typeAliasTypeVar,
|
10682
|
-
/* flags */ undefined,
|
10683
|
-
/* isIncomplete */ false);
|
10680
|
+
writeTypeCache(node, { type: typeAliasTypeVar }, /* flags */ undefined);
|
10681
|
+
writeTypeCache(node.leftExpression, { type: typeAliasTypeVar }, /* flags */ undefined);
|
10684
10682
|
if (node.leftExpression.nodeType === 54 /* TypeAnnotation */) {
|
10685
|
-
writeTypeCache(node.leftExpression.valueExpression, typeAliasTypeVar,
|
10686
|
-
/* flags */ undefined
|
10687
|
-
/* isIncomplete */ false);
|
10683
|
+
writeTypeCache(node.leftExpression.valueExpression, { type: typeAliasTypeVar },
|
10684
|
+
/* flags */ undefined);
|
10688
10685
|
}
|
10689
10686
|
}
|
10690
10687
|
const srcTypeResult = getTypeOfExpression(node.rightExpression, flags, declaredType);
|
@@ -10753,7 +10750,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10753
10750
|
assignTypeToExpression(node.leftExpression, rightHandType, isIncomplete, node.rightExpression,
|
10754
10751
|
/* ignoreEmptyContainers */ true,
|
10755
10752
|
/* allowAssignmentToFinalVar */ true, expectedTypeDiagAddendum);
|
10756
|
-
writeTypeCache(node, rightHandType, 0 /* None
|
10753
|
+
writeTypeCache(node, { type: rightHandType, isIncomplete }, 0 /* None */);
|
10757
10754
|
}
|
10758
10755
|
function isPossibleTypeAliasOrTypedDict(decl) {
|
10759
10756
|
var _a;
|
@@ -10800,7 +10797,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10800
10797
|
typeAliasTypeVar.details.recursiveTypeAliasScopeId = scopeId;
|
10801
10798
|
typeAliasTypeVar.scopeId = scopeId;
|
10802
10799
|
// Write the type to the type cache. It will be replaced below.
|
10803
|
-
writeTypeCache(node.name, typeAliasTypeVar, /* flags */ undefined
|
10800
|
+
writeTypeCache(node.name, { type: typeAliasTypeVar }, /* flags */ undefined);
|
10804
10801
|
// Set a partial type to handle recursive (self-referential) type aliases.
|
10805
10802
|
const scope = ScopeUtils.getScopeForNode(node);
|
10806
10803
|
const typeAliasSymbol = scope === null || scope === void 0 ? void 0 : scope.lookUpSymbolRecursive(node.name.value);
|
@@ -10839,7 +10836,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10839
10836
|
name: node.name.value,
|
10840
10837
|
}), node.name);
|
10841
10838
|
}
|
10842
|
-
writeTypeCache(node.name, aliasType, 0 /* None
|
10839
|
+
writeTypeCache(node.name, { type: aliasType, isIncomplete }, 0 /* None */);
|
10843
10840
|
return aliasType;
|
10844
10841
|
}
|
10845
10842
|
function evaluateTypesForAugmentedAssignment(node) {
|
@@ -10847,7 +10844,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10847
10844
|
return;
|
10848
10845
|
}
|
10849
10846
|
const destTypeResult = getTypeOfAugmentedAssignment(node, /* expectedType */ undefined);
|
10850
|
-
writeTypeCache(node, destTypeResult
|
10847
|
+
writeTypeCache(node, destTypeResult, 0 /* None */);
|
10851
10848
|
}
|
10852
10849
|
function getPseudoGenericTypeVarName(paramName) {
|
10853
10850
|
return `__type_of_${paramName}`;
|
@@ -10906,8 +10903,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10906
10903
|
setSymbolResolutionPartialType(classSymbol, classDecl, classType);
|
10907
10904
|
}
|
10908
10905
|
classType.details.flags |= 131072 /* PartiallyEvaluated */;
|
10909
|
-
writeTypeCache(node, classType, /* flags */ undefined
|
10910
|
-
writeTypeCache(node.name, classType, /* flags */ undefined
|
10906
|
+
writeTypeCache(node, { type: classType }, /* flags */ undefined);
|
10907
|
+
writeTypeCache(node.name, { type: classType }, /* flags */ undefined);
|
10911
10908
|
// Keep a list of unique type parameters that are used in the
|
10912
10909
|
// base class arguments.
|
10913
10910
|
let typeParameters = [];
|
@@ -11330,9 +11327,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11330
11327
|
}
|
11331
11328
|
}
|
11332
11329
|
// Update the undecorated class type.
|
11333
|
-
writeTypeCache(node.name, classType, 0 /* None
|
11330
|
+
writeTypeCache(node.name, { type: classType }, 0 /* None */);
|
11334
11331
|
// Update the decorated class type.
|
11335
|
-
writeTypeCache(node, decoratedType, 0 /* None
|
11332
|
+
writeTypeCache(node, { type: decoratedType }, 0 /* None */);
|
11336
11333
|
// Stash away a reference to the UnionType class if we encounter it.
|
11337
11334
|
// There's no easy way to otherwise reference it.
|
11338
11335
|
if (types_1.ClassType.isBuiltIn(classType, 'UnionType')) {
|
@@ -11345,7 +11342,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11345
11342
|
// parameters and updates the scope of the type parameter referred to in the
|
11346
11343
|
// default type expression.
|
11347
11344
|
function validateTypeParameterDefault(errorNode, typeParam, otherLiveTypeParams) {
|
11348
|
-
if (!typeParam.details.defaultType
|
11345
|
+
if (!typeParam.details.defaultType &&
|
11346
|
+
!typeParam.details.isSynthesized &&
|
11347
|
+
!typeParam.details.isSynthesizedSelf) {
|
11349
11348
|
const typeVarWithDefault = otherLiveTypeParams.find((param) => param.details.defaultType);
|
11350
11349
|
if (typeVarWithDefault) {
|
11351
11350
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarWithoutDefault().format({
|
@@ -11444,7 +11443,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11444
11443
|
if (!typeOfParam || !(0, types_1.isTypeVar)(typeOfParam)) {
|
11445
11444
|
return;
|
11446
11445
|
}
|
11447
|
-
writeTypeCache(param.name, typeOfParam, 0 /* None
|
11446
|
+
writeTypeCache(param.name, { type: typeOfParam }, 0 /* None */);
|
11448
11447
|
paramTypes.push(typeOfParam);
|
11449
11448
|
});
|
11450
11449
|
return paramTypes;
|
@@ -11743,8 +11742,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11743
11742
|
if (functionDecl && functionSymbol) {
|
11744
11743
|
setSymbolResolutionPartialType(functionSymbol.symbol, functionDecl, functionType);
|
11745
11744
|
}
|
11746
|
-
writeTypeCache(node, functionType, /* flags */ undefined
|
11747
|
-
writeTypeCache(node.name, functionType, /* flags */ undefined
|
11745
|
+
writeTypeCache(node, { type: functionType }, /* flags */ undefined);
|
11746
|
+
writeTypeCache(node.name, { type: functionType }, /* flags */ undefined);
|
11748
11747
|
// Is this an "__init__" method within a pseudo-generic class? If so,
|
11749
11748
|
// we'll add generic types to the constructor's parameters.
|
11750
11749
|
const addGenericParamTypes = containingClassType &&
|
@@ -11954,7 +11953,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11954
11953
|
if ((0, types_1.isUnknown)(paramType)) {
|
11955
11954
|
functionType.details.flags |= 16384 /* UnannotatedParams */;
|
11956
11955
|
}
|
11957
|
-
writeTypeCache(paramNameNode, paramType, 0 /* None
|
11956
|
+
writeTypeCache(paramNameNode, { type: paramType }, 0 /* None */);
|
11958
11957
|
}
|
11959
11958
|
});
|
11960
11959
|
// If the function ends in P.args and P.kwargs parameters, make it exempt from
|
@@ -12059,8 +12058,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12059
12058
|
}
|
12060
12059
|
decoratedType = addOverloadsToFunctionType(node, decoratedType);
|
12061
12060
|
}
|
12062
|
-
writeTypeCache(node.name, functionType, 0 /* None
|
12063
|
-
writeTypeCache(node, decoratedType, 0 /* None
|
12061
|
+
writeTypeCache(node.name, { type: functionType }, 0 /* None */);
|
12062
|
+
writeTypeCache(node, { type: decoratedType }, 0 /* None */);
|
12064
12063
|
return { functionType, decoratedType };
|
12065
12064
|
}
|
12066
12065
|
// If the declared return type of a function contains type variables that
|
@@ -12640,7 +12639,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12640
12639
|
}
|
12641
12640
|
}
|
12642
12641
|
}
|
12643
|
-
writeTypeCache(node.suite, inferredReturnType, 0 /* None
|
12642
|
+
writeTypeCache(node.suite, { type: inferredReturnType, isIncomplete }, 0 /* None */);
|
12644
12643
|
}
|
12645
12644
|
finally {
|
12646
12645
|
functionRecursionMap.delete(node.id);
|
@@ -12683,7 +12682,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12683
12682
|
const iteratorTypeResult = getTypeOfExpression(node.iterableExpression);
|
12684
12683
|
const iteratedType = (_b = (_a = getTypeOfIterator(iteratorTypeResult, !!node.isAsync, node.iterableExpression)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
12685
12684
|
assignTypeToExpression(node.targetExpression, iteratedType, !!iteratorTypeResult.isIncomplete, node.targetExpression);
|
12686
|
-
writeTypeCache(node, iteratedType, 0 /* None
|
12685
|
+
writeTypeCache(node, { type: iteratedType, isIncomplete: !!iteratorTypeResult.isIncomplete }, 0 /* None */);
|
12687
12686
|
}
|
12688
12687
|
function evaluateTypesForExceptStatement(node) {
|
12689
12688
|
// This should be called only if the except node has a target exception.
|
@@ -12733,7 +12732,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12733
12732
|
if (node.name) {
|
12734
12733
|
assignTypeToExpression(node.name, targetType, /* isIncomplete */ false, node.name);
|
12735
12734
|
}
|
12736
|
-
writeTypeCache(node, targetType, 0 /* None
|
12735
|
+
writeTypeCache(node, { type: targetType }, 0 /* None */);
|
12737
12736
|
}
|
12738
12737
|
function evaluateTypesForWithStatement(node) {
|
12739
12738
|
if (readTypeCache(node, 0 /* None */)) {
|
@@ -12798,7 +12797,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12798
12797
|
if (node.target) {
|
12799
12798
|
assignTypeToExpression(node.target, scopedType, !!exprTypeResult.isIncomplete, node.target);
|
12800
12799
|
}
|
12801
|
-
writeTypeCache(node, scopedType, 0 /* None
|
12800
|
+
writeTypeCache(node, { type: scopedType, isIncomplete: !!exprTypeResult.isIncomplete }, 0 /* None */);
|
12802
12801
|
}
|
12803
12802
|
function evaluateTypesForImportAs(node) {
|
12804
12803
|
var _a;
|
@@ -12830,7 +12829,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12830
12829
|
}
|
12831
12830
|
}
|
12832
12831
|
assignTypeToNameNode(symbolNameNode, symbolType, /* isIncomplete */ false, /* ignoreEmptyContainers */ false);
|
12833
|
-
writeTypeCache(node, symbolType, 0 /* None
|
12832
|
+
writeTypeCache(node, { type: symbolType }, 0 /* None */);
|
12834
12833
|
}
|
12835
12834
|
function evaluateTypesForImportFromAs(node) {
|
12836
12835
|
var _a;
|
@@ -12887,7 +12886,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12887
12886
|
}
|
12888
12887
|
}
|
12889
12888
|
assignTypeToNameNode(aliasNode, symbolType, /* isIncomplete */ false, /* ignoreEmptyContainers */ false);
|
12890
|
-
writeTypeCache(node, symbolType, 0 /* None
|
12889
|
+
writeTypeCache(node, { type: symbolType }, 0 /* None */);
|
12891
12890
|
}
|
12892
12891
|
function evaluateTypesForMatchStatement(node) {
|
12893
12892
|
if (readTypeCache(node, 0 /* None */)) {
|
@@ -12902,7 +12901,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12902
12901
|
/* isPositiveTest */ false);
|
12903
12902
|
}
|
12904
12903
|
}
|
12905
|
-
writeTypeCache(node, subjectType, 0 /* None
|
12904
|
+
writeTypeCache(node, { type: subjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* None */);
|
12906
12905
|
}
|
12907
12906
|
function evaluateTypesForCaseStatement(node) {
|
12908
12907
|
if (readTypeCache(node, 0 /* None */)) {
|
@@ -12936,7 +12935,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12936
12935
|
subjectType = (0, patternMatching_1.narrowTypeBasedOnPattern)(evaluatorInterface, subjectType, node.pattern,
|
12937
12936
|
/* isPositiveTest */ true);
|
12938
12937
|
(0, patternMatching_1.assignTypeToPatternTargets)(evaluatorInterface, subjectType, !!subjectTypeResult.isIncomplete, subjectIsObject, node.pattern);
|
12939
|
-
writeTypeCache(node, subjectType, 0 /* None
|
12938
|
+
writeTypeCache(node, { type: subjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* None */);
|
12940
12939
|
}
|
12941
12940
|
function evaluateTypesForImportFrom(node) {
|
12942
12941
|
if (readTypeCache(node, 0 /* None */)) {
|
@@ -12958,7 +12957,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12958
12957
|
}
|
12959
12958
|
}
|
12960
12959
|
assignTypeToNameNode(symbolNameNode, symbolType, /* isIncomplete */ false, /* ignoreEmptyContainers */ false);
|
12961
|
-
writeTypeCache(node, symbolType, 0 /* None
|
12960
|
+
writeTypeCache(node, { type: symbolType }, 0 /* None */);
|
12962
12961
|
}
|
12963
12962
|
function evaluateTypesForTypeAnnotationNode(node) {
|
12964
12963
|
var _a;
|
@@ -12974,7 +12973,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12974
12973
|
allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(node.valueExpression),
|
12975
12974
|
allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(node.valueExpression),
|
12976
12975
|
});
|
12977
|
-
writeTypeCache(node.valueExpression, annotationType, 0 /* None
|
12976
|
+
writeTypeCache(node.valueExpression, { type: annotationType }, 0 /* None */);
|
12978
12977
|
}
|
12979
12978
|
}
|
12980
12979
|
function getAliasedSymbolTypeForName(node, name) {
|
@@ -13311,7 +13310,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13311
13310
|
const param = functionNode.parameters[paramIndex];
|
13312
13311
|
const annotatedType = getTypeOfParameterAnnotation(typeAnnotation, functionNode.parameters[paramIndex].category);
|
13313
13312
|
const adjType = transformVariadicParamType(node, node.category, adjustParameterAnnotatedType(param, annotatedType));
|
13314
|
-
writeTypeCache(node.name, adjType, 0 /* None
|
13313
|
+
writeTypeCache(node.name, { type: adjType }, 0 /* None */);
|
13315
13314
|
return;
|
13316
13315
|
}
|
13317
13316
|
const containingClassNode = ParseTreeUtils.getEnclosingClass(functionNode, /* stopAtFunction */ true);
|
@@ -13322,7 +13321,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13322
13321
|
const typeParamName = getPseudoGenericTypeVarName(node.name.value);
|
13323
13322
|
const paramType = classInfo.classType.details.typeParameters.find((param) => param.details.name === typeParamName);
|
13324
13323
|
if (paramType) {
|
13325
|
-
writeTypeCache(node.name, paramType, 0 /* None
|
13324
|
+
writeTypeCache(node.name, { type: paramType }, 0 /* None */);
|
13326
13325
|
return;
|
13327
13326
|
}
|
13328
13327
|
}
|
@@ -13331,8 +13330,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13331
13330
|
// a parent class if it has an annotated type.
|
13332
13331
|
const functionFlags = getFunctionFlagsFromDecorators(functionNode, /* isInClass */ true);
|
13333
13332
|
const inferredParamType = inferParameterType(functionNode, functionFlags, paramIndex, classInfo === null || classInfo === void 0 ? void 0 : classInfo.classType);
|
13334
|
-
writeTypeCache(node.name, transformVariadicParamType(node, node.category, inferredParamType !== null && inferredParamType !== void 0 ? inferredParamType : types_1.UnknownType.create()), 0 /* None
|
13335
|
-
/* isIncomplete */ false);
|
13333
|
+
writeTypeCache(node.name, { type: transformVariadicParamType(node, node.category, inferredParamType !== null && inferredParamType !== void 0 ? inferredParamType : types_1.UnknownType.create()) }, 0 /* None */);
|
13336
13334
|
}
|
13337
13335
|
// Evaluates the types that are assigned within the statement that contains
|
13338
13336
|
// the specified parse node. In some cases, a broader statement may need to
|
@@ -13445,13 +13443,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13445
13443
|
// If the type cache is already populated with a complete type,
|
13446
13444
|
// don't bother doing additional work.
|
13447
13445
|
let cacheEntry = readTypeCacheEntry(subnode);
|
13448
|
-
if (cacheEntry && !cacheEntry.isIncomplete) {
|
13449
|
-
return { type: cacheEntry.type };
|
13446
|
+
if (cacheEntry && !cacheEntry.typeResult.isIncomplete) {
|
13447
|
+
return { type: cacheEntry.typeResult.type };
|
13450
13448
|
}
|
13451
13449
|
callback();
|
13452
13450
|
cacheEntry = readTypeCacheEntry(subnode);
|
13453
13451
|
if (cacheEntry) {
|
13454
|
-
return {
|
13452
|
+
return {
|
13453
|
+
type: cacheEntry.typeResult.type,
|
13454
|
+
isIncomplete: cacheEntry.typeResult.isIncomplete,
|
13455
|
+
expectedTypeDiagAddendum: cacheEntry.typeResult.expectedTypeDiagAddendum,
|
13456
|
+
};
|
13455
13457
|
}
|
13456
13458
|
return undefined;
|
13457
13459
|
}
|
@@ -14002,8 +14004,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14002
14004
|
// Disables recording of errors and warnings and disables
|
14003
14005
|
// any caching of types, under the assumption that we're
|
14004
14006
|
// performing speculative evaluations.
|
14005
|
-
function useSpeculativeMode(speculativeNode, callback
|
14006
|
-
speculativeTypeTracker.enterSpeculativeContext(speculativeNode
|
14007
|
+
function useSpeculativeMode(speculativeNode, callback) {
|
14008
|
+
speculativeTypeTracker.enterSpeculativeContext(speculativeNode);
|
14007
14009
|
try {
|
14008
14010
|
const result = callback();
|
14009
14011
|
speculativeTypeTracker.leaveSpeculativeContext();
|
@@ -14381,8 +14383,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14381
14383
|
}
|
14382
14384
|
// Cache the value before we evaluate the bound or the default type in
|
14383
14385
|
// case it refers to itself in a circular manner.
|
14384
|
-
writeTypeCache(node, typeVar, /* flags */ undefined
|
14385
|
-
writeTypeCache(node.name, typeVar, /* flags */ undefined
|
14386
|
+
writeTypeCache(node, { type: typeVar }, /* flags */ undefined);
|
14387
|
+
writeTypeCache(node.name, { type: typeVar }, /* flags */ undefined);
|
14386
14388
|
if (node.boundExpression) {
|
14387
14389
|
if (node.boundExpression.nodeType === 52 /* Tuple */) {
|
14388
14390
|
const constraints = node.boundExpression.expressions.map((constraint) => {
|
@@ -14684,7 +14686,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14684
14686
|
return getEffectiveTypeOfSymbolForUsage(symbol).type;
|
14685
14687
|
}
|
14686
14688
|
function getEffectiveTypeOfSymbolForUsage(symbol, usageNode, useLastDecl = false) {
|
14687
|
-
var _a;
|
14689
|
+
var _a, _b;
|
14688
14690
|
// If there's a declared type, it takes precedence over inferred types.
|
14689
14691
|
if (symbol.hasTypedDeclarations()) {
|
14690
14692
|
const declaredType = getDeclaredTypeOfSymbol(symbol, usageNode);
|
@@ -14708,7 +14710,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14708
14710
|
}
|
14709
14711
|
// Look in the cache to see if we've computed this already.
|
14710
14712
|
let cacheEntries = effectiveTypeCache.get(symbol.id);
|
14711
|
-
let evaluationAttempts = 0;
|
14712
14713
|
const usageNodeId = usageNode ? usageNode.id : undefined;
|
14713
14714
|
const effectiveTypeCacheKey = `${usageNodeId === undefined ? '.' : usageNodeId.toString()}${useLastDecl ? '*' : ''}`;
|
14714
14715
|
if (cacheEntries) {
|
@@ -14717,7 +14718,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14717
14718
|
if (!result.isIncomplete) {
|
14718
14719
|
return result;
|
14719
14720
|
}
|
14720
|
-
evaluationAttempts = ((_a = result.evaluationAttempts) !== null && _a !== void 0 ? _a : 0) + 1;
|
14721
14721
|
}
|
14722
14722
|
}
|
14723
14723
|
// Infer the type.
|
@@ -14845,20 +14845,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14845
14845
|
}
|
14846
14846
|
isIncomplete = true;
|
14847
14847
|
// Note that at least one decl could not be evaluated because
|
14848
|
-
// it was already in the process of being evaluated.
|
14849
|
-
|
14850
|
-
// many times because this probably means there's a cyclical
|
14851
|
-
// dependency that cannot be broken.
|
14852
|
-
if (evaluationAttempts < maxEffectiveTypeEvaluationAttempts) {
|
14853
|
-
sawPendingEvaluation = true;
|
14854
|
-
}
|
14848
|
+
// it was already in the process of being evaluated.
|
14849
|
+
sawPendingEvaluation = true;
|
14855
14850
|
}
|
14856
14851
|
}
|
14857
14852
|
});
|
14858
14853
|
if (typesToCombine.length > 0) {
|
14854
|
+
// How many times have we already attempted to evaluate this declaration already?
|
14855
|
+
const evaluationAttempts = ((_b = (_a = cacheEntries === null || cacheEntries === void 0 ? void 0 : cacheEntries.get(effectiveTypeCacheKey)) === null || _a === void 0 ? void 0 : _a.evaluationAttempts) !== null && _b !== void 0 ? _b : 0) + 1;
|
14856
|
+
// Ignore the pending evaluation flag if we've already attempted the
|
14857
|
+
// type evaluation many times because this probably means there's a
|
14858
|
+
// cyclical dependency that cannot be broken.
|
14859
|
+
isIncomplete = sawPendingEvaluation && evaluationAttempts < maxEffectiveTypeEvaluationAttempts;
|
14859
14860
|
const result = {
|
14860
14861
|
type: (0, types_1.combineTypes)(typesToCombine),
|
14861
|
-
isIncomplete
|
14862
|
+
isIncomplete,
|
14862
14863
|
includesVariableDecl,
|
14863
14864
|
includesIllegalTypeAliasDecl: !decls.every((decl) => (0, declarationUtils_1.isPossibleTypeAliasDeclaration)(decl)),
|
14864
14865
|
isRecursiveDefinition: false,
|
@@ -14880,7 +14881,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14880
14881
|
includesVariableDecl,
|
14881
14882
|
includesIllegalTypeAliasDecl: !decls.every((decl) => (0, declarationUtils_1.isPossibleTypeAliasDeclaration)(decl)),
|
14882
14883
|
isRecursiveDefinition: false,
|
14883
|
-
evaluationAttempts,
|
14884
14884
|
};
|
14885
14885
|
}
|
14886
14886
|
function getDeclaredTypeOfSymbol(symbol, usageNode) {
|
@@ -15139,7 +15139,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15139
15139
|
paramType = types_1.UnknownType.create();
|
15140
15140
|
}
|
15141
15141
|
paramTypes.push(paramType);
|
15142
|
-
writeTypeCache(param.name, paramType, 0 /* None
|
15142
|
+
writeTypeCache(param.name, { type: paramType }, 0 /* None */);
|
15143
15143
|
}
|
15144
15144
|
});
|
15145
15145
|
// Don't bother trying to determine the contextual return
|
@@ -16658,6 +16658,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16658
16658
|
if (destDetails.argsIndex === undefined) {
|
16659
16659
|
return;
|
16660
16660
|
}
|
16661
|
+
// If the *args parameter isn't an unpacked TypeVarTuple or tuple,
|
16662
|
+
// we have nothing to do.
|
16663
|
+
if (!(0, types_1.isUnpacked)(destDetails.params[destDetails.argsIndex].type)) {
|
16664
|
+
return;
|
16665
|
+
}
|
16661
16666
|
// If the source doesn't have enough positional parameters, we have nothing to do.
|
16662
16667
|
if (srcDetails.params.length < destDetails.argsIndex) {
|
16663
16668
|
return;
|
@@ -16891,9 +16896,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16891
16896
|
// The converse situation is OK.
|
16892
16897
|
if (!types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType) &&
|
16893
16898
|
srcParamDetails.argsIndex === undefined &&
|
16899
|
+
srcType.details.paramSpec === undefined &&
|
16894
16900
|
destParamDetails.argsIndex !== undefined &&
|
16895
|
-
!destParamDetails.hasUnpackedVariadicTypeVar
|
16896
|
-
!targetIncludesParamSpec) {
|
16901
|
+
!destParamDetails.hasUnpackedVariadicTypeVar) {
|
16897
16902
|
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.Localizer.DiagnosticAddendum.argsParamMissing().format({
|
16898
16903
|
paramName: (_h = destParamDetails.params[destParamDetails.argsIndex].param.name) !== null && _h !== void 0 ? _h : '',
|
16899
16904
|
}));
|
@@ -17848,6 +17853,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17848
17853
|
const evaluatorInterface = {
|
17849
17854
|
runWithCancellationToken,
|
17850
17855
|
getType,
|
17856
|
+
getTypeResult,
|
17851
17857
|
getCachedType,
|
17852
17858
|
getTypeOfExpression,
|
17853
17859
|
getTypeOfAnnotation,
|