@zzzen/pyright-internal 1.2.0-dev.20230101 → 1.2.0-dev.20230115
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/analyzerFileInfo.js +14 -1
- package/dist/analyzer/analyzerFileInfo.js.map +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +3 -3
- package/dist/analyzer/backgroundAnalysisProgram.js +4 -4
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -1
- package/dist/analyzer/checker.js +145 -53
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +26 -11
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +4 -2
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/dataClasses.js +6 -1
- package/dist/analyzer/dataClasses.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 +54 -32
- 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/service.d.ts +3 -2
- package/dist/analyzer/service.js +14 -12
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +4 -3
- package/dist/analyzer/sourceFile.js +4 -4
- package/dist/analyzer/sourceFile.js.map +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 +0 -1
- package/dist/analyzer/typeCacheUtils.js +3 -3
- 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 +494 -423
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +20 -13
- package/dist/analyzer/typeEvaluatorTypes.js +15 -15
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +5 -1
- package/dist/analyzer/typeGuards.js +204 -44
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +8 -0
- package/dist/analyzer/typeUtils.js +15 -4
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +3 -0
- package/dist/analyzer/types.js +10 -2
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +4 -1
- package/dist/backgroundAnalysisBase.js +1 -1
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +5 -2
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/createTypeStub.js +3 -0
- package/dist/commands/createTypeStub.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/configOptions.d.ts +1 -0
- package/dist/common/configOptions.js +4 -0
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/diagnosticRules.d.ts +1 -0
- package/dist/common/diagnosticRules.js +1 -0
- package/dist/common/diagnosticRules.js.map +1 -1
- package/dist/common/fileSystem.d.ts +1 -0
- package/dist/common/fileSystem.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/languageServerBase.js +2 -2
- package/dist/languageServerBase.js.map +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/documentSymbolCollector.d.ts +12 -4
- package/dist/languageService/documentSymbolCollector.js +103 -22
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/documentSymbolProvider.js +6 -0
- package/dist/languageService/documentSymbolProvider.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.d.ts +1 -1
- package/dist/languageService/indentationUtils.js +74 -29
- package/dist/languageService/indentationUtils.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +5 -4
- package/dist/languageService/referencesProvider.js +15 -10
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameModuleProvider.js +11 -11
- package/dist/languageService/renameModuleProvider.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/localization/localize.d.ts +3 -0
- package/dist/localization/localize.js +3 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +3 -0
- package/dist/parser/tokenizer.js +6 -2
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/tests/checker.test.js +16 -0
- package/dist/tests/checker.test.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/documentSymbolCollector.test.js +86 -5
- package/dist/tests/documentSymbolCollector.test.js.map +1 -1
- package/dist/tests/filesystem.test.js +11 -0
- package/dist/tests/filesystem.test.js.map +1 -1
- package/dist/tests/fourslash/rename.init.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.init.fourslash.js +23 -0
- package/dist/tests/fourslash/rename.init.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/testState.d.ts +2 -2
- package/dist/tests/harness/fourslash/testState.js +10 -7
- 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 +13 -13
- package/dist/tests/indentationUtils.ptvs.test.js.map +1 -1
- package/dist/tests/indentationUtils.test.js +68 -10
- package/dist/tests/indentationUtils.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +24 -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 +10 -2
- 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,33 +321,27 @@ 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, inferenceContext, 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, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType);
|
346
340
|
}
|
347
341
|
}
|
348
342
|
}
|
349
|
-
function deleteTypeCacheEntry(node) {
|
350
|
-
const typeCacheToUse = returnTypeInferenceTypeCache && isNodeInReturnTypeInferenceContext(node)
|
351
|
-
? returnTypeInferenceTypeCache
|
352
|
-
: typeCache;
|
353
|
-
typeCacheToUse.delete(node.id);
|
354
|
-
}
|
355
343
|
function setTypeForNode(node, type = types_1.UnknownType.create(), flags = 0 /* None */) {
|
356
|
-
writeTypeCache(node, type, flags
|
344
|
+
writeTypeCache(node, { type }, flags);
|
357
345
|
}
|
358
346
|
function setAsymmetricDescriptorAssignment(node) {
|
359
347
|
if (speculativeTypeTracker.isSpeculative(/* node */ undefined)) {
|
@@ -435,6 +423,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
435
423
|
evaluateTypesForExpressionInContext(node);
|
436
424
|
})) === null || _a === void 0 ? void 0 : _a.type;
|
437
425
|
}
|
426
|
+
function getTypeResult(node) {
|
427
|
+
return evaluateTypeForSubnode(node, () => {
|
428
|
+
evaluateTypesForExpressionInContext(node);
|
429
|
+
});
|
430
|
+
}
|
438
431
|
// Reads the type of the node from the cache.
|
439
432
|
function getCachedType(node) {
|
440
433
|
return readTypeCache(node, 0 /* None */);
|
@@ -493,24 +486,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
493
486
|
typedDictClassType = getTypingType(node, '_TypedDict');
|
494
487
|
}
|
495
488
|
}
|
496
|
-
function getTypeOfExpression(node, flags = 0 /* None */,
|
497
|
-
var _a;
|
489
|
+
function getTypeOfExpression(node, flags = 0 /* None */, inferenceContext) {
|
490
|
+
var _a, _b;
|
498
491
|
// Is this type already cached?
|
499
|
-
const
|
500
|
-
if (
|
492
|
+
const cacheEntry = readTypeCacheEntry(node);
|
493
|
+
if (cacheEntry && !cacheEntry.typeResult.isIncomplete) {
|
501
494
|
if (printExpressionTypes) {
|
502
|
-
console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Cached ${printType(
|
495
|
+
console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Cached ${printType(cacheEntry.typeResult.type)} ${cacheEntry.typeResult.typeErrors ? ' Errors' : ''}`);
|
503
496
|
}
|
504
|
-
return
|
497
|
+
return cacheEntry.typeResult;
|
505
498
|
}
|
506
499
|
else {
|
507
500
|
// Is it cached in the speculative type cache?
|
508
|
-
const cachedTypeResult = speculativeTypeTracker.getSpeculativeType(node, expectedType);
|
501
|
+
const cachedTypeResult = speculativeTypeTracker.getSpeculativeType(node, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType);
|
509
502
|
if (cachedTypeResult) {
|
510
503
|
if (printExpressionTypes) {
|
511
504
|
console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Speculative ${printType(cachedTypeResult.type)}`);
|
512
505
|
}
|
513
|
-
return
|
506
|
+
return cachedTypeResult;
|
514
507
|
}
|
515
508
|
}
|
516
509
|
if (printExpressionTypes) {
|
@@ -521,14 +514,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
521
514
|
// the cancellation check. If the operation is canceled, an exception
|
522
515
|
// will be thrown at this point.
|
523
516
|
checkForCancellation();
|
524
|
-
|
517
|
+
if (inferenceContext) {
|
518
|
+
inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
|
519
|
+
}
|
525
520
|
// If we haven't already fetched some core type definitions from the
|
526
521
|
// typeshed stubs, do so here. It would be better to fetch this when it's
|
527
522
|
// needed in assignType, but we don't have access to the parse tree
|
528
523
|
// at that point.
|
529
524
|
initializedBasicTypes(node);
|
530
525
|
let typeResult;
|
531
|
-
let reportExpectingTypeErrors = (flags &
|
526
|
+
let reportExpectingTypeErrors = (flags & 128 /* ExpectingType */) !== 0;
|
532
527
|
switch (node.nodeType) {
|
533
528
|
case 38 /* Name */: {
|
534
529
|
typeResult = getTypeOfName(node, flags);
|
@@ -543,11 +538,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
543
538
|
break;
|
544
539
|
}
|
545
540
|
case 9 /* Call */: {
|
546
|
-
typeResult = getTypeOfCall(node,
|
541
|
+
typeResult = getTypeOfCall(node, inferenceContext, flags);
|
547
542
|
break;
|
548
543
|
}
|
549
544
|
case 52 /* Tuple */: {
|
550
|
-
typeResult = getTypeOfTuple(node,
|
545
|
+
typeResult = getTypeOfTuple(node, inferenceContext, flags);
|
551
546
|
break;
|
552
547
|
}
|
553
548
|
case 11 /* Constant */: {
|
@@ -573,20 +568,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
573
568
|
break;
|
574
569
|
}
|
575
570
|
case 55 /* UnaryOperation */: {
|
576
|
-
typeResult = getTypeOfUnaryOperation(node,
|
571
|
+
typeResult = getTypeOfUnaryOperation(node, inferenceContext);
|
577
572
|
break;
|
578
573
|
}
|
579
574
|
case 7 /* BinaryOperation */: {
|
580
|
-
typeResult = getTypeOfBinaryOperation(node,
|
575
|
+
typeResult = getTypeOfBinaryOperation(node, inferenceContext, flags);
|
581
576
|
break;
|
582
577
|
}
|
583
578
|
case 5 /* AugmentedAssignment */: {
|
584
|
-
typeResult = getTypeOfAugmentedAssignment(node,
|
579
|
+
typeResult = getTypeOfAugmentedAssignment(node, inferenceContext);
|
585
580
|
break;
|
586
581
|
}
|
587
582
|
case 31 /* List */:
|
588
583
|
case 45 /* Set */: {
|
589
|
-
typeResult = getTypeOfListOrSet(node,
|
584
|
+
typeResult = getTypeOfListOrSet(node, inferenceContext);
|
590
585
|
break;
|
591
586
|
}
|
592
587
|
case 46 /* Slice */: {
|
@@ -594,23 +589,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
594
589
|
break;
|
595
590
|
}
|
596
591
|
case 6 /* Await */: {
|
597
|
-
typeResult = getTypeOfAwaitOperator(node, flags,
|
592
|
+
typeResult = getTypeOfAwaitOperator(node, flags, inferenceContext);
|
598
593
|
break;
|
599
594
|
}
|
600
595
|
case 51 /* Ternary */: {
|
601
|
-
typeResult = getTypeOfTernary(node, flags,
|
596
|
+
typeResult = getTypeOfTernary(node, flags, inferenceContext);
|
602
597
|
break;
|
603
598
|
}
|
604
599
|
case 32 /* ListComprehension */: {
|
605
|
-
typeResult = getTypeOfListComprehension(node,
|
600
|
+
typeResult = getTypeOfListComprehension(node, inferenceContext);
|
606
601
|
break;
|
607
602
|
}
|
608
603
|
case 15 /* Dictionary */: {
|
609
|
-
typeResult = getTypeOfDictionary(node,
|
604
|
+
typeResult = getTypeOfDictionary(node, inferenceContext);
|
610
605
|
break;
|
611
606
|
}
|
612
607
|
case 30 /* Lambda */: {
|
613
|
-
typeResult = getTypeOfLambda(node,
|
608
|
+
typeResult = getTypeOfLambda(node, inferenceContext);
|
614
609
|
break;
|
615
610
|
}
|
616
611
|
case 3 /* Assignment */: {
|
@@ -637,15 +632,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
637
632
|
break;
|
638
633
|
}
|
639
634
|
case 56 /* Unpack */: {
|
640
|
-
typeResult = getTypeOfUnpackOperator(node, flags,
|
635
|
+
typeResult = getTypeOfUnpackOperator(node, flags, inferenceContext);
|
641
636
|
break;
|
642
637
|
}
|
643
638
|
case 54 /* TypeAnnotation */: {
|
644
|
-
typeResult = getTypeOfExpression(node.typeAnnotation,
|
645
|
-
|
639
|
+
typeResult = getTypeOfExpression(node.typeAnnotation, 128 /* ExpectingType */ |
|
640
|
+
256 /* ExpectingTypeAnnotation */ |
|
646
641
|
8 /* EvaluateStringLiteralAsType */ |
|
647
|
-
32 /*
|
648
|
-
|
642
|
+
32 /* DisallowParamSpec */ |
|
643
|
+
64 /* DisallowTypeVarTuple */ |
|
649
644
|
32768 /* VariableTypeAnnotation */);
|
650
645
|
break;
|
651
646
|
}
|
@@ -666,14 +661,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
666
661
|
break;
|
667
662
|
}
|
668
663
|
default:
|
669
|
-
(0, debug_1.assertNever)(node);
|
664
|
+
(0, debug_1.assertNever)(node, `Illegal node type: ${node.nodeType}`);
|
670
665
|
}
|
671
666
|
if (!typeResult) {
|
672
667
|
// We shouldn't get here. If we do, report an error.
|
673
668
|
(0, debug_1.fail)(`Unhandled expression type '${ParseTreeUtils.printExpression(node)}'`);
|
674
669
|
}
|
675
670
|
if (reportExpectingTypeErrors && !typeResult.isIncomplete) {
|
676
|
-
if (flags &
|
671
|
+
if (flags & 64 /* DisallowTypeVarTuple */) {
|
677
672
|
if ((0, types_1.isVariadicTypeVar)(typeResult.type) && !typeResult.type.isVariadicInUnion) {
|
678
673
|
addError(localize_1.Localizer.Diagnostic.typeVarTupleContext(), node);
|
679
674
|
typeResult.type = types_1.UnknownType.create();
|
@@ -695,13 +690,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
695
690
|
typeResult.type.details.illegalRecursionDetected = true;
|
696
691
|
}
|
697
692
|
}
|
698
|
-
writeTypeCache(node, typeResult
|
699
|
-
|
700
|
-
|
701
|
-
|
693
|
+
writeTypeCache(node, typeResult, flags, inferenceContext, /* allowSpeculativeCaching */ true);
|
694
|
+
if (inferenceContext &&
|
695
|
+
!(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) &&
|
696
|
+
!(0, types_1.isNever)(inferenceContext.expectedType)) {
|
697
|
+
expectedTypeCache.set(node.id, inferenceContext.expectedType);
|
702
698
|
if (!typeResult.isIncomplete && !typeResult.expectedTypeDiagAddendum) {
|
703
699
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
704
|
-
|
700
|
+
// Make sure the resulting type is assignable to the expected type.
|
701
|
+
// Use the "solve for scopes" of the associated typeVarContext if
|
702
|
+
// it is provided.
|
703
|
+
if (!assignType(inferenceContext.expectedType, typeResult.type, diag, new typeVarContext_1.TypeVarContext((_b = inferenceContext.typeVarContext) === null || _b === void 0 ? void 0 : _b.getSolveForScopes()))) {
|
704
|
+
typeResult.typeErrors = true;
|
705
705
|
typeResult.expectedTypeDiagAddendum = diag;
|
706
706
|
diag.addTextRange(node);
|
707
707
|
}
|
@@ -713,11 +713,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
713
713
|
}
|
714
714
|
return typeResult;
|
715
715
|
}
|
716
|
-
function getTypeOfAwaitOperator(node, flags,
|
717
|
-
const effectiveExpectedType =
|
718
|
-
? createAwaitableReturnType(node, expectedType, /* isGenerator */ false)
|
716
|
+
function getTypeOfAwaitOperator(node, flags, inferenceContext) {
|
717
|
+
const effectiveExpectedType = inferenceContext
|
718
|
+
? createAwaitableReturnType(node, inferenceContext.expectedType, /* isGenerator */ false)
|
719
719
|
: undefined;
|
720
|
-
const exprTypeResult = getTypeOfExpression(node.expression, flags, effectiveExpectedType);
|
720
|
+
const exprTypeResult = getTypeOfExpression(node.expression, flags, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType));
|
721
721
|
const typeResult = {
|
722
722
|
type: getTypeOfAwaitable(exprTypeResult.type, node.expression),
|
723
723
|
};
|
@@ -730,7 +730,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
730
730
|
if ((flags & 1 /* ConvertEllipsisToAny */) !== 0) {
|
731
731
|
typeResult = { type: types_1.AnyType.create(/* isEllipsis */ true) };
|
732
732
|
}
|
733
|
-
else if ((flags &
|
733
|
+
else if ((flags & 512 /* ConvertEllipsisToUnknown */) !== 0) {
|
734
734
|
typeResult = { type: types_1.UnknownType.create() };
|
735
735
|
}
|
736
736
|
else {
|
@@ -751,19 +751,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
751
751
|
}
|
752
752
|
return typeResult;
|
753
753
|
}
|
754
|
-
function getTypeOfUnpackOperator(node, flags,
|
754
|
+
function getTypeOfUnpackOperator(node, flags, inferenceContext) {
|
755
755
|
var _a;
|
756
756
|
let typeResult;
|
757
757
|
let iterExpectedType;
|
758
|
-
if (
|
758
|
+
if (inferenceContext) {
|
759
759
|
const iterableType = getBuiltInType(node, 'Iterable');
|
760
760
|
if (iterableType && (0, types_1.isInstantiableClass)(iterableType)) {
|
761
|
-
iterExpectedType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(iterableType, [expectedType],
|
761
|
+
iterExpectedType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(iterableType, [inferenceContext.expectedType],
|
762
|
+
/* isTypeArgumentExplicit */ true));
|
762
763
|
}
|
763
764
|
}
|
764
|
-
const iterTypeResult = getTypeOfExpression(node.expression, flags, iterExpectedType);
|
765
|
+
const iterTypeResult = getTypeOfExpression(node.expression, flags, (0, typeUtils_1.makeInferenceContext)(iterExpectedType));
|
765
766
|
const iterType = iterTypeResult.type;
|
766
|
-
if ((flags &
|
767
|
+
if ((flags & 64 /* DisallowTypeVarTuple */) === 0 &&
|
767
768
|
(0, types_1.isVariadicTypeVar)(iterType) &&
|
768
769
|
!iterType.isVariadicUnpacked) {
|
769
770
|
typeResult = { type: types_1.TypeVarType.cloneForUnpacked(iterType) };
|
@@ -791,7 +792,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
791
792
|
function getTypeOfStringList(node, flags, isExpectingType) {
|
792
793
|
let typeResult;
|
793
794
|
if (isExpectingType) {
|
794
|
-
let updatedFlags = flags | 4 /* AllowForwardReferences */ |
|
795
|
+
let updatedFlags = flags | 4 /* AllowForwardReferences */ | 128 /* ExpectingType */;
|
795
796
|
// In most cases, annotations within a string are not parsed by the interpreter.
|
796
797
|
// There are a few exceptions (e.g. the "bound" value for a TypeVar constructor).
|
797
798
|
if ((flags & 4194304 /* InterpreterParsesStringLiteral */) === 0) {
|
@@ -941,27 +942,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
941
942
|
return specialType;
|
942
943
|
}
|
943
944
|
}
|
944
|
-
let evaluatorFlags =
|
945
|
-
|
945
|
+
let evaluatorFlags = 128 /* ExpectingType */ |
|
946
|
+
256 /* ExpectingTypeAnnotation */ |
|
946
947
|
1 /* ConvertEllipsisToAny */ |
|
947
948
|
8 /* EvaluateStringLiteralAsType */;
|
948
949
|
if (options === null || options === void 0 ? void 0 : options.isVariableAnnotation) {
|
949
950
|
evaluatorFlags |= 32768 /* VariableTypeAnnotation */;
|
950
951
|
}
|
951
952
|
if (!(options === null || options === void 0 ? void 0 : options.allowFinal)) {
|
952
|
-
evaluatorFlags |= 16 /*
|
953
|
+
evaluatorFlags |= 16 /* DisallowFinal */;
|
953
954
|
}
|
954
955
|
if (!(options === null || options === void 0 ? void 0 : options.allowClassVar)) {
|
955
|
-
evaluatorFlags |= 131072 /*
|
956
|
+
evaluatorFlags |= 131072 /* DisallowClassVar */;
|
956
957
|
}
|
957
958
|
if (!(options === null || options === void 0 ? void 0 : options.allowTypeVarTuple)) {
|
958
|
-
evaluatorFlags |=
|
959
|
+
evaluatorFlags |= 64 /* DisallowTypeVarTuple */;
|
959
960
|
}
|
960
961
|
else {
|
961
962
|
evaluatorFlags |= 2097152 /* AllowUnpackedTupleOrTypeVarTuple */;
|
962
963
|
}
|
963
964
|
if (!(options === null || options === void 0 ? void 0 : options.allowParamSpec)) {
|
964
|
-
evaluatorFlags |= 32 /*
|
965
|
+
evaluatorFlags |= 32 /* DisallowParamSpec */;
|
965
966
|
}
|
966
967
|
if (options === null || options === void 0 ? void 0 : options.associateTypeVarsWithScope) {
|
967
968
|
evaluatorFlags |= 8192 /* AssociateTypeVarsWithCurrentScope */;
|
@@ -2087,7 +2088,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2087
2088
|
if (!isTypeIncomplete) {
|
2088
2089
|
reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, nameNode, destType, nameNode, ignoreEmptyContainers);
|
2089
2090
|
}
|
2090
|
-
writeTypeCache(nameNode, destType, 0 /* None
|
2091
|
+
writeTypeCache(nameNode, { type: destType, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
2091
2092
|
}
|
2092
2093
|
function assignTypeToMemberAccessNode(target, type, isTypeIncomplete, srcExpr, expectedTypeDiagAddendum) {
|
2093
2094
|
const baseTypeResult = getTypeOfExpression(target.leftExpression, 2 /* DoNotSpecialize */);
|
@@ -2131,8 +2132,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2131
2132
|
if (setTypeResult.isAsymmetricDescriptor) {
|
2132
2133
|
setAsymmetricDescriptorAssignment(target);
|
2133
2134
|
}
|
2134
|
-
writeTypeCache(target.memberName, type, 0 /* None
|
2135
|
-
writeTypeCache(target, type, 0 /* None
|
2135
|
+
writeTypeCache(target.memberName, { type, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
2136
|
+
writeTypeCache(target, { type, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
2136
2137
|
}
|
2137
2138
|
function assignTypeToMemberVariable(node, srcType, isTypeIncomplete, isInstanceMember, srcExprNode) {
|
2138
2139
|
const memberName = node.memberName.value;
|
@@ -2307,7 +2308,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2307
2308
|
const targetType = typeList.length === 0 ? types_1.UnknownType.create() : (0, types_1.combineTypes)(typeList);
|
2308
2309
|
assignTypeToExpression(expr, targetType, isTypeIncomplete, srcExpr, /* ignoreEmptyContainers */ true);
|
2309
2310
|
});
|
2310
|
-
writeTypeCache(target, type, 0 /* None
|
2311
|
+
writeTypeCache(target, { type, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
2311
2312
|
}
|
2312
2313
|
// Replaces all of the top-level TypeVars (as opposed to TypeVars
|
2313
2314
|
// used as type arguments in other types) with their concrete form.
|
@@ -2534,7 +2535,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2534
2535
|
setErrorNode: srcExpr,
|
2535
2536
|
setExpectedTypeDiag: expectedTypeDiagAddendum,
|
2536
2537
|
}, 0 /* None */);
|
2537
|
-
writeTypeCache(target, type, 0 /* None
|
2538
|
+
writeTypeCache(target, { type, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
2538
2539
|
break;
|
2539
2540
|
}
|
2540
2541
|
case 31 /* List */:
|
@@ -2615,7 +2616,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2615
2616
|
suppressDiagnostics(node.typeExpression, () => {
|
2616
2617
|
callResult = validateConstructorArguments(node.typeExpression, [], concreteSubtype,
|
2617
2618
|
/* skipUnknownArgCheck */ false,
|
2618
|
-
/*
|
2619
|
+
/* inferenceContext */ undefined);
|
2619
2620
|
});
|
2620
2621
|
if (callResult && callResult.argumentErrors) {
|
2621
2622
|
diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeNotInstantiable().format({
|
@@ -2657,14 +2658,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2657
2658
|
case 35 /* MemberAccess */: {
|
2658
2659
|
const baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /* DoNotSpecialize */);
|
2659
2660
|
const memberType = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* None */);
|
2660
|
-
writeTypeCache(node.memberName, memberType.type, 0 /* None
|
2661
|
-
writeTypeCache(node, memberType.type, 0 /* None
|
2661
|
+
writeTypeCache(node.memberName, { type: memberType.type }, 0 /* None */);
|
2662
|
+
writeTypeCache(node, { type: memberType.type }, 0 /* None */);
|
2662
2663
|
break;
|
2663
2664
|
}
|
2664
2665
|
case 24 /* Index */: {
|
2665
2666
|
const baseTypeResult = getTypeOfExpression(node.baseExpression, 2 /* DoNotSpecialize */);
|
2666
2667
|
getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* None */);
|
2667
|
-
writeTypeCache(node, types_1.UnboundType.create(), 0 /* None
|
2668
|
+
writeTypeCache(node, { type: types_1.UnboundType.create() }, 0 /* None */);
|
2668
2669
|
break;
|
2669
2670
|
}
|
2670
2671
|
case 52 /* Tuple */: {
|
@@ -2766,14 +2767,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2766
2767
|
else {
|
2767
2768
|
// Look for the scope that contains the value definition and
|
2768
2769
|
// see if it has a declared type.
|
2769
|
-
let symbolWithScope = lookUpSymbolRecursive(node, name, !allowForwardReferences, allowForwardReferences && (flags &
|
2770
|
+
let symbolWithScope = lookUpSymbolRecursive(node, name, !allowForwardReferences, allowForwardReferences && (flags & 256 /* ExpectingTypeAnnotation */) !== 0);
|
2770
2771
|
if (!symbolWithScope) {
|
2771
2772
|
// If the node is part of a "from X import Y as Z" statement and the node
|
2772
2773
|
// is the "Y" (non-aliased) name, we need to look up the alias symbol
|
2773
2774
|
// since the non-aliased name is not in the symbol table.
|
2774
2775
|
const alias = getAliasFromImport(node);
|
2775
2776
|
if (alias) {
|
2776
|
-
symbolWithScope = lookUpSymbolRecursive(alias, alias.value, !allowForwardReferences, allowForwardReferences && (flags &
|
2777
|
+
symbolWithScope = lookUpSymbolRecursive(alias, alias.value, !allowForwardReferences, allowForwardReferences && (flags & 256 /* ExpectingTypeAnnotation */) !== 0);
|
2777
2778
|
}
|
2778
2779
|
}
|
2779
2780
|
if (symbolWithScope) {
|
@@ -2832,7 +2833,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2832
2833
|
}
|
2833
2834
|
const codeFlowTypeResult = getFlowTypeOfReference(node, symbol.id, typeAtStart,
|
2834
2835
|
/* startNode */ undefined, {
|
2835
|
-
skipConditionalNarrowing: (flags &
|
2836
|
+
skipConditionalNarrowing: (flags & 256 /* ExpectingTypeAnnotation */) !== 0,
|
2836
2837
|
});
|
2837
2838
|
if (codeFlowTypeResult.type) {
|
2838
2839
|
type = codeFlowTypeResult.type;
|
@@ -2852,7 +2853,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2852
2853
|
}
|
2853
2854
|
// Detect, report, and fill in missing type arguments if appropriate.
|
2854
2855
|
type = reportMissingTypeArguments(node, type, flags);
|
2855
|
-
if ((flags &
|
2856
|
+
if ((flags & 256 /* ExpectingTypeAnnotation */) !== 0) {
|
2856
2857
|
// Verify that the name does not refer to a (non type alias) variable.
|
2857
2858
|
if (effectiveTypeInfo.includesVariableDecl && !type.typeAliasInfo) {
|
2858
2859
|
let isAllowedTypeForVariable = (0, types_1.isTypeVar)(type) || (0, typeUtils_1.isTypeAliasPlaceholder)(type);
|
@@ -2889,7 +2890,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2889
2890
|
}
|
2890
2891
|
}
|
2891
2892
|
if ((0, types_1.isParamSpec)(type)) {
|
2892
|
-
if (flags & 32 /*
|
2893
|
+
if (flags & 32 /* DisallowParamSpec */) {
|
2893
2894
|
addError(localize_1.Localizer.Diagnostic.paramSpecContext(), node);
|
2894
2895
|
type = types_1.UnknownType.create();
|
2895
2896
|
}
|
@@ -2897,7 +2898,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2897
2898
|
if ((0, types_1.isTypeVar)(type) &&
|
2898
2899
|
!type.details.isParamSpec &&
|
2899
2900
|
!type.isVariadicInUnion &&
|
2900
|
-
(flags &
|
2901
|
+
(flags & 128 /* ExpectingType */) === 0 &&
|
2901
2902
|
type.details.name === name) {
|
2902
2903
|
// Handle the special case of a PEP 604 union. These can appear within
|
2903
2904
|
// an implied type alias where we are not expecting a type.
|
@@ -2917,8 +2918,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2917
2918
|
}
|
2918
2919
|
}
|
2919
2920
|
}
|
2920
|
-
if ((flags &
|
2921
|
-
if ((flags &
|
2921
|
+
if ((flags & 128 /* ExpectingType */) !== 0) {
|
2922
|
+
if ((flags & 1024 /* AllowGenericClassType */) === 0) {
|
2922
2923
|
if ((0, types_1.isInstantiableClass)(type) && types_1.ClassType.isBuiltIn(type, 'Generic')) {
|
2923
2924
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.genericNotAllowed(), node);
|
2924
2925
|
}
|
@@ -3037,7 +3038,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3037
3038
|
if (enclosingScope) {
|
3038
3039
|
// If the enclosing scope is using type parameter syntax, traditional
|
3039
3040
|
// type variables can't be used in this context.
|
3040
|
-
if (enclosingScope.typeParameters
|
3041
|
+
if (enclosingScope.typeParameters &&
|
3042
|
+
!enclosingScope.typeParameters.parameters.some((param) => param.name.value === type.details.name)) {
|
3041
3043
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeParameterNotDeclared().format({
|
3042
3044
|
name: type.details.name,
|
3043
3045
|
container: enclosingScope.name.value,
|
@@ -3090,7 +3092,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3090
3092
|
}
|
3091
3093
|
// Is this a generic class that needs to be specialized?
|
3092
3094
|
if ((0, types_1.isInstantiableClass)(type)) {
|
3093
|
-
if ((flags &
|
3095
|
+
if ((flags & 128 /* ExpectingType */) !== 0) {
|
3094
3096
|
if ((0, typeUtils_1.requiresTypeArguments)(type) && !type.typeArguments) {
|
3095
3097
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportMissingTypeArgument, diagnosticRules_1.DiagnosticRule.reportMissingTypeArgument, localize_1.Localizer.Diagnostic.typeArgsMissingForClass().format({
|
3096
3098
|
name: type.aliasName || type.details.name,
|
@@ -3102,7 +3104,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3102
3104
|
}
|
3103
3105
|
}
|
3104
3106
|
// Is this a generic type alias that needs to be specialized?
|
3105
|
-
if ((flags &
|
3107
|
+
if ((flags & 128 /* ExpectingType */) !== 0 &&
|
3106
3108
|
type.typeAliasInfo &&
|
3107
3109
|
type.typeAliasInfo.typeParameters &&
|
3108
3110
|
type.typeAliasInfo.typeParameters.length > 0 &&
|
@@ -3256,7 +3258,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3256
3258
|
function getTypeOfMemberAccess(node, flags) {
|
3257
3259
|
const baseTypeFlags = 2 /* DoNotSpecialize */ |
|
3258
3260
|
(flags &
|
3259
|
-
(
|
3261
|
+
(256 /* ExpectingTypeAnnotation */ |
|
3260
3262
|
32768 /* VariableTypeAnnotation */ |
|
3261
3263
|
4 /* AllowForwardReferences */ |
|
3262
3264
|
524288 /* NotParsedByInterpreter */ |
|
@@ -3273,8 +3275,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3273
3275
|
const typeResult = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'get' }, flags | 2 /* DoNotSpecialize */);
|
3274
3276
|
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(node)) {
|
3275
3277
|
// Before performing code flow analysis, update the cache to prevent recursion.
|
3276
|
-
writeTypeCache(node, typeResult
|
3277
|
-
writeTypeCache(node.memberName, typeResult
|
3278
|
+
writeTypeCache(node, { ...typeResult, isIncomplete: true }, flags);
|
3279
|
+
writeTypeCache(node.memberName, { ...typeResult, isIncomplete: true }, flags);
|
3278
3280
|
// If the type is initially unbound, see if there's a parent class that
|
3279
3281
|
// potentially initialized the value.
|
3280
3282
|
let typeAtStart = typeResult.type;
|
@@ -3297,7 +3299,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3297
3299
|
const codeFlowTypeResult = getFlowTypeOfReference(node, symbol_1.indeterminateSymbolId, typeAtStart,
|
3298
3300
|
/* startNode */ undefined, {
|
3299
3301
|
isTypeAtStartIncomplete,
|
3300
|
-
skipConditionalNarrowing: (flags &
|
3302
|
+
skipConditionalNarrowing: (flags & 256 /* ExpectingTypeAnnotation */) !== 0,
|
3301
3303
|
});
|
3302
3304
|
if (codeFlowTypeResult.type) {
|
3303
3305
|
typeResult.type = codeFlowTypeResult.type;
|
@@ -3307,14 +3309,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3307
3309
|
}
|
3308
3310
|
// Detect, report, and fill in missing type arguments if appropriate.
|
3309
3311
|
typeResult.type = reportMissingTypeArguments(node, typeResult.type, flags);
|
3310
|
-
deleteTypeCacheEntry(node);
|
3311
|
-
deleteTypeCacheEntry(node.memberName);
|
3312
3312
|
}
|
3313
3313
|
if (baseTypeResult.isIncomplete) {
|
3314
3314
|
typeResult.isIncomplete = true;
|
3315
3315
|
}
|
3316
3316
|
// Cache the type information in the member name node.
|
3317
|
-
writeTypeCache(node.memberName, typeResult
|
3317
|
+
writeTypeCache(node.memberName, typeResult, flags);
|
3318
3318
|
return typeResult;
|
3319
3319
|
}
|
3320
3320
|
function getTypeOfMemberAccessWithBaseType(node, baseTypeResult, usage, flags) {
|
@@ -3382,7 +3382,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3382
3382
|
}
|
3383
3383
|
return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
|
3384
3384
|
}
|
3385
|
-
if (flags &
|
3385
|
+
if (flags & 128 /* ExpectingType */) {
|
3386
3386
|
if (!isIncomplete) {
|
3387
3387
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarNoMember().format({
|
3388
3388
|
type: printType(baseType),
|
@@ -3687,7 +3687,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3687
3687
|
}
|
3688
3688
|
}
|
3689
3689
|
// Don't include variables within typed dict classes.
|
3690
|
-
if (types_1.ClassType.isTypedDictClass(classType)) {
|
3690
|
+
if ((0, types_1.isClass)(memberInfo.classType) && types_1.ClassType.isTypedDictClass(memberInfo.classType)) {
|
3691
3691
|
const typedDecls = memberInfo.symbol.getTypedDeclarations();
|
3692
3692
|
if (typedDecls.length > 0 && typedDecls[0].type === 1 /* Variable */) {
|
3693
3693
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.memberUnknown().format({ name: memberName }));
|
@@ -4142,7 +4142,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4142
4142
|
// If this is meant to be a type and the base expression is a string expression,
|
4143
4143
|
// emit an error because this will generate a runtime exception in Python versions
|
4144
4144
|
// less than 3.10.
|
4145
|
-
if (flags &
|
4145
|
+
if (flags & 128 /* ExpectingType */) {
|
4146
4146
|
if (node.baseExpression.nodeType === 48 /* StringList */) {
|
4147
4147
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
4148
4148
|
if (!fileInfo.isStubFile && fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_10) {
|
@@ -4193,12 +4193,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4193
4193
|
});
|
4194
4194
|
if (baseTypeSupportsIndexNarrowing) {
|
4195
4195
|
// Before performing code flow analysis, update the cache to prevent recursion.
|
4196
|
-
writeTypeCache(node, indexTypeResult
|
4196
|
+
writeTypeCache(node, indexTypeResult, flags);
|
4197
4197
|
// See if we can refine the type based on code flow analysis.
|
4198
4198
|
const codeFlowTypeResult = getFlowTypeOfReference(node, symbol_1.indeterminateSymbolId, indexTypeResult.type,
|
4199
4199
|
/* startNode */ undefined, {
|
4200
4200
|
isTypeAtStartIncomplete: !!baseTypeResult.isIncomplete || !!indexTypeResult.isIncomplete,
|
4201
|
-
skipConditionalNarrowing: (flags &
|
4201
|
+
skipConditionalNarrowing: (flags & 256 /* ExpectingTypeAnnotation */) !== 0,
|
4202
4202
|
});
|
4203
4203
|
if (codeFlowTypeResult.type) {
|
4204
4204
|
indexTypeResult.type = codeFlowTypeResult.type;
|
@@ -4206,14 +4206,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4206
4206
|
if (codeFlowTypeResult.isIncomplete) {
|
4207
4207
|
indexTypeResult.isIncomplete = true;
|
4208
4208
|
}
|
4209
|
-
deleteTypeCacheEntry(node);
|
4210
4209
|
}
|
4211
4210
|
}
|
4212
4211
|
if (baseTypeResult.isIncomplete) {
|
4213
4212
|
indexTypeResult.isIncomplete = true;
|
4214
4213
|
}
|
4215
4214
|
// Handle "Required" and "NotRequired" specially.
|
4216
|
-
if ((flags & 1048576 /*
|
4215
|
+
if ((flags & 1048576 /* AllowRequired */) !== 0) {
|
4217
4216
|
if ((0, types_1.isInstantiableClass)(baseTypeResult.type)) {
|
4218
4217
|
if (types_1.ClassType.isBuiltIn(baseTypeResult.type, 'Required')) {
|
4219
4218
|
indexTypeResult.isRequired = true;
|
@@ -4455,7 +4454,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4455
4454
|
if ((0, types_1.isAnyOrUnknown)(concreteSubtype)) {
|
4456
4455
|
return concreteSubtype;
|
4457
4456
|
}
|
4458
|
-
if (flags &
|
4457
|
+
if (flags & 128 /* ExpectingType */) {
|
4459
4458
|
if ((0, types_1.isTypeVar)(unexpandedSubtype)) {
|
4460
4459
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarNotSubscriptable().format({
|
4461
4460
|
type: printType(unexpandedSubtype),
|
@@ -4791,16 +4790,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4791
4790
|
const typeArgs = [];
|
4792
4791
|
let adjFlags = flags;
|
4793
4792
|
if (isFinalAnnotation || isClassVarAnnotation) {
|
4794
|
-
adjFlags |= 131072 /*
|
4793
|
+
adjFlags |= 131072 /* DisallowClassVar */ | 16 /* DisallowFinal */;
|
4795
4794
|
}
|
4796
4795
|
else {
|
4797
4796
|
adjFlags &= ~(2 /* DoNotSpecialize */ |
|
4798
|
-
32 /*
|
4799
|
-
|
4800
|
-
1048576 /*
|
4797
|
+
32 /* DisallowParamSpec */ |
|
4798
|
+
64 /* DisallowTypeVarTuple */ |
|
4799
|
+
1048576 /* AllowRequired */ |
|
4801
4800
|
16384 /* EnforceTypeVarVarianceConsistency */);
|
4802
4801
|
if (!isAnnotatedClass) {
|
4803
|
-
adjFlags |= 131072 /*
|
4802
|
+
adjFlags |= 131072 /* DisallowClassVar */ | 16 /* DisallowFinal */;
|
4804
4803
|
}
|
4805
4804
|
adjFlags |= 2097152 /* AllowUnpackedTupleOrTypeVarTuple */;
|
4806
4805
|
}
|
@@ -4812,10 +4811,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4812
4811
|
// should be treated as a type. The others can be regular (non-type) objects.
|
4813
4812
|
if (hasCustomClassGetItem || (isAnnotatedClass && argIndex > 0)) {
|
4814
4813
|
typeResult = {
|
4815
|
-
...getTypeOfExpression(expr, 32 /*
|
4816
|
-
|
4814
|
+
...getTypeOfExpression(expr, 32 /* DisallowParamSpec */ |
|
4815
|
+
64 /* DisallowTypeVarTuple */ |
|
4817
4816
|
2 /* DoNotSpecialize */ |
|
4818
|
-
131072 /*
|
4817
|
+
131072 /* DisallowClassVar */),
|
4819
4818
|
node: expr,
|
4820
4819
|
};
|
4821
4820
|
}
|
@@ -4862,7 +4861,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4862
4861
|
function getTypeArg(node, flags) {
|
4863
4862
|
let typeResult;
|
4864
4863
|
let adjustedFlags = flags |
|
4865
|
-
|
4864
|
+
128 /* ExpectingType */ |
|
4866
4865
|
1 /* ConvertEllipsisToAny */ |
|
4867
4866
|
8 /* EvaluateStringLiteralAsType */;
|
4868
4867
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -4886,7 +4885,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4886
4885
|
if ((0, types_1.isClass)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'Protocol')) {
|
4887
4886
|
addError(localize_1.Localizer.Diagnostic.protocolNotAllowedInTypeArgument(), node);
|
4888
4887
|
}
|
4889
|
-
if ((flags & 131072 /*
|
4888
|
+
if ((flags & 131072 /* DisallowClassVar */) !== 0) {
|
4890
4889
|
// "ClassVar" is not allowed as a type argument.
|
4891
4890
|
if ((0, types_1.isClass)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'ClassVar')) {
|
4892
4891
|
addError(localize_1.Localizer.Diagnostic.classVarNotAllowed(), node);
|
@@ -4895,23 +4894,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4895
4894
|
}
|
4896
4895
|
return typeResult;
|
4897
4896
|
}
|
4898
|
-
function getTypeOfTuple(node,
|
4899
|
-
if ((flags &
|
4897
|
+
function getTypeOfTuple(node, inferenceContext, flags) {
|
4898
|
+
if ((flags & 128 /* ExpectingType */) !== 0 && node.expressions.length === 0 && !inferenceContext) {
|
4900
4899
|
return { type: makeTupleObject([]), isEmptyTupleShorthand: true };
|
4901
4900
|
}
|
4902
4901
|
// If the expected type is a union, recursively call for each of the subtypes
|
4903
4902
|
// to find one that matches.
|
4904
|
-
let effectiveExpectedType = expectedType;
|
4905
|
-
let expectedTypeContainsAny =
|
4906
|
-
if (
|
4903
|
+
let effectiveExpectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
|
4904
|
+
let expectedTypeContainsAny = inferenceContext && (0, types_1.isAny)(inferenceContext.expectedType);
|
4905
|
+
if (inferenceContext && (0, types_1.isUnion)(inferenceContext.expectedType)) {
|
4907
4906
|
let matchingSubtype;
|
4908
|
-
(0, typeUtils_1.doForEachSubtype)(expectedType, (subtype) => {
|
4907
|
+
(0, typeUtils_1.doForEachSubtype)(inferenceContext.expectedType, (subtype) => {
|
4909
4908
|
if ((0, types_1.isAny)(subtype)) {
|
4910
4909
|
expectedTypeContainsAny = true;
|
4911
4910
|
}
|
4912
4911
|
if (!matchingSubtype) {
|
4913
4912
|
const subtypeResult = useSpeculativeMode(node, () => {
|
4914
|
-
return
|
4913
|
+
return getTypeOfTupleWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext));
|
4915
4914
|
});
|
4916
4915
|
if (subtypeResult && assignType(subtype, subtypeResult.type)) {
|
4917
4916
|
matchingSubtype = subtype;
|
@@ -4922,7 +4921,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4922
4921
|
}
|
4923
4922
|
let expectedTypeDiagAddendum;
|
4924
4923
|
if (effectiveExpectedType) {
|
4925
|
-
const result =
|
4924
|
+
const result = getTypeOfTupleWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext));
|
4926
4925
|
if (result && !result.typeErrors) {
|
4927
4926
|
return result;
|
4928
4927
|
}
|
@@ -4936,9 +4935,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4936
4935
|
}
|
4937
4936
|
return { ...typeResult, expectedTypeDiagAddendum };
|
4938
4937
|
}
|
4939
|
-
function
|
4940
|
-
expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expectedType);
|
4941
|
-
if (!(0, types_1.isClassInstance)(expectedType)) {
|
4938
|
+
function getTypeOfTupleWithContext(node, inferenceContext) {
|
4939
|
+
inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
|
4940
|
+
if (!(0, types_1.isClassInstance)(inferenceContext.expectedType)) {
|
4942
4941
|
return undefined;
|
4943
4942
|
}
|
4944
4943
|
if (!tupleClassType || !(0, types_1.isInstantiableClass)(tupleClassType)) {
|
@@ -4946,9 +4945,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4946
4945
|
}
|
4947
4946
|
// Build an array of expected types.
|
4948
4947
|
let expectedTypes = [];
|
4949
|
-
if ((0, typeUtils_1.isTupleClass)(expectedType) && expectedType.tupleTypeArguments) {
|
4950
|
-
expectedTypes = expectedType.tupleTypeArguments.map((t) => (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(t.type));
|
4951
|
-
const unboundedIndex = expectedType.tupleTypeArguments.findIndex((t) => t.isUnbounded);
|
4948
|
+
if ((0, typeUtils_1.isTupleClass)(inferenceContext.expectedType) && inferenceContext.expectedType.tupleTypeArguments) {
|
4949
|
+
expectedTypes = inferenceContext.expectedType.tupleTypeArguments.map((t) => (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(t.type));
|
4950
|
+
const unboundedIndex = inferenceContext.expectedType.tupleTypeArguments.findIndex((t) => t.isUnbounded);
|
4952
4951
|
if (unboundedIndex >= 0) {
|
4953
4952
|
if (expectedTypes.length > node.expressions.length) {
|
4954
4953
|
expectedTypes.splice(unboundedIndex, 1);
|
@@ -4962,7 +4961,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4962
4961
|
}
|
4963
4962
|
else {
|
4964
4963
|
const tupleTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(tupleClassType));
|
4965
|
-
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(tupleClassType), expectedType, tupleTypeVarContext, getTypeVarScopesForNode(node))) {
|
4964
|
+
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(tupleClassType), inferenceContext.expectedType, tupleTypeVarContext, getTypeVarScopesForNode(node))) {
|
4966
4965
|
return undefined;
|
4967
4966
|
}
|
4968
4967
|
const specializedTuple = (0, typeUtils_1.applySolvedTypeVars)(tupleClassType, tupleTypeVarContext);
|
@@ -4975,7 +4974,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4975
4974
|
}
|
4976
4975
|
}
|
4977
4976
|
const entryTypeResults = node.expressions.map((expr, index) => getTypeOfExpression(expr,
|
4978
|
-
/* flags */ undefined, index < expectedTypes.length ? expectedTypes[index] : undefined));
|
4977
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(index < expectedTypes.length ? expectedTypes[index] : undefined)));
|
4979
4978
|
const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
|
4980
4979
|
const type = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, buildTupleTypesList(entryTypeResults),
|
4981
4980
|
/* isTypeArgumentExplicit */ true));
|
@@ -5042,7 +5041,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5042
5041
|
}
|
5043
5042
|
return entryTypes;
|
5044
5043
|
}
|
5045
|
-
function getTypeOfCall(node,
|
5044
|
+
function getTypeOfCall(node, inferenceContext, flags) {
|
5046
5045
|
var _a;
|
5047
5046
|
const baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /* DoNotSpecialize */);
|
5048
5047
|
const argList = node.arguments.map((arg) => {
|
@@ -5064,15 +5063,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5064
5063
|
node.leftExpression.nodeType === 38 /* Name */ &&
|
5065
5064
|
node.leftExpression.value === 'reveal_type') {
|
5066
5065
|
// Handle the implicit "reveal_type" call.
|
5067
|
-
typeResult = getTypeOfRevealType(node,
|
5066
|
+
typeResult = getTypeOfRevealType(node, inferenceContext);
|
5068
5067
|
}
|
5069
5068
|
else if ((0, types_1.isFunction)(baseTypeResult.type) && baseTypeResult.type.details.builtInName === 'reveal_type') {
|
5070
5069
|
// Handle the "typing.reveal_type" call.
|
5071
|
-
typeResult = getTypeOfRevealType(node,
|
5070
|
+
typeResult = getTypeOfRevealType(node, inferenceContext);
|
5072
5071
|
}
|
5073
5072
|
else if ((0, types_1.isFunction)(baseTypeResult.type) && baseTypeResult.type.details.builtInName === 'assert_type') {
|
5074
5073
|
// Handle the "typing.assert_type" call.
|
5075
|
-
typeResult = getTypeOfAssertType(node,
|
5074
|
+
typeResult = getTypeOfAssertType(node, inferenceContext);
|
5076
5075
|
}
|
5077
5076
|
else if ((0, types_1.isAnyOrUnknown)(baseTypeResult.type) &&
|
5078
5077
|
node.leftExpression.nodeType === 38 /* Name */ &&
|
@@ -5088,11 +5087,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5088
5087
|
else {
|
5089
5088
|
const callResult = validateCallArguments(node, argList, baseTypeResult,
|
5090
5089
|
/* typeVarContext */ undefined,
|
5091
|
-
/* skipUnknownArgCheck */ false,
|
5090
|
+
/* skipUnknownArgCheck */ false, inferenceContext);
|
5092
5091
|
typeResult.type = (_a = callResult.returnType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
5093
5092
|
if (callResult.argumentErrors) {
|
5094
5093
|
typeResult.typeErrors = true;
|
5095
5094
|
}
|
5095
|
+
else {
|
5096
|
+
typeResult.overloadsUsedForCall = callResult.overloadsUsedForCall;
|
5097
|
+
}
|
5096
5098
|
if (callResult.isTypeIncomplete) {
|
5097
5099
|
typeResult.isIncomplete = true;
|
5098
5100
|
}
|
@@ -5126,13 +5128,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5126
5128
|
});
|
5127
5129
|
}
|
5128
5130
|
}
|
5129
|
-
if ((flags &
|
5131
|
+
if ((flags & 256 /* ExpectingTypeAnnotation */) !== 0) {
|
5130
5132
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAnnotationCall(), node);
|
5131
5133
|
typeResult = { type: types_1.UnknownType.create() };
|
5132
5134
|
}
|
5133
5135
|
return typeResult;
|
5134
5136
|
}
|
5135
|
-
function getTypeOfAssertType(node,
|
5137
|
+
function getTypeOfAssertType(node, inferenceContext) {
|
5136
5138
|
if (node.arguments.length !== 2 ||
|
5137
5139
|
node.arguments[0].argumentCategory !== 0 /* Simple */ ||
|
5138
5140
|
node.arguments[0].name !== undefined ||
|
@@ -5142,7 +5144,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5142
5144
|
return { type: types_1.UnknownType.create() };
|
5143
5145
|
}
|
5144
5146
|
const arg0TypeResult = getTypeOfExpression(node.arguments[0].valueExpression,
|
5145
|
-
/* flags */ undefined,
|
5147
|
+
/* flags */ undefined, inferenceContext);
|
5146
5148
|
if (arg0TypeResult.isIncomplete) {
|
5147
5149
|
return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
|
5148
5150
|
}
|
@@ -5155,7 +5157,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5155
5157
|
}
|
5156
5158
|
return { type: arg0TypeResult.type };
|
5157
5159
|
}
|
5158
|
-
function getTypeOfRevealType(node,
|
5160
|
+
function getTypeOfRevealType(node, inferenceContext) {
|
5159
5161
|
let arg0Value;
|
5160
5162
|
let expectedRevealTypeNode;
|
5161
5163
|
let expectedRevealType;
|
@@ -5192,7 +5194,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5192
5194
|
addError(localize_1.Localizer.Diagnostic.revealTypeArgs(), node);
|
5193
5195
|
return { type: types_1.UnknownType.create() };
|
5194
5196
|
}
|
5195
|
-
const typeResult = getTypeOfExpression(arg0Value, /* flags */ undefined,
|
5197
|
+
const typeResult = getTypeOfExpression(arg0Value, /* flags */ undefined, inferenceContext);
|
5196
5198
|
const type = typeResult.type;
|
5197
5199
|
const exprString = ParseTreeUtils.printExpression(arg0Value);
|
5198
5200
|
const typeString = printType(type, { expandTypeAlias: true });
|
@@ -5396,11 +5398,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5396
5398
|
// there will be only one argument list in expandedArgTypes, and all entries
|
5397
5399
|
// (one for each argument) will be undefined. On subsequent calls, this
|
5398
5400
|
// list will grow to include union expansions.
|
5399
|
-
function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck,
|
5401
|
+
function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, inferenceContext) {
|
5400
5402
|
var _a;
|
5401
5403
|
const returnTypes = [];
|
5402
5404
|
const matchedOverloads = [];
|
5403
5405
|
let isTypeIncomplete = false;
|
5406
|
+
const overloadsUsedForCall = [];
|
5404
5407
|
for (let expandedTypesIndex = 0; expandedTypesIndex < expandedArgTypes.length; expandedTypesIndex++) {
|
5405
5408
|
let matchedOverload;
|
5406
5409
|
const argTypeOverride = expandedArgTypes[expandedTypesIndex];
|
@@ -5434,12 +5437,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5434
5437
|
// record any final types in the type cache.
|
5435
5438
|
const callResult = useSpeculativeMode(errorNode, () => {
|
5436
5439
|
return validateFunctionArgumentTypesWithExpectedType(errorNode, matchResults, effectiveTypeVarContext,
|
5437
|
-
/* skipUnknownArgCheck */ true,
|
5440
|
+
/* skipUnknownArgCheck */ true, inferenceContext);
|
5438
5441
|
});
|
5439
5442
|
if (callResult.isTypeIncomplete) {
|
5440
5443
|
isTypeIncomplete = true;
|
5441
5444
|
}
|
5442
5445
|
if (!callResult.argumentErrors && callResult.returnType) {
|
5446
|
+
overloadsUsedForCall.push(overload);
|
5443
5447
|
matchedOverload = overload;
|
5444
5448
|
matchedOverloads.push({
|
5445
5449
|
overload: matchedOverload,
|
@@ -5485,7 +5489,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5485
5489
|
returnTypes.push(dedupedMatchResults.length > 1 ? types_1.UnknownType.createPossibleType(combinedTypes) : combinedTypes);
|
5486
5490
|
}
|
5487
5491
|
if (!matchedOverload) {
|
5488
|
-
return { argumentErrors: true, isTypeIncomplete };
|
5492
|
+
return { argumentErrors: true, isTypeIncomplete, overloadsUsedForCall };
|
5489
5493
|
}
|
5490
5494
|
}
|
5491
5495
|
// We found a match for all of the expanded argument lists. Copy the
|
@@ -5500,16 +5504,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5500
5504
|
const finalTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : matchedOverloads[0].typeVarContext;
|
5501
5505
|
finalTypeVarContext.unlock();
|
5502
5506
|
finalTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(matchedOverloads[0].overload));
|
5503
|
-
const finalCallResult = validateFunctionArgumentTypesWithExpectedType(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck,
|
5507
|
+
const finalCallResult = validateFunctionArgumentTypesWithExpectedType(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck, inferenceContext);
|
5504
5508
|
if (finalCallResult.isTypeIncomplete) {
|
5505
5509
|
isTypeIncomplete = true;
|
5506
5510
|
}
|
5507
5511
|
return {
|
5508
|
-
argumentErrors:
|
5512
|
+
argumentErrors: finalCallResult.argumentErrors,
|
5509
5513
|
isArgumentAnyOrUnknown: finalCallResult.isArgumentAnyOrUnknown,
|
5510
5514
|
returnType: (0, types_1.combineTypes)(returnTypes),
|
5511
5515
|
isTypeIncomplete,
|
5512
5516
|
specializedInitSelfType: finalCallResult.specializedInitSelfType,
|
5517
|
+
overloadsUsedForCall,
|
5513
5518
|
};
|
5514
5519
|
}
|
5515
5520
|
function getBestOverloadForArguments(errorNode, type, argList) {
|
@@ -5549,7 +5554,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5549
5554
|
return a.overloadIndex - b.overloadIndex;
|
5550
5555
|
});
|
5551
5556
|
}
|
5552
|
-
function validateOverloadedFunctionArguments(errorNode, argList, type, typeVarContext, skipUnknownArgCheck,
|
5557
|
+
function validateOverloadedFunctionArguments(errorNode, argList, type, typeVarContext, skipUnknownArgCheck, inferenceContext) {
|
5553
5558
|
let filteredMatchResults = [];
|
5554
5559
|
let contextFreeArgTypes;
|
5555
5560
|
// Start by evaluating the types of the arguments without any expected
|
@@ -5583,7 +5588,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5583
5588
|
diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.argumentTypes().format({ types: argTypes.join(', ') }));
|
5584
5589
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.noOverload().format({ name: functionName }) + diagAddendum.getString(), errorNode);
|
5585
5590
|
}
|
5586
|
-
return { argumentErrors: true, isTypeIncomplete: false };
|
5591
|
+
return { argumentErrors: true, isTypeIncomplete: false, overloadsUsedForCall: [] };
|
5587
5592
|
}
|
5588
5593
|
// Create a helper lambda that evaluates the overload that matches
|
5589
5594
|
// the arg/param lists.
|
@@ -5596,7 +5601,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5596
5601
|
const effectiveTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : new typeVarContext_1.TypeVarContext();
|
5597
5602
|
effectiveTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(lastMatch.overload));
|
5598
5603
|
effectiveTypeVarContext.unlock();
|
5599
|
-
return validateFunctionArgumentTypesWithExpectedType(errorNode, lastMatch, effectiveTypeVarContext, skipUnknownArgCheck,
|
5604
|
+
return validateFunctionArgumentTypesWithExpectedType(errorNode, lastMatch, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
|
5600
5605
|
};
|
5601
5606
|
// If there is only one possible arg/param match among the overloads,
|
5602
5607
|
// use the normal type matching mechanism because it is faster and
|
@@ -5607,7 +5612,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5607
5612
|
let expandedArgTypes = [argList.map((arg) => undefined)];
|
5608
5613
|
let isTypeIncomplete = false;
|
5609
5614
|
while (true) {
|
5610
|
-
const callResult = validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, filteredMatchResults, typeVarContext, skipUnknownArgCheck,
|
5615
|
+
const callResult = validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, filteredMatchResults, typeVarContext, skipUnknownArgCheck, inferenceContext);
|
5611
5616
|
if (callResult.isTypeIncomplete) {
|
5612
5617
|
isTypeIncomplete = true;
|
5613
5618
|
}
|
@@ -5619,7 +5624,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5619
5624
|
if (!contextFreeArgTypes) {
|
5620
5625
|
useSpeculativeMode(errorNode, () => {
|
5621
5626
|
// Evaluate the types of each argument expression without regard to
|
5622
|
-
// the
|
5627
|
+
// the context. We'll use this to determine whether we need to do
|
5623
5628
|
// union expansion.
|
5624
5629
|
contextFreeArgTypes = argList.map((arg) => {
|
5625
5630
|
if (arg.typeResult) {
|
@@ -5649,9 +5654,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5649
5654
|
// Replace the result with an unknown type since we don't know
|
5650
5655
|
// what overload should have been used.
|
5651
5656
|
result.returnType = types_1.UnknownType.create();
|
5652
|
-
return result;
|
5657
|
+
return { ...result, argumentErrors: true };
|
5653
5658
|
}
|
5654
|
-
return { argumentErrors: true, isTypeIncomplete: false };
|
5659
|
+
return { argumentErrors: true, isTypeIncomplete: false, overloadsUsedForCall: [] };
|
5655
5660
|
}
|
5656
5661
|
// Replaces each item in the expandedArgTypes with n items where n is
|
5657
5662
|
// the number of subtypes in a union. The contextFreeArgTypes parameter
|
@@ -5703,13 +5708,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5703
5708
|
// If successful, it returns the resulting (specialized) object type that
|
5704
5709
|
// is allocated by the constructor. If unsuccessful, it records diagnostic
|
5705
5710
|
// information and returns undefined.
|
5706
|
-
function validateConstructorArguments(errorNode, argList, type, skipUnknownArgCheck,
|
5711
|
+
function validateConstructorArguments(errorNode, argList, type, skipUnknownArgCheck, inferenceContext) {
|
5707
5712
|
var _a;
|
5708
5713
|
let validatedTypes = false;
|
5709
5714
|
let returnType;
|
5710
5715
|
let reportedErrors = false;
|
5711
5716
|
let isTypeIncomplete = false;
|
5712
5717
|
let usedMetaclassCallMethod = false;
|
5718
|
+
const overloadsUsedForCall = [];
|
5713
5719
|
// Create a helper function that determines whether we should skip argument
|
5714
5720
|
// validation for either __init__ or __new__. This is required for certain
|
5715
5721
|
// synthesized constructor types, namely NamedTuples.
|
@@ -5727,13 +5733,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5727
5733
|
// If there is an expected type, analyze the constructor call
|
5728
5734
|
// for each of the subtypes that comprise the expected type. If
|
5729
5735
|
// one or more analyzes with no errors, use those results.
|
5730
|
-
if (
|
5731
|
-
const expectedCallResult = validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck,
|
5736
|
+
if (inferenceContext) {
|
5737
|
+
const expectedCallResult = validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, initMethodType);
|
5732
5738
|
if (expectedCallResult) {
|
5733
5739
|
returnType = expectedCallResult.returnType;
|
5734
5740
|
if (expectedCallResult.isTypeIncomplete) {
|
5735
5741
|
isTypeIncomplete = true;
|
5736
5742
|
}
|
5743
|
+
overloadsUsedForCall.push(...expectedCallResult.overloadsUsedForCall);
|
5737
5744
|
}
|
5738
5745
|
}
|
5739
5746
|
if (!returnType) {
|
@@ -5750,10 +5757,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5750
5757
|
adjustedClassType = types_1.ClassType.cloneAsInstantiable(callResult.specializedInitSelfType);
|
5751
5758
|
}
|
5752
5759
|
returnType = applyExpectedTypeForConstructor(adjustedClassType,
|
5753
|
-
/*
|
5760
|
+
/* inferenceContext */ undefined, typeVarContext);
|
5754
5761
|
if (callResult.isTypeIncomplete) {
|
5755
5762
|
isTypeIncomplete = true;
|
5756
5763
|
}
|
5764
|
+
overloadsUsedForCall.push(...callResult.overloadsUsedForCall);
|
5757
5765
|
}
|
5758
5766
|
else {
|
5759
5767
|
reportedErrors = true;
|
@@ -5791,8 +5799,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5791
5799
|
const constructorMethodType = constructorMethodInfo.type;
|
5792
5800
|
// If there is an expected type that was not applied above when
|
5793
5801
|
// handling the __init__ method, try to apply it with the __new__ method.
|
5794
|
-
if (
|
5795
|
-
const expectedCallResult = validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck,
|
5802
|
+
if (inferenceContext && !returnType) {
|
5803
|
+
const expectedCallResult = validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, constructorMethodType);
|
5796
5804
|
if (expectedCallResult) {
|
5797
5805
|
returnType = expectedCallResult.returnType;
|
5798
5806
|
if (expectedCallResult.isTypeIncomplete) {
|
@@ -5807,14 +5815,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5807
5815
|
typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(constructorMethodType));
|
5808
5816
|
// Skip the unknown argument check if we've already checked for __init__.
|
5809
5817
|
const callResult = validateCallArguments(errorNode, argList, constructorMethodInfo, typeVarContext, skipUnknownArgCheck);
|
5818
|
+
if (callResult.isTypeIncomplete) {
|
5819
|
+
isTypeIncomplete = true;
|
5820
|
+
}
|
5810
5821
|
if (callResult.argumentErrors) {
|
5811
5822
|
reportedErrors = true;
|
5812
5823
|
}
|
5813
5824
|
else {
|
5814
5825
|
let newReturnType = callResult.returnType;
|
5815
|
-
if (callResult.isTypeIncomplete) {
|
5816
|
-
isTypeIncomplete = true;
|
5817
|
-
}
|
5818
5826
|
// If the constructor returned an object whose type matches the class of
|
5819
5827
|
// the original type being constructed, use the return type in case it was
|
5820
5828
|
// specialized. If it doesn't match, we'll fall back on the assumption that
|
@@ -5849,10 +5857,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5849
5857
|
}
|
5850
5858
|
}
|
5851
5859
|
if (!returnType) {
|
5852
|
-
returnType = applyExpectedTypeForConstructor(type,
|
5860
|
+
returnType = applyExpectedTypeForConstructor(type, inferenceContext, typeVarContext);
|
5853
5861
|
}
|
5854
5862
|
else if ((0, types_1.isClassInstance)(returnType) && (0, typeUtils_1.isTupleClass)(returnType) && !returnType.tupleTypeArguments) {
|
5855
|
-
returnType = applyExpectedTypeForTupleConstructor(returnType,
|
5863
|
+
returnType = applyExpectedTypeForTupleConstructor(returnType, inferenceContext);
|
5856
5864
|
}
|
5857
5865
|
validatedTypes = true;
|
5858
5866
|
}
|
@@ -5881,7 +5889,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5881
5889
|
if (!returnType) {
|
5882
5890
|
// There was no __init__ or __new__ method or we couldn't match the provided
|
5883
5891
|
// arguments to them.
|
5884
|
-
if (!
|
5892
|
+
if (!inferenceContext && type.typeArguments) {
|
5885
5893
|
// If there was no expected type but the type was already specialized,
|
5886
5894
|
// assume that we're constructing an instance of the specialized type.
|
5887
5895
|
returnType = (0, typeUtils_1.convertToInstance)(type);
|
@@ -5890,10 +5898,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5890
5898
|
// Do our best to specialize the instantiated class based on the expected
|
5891
5899
|
// type if provided.
|
5892
5900
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type));
|
5893
|
-
if (
|
5894
|
-
(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(type), expectedType, typeVarContext, getTypeVarScopesForNode(errorNode));
|
5901
|
+
if (inferenceContext) {
|
5902
|
+
(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(type), inferenceContext.expectedType, typeVarContext, getTypeVarScopesForNode(errorNode));
|
5895
5903
|
}
|
5896
|
-
returnType = applyExpectedTypeForConstructor(type,
|
5904
|
+
returnType = applyExpectedTypeForConstructor(type, inferenceContext, typeVarContext);
|
5897
5905
|
}
|
5898
5906
|
}
|
5899
5907
|
if (!reportedErrors) {
|
@@ -5910,16 +5918,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5910
5918
|
reportedErrors = true;
|
5911
5919
|
}
|
5912
5920
|
}
|
5913
|
-
const result = {
|
5921
|
+
const result = {
|
5922
|
+
argumentErrors: reportedErrors,
|
5923
|
+
returnType,
|
5924
|
+
isTypeIncomplete,
|
5925
|
+
overloadsUsedForCall,
|
5926
|
+
};
|
5914
5927
|
return result;
|
5915
5928
|
}
|
5916
5929
|
// For a constructor call that targets a generic class and an "expected type"
|
5917
5930
|
// (i.e. bidirectional inference), this function attempts to infer the correct
|
5918
5931
|
// specialized return type for the constructor.
|
5919
|
-
function validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck,
|
5932
|
+
function validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, constructorMethodType) {
|
5920
5933
|
let isTypeIncomplete = false;
|
5921
5934
|
let argumentErrors = false;
|
5922
|
-
const
|
5935
|
+
const overloadsUsedForCall = [];
|
5936
|
+
const returnType = (0, typeUtils_1.mapSubtypes)(inferenceContext.expectedType, (expectedSubType) => {
|
5923
5937
|
expectedSubType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expectedSubType);
|
5924
5938
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type));
|
5925
5939
|
if ((0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(type), expectedSubType, typeVarContext, getTypeVarScopesForNode(errorNode))) {
|
@@ -5927,16 +5941,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5927
5941
|
useSpeculativeMode(errorNode, () => {
|
5928
5942
|
callResult = validateCallArguments(errorNode, argList, { type: constructorMethodType }, typeVarContext.clone(), skipUnknownArgCheck);
|
5929
5943
|
});
|
5930
|
-
if (!
|
5944
|
+
if (!callResult.argumentErrors) {
|
5931
5945
|
// Call validateCallArguments again, this time without speculative
|
5932
5946
|
// mode, so any errors are reported.
|
5933
|
-
|
5947
|
+
callResult = validateCallArguments(errorNode, argList, { type: constructorMethodType }, typeVarContext, skipUnknownArgCheck);
|
5934
5948
|
if (callResult.isTypeIncomplete) {
|
5935
5949
|
isTypeIncomplete = true;
|
5936
5950
|
}
|
5937
5951
|
if (callResult.argumentErrors) {
|
5938
5952
|
argumentErrors = true;
|
5939
5953
|
}
|
5954
|
+
overloadsUsedForCall.push(...callResult.overloadsUsedForCall);
|
5940
5955
|
return applyExpectedSubtypeForConstructor(type, expectedSubType, typeVarContext);
|
5941
5956
|
}
|
5942
5957
|
}
|
@@ -5945,7 +5960,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5945
5960
|
if ((0, types_1.isNever)(returnType)) {
|
5946
5961
|
return undefined;
|
5947
5962
|
}
|
5948
|
-
return { returnType, isTypeIncomplete, argumentErrors };
|
5963
|
+
return { returnType, isTypeIncomplete, argumentErrors, overloadsUsedForCall };
|
5949
5964
|
}
|
5950
5965
|
function applyExpectedSubtypeForConstructor(type, expectedSubtype, typeVarContext) {
|
5951
5966
|
const specializedType = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstance(type), typeVarContext);
|
@@ -5960,10 +5975,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5960
5975
|
}
|
5961
5976
|
// Handles the case where a constructor is a generic type and the type
|
5962
5977
|
// arguments are not specified but can be provided by the expected type.
|
5963
|
-
function applyExpectedTypeForConstructor(type,
|
5978
|
+
function applyExpectedTypeForConstructor(type, inferenceContext, typeVarContext) {
|
5964
5979
|
let unsolvedTypeVarsAreUnknown = true;
|
5965
|
-
if (
|
5966
|
-
const specializedExpectedType = (0, typeUtils_1.mapSubtypes)(expectedType, (expectedSubtype) => {
|
5980
|
+
if (inferenceContext) {
|
5981
|
+
const specializedExpectedType = (0, typeUtils_1.mapSubtypes)(inferenceContext.expectedType, (expectedSubtype) => {
|
5967
5982
|
return applyExpectedSubtypeForConstructor(type, expectedSubtype, typeVarContext);
|
5968
5983
|
});
|
5969
5984
|
if (!(0, types_1.isNever)(specializedExpectedType)) {
|
@@ -5983,13 +5998,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5983
5998
|
}
|
5984
5999
|
// Similar to applyExpectedTypeForConstructor, this function handles the
|
5985
6000
|
// special case of the tuple class.
|
5986
|
-
function applyExpectedTypeForTupleConstructor(type,
|
6001
|
+
function applyExpectedTypeForTupleConstructor(type, inferenceContext) {
|
5987
6002
|
let specializedType = type;
|
5988
|
-
if (
|
5989
|
-
(0, types_1.isClassInstance)(expectedType) &&
|
5990
|
-
(0, typeUtils_1.isTupleClass)(expectedType) &&
|
5991
|
-
expectedType.tupleTypeArguments) {
|
5992
|
-
specializedType = (0, typeUtils_1.specializeTupleClass)(type, expectedType.tupleTypeArguments);
|
6003
|
+
if (inferenceContext &&
|
6004
|
+
(0, types_1.isClassInstance)(inferenceContext.expectedType) &&
|
6005
|
+
(0, typeUtils_1.isTupleClass)(inferenceContext.expectedType) &&
|
6006
|
+
inferenceContext.expectedType.tupleTypeArguments) {
|
6007
|
+
specializedType = (0, typeUtils_1.specializeTupleClass)(type, inferenceContext.expectedType.tupleTypeArguments);
|
5993
6008
|
}
|
5994
6009
|
return specializedType;
|
5995
6010
|
}
|
@@ -5997,12 +6012,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5997
6012
|
// list, specializes the call based on arg types, and returns the
|
5998
6013
|
// specialized type of the return value. If it detects an error along
|
5999
6014
|
// the way, it emits a diagnostic and sets argumentErrors to true.
|
6000
|
-
function validateCallArguments(errorNode, argList, callTypeResult, typeVarContext, skipUnknownArgCheck = false,
|
6015
|
+
function validateCallArguments(errorNode, argList, callTypeResult, typeVarContext, skipUnknownArgCheck = false, inferenceContext, recursionCount = 0) {
|
6001
6016
|
let argumentErrors = false;
|
6002
6017
|
let isTypeIncomplete = false;
|
6003
6018
|
let specializedInitSelfType;
|
6019
|
+
const overloadsUsedForCall = [];
|
6004
6020
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
6005
|
-
return { returnType: types_1.UnknownType.create(), argumentErrors: true };
|
6021
|
+
return { returnType: types_1.UnknownType.create(), argumentErrors: true, overloadsUsedForCall };
|
6006
6022
|
}
|
6007
6023
|
recursionCount++;
|
6008
6024
|
if (types_1.TypeBase.isSpecialForm(callTypeResult.type)) {
|
@@ -6011,7 +6027,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6011
6027
|
expression: ParseTreeUtils.printExpression(exprNode),
|
6012
6028
|
type: printType(callTypeResult.type, { expandTypeAlias: true }),
|
6013
6029
|
}), exprNode);
|
6014
|
-
return { returnType: types_1.UnknownType.create(), argumentErrors: true };
|
6030
|
+
return { returnType: types_1.UnknownType.create(), argumentErrors: true, overloadsUsedForCall };
|
6015
6031
|
}
|
6016
6032
|
const returnType = mapSubtypesExpandTypeVars(callTypeResult.type,
|
6017
6033
|
/* conditionFilter */ undefined, (expandedSubtype, unexpandedSubtype) => {
|
@@ -6055,10 +6071,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6055
6071
|
effectiveTypeVarContext.addSolveForScope(types_1.WildcardTypeVarScopeId);
|
6056
6072
|
}
|
6057
6073
|
}
|
6058
|
-
const functionResult = validateFunctionArguments(errorNode, argList, expandedSubtype, effectiveTypeVarContext, skipUnknownArgCheck,
|
6074
|
+
const functionResult = validateFunctionArguments(errorNode, argList, expandedSubtype, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
|
6059
6075
|
if (functionResult.isTypeIncomplete) {
|
6060
6076
|
isTypeIncomplete = true;
|
6061
6077
|
}
|
6078
|
+
overloadsUsedForCall.push(...functionResult.overloadsUsedForCall);
|
6062
6079
|
if (functionResult.argumentErrors) {
|
6063
6080
|
argumentErrors = true;
|
6064
6081
|
}
|
@@ -6103,7 +6120,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6103
6120
|
}
|
6104
6121
|
return (0, typeUtils_1.convertToInstance)(castToType);
|
6105
6122
|
}
|
6106
|
-
const functionResult = validateOverloadedFunctionArguments(errorNode, argList, expandedSubtype, typeVarContext, skipUnknownArgCheck,
|
6123
|
+
const functionResult = validateOverloadedFunctionArguments(errorNode, argList, expandedSubtype, typeVarContext, skipUnknownArgCheck, inferenceContext);
|
6124
|
+
overloadsUsedForCall.push(...functionResult.overloadsUsedForCall);
|
6107
6125
|
if (functionResult.isTypeIncomplete) {
|
6108
6126
|
isTypeIncomplete = true;
|
6109
6127
|
}
|
@@ -6139,7 +6157,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6139
6157
|
const className = expandedSubtype.aliasName || expandedSubtype.details.name;
|
6140
6158
|
if (className === 'type') {
|
6141
6159
|
// Validate the constructor arguments.
|
6142
|
-
validateConstructorArguments(errorNode, argList, expandedSubtype, skipUnknownArgCheck,
|
6160
|
+
validateConstructorArguments(errorNode, argList, expandedSubtype, skipUnknownArgCheck, inferenceContext);
|
6143
6161
|
// Handle the 'type' call specially.
|
6144
6162
|
if (argList.length === 1) {
|
6145
6163
|
// The one-parameter form of "type" returns the class
|
@@ -6235,7 +6253,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6235
6253
|
}), errorNode);
|
6236
6254
|
}
|
6237
6255
|
// Assume this is a call to the constructor.
|
6238
|
-
const constructorResult = validateConstructorArguments(errorNode, argList, expandedSubtype, skipUnknownArgCheck,
|
6256
|
+
const constructorResult = validateConstructorArguments(errorNode, argList, expandedSubtype, skipUnknownArgCheck, inferenceContext);
|
6257
|
+
overloadsUsedForCall.push(...constructorResult.overloadsUsedForCall);
|
6239
6258
|
if (constructorResult.argumentErrors) {
|
6240
6259
|
argumentErrors = true;
|
6241
6260
|
}
|
@@ -6275,7 +6294,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6275
6294
|
else {
|
6276
6295
|
const memberType = (_d = getTypeOfObjectMember(errorNode, expandedSubtype, '__call__')) === null || _d === void 0 ? void 0 : _d.type;
|
6277
6296
|
if (memberType) {
|
6278
|
-
const functionResult = validateCallArguments(errorNode, argList, { type: memberType }, typeVarContext, skipUnknownArgCheck,
|
6297
|
+
const functionResult = validateCallArguments(errorNode, argList, { type: memberType }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
6298
|
+
overloadsUsedForCall.push(...functionResult.overloadsUsedForCall);
|
6279
6299
|
if (functionResult.argumentErrors) {
|
6280
6300
|
argumentErrors = true;
|
6281
6301
|
}
|
@@ -6307,7 +6327,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6307
6327
|
// need to handle recursive type aliases.
|
6308
6328
|
case 10 /* TypeVar */: {
|
6309
6329
|
expandedSubtype = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expandedSubtype);
|
6310
|
-
const callResult = validateCallArguments(errorNode, argList, { type: expandedSubtype }, typeVarContext, skipUnknownArgCheck,
|
6330
|
+
const callResult = validateCallArguments(errorNode, argList, { type: expandedSubtype }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
6331
|
+
overloadsUsedForCall.push(...callResult.overloadsUsedForCall);
|
6311
6332
|
if (callResult.argumentErrors) {
|
6312
6333
|
argumentErrors = true;
|
6313
6334
|
}
|
@@ -6325,6 +6346,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6325
6346
|
returnType: (0, types_1.isNever)(returnType) && !returnType.isNoReturn ? undefined : returnType,
|
6326
6347
|
isTypeIncomplete,
|
6327
6348
|
specializedInitSelfType,
|
6349
|
+
overloadsUsedForCall,
|
6328
6350
|
};
|
6329
6351
|
}
|
6330
6352
|
// Expands any unpacked tuples within an argument list.
|
@@ -7130,19 +7152,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7130
7152
|
// After having matched arguments with parameters, this function evaluates the
|
7131
7153
|
// types of each argument expression and validates that the resulting type is
|
7132
7154
|
// compatible with the declared type of the corresponding parameter.
|
7133
|
-
function validateFunctionArgumentTypesWithExpectedType(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false,
|
7155
|
+
function validateFunctionArgumentTypesWithExpectedType(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
|
7134
7156
|
var _a;
|
7135
7157
|
const type = matchResults.overload;
|
7136
|
-
if (!
|
7137
|
-
(0, types_1.isAnyOrUnknown)(expectedType) ||
|
7138
|
-
(0, types_1.isNever)(expectedType) ||
|
7139
|
-
(0, typeUtils_1.requiresSpecialization)(expectedType) ||
|
7158
|
+
if (!inferenceContext ||
|
7159
|
+
(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) ||
|
7160
|
+
(0, types_1.isNever)(inferenceContext.expectedType) ||
|
7161
|
+
(0, typeUtils_1.requiresSpecialization)(inferenceContext.expectedType) ||
|
7140
7162
|
!type.details.declaredReturnType ||
|
7141
7163
|
!(0, typeUtils_1.requiresSpecialization)((_a = types_1.FunctionType.getSpecializedReturnType(type)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create())) {
|
7142
7164
|
return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, skipUnknownArgCheck);
|
7143
7165
|
}
|
7144
7166
|
const effectiveReturnType = getFunctionEffectiveReturnType(type);
|
7145
|
-
let effectiveExpectedType = expectedType;
|
7167
|
+
let effectiveExpectedType = inferenceContext.expectedType;
|
7146
7168
|
let effectiveFlags = 0 /* Default */;
|
7147
7169
|
if ((0, typeUtils_1.containsLiteralType)(effectiveExpectedType, /* includeTypeArgs */ true)) {
|
7148
7170
|
effectiveFlags |= 128 /* RetainLiteralsForTypeVar */;
|
@@ -7150,7 +7172,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7150
7172
|
// If the expected type is a union, we don't know which type is expected.
|
7151
7173
|
// We may or may not be able to make use of the expected type. We'll evaluate
|
7152
7174
|
// speculatively to see if using the expected type works.
|
7153
|
-
if ((0, types_1.isUnion)(expectedType)) {
|
7175
|
+
if ((0, types_1.isUnion)(inferenceContext.expectedType)) {
|
7154
7176
|
let speculativeResults;
|
7155
7177
|
useSpeculativeMode(errorNode, () => {
|
7156
7178
|
const typeVarContextCopy = typeVarContext.clone();
|
@@ -7372,6 +7394,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7372
7394
|
}
|
7373
7395
|
let specializedReturnType = (0, typeUtils_1.addConditionToType)((0, typeUtils_1.applySolvedTypeVars)(returnType, typeVarContext, {
|
7374
7396
|
unknownIfNotFound,
|
7397
|
+
useUnknownOverDefault: skipUnknownArgCheck,
|
7375
7398
|
eliminateUnsolvedInUnions,
|
7376
7399
|
}), typeCondition);
|
7377
7400
|
// If the final return type is an unpacked tuple, turn it into a normal (unpacked) tuple.
|
@@ -7400,6 +7423,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7400
7423
|
isTypeIncomplete,
|
7401
7424
|
activeParam: matchResults.activeParam,
|
7402
7425
|
specializedInitSelfType,
|
7426
|
+
overloadsUsedForCall: argumentErrors ? [] : [type],
|
7403
7427
|
};
|
7404
7428
|
}
|
7405
7429
|
function adjustCallableReturnType(type) {
|
@@ -7419,7 +7443,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7419
7443
|
// Tries to assign the call arguments to the function parameter
|
7420
7444
|
// list and reports any mismatches in types or counts. Returns the
|
7421
7445
|
// specialized return type of the call.
|
7422
|
-
function validateFunctionArguments(errorNode, argList, type, typeVarContext, skipUnknownArgCheck = false,
|
7446
|
+
function validateFunctionArguments(errorNode, argList, type, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
|
7423
7447
|
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, type, 0);
|
7424
7448
|
if (matchResults.argumentErrors) {
|
7425
7449
|
// Evaluate types of all args. This will ensure that referenced symbols are
|
@@ -7432,9 +7456,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7432
7456
|
return {
|
7433
7457
|
argumentErrors: true,
|
7434
7458
|
activeParam: matchResults.activeParam,
|
7459
|
+
overloadsUsedForCall: [],
|
7435
7460
|
};
|
7436
7461
|
}
|
7437
|
-
return validateFunctionArgumentTypesWithExpectedType(errorNode, matchResults, typeVarContext, skipUnknownArgCheck,
|
7462
|
+
return validateFunctionArgumentTypesWithExpectedType(errorNode, matchResults, typeVarContext, skipUnknownArgCheck, inferenceContext);
|
7438
7463
|
}
|
7439
7464
|
// Determines whether the specified argument list satisfies the function
|
7440
7465
|
// signature bound to the specified ParamSpec. Return value indicates success.
|
@@ -7558,11 +7583,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7558
7583
|
// to true if this is the first pass through the parameter list because
|
7559
7584
|
// a wide bound on a TypeVar (if a narrow bound has not yet been established)
|
7560
7585
|
// will unnecessarily constrain the expected type.
|
7561
|
-
let expectedType
|
7562
|
-
|
7563
|
-
argParam.paramType
|
7564
|
-
|
7565
|
-
: (0, typeUtils_1.applySolvedTypeVars)(argParam.paramType, typeVarContext, { useNarrowBoundOnly });
|
7586
|
+
let expectedType;
|
7587
|
+
if (!(0, types_1.isTypeVar)(argParam.paramType) || argParam.paramType.scopeId !== (functionType === null || functionType === void 0 ? void 0 : functionType.details.typeVarScopeId)) {
|
7588
|
+
expectedType = (0, typeUtils_1.applySolvedTypeVars)(argParam.paramType, typeVarContext, { useNarrowBoundOnly });
|
7589
|
+
}
|
7566
7590
|
// If the expected type is unknown, don't use an expected type. Instead,
|
7567
7591
|
// use default rules for evaluating the expression type.
|
7568
7592
|
if (expectedType && (0, types_1.isUnknown)(expectedType)) {
|
@@ -7575,10 +7599,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7575
7599
|
else {
|
7576
7600
|
const flags = argParam.expectingType
|
7577
7601
|
? 8 /* EvaluateStringLiteralAsType */ |
|
7578
|
-
32 /*
|
7579
|
-
|
7602
|
+
32 /* DisallowParamSpec */ |
|
7603
|
+
64 /* DisallowTypeVarTuple */
|
7580
7604
|
: 0 /* None */;
|
7581
|
-
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, expectedType);
|
7605
|
+
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, typeVarContext));
|
7582
7606
|
argType = exprTypeResult.type;
|
7583
7607
|
if (exprTypeResult.isIncomplete) {
|
7584
7608
|
isTypeIncomplete = true;
|
@@ -7591,7 +7615,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7591
7615
|
if (argParam.argument &&
|
7592
7616
|
argParam.argument.name &&
|
7593
7617
|
!speculativeTypeTracker.isSpeculative(argParam.errorNode)) {
|
7594
|
-
writeTypeCache(argParam.argument.name, expectedType
|
7618
|
+
writeTypeCache(argParam.argument.name, { type: expectedType !== null && expectedType !== void 0 ? expectedType : argType, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
7595
7619
|
}
|
7596
7620
|
}
|
7597
7621
|
else {
|
@@ -7601,8 +7625,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7601
7625
|
}
|
7602
7626
|
else if (argParam.expectingType && !argParam.argument.typeResult && argParam.argument.valueExpression) {
|
7603
7627
|
const argTypeResult = getTypeOfExpression(argParam.argument.valueExpression, 8 /* EvaluateStringLiteralAsType */ |
|
7604
|
-
32 /*
|
7605
|
-
|
7628
|
+
32 /* DisallowParamSpec */ |
|
7629
|
+
64 /* DisallowTypeVarTuple */);
|
7606
7630
|
argType = argTypeResult.type;
|
7607
7631
|
if (argTypeResult.isIncomplete) {
|
7608
7632
|
isTypeIncomplete = true;
|
@@ -7997,7 +8021,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7997
8021
|
});
|
7998
8022
|
// Update the type cache so we don't attempt to re-evaluate this node.
|
7999
8023
|
// The type doesn't matter, so use Any.
|
8000
|
-
writeTypeCache(node, types_1.AnyType.create(), /* flags */ undefined
|
8024
|
+
writeTypeCache(node, { type: types_1.AnyType.create() }, /* flags */ undefined);
|
8001
8025
|
return functionType;
|
8002
8026
|
}
|
8003
8027
|
else {
|
@@ -8139,7 +8163,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8139
8163
|
function getTypeOfConstant(node, flags) {
|
8140
8164
|
let type;
|
8141
8165
|
if (node.constType === 26 /* None */) {
|
8142
|
-
type = (flags &
|
8166
|
+
type = (flags & 128 /* ExpectingType */) !== 0 ? types_1.NoneType.createType() : types_1.NoneType.createInstance();
|
8143
8167
|
}
|
8144
8168
|
else if (node.constType === 33 /* True */ ||
|
8145
8169
|
node.constType === 15 /* False */ ||
|
@@ -8161,7 +8185,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8161
8185
|
}
|
8162
8186
|
return { type };
|
8163
8187
|
}
|
8164
|
-
function getTypeOfUnaryOperation(node,
|
8188
|
+
function getTypeOfUnaryOperation(node, inferenceContext) {
|
8165
8189
|
const exprTypeResult = getTypeOfExpression(node.expression);
|
8166
8190
|
let exprType = makeTopLevelTypeVarsConcrete(exprTypeResult.type);
|
8167
8191
|
const isIncomplete = exprTypeResult.isIncomplete;
|
@@ -8224,15 +8248,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8224
8248
|
}
|
8225
8249
|
else {
|
8226
8250
|
const magicMethodName = unaryOperatorMap[node.operator];
|
8227
|
-
type = getTypeOfMagicMethodReturn(exprType, [], magicMethodName, node,
|
8251
|
+
type = getTypeOfMagicMethodReturn(exprType, [], magicMethodName, node, inferenceContext);
|
8228
8252
|
}
|
8229
8253
|
if (!type) {
|
8230
8254
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
8231
|
-
if (
|
8255
|
+
if (inferenceContext) {
|
8232
8256
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotSupportUnaryOperatorBidirectional().format({
|
8233
8257
|
operator: ParseTreeUtils.printOperator(node.operator),
|
8234
8258
|
type: printType(exprType),
|
8235
|
-
expectedType: printType(expectedType),
|
8259
|
+
expectedType: printType(inferenceContext.expectedType),
|
8236
8260
|
}), node);
|
8237
8261
|
}
|
8238
8262
|
else {
|
@@ -8247,7 +8271,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8247
8271
|
}
|
8248
8272
|
return { type, isIncomplete };
|
8249
8273
|
}
|
8250
|
-
function getTypeOfBinaryOperation(node,
|
8274
|
+
function getTypeOfBinaryOperation(node, inferenceContext, flags) {
|
8251
8275
|
const leftExpression = node.leftExpression;
|
8252
8276
|
let rightExpression = node.rightExpression;
|
8253
8277
|
let isIncomplete = false;
|
@@ -8259,7 +8283,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8259
8283
|
!rightExpression.parenthesized &&
|
8260
8284
|
ParseTreeUtils.operatorSupportsChaining(rightExpression.operator)) {
|
8261
8285
|
// Evaluate the right expression so it is type checked.
|
8262
|
-
getTypeOfBinaryOperation(rightExpression,
|
8286
|
+
getTypeOfBinaryOperation(rightExpression, inferenceContext, flags);
|
8263
8287
|
// Use the left side of the right expression for comparison purposes.
|
8264
8288
|
rightExpression = rightExpression.leftExpression;
|
8265
8289
|
}
|
@@ -8267,21 +8291,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8267
8291
|
// For most binary operations, the "expected type" is applied to the output
|
8268
8292
|
// of the magic method for that operation. However, the "or" and "and" operators
|
8269
8293
|
// have no magic method, so we apply the expected type directly to both operands.
|
8270
|
-
let expectedOperandType = node.operator === 37 /* Or */ || node.operator === 36 /* And */
|
8294
|
+
let expectedOperandType = node.operator === 37 /* Or */ || node.operator === 36 /* And */
|
8295
|
+
? inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType
|
8296
|
+
: undefined;
|
8271
8297
|
// Handle the very special case where the expected type is a list
|
8272
8298
|
// and the operator is a multiply. This comes up in the common case
|
8273
8299
|
// of "x: List[Optional[X]] = [None] * y" where y is an integer literal.
|
8274
8300
|
let expectedLeftOperandType;
|
8275
8301
|
if (node.operator === 26 /* Multiply */ &&
|
8276
|
-
|
8277
|
-
(0, types_1.isClassInstance)(expectedType) &&
|
8278
|
-
types_1.ClassType.isBuiltIn(expectedType, 'list') &&
|
8279
|
-
expectedType.typeArguments &&
|
8280
|
-
expectedType.typeArguments.length >= 1 &&
|
8302
|
+
inferenceContext &&
|
8303
|
+
(0, types_1.isClassInstance)(inferenceContext.expectedType) &&
|
8304
|
+
types_1.ClassType.isBuiltIn(inferenceContext.expectedType, 'list') &&
|
8305
|
+
inferenceContext.expectedType.typeArguments &&
|
8306
|
+
inferenceContext.expectedType.typeArguments.length >= 1 &&
|
8281
8307
|
node.leftExpression.nodeType === 31 /* List */) {
|
8282
|
-
expectedLeftOperandType = expectedType;
|
8308
|
+
expectedLeftOperandType = inferenceContext.expectedType;
|
8283
8309
|
}
|
8284
|
-
const
|
8310
|
+
const effectiveExpectedType = expectedOperandType !== null && expectedOperandType !== void 0 ? expectedOperandType : expectedLeftOperandType;
|
8311
|
+
const leftTypeResult = getTypeOfExpression(leftExpression, flags, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType));
|
8285
8312
|
let leftType = leftTypeResult.type;
|
8286
8313
|
if (!expectedOperandType) {
|
8287
8314
|
if (node.operator === 37 /* Or */ || node.operator === 36 /* And */) {
|
@@ -8297,10 +8324,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8297
8324
|
else if (node.operator === 6 /* BitwiseOr */) {
|
8298
8325
|
// If this is a bitwise or ("|"), use the type of the left operand. This allows
|
8299
8326
|
// us to support the case where a TypedDict is being updated with a dict expression.
|
8300
|
-
|
8327
|
+
if ((0, types_1.isClassInstance)(leftType) && types_1.ClassType.isTypedDictClass(leftType)) {
|
8328
|
+
expectedOperandType = leftType;
|
8329
|
+
}
|
8301
8330
|
}
|
8302
8331
|
}
|
8303
|
-
const rightTypeResult = getTypeOfExpression(rightExpression, flags, expectedOperandType);
|
8332
|
+
const rightTypeResult = getTypeOfExpression(rightExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedOperandType));
|
8304
8333
|
let rightType = rightTypeResult.type;
|
8305
8334
|
if (leftTypeResult.isIncomplete || rightTypeResult.isIncomplete) {
|
8306
8335
|
isIncomplete = true;
|
@@ -8394,7 +8423,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8394
8423
|
// incomplete because we may be evaluating types within a loop,
|
8395
8424
|
// so the literal values may change each time.
|
8396
8425
|
const isLiteralMathAllowed = !ParseTreeUtils.isWithinLoop(node);
|
8397
|
-
|
8426
|
+
// Don't special-case tuple __add__ if the left type is a union. This
|
8427
|
+
// can result in an infinite loop if we keep creating new tuple types
|
8428
|
+
// within a loop construct using __add__.
|
8429
|
+
const isTupleAddAllowed = !(0, types_1.isUnion)(leftType);
|
8430
|
+
let type = validateBinaryOperation(node.operator, { type: leftType, isIncomplete: leftTypeResult.isIncomplete }, { type: rightType, isIncomplete: rightTypeResult.isIncomplete }, node, inferenceContext, diag, { isLiteralMathAllowed, isTupleAddAllowed });
|
8398
8431
|
if (!diag.isEmpty() || !type) {
|
8399
8432
|
if (!isIncomplete) {
|
8400
8433
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -8439,7 +8472,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8439
8472
|
}
|
8440
8473
|
return true;
|
8441
8474
|
}
|
8442
|
-
function getTypeOfAugmentedAssignment(node,
|
8475
|
+
function getTypeOfAugmentedAssignment(node, inferenceContext) {
|
8443
8476
|
const operatorMap = {
|
8444
8477
|
[1 /* AddEqual */]: ['__iadd__', 0 /* Add */],
|
8445
8478
|
[34 /* SubtractEqual */]: ['__isub__', 33 /* Subtract */],
|
@@ -8466,7 +8499,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8466
8499
|
// us to support the case where a TypedDict is being updated with a dict expression.
|
8467
8500
|
expectedOperandType = leftType;
|
8468
8501
|
}
|
8469
|
-
const rightTypeResult = getTypeOfExpression(node.rightExpression,
|
8502
|
+
const rightTypeResult = getTypeOfExpression(node.rightExpression,
|
8503
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedOperandType));
|
8470
8504
|
const rightType = rightTypeResult.type;
|
8471
8505
|
const isIncomplete = !!rightTypeResult.isIncomplete || !!leftTypeResult.isIncomplete;
|
8472
8506
|
if ((0, types_1.isNever)(leftType) || (0, types_1.isNever)(rightType)) {
|
@@ -8480,14 +8514,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8480
8514
|
return (0, typeUtils_1.preserveUnknown)(leftSubtypeUnexpanded, rightSubtypeUnexpanded);
|
8481
8515
|
}
|
8482
8516
|
const magicMethodName = operatorMap[node.operator][0];
|
8483
|
-
let returnType = getTypeOfMagicMethodReturn(leftSubtypeUnexpanded, [{ type: rightSubtypeUnexpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, node,
|
8517
|
+
let returnType = getTypeOfMagicMethodReturn(leftSubtypeUnexpanded, [{ type: rightSubtypeUnexpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, node, inferenceContext);
|
8484
8518
|
if (!returnType && leftSubtypeUnexpanded !== leftSubtypeExpanded) {
|
8485
8519
|
// Try with the expanded left type.
|
8486
|
-
returnType = getTypeOfMagicMethodReturn(leftSubtypeExpanded, [{ type: rightSubtypeUnexpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, node,
|
8520
|
+
returnType = getTypeOfMagicMethodReturn(leftSubtypeExpanded, [{ type: rightSubtypeUnexpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, node, inferenceContext);
|
8487
8521
|
}
|
8488
8522
|
if (!returnType && rightSubtypeUnexpanded !== rightSubtypeExpanded) {
|
8489
8523
|
// Try with the expanded left and right type.
|
8490
|
-
returnType = getTypeOfMagicMethodReturn(leftSubtypeExpanded, [{ type: rightSubtypeExpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, node,
|
8524
|
+
returnType = getTypeOfMagicMethodReturn(leftSubtypeExpanded, [{ type: rightSubtypeExpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, node, inferenceContext);
|
8491
8525
|
}
|
8492
8526
|
if (!returnType) {
|
8493
8527
|
// If the LHS class didn't support the magic method for augmented
|
@@ -8500,7 +8534,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8500
8534
|
!rightTypeResult.isIncomplete &&
|
8501
8535
|
(0, typeUtils_1.getUnionSubtypeCount)(leftType) * (0, typeUtils_1.getUnionSubtypeCount)(rightType) <
|
8502
8536
|
maxLiteralMathSubtypeCount;
|
8503
|
-
|
8537
|
+
// Don't special-case tuple __add__ if the left type is a union. This
|
8538
|
+
// can result in an infinite loop if we keep creating new tuple types
|
8539
|
+
// within a loop construct using __add__.
|
8540
|
+
const isTupleAddAllowed = !(0, types_1.isUnion)(leftType);
|
8541
|
+
returnType = validateBinaryOperation(binaryOperator, { type: leftSubtypeUnexpanded, isIncomplete: leftTypeResult.isIncomplete }, { type: rightSubtypeUnexpanded, isIncomplete: rightTypeResult.isIncomplete }, node, inferenceContext, diag, { isLiteralMathAllowed, isTupleAddAllowed });
|
8504
8542
|
}
|
8505
8543
|
return returnType;
|
8506
8544
|
});
|
@@ -8523,7 +8561,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8523
8561
|
assignTypeToExpression(node.destExpression, typeResult.type, !!typeResult.isIncomplete, node.rightExpression);
|
8524
8562
|
return typeResult;
|
8525
8563
|
}
|
8526
|
-
function validateBinaryOperation(operator, leftTypeResult, rightTypeResult, errorNode,
|
8564
|
+
function validateBinaryOperation(operator, leftTypeResult, rightTypeResult, errorNode, inferenceContext, diag, options) {
|
8527
8565
|
const leftType = leftTypeResult.type;
|
8528
8566
|
const rightType = rightTypeResult.type;
|
8529
8567
|
let type;
|
@@ -8577,7 +8615,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8577
8615
|
return (0, typeUtils_1.preserveUnknown)(leftSubtype, rightSubtypeExpanded);
|
8578
8616
|
}
|
8579
8617
|
let returnType = getTypeOfMagicMethodReturn(rightSubtypeExpanded, [{ type: leftSubtype, isIncomplete: leftTypeResult.isIncomplete }], '__contains__', errorNode,
|
8580
|
-
/*
|
8618
|
+
/* inferenceContext */ undefined);
|
8581
8619
|
if (!returnType) {
|
8582
8620
|
// If __contains__ was not supported, fall back
|
8583
8621
|
// on an iterable.
|
@@ -8624,7 +8662,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8624
8662
|
// Handle certain operations on certain homogenous literal types
|
8625
8663
|
// using special-case math. For example, Literal[1, 2] + Literal[3, 4]
|
8626
8664
|
// should result in Literal[4, 5, 6].
|
8627
|
-
if (isLiteralMathAllowed) {
|
8665
|
+
if (options.isLiteralMathAllowed) {
|
8628
8666
|
const leftLiteralClassName = (0, typeUtils_1.getLiteralTypeClassName)(leftType);
|
8629
8667
|
if (leftLiteralClassName && !(0, typeUtils_1.getTypeCondition)(leftType)) {
|
8630
8668
|
const rightLiteralClassName = (0, typeUtils_1.getLiteralTypeClassName)(rightType);
|
@@ -8688,7 +8726,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8688
8726
|
else {
|
8689
8727
|
// Convert back to a simple number if it fits. Leave as a bigint
|
8690
8728
|
// if it doesn't.
|
8691
|
-
if (newValue
|
8729
|
+
if (newValue >= Number.MIN_SAFE_INTEGER &&
|
8730
|
+
newValue <= Number.MAX_SAFE_INTEGER) {
|
8692
8731
|
newValue = Number(newValue);
|
8693
8732
|
}
|
8694
8733
|
return types_1.ClassType.cloneWithLiteral(leftClassSubtype, newValue);
|
@@ -8716,7 +8755,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8716
8755
|
return (0, typeUtils_1.preserveUnknown)(leftSubtypeUnexpanded, rightSubtypeUnexpanded);
|
8717
8756
|
}
|
8718
8757
|
// Special-case __add__ for tuples when the types for both tuples are known.
|
8719
|
-
if (
|
8758
|
+
if (options.isTupleAddAllowed &&
|
8759
|
+
operator === 0 /* Add */ &&
|
8720
8760
|
(0, types_1.isClassInstance)(leftSubtypeExpanded) &&
|
8721
8761
|
(0, typeUtils_1.isTupleClass)(leftSubtypeExpanded) &&
|
8722
8762
|
leftSubtypeExpanded.tupleTypeArguments &&
|
@@ -8733,19 +8773,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8733
8773
|
]));
|
8734
8774
|
}
|
8735
8775
|
const magicMethodName = binaryOperatorMap[operator][0];
|
8736
|
-
let resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(leftSubtypeUnexpanded), [{ type: rightSubtypeUnexpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, errorNode,
|
8776
|
+
let resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(leftSubtypeUnexpanded), [{ type: rightSubtypeUnexpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, errorNode, inferenceContext);
|
8737
8777
|
if (!resultType && leftSubtypeUnexpanded !== leftSubtypeExpanded) {
|
8738
8778
|
// Try the expanded left type.
|
8739
|
-
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(leftSubtypeExpanded), [{ type: rightSubtypeUnexpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, errorNode,
|
8779
|
+
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(leftSubtypeExpanded), [{ type: rightSubtypeUnexpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, errorNode, inferenceContext);
|
8740
8780
|
}
|
8741
8781
|
if (!resultType && rightSubtypeUnexpanded !== rightSubtypeExpanded) {
|
8742
8782
|
// Try the expanded left and right type.
|
8743
|
-
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(leftSubtypeExpanded), [{ type: rightSubtypeExpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, errorNode,
|
8783
|
+
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(leftSubtypeExpanded), [{ type: rightSubtypeExpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, errorNode, inferenceContext);
|
8744
8784
|
}
|
8745
8785
|
if (!resultType) {
|
8746
8786
|
// Try the alternate form (swapping right and left).
|
8747
8787
|
const altMagicMethodName = binaryOperatorMap[operator][1];
|
8748
|
-
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(rightSubtypeUnexpanded), [{ type: leftSubtypeUnexpanded, isIncomplete: leftTypeResult.isIncomplete }], altMagicMethodName, errorNode,
|
8788
|
+
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(rightSubtypeUnexpanded), [{ type: leftSubtypeUnexpanded, isIncomplete: leftTypeResult.isIncomplete }], altMagicMethodName, errorNode, inferenceContext);
|
8749
8789
|
if (!resultType && rightSubtypeUnexpanded !== rightSubtypeExpanded) {
|
8750
8790
|
// Try the expanded right type.
|
8751
8791
|
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(rightSubtypeExpanded), [
|
@@ -8753,20 +8793,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8753
8793
|
type: leftSubtypeUnexpanded,
|
8754
8794
|
isIncomplete: leftTypeResult.isIncomplete,
|
8755
8795
|
},
|
8756
|
-
], altMagicMethodName, errorNode,
|
8796
|
+
], altMagicMethodName, errorNode, inferenceContext);
|
8757
8797
|
}
|
8758
8798
|
if (!resultType && leftSubtypeUnexpanded !== leftSubtypeExpanded) {
|
8759
8799
|
// Try the expanded right and left type.
|
8760
|
-
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(rightSubtypeExpanded), [{ type: leftSubtypeExpanded, isIncomplete: leftTypeResult.isIncomplete }], altMagicMethodName, errorNode,
|
8800
|
+
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(rightSubtypeExpanded), [{ type: leftSubtypeExpanded, isIncomplete: leftTypeResult.isIncomplete }], altMagicMethodName, errorNode, inferenceContext);
|
8761
8801
|
}
|
8762
8802
|
}
|
8763
8803
|
if (!resultType) {
|
8764
|
-
if (
|
8804
|
+
if (inferenceContext) {
|
8765
8805
|
diag.addMessage(localize_1.Localizer.Diagnostic.typeNotSupportBinaryOperatorBidirectional().format({
|
8766
8806
|
operator: ParseTreeUtils.printOperator(operator),
|
8767
8807
|
leftType: printType(leftSubtypeExpanded),
|
8768
8808
|
rightType: printType(rightSubtypeExpanded),
|
8769
|
-
expectedType: printType(expectedType),
|
8809
|
+
expectedType: printType(inferenceContext.expectedType),
|
8770
8810
|
}));
|
8771
8811
|
}
|
8772
8812
|
else {
|
@@ -8784,7 +8824,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8784
8824
|
}
|
8785
8825
|
return type && (0, types_1.isNever)(type) ? undefined : type;
|
8786
8826
|
}
|
8787
|
-
function getTypeOfMagicMethodReturn(objType, args, magicMethodName, errorNode,
|
8827
|
+
function getTypeOfMagicMethodReturn(objType, args, magicMethodName, errorNode, inferenceContext) {
|
8788
8828
|
let magicMethodSupported = true;
|
8789
8829
|
// Create a helper lambda for object subtypes.
|
8790
8830
|
const handleSubtype = (subtype) => {
|
@@ -8812,7 +8852,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8812
8852
|
useSpeculativeMode(errorNode, () => {
|
8813
8853
|
callResult = validateCallArguments(errorNode, functionArgs, { type: magicMethodType },
|
8814
8854
|
/* typeVarContext */ undefined,
|
8815
|
-
/* skipUnknownArgCheck */ true,
|
8855
|
+
/* skipUnknownArgCheck */ true, inferenceContext);
|
8816
8856
|
});
|
8817
8857
|
if (callResult.argumentErrors) {
|
8818
8858
|
magicMethodSupported = false;
|
@@ -8860,20 +8900,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8860
8900
|
}
|
8861
8901
|
return type;
|
8862
8902
|
}
|
8863
|
-
function getTypeOfDictionary(node,
|
8903
|
+
function getTypeOfDictionary(node, inferenceContext) {
|
8864
8904
|
// If the expected type is a union, analyze for each of the subtypes
|
8865
8905
|
// to find one that matches.
|
8866
|
-
let effectiveExpectedType = expectedType;
|
8867
|
-
if (
|
8906
|
+
let effectiveExpectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
|
8907
|
+
if (inferenceContext && (0, types_1.isUnion)(inferenceContext.expectedType)) {
|
8868
8908
|
let matchingSubtype;
|
8869
8909
|
let matchingSubtypeResult;
|
8870
|
-
(0, typeUtils_1.doForEachSubtype)(expectedType, (subtype) => {
|
8910
|
+
(0, typeUtils_1.doForEachSubtype)(inferenceContext.expectedType, (subtype) => {
|
8871
8911
|
// Use shortcut if we've already found a match.
|
8872
8912
|
if (matchingSubtypeResult && !matchingSubtypeResult.typeErrors) {
|
8873
8913
|
return;
|
8874
8914
|
}
|
8875
8915
|
const subtypeResult = useSpeculativeMode(node, () => {
|
8876
|
-
return
|
8916
|
+
return getTypeOfDictionaryWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext));
|
8877
8917
|
});
|
8878
8918
|
if (subtypeResult && assignType(subtype, subtypeResult.type)) {
|
8879
8919
|
// If this is the first result we're seeing or it's the first result
|
@@ -8889,28 +8929,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8889
8929
|
let expectedTypeDiagAddendum = undefined;
|
8890
8930
|
if (effectiveExpectedType) {
|
8891
8931
|
expectedTypeDiagAddendum = new diagnostic_1.DiagnosticAddendum();
|
8892
|
-
const result =
|
8932
|
+
const result = getTypeOfDictionaryWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext), expectedTypeDiagAddendum);
|
8893
8933
|
if (result) {
|
8894
8934
|
return result;
|
8895
8935
|
}
|
8896
8936
|
}
|
8897
|
-
const result = getTypeOfDictionaryInferred(node, /* hasExpectedType */ !!
|
8937
|
+
const result = getTypeOfDictionaryInferred(node, /* hasExpectedType */ !!inferenceContext);
|
8898
8938
|
return { ...result, expectedTypeDiagAddendum };
|
8899
8939
|
}
|
8900
|
-
|
8901
|
-
|
8902
|
-
|
8903
|
-
|
8904
|
-
expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expectedType);
|
8905
|
-
if (!(0, types_1.isClassInstance)(expectedType)) {
|
8940
|
+
function getTypeOfDictionaryWithContext(node, inferenceContext, expectedDiagAddendum) {
|
8941
|
+
inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
|
8942
|
+
const concreteExpectedType = makeTopLevelTypeVarsConcrete(inferenceContext.expectedType);
|
8943
|
+
if (!(0, types_1.isClassInstance)(concreteExpectedType)) {
|
8906
8944
|
return undefined;
|
8907
8945
|
}
|
8908
8946
|
const keyTypes = [];
|
8909
8947
|
const valueTypes = [];
|
8910
8948
|
let isIncomplete = false;
|
8911
8949
|
// Handle TypedDict's as a special case.
|
8912
|
-
if (types_1.ClassType.isTypedDictClass(
|
8913
|
-
const expectedTypedDictEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface,
|
8950
|
+
if (types_1.ClassType.isTypedDictClass(concreteExpectedType)) {
|
8951
|
+
const expectedTypedDictEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, concreteExpectedType);
|
8914
8952
|
// Infer the key and value types if possible.
|
8915
8953
|
if (getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
|
8916
8954
|
/* forceStrictInference */ true,
|
@@ -8918,8 +8956,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8918
8956
|
/* expectedValueType */ undefined, expectedTypedDictEntries, expectedDiagAddendum)) {
|
8919
8957
|
isIncomplete = true;
|
8920
8958
|
}
|
8921
|
-
if (types_1.ClassType.isTypedDictClass(
|
8922
|
-
const resultTypedDict = (0, typedDicts_1.assignToTypedDict)(evaluatorInterface,
|
8959
|
+
if (types_1.ClassType.isTypedDictClass(concreteExpectedType)) {
|
8960
|
+
const resultTypedDict = (0, typedDicts_1.assignToTypedDict)(evaluatorInterface, concreteExpectedType, keyTypes, valueTypes,
|
8923
8961
|
// Don't overwrite existing expectedDiagAddendum messages if they were
|
8924
8962
|
// already provided by getKeyValueTypesFromDictionary.
|
8925
8963
|
(expectedDiagAddendum === null || expectedDiagAddendum === void 0 ? void 0 : expectedDiagAddendum.isEmpty()) ? expectedDiagAddendum : undefined);
|
@@ -8937,7 +8975,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8937
8975
|
return undefined;
|
8938
8976
|
}
|
8939
8977
|
const dictTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(builtInDict));
|
8940
|
-
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInDict, expectedType, dictTypeVarContext, getTypeVarScopesForNode(node))) {
|
8978
|
+
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInDict, inferenceContext.expectedType, dictTypeVarContext, getTypeVarScopesForNode(node))) {
|
8941
8979
|
return undefined;
|
8942
8980
|
}
|
8943
8981
|
const specializedDict = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(builtInDict), dictTypeVarContext);
|
@@ -8954,8 +8992,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8954
8992
|
// Dict and MutableMapping types have invariant value types, so they
|
8955
8993
|
// cannot be narrowed further. Other super-types like Mapping, Collection,
|
8956
8994
|
// and Iterable use covariant value types, so they can be narrowed.
|
8957
|
-
const isValueTypeInvariant = (0, types_1.isClassInstance)(expectedType) &&
|
8958
|
-
(types_1.ClassType.isBuiltIn(expectedType, 'dict') ||
|
8995
|
+
const isValueTypeInvariant = (0, types_1.isClassInstance)(inferenceContext.expectedType) &&
|
8996
|
+
(types_1.ClassType.isBuiltIn(inferenceContext.expectedType, 'dict') ||
|
8997
|
+
types_1.ClassType.isBuiltIn(inferenceContext.expectedType, 'MutableMapping'));
|
8959
8998
|
const specializedKeyType = inferTypeArgFromExpectedType(expectedKeyType, keyTypes.map((result) => result.type),
|
8960
8999
|
/* isNarrowable */ false);
|
8961
9000
|
const specializedValueType = inferTypeArgFromExpectedType(expectedValueType, valueTypes.map((result) => result.type),
|
@@ -9019,7 +9058,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9019
9058
|
let addUnknown = true;
|
9020
9059
|
if (entryNode.nodeType === 17 /* DictionaryKeyEntry */) {
|
9021
9060
|
const keyTypeResult = getTypeOfExpression(entryNode.keyExpression,
|
9022
|
-
/* flags */ undefined, expectedKeyType !== null && expectedKeyType !== void 0 ? expectedKeyType : (forceStrictInference ? types_1.NeverType.createNever() : undefined));
|
9061
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedKeyType !== null && expectedKeyType !== void 0 ? expectedKeyType : (forceStrictInference ? types_1.NeverType.createNever() : undefined)));
|
9023
9062
|
if (keyTypeResult.isIncomplete) {
|
9024
9063
|
isIncomplete = true;
|
9025
9064
|
}
|
@@ -9033,12 +9072,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9033
9072
|
types_1.ClassType.isBuiltIn(keyType, 'str') &&
|
9034
9073
|
(0, typeUtils_1.isLiteralType)(keyType) &&
|
9035
9074
|
expectedTypedDictEntries.has(keyType.literalValue)) {
|
9075
|
+
const effectiveValueType = expectedTypedDictEntries.get(keyType.literalValue).valueType;
|
9036
9076
|
valueTypeResult = getTypeOfExpression(entryNode.valueExpression,
|
9037
|
-
/* flags */ undefined,
|
9077
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(effectiveValueType));
|
9038
9078
|
}
|
9039
9079
|
else {
|
9080
|
+
const effectiveValueType = expectedValueType !== null && expectedValueType !== void 0 ? expectedValueType : (forceStrictInference ? types_1.NeverType.createNever() : undefined);
|
9040
9081
|
valueTypeResult = getTypeOfExpression(entryNode.valueExpression,
|
9041
|
-
/* flags */ undefined,
|
9082
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(effectiveValueType));
|
9042
9083
|
}
|
9043
9084
|
if (expectedDiagAddendum && valueTypeResult.expectedTypeDiagAddendum) {
|
9044
9085
|
expectedDiagAddendum.addAddendum(valueTypeResult.expectedTypeDiagAddendum);
|
@@ -9136,20 +9177,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9136
9177
|
});
|
9137
9178
|
return isIncomplete;
|
9138
9179
|
}
|
9139
|
-
function getTypeOfListOrSet(node,
|
9180
|
+
function getTypeOfListOrSet(node, inferenceContext) {
|
9140
9181
|
// If the expected type is a union, recursively call for each of the subtypes
|
9141
9182
|
// to find one that matches.
|
9142
|
-
let effectiveExpectedType = expectedType;
|
9143
|
-
if (
|
9183
|
+
let effectiveExpectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
|
9184
|
+
if (inferenceContext && (0, types_1.isUnion)(inferenceContext.expectedType)) {
|
9144
9185
|
let matchingSubtype;
|
9145
9186
|
let matchingSubtypeResult;
|
9146
|
-
(0, typeUtils_1.doForEachSubtype)(expectedType, (subtype) => {
|
9187
|
+
(0, typeUtils_1.doForEachSubtype)(inferenceContext.expectedType, (subtype) => {
|
9147
9188
|
// Use shortcut if we've already found a match.
|
9148
9189
|
if (matchingSubtypeResult && !matchingSubtypeResult.typeErrors) {
|
9149
9190
|
return;
|
9150
9191
|
}
|
9151
9192
|
const subtypeResult = useSpeculativeMode(node, () => {
|
9152
|
-
return
|
9193
|
+
return getTypeOfListOrSetWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext));
|
9153
9194
|
});
|
9154
9195
|
if (subtypeResult && assignType(subtype, subtypeResult.type)) {
|
9155
9196
|
// If this is the first result we're seeing or it's the first result
|
@@ -9164,24 +9205,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9164
9205
|
}
|
9165
9206
|
let expectedTypeDiagAddendum;
|
9166
9207
|
if (effectiveExpectedType) {
|
9167
|
-
const result =
|
9208
|
+
const result = getTypeOfListOrSetWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext));
|
9168
9209
|
if (result && !result.typeErrors) {
|
9169
9210
|
return result;
|
9170
9211
|
}
|
9171
9212
|
expectedTypeDiagAddendum = result === null || result === void 0 ? void 0 : result.expectedTypeDiagAddendum;
|
9172
9213
|
}
|
9173
|
-
const typeResult = getTypeOfListOrSetInferred(node, /* hasExpectedType */
|
9214
|
+
const typeResult = getTypeOfListOrSetInferred(node, /* hasExpectedType */ inferenceContext !== undefined);
|
9174
9215
|
return { ...typeResult, expectedTypeDiagAddendum };
|
9175
9216
|
}
|
9176
9217
|
// Attempts to determine the type of a list or set statement based on an expected type.
|
9177
9218
|
// Returns undefined if that type cannot be honored.
|
9178
|
-
function
|
9219
|
+
function getTypeOfListOrSetWithContext(node, inferenceContext) {
|
9179
9220
|
const builtInClassName = node.nodeType === 31 /* List */ ? 'list' : 'set';
|
9180
|
-
expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expectedType);
|
9221
|
+
inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
|
9181
9222
|
let isIncomplete = false;
|
9182
9223
|
let typeErrors = false;
|
9183
9224
|
const verifyHashable = node.nodeType === 45 /* Set */;
|
9184
|
-
if (!(0, types_1.isClassInstance)(expectedType)) {
|
9225
|
+
if (!(0, types_1.isClassInstance)(inferenceContext.expectedType)) {
|
9185
9226
|
return undefined;
|
9186
9227
|
}
|
9187
9228
|
const builtInListOrSet = getBuiltInObject(node, builtInClassName);
|
@@ -9189,7 +9230,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9189
9230
|
return undefined;
|
9190
9231
|
}
|
9191
9232
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(builtInListOrSet));
|
9192
|
-
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInListOrSet, expectedType, typeVarContext, getTypeVarScopesForNode(node))) {
|
9233
|
+
if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, builtInListOrSet, inferenceContext.expectedType, typeVarContext, getTypeVarScopesForNode(node))) {
|
9193
9234
|
return undefined;
|
9194
9235
|
}
|
9195
9236
|
const specializedListOrSet = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(builtInListOrSet), typeVarContext);
|
@@ -9205,7 +9246,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9205
9246
|
entryTypeResult = getElementTypeFromListComprehension(entry, expectedEntryType);
|
9206
9247
|
}
|
9207
9248
|
else {
|
9208
|
-
entryTypeResult = getTypeOfExpression(entry,
|
9249
|
+
entryTypeResult = getTypeOfExpression(entry,
|
9250
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedEntryType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext));
|
9209
9251
|
}
|
9210
9252
|
entryTypes.push(entryTypeResult.type);
|
9211
9253
|
if (entryTypeResult.isIncomplete) {
|
@@ -9221,7 +9263,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9221
9263
|
verifySetEntryOrDictKeyIsHashable(entry, entryTypeResult.type, /* isDictKey */ false);
|
9222
9264
|
}
|
9223
9265
|
});
|
9224
|
-
const isExpectedTypeListOrSet = (0, types_1.isClassInstance)(expectedType) &&
|
9266
|
+
const isExpectedTypeListOrSet = (0, types_1.isClassInstance)(inferenceContext.expectedType) &&
|
9267
|
+
types_1.ClassType.isBuiltIn(inferenceContext.expectedType, builtInClassName);
|
9225
9268
|
const specializedEntryType = inferTypeArgFromExpectedType(expectedEntryType, entryTypes,
|
9226
9269
|
/* isNarrowable */ !isExpectedTypeListOrSet);
|
9227
9270
|
if (!specializedEntryType) {
|
@@ -9344,13 +9387,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9344
9387
|
}
|
9345
9388
|
return undefined;
|
9346
9389
|
}
|
9347
|
-
function getTypeOfTernary(node, flags,
|
9390
|
+
function getTypeOfTernary(node, flags, inferenceContext) {
|
9348
9391
|
getTypeOfExpression(node.testExpression);
|
9349
9392
|
const typesToCombine = [];
|
9350
9393
|
let isIncomplete = false;
|
9351
9394
|
let typeErrors = false;
|
9352
9395
|
if (isNodeReachable(node.ifExpression)) {
|
9353
|
-
const ifType = getTypeOfExpression(node.ifExpression, flags,
|
9396
|
+
const ifType = getTypeOfExpression(node.ifExpression, flags, inferenceContext);
|
9354
9397
|
typesToCombine.push(ifType.type);
|
9355
9398
|
if (ifType.isIncomplete) {
|
9356
9399
|
isIncomplete = true;
|
@@ -9360,7 +9403,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9360
9403
|
}
|
9361
9404
|
}
|
9362
9405
|
if (isNodeReachable(node.elseExpression)) {
|
9363
|
-
const elseType = getTypeOfExpression(node.elseExpression, flags,
|
9406
|
+
const elseType = getTypeOfExpression(node.elseExpression, flags, inferenceContext);
|
9364
9407
|
typesToCombine.push(elseType.type);
|
9365
9408
|
if (elseType.isIncomplete) {
|
9366
9409
|
isIncomplete = true;
|
@@ -9394,7 +9437,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9394
9437
|
}
|
9395
9438
|
}
|
9396
9439
|
if (node.expression) {
|
9397
|
-
const exprResult = getTypeOfExpression(node.expression,
|
9440
|
+
const exprResult = getTypeOfExpression(node.expression,
|
9441
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedYieldType));
|
9398
9442
|
if (exprResult.isIncomplete) {
|
9399
9443
|
isIncomplete = true;
|
9400
9444
|
}
|
@@ -9425,16 +9469,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9425
9469
|
}
|
9426
9470
|
return { type: returnedType || types_1.UnknownType.create() };
|
9427
9471
|
}
|
9428
|
-
function getTypeOfLambda(node,
|
9472
|
+
function getTypeOfLambda(node, inferenceContext) {
|
9429
9473
|
let isIncomplete = false;
|
9430
9474
|
const functionType = types_1.FunctionType.createInstance('', '', '', 131072 /* PartiallyEvaluated */);
|
9431
9475
|
functionType.details.typeVarScopeId = getScopeIdForNode(node);
|
9432
9476
|
// Pre-cache the incomplete function type in case the evaluation of the
|
9433
9477
|
// lambda depends on itself.
|
9434
|
-
writeTypeCache(node, functionType,
|
9478
|
+
writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /* None */);
|
9435
9479
|
let expectedFunctionTypes = [];
|
9436
|
-
if (
|
9437
|
-
(0, typeUtils_1.mapSubtypes)(expectedType, (subtype) => {
|
9480
|
+
if (inferenceContext) {
|
9481
|
+
(0, typeUtils_1.mapSubtypes)(inferenceContext.expectedType, (subtype) => {
|
9438
9482
|
if ((0, types_1.isFunction)(subtype)) {
|
9439
9483
|
expectedFunctionTypes.push(subtype);
|
9440
9484
|
}
|
@@ -9468,8 +9512,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9468
9512
|
paramType = types_1.FunctionType.getEffectiveParameterType(expectedFunctionType, index);
|
9469
9513
|
}
|
9470
9514
|
if (param.name) {
|
9471
|
-
writeTypeCache(param.name, transformVariadicParamType(node, param.category, paramType), 0 /* None
|
9472
|
-
/* isIncomplete */ false);
|
9515
|
+
writeTypeCache(param.name, { type: transformVariadicParamType(node, param.category, paramType) }, 0 /* None */);
|
9473
9516
|
}
|
9474
9517
|
if (param.defaultValue) {
|
9475
9518
|
// Evaluate the default value if it's present.
|
@@ -9525,13 +9568,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9525
9568
|
// evaluation scope for the return expression and do not allow retention
|
9526
9569
|
// of the cached types.
|
9527
9570
|
const inferLambdaReturnType = () => {
|
9528
|
-
const returnTypeResult = getTypeOfExpression(node.expression,
|
9571
|
+
const returnTypeResult = getTypeOfExpression(node.expression,
|
9572
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
|
9529
9573
|
functionType.inferredReturnType = returnTypeResult.type;
|
9530
9574
|
if (returnTypeResult.isIncomplete) {
|
9531
9575
|
isIncomplete = true;
|
9532
9576
|
}
|
9533
9577
|
};
|
9534
9578
|
if (speculativeTypeTracker.isSpeculative(node)) {
|
9579
|
+
// We need to set allowCacheRetention to false because we don't want to
|
9580
|
+
// cache the type of the lambda return expression because it depends on
|
9581
|
+
// the parameter types that we set above, and the speculative type cache
|
9582
|
+
// doesn't know about that context.
|
9535
9583
|
useSpeculativeMode(node.expression, () => {
|
9536
9584
|
inferLambdaReturnType();
|
9537
9585
|
},
|
@@ -9544,7 +9592,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9544
9592
|
functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
|
9545
9593
|
return { type: functionType, isIncomplete };
|
9546
9594
|
}
|
9547
|
-
function getTypeOfListComprehension(node,
|
9595
|
+
function getTypeOfListComprehension(node, inferenceContext) {
|
9548
9596
|
var _a;
|
9549
9597
|
let isIncomplete = false;
|
9550
9598
|
let typeErrors = false;
|
@@ -9558,8 +9606,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9558
9606
|
isAsync = true;
|
9559
9607
|
}
|
9560
9608
|
let expectedElementType;
|
9561
|
-
if (
|
9562
|
-
expectedElementType = (_a = getTypeOfIterator({ type: expectedType }, isAsync,
|
9609
|
+
if (inferenceContext) {
|
9610
|
+
expectedElementType = (_a = getTypeOfIterator({ type: inferenceContext.expectedType }, isAsync,
|
9611
|
+
/* errorNode */ undefined)) === null || _a === void 0 ? void 0 : _a.type;
|
9563
9612
|
}
|
9564
9613
|
const elementTypeResult = getElementTypeFromListComprehension(node, expectedElementType);
|
9565
9614
|
if (elementTypeResult.isIncomplete) {
|
@@ -9572,9 +9621,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9572
9621
|
// Handle the special case where a generator function (e.g. `(await x for x in y)`)
|
9573
9622
|
// is expected to be an AsyncGenerator.
|
9574
9623
|
if (!isAsync &&
|
9575
|
-
|
9576
|
-
(0, types_1.isClassInstance)(expectedType) &&
|
9577
|
-
types_1.ClassType.isBuiltIn(expectedType, 'AsyncGenerator')) {
|
9624
|
+
inferenceContext &&
|
9625
|
+
(0, types_1.isClassInstance)(inferenceContext.expectedType) &&
|
9626
|
+
types_1.ClassType.isBuiltIn(inferenceContext.expectedType, 'AsyncGenerator')) {
|
9578
9627
|
isAsync = true;
|
9579
9628
|
}
|
9580
9629
|
const builtInIteratorType = getTypingType(node, isAsync ? 'AsyncGenerator' : 'Generator');
|
@@ -9652,7 +9701,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9652
9701
|
if (node.expression.nodeType === 17 /* DictionaryKeyEntry */) {
|
9653
9702
|
// Create a tuple with the key/value types.
|
9654
9703
|
const keyTypeResult = getTypeOfExpression(node.expression.keyExpression,
|
9655
|
-
/* flags */ undefined, expectedKeyType);
|
9704
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedKeyType));
|
9656
9705
|
if (keyTypeResult.isIncomplete) {
|
9657
9706
|
isIncomplete = true;
|
9658
9707
|
}
|
@@ -9664,7 +9713,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9664
9713
|
keyType = stripLiteralValue(keyType);
|
9665
9714
|
}
|
9666
9715
|
const valueTypeResult = getTypeOfExpression(node.expression.valueExpression,
|
9667
|
-
/* flags */ undefined, expectedValueOrElementType);
|
9716
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
|
9668
9717
|
if (valueTypeResult.isIncomplete) {
|
9669
9718
|
isIncomplete = true;
|
9670
9719
|
}
|
@@ -9679,11 +9728,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9679
9728
|
}
|
9680
9729
|
else if (node.expression.nodeType === 16 /* DictionaryExpandEntry */) {
|
9681
9730
|
// The parser should have reported an error in this case because it's not allowed.
|
9682
|
-
getTypeOfExpression(node.expression.expandExpression,
|
9731
|
+
getTypeOfExpression(node.expression.expandExpression,
|
9732
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
|
9683
9733
|
}
|
9684
9734
|
else if ((0, parseNodes_1.isExpressionNode)(node)) {
|
9685
9735
|
const exprTypeResult = getTypeOfExpression(node.expression,
|
9686
|
-
/* flags */ undefined, expectedValueOrElementType);
|
9736
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
|
9687
9737
|
if (exprTypeResult.isIncomplete) {
|
9688
9738
|
isIncomplete = true;
|
9689
9739
|
}
|
@@ -9885,7 +9935,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9885
9935
|
// If no type arguments are provided, the resulting type
|
9886
9936
|
// depends on whether we're evaluating a type annotation or
|
9887
9937
|
// we're in some other context.
|
9888
|
-
if ((flags &
|
9938
|
+
if ((flags & 256 /* ExpectingTypeAnnotation */) !== 0) {
|
9889
9939
|
addError(localize_1.Localizer.Diagnostic.optionalExtraArgs(), errorNode);
|
9890
9940
|
return types_1.UnknownType.create();
|
9891
9941
|
}
|
@@ -10009,7 +10059,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10009
10059
|
// Creates a ClassVar type.
|
10010
10060
|
function createClassVarType(classType, errorNode, typeArgs, flags) {
|
10011
10061
|
var _a;
|
10012
|
-
if (flags & 131072 /*
|
10062
|
+
if (flags & 131072 /* DisallowClassVar */) {
|
10013
10063
|
addError(localize_1.Localizer.Diagnostic.classVarNotAllowed(), errorNode);
|
10014
10064
|
return types_1.AnyType.create();
|
10015
10065
|
}
|
@@ -10042,7 +10092,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10042
10092
|
// depends on whether we're evaluating a type annotation or
|
10043
10093
|
// we're in some other context.
|
10044
10094
|
if (!typeArgs) {
|
10045
|
-
if ((flags &
|
10095
|
+
if ((flags & 256 /* ExpectingTypeAnnotation */) !== 0) {
|
10046
10096
|
addError(localize_1.Localizer.Diagnostic.typeGuardArgCount(), errorNode);
|
10047
10097
|
}
|
10048
10098
|
return classType;
|
@@ -10103,7 +10153,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10103
10153
|
// If no type arguments are provided, the resulting type
|
10104
10154
|
// depends on whether we're evaluating a type annotation or
|
10105
10155
|
// we're in some other context.
|
10106
|
-
if (!typeArgs && (flags &
|
10156
|
+
if (!typeArgs && (flags & 256 /* ExpectingTypeAnnotation */) === 0) {
|
10107
10157
|
return classType;
|
10108
10158
|
}
|
10109
10159
|
if (!typeArgs || typeArgs.length !== 1) {
|
@@ -10124,7 +10174,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10124
10174
|
isUsageLegal = true;
|
10125
10175
|
}
|
10126
10176
|
}
|
10127
|
-
if ((flags & 1048576 /*
|
10177
|
+
if ((flags & 1048576 /* AllowRequired */) !== 0) {
|
10128
10178
|
isUsageLegal = true;
|
10129
10179
|
}
|
10130
10180
|
if (!isUsageLegal) {
|
@@ -10139,7 +10189,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10139
10189
|
// If no type arguments are provided, the resulting type
|
10140
10190
|
// depends on whether we're evaluating a type annotation or
|
10141
10191
|
// we're in some other context.
|
10142
|
-
if (!typeArgs && (flags &
|
10192
|
+
if (!typeArgs && (flags & 256 /* ExpectingTypeAnnotation */) === 0) {
|
10143
10193
|
return classType;
|
10144
10194
|
}
|
10145
10195
|
if (!typeArgs || typeArgs.length !== 1) {
|
@@ -10173,7 +10223,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10173
10223
|
}
|
10174
10224
|
// Creates a "Final" type.
|
10175
10225
|
function createFinalType(classType, errorNode, typeArgs, flags) {
|
10176
|
-
if (flags & 16 /*
|
10226
|
+
if (flags & 16 /* DisallowFinal */) {
|
10177
10227
|
addError(localize_1.Localizer.Diagnostic.finalContext(), errorNode);
|
10178
10228
|
return types_1.AnyType.create();
|
10179
10229
|
}
|
@@ -10330,7 +10380,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10330
10380
|
// If no type arguments are provided, the resulting type
|
10331
10381
|
// depends on whether we're evaluating a type annotation or
|
10332
10382
|
// we're in some other context.
|
10333
|
-
if ((flags &
|
10383
|
+
if ((flags & 256 /* ExpectingTypeAnnotation */) !== 0) {
|
10334
10384
|
addError(localize_1.Localizer.Diagnostic.unionTypeArgCount(), errorNode);
|
10335
10385
|
return types_1.NeverType.createNever();
|
10336
10386
|
}
|
@@ -10381,7 +10431,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10381
10431
|
// If no type arguments are provided, the resulting type
|
10382
10432
|
// depends on whether we're evaluating a type annotation or
|
10383
10433
|
// we're in some other context.
|
10384
|
-
if ((flags & (
|
10434
|
+
if ((flags & (256 /* ExpectingTypeAnnotation */ | 262144 /* DisallowNakedGeneric */)) !== 0) {
|
10385
10435
|
addError(localize_1.Localizer.Diagnostic.genericTypeArgMissing(), errorNode);
|
10386
10436
|
}
|
10387
10437
|
return classType;
|
@@ -10559,7 +10609,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10559
10609
|
specialType.details.baseClasses.push(strClassType !== null && strClassType !== void 0 ? strClassType : types_1.AnyType.create());
|
10560
10610
|
(0, typeUtils_1.computeMroLinearization)(specialType);
|
10561
10611
|
}
|
10562
|
-
writeTypeCache(node, specialType, 0 /* None
|
10612
|
+
writeTypeCache(node, { type: specialType }, 0 /* None */);
|
10563
10613
|
return specialType;
|
10564
10614
|
}
|
10565
10615
|
return undefined;
|
@@ -10611,7 +10661,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10611
10661
|
let flags = 0 /* None */;
|
10612
10662
|
if (fileInfo.isStubFile) {
|
10613
10663
|
// An assignment of ellipsis means "Any" within a type stub file.
|
10614
|
-
flags |=
|
10664
|
+
flags |= 512 /* ConvertEllipsisToUnknown */;
|
10615
10665
|
}
|
10616
10666
|
if (node.rightExpression.nodeType === 38 /* Name */ ||
|
10617
10667
|
node.rightExpression.nodeType === 35 /* MemberAccess */) {
|
@@ -10622,11 +10672,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10622
10672
|
}
|
10623
10673
|
if (isDeclaredTypeAlias(node.leftExpression)) {
|
10624
10674
|
flags |=
|
10625
|
-
|
10675
|
+
128 /* ExpectingType */ |
|
10626
10676
|
8 /* EvaluateStringLiteralAsType */ |
|
10627
|
-
32 /*
|
10628
|
-
|
10629
|
-
131072 /*
|
10677
|
+
32 /* DisallowParamSpec */ |
|
10678
|
+
64 /* DisallowTypeVarTuple */ |
|
10679
|
+
131072 /* DisallowClassVar */;
|
10630
10680
|
flags &= ~2 /* DoNotSpecialize */;
|
10631
10681
|
}
|
10632
10682
|
// Is this type already cached?
|
@@ -10639,7 +10689,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10639
10689
|
if (fileInfo.isTypingStubFile || fileInfo.isTypingExtensionsStubFile) {
|
10640
10690
|
rightHandType = handleTypingStubAssignment(node);
|
10641
10691
|
if (rightHandType) {
|
10642
|
-
writeTypeCache(node.rightExpression, rightHandType, 0 /* None
|
10692
|
+
writeTypeCache(node.rightExpression, { type: rightHandType }, 0 /* None */);
|
10643
10693
|
}
|
10644
10694
|
}
|
10645
10695
|
if (!rightHandType) {
|
@@ -10677,17 +10727,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10677
10727
|
typeAliasTypeVar.details.recursiveTypeAliasScopeId = scopeId;
|
10678
10728
|
typeAliasTypeVar.scopeId = scopeId;
|
10679
10729
|
// 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);
|
10730
|
+
writeTypeCache(node, { type: typeAliasTypeVar }, /* flags */ undefined);
|
10731
|
+
writeTypeCache(node.leftExpression, { type: typeAliasTypeVar }, /* flags */ undefined);
|
10684
10732
|
if (node.leftExpression.nodeType === 54 /* TypeAnnotation */) {
|
10685
|
-
writeTypeCache(node.leftExpression.valueExpression, typeAliasTypeVar,
|
10686
|
-
/* flags */ undefined
|
10687
|
-
/* isIncomplete */ false);
|
10733
|
+
writeTypeCache(node.leftExpression.valueExpression, { type: typeAliasTypeVar },
|
10734
|
+
/* flags */ undefined);
|
10688
10735
|
}
|
10689
10736
|
}
|
10690
|
-
const srcTypeResult = getTypeOfExpression(node.rightExpression, flags, declaredType);
|
10737
|
+
const srcTypeResult = getTypeOfExpression(node.rightExpression, flags, (0, typeUtils_1.makeInferenceContext)(declaredType));
|
10691
10738
|
let srcType = srcTypeResult.type;
|
10692
10739
|
expectedTypeDiagAddendum = srcTypeResult.expectedTypeDiagAddendum;
|
10693
10740
|
if (srcTypeResult.isIncomplete) {
|
@@ -10717,12 +10764,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10717
10764
|
(0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node.leftExpression, () => rightHandType) || rightHandType;
|
10718
10765
|
}
|
10719
10766
|
if (typeAliasNameNode) {
|
10720
|
-
// Clear out the temporary types we wrote above.
|
10721
|
-
deleteTypeCacheEntry(node);
|
10722
|
-
deleteTypeCacheEntry(node.leftExpression);
|
10723
|
-
if (node.leftExpression.nodeType === 54 /* TypeAnnotation */) {
|
10724
|
-
deleteTypeCacheEntry(node.leftExpression.valueExpression);
|
10725
|
-
}
|
10726
10767
|
// If this was a speculative type alias, it becomes a real type alias
|
10727
10768
|
// only if the evaluated type is an instantiable type.
|
10728
10769
|
if (!isSpeculativeTypeAlias ||
|
@@ -10753,7 +10794,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10753
10794
|
assignTypeToExpression(node.leftExpression, rightHandType, isIncomplete, node.rightExpression,
|
10754
10795
|
/* ignoreEmptyContainers */ true,
|
10755
10796
|
/* allowAssignmentToFinalVar */ true, expectedTypeDiagAddendum);
|
10756
|
-
writeTypeCache(node, rightHandType, 0 /* None
|
10797
|
+
writeTypeCache(node, { type: rightHandType, isIncomplete }, 0 /* None */);
|
10757
10798
|
}
|
10758
10799
|
function isPossibleTypeAliasOrTypedDict(decl) {
|
10759
10800
|
var _a;
|
@@ -10800,7 +10841,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10800
10841
|
typeAliasTypeVar.details.recursiveTypeAliasScopeId = scopeId;
|
10801
10842
|
typeAliasTypeVar.scopeId = scopeId;
|
10802
10843
|
// Write the type to the type cache. It will be replaced below.
|
10803
|
-
writeTypeCache(node.name, typeAliasTypeVar, /* flags */ undefined
|
10844
|
+
writeTypeCache(node.name, { type: typeAliasTypeVar }, /* flags */ undefined);
|
10804
10845
|
// Set a partial type to handle recursive (self-referential) type aliases.
|
10805
10846
|
const scope = ScopeUtils.getScopeForNode(node);
|
10806
10847
|
const typeAliasSymbol = scope === null || scope === void 0 ? void 0 : scope.lookUpSymbolRecursive(node.name.value);
|
@@ -10822,8 +10863,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10822
10863
|
if (aliasTypeResult.isIncomplete) {
|
10823
10864
|
isIncomplete = true;
|
10824
10865
|
}
|
10825
|
-
// Clear the temporary type we wrote above.
|
10826
|
-
deleteTypeCacheEntry(node.name);
|
10827
10866
|
aliasType = transformTypeForTypeAlias(aliasType, node.name, node.expression, typeParameters, (_a = node.typeParameters) === null || _a === void 0 ? void 0 : _a.parameters);
|
10828
10867
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, aliasType)) {
|
10829
10868
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIsRecursiveDirect().format({
|
@@ -10839,15 +10878,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10839
10878
|
name: node.name.value,
|
10840
10879
|
}), node.name);
|
10841
10880
|
}
|
10842
|
-
writeTypeCache(node.name, aliasType, 0 /* None
|
10881
|
+
writeTypeCache(node.name, { type: aliasType, isIncomplete }, 0 /* None */);
|
10843
10882
|
return aliasType;
|
10844
10883
|
}
|
10845
10884
|
function evaluateTypesForAugmentedAssignment(node) {
|
10846
10885
|
if (readTypeCache(node, 0 /* None */)) {
|
10847
10886
|
return;
|
10848
10887
|
}
|
10849
|
-
const destTypeResult = getTypeOfAugmentedAssignment(node, /*
|
10850
|
-
writeTypeCache(node, destTypeResult
|
10888
|
+
const destTypeResult = getTypeOfAugmentedAssignment(node, /* inferenceContext */ undefined);
|
10889
|
+
writeTypeCache(node, destTypeResult, 0 /* None */);
|
10851
10890
|
}
|
10852
10891
|
function getPseudoGenericTypeVarName(paramName) {
|
10853
10892
|
return `__type_of_${paramName}`;
|
@@ -10906,8 +10945,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10906
10945
|
setSymbolResolutionPartialType(classSymbol, classDecl, classType);
|
10907
10946
|
}
|
10908
10947
|
classType.details.flags |= 131072 /* PartiallyEvaluated */;
|
10909
|
-
writeTypeCache(node, classType, /* flags */ undefined
|
10910
|
-
writeTypeCache(node.name, classType, /* flags */ undefined
|
10948
|
+
writeTypeCache(node, { type: classType }, /* flags */ undefined);
|
10949
|
+
writeTypeCache(node.name, { type: classType }, /* flags */ undefined);
|
10911
10950
|
// Keep a list of unique type parameters that are used in the
|
10912
10951
|
// base class arguments.
|
10913
10952
|
let typeParameters = [];
|
@@ -10920,8 +10959,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10920
10959
|
let protocolTypeParameters;
|
10921
10960
|
const initSubclassArgs = [];
|
10922
10961
|
let metaclassNode;
|
10923
|
-
let exprFlags =
|
10924
|
-
|
10962
|
+
let exprFlags = 128 /* ExpectingType */ |
|
10963
|
+
1024 /* AllowGenericClassType */ |
|
10925
10964
|
262144 /* DisallowNakedGeneric */ |
|
10926
10965
|
2048 /* DisallowTypeVarsWithScopeId */ |
|
10927
10966
|
8192 /* AssociateTypeVarsWithCurrentScope */ |
|
@@ -11330,9 +11369,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11330
11369
|
}
|
11331
11370
|
}
|
11332
11371
|
// Update the undecorated class type.
|
11333
|
-
writeTypeCache(node.name, classType, 0 /* None
|
11372
|
+
writeTypeCache(node.name, { type: classType }, 0 /* None */);
|
11334
11373
|
// Update the decorated class type.
|
11335
|
-
writeTypeCache(node, decoratedType, 0 /* None
|
11374
|
+
writeTypeCache(node, { type: decoratedType }, 0 /* None */);
|
11336
11375
|
// Stash away a reference to the UnionType class if we encounter it.
|
11337
11376
|
// There's no easy way to otherwise reference it.
|
11338
11377
|
if (types_1.ClassType.isBuiltIn(classType, 'UnionType')) {
|
@@ -11345,7 +11384,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11345
11384
|
// parameters and updates the scope of the type parameter referred to in the
|
11346
11385
|
// default type expression.
|
11347
11386
|
function validateTypeParameterDefault(errorNode, typeParam, otherLiveTypeParams) {
|
11348
|
-
if (!typeParam.details.defaultType
|
11387
|
+
if (!typeParam.details.defaultType &&
|
11388
|
+
!typeParam.details.isSynthesized &&
|
11389
|
+
!typeParam.details.isSynthesizedSelf) {
|
11349
11390
|
const typeVarWithDefault = otherLiveTypeParams.find((param) => param.details.defaultType);
|
11350
11391
|
if (typeVarWithDefault) {
|
11351
11392
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarWithoutDefault().format({
|
@@ -11444,7 +11485,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11444
11485
|
if (!typeOfParam || !(0, types_1.isTypeVar)(typeOfParam)) {
|
11445
11486
|
return;
|
11446
11487
|
}
|
11447
|
-
writeTypeCache(param.name, typeOfParam, 0 /* None
|
11488
|
+
writeTypeCache(param.name, { type: typeOfParam }, 0 /* None */);
|
11448
11489
|
paramTypes.push(typeOfParam);
|
11449
11490
|
});
|
11450
11491
|
return paramTypes;
|
@@ -11526,6 +11567,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11526
11567
|
originalClassType.details.classDataClassTransform = (0, dataClasses_1.validateDataClassTransformDecorator)(evaluatorInterface, decoratorNode.expression);
|
11527
11568
|
}
|
11528
11569
|
}
|
11570
|
+
if ((0, types_1.isOverloadedFunction)(decoratorCallType)) {
|
11571
|
+
if (decoratorCallType.overloads.length > 0 &&
|
11572
|
+
decoratorCallType.overloads[0].details.builtInName === 'deprecated') {
|
11573
|
+
originalClassType.details.deprecatedMessage = getCustomDeprecationMessage(decoratorNode);
|
11574
|
+
return inputClassType;
|
11575
|
+
}
|
11576
|
+
}
|
11529
11577
|
}
|
11530
11578
|
if ((0, types_1.isOverloadedFunction)(decoratorType)) {
|
11531
11579
|
const dataclassBehaviors = (0, dataClasses_1.getDataclassDecoratorBehaviors)(decoratorType);
|
@@ -11534,6 +11582,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11534
11582
|
/* callNode */ undefined);
|
11535
11583
|
return inputClassType;
|
11536
11584
|
}
|
11585
|
+
if (decoratorType.overloads.length > 0 && decoratorType.overloads[0].details.builtInName === 'deprecated') {
|
11586
|
+
originalClassType.details.deprecatedMessage = getCustomDeprecationMessage(decoratorNode);
|
11587
|
+
return inputClassType;
|
11588
|
+
}
|
11537
11589
|
}
|
11538
11590
|
else if ((0, types_1.isFunction)(decoratorType)) {
|
11539
11591
|
if (decoratorType.details.builtInName === 'final') {
|
@@ -11543,7 +11595,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11543
11595
|
// dependency between builtins, typing and _typeshed stubs.
|
11544
11596
|
return inputClassType;
|
11545
11597
|
}
|
11546
|
-
|
11598
|
+
if (decoratorType.details.builtInName === 'runtime_checkable') {
|
11547
11599
|
originalClassType.details.flags |= 32768 /* RuntimeCheckable */;
|
11548
11600
|
// Don't call getTypeOfDecorator for runtime_checkable. It appears
|
11549
11601
|
// frequently in stubs, and it's a waste of time to validate its
|
@@ -11569,6 +11621,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11569
11621
|
}
|
11570
11622
|
return getTypeOfDecorator(decoratorNode, inputClassType);
|
11571
11623
|
}
|
11624
|
+
// Given a @typing.deprecated decorator node, returns either '' or a custom
|
11625
|
+
// deprecation message if one is provided.
|
11626
|
+
function getCustomDeprecationMessage(decorator) {
|
11627
|
+
if (decorator.expression.nodeType === 9 /* Call */ &&
|
11628
|
+
decorator.expression.arguments.length > 0 &&
|
11629
|
+
decorator.expression.arguments[0].argumentCategory === 0 /* Simple */ &&
|
11630
|
+
decorator.expression.arguments[0].valueExpression.nodeType === 48 /* StringList */ &&
|
11631
|
+
decorator.expression.arguments[0].valueExpression.strings.length === 1) {
|
11632
|
+
return decorator.expression.arguments[0].valueExpression.strings[0].value;
|
11633
|
+
}
|
11634
|
+
return '';
|
11635
|
+
}
|
11572
11636
|
// Runs any registered "callback hooks" that depend on the specified class type.
|
11573
11637
|
// This allows us to complete any work that requires dependent classes to be
|
11574
11638
|
// completed.
|
@@ -11603,7 +11667,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11603
11667
|
if (initSubclassMethodType) {
|
11604
11668
|
validateCallArguments(errorNode, argList, { type: initSubclassMethodType },
|
11605
11669
|
/* typeVarContext */ undefined,
|
11606
|
-
/* skipUnknownArgCheck */ false, types_1.NoneType.createInstance());
|
11670
|
+
/* skipUnknownArgCheck */ false, (0, typeUtils_1.makeInferenceContext)(types_1.NoneType.createInstance()));
|
11607
11671
|
}
|
11608
11672
|
}
|
11609
11673
|
else if (classType.details.effectiveMetaclass && (0, types_1.isClass)(classType.details.effectiveMetaclass)) {
|
@@ -11743,8 +11807,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11743
11807
|
if (functionDecl && functionSymbol) {
|
11744
11808
|
setSymbolResolutionPartialType(functionSymbol.symbol, functionDecl, functionType);
|
11745
11809
|
}
|
11746
|
-
writeTypeCache(node, functionType, /* flags */ undefined
|
11747
|
-
writeTypeCache(node.name, functionType, /* flags */ undefined
|
11810
|
+
writeTypeCache(node, { type: functionType }, /* flags */ undefined);
|
11811
|
+
writeTypeCache(node.name, { type: functionType }, /* flags */ undefined);
|
11748
11812
|
// Is this an "__init__" method within a pseudo-generic class? If so,
|
11749
11813
|
// we'll add generic types to the constructor's parameters.
|
11750
11814
|
const addGenericParamTypes = containingClassType &&
|
@@ -11853,7 +11917,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11853
11917
|
}
|
11854
11918
|
let defaultValueType;
|
11855
11919
|
if (param.defaultValue) {
|
11856
|
-
defaultValueType = getTypeOfExpression(param.defaultValue, 1 /* ConvertEllipsisToAny */, annotatedType).type;
|
11920
|
+
defaultValueType = getTypeOfExpression(param.defaultValue, 1 /* ConvertEllipsisToAny */, (0, typeUtils_1.makeInferenceContext)(annotatedType)).type;
|
11857
11921
|
}
|
11858
11922
|
if (annotatedType) {
|
11859
11923
|
// If there was both a type annotation and a default value, verify
|
@@ -11954,7 +12018,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11954
12018
|
if ((0, types_1.isUnknown)(paramType)) {
|
11955
12019
|
functionType.details.flags |= 16384 /* UnannotatedParams */;
|
11956
12020
|
}
|
11957
|
-
writeTypeCache(paramNameNode, paramType, 0 /* None
|
12021
|
+
writeTypeCache(paramNameNode, { type: paramType }, 0 /* None */);
|
11958
12022
|
}
|
11959
12023
|
});
|
11960
12024
|
// If the function ends in P.args and P.kwargs parameters, make it exempt from
|
@@ -12059,8 +12123,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12059
12123
|
}
|
12060
12124
|
decoratedType = addOverloadsToFunctionType(node, decoratedType);
|
12061
12125
|
}
|
12062
|
-
writeTypeCache(node.name, functionType, 0 /* None
|
12063
|
-
writeTypeCache(node, decoratedType, 0 /* None
|
12126
|
+
writeTypeCache(node.name, { type: functionType }, 0 /* None */);
|
12127
|
+
writeTypeCache(node, { type: decoratedType }, 0 /* None */);
|
12064
12128
|
return { functionType, decoratedType };
|
12065
12129
|
}
|
12066
12130
|
// If the declared return type of a function contains type variables that
|
@@ -12111,7 +12175,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12111
12175
|
// parameter is annotated with a "raw" function-scoped type variable, as in:
|
12112
12176
|
// "def foo(value: T = 3)"
|
12113
12177
|
// In this case, we need to include the default value type in a union.
|
12114
|
-
const defaultArgType = getTypeOfExpression(param.defaultValue, 1 /* ConvertEllipsisToAny */, type).type;
|
12178
|
+
const defaultArgType = getTypeOfExpression(param.defaultValue, 1 /* ConvertEllipsisToAny */, (0, typeUtils_1.makeInferenceContext)(type)).type;
|
12115
12179
|
if (!(0, types_1.isAny)(defaultArgType)) {
|
12116
12180
|
type = (0, types_1.combineTypes)([type, defaultArgType]);
|
12117
12181
|
}
|
@@ -12311,6 +12375,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12311
12375
|
return inputFunctionType;
|
12312
12376
|
}
|
12313
12377
|
}
|
12378
|
+
if ((0, types_1.isOverloadedFunction)(decoratorCallType)) {
|
12379
|
+
if (decoratorCallType.overloads.length > 0 &&
|
12380
|
+
decoratorCallType.overloads[0].details.builtInName === 'deprecated') {
|
12381
|
+
undecoratedType.details.deprecatedMessage = getCustomDeprecationMessage(decoratorNode);
|
12382
|
+
return inputFunctionType;
|
12383
|
+
}
|
12384
|
+
}
|
12314
12385
|
}
|
12315
12386
|
let returnType = getTypeOfDecorator(decoratorNode, inputFunctionType);
|
12316
12387
|
// Check for some built-in decorator types with known semantics.
|
@@ -12344,6 +12415,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12344
12415
|
}
|
12345
12416
|
}
|
12346
12417
|
}
|
12418
|
+
else if ((0, types_1.isOverloadedFunction)(decoratorType)) {
|
12419
|
+
if (decoratorType.overloads.length > 0 && decoratorType.overloads[0].details.builtInName === 'deprecated') {
|
12420
|
+
undecoratedType.details.deprecatedMessage = getCustomDeprecationMessage(decoratorNode);
|
12421
|
+
return inputFunctionType;
|
12422
|
+
}
|
12423
|
+
}
|
12347
12424
|
else if ((0, types_1.isInstantiableClass)(decoratorType)) {
|
12348
12425
|
if (types_1.ClassType.isBuiltIn(decoratorType)) {
|
12349
12426
|
switch (decoratorType.details.name) {
|
@@ -12640,7 +12717,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12640
12717
|
}
|
12641
12718
|
}
|
12642
12719
|
}
|
12643
|
-
writeTypeCache(node.suite, inferredReturnType, 0 /* None
|
12720
|
+
writeTypeCache(node.suite, { type: inferredReturnType, isIncomplete }, 0 /* None */);
|
12644
12721
|
}
|
12645
12722
|
finally {
|
12646
12723
|
functionRecursionMap.delete(node.id);
|
@@ -12683,7 +12760,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12683
12760
|
const iteratorTypeResult = getTypeOfExpression(node.iterableExpression);
|
12684
12761
|
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
12762
|
assignTypeToExpression(node.targetExpression, iteratedType, !!iteratorTypeResult.isIncomplete, node.targetExpression);
|
12686
|
-
writeTypeCache(node, iteratedType, 0 /* None
|
12763
|
+
writeTypeCache(node, { type: iteratedType, isIncomplete: !!iteratorTypeResult.isIncomplete }, 0 /* None */);
|
12687
12764
|
}
|
12688
12765
|
function evaluateTypesForExceptStatement(node) {
|
12689
12766
|
// This should be called only if the except node has a target exception.
|
@@ -12733,7 +12810,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12733
12810
|
if (node.name) {
|
12734
12811
|
assignTypeToExpression(node.name, targetType, /* isIncomplete */ false, node.name);
|
12735
12812
|
}
|
12736
|
-
writeTypeCache(node, targetType, 0 /* None
|
12813
|
+
writeTypeCache(node, { type: targetType }, 0 /* None */);
|
12737
12814
|
}
|
12738
12815
|
function evaluateTypesForWithStatement(node) {
|
12739
12816
|
if (readTypeCache(node, 0 /* None */)) {
|
@@ -12757,7 +12834,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12757
12834
|
const additionalHelp = new diagnostic_1.DiagnosticAddendum();
|
12758
12835
|
if ((0, types_1.isClass)(subtype)) {
|
12759
12836
|
let enterType = getTypeOfMagicMethodReturn(subtype, [], enterMethodName, node.expression,
|
12760
|
-
/*
|
12837
|
+
/* inferenceContext */ undefined);
|
12761
12838
|
if (enterType) {
|
12762
12839
|
// For "async while", an implicit "await" is performed.
|
12763
12840
|
if (isAsync) {
|
@@ -12767,7 +12844,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12767
12844
|
}
|
12768
12845
|
if (!isAsync) {
|
12769
12846
|
if (getTypeOfMagicMethodReturn(subtype, [], '__aenter__', node.expression,
|
12770
|
-
/*
|
12847
|
+
/* inferenceContext */ undefined)) {
|
12771
12848
|
additionalHelp.addMessage(localize_1.Localizer.DiagnosticAddendum.asyncHelp());
|
12772
12849
|
}
|
12773
12850
|
}
|
@@ -12787,7 +12864,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12787
12864
|
if ((0, types_1.isClass)(subtype)) {
|
12788
12865
|
const anyArg = { type: types_1.AnyType.create() };
|
12789
12866
|
const exitType = getTypeOfMagicMethodReturn(subtype, [anyArg, anyArg, anyArg], exitMethodName, node.expression,
|
12790
|
-
/*
|
12867
|
+
/* inferenceContext */ undefined);
|
12791
12868
|
if (exitType) {
|
12792
12869
|
return;
|
12793
12870
|
}
|
@@ -12798,7 +12875,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12798
12875
|
if (node.target) {
|
12799
12876
|
assignTypeToExpression(node.target, scopedType, !!exprTypeResult.isIncomplete, node.target);
|
12800
12877
|
}
|
12801
|
-
writeTypeCache(node, scopedType, 0 /* None
|
12878
|
+
writeTypeCache(node, { type: scopedType, isIncomplete: !!exprTypeResult.isIncomplete }, 0 /* None */);
|
12802
12879
|
}
|
12803
12880
|
function evaluateTypesForImportAs(node) {
|
12804
12881
|
var _a;
|
@@ -12830,7 +12907,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12830
12907
|
}
|
12831
12908
|
}
|
12832
12909
|
assignTypeToNameNode(symbolNameNode, symbolType, /* isIncomplete */ false, /* ignoreEmptyContainers */ false);
|
12833
|
-
writeTypeCache(node, symbolType, 0 /* None
|
12910
|
+
writeTypeCache(node, { type: symbolType }, 0 /* None */);
|
12834
12911
|
}
|
12835
12912
|
function evaluateTypesForImportFromAs(node) {
|
12836
12913
|
var _a;
|
@@ -12887,7 +12964,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12887
12964
|
}
|
12888
12965
|
}
|
12889
12966
|
assignTypeToNameNode(aliasNode, symbolType, /* isIncomplete */ false, /* ignoreEmptyContainers */ false);
|
12890
|
-
writeTypeCache(node, symbolType, 0 /* None
|
12967
|
+
writeTypeCache(node, { type: symbolType }, 0 /* None */);
|
12891
12968
|
}
|
12892
12969
|
function evaluateTypesForMatchStatement(node) {
|
12893
12970
|
if (readTypeCache(node, 0 /* None */)) {
|
@@ -12902,7 +12979,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12902
12979
|
/* isPositiveTest */ false);
|
12903
12980
|
}
|
12904
12981
|
}
|
12905
|
-
writeTypeCache(node, subjectType, 0 /* None
|
12982
|
+
writeTypeCache(node, { type: subjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* None */);
|
12906
12983
|
}
|
12907
12984
|
function evaluateTypesForCaseStatement(node) {
|
12908
12985
|
if (readTypeCache(node, 0 /* None */)) {
|
@@ -12936,7 +13013,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12936
13013
|
subjectType = (0, patternMatching_1.narrowTypeBasedOnPattern)(evaluatorInterface, subjectType, node.pattern,
|
12937
13014
|
/* isPositiveTest */ true);
|
12938
13015
|
(0, patternMatching_1.assignTypeToPatternTargets)(evaluatorInterface, subjectType, !!subjectTypeResult.isIncomplete, subjectIsObject, node.pattern);
|
12939
|
-
writeTypeCache(node, subjectType, 0 /* None
|
13016
|
+
writeTypeCache(node, { type: subjectType, isIncomplete: !!subjectTypeResult.isIncomplete }, 0 /* None */);
|
12940
13017
|
}
|
12941
13018
|
function evaluateTypesForImportFrom(node) {
|
12942
13019
|
if (readTypeCache(node, 0 /* None */)) {
|
@@ -12958,7 +13035,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12958
13035
|
}
|
12959
13036
|
}
|
12960
13037
|
assignTypeToNameNode(symbolNameNode, symbolType, /* isIncomplete */ false, /* ignoreEmptyContainers */ false);
|
12961
|
-
writeTypeCache(node, symbolType, 0 /* None
|
13038
|
+
writeTypeCache(node, { type: symbolType }, 0 /* None */);
|
12962
13039
|
}
|
12963
13040
|
function evaluateTypesForTypeAnnotationNode(node) {
|
12964
13041
|
var _a;
|
@@ -12974,7 +13051,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12974
13051
|
allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(node.valueExpression),
|
12975
13052
|
allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(node.valueExpression),
|
12976
13053
|
});
|
12977
|
-
writeTypeCache(node.valueExpression, annotationType, 0 /* None
|
13054
|
+
writeTypeCache(node.valueExpression, { type: annotationType }, 0 /* None */);
|
12978
13055
|
}
|
12979
13056
|
}
|
12980
13057
|
function getAliasedSymbolTypeForName(node, name) {
|
@@ -13171,18 +13248,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13171
13248
|
nodeToEvaluate = parent;
|
13172
13249
|
continue;
|
13173
13250
|
}
|
13174
|
-
else {
|
13175
|
-
// Check for expression types that are always contextual.
|
13176
|
-
if (nodeToEvaluate.nodeType !== 15 /* Dictionary */ &&
|
13177
|
-
nodeToEvaluate.nodeType !== 31 /* List */ &&
|
13178
|
-
nodeToEvaluate.nodeType !== 30 /* Lambda */ &&
|
13179
|
-
nodeToEvaluate.nodeType !== 45 /* Set */ &&
|
13180
|
-
nodeToEvaluate.nodeType !== 52 /* Tuple */ &&
|
13181
|
-
nodeToEvaluate.nodeType !== 56 /* Unpack */ &&
|
13182
|
-
nodeToEvaluate.nodeType !== 32 /* ListComprehension */) {
|
13183
|
-
break;
|
13184
|
-
}
|
13185
|
-
}
|
13186
13251
|
if (!(0, parseNodes_1.isExpressionNode)(parent)) {
|
13187
13252
|
// If we've hit a non-expression node, we generally want to
|
13188
13253
|
// stop. However, there are a few special "pass through"
|
@@ -13269,7 +13334,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13269
13334
|
const declaredReturnType = enclosingFunctionNode
|
13270
13335
|
? getFunctionDeclaredReturnType(enclosingFunctionNode)
|
13271
13336
|
: undefined;
|
13272
|
-
getTypeOfExpression(parent.returnExpression, 0 /* None */, declaredReturnType);
|
13337
|
+
getTypeOfExpression(parent.returnExpression, 0 /* None */, (0, typeUtils_1.makeInferenceContext)(declaredReturnType));
|
13273
13338
|
return;
|
13274
13339
|
}
|
13275
13340
|
break;
|
@@ -13311,7 +13376,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13311
13376
|
const param = functionNode.parameters[paramIndex];
|
13312
13377
|
const annotatedType = getTypeOfParameterAnnotation(typeAnnotation, functionNode.parameters[paramIndex].category);
|
13313
13378
|
const adjType = transformVariadicParamType(node, node.category, adjustParameterAnnotatedType(param, annotatedType));
|
13314
|
-
writeTypeCache(node.name, adjType, 0 /* None
|
13379
|
+
writeTypeCache(node.name, { type: adjType }, 0 /* None */);
|
13315
13380
|
return;
|
13316
13381
|
}
|
13317
13382
|
const containingClassNode = ParseTreeUtils.getEnclosingClass(functionNode, /* stopAtFunction */ true);
|
@@ -13322,7 +13387,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13322
13387
|
const typeParamName = getPseudoGenericTypeVarName(node.name.value);
|
13323
13388
|
const paramType = classInfo.classType.details.typeParameters.find((param) => param.details.name === typeParamName);
|
13324
13389
|
if (paramType) {
|
13325
|
-
writeTypeCache(node.name, paramType, 0 /* None
|
13390
|
+
writeTypeCache(node.name, { type: paramType }, 0 /* None */);
|
13326
13391
|
return;
|
13327
13392
|
}
|
13328
13393
|
}
|
@@ -13331,8 +13396,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13331
13396
|
// a parent class if it has an annotated type.
|
13332
13397
|
const functionFlags = getFunctionFlagsFromDecorators(functionNode, /* isInClass */ true);
|
13333
13398
|
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);
|
13399
|
+
writeTypeCache(node.name, { type: transformVariadicParamType(node, node.category, inferredParamType !== null && inferredParamType !== void 0 ? inferredParamType : types_1.UnknownType.create()) }, 0 /* None */);
|
13336
13400
|
}
|
13337
13401
|
// Evaluates the types that are assigned within the statement that contains
|
13338
13402
|
// the specified parse node. In some cases, a broader statement may need to
|
@@ -13445,13 +13509,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13445
13509
|
// If the type cache is already populated with a complete type,
|
13446
13510
|
// don't bother doing additional work.
|
13447
13511
|
let cacheEntry = readTypeCacheEntry(subnode);
|
13448
|
-
if (cacheEntry && !cacheEntry.isIncomplete) {
|
13449
|
-
return
|
13512
|
+
if (cacheEntry && !cacheEntry.typeResult.isIncomplete) {
|
13513
|
+
return cacheEntry.typeResult;
|
13450
13514
|
}
|
13451
13515
|
callback();
|
13452
13516
|
cacheEntry = readTypeCacheEntry(subnode);
|
13453
13517
|
if (cacheEntry) {
|
13454
|
-
return
|
13518
|
+
return cacheEntry.typeResult;
|
13455
13519
|
}
|
13456
13520
|
return undefined;
|
13457
13521
|
}
|
@@ -13848,9 +13912,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13848
13912
|
return getTypeOfExpressionExpectingType(arg.valueExpression);
|
13849
13913
|
}
|
13850
13914
|
function getTypeOfExpressionExpectingType(node, options) {
|
13851
|
-
let flags =
|
13852
|
-
8 /* EvaluateStringLiteralAsType */ |
|
13853
|
-
131072 /* ClassVarDisallowed */;
|
13915
|
+
let flags = 128 /* ExpectingType */ | 8 /* EvaluateStringLiteralAsType */ | 131072 /* DisallowClassVar */;
|
13854
13916
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
13855
13917
|
if (fileInfo.isStubFile) {
|
13856
13918
|
flags |= 4 /* AllowForwardReferences */;
|
@@ -13859,19 +13921,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13859
13921
|
flags |= 4194304 /* InterpreterParsesStringLiteral */;
|
13860
13922
|
}
|
13861
13923
|
if (!(options === null || options === void 0 ? void 0 : options.allowFinal)) {
|
13862
|
-
flags |= 16 /*
|
13924
|
+
flags |= 16 /* DisallowFinal */;
|
13863
13925
|
}
|
13864
13926
|
if (options === null || options === void 0 ? void 0 : options.allowRequired) {
|
13865
|
-
flags |= 1048576 /*
|
13927
|
+
flags |= 1048576 /* AllowRequired */ | 256 /* ExpectingTypeAnnotation */;
|
13866
13928
|
}
|
13867
13929
|
if (options === null || options === void 0 ? void 0 : options.allowUnpackedTuple) {
|
13868
13930
|
flags |= 2097152 /* AllowUnpackedTupleOrTypeVarTuple */;
|
13869
13931
|
}
|
13870
13932
|
else {
|
13871
|
-
flags |=
|
13933
|
+
flags |= 64 /* DisallowTypeVarTuple */;
|
13872
13934
|
}
|
13873
13935
|
if (!(options === null || options === void 0 ? void 0 : options.allowParamSpec)) {
|
13874
|
-
flags |= 32 /*
|
13936
|
+
flags |= 32 /* DisallowParamSpec */;
|
13875
13937
|
}
|
13876
13938
|
return getTypeOfExpression(node, flags);
|
13877
13939
|
}
|
@@ -14381,8 +14443,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14381
14443
|
}
|
14382
14444
|
// Cache the value before we evaluate the bound or the default type in
|
14383
14445
|
// case it refers to itself in a circular manner.
|
14384
|
-
writeTypeCache(node, typeVar, /* flags */ undefined
|
14385
|
-
writeTypeCache(node.name, typeVar, /* flags */ undefined
|
14446
|
+
writeTypeCache(node, { type: typeVar }, /* flags */ undefined);
|
14447
|
+
writeTypeCache(node.name, { type: typeVar }, /* flags */ undefined);
|
14386
14448
|
if (node.boundExpression) {
|
14387
14449
|
if (node.boundExpression.nodeType === 52 /* Tuple */) {
|
14388
14450
|
const constraints = node.boundExpression.expressions.map((constraint) => {
|
@@ -14684,7 +14746,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14684
14746
|
return getEffectiveTypeOfSymbolForUsage(symbol).type;
|
14685
14747
|
}
|
14686
14748
|
function getEffectiveTypeOfSymbolForUsage(symbol, usageNode, useLastDecl = false) {
|
14687
|
-
var _a;
|
14749
|
+
var _a, _b;
|
14688
14750
|
// If there's a declared type, it takes precedence over inferred types.
|
14689
14751
|
if (symbol.hasTypedDeclarations()) {
|
14690
14752
|
const declaredType = getDeclaredTypeOfSymbol(symbol, usageNode);
|
@@ -14708,7 +14770,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14708
14770
|
}
|
14709
14771
|
// Look in the cache to see if we've computed this already.
|
14710
14772
|
let cacheEntries = effectiveTypeCache.get(symbol.id);
|
14711
|
-
let evaluationAttempts = 0;
|
14712
14773
|
const usageNodeId = usageNode ? usageNode.id : undefined;
|
14713
14774
|
const effectiveTypeCacheKey = `${usageNodeId === undefined ? '.' : usageNodeId.toString()}${useLastDecl ? '*' : ''}`;
|
14714
14775
|
if (cacheEntries) {
|
@@ -14717,7 +14778,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14717
14778
|
if (!result.isIncomplete) {
|
14718
14779
|
return result;
|
14719
14780
|
}
|
14720
|
-
evaluationAttempts = ((_a = result.evaluationAttempts) !== null && _a !== void 0 ? _a : 0) + 1;
|
14721
14781
|
}
|
14722
14782
|
}
|
14723
14783
|
// Infer the type.
|
@@ -14845,20 +14905,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14845
14905
|
}
|
14846
14906
|
isIncomplete = true;
|
14847
14907
|
// 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
|
-
}
|
14908
|
+
// it was already in the process of being evaluated.
|
14909
|
+
sawPendingEvaluation = true;
|
14855
14910
|
}
|
14856
14911
|
}
|
14857
14912
|
});
|
14858
14913
|
if (typesToCombine.length > 0) {
|
14914
|
+
// How many times have we already attempted to evaluate this declaration already?
|
14915
|
+
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;
|
14916
|
+
// Ignore the pending evaluation flag if we've already attempted the
|
14917
|
+
// type evaluation many times because this probably means there's a
|
14918
|
+
// cyclical dependency that cannot be broken.
|
14919
|
+
isIncomplete = sawPendingEvaluation && evaluationAttempts < maxEffectiveTypeEvaluationAttempts;
|
14859
14920
|
const result = {
|
14860
14921
|
type: (0, types_1.combineTypes)(typesToCombine),
|
14861
|
-
isIncomplete
|
14922
|
+
isIncomplete,
|
14862
14923
|
includesVariableDecl,
|
14863
14924
|
includesIllegalTypeAliasDecl: !decls.every((decl) => (0, declarationUtils_1.isPossibleTypeAliasDeclaration)(decl)),
|
14864
14925
|
isRecursiveDefinition: false,
|
@@ -14880,7 +14941,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14880
14941
|
includesVariableDecl,
|
14881
14942
|
includesIllegalTypeAliasDecl: !decls.every((decl) => (0, declarationUtils_1.isPossibleTypeAliasDeclaration)(decl)),
|
14882
14943
|
isRecursiveDefinition: false,
|
14883
|
-
evaluationAttempts,
|
14884
14944
|
};
|
14885
14945
|
}
|
14886
14946
|
function getDeclaredTypeOfSymbol(symbol, usageNode) {
|
@@ -15139,7 +15199,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15139
15199
|
paramType = types_1.UnknownType.create();
|
15140
15200
|
}
|
15141
15201
|
paramTypes.push(paramType);
|
15142
|
-
writeTypeCache(param.name, paramType, 0 /* None
|
15202
|
+
writeTypeCache(param.name, { type: paramType }, 0 /* None */);
|
15143
15203
|
}
|
15144
15204
|
});
|
15145
15205
|
// Don't bother trying to determine the contextual return
|
@@ -16225,6 +16285,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16225
16285
|
}
|
16226
16286
|
});
|
16227
16287
|
}
|
16288
|
+
else if (remainingSrcSubtypes.length === 0) {
|
16289
|
+
// If we've assigned all of the source subtypes but one or more dest
|
16290
|
+
// TypeVars have gone unmatched, treat this as success.
|
16291
|
+
return true;
|
16292
|
+
}
|
16228
16293
|
else {
|
16229
16294
|
// Try to assign a union of the remaining source types to
|
16230
16295
|
// the first destination TypeVar.
|
@@ -16658,6 +16723,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16658
16723
|
if (destDetails.argsIndex === undefined) {
|
16659
16724
|
return;
|
16660
16725
|
}
|
16726
|
+
// If the *args parameter isn't an unpacked TypeVarTuple or tuple,
|
16727
|
+
// we have nothing to do.
|
16728
|
+
if (!(0, types_1.isUnpacked)(destDetails.params[destDetails.argsIndex].type)) {
|
16729
|
+
return;
|
16730
|
+
}
|
16661
16731
|
// If the source doesn't have enough positional parameters, we have nothing to do.
|
16662
16732
|
if (srcDetails.params.length < destDetails.argsIndex) {
|
16663
16733
|
return;
|
@@ -16891,9 +16961,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16891
16961
|
// The converse situation is OK.
|
16892
16962
|
if (!types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType) &&
|
16893
16963
|
srcParamDetails.argsIndex === undefined &&
|
16964
|
+
srcType.details.paramSpec === undefined &&
|
16894
16965
|
destParamDetails.argsIndex !== undefined &&
|
16895
|
-
!destParamDetails.hasUnpackedVariadicTypeVar
|
16896
|
-
!targetIncludesParamSpec) {
|
16966
|
+
!destParamDetails.hasUnpackedVariadicTypeVar) {
|
16897
16967
|
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.Localizer.DiagnosticAddendum.argsParamMissing().format({
|
16898
16968
|
paramName: (_h = destParamDetails.params[destParamDetails.argsIndex].param.name) !== null && _h !== void 0 ? _h : '',
|
16899
16969
|
}));
|
@@ -17848,6 +17918,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17848
17918
|
const evaluatorInterface = {
|
17849
17919
|
runWithCancellationToken,
|
17850
17920
|
getType,
|
17921
|
+
getTypeResult,
|
17851
17922
|
getCachedType,
|
17852
17923
|
getTypeOfExpression,
|
17853
17924
|
getTypeOfAnnotation,
|