@zzzen/pyright-internal 1.2.0-dev.20240519 → 1.2.0-dev.20240526
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/analysis.d.ts +5 -1
- package/dist/analyzer/analysis.js +3 -3
- package/dist/analyzer/analysis.js.map +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.js +1 -1
- package/dist/analyzer/binder.js +6 -0
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +10 -2
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +5 -1
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +2 -1
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.d.ts +2 -1
- package/dist/analyzer/constructorTransform.js +7 -6
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +2 -2
- package/dist/analyzer/constructors.js +25 -22
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/decorators.js +3 -1
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.js +3 -2
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.js +11 -4
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +5 -5
- package/dist/analyzer/parameterUtils.js +16 -16
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parentDirectoryCache.js +1 -2
- package/dist/analyzer/parentDirectoryCache.js.map +1 -1
- package/dist/analyzer/program.d.ts +2 -1
- package/dist/analyzer/program.js +13 -6
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/service.d.ts +4 -2
- package/dist/analyzer/service.js +67 -33
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +1 -1
- package/dist/analyzer/sourceFile.js +20 -6
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +6 -3
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +359 -259
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +5 -4
- package/dist/analyzer/typeEvaluatorTypes.js +3 -0
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typePrinter.js +7 -1
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +3 -4
- package/dist/analyzer/typeUtils.js +7 -7
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/backgroundAnalysisBase.js +4 -4
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +2 -0
- package/dist/backgroundThreadBase.js +7 -3
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/createTypeStub.d.ts +7 -1
- package/dist/commands/createTypeStub.js +45 -32
- package/dist/commands/createTypeStub.js.map +1 -1
- package/dist/common/configOptions.d.ts +4 -3
- package/dist/common/configOptions.js +36 -31
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/console.d.ts +3 -0
- package/dist/common/console.js +4 -0
- package/dist/common/console.js.map +1 -1
- package/dist/common/languageServerInterface.d.ts +46 -0
- package/dist/common/languageServerInterface.js.map +1 -1
- package/dist/common/uri/uri.js +2 -0
- package/dist/common/uri/uri.js.map +1 -1
- package/dist/common/uri/uriUtils.d.ts +1 -1
- package/dist/common/uri/uriUtils.js +3 -3
- package/dist/common/uri/uriUtils.js.map +1 -1
- package/dist/common/workspaceEditUtils.js +8 -6
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +4 -45
- package/dist/languageServerBase.js +36 -28
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.d.ts +2 -2
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +5 -5
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +1 -1
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolProvider.js +1 -1
- package/dist/languageService/documentSymbolProvider.js.map +1 -1
- package/dist/languageService/fileWatcherDynamicFeature.d.ts +2 -2
- package/dist/languageService/fileWatcherDynamicFeature.js +2 -2
- package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
- package/dist/languageService/navigationUtils.js +1 -1
- package/dist/languageService/navigationUtils.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.js +1 -1
- package/dist/languageService/workspaceSymbolProvider.js.map +1 -1
- package/dist/localization/package.nls.cs.json +1 -1
- package/dist/localization/package.nls.de.json +2 -2
- package/dist/localization/package.nls.en-us.json +2 -2
- package/dist/localization/package.nls.es.json +2 -2
- package/dist/localization/package.nls.fr.json +2 -2
- package/dist/localization/package.nls.it.json +1 -1
- package/dist/localization/package.nls.ja.json +2 -2
- package/dist/localization/package.nls.ko.json +1 -1
- package/dist/localization/package.nls.pl.json +1 -1
- package/dist/localization/package.nls.pt-br.json +1 -1
- package/dist/localization/package.nls.qps-ploc.json +2 -2
- package/dist/localization/package.nls.ru.json +2 -2
- package/dist/localization/package.nls.tr.json +1 -1
- package/dist/localization/package.nls.zh-cn.json +2 -2
- package/dist/localization/package.nls.zh-tw.json +1 -1
- package/dist/parser/tokenizer.js +2 -2
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/pyright.js +1 -1
- package/dist/pyright.js.map +1 -1
- package/dist/tests/config.test.js +15 -3
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +2 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/fourslash/testStateUtils.js +1 -1
- package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
- package/dist/tests/hoverProvider.test.js +17 -0
- package/dist/tests/hoverProvider.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +4 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +3 -3
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +5 -1
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +6 -2
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/package.json +1 -1
@@ -509,7 +509,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
509
509
|
}
|
510
510
|
}
|
511
511
|
}
|
512
|
-
function getTypeOfExpression(node, flags = 0 /* EvaluatorFlags.None */, inferenceContext) {
|
512
|
+
function getTypeOfExpression(node, flags = 0 /* EvaluatorFlags.None */, inferenceContext, signatureTracker) {
|
513
513
|
// Is this type already cached?
|
514
514
|
const cacheEntry = readTypeCacheEntry(node);
|
515
515
|
if (cacheEntry &&
|
@@ -547,9 +547,55 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
547
547
|
// needed in assignType, but we don't have access to the parse tree
|
548
548
|
// at that point.
|
549
549
|
initializedBasicTypes(node);
|
550
|
+
let typeResult = getTypeOfExpressionCore(node, flags, inferenceContext, signatureTracker);
|
551
|
+
// Should we disable type promotions for bytes?
|
552
|
+
if ((0, types_1.isInstantiableClass)(typeResult.type) &&
|
553
|
+
typeResult.type.includePromotions &&
|
554
|
+
!typeResult.type.includeSubclasses &&
|
555
|
+
types_1.ClassType.isBuiltIn(typeResult.type, 'bytes')) {
|
556
|
+
if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.disableBytesTypePromotions) {
|
557
|
+
typeResult = {
|
558
|
+
...typeResult,
|
559
|
+
type: types_1.ClassType.cloneRemoveTypePromotions(typeResult.type),
|
560
|
+
};
|
561
|
+
}
|
562
|
+
}
|
563
|
+
// Don't allow speculative caching for assignment expressions because
|
564
|
+
// the target name node won't have a corresponding type cached speculatively.
|
565
|
+
const allowSpeculativeCaching = node.nodeType !== 4 /* ParseNodeType.AssignmentExpression */;
|
566
|
+
writeTypeCache(node, typeResult, flags, inferenceContext, allowSpeculativeCaching);
|
567
|
+
// If there was an expected type, make sure that the result type is compatible.
|
568
|
+
if (inferenceContext &&
|
569
|
+
!(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) &&
|
570
|
+
!(0, types_1.isNever)(inferenceContext.expectedType)) {
|
571
|
+
expectedTypeCache.set(node.id, inferenceContext.expectedType);
|
572
|
+
// If this is a generic function and there is a signature tracker,
|
573
|
+
// make sure the signature is unique.
|
574
|
+
if (signatureTracker && (0, types_1.isFunction)(typeResult.type)) {
|
575
|
+
typeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(typeResult.type, signatureTracker, node.start);
|
576
|
+
}
|
577
|
+
if (!typeResult.isIncomplete && !typeResult.expectedTypeDiagAddendum) {
|
578
|
+
const diag = new diagnostic_1.DiagnosticAddendum();
|
579
|
+
// Make sure the resulting type is assignable to the expected type.
|
580
|
+
if (!assignType(inferenceContext.expectedType, typeResult.type, diag,
|
581
|
+
/* destTypeVarContext */ undefined,
|
582
|
+
/* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */)) {
|
583
|
+
typeResult.typeErrors = true;
|
584
|
+
typeResult.expectedTypeDiagAddendum = diag;
|
585
|
+
diag.addTextRange(node);
|
586
|
+
}
|
587
|
+
}
|
588
|
+
}
|
589
|
+
if (printExpressionTypes) {
|
590
|
+
printExpressionSpaceCount--;
|
591
|
+
console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Post ${printType(typeResult.type)}${typeResult.isIncomplete ? ' Incomplete' : ''}`);
|
592
|
+
}
|
593
|
+
return typeResult;
|
594
|
+
}
|
595
|
+
// This is a helper function that implements the core of getTypeOfExpression.
|
596
|
+
function getTypeOfExpressionCore(node, flags = 0 /* EvaluatorFlags.None */, inferenceContext, signatureTracker) {
|
550
597
|
let typeResult;
|
551
598
|
let expectingInstantiable = (flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) !== 0;
|
552
|
-
let allowSpeculativeCaching = true;
|
553
599
|
switch (node.nodeType) {
|
554
600
|
case 38 /* ParseNodeType.Name */: {
|
555
601
|
typeResult = getTypeOfName(node, flags);
|
@@ -564,11 +610,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
564
610
|
break;
|
565
611
|
}
|
566
612
|
case 9 /* ParseNodeType.Call */: {
|
567
|
-
typeResult = getTypeOfCall(node, flags, inferenceContext);
|
613
|
+
typeResult = getTypeOfCall(node, flags, inferenceContext, signatureTracker);
|
568
614
|
break;
|
569
615
|
}
|
570
616
|
case 52 /* ParseNodeType.Tuple */: {
|
571
|
-
typeResult = getTypeOfTuple(node, flags, inferenceContext);
|
617
|
+
typeResult = getTypeOfTuple(node, flags, inferenceContext, signatureTracker);
|
572
618
|
break;
|
573
619
|
}
|
574
620
|
case 11 /* ParseNodeType.Constant */: {
|
@@ -629,7 +675,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
629
675
|
break;
|
630
676
|
}
|
631
677
|
case 32 /* ParseNodeType.ListComprehension */: {
|
632
|
-
typeResult = getTypeOfListComprehension(node, inferenceContext);
|
678
|
+
typeResult = getTypeOfListComprehension(node, flags, inferenceContext);
|
633
679
|
break;
|
634
680
|
}
|
635
681
|
case 15 /* ParseNodeType.Dictionary */: {
|
@@ -641,7 +687,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
641
687
|
break;
|
642
688
|
}
|
643
689
|
case 3 /* ParseNodeType.Assignment */: {
|
644
|
-
typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext);
|
690
|
+
typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext, signatureTracker);
|
645
691
|
assignTypeToExpression(node.leftExpression, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
|
646
692
|
/* ignoreEmptyContainers */ true,
|
647
693
|
/* allowAssignmentToFinalVar */ true);
|
@@ -651,12 +697,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
651
697
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
652
698
|
addError(localize_1.LocMessage.walrusNotAllowed(), node);
|
653
699
|
}
|
654
|
-
typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext);
|
700
|
+
typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext, signatureTracker);
|
655
701
|
assignTypeToExpression(node.name, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
|
656
702
|
/* ignoreEmptyContainers */ true);
|
657
|
-
// Don't allow speculative caching for assignment expressions because
|
658
|
-
// the target name node won't have a corresponding type cached speculatively.
|
659
|
-
allowSpeculativeCaching = false;
|
660
703
|
break;
|
661
704
|
}
|
662
705
|
case 60 /* ParseNodeType.Yield */: {
|
@@ -707,45 +750,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
707
750
|
if (expectingInstantiable) {
|
708
751
|
validateTypeIsInstantiable(typeResult, flags, node);
|
709
752
|
}
|
710
|
-
// Should we disable type promotions for bytes?
|
711
|
-
if ((0, types_1.isInstantiableClass)(typeResult.type) &&
|
712
|
-
typeResult.type.includePromotions &&
|
713
|
-
!typeResult.type.includeSubclasses &&
|
714
|
-
types_1.ClassType.isBuiltIn(typeResult.type, 'bytes')) {
|
715
|
-
if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.disableBytesTypePromotions) {
|
716
|
-
typeResult = {
|
717
|
-
...typeResult,
|
718
|
-
type: types_1.ClassType.cloneRemoveTypePromotions(typeResult.type),
|
719
|
-
};
|
720
|
-
}
|
721
|
-
}
|
722
|
-
writeTypeCache(node, typeResult, flags, inferenceContext, allowSpeculativeCaching);
|
723
|
-
// If there was an expected type, make sure that the result type is compatible.
|
724
|
-
if (inferenceContext &&
|
725
|
-
!(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) &&
|
726
|
-
!(0, types_1.isNever)(inferenceContext.expectedType)) {
|
727
|
-
expectedTypeCache.set(node.id, inferenceContext.expectedType);
|
728
|
-
// If this is a generic function and there is a signature tracker,
|
729
|
-
// make sure the signature is unique.
|
730
|
-
if (inferenceContext.signatureTracker && (0, types_1.isFunction)(typeResult.type)) {
|
731
|
-
typeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(typeResult.type, inferenceContext.signatureTracker, node.start);
|
732
|
-
}
|
733
|
-
if (!typeResult.isIncomplete && !typeResult.expectedTypeDiagAddendum) {
|
734
|
-
const diag = new diagnostic_1.DiagnosticAddendum();
|
735
|
-
// Make sure the resulting type is assignable to the expected type.
|
736
|
-
if (!assignType(inferenceContext.expectedType, typeResult.type, diag,
|
737
|
-
/* destTypeVarContext */ undefined,
|
738
|
-
/* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */)) {
|
739
|
-
typeResult.typeErrors = true;
|
740
|
-
typeResult.expectedTypeDiagAddendum = diag;
|
741
|
-
diag.addTextRange(node);
|
742
|
-
}
|
743
|
-
}
|
744
|
-
}
|
745
|
-
if (printExpressionTypes) {
|
746
|
-
printExpressionSpaceCount--;
|
747
|
-
console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Post ${printType(typeResult.type)}${typeResult.isIncomplete ? ' Incomplete' : ''}`);
|
748
|
-
}
|
749
753
|
return typeResult;
|
750
754
|
}
|
751
755
|
// Reports the case where a function or class has been decorated with
|
@@ -1536,7 +1540,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1536
1540
|
let callResult;
|
1537
1541
|
useSpeculativeMode(callNode, () => {
|
1538
1542
|
callResult = validateFunctionArguments(exprNode, argList, { type }, new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type)),
|
1539
|
-
/* skipUnknownArgCheck */ true
|
1543
|
+
/* skipUnknownArgCheck */ true,
|
1544
|
+
/* inferenceContext */ undefined,
|
1545
|
+
/* signatureTracker */ undefined);
|
1540
1546
|
});
|
1541
1547
|
signatures.push({
|
1542
1548
|
type: expandTypedKwargs(type),
|
@@ -2856,7 +2862,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2856
2862
|
suppressDiagnostics(node.typeExpression, () => {
|
2857
2863
|
callResult = (0, constructors_1.validateConstructorArguments)(evaluatorInterface, node.typeExpression, [], concreteSubtype,
|
2858
2864
|
/* skipUnknownArgCheck */ false,
|
2859
|
-
/* inferenceContext */ undefined
|
2865
|
+
/* inferenceContext */ undefined,
|
2866
|
+
/* signatureTracker */ undefined);
|
2860
2867
|
});
|
2861
2868
|
if (callResult && callResult.argumentErrors) {
|
2862
2869
|
diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeNotInstantiable().format({
|
@@ -4210,7 +4217,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4210
4217
|
const callResult = suppressDiagnostics(errorNode, () => {
|
4211
4218
|
return validateCallArguments(errorNode, argList, { type: methodType },
|
4212
4219
|
/* typeVarContext */ undefined,
|
4213
|
-
/* skipUnknownArgCheck */ true
|
4220
|
+
/* skipUnknownArgCheck */ true,
|
4221
|
+
/* inferenceContext */ undefined,
|
4222
|
+
/* signatureTracker */ undefined);
|
4214
4223
|
});
|
4215
4224
|
// Collect deprecation information associated with the member access method.
|
4216
4225
|
let deprecationInfo;
|
@@ -4407,7 +4416,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4407
4416
|
}
|
4408
4417
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(accessMemberType));
|
4409
4418
|
const callResult = validateCallArguments(errorNode, argList, { type: accessMemberType }, typeVarContext,
|
4410
|
-
/* skipUnknownArgCheck */ true
|
4419
|
+
/* skipUnknownArgCheck */ true,
|
4420
|
+
/* inferenceContext */ undefined,
|
4421
|
+
/* signatureTracker */ undefined);
|
4411
4422
|
let isAsymmetricAccessor = false;
|
4412
4423
|
if (usage.method === 'set') {
|
4413
4424
|
isAsymmetricAccessor = isClassWithAsymmetricAttributeAccessor(classType);
|
@@ -5209,7 +5220,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5209
5220
|
useSpeculativeMode(node, () => {
|
5210
5221
|
callResult = validateCallArguments(node, argList, { type: itemMethodType },
|
5211
5222
|
/* typeVarContext */ undefined,
|
5212
|
-
/* skipUnknownArgCheck */ true
|
5223
|
+
/* skipUnknownArgCheck */ true,
|
5224
|
+
/* inferenceContext */ undefined,
|
5225
|
+
/* signatureTracker */ undefined);
|
5213
5226
|
if (callResult.argumentErrors) {
|
5214
5227
|
// If the object supports "__index__" magic method, convert
|
5215
5228
|
// the index to an int and try again.
|
@@ -5223,7 +5236,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5223
5236
|
altArgList[0].typeResult = { type: intType };
|
5224
5237
|
}
|
5225
5238
|
}
|
5226
|
-
callResult = validateCallArguments(node, altArgList, { type: itemMethodType }
|
5239
|
+
callResult = validateCallArguments(node, altArgList, { type: itemMethodType },
|
5240
|
+
/* typeVarContext */ undefined,
|
5241
|
+
/* skipUnknownArgCheck */ true,
|
5242
|
+
/* inferenceContext */ undefined,
|
5243
|
+
/* signatureTracker */ undefined);
|
5227
5244
|
// We were successful, so replace the arg list.
|
5228
5245
|
if (!callResult.argumentErrors) {
|
5229
5246
|
argList = altArgList;
|
@@ -5234,7 +5251,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5234
5251
|
}
|
5235
5252
|
callResult = validateCallArguments(node, argList, { type: itemMethodType },
|
5236
5253
|
/* typeVarContext */ undefined,
|
5237
|
-
/* skipUnknownArgCheck */ true
|
5254
|
+
/* skipUnknownArgCheck */ true,
|
5255
|
+
/* inferenceContext */ undefined,
|
5256
|
+
/* signatureTracker */ undefined);
|
5238
5257
|
return {
|
5239
5258
|
type: (_d = callResult.returnType) !== null && _d !== void 0 ? _d : types_1.UnknownType.create(),
|
5240
5259
|
isIncomplete: !!callResult.isTypeIncomplete,
|
@@ -5288,9 +5307,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5288
5307
|
function getTypeArgs(node, flags, options) {
|
5289
5308
|
const typeArgs = [];
|
5290
5309
|
let adjFlags = flags;
|
5291
|
-
if (
|
5310
|
+
if (options === null || options === void 0 ? void 0 : options.isFinalAnnotation) {
|
5292
5311
|
adjFlags |= 131072 /* EvaluatorFlags.DisallowClassVar */ | 16 /* EvaluatorFlags.DisallowFinal */;
|
5293
5312
|
}
|
5313
|
+
else if (options === null || options === void 0 ? void 0 : options.isClassVarAnnotation) {
|
5314
|
+
adjFlags |= 131072 /* EvaluatorFlags.DisallowClassVar */;
|
5315
|
+
// If the annotation is a variable within the body of a dataclass, a
|
5316
|
+
// Final is allowed within the ClassVar annotation. In all other cases,
|
5317
|
+
// it's disallowed.
|
5318
|
+
let disallowFinal = true;
|
5319
|
+
const enclosingClassNode = ParseTreeUtils.getEnclosingClass(node, /* stopeAtFunction */ true);
|
5320
|
+
if (enclosingClassNode) {
|
5321
|
+
const classTypeInfo = getTypeOfClass(enclosingClassNode);
|
5322
|
+
if (classTypeInfo && types_1.ClassType.isDataClass(classTypeInfo.classType)) {
|
5323
|
+
disallowFinal = false;
|
5324
|
+
}
|
5325
|
+
}
|
5326
|
+
if (disallowFinal) {
|
5327
|
+
adjFlags |= 16 /* EvaluatorFlags.DisallowFinal */;
|
5328
|
+
}
|
5329
|
+
}
|
5294
5330
|
else {
|
5295
5331
|
adjFlags &= ~(2 /* EvaluatorFlags.DoNotSpecialize */ |
|
5296
5332
|
32 /* EvaluatorFlags.DisallowParamSpec */ |
|
@@ -5425,7 +5461,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5425
5461
|
}
|
5426
5462
|
return typeResult;
|
5427
5463
|
}
|
5428
|
-
function getTypeOfTuple(node, flags, inferenceContext) {
|
5464
|
+
function getTypeOfTuple(node, flags, inferenceContext, signatureTracker) {
|
5429
5465
|
var _a;
|
5430
5466
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0 &&
|
5431
5467
|
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
|
@@ -5442,6 +5478,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5442
5478
|
!inferenceContext) {
|
5443
5479
|
return { type: makeTupleObject([]), isEmptyTupleShorthand: true };
|
5444
5480
|
}
|
5481
|
+
flags &= ~(256 /* EvaluatorFlags.ExpectingTypeAnnotation */ |
|
5482
|
+
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
|
5483
|
+
128 /* EvaluatorFlags.ExpectingInstantiableType */);
|
5445
5484
|
// If the expected type is a union, recursively call for each of the subtypes
|
5446
5485
|
// to find one that matches.
|
5447
5486
|
let effectiveExpectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
|
@@ -5454,7 +5493,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5454
5493
|
}
|
5455
5494
|
if (!matchingSubtype) {
|
5456
5495
|
const subtypeResult = useSpeculativeMode(node, () => {
|
5457
|
-
return getTypeOfTupleWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype)
|
5496
|
+
return getTypeOfTupleWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(subtype),
|
5497
|
+
/* signatureTracker */ undefined);
|
5458
5498
|
});
|
5459
5499
|
if (subtypeResult && assignType(subtype, subtypeResult.type)) {
|
5460
5500
|
matchingSubtype = subtype;
|
@@ -5466,14 +5506,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5466
5506
|
}
|
5467
5507
|
let expectedTypeDiagAddendum;
|
5468
5508
|
if (effectiveExpectedType) {
|
5469
|
-
const result = getTypeOfTupleWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType,
|
5470
|
-
/* isTypeIncomplete */ false, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.signatureTracker));
|
5509
|
+
const result = getTypeOfTupleWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType), signatureTracker);
|
5471
5510
|
if (result && !result.typeErrors) {
|
5472
5511
|
return result;
|
5473
5512
|
}
|
5474
5513
|
expectedTypeDiagAddendum = result === null || result === void 0 ? void 0 : result.expectedTypeDiagAddendum;
|
5475
5514
|
}
|
5476
|
-
const typeResult = getTypeOfTupleInferred(node);
|
5515
|
+
const typeResult = getTypeOfTupleInferred(node, flags);
|
5477
5516
|
// If there was an expected type of Any, replace the resulting type
|
5478
5517
|
// with Any rather than return a type with unknowns.
|
5479
5518
|
if (expectedTypeContainsAny) {
|
@@ -5481,7 +5520,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5481
5520
|
}
|
5482
5521
|
return { ...typeResult, expectedTypeDiagAddendum };
|
5483
5522
|
}
|
5484
|
-
function getTypeOfTupleWithContext(node, inferenceContext) {
|
5523
|
+
function getTypeOfTupleWithContext(node, flags, inferenceContext, signatureTracker) {
|
5485
5524
|
inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
|
5486
5525
|
if (!(0, types_1.isClassInstance)(inferenceContext.expectedType)) {
|
5487
5526
|
return undefined;
|
@@ -5519,10 +5558,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5519
5558
|
expectedTypes.push(homogenousType);
|
5520
5559
|
}
|
5521
5560
|
}
|
5522
|
-
const entryTypeResults = node.expressions.map((expr, index) => getTypeOfExpression(expr,
|
5523
|
-
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(index < expectedTypes.length ? expectedTypes[index] : undefined, inferenceContext.isTypeIncomplete, inferenceContext.signatureTracker)));
|
5561
|
+
const entryTypeResults = node.expressions.map((expr, index) => getTypeOfExpression(expr, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(index < expectedTypes.length ? expectedTypes[index] : undefined, inferenceContext.isTypeIncomplete), signatureTracker));
|
5524
5562
|
const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
|
5525
|
-
const type = makeTupleObject(buildTupleTypesList(entryTypeResults));
|
5563
|
+
const type = makeTupleObject(buildTupleTypesList(entryTypeResults, /* stripLiterals */ false));
|
5526
5564
|
// Copy any expected type diag addenda for precision error reporting.
|
5527
5565
|
let expectedTypeDiagAddendum;
|
5528
5566
|
if (entryTypeResults.some((result) => result.expectedTypeDiagAddendum)) {
|
@@ -5535,10 +5573,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5535
5573
|
}
|
5536
5574
|
return { type, expectedTypeDiagAddendum, isIncomplete };
|
5537
5575
|
}
|
5538
|
-
function getTypeOfTupleInferred(node) {
|
5539
|
-
const entryTypeResults = node.expressions.map((expr) => getTypeOfExpression(expr));
|
5576
|
+
function getTypeOfTupleInferred(node, flags) {
|
5577
|
+
const entryTypeResults = node.expressions.map((expr) => getTypeOfExpression(expr, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */));
|
5540
5578
|
const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
|
5541
|
-
const type = makeTupleObject(buildTupleTypesList(entryTypeResults));
|
5579
|
+
const type = makeTupleObject(buildTupleTypesList(entryTypeResults, (flags & 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */) !== 0));
|
5542
5580
|
if (isIncomplete) {
|
5543
5581
|
if ((0, typeUtils_1.getContainerDepth)(type) > maxInferredContainerDepth) {
|
5544
5582
|
return { type: types_1.UnknownType.create() };
|
@@ -5546,7 +5584,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5546
5584
|
}
|
5547
5585
|
return { type, isIncomplete };
|
5548
5586
|
}
|
5549
|
-
function buildTupleTypesList(entryTypeResults) {
|
5587
|
+
function buildTupleTypesList(entryTypeResults, stripLiterals) {
|
5550
5588
|
const entryTypes = [];
|
5551
5589
|
for (const typeResult of entryTypeResults) {
|
5552
5590
|
let possibleUnpackedTuple;
|
@@ -5575,7 +5613,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5575
5613
|
entryTypes.push({ type: types_1.UnknownType.create(/* isIncomplete */ true), isUnbounded: false });
|
5576
5614
|
}
|
5577
5615
|
else {
|
5578
|
-
|
5616
|
+
const entryType = stripLiterals ? stripLiteralValue(typeResult.type) : typeResult.type;
|
5617
|
+
entryTypes.push({ type: entryType, isUnbounded: !!typeResult.unpackedType });
|
5579
5618
|
}
|
5580
5619
|
}
|
5581
5620
|
// If there are multiple unbounded entries, combine all of them into a single
|
@@ -5588,7 +5627,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5588
5627
|
}
|
5589
5628
|
return entryTypes;
|
5590
5629
|
}
|
5591
|
-
function getTypeOfCall(node, flags, inferenceContext) {
|
5630
|
+
function getTypeOfCall(node, flags, inferenceContext, signatureTracker) {
|
5592
5631
|
var _a;
|
5593
5632
|
let baseTypeResult;
|
5594
5633
|
// Check for the use of `type(x)` within a type annotation. This isn't
|
@@ -5621,8 +5660,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5621
5660
|
// If the inference context has an associated signature tracker, make sure
|
5622
5661
|
// the base type of this call is not the same as one of the tracked signatures.
|
5623
5662
|
// This is important for nested generic calls (e.g. "foo(foo(x))").
|
5624
|
-
if (
|
5625
|
-
baseTypeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(baseTypeResult.type,
|
5663
|
+
if (signatureTracker) {
|
5664
|
+
baseTypeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(baseTypeResult.type, signatureTracker, node.leftExpression.start);
|
5626
5665
|
}
|
5627
5666
|
if (!(0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
|
5628
5667
|
if (node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ && node.leftExpression.value === 'super') {
|
@@ -5633,15 +5672,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5633
5672
|
node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
5634
5673
|
node.leftExpression.value === 'reveal_type') {
|
5635
5674
|
// Handle the implicit "reveal_type" call.
|
5636
|
-
typeResult = getTypeOfRevealType(node, inferenceContext);
|
5675
|
+
typeResult = getTypeOfRevealType(node, inferenceContext, signatureTracker);
|
5637
5676
|
}
|
5638
5677
|
else if ((0, types_1.isFunction)(baseTypeResult.type) && baseTypeResult.type.details.builtInName === 'reveal_type') {
|
5639
5678
|
// Handle the "typing.reveal_type" call.
|
5640
|
-
typeResult = getTypeOfRevealType(node, inferenceContext);
|
5679
|
+
typeResult = getTypeOfRevealType(node, inferenceContext, signatureTracker);
|
5641
5680
|
}
|
5642
5681
|
else if ((0, types_1.isFunction)(baseTypeResult.type) && baseTypeResult.type.details.builtInName === 'assert_type') {
|
5643
5682
|
// Handle the "typing.assert_type" call.
|
5644
|
-
typeResult = getTypeOfAssertType(node, inferenceContext);
|
5683
|
+
typeResult = getTypeOfAssertType(node, inferenceContext, signatureTracker);
|
5645
5684
|
}
|
5646
5685
|
else if ((0, types_1.isAnyOrUnknown)(baseTypeResult.type) &&
|
5647
5686
|
node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
@@ -5657,7 +5696,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5657
5696
|
else {
|
5658
5697
|
const callResult = validateCallArguments(node, argList, baseTypeResult,
|
5659
5698
|
/* typeVarContext */ undefined,
|
5660
|
-
/* skipUnknownArgCheck */ false, inferenceContext);
|
5699
|
+
/* skipUnknownArgCheck */ false, inferenceContext, signatureTracker);
|
5661
5700
|
typeResult.type = (_a = callResult.returnType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
5662
5701
|
if (callResult.argumentErrors) {
|
5663
5702
|
typeResult.typeErrors = true;
|
@@ -5751,7 +5790,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5751
5790
|
}
|
5752
5791
|
return typeResult;
|
5753
5792
|
}
|
5754
|
-
function getTypeOfAssertType(node, inferenceContext) {
|
5793
|
+
function getTypeOfAssertType(node, inferenceContext, signatureTracker) {
|
5755
5794
|
if (node.arguments.length !== 2 ||
|
5756
5795
|
node.arguments[0].argumentCategory !== 0 /* ArgumentCategory.Simple */ ||
|
5757
5796
|
node.arguments[0].name !== undefined ||
|
@@ -5761,7 +5800,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5761
5800
|
return { type: types_1.UnknownType.create() };
|
5762
5801
|
}
|
5763
5802
|
const arg0TypeResult = getTypeOfExpression(node.arguments[0].valueExpression,
|
5764
|
-
/* flags */ undefined, inferenceContext);
|
5803
|
+
/* flags */ undefined, inferenceContext, signatureTracker);
|
5765
5804
|
if (arg0TypeResult.isIncomplete) {
|
5766
5805
|
return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
|
5767
5806
|
}
|
@@ -5775,7 +5814,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5775
5814
|
}
|
5776
5815
|
return { type: arg0TypeResult.type };
|
5777
5816
|
}
|
5778
|
-
function getTypeOfRevealType(node, inferenceContext) {
|
5817
|
+
function getTypeOfRevealType(node, inferenceContext, signatureTracker) {
|
5779
5818
|
let arg0Value;
|
5780
5819
|
let expectedRevealTypeNode;
|
5781
5820
|
let expectedRevealType;
|
@@ -5812,7 +5851,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5812
5851
|
addError(localize_1.LocMessage.revealTypeArgs(), node);
|
5813
5852
|
return { type: types_1.UnknownType.create() };
|
5814
5853
|
}
|
5815
|
-
const typeResult = getTypeOfExpression(arg0Value, /* flags */ undefined, inferenceContext);
|
5854
|
+
const typeResult = getTypeOfExpression(arg0Value, /* flags */ undefined, inferenceContext, signatureTracker);
|
5816
5855
|
const type = typeResult.type;
|
5817
5856
|
const exprString = ParseTreeUtils.printExpression(arg0Value);
|
5818
5857
|
const typeString = printType(type, { expandTypeAlias: true });
|
@@ -6095,7 +6134,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6095
6134
|
// there will be only one argument list in expandedArgTypes, and all entries
|
6096
6135
|
// (one for each argument) will be undefined. On subsequent calls, this
|
6097
6136
|
// list will grow to include union expansions.
|
6098
|
-
function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, inferenceContext) {
|
6137
|
+
function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker) {
|
6099
6138
|
var _a, _b;
|
6100
6139
|
const returnTypes = [];
|
6101
6140
|
const matchedOverloads = [];
|
@@ -6131,7 +6170,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6131
6170
|
// record any final types in the type cache.
|
6132
6171
|
const callResult = useSpeculativeMode(errorNode, () => {
|
6133
6172
|
return validateFunctionArgumentTypesWithContext(errorNode, matchResults, effectiveTypeVarContext,
|
6134
|
-
/* skipUnknownArgCheck */ true, inferenceContext);
|
6173
|
+
/* skipUnknownArgCheck */ true, inferenceContext, signatureTracker);
|
6135
6174
|
});
|
6136
6175
|
if (callResult.isTypeIncomplete) {
|
6137
6176
|
isTypeIncomplete = true;
|
@@ -6240,7 +6279,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6240
6279
|
const finalTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : matchedOverloads[0].typeVarContext;
|
6241
6280
|
finalTypeVarContext.unlock();
|
6242
6281
|
finalTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(matchedOverloads[0].overload));
|
6243
|
-
const finalCallResult = validateFunctionArgumentTypesWithContext(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck, inferenceContext);
|
6282
|
+
const finalCallResult = validateFunctionArgumentTypesWithContext(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
|
6244
6283
|
if (finalCallResult.isTypeIncomplete) {
|
6245
6284
|
isTypeIncomplete = true;
|
6246
6285
|
}
|
@@ -6306,7 +6345,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6306
6345
|
// Create a list of potential overload matches based on arguments.
|
6307
6346
|
types_1.OverloadedFunctionType.getOverloads(typeResult.type).forEach((overload) => {
|
6308
6347
|
useSpeculativeMode(errorNode, () => {
|
6309
|
-
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex
|
6348
|
+
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex,
|
6349
|
+
/* signatureTracker */ undefined);
|
6310
6350
|
if (!matchResults.argumentErrors) {
|
6311
6351
|
matches.push(matchResults);
|
6312
6352
|
}
|
@@ -6337,7 +6377,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6337
6377
|
return a.overloadIndex - b.overloadIndex;
|
6338
6378
|
});
|
6339
6379
|
}
|
6340
|
-
function validateOverloadedFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck, inferenceContext) {
|
6380
|
+
function validateOverloadedFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker) {
|
6341
6381
|
let filteredMatchResults = [];
|
6342
6382
|
let contextFreeArgTypes;
|
6343
6383
|
let isTypeIncomplete = !!typeResult.isIncomplete;
|
@@ -6352,7 +6392,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6352
6392
|
// Consider only the functions that have the @overload decorator,
|
6353
6393
|
// not the final function that omits the overload. This is the
|
6354
6394
|
// intended behavior according to PEP 484.
|
6355
|
-
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
|
6395
|
+
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex, signatureTracker);
|
6356
6396
|
if (!matchResults.argumentErrors) {
|
6357
6397
|
filteredMatchResults.push(matchResults);
|
6358
6398
|
}
|
@@ -6369,7 +6409,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6369
6409
|
const functionName = typeResult.type.overloads[0].details.name || '<anonymous function>';
|
6370
6410
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
6371
6411
|
const argTypes = argList.map((t) => {
|
6372
|
-
const typeString = printType(getTypeOfArgument(t).type);
|
6412
|
+
const typeString = printType(getTypeOfArgument(t, /* inferenceContext */ undefined, signatureTracker).type);
|
6373
6413
|
if (t.argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
|
6374
6414
|
return `*${typeString}`;
|
6375
6415
|
}
|
@@ -6408,7 +6448,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6408
6448
|
const effectiveTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : new typeVarContext_1.TypeVarContext();
|
6409
6449
|
effectiveTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeIds)(bestMatch.overload));
|
6410
6450
|
effectiveTypeVarContext.unlock();
|
6411
|
-
return validateFunctionArgumentTypesWithContext(errorNode, bestMatch, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
|
6451
|
+
return validateFunctionArgumentTypesWithContext(errorNode, bestMatch, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
|
6412
6452
|
}
|
6413
6453
|
// If there is only one possible arg/param match among the overloads,
|
6414
6454
|
// use the normal type matching mechanism because it is faster and
|
@@ -6420,7 +6460,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6420
6460
|
}
|
6421
6461
|
let expandedArgTypes = [argList.map((arg) => undefined)];
|
6422
6462
|
while (true) {
|
6423
|
-
const callResult = validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, filteredMatchResults, typeVarContext, skipUnknownArgCheck, inferenceContext);
|
6463
|
+
const callResult = validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, filteredMatchResults, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
|
6424
6464
|
if (callResult.isTypeIncomplete) {
|
6425
6465
|
isTypeIncomplete = true;
|
6426
6466
|
}
|
@@ -6518,7 +6558,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6518
6558
|
// list, specializes the call based on arg types, and returns the
|
6519
6559
|
// specialized type of the return value. If it detects an error along
|
6520
6560
|
// the way, it emits a diagnostic and sets argumentErrors to true.
|
6521
|
-
function validateCallArguments(errorNode, argList, callTypeResult, typeVarContext, skipUnknownArgCheck
|
6561
|
+
function validateCallArguments(errorNode, argList, callTypeResult, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount = 0) {
|
6522
6562
|
let argumentErrors = false;
|
6523
6563
|
let isTypeIncomplete = false;
|
6524
6564
|
let specializedInitSelfType;
|
@@ -6537,7 +6577,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6537
6577
|
}
|
6538
6578
|
let returnType = mapSubtypesExpandTypeVars(callTypeResult.type, { sortSubtypes: true }, (expandedSubtype, unexpandedSubtype, isLastIteration) => {
|
6539
6579
|
return useSpeculativeMode(isLastIteration ? undefined : errorNode, () => {
|
6540
|
-
const callResult = validateCallArgumentsForSubtype(errorNode, argList, expandedSubtype, unexpandedSubtype, !!callTypeResult.isIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
6580
|
+
const callResult = validateCallArgumentsForSubtype(errorNode, argList, expandedSubtype, unexpandedSubtype, !!callTypeResult.isIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount);
|
6541
6581
|
if (callResult.argumentErrors) {
|
6542
6582
|
argumentErrors = true;
|
6543
6583
|
}
|
@@ -6567,7 +6607,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6567
6607
|
overloadsUsedForCall,
|
6568
6608
|
};
|
6569
6609
|
}
|
6570
|
-
function validateCallArgumentsForSubtype(errorNode, argList, expandedCallType, unexpandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount) {
|
6610
|
+
function validateCallArgumentsForSubtype(errorNode, argList, expandedCallType, unexpandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount) {
|
6571
6611
|
switch (expandedCallType.category) {
|
6572
6612
|
case 3 /* TypeCategory.Never */:
|
6573
6613
|
case 1 /* TypeCategory.Unknown */:
|
@@ -6578,17 +6618,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6578
6618
|
if (!isCallTypeIncomplete) {
|
6579
6619
|
argList.forEach((arg) => {
|
6580
6620
|
if (arg.valueExpression && !isSpeculativeModeInUse(arg.valueExpression)) {
|
6581
|
-
getTypeOfArgument(arg);
|
6621
|
+
getTypeOfArgument(arg, /* inferenceContext */ undefined, signatureTracker);
|
6582
6622
|
}
|
6583
6623
|
});
|
6584
6624
|
}
|
6585
6625
|
return { returnType: expandedCallType };
|
6586
6626
|
}
|
6587
6627
|
case 4 /* TypeCategory.Function */: {
|
6588
|
-
return validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext);
|
6628
|
+
return validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
|
6589
6629
|
}
|
6590
6630
|
case 5 /* TypeCategory.OverloadedFunction */: {
|
6591
|
-
return validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext);
|
6631
|
+
return validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
|
6592
6632
|
}
|
6593
6633
|
case 6 /* TypeCategory.Class */: {
|
6594
6634
|
if ((0, typeUtils_1.isNoneInstance)(expandedCallType)) {
|
@@ -6596,16 +6636,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6596
6636
|
return { argumentErrors: true };
|
6597
6637
|
}
|
6598
6638
|
if (types_1.TypeBase.isInstantiable(expandedCallType)) {
|
6599
|
-
return validateCallForInstantiableClass(errorNode, argList, expandedCallType, unexpandedCallType, skipUnknownArgCheck, inferenceContext);
|
6639
|
+
return validateCallForInstantiableClass(errorNode, argList, expandedCallType, unexpandedCallType, skipUnknownArgCheck, inferenceContext, signatureTracker);
|
6600
6640
|
}
|
6601
|
-
return validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
6641
|
+
return validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount);
|
6602
6642
|
}
|
6603
6643
|
// TypeVars should have been expanded in most cases,
|
6604
6644
|
// but we still need to handle the case of Type[T] where
|
6605
6645
|
// T is a constrained type that contains a union. We also
|
6606
6646
|
// need to handle recursive type aliases.
|
6607
6647
|
case 9 /* TypeCategory.TypeVar */: {
|
6608
|
-
return validateCallArguments(errorNode, argList, { type: (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expandedCallType), isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
6648
|
+
return validateCallArguments(errorNode, argList, { type: (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expandedCallType), isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount);
|
6609
6649
|
}
|
6610
6650
|
case 7 /* TypeCategory.Module */: {
|
6611
6651
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.moduleNotCallable(), errorNode);
|
@@ -6614,7 +6654,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6614
6654
|
}
|
6615
6655
|
return { argumentErrors: true };
|
6616
6656
|
}
|
6617
|
-
function validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext) {
|
6657
|
+
function validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker) {
|
6618
6658
|
var _a;
|
6619
6659
|
if (types_1.TypeBase.isInstantiable(expandedCallType)) {
|
6620
6660
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.callableNotInstantiable().format({
|
@@ -6634,14 +6674,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6634
6674
|
const result = {
|
6635
6675
|
returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList, /* includesTypes */ false),
|
6636
6676
|
};
|
6637
|
-
validateFunctionArguments(errorNode, argList, { type: expandedCallType }, effectiveTypeVarContext, skipUnknownArgCheck);
|
6677
|
+
validateFunctionArguments(errorNode, argList, { type: expandedCallType }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
|
6638
6678
|
return result;
|
6639
6679
|
}
|
6640
6680
|
// Handle the NewType specially, replacing the normal return type.
|
6641
6681
|
if (expandedCallType.details.builtInName === 'NewType') {
|
6642
6682
|
return { returnType: createNewType(errorNode, argList) };
|
6643
6683
|
}
|
6644
|
-
const functionResult = validateFunctionArguments(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
|
6684
|
+
const functionResult = validateFunctionArguments(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
|
6645
6685
|
let isTypeIncomplete = !!functionResult.isTypeIncomplete;
|
6646
6686
|
let returnType = functionResult.returnType;
|
6647
6687
|
let argumentErrors = !!functionResult.argumentErrors;
|
@@ -6748,13 +6788,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6748
6788
|
}
|
6749
6789
|
return { symbol, symbolName, classType, hasImplementation };
|
6750
6790
|
}
|
6751
|
-
function validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext) {
|
6791
|
+
function validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker) {
|
6752
6792
|
var _a, _b;
|
6753
6793
|
// Handle the 'cast' call as a special case.
|
6754
6794
|
if (expandedCallType.overloads[0].details.builtInName === 'cast' && argList.length === 2) {
|
6755
6795
|
return { returnType: evaluateCastCall(argList, errorNode) };
|
6756
6796
|
}
|
6757
|
-
const callResult = validateOverloadedFunctionArguments(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext);
|
6797
|
+
const callResult = validateOverloadedFunctionArguments(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
|
6758
6798
|
let returnType = (_a = callResult.returnType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
6759
6799
|
let isTypeIncomplete = !!callResult.isTypeIncomplete;
|
6760
6800
|
let argumentErrors = !!callResult.argumentErrors;
|
@@ -6781,7 +6821,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6781
6821
|
specializedInitSelfType: callResult.specializedInitSelfType,
|
6782
6822
|
};
|
6783
6823
|
}
|
6784
|
-
function validateCallForInstantiableClass(errorNode, argList, expandedCallType, unexpandedCallType, skipUnknownArgCheck, inferenceContext) {
|
6824
|
+
function validateCallForInstantiableClass(errorNode, argList, expandedCallType, unexpandedCallType, skipUnknownArgCheck, inferenceContext, signatureTracker) {
|
6785
6825
|
var _a, _b;
|
6786
6826
|
if (expandedCallType.literalValue !== undefined) {
|
6787
6827
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.literalNotCallable(), errorNode);
|
@@ -6798,11 +6838,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6798
6838
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true };
|
6799
6839
|
}
|
6800
6840
|
// Validate the constructor arguments.
|
6801
|
-
(0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedCallType, skipUnknownArgCheck, inferenceContext);
|
6841
|
+
(0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedCallType, skipUnknownArgCheck, inferenceContext, signatureTracker);
|
6802
6842
|
// The one-parameter form of "type" returns the class
|
6803
6843
|
// for the specified object.
|
6804
6844
|
if (expandedCallType.details.name === 'type' && argList.length === 1) {
|
6805
|
-
const argType = getTypeOfArgument(argList[0]
|
6845
|
+
const argType = getTypeOfArgument(argList[0],
|
6846
|
+
/* inferenceContext */ undefined, signatureTracker).type;
|
6806
6847
|
const returnType = (0, typeUtils_1.mapSubtypes)(argType, (subtype) => {
|
6807
6848
|
if ((0, types_1.isInstantiableClass)(subtype) && subtype.details.effectiveMetaclass) {
|
6808
6849
|
return subtype.details.effectiveMetaclass;
|
@@ -6864,7 +6905,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6864
6905
|
if (initTypeResult && (0, types_1.isOverloadedFunction)(initTypeResult.type)) {
|
6865
6906
|
validateOverloadedFunctionArguments(errorNode, argList, { type: initTypeResult.type },
|
6866
6907
|
/* typeVarContext */ undefined, skipUnknownArgCheck,
|
6867
|
-
/* inferenceContext */ undefined);
|
6908
|
+
/* inferenceContext */ undefined, signatureTracker);
|
6868
6909
|
}
|
6869
6910
|
return result;
|
6870
6911
|
}
|
@@ -6926,7 +6967,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6926
6967
|
}), errorNode);
|
6927
6968
|
}
|
6928
6969
|
// Assume this is a call to the constructor.
|
6929
|
-
const constructorResult = (0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedCallType, skipUnknownArgCheck, inferenceContext);
|
6970
|
+
const constructorResult = (0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedCallType, skipUnknownArgCheck, inferenceContext, signatureTracker);
|
6930
6971
|
const overloadsUsedForCall = constructorResult.overloadsUsedForCall;
|
6931
6972
|
const argumentErrors = constructorResult.argumentErrors;
|
6932
6973
|
const isTypeIncomplete = constructorResult.isTypeIncomplete;
|
@@ -6945,7 +6986,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6945
6986
|
returnType.details.mro.some((baseClass) => (0, types_1.isInstantiableClass)(baseClass) && types_1.ClassType.isBuiltIn(baseClass, 'type'))) {
|
6946
6987
|
let newClassName = '__class_' + returnType.details.name;
|
6947
6988
|
if (argList.length === 3) {
|
6948
|
-
const firstArgType = getTypeOfArgument(argList[0]
|
6989
|
+
const firstArgType = getTypeOfArgument(argList[0],
|
6990
|
+
/* inferenceContext */ undefined, signatureTracker).type;
|
6949
6991
|
if ((0, types_1.isClassInstance)(firstArgType) &&
|
6950
6992
|
types_1.ClassType.isBuiltIn(firstArgType, 'str') &&
|
6951
6993
|
typeof firstArgType.literalValue === 'string') {
|
@@ -6961,7 +7003,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6961
7003
|
}
|
6962
7004
|
return { returnType, overloadsUsedForCall, argumentErrors, isTypeIncomplete };
|
6963
7005
|
}
|
6964
|
-
function validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount) {
|
7006
|
+
function validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount) {
|
6965
7007
|
var _a;
|
6966
7008
|
const callDiag = new diagnostic_1.DiagnosticAddendum();
|
6967
7009
|
const callMethodResult = getTypeOfBoundMember(errorNode, expandedCallType, '__call__',
|
@@ -6974,7 +7016,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6974
7016
|
}) + callDiag.getString(), errorNode);
|
6975
7017
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true };
|
6976
7018
|
}
|
6977
|
-
const callResult = validateCallArguments(errorNode, argList, { type: callMethodType }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
7019
|
+
const callResult = validateCallArguments(errorNode, argList, { type: callMethodType }, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount);
|
6978
7020
|
let returnType = (_a = callResult.returnType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
6979
7021
|
if ((0, types_1.isTypeVar)(unexpandedCallType) &&
|
6980
7022
|
types_1.TypeBase.isInstantiable(unexpandedCallType) &&
|
@@ -6994,7 +7036,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6994
7036
|
function evaluateCastCall(argList, errorNode) {
|
6995
7037
|
// Verify that the cast is necessary.
|
6996
7038
|
const castToType = getTypeOfArgumentExpectingType(argList[0], { enforceTypeAnnotationRules: true }).type;
|
6997
|
-
let castFromType = getTypeOfArgument(argList[1]
|
7039
|
+
let castFromType = getTypeOfArgument(argList[1],
|
7040
|
+
/* inferenceContext */ undefined,
|
7041
|
+
/* signatureTracker */ undefined).type;
|
6998
7042
|
if (castFromType.specialForm) {
|
6999
7043
|
castFromType = castFromType.specialForm;
|
7000
7044
|
}
|
@@ -7010,12 +7054,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7010
7054
|
return (0, typeUtils_1.convertToInstance)(castToType);
|
7011
7055
|
}
|
7012
7056
|
// Expands any unpacked tuples within an argument list.
|
7013
|
-
function expandArgList(argList) {
|
7057
|
+
function expandArgList(argList, signatureTracker) {
|
7014
7058
|
var _a;
|
7015
7059
|
const expandedArgList = [];
|
7016
7060
|
for (const arg of argList) {
|
7017
7061
|
if (arg.argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
|
7018
|
-
const argType = getTypeOfArgument(arg).type;
|
7062
|
+
const argType = getTypeOfArgument(arg, /* inferenceContext */ undefined, signatureTracker).type;
|
7019
7063
|
// If this is a tuple with specified element types, use those
|
7020
7064
|
// specified types rather than using the more generic iterator
|
7021
7065
|
// type which will be a union of all element types.
|
@@ -7057,7 +7101,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7057
7101
|
// function. This matching is done based on positions and keywords. Type evaluation and
|
7058
7102
|
// validation is left to the caller.
|
7059
7103
|
// This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
|
7060
|
-
function matchFunctionArgumentsToParameters(errorNode, argList, typeResult, overloadIndex) {
|
7104
|
+
function matchFunctionArgumentsToParameters(errorNode, argList, typeResult, overloadIndex, signatureTracker) {
|
7061
7105
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
7062
7106
|
const paramDetails = (0, parameterUtils_1.getParameterListDetails)(typeResult.type);
|
7063
7107
|
let argIndex = 0;
|
@@ -7066,7 +7110,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7066
7110
|
let isTypeIncomplete = !!typeResult.isIncomplete;
|
7067
7111
|
let isVariadicTypeVarFullyMatched = false;
|
7068
7112
|
// Expand any unpacked tuples in the arg list.
|
7069
|
-
argList = expandArgList(argList);
|
7113
|
+
argList = expandArgList(argList, signatureTracker);
|
7070
7114
|
// Build a map of parameters by name.
|
7071
7115
|
const paramMap = new Map();
|
7072
7116
|
paramDetails.params.forEach((paramInfo) => {
|
@@ -7076,7 +7120,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7076
7120
|
paramMap.set(param.name, {
|
7077
7121
|
argsNeeded: param.category === 0 /* ParameterCategory.Simple */ && !param.hasDefault ? 1 : 0,
|
7078
7122
|
argsReceived: 0,
|
7079
|
-
isPositionalOnly: paramInfo.
|
7123
|
+
isPositionalOnly: paramInfo.kind === parameterUtils_1.ParameterKind.Positional,
|
7080
7124
|
});
|
7081
7125
|
}
|
7082
7126
|
});
|
@@ -7190,7 +7234,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7190
7234
|
// If this is an unpacked iterable, we will conservatively assume that it
|
7191
7235
|
// might have zero iterations unless we can tell from its type that it
|
7192
7236
|
// definitely has at least one iterable value.
|
7193
|
-
const argType = getTypeOfArgument(argList[argIndex]
|
7237
|
+
const argType = getTypeOfArgument(argList[argIndex],
|
7238
|
+
/* inferenceContext */ undefined, signatureTracker).type;
|
7194
7239
|
if ((0, types_1.isClassInstance)(argType) &&
|
7195
7240
|
(0, typeUtils_1.isTupleClass)(argType) &&
|
7196
7241
|
!(0, typeUtils_1.isUnboundedTupleClass)(argType) &&
|
@@ -7225,7 +7270,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7225
7270
|
(0, types_1.isVariadicTypeVar)(paramType);
|
7226
7271
|
if (argList[argIndex].argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
|
7227
7272
|
let isArgCompatibleWithVariadic = false;
|
7228
|
-
const argTypeResult = getTypeOfArgument(argList[argIndex]
|
7273
|
+
const argTypeResult = getTypeOfArgument(argList[argIndex],
|
7274
|
+
/* inferenceContext */ undefined, signatureTracker);
|
7229
7275
|
let listElementType;
|
7230
7276
|
let advanceToNextArg = false;
|
7231
7277
|
// Handle the case where *args is being passed to a function defined
|
@@ -7460,7 +7506,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7460
7506
|
while (argIndex < argList.length) {
|
7461
7507
|
if (argList[argIndex].argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */) {
|
7462
7508
|
// Verify that the type used in this expression is a SupportsKeysAndGetItem[str, T].
|
7463
|
-
const argType = getTypeOfArgument(argList[argIndex], (0, typeUtils_1.makeInferenceContext)(paramDetails.unpackedKwargsTypedDictType)).type;
|
7509
|
+
const argType = getTypeOfArgument(argList[argIndex], (0, typeUtils_1.makeInferenceContext)(paramDetails.unpackedKwargsTypedDictType), signatureTracker).type;
|
7464
7510
|
if ((0, types_1.isAnyOrUnknown)(argType)) {
|
7465
7511
|
unpackedDictionaryArgType = argType;
|
7466
7512
|
}
|
@@ -7675,7 +7721,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7675
7721
|
// Handle the case where a *args: P.args (or *args: Any) is passed as an
|
7676
7722
|
// argument to a function that accepts a ParamSpec.
|
7677
7723
|
if (typeResult.type.details.paramSpec) {
|
7678
|
-
const argTypeResult = getTypeOfArgument(argList[argIndex]
|
7724
|
+
const argTypeResult = getTypeOfArgument(argList[argIndex],
|
7725
|
+
/* inferenceContext */ undefined, signatureTracker);
|
7679
7726
|
const argType = argTypeResult.type;
|
7680
7727
|
if (argTypeResult.isIncomplete) {
|
7681
7728
|
isTypeIncomplete = true;
|
@@ -7798,7 +7845,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7798
7845
|
if ((0, types_1.isVariadicTypeVar)(paramType) && !paramType.isVariadicInUnion) {
|
7799
7846
|
const tupleTypeArgs = variadicArgs.map((argParam) => {
|
7800
7847
|
var _a;
|
7801
|
-
const argType = getTypeOfArgument(argParam.argument
|
7848
|
+
const argType = getTypeOfArgument(argParam.argument,
|
7849
|
+
/* inferenceContext */ undefined, signatureTracker).type;
|
7802
7850
|
const containsVariadicTypeVar = (0, types_1.isUnpackedVariadicTypeVar)(argType) ||
|
7803
7851
|
((0, types_1.isClassInstance)(argType) &&
|
7804
7852
|
(0, typeUtils_1.isTupleClass)(argType) &&
|
@@ -7878,10 +7926,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7878
7926
|
// After having matched arguments with parameters, this function evaluates the
|
7879
7927
|
// types of each argument expression and validates that the resulting type is
|
7880
7928
|
// compatible with the declared type of the corresponding parameter.
|
7881
|
-
function validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
|
7882
|
-
var _a
|
7929
|
+
function validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext, signatureTracker) {
|
7930
|
+
var _a;
|
7883
7931
|
const type = matchResults.overload;
|
7884
|
-
|
7932
|
+
if (!signatureTracker) {
|
7933
|
+
signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
7934
|
+
}
|
7885
7935
|
matchResults.overload = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(matchResults.overload, signatureTracker, errorNode.start);
|
7886
7936
|
// Can we safely ignore the inference context (either because it's not provided
|
7887
7937
|
// or will have no effect)? If so, we can eliminate a bunch of extra work.
|
@@ -7889,7 +7939,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7889
7939
|
(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) ||
|
7890
7940
|
(0, types_1.isNever)(inferenceContext.expectedType) ||
|
7891
7941
|
!type.details.declaredReturnType ||
|
7892
|
-
!(0, typeUtils_1.requiresSpecialization)((
|
7942
|
+
!(0, typeUtils_1.requiresSpecialization)((_a = types_1.FunctionType.getSpecializedReturnType(type)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create())) {
|
7893
7943
|
return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck);
|
7894
7944
|
}
|
7895
7945
|
const effectiveReturnType = getFunctionEffectiveReturnType(type);
|
@@ -7972,7 +8022,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7972
8022
|
}
|
7973
8023
|
return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck);
|
7974
8024
|
}
|
7975
|
-
function validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck
|
8025
|
+
function validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck) {
|
7976
8026
|
const type = matchResults.overload;
|
7977
8027
|
let isTypeIncomplete = matchResults.isTypeIncomplete;
|
7978
8028
|
let argumentErrors = false;
|
@@ -8289,11 +8339,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8289
8339
|
// Tries to assign the call arguments to the function parameter
|
8290
8340
|
// list and reports any mismatches in types or counts. Returns the
|
8291
8341
|
// specialized return type of the call.
|
8292
|
-
function validateFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
|
8293
|
-
|
8294
|
-
|
8342
|
+
function validateFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck = false, inferenceContext, signatureTracker) {
|
8343
|
+
if (!signatureTracker) {
|
8344
|
+
signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
8345
|
+
}
|
8295
8346
|
typeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(typeResult.type, signatureTracker, errorNode.start);
|
8296
|
-
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, typeResult, 0);
|
8347
|
+
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, typeResult, 0, signatureTracker);
|
8297
8348
|
if (matchResults.argumentErrors) {
|
8298
8349
|
// Evaluate types of all args. This will ensure that referenced symbols are
|
8299
8350
|
// not reported as unaccessed.
|
@@ -8308,7 +8359,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8308
8359
|
overloadsUsedForCall: [],
|
8309
8360
|
};
|
8310
8361
|
}
|
8311
|
-
return validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck, (0, typeUtils_1.makeInferenceContext)(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete, signatureTracker)
|
8362
|
+
return validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck, (0, typeUtils_1.makeInferenceContext)(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete), signatureTracker);
|
8312
8363
|
}
|
8313
8364
|
// Determines whether the specified argument list satisfies the function
|
8314
8365
|
// signature bound to the specified ParamSpec. Return value indicates success.
|
@@ -8344,7 +8395,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8344
8395
|
if (!paramSpecType) {
|
8345
8396
|
paramSpecType = (0, typeUtils_1.convertTypeToParamSpecValue)(paramSpec);
|
8346
8397
|
}
|
8347
|
-
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: paramSpecType }, 0);
|
8398
|
+
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: paramSpecType }, 0, signatureTracker);
|
8348
8399
|
const functionType = matchResults.overload;
|
8349
8400
|
const srcTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(paramSpecType));
|
8350
8401
|
if (matchResults.argumentErrors) {
|
@@ -8369,7 +8420,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8369
8420
|
let argumentErrors = false;
|
8370
8421
|
let argErrorNode;
|
8371
8422
|
for (const arg of argList) {
|
8372
|
-
const argType = (_a = getTypeOfArgument(arg)) === null || _a === void 0 ? void 0 : _a.type;
|
8423
|
+
const argType = (_a = getTypeOfArgument(arg, /* inferenceContext */ undefined, signatureTracker)) === null || _a === void 0 ? void 0 : _a.type;
|
8373
8424
|
const isArgTypeCompatible = argType && ((0, types_1.isTypeSame)(argType, paramSpec, { ignoreTypeFlags: true }) || (0, types_1.isAnyOrUnknown)(argType));
|
8374
8425
|
if (arg.argumentCategory === 1 /* ArgumentCategory.UnpackedList */ && !sawArgs && isArgTypeCompatible) {
|
8375
8426
|
sawArgs = true;
|
@@ -8394,7 +8445,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8394
8445
|
}
|
8395
8446
|
return { argumentErrors, typeVarContexts: [srcTypeVarContext] };
|
8396
8447
|
}
|
8397
|
-
const result = validateFunctionArgumentTypes(errorNode, matchResults, srcTypeVarContext, signatureTracker
|
8448
|
+
const result = validateFunctionArgumentTypes(errorNode, matchResults, srcTypeVarContext, signatureTracker,
|
8449
|
+
/* skipUnknownArgCheck */ undefined);
|
8398
8450
|
return { argumentErrors: !!result.argumentErrors, typeVarContexts: [srcTypeVarContext] };
|
8399
8451
|
}
|
8400
8452
|
function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, options) {
|
@@ -8457,7 +8509,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8457
8509
|
16 /* EvaluatorFlags.DisallowFinal */ |
|
8458
8510
|
2 /* EvaluatorFlags.DoNotSpecialize */
|
8459
8511
|
: 2 /* EvaluatorFlags.DoNotSpecialize */ | 16 /* EvaluatorFlags.DisallowFinal */;
|
8460
|
-
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete), signatureTracker)
|
8512
|
+
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete)), signatureTracker);
|
8461
8513
|
argType = exprTypeResult.type;
|
8462
8514
|
// If the type includes multiple instances of a generic function
|
8463
8515
|
// signature, force the type arguments for the duplicates to have
|
@@ -8492,7 +8544,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8492
8544
|
argType = argParam.argType;
|
8493
8545
|
}
|
8494
8546
|
else {
|
8495
|
-
const argTypeResult = getTypeOfArgument(argParam.argument
|
8547
|
+
const argTypeResult = getTypeOfArgument(argParam.argument,
|
8548
|
+
/* inferenceContext */ undefined, signatureTracker);
|
8496
8549
|
argType = argTypeResult.type;
|
8497
8550
|
if (argTypeResult.isIncomplete) {
|
8498
8551
|
isTypeIncomplete = true;
|
@@ -9190,12 +9243,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9190
9243
|
// Implements the semantics of the multi-parameter variant of the "type" call.
|
9191
9244
|
function createClassFromMetaclass(errorNode, argList, metaclass) {
|
9192
9245
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
9193
|
-
const arg0Type = getTypeOfArgument(argList[0]
|
9246
|
+
const arg0Type = getTypeOfArgument(argList[0],
|
9247
|
+
/* inferenceContext */ undefined,
|
9248
|
+
/* signatureTracker */ undefined).type;
|
9194
9249
|
if (!(0, types_1.isClassInstance)(arg0Type) || !types_1.ClassType.isBuiltIn(arg0Type, 'str')) {
|
9195
9250
|
return undefined;
|
9196
9251
|
}
|
9197
9252
|
const className = arg0Type.literalValue || '_';
|
9198
|
-
const arg1Type = getTypeOfArgument(argList[1]
|
9253
|
+
const arg1Type = getTypeOfArgument(argList[1],
|
9254
|
+
/* inferenceContext */ undefined,
|
9255
|
+
/* signatureTracker */ undefined).type;
|
9199
9256
|
// TODO - properly handle case where tuple of base classes is provided.
|
9200
9257
|
if (!(0, types_1.isClassInstance)(arg1Type) || !(0, typeUtils_1.isTupleClass)(arg1Type) || arg1Type.tupleTypeArguments === undefined) {
|
9201
9258
|
return undefined;
|
@@ -9258,7 +9315,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9258
9315
|
(0, debug_1.assert)(magicMethodType !== undefined);
|
9259
9316
|
return validateCallArguments(errorNode, functionArgs, { type: magicMethodType },
|
9260
9317
|
/* typeVarContext */ undefined,
|
9261
|
-
/* skipUnknownArgCheck */ true, inferenceContext
|
9318
|
+
/* skipUnknownArgCheck */ true, inferenceContext,
|
9319
|
+
/* signatureTracker */ undefined);
|
9262
9320
|
});
|
9263
9321
|
// If there were errors with the expected type, try
|
9264
9322
|
// to evaluate without the expected type.
|
@@ -9267,7 +9325,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9267
9325
|
(0, debug_1.assert)(magicMethodType !== undefined);
|
9268
9326
|
return validateCallArguments(errorNode, functionArgs, { type: magicMethodType },
|
9269
9327
|
/* typeVarContext */ undefined,
|
9270
|
-
/* skipUnknownArgCheck */ true
|
9328
|
+
/* skipUnknownArgCheck */ true,
|
9329
|
+
/* inferenceContext */ undefined,
|
9330
|
+
/* signatureTracker */ undefined);
|
9271
9331
|
});
|
9272
9332
|
}
|
9273
9333
|
if (callResult.argumentErrors) {
|
@@ -9325,7 +9385,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9325
9385
|
return;
|
9326
9386
|
}
|
9327
9387
|
const subtypeResult = useSpeculativeMode(node, () => {
|
9328
|
-
return getTypeOfDictionaryWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype));
|
9388
|
+
return getTypeOfDictionaryWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(subtype));
|
9329
9389
|
});
|
9330
9390
|
if (subtypeResult && assignType(subtype, subtypeResult.type)) {
|
9331
9391
|
// If this is the first result we're seeing or it's the first result
|
@@ -9342,15 +9402,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9342
9402
|
let expectedTypeDiagAddendum = undefined;
|
9343
9403
|
if (effectiveExpectedType) {
|
9344
9404
|
expectedTypeDiagAddendum = new diagnostic_1.DiagnosticAddendum();
|
9345
|
-
const result = getTypeOfDictionaryWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType), expectedTypeDiagAddendum);
|
9405
|
+
const result = getTypeOfDictionaryWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType), expectedTypeDiagAddendum);
|
9346
9406
|
if (result) {
|
9347
9407
|
return result;
|
9348
9408
|
}
|
9349
9409
|
}
|
9350
|
-
const result = getTypeOfDictionaryInferred(node, /* hasExpectedType */ !!inferenceContext);
|
9410
|
+
const result = getTypeOfDictionaryInferred(node, flags, /* hasExpectedType */ !!inferenceContext);
|
9351
9411
|
return { ...result, expectedTypeDiagAddendum };
|
9352
9412
|
}
|
9353
|
-
function getTypeOfDictionaryWithContext(node, inferenceContext, expectedDiagAddendum) {
|
9413
|
+
function getTypeOfDictionaryWithContext(node, flags, inferenceContext, expectedDiagAddendum) {
|
9354
9414
|
inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
|
9355
9415
|
let concreteExpectedType = makeTopLevelTypeVarsConcrete(inferenceContext.expectedType);
|
9356
9416
|
if (!(0, types_1.isClassInstance)(concreteExpectedType)) {
|
@@ -9367,7 +9427,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9367
9427
|
concreteExpectedType = types_1.TypeBase.cloneForCondition(concreteExpectedType, undefined);
|
9368
9428
|
const expectedTypedDictEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, concreteExpectedType);
|
9369
9429
|
// Infer the key and value types if possible.
|
9370
|
-
const keyValueTypeResult = getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
|
9430
|
+
const keyValueTypeResult = getKeyAndValueTypesFromDictionary(node, flags, keyTypes, valueTypes,
|
9371
9431
|
/* forceStrictInference */ true,
|
9372
9432
|
/* isValueTypeInvariant */ true,
|
9373
9433
|
/* expectedKeyType */ undefined,
|
@@ -9425,7 +9485,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9425
9485
|
}
|
9426
9486
|
}
|
9427
9487
|
// Infer the key and value types if possible.
|
9428
|
-
const keyValueResult = getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
|
9488
|
+
const keyValueResult = getKeyAndValueTypesFromDictionary(node, flags, keyTypes, valueTypes,
|
9429
9489
|
/* forceStrictInference */ true, isValueTypeInvariant, expectedKeyType, expectedValueType, undefined, expectedDiagAddendum);
|
9430
9490
|
if (keyValueResult.isIncomplete) {
|
9431
9491
|
isIncomplete = true;
|
@@ -9444,7 +9504,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9444
9504
|
}
|
9445
9505
|
// Attempts to infer the type of a dictionary statement. If hasExpectedType
|
9446
9506
|
// is true, strict inference is used for the subexpressions.
|
9447
|
-
function getTypeOfDictionaryInferred(node, hasExpectedType) {
|
9507
|
+
function getTypeOfDictionaryInferred(node, flags, hasExpectedType) {
|
9448
9508
|
const fallbackType = hasExpectedType ? types_1.AnyType.create() : types_1.UnknownType.create();
|
9449
9509
|
let keyType = fallbackType;
|
9450
9510
|
let valueType = fallbackType;
|
@@ -9454,7 +9514,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9454
9514
|
let isIncomplete = false;
|
9455
9515
|
let typeErrors = false;
|
9456
9516
|
// Infer the key and value types if possible.
|
9457
|
-
const keyValueResult = getKeyAndValueTypesFromDictionary(node, keyTypeResults, valueTypeResults,
|
9517
|
+
const keyValueResult = getKeyAndValueTypesFromDictionary(node, flags, keyTypeResults, valueTypeResults,
|
9458
9518
|
/* forceStrictInference */ hasExpectedType,
|
9459
9519
|
/* isValueTypeInvariant */ false);
|
9460
9520
|
if (keyValueResult.isIncomplete) {
|
@@ -9498,16 +9558,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9498
9558
|
}
|
9499
9559
|
return { type, isIncomplete, typeErrors };
|
9500
9560
|
}
|
9501
|
-
function getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes, forceStrictInference, isValueTypeInvariant, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum) {
|
9561
|
+
function getKeyAndValueTypesFromDictionary(node, flags, keyTypes, valueTypes, forceStrictInference, isValueTypeInvariant, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum) {
|
9502
9562
|
let isIncomplete = false;
|
9503
9563
|
let typeErrors = false;
|
9564
|
+
// Mask out some of the flags that are not applicable for a dictionary key
|
9565
|
+
// even if it appears within an inlined TypedDict annotation.
|
9566
|
+
const keyFlags = flags &
|
9567
|
+
~(256 /* EvaluatorFlags.ExpectingTypeAnnotation */ |
|
9568
|
+
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
|
9569
|
+
128 /* EvaluatorFlags.ExpectingInstantiableType */);
|
9504
9570
|
// Infer the key and value types if possible.
|
9505
9571
|
node.entries.forEach((entryNode, index) => {
|
9506
9572
|
var _a, _b, _c, _d;
|
9507
9573
|
let addUnknown = true;
|
9508
9574
|
if (entryNode.nodeType === 17 /* ParseNodeType.DictionaryKeyEntry */) {
|
9509
|
-
const keyTypeResult = getTypeOfExpression(entryNode.keyExpression,
|
9510
|
-
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedKeyType !== null && expectedKeyType !== void 0 ? expectedKeyType : (forceStrictInference ? types_1.NeverType.createNever() : undefined)));
|
9575
|
+
const keyTypeResult = getTypeOfExpression(entryNode.keyExpression, keyFlags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedKeyType !== null && expectedKeyType !== void 0 ? expectedKeyType : (forceStrictInference ? types_1.NeverType.createNever() : undefined)));
|
9511
9576
|
if (keyTypeResult.isIncomplete) {
|
9512
9577
|
isIncomplete = true;
|
9513
9578
|
}
|
@@ -9530,14 +9595,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9530
9595
|
expectedTypedDictEntries.knownItems.has(keyType.literalValue)) {
|
9531
9596
|
const effectiveValueType = expectedTypedDictEntries.knownItems.get(keyType.literalValue).valueType;
|
9532
9597
|
entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
|
9533
|
-
valueTypeResult = getTypeOfExpression(entryNode.valueExpression,
|
9534
|
-
/* flags */ undefined, entryInferenceContext);
|
9598
|
+
valueTypeResult = getTypeOfExpression(entryNode.valueExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, entryInferenceContext);
|
9535
9599
|
}
|
9536
9600
|
else {
|
9537
9601
|
const effectiveValueType = expectedValueType !== null && expectedValueType !== void 0 ? expectedValueType : (forceStrictInference ? types_1.NeverType.createNever() : undefined);
|
9538
9602
|
entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
|
9539
|
-
valueTypeResult = getTypeOfExpression(entryNode.valueExpression,
|
9540
|
-
/* flags */ undefined, entryInferenceContext);
|
9603
|
+
valueTypeResult = getTypeOfExpression(entryNode.valueExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, entryInferenceContext);
|
9541
9604
|
}
|
9542
9605
|
if (entryInferenceContext && !valueTypeResult.typeErrors) {
|
9543
9606
|
const fromExpectedType = inferTypeArgFromExpectedEntryType(entryInferenceContext, [valueTypeResult.type], !isValueTypeInvariant);
|
@@ -9579,8 +9642,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9579
9642
|
}
|
9580
9643
|
}
|
9581
9644
|
const entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(expectedType);
|
9582
|
-
let unexpandedTypeResult = getTypeOfExpression(entryNode.expandExpression,
|
9583
|
-
/* flags */ undefined, entryInferenceContext);
|
9645
|
+
let unexpandedTypeResult = getTypeOfExpression(entryNode.expandExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, entryInferenceContext);
|
9584
9646
|
if (entryInferenceContext && !unexpandedTypeResult.typeErrors) {
|
9585
9647
|
const fromExpectedType = inferTypeArgFromExpectedEntryType(entryInferenceContext, [unexpandedTypeResult.type], !isValueTypeInvariant);
|
9586
9648
|
if (fromExpectedType) {
|
@@ -9645,7 +9707,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9645
9707
|
}
|
9646
9708
|
}
|
9647
9709
|
else if (entryNode.nodeType === 32 /* ParseNodeType.ListComprehension */) {
|
9648
|
-
const dictEntryTypeResult = getElementTypeFromListComprehension(entryNode, expectedValueType, expectedKeyType);
|
9710
|
+
const dictEntryTypeResult = getElementTypeFromListComprehension(entryNode, flags, expectedValueType, expectedKeyType);
|
9649
9711
|
const dictEntryType = dictEntryTypeResult.type;
|
9650
9712
|
if (dictEntryTypeResult.isIncomplete) {
|
9651
9713
|
isIncomplete = true;
|
@@ -9683,6 +9745,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9683
9745
|
diag.addMessage(localize_1.LocAddendum.useListInstead());
|
9684
9746
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.listInAnnotation() + diag.getString(), node);
|
9685
9747
|
}
|
9748
|
+
flags &= ~(256 /* EvaluatorFlags.ExpectingTypeAnnotation */ |
|
9749
|
+
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
|
9750
|
+
128 /* EvaluatorFlags.ExpectingInstantiableType */);
|
9686
9751
|
// If the expected type is a union, recursively call for each of the subtypes
|
9687
9752
|
// to find one that matches.
|
9688
9753
|
let effectiveExpectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
|
@@ -9695,7 +9760,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9695
9760
|
return;
|
9696
9761
|
}
|
9697
9762
|
const subtypeResult = useSpeculativeMode(node, () => {
|
9698
|
-
return getTypeOfListOrSetWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype));
|
9763
|
+
return getTypeOfListOrSetWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(subtype));
|
9699
9764
|
});
|
9700
9765
|
if (subtypeResult && assignType(subtype, subtypeResult.type)) {
|
9701
9766
|
// If this is the first result we're seeing or it's the first result
|
@@ -9711,18 +9776,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9711
9776
|
}
|
9712
9777
|
let expectedTypeDiagAddendum;
|
9713
9778
|
if (effectiveExpectedType) {
|
9714
|
-
const result = getTypeOfListOrSetWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType));
|
9779
|
+
const result = getTypeOfListOrSetWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType));
|
9715
9780
|
if (result && !result.typeErrors) {
|
9716
9781
|
return result;
|
9717
9782
|
}
|
9718
9783
|
expectedTypeDiagAddendum = result === null || result === void 0 ? void 0 : result.expectedTypeDiagAddendum;
|
9719
9784
|
}
|
9720
|
-
const typeResult = getTypeOfListOrSetInferred(node,
|
9785
|
+
const typeResult = getTypeOfListOrSetInferred(node, flags,
|
9786
|
+
/* hasExpectedType */ inferenceContext !== undefined);
|
9721
9787
|
return { ...typeResult, expectedTypeDiagAddendum };
|
9722
9788
|
}
|
9723
9789
|
// Attempts to determine the type of a list or set statement based on an expected type.
|
9724
9790
|
// Returns undefined if that type cannot be honored.
|
9725
|
-
function getTypeOfListOrSetWithContext(node, inferenceContext) {
|
9791
|
+
function getTypeOfListOrSetWithContext(node, flags, inferenceContext) {
|
9726
9792
|
const builtInClassName = node.nodeType === 31 /* ParseNodeType.List */ ? 'list' : 'set';
|
9727
9793
|
inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
|
9728
9794
|
let isIncomplete = false;
|
@@ -9737,11 +9803,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9737
9803
|
node.entries.forEach((entry) => {
|
9738
9804
|
let entryTypeResult;
|
9739
9805
|
if (entry.nodeType === 32 /* ParseNodeType.ListComprehension */) {
|
9740
|
-
entryTypeResult = getElementTypeFromListComprehension(entry, expectedEntryType);
|
9806
|
+
entryTypeResult = getElementTypeFromListComprehension(entry, flags, expectedEntryType);
|
9741
9807
|
}
|
9742
9808
|
else {
|
9743
|
-
entryTypeResult = getTypeOfExpression(entry,
|
9744
|
-
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedEntryType));
|
9809
|
+
entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedEntryType));
|
9745
9810
|
}
|
9746
9811
|
entryTypes.push(entryTypeResult.type);
|
9747
9812
|
if (entryTypeResult.isIncomplete) {
|
@@ -9795,7 +9860,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9795
9860
|
return specializedListOrSet.typeArguments[0];
|
9796
9861
|
}
|
9797
9862
|
// Attempts to infer the type of a list or set statement with no "expected type".
|
9798
|
-
function getTypeOfListOrSetInferred(node, hasExpectedType) {
|
9863
|
+
function getTypeOfListOrSetInferred(node, flags, hasExpectedType) {
|
9799
9864
|
const builtInClassName = node.nodeType === 31 /* ParseNodeType.List */ ? 'list' : 'set';
|
9800
9865
|
const verifyHashable = node.nodeType === 45 /* ParseNodeType.Set */;
|
9801
9866
|
let isEmptyContainer = false;
|
@@ -9805,10 +9870,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9805
9870
|
node.entries.forEach((entry, index) => {
|
9806
9871
|
let entryTypeResult;
|
9807
9872
|
if (entry.nodeType === 32 /* ParseNodeType.ListComprehension */ && !entry.isGenerator) {
|
9808
|
-
entryTypeResult = getElementTypeFromListComprehension(entry);
|
9873
|
+
entryTypeResult = getElementTypeFromListComprehension(entry, flags);
|
9809
9874
|
}
|
9810
9875
|
else {
|
9811
|
-
entryTypeResult = getTypeOfExpression(entry);
|
9876
|
+
entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */);
|
9812
9877
|
}
|
9813
9878
|
if (entryTypeResult.isIncomplete) {
|
9814
9879
|
isIncomplete = true;
|
@@ -10124,7 +10189,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10124
10189
|
}
|
10125
10190
|
return { type: functionType, isIncomplete, typeErrors };
|
10126
10191
|
}
|
10127
|
-
function getTypeOfListComprehension(node, inferenceContext) {
|
10192
|
+
function getTypeOfListComprehension(node, flags, inferenceContext) {
|
10128
10193
|
let isIncomplete = false;
|
10129
10194
|
let typeErrors = false;
|
10130
10195
|
// If any of the "for" clauses are marked async or any of the "if" clauses
|
@@ -10142,7 +10207,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10142
10207
|
}
|
10143
10208
|
const builtInIteratorType = getTypingType(node, isAsync ? 'AsyncGenerator' : 'Generator');
|
10144
10209
|
const expectedEntryType = getExpectedEntryTypeForIterable(node, builtInIteratorType, inferenceContext);
|
10145
|
-
const elementTypeResult = getElementTypeFromListComprehension(node, expectedEntryType);
|
10210
|
+
const elementTypeResult = getElementTypeFromListComprehension(node, flags, expectedEntryType);
|
10146
10211
|
if (elementTypeResult.isIncomplete) {
|
10147
10212
|
isIncomplete = true;
|
10148
10213
|
}
|
@@ -10212,7 +10277,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10212
10277
|
}
|
10213
10278
|
// Returns the type of one entry returned by the list comprehension,
|
10214
10279
|
// as opposed to the entire list.
|
10215
|
-
function getElementTypeFromListComprehension(node, expectedValueOrElementType, expectedKeyType) {
|
10280
|
+
function getElementTypeFromListComprehension(node, flags, expectedValueOrElementType, expectedKeyType) {
|
10216
10281
|
let isIncomplete = false;
|
10217
10282
|
let typeErrors = false;
|
10218
10283
|
// "Execute" the list comprehensions from start to finish.
|
@@ -10224,8 +10289,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10224
10289
|
let type = types_1.UnknownType.create();
|
10225
10290
|
if (node.expression.nodeType === 17 /* ParseNodeType.DictionaryKeyEntry */) {
|
10226
10291
|
// Create a tuple with the key/value types.
|
10227
|
-
const keyTypeResult = getTypeOfExpression(node.expression.keyExpression,
|
10228
|
-
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedKeyType));
|
10292
|
+
const keyTypeResult = getTypeOfExpression(node.expression.keyExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedKeyType));
|
10229
10293
|
if (keyTypeResult.isIncomplete) {
|
10230
10294
|
isIncomplete = true;
|
10231
10295
|
}
|
@@ -10236,8 +10300,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10236
10300
|
if (!expectedKeyType || !(0, typeUtils_1.containsLiteralType)(expectedKeyType)) {
|
10237
10301
|
keyType = stripLiteralValue(keyType);
|
10238
10302
|
}
|
10239
|
-
const valueTypeResult = getTypeOfExpression(node.expression.valueExpression,
|
10240
|
-
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
|
10303
|
+
const valueTypeResult = getTypeOfExpression(node.expression.valueExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
|
10241
10304
|
if (valueTypeResult.isIncomplete) {
|
10242
10305
|
isIncomplete = true;
|
10243
10306
|
}
|
@@ -10255,12 +10318,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10255
10318
|
}
|
10256
10319
|
else if (node.expression.nodeType === 16 /* ParseNodeType.DictionaryExpandEntry */) {
|
10257
10320
|
// The parser should have reported an error in this case because it's not allowed.
|
10258
|
-
getTypeOfExpression(node.expression.expandExpression,
|
10259
|
-
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
|
10321
|
+
getTypeOfExpression(node.expression.expandExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
|
10260
10322
|
}
|
10261
10323
|
else if ((0, parseNodes_1.isExpressionNode)(node)) {
|
10262
|
-
const exprTypeResult = getTypeOfExpression(node.expression,
|
10263
|
-
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
|
10324
|
+
const exprTypeResult = getTypeOfExpression(node.expression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
|
10264
10325
|
if (exprTypeResult.isIncomplete) {
|
10265
10326
|
isIncomplete = true;
|
10266
10327
|
}
|
@@ -12448,7 +12509,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12448
12509
|
if (initSubclassMethodType && initSubclassMethodInfo.classType) {
|
12449
12510
|
const callResult = validateCallArguments(errorNode, argList, { type: initSubclassMethodType },
|
12450
12511
|
/* typeVarContext */ undefined,
|
12451
|
-
/* skipUnknownArgCheck */ false, (0, typeUtils_1.makeInferenceContext)(getNoneType())
|
12512
|
+
/* skipUnknownArgCheck */ false, (0, typeUtils_1.makeInferenceContext)(getNoneType()),
|
12513
|
+
/* signatureTracker */ undefined);
|
12452
12514
|
if (callResult.argumentErrors) {
|
12453
12515
|
const diag = addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.initSubclassCallFailed(), node.name);
|
12454
12516
|
const initSubclassFunction = (0, types_1.isOverloadedFunction)(initSubclassMethodType)
|
@@ -14547,9 +14609,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14547
14609
|
const specializedClass = types_1.ClassType.cloneForSpecialization(classType, typeArgTypes, typeArgs !== undefined);
|
14548
14610
|
return { type: specializedClass };
|
14549
14611
|
}
|
14550
|
-
function getTypeOfArgument(arg, inferenceContext) {
|
14612
|
+
function getTypeOfArgument(arg, inferenceContext, signatureTracker) {
|
14613
|
+
var _a, _b;
|
14551
14614
|
if (arg.typeResult) {
|
14552
|
-
|
14615
|
+
const type = (_b = (_a = arg.typeResult.type) === null || _a === void 0 ? void 0 : _a.specialForm) !== null && _b !== void 0 ? _b : arg.typeResult.type;
|
14616
|
+
return { type, isIncomplete: arg.typeResult.isIncomplete };
|
14553
14617
|
}
|
14554
14618
|
if (!arg.valueExpression) {
|
14555
14619
|
// We shouldn't ever get here, but just in case.
|
@@ -14557,7 +14621,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14557
14621
|
}
|
14558
14622
|
// If there was no defined type provided, there should always
|
14559
14623
|
// be a value expression from which we can retrieve the type.
|
14560
|
-
|
14624
|
+
const typeResult = getTypeOfExpression(arg.valueExpression,
|
14625
|
+
/* flags */ undefined, inferenceContext, signatureTracker);
|
14626
|
+
if (signatureTracker) {
|
14627
|
+
typeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(typeResult.type, signatureTracker, arg.valueExpression.start);
|
14628
|
+
}
|
14629
|
+
return typeResult;
|
14561
14630
|
}
|
14562
14631
|
// This function is like getTypeOfArgument except that it is
|
14563
14632
|
// used in cases where the argument is expected to be a type
|
@@ -15832,7 +15901,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15832
15901
|
function getFunctionEffectiveReturnType(type, callSiteInfo, inferTypeIfNeeded = true) {
|
15833
15902
|
const specializedReturnType = types_1.FunctionType.getSpecializedReturnType(type, /* includeInferred */ false);
|
15834
15903
|
if (specializedReturnType && !(0, types_1.isUnknown)(specializedReturnType)) {
|
15835
|
-
|
15904
|
+
const liveTypeVarScopes = (callSiteInfo === null || callSiteInfo === void 0 ? void 0 : callSiteInfo.errorNode)
|
15905
|
+
? ParseTreeUtils.getTypeVarScopesForNode(callSiteInfo === null || callSiteInfo === void 0 ? void 0 : callSiteInfo.errorNode)
|
15906
|
+
: [];
|
15907
|
+
return adjustCallableReturnType(type, specializedReturnType, liveTypeVarScopes);
|
15836
15908
|
}
|
15837
15909
|
if (inferTypeIfNeeded) {
|
15838
15910
|
return getFunctionInferredReturnType(type, callSiteInfo);
|
@@ -16224,24 +16296,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16224
16296
|
return true;
|
16225
16297
|
}
|
16226
16298
|
}
|
16227
|
-
|
16228
|
-
|
16229
|
-
|
16230
|
-
|
16231
|
-
|
16232
|
-
|
16233
|
-
destErrorTypeText
|
16234
|
-
|
16235
|
-
|
16236
|
-
|
16237
|
-
|
16238
|
-
|
16239
|
-
|
16240
|
-
|
16241
|
-
|
16242
|
-
|
16243
|
-
|
16244
|
-
|
16299
|
+
if (diag) {
|
16300
|
+
const destErrorType = reportErrorsUsingObjType ? types_1.ClassType.cloneAsInstance(destType) : destType;
|
16301
|
+
const srcErrorType = reportErrorsUsingObjType ? types_1.ClassType.cloneAsInstance(srcType) : srcType;
|
16302
|
+
let destErrorTypeText = printType(destErrorType);
|
16303
|
+
let srcErrorTypeText = printType(srcErrorType);
|
16304
|
+
// If the text is the same, use the fully-qualified name rather than the short name.
|
16305
|
+
if (destErrorTypeText === srcErrorTypeText && destType.details.fullName && srcType.details.fullName) {
|
16306
|
+
destErrorTypeText = destType.details.fullName;
|
16307
|
+
srcErrorTypeText = srcType.details.fullName;
|
16308
|
+
}
|
16309
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeIncompatible().format({
|
16310
|
+
sourceType: srcErrorTypeText,
|
16311
|
+
destType: destErrorTypeText,
|
16312
|
+
}));
|
16313
|
+
// Tell the user about the disableBytesTypePromotions if that is involved.
|
16314
|
+
if (types_1.ClassType.isBuiltIn(destType, 'bytes')) {
|
16315
|
+
const promotions = typePromotions.get(destType.details.fullName);
|
16316
|
+
if (promotions && promotions.some((name) => name === srcType.details.fullName)) {
|
16317
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.bytesTypePromotions());
|
16318
|
+
}
|
16245
16319
|
}
|
16246
16320
|
}
|
16247
16321
|
return false;
|
@@ -17058,9 +17132,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17058
17132
|
if (types_1.ClassType.isBuiltIn(destType, 'type') && ((_c = srcType.instantiableNestingLevel) !== null && _c !== void 0 ? _c : 0) > 0) {
|
17059
17133
|
return true;
|
17060
17134
|
}
|
17061
|
-
if (
|
17062
|
-
|
17063
|
-
|
17135
|
+
if (isSpecialFormClass(expandedSrcType, flags)) {
|
17136
|
+
if (destType.specialForm) {
|
17137
|
+
return assignType(destType.specialForm, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
|
17138
|
+
}
|
17139
|
+
}
|
17140
|
+
else if (assignClass(destType, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
|
17141
|
+
/* reportErrorsUsingObjType */ false)) {
|
17064
17142
|
return true;
|
17065
17143
|
}
|
17066
17144
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
@@ -17818,7 +17896,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17818
17896
|
}
|
17819
17897
|
let srcLastToPackIndex = srcDetails.params.findIndex((p, i) => {
|
17820
17898
|
(0, debug_1.assert)(destDetails.argsIndex !== undefined);
|
17821
|
-
return i >= destDetails.argsIndex && p.
|
17899
|
+
return i >= destDetails.argsIndex && p.kind === parameterUtils_1.ParameterKind.Keyword;
|
17822
17900
|
});
|
17823
17901
|
if (srcLastToPackIndex < 0) {
|
17824
17902
|
srcLastToPackIndex = srcDetails.params.length;
|
@@ -17866,7 +17944,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17866
17944
|
},
|
17867
17945
|
type: srcPositionalsType,
|
17868
17946
|
index: -1,
|
17869
|
-
|
17947
|
+
kind: parameterUtils_1.ParameterKind.Positional,
|
17870
17948
|
},
|
17871
17949
|
...srcDetails.params.slice(destDetails.argsIndex + srcPositionalsToPack.length, srcDetails.params.length),
|
17872
17950
|
];
|
@@ -17874,15 +17952,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17874
17952
|
srcDetails.argsIndex = argsIndex >= 0 ? argsIndex : undefined;
|
17875
17953
|
const kwargsIndex = srcDetails.params.findIndex((param) => param.param.category === 2 /* ParameterCategory.KwargsDict */);
|
17876
17954
|
srcDetails.kwargsIndex = kwargsIndex >= 0 ? kwargsIndex : undefined;
|
17877
|
-
const firstKeywordOnlyIndex = srcDetails.params.findIndex((param) => param.
|
17955
|
+
const firstKeywordOnlyIndex = srcDetails.params.findIndex((param) => param.kind === parameterUtils_1.ParameterKind.Keyword);
|
17878
17956
|
srcDetails.firstKeywordOnlyIndex = firstKeywordOnlyIndex >= 0 ? firstKeywordOnlyIndex : undefined;
|
17879
|
-
srcDetails.positionOnlyParamCount = Math.max(0, srcDetails.params.findIndex((p) => p.
|
17957
|
+
srcDetails.positionOnlyParamCount = Math.max(0, srcDetails.params.findIndex((p) => p.kind !== parameterUtils_1.ParameterKind.Positional ||
|
17880
17958
|
p.param.category !== 0 /* ParameterCategory.Simple */ ||
|
17881
17959
|
p.param.hasDefault));
|
17882
17960
|
}
|
17883
17961
|
}
|
17884
17962
|
function assignFunction(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
|
17885
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
17963
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
17886
17964
|
let canAssign = true;
|
17887
17965
|
const checkReturnType = (flags & 64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */) === 0;
|
17888
17966
|
const reverseMatching = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) !== 0;
|
@@ -17918,11 +17996,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17918
17996
|
const destParamName = (_c = destParam.param.name) !== null && _c !== void 0 ? _c : '';
|
17919
17997
|
const srcParamName = (_d = srcParam.param.name) !== null && _d !== void 0 ? _d : '';
|
17920
17998
|
if (destParamName) {
|
17921
|
-
const isDestPositionalOnly = destParam.
|
17999
|
+
const isDestPositionalOnly = destParam.kind === parameterUtils_1.ParameterKind.Positional;
|
17922
18000
|
if (!isDestPositionalOnly &&
|
17923
18001
|
destParam.param.category !== 1 /* ParameterCategory.ArgsList */ &&
|
17924
18002
|
srcParam.param.category !== 1 /* ParameterCategory.ArgsList */) {
|
17925
|
-
if (srcParam.
|
18003
|
+
if (srcParam.kind === parameterUtils_1.ParameterKind.Positional) {
|
17926
18004
|
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionParamPositionOnly().format({
|
17927
18005
|
name: destParamName,
|
17928
18006
|
}));
|
@@ -17968,10 +18046,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17968
18046
|
canAssign = false;
|
17969
18047
|
}
|
17970
18048
|
}
|
17971
|
-
else if (destParam.
|
17972
|
-
srcParam.
|
18049
|
+
else if (destParam.kind !== parameterUtils_1.ParameterKind.Positional &&
|
18050
|
+
srcParam.kind === parameterUtils_1.ParameterKind.Positional &&
|
17973
18051
|
srcParamDetails.kwargsIndex === undefined &&
|
17974
|
-
!srcParamDetails.params.some((p) => p.
|
18052
|
+
!srcParamDetails.params.some((p) => p.kind === parameterUtils_1.ParameterKind.Keyword &&
|
17975
18053
|
p.param.category === 0 /* ParameterCategory.Simple */ &&
|
17976
18054
|
p.param.name === destParam.param.name)) {
|
17977
18055
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.namedParamMissingInSource().format({
|
@@ -17989,36 +18067,50 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17989
18067
|
}));
|
17990
18068
|
canAssign = false;
|
17991
18069
|
}
|
17992
|
-
if (destPositionalCount < srcPositionalCount) {
|
17993
|
-
|
17994
|
-
|
17995
|
-
|
17996
|
-
|
17997
|
-
|
17998
|
-
|
17999
|
-
|
18000
|
-
|
18001
|
-
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionTooFewParams().format({
|
18002
|
-
expected: nonDefaultSrcParamCount,
|
18003
|
-
received: destPositionalCount,
|
18004
|
-
}));
|
18005
|
-
canAssign = false;
|
18006
|
-
}
|
18070
|
+
if (destPositionalCount < srcPositionalCount && !targetIncludesParamSpec) {
|
18071
|
+
for (let i = destPositionalCount; i < srcPositionalCount; i++) {
|
18072
|
+
// If the dest has an *args parameter, make sure it can accept the remaining
|
18073
|
+
// positional arguments in the source.
|
18074
|
+
if (destParamDetails.argsIndex !== undefined) {
|
18075
|
+
const destArgsType = destParamDetails.params[destParamDetails.argsIndex].type;
|
18076
|
+
const srcParamType = srcParamDetails.params[i].type;
|
18077
|
+
if (!assignFunctionParameter(destArgsType, srcParamType, i, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
18078
|
+
canAssign = false;
|
18007
18079
|
}
|
18080
|
+
continue;
|
18008
18081
|
}
|
18009
|
-
|
18010
|
-
|
18011
|
-
|
18012
|
-
|
18013
|
-
|
18014
|
-
|
18015
|
-
|
18016
|
-
|
18017
|
-
|
18018
|
-
|
18019
|
-
|
18082
|
+
// If The source parameter has a default value, it is OK for the
|
18083
|
+
// corresponding dest parameter to be missing.
|
18084
|
+
const srcParam = srcParamDetails.params[i];
|
18085
|
+
if (srcParam.param.hasDefault) {
|
18086
|
+
// Assign default arg value in case it is needed for
|
18087
|
+
// populating TypeVar constraints.
|
18088
|
+
const paramInfo = srcParamDetails.params[i];
|
18089
|
+
const defaultArgType = (_f = paramInfo.defaultArgType) !== null && _f !== void 0 ? _f : paramInfo.param.defaultType;
|
18090
|
+
if (defaultArgType &&
|
18091
|
+
!assignType(paramInfo.type, defaultArgType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), srcTypeVarContext,
|
18092
|
+
/* destTypeVarContext */ undefined, flags, recursionCount)) {
|
18093
|
+
canAssign = false;
|
18020
18094
|
}
|
18095
|
+
continue;
|
18096
|
+
}
|
18097
|
+
// If the source parameter is also addressible by keyword, it is OK
|
18098
|
+
// that there is no matching positional parameter in the dest.
|
18099
|
+
if (srcParam.kind === parameterUtils_1.ParameterKind.Standard) {
|
18100
|
+
continue;
|
18101
|
+
}
|
18102
|
+
// If the source parameter is a variadic, it is OK that there is no
|
18103
|
+
// matching positional parameter in the dest.
|
18104
|
+
if (srcParam.param.category === 1 /* ParameterCategory.ArgsList */) {
|
18105
|
+
continue;
|
18021
18106
|
}
|
18107
|
+
const nonDefaultSrcParamCount = srcParamDetails.params.filter((p) => !!p.param.name && !p.param.hasDefault && p.param.category === 0 /* ParameterCategory.Simple */).length;
|
18108
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionTooFewParams().format({
|
18109
|
+
expected: nonDefaultSrcParamCount,
|
18110
|
+
received: destPositionalCount,
|
18111
|
+
}));
|
18112
|
+
canAssign = false;
|
18113
|
+
break;
|
18022
18114
|
}
|
18023
18115
|
}
|
18024
18116
|
else if (srcPositionalCount < destPositionalCount) {
|
@@ -18039,10 +18131,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18039
18131
|
if (!assignFunctionParameter(destParamType, srcArgsType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
18040
18132
|
canAssign = false;
|
18041
18133
|
}
|
18042
|
-
if (destParamDetails.params[paramIndex].
|
18134
|
+
if (destParamDetails.params[paramIndex].kind !== parameterUtils_1.ParameterKind.Positional &&
|
18043
18135
|
srcParamDetails.kwargsIndex === undefined) {
|
18044
18136
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.namedParamMissingInSource().format({
|
18045
|
-
name: (
|
18137
|
+
name: (_g = destParamDetails.params[paramIndex].param.name) !== null && _g !== void 0 ? _g : '',
|
18046
18138
|
}));
|
18047
18139
|
canAssign = false;
|
18048
18140
|
}
|
@@ -18090,7 +18182,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18090
18182
|
destParamDetails.argsIndex !== undefined &&
|
18091
18183
|
!destParamDetails.hasUnpackedVariadicTypeVar) {
|
18092
18184
|
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.argsParamMissing().format({
|
18093
|
-
paramName: (
|
18185
|
+
paramName: (_h = destParamDetails.params[destParamDetails.argsIndex].param.name) !== null && _h !== void 0 ? _h : '',
|
18094
18186
|
}));
|
18095
18187
|
canAssign = false;
|
18096
18188
|
}
|
@@ -18117,16 +18209,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18117
18209
|
}
|
18118
18210
|
if (srcStartOfNamed >= 0) {
|
18119
18211
|
srcParamDetails.params.forEach((srcParamInfo, index) => {
|
18212
|
+
var _a;
|
18120
18213
|
if (index >= srcStartOfNamed) {
|
18121
18214
|
if (srcParamInfo.param.name &&
|
18122
18215
|
srcParamInfo.param.category === 0 /* ParameterCategory.Simple */ &&
|
18123
|
-
srcParamInfo.
|
18216
|
+
srcParamInfo.kind !== parameterUtils_1.ParameterKind.Positional) {
|
18124
18217
|
const destParamInfo = destParamMap.get(srcParamInfo.param.name);
|
18125
18218
|
const paramDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
|
18126
18219
|
const srcParamType = srcParamInfo.type;
|
18127
18220
|
if (!destParamInfo) {
|
18128
18221
|
if (destParamDetails.kwargsIndex === undefined && !srcParamInfo.param.hasDefault) {
|
18129
|
-
if (paramDiag
|
18222
|
+
if (paramDiag) {
|
18130
18223
|
paramDiag.addMessage(localize_1.LocAddendum.namedParamMissingInDest().format({
|
18131
18224
|
name: srcParamInfo.param.name,
|
18132
18225
|
}));
|
@@ -18139,6 +18232,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18139
18232
|
canAssign = false;
|
18140
18233
|
}
|
18141
18234
|
}
|
18235
|
+
else if (srcParamInfo.param.hasDefault) {
|
18236
|
+
// Assign default arg values in case they are needed for
|
18237
|
+
// populating TypeVar constraints.
|
18238
|
+
const defaultArgType = (_a = srcParamInfo.defaultArgType) !== null && _a !== void 0 ? _a : srcParamInfo.param.defaultType;
|
18239
|
+
if (defaultArgType &&
|
18240
|
+
!assignType(srcParamInfo.type, defaultArgType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), srcTypeVarContext,
|
18241
|
+
/* destTypeVarContext */ undefined, flags, recursionCount)) {
|
18242
|
+
canAssign = false;
|
18243
|
+
}
|
18244
|
+
}
|
18142
18245
|
}
|
18143
18246
|
else {
|
18144
18247
|
const destParamType = destParamInfo.type;
|
@@ -18203,7 +18306,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18203
18306
|
// If the source and the dest are using the same ParamSpec, any additional
|
18204
18307
|
// concatenated parameters must match.
|
18205
18308
|
if (targetIncludesParamSpec &&
|
18206
|
-
((
|
18309
|
+
((_j = srcType.details.paramSpec) === null || _j === void 0 ? void 0 : _j.nameWithScope) === ((_k = destType.details.paramSpec) === null || _k === void 0 ? void 0 : _k.nameWithScope)) {
|
18207
18310
|
if (srcParamDetails.params.length !== destParamDetails.params.length) {
|
18208
18311
|
canAssign = false;
|
18209
18312
|
}
|
@@ -18673,13 +18776,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18673
18776
|
const overrideParam = overrideParamDetails.params[i].param;
|
18674
18777
|
if (i >= baseParamDetails.positionOnlyParamCount &&
|
18675
18778
|
!(0, symbolNameUtils_1.isPrivateOrProtectedName)(baseParam.name || '') &&
|
18676
|
-
baseParamDetails.params[i].
|
18779
|
+
baseParamDetails.params[i].kind !== parameterUtils_1.ParameterKind.Positional &&
|
18677
18780
|
baseParam.category === 0 /* ParameterCategory.Simple */ &&
|
18678
18781
|
enforceParamNames &&
|
18679
18782
|
baseParam.name !== overrideParam.name) {
|
18680
18783
|
if (overrideParam.category === 0 /* ParameterCategory.Simple */) {
|
18681
18784
|
if (!baseParam.isNameSynthesized) {
|
18682
|
-
if (overrideParamDetails.params[i].
|
18785
|
+
if (overrideParamDetails.params[i].kind === parameterUtils_1.ParameterKind.Positional) {
|
18683
18786
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
|
18684
18787
|
index: i + 1,
|
18685
18788
|
baseName: baseParam.name || '*',
|
@@ -18698,8 +18801,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18698
18801
|
}
|
18699
18802
|
else if (i < overrideParamDetails.positionOnlyParamCount &&
|
18700
18803
|
i >= baseParamDetails.positionOnlyParamCount) {
|
18701
|
-
if (!baseParam.isNameSynthesized &&
|
18702
|
-
baseParamDetails.params[i].source !== parameterUtils_1.ParameterSource.PositionOnly) {
|
18804
|
+
if (!baseParam.isNameSynthesized && baseParamDetails.params[i].kind !== parameterUtils_1.ParameterKind.Positional) {
|
18703
18805
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
|
18704
18806
|
index: i + 1,
|
18705
18807
|
baseName: baseParam.name || '*',
|
@@ -18737,7 +18839,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18737
18839
|
if (enforceParamNames && overrideParamDetails.kwargsIndex === undefined) {
|
18738
18840
|
for (let i = positionalParamCount; i < baseParamDetails.positionParamCount; i++) {
|
18739
18841
|
const baseParam = baseParamDetails.params[i];
|
18740
|
-
if (baseParam.
|
18842
|
+
if (baseParam.kind === parameterUtils_1.ParameterKind.Standard &&
|
18741
18843
|
baseParam.param.category === 0 /* ParameterCategory.Simple */) {
|
18742
18844
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
|
18743
18845
|
index: i + 1,
|
@@ -18770,10 +18872,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18770
18872
|
}
|
18771
18873
|
}
|
18772
18874
|
// Now check any keyword-only parameters.
|
18773
|
-
const baseKwOnlyParams = baseParamDetails.params.filter((paramInfo) => paramInfo.
|
18774
|
-
|
18775
|
-
const overrideKwOnlyParams = overrideParamDetails.params.filter((paramInfo) => paramInfo.source === parameterUtils_1.ParameterSource.KeywordOnly &&
|
18776
|
-
paramInfo.param.category === 0 /* ParameterCategory.Simple */);
|
18875
|
+
const baseKwOnlyParams = baseParamDetails.params.filter((paramInfo) => paramInfo.kind === parameterUtils_1.ParameterKind.Keyword && paramInfo.param.category === 0 /* ParameterCategory.Simple */);
|
18876
|
+
const overrideKwOnlyParams = overrideParamDetails.params.filter((paramInfo) => paramInfo.kind === parameterUtils_1.ParameterKind.Keyword && paramInfo.param.category === 0 /* ParameterCategory.Simple */);
|
18777
18877
|
baseKwOnlyParams.forEach((paramInfo) => {
|
18778
18878
|
var _a, _b, _c;
|
18779
18879
|
const overrideParamInfo = overrideKwOnlyParams.find((pi) => paramInfo.param.name === pi.param.name);
|