@zzzen/pyright-internal 1.2.0-dev.20220911 → 1.2.0-dev.20220925
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/binder.js +11 -6
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +10 -4
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +0 -6
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +3 -2
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/service.js +2 -2
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +3 -2
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +122 -54
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -0
- package/dist/analyzer/typeEvaluatorTypes.js +4 -0
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeEvaluatorWithTracker.d.ts +1 -2
- package/dist/analyzer/typeEvaluatorWithTracker.js +39 -103
- package/dist/analyzer/typeEvaluatorWithTracker.js.map +1 -1
- package/dist/analyzer/typeGuards.js +4 -1
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.js +16 -8
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +2 -0
- package/dist/analyzer/types.js +8 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/logTracker.d.ts +1 -0
- package/dist/common/logTracker.js +4 -0
- package/dist/common/logTracker.js.map +1 -1
- package/dist/common/timing.d.ts +1 -1
- package/dist/common/timing.js +3 -3
- package/dist/common/timing.js.map +1 -1
- package/dist/languageService/completionProvider.js +1 -0
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/indentationUtils.d.ts +5 -0
- package/dist/languageService/indentationUtils.js +68 -27
- package/dist/languageService/indentationUtils.js.map +1 -1
- package/dist/languageService/insertionPointUtils.d.ts +2 -2
- package/dist/languageService/insertionPointUtils.js +1 -1
- package/dist/languageService/insertionPointUtils.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +2 -1
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +4 -0
- package/dist/localization/localize.js +1 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +2 -1
- package/dist/parser/parser.js +43 -46
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.d.ts +1 -1
- package/dist/parser/tokenizer.js +46 -20
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/tokenizerTypes.d.ts +3 -1
- package/dist/parser/tokenizerTypes.js +2 -0
- package/dist/parser/tokenizerTypes.js.map +1 -1
- package/dist/tests/fourslash/hover.variable.docString.fourslash.js +3 -0
- package/dist/tests/fourslash/hover.variable.docString.fourslash.js.map +1 -1
- package/dist/tests/fourslash/signature.paramspec.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.paramspec.fourslash.js +30 -0
- package/dist/tests/fourslash/signature.paramspec.fourslash.js.map +1 -0
- package/dist/tests/ipythonMode.test.js +47 -4
- package/dist/tests/ipythonMode.test.js.map +1 -1
- package/dist/tests/logger.test.d.ts +1 -0
- package/dist/tests/logger.test.js +99 -0
- package/dist/tests/logger.test.js.map +1 -0
- package/dist/tests/parser.test.js +2 -2
- package/dist/tests/testUtils.d.ts +4 -1
- package/dist/tests/testUtils.js +10 -4
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/tokenizer.test.js +3 -0
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +2 -2
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +4 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/package.json +3 -3
@@ -1255,13 +1255,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1255
1255
|
// it to the class.
|
1256
1256
|
function getTypeOfClassMember(errorNode, classType, memberName, usage = { method: 'get' }, diag = undefined, memberAccessFlags = 0 /* None */, bindToType) {
|
1257
1257
|
let memberInfo;
|
1258
|
+
const classDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
|
1259
|
+
const metaclassDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
|
1258
1260
|
if (types_1.ClassType.isPartiallyEvaluated(classType)) {
|
1259
1261
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classDefinitionCycle().format({ name: classType.details.name }), errorNode);
|
1260
1262
|
return { type: types_1.UnknownType.create() };
|
1261
1263
|
}
|
1262
1264
|
if ((memberAccessFlags & 32 /* ConsiderMetaclassOnly */) === 0) {
|
1263
1265
|
memberInfo = getTypeOfClassMemberName(errorNode, classType,
|
1264
|
-
/* isAccessedThroughObject */ false, memberName, usage,
|
1266
|
+
/* isAccessedThroughObject */ false, memberName, usage, classDiag, memberAccessFlags | 1 /* AccessClassMembersOnly */, bindToType);
|
1265
1267
|
}
|
1266
1268
|
// If this is a protocol class X and we're accessing a non ClassVar,
|
1267
1269
|
// emit an error.
|
@@ -1278,13 +1280,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1278
1280
|
}), errorNode);
|
1279
1281
|
}
|
1280
1282
|
}
|
1283
|
+
const isMemberPresentOnClass = (memberInfo === null || memberInfo === void 0 ? void 0 : memberInfo.classType) !== undefined;
|
1281
1284
|
// If it wasn't found on the class, see if it's part of the metaclass.
|
1282
1285
|
if (!memberInfo) {
|
1283
1286
|
const metaclass = classType.details.effectiveMetaclass;
|
1284
1287
|
if (metaclass && (0, types_1.isInstantiableClass)(metaclass) && !types_1.ClassType.isSameGenericClass(metaclass, classType)) {
|
1285
1288
|
memberInfo = getTypeOfClassMemberName(errorNode, metaclass,
|
1286
|
-
/* isAccessedThroughObject */ true, memberName, usage,
|
1287
|
-
/* diag */ undefined, memberAccessFlags, classType);
|
1289
|
+
/* isAccessedThroughObject */ true, memberName, usage, metaclassDiag, memberAccessFlags, classType);
|
1288
1290
|
}
|
1289
1291
|
}
|
1290
1292
|
if (memberInfo) {
|
@@ -1294,6 +1296,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1294
1296
|
isAsymmetricDescriptor: memberInfo.isAsymmetricDescriptor,
|
1295
1297
|
};
|
1296
1298
|
}
|
1299
|
+
// Determine whether to use the class or metaclass diagnostic addendum.
|
1300
|
+
const subDiag = isMemberPresentOnClass ? classDiag : metaclassDiag;
|
1301
|
+
if (diag && subDiag) {
|
1302
|
+
diag.addAddendum(subDiag);
|
1303
|
+
}
|
1297
1304
|
return undefined;
|
1298
1305
|
}
|
1299
1306
|
function getBoundMethod(classType, memberName, recursionCount = 0, treatConstructorAsClassMember = false) {
|
@@ -5779,7 +5786,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5779
5786
|
// Validates that the arguments can be assigned to the call's parameter
|
5780
5787
|
// list, specializes the call based on arg types, and returns the
|
5781
5788
|
// specialized type of the return value. If it detects an error along
|
5782
|
-
// the way, it emits a diagnostic and
|
5789
|
+
// the way, it emits a diagnostic and sets argumentErrors to true.
|
5783
5790
|
function validateCallArguments(errorNode, argList, callTypeResult, typeVarContext, skipUnknownArgCheck = false, expectedType, recursionCount = 0) {
|
5784
5791
|
let argumentErrors = false;
|
5785
5792
|
let isTypeIncomplete = false;
|
@@ -6422,6 +6429,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6422
6429
|
paramIndex++;
|
6423
6430
|
}
|
6424
6431
|
}
|
6432
|
+
// If there weren't enough positional arguments to populate all of the
|
6433
|
+
// positional-only parameters and the next positional-only parameter is
|
6434
|
+
// an unbounded tuple, skip past it.
|
6435
|
+
let skippedArgsParam = false;
|
6436
|
+
if (positionalOnlyLimitIndex >= 0 &&
|
6437
|
+
paramIndex < positionalOnlyLimitIndex &&
|
6438
|
+
paramDetails.params[paramIndex].param.category === 1 /* VarArgList */ &&
|
6439
|
+
!(0, types_1.isParamSpec)(paramDetails.params[paramIndex].param.type)) {
|
6440
|
+
paramIndex++;
|
6441
|
+
skippedArgsParam = true;
|
6442
|
+
}
|
6425
6443
|
// Check if there weren't enough positional arguments to populate all of
|
6426
6444
|
// the positional-only parameters.
|
6427
6445
|
if (positionalOnlyLimitIndex >= 0 &&
|
@@ -6431,7 +6449,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6431
6449
|
const positionOnlyWithoutDefaultsCount = firstParamWithDefault >= 0 && firstParamWithDefault < positionalOnlyLimitIndex
|
6432
6450
|
? firstParamWithDefault
|
6433
6451
|
: positionalOnlyLimitIndex;
|
6434
|
-
|
6452
|
+
// Calculate the number of remaining positional parameters to report.
|
6453
|
+
let argsRemainingCount = positionOnlyWithoutDefaultsCount - positionalArgCount;
|
6454
|
+
if (skippedArgsParam) {
|
6455
|
+
// If we skipped an args parameter above, reduce the count by one
|
6456
|
+
// because it's permitted to pass zero arguments to *args.
|
6457
|
+
argsRemainingCount--;
|
6458
|
+
}
|
6459
|
+
const firstArgsParam = paramDetails.params.findIndex((paramInfo) => paramInfo.param.category === 1 /* VarArgList */ && !(0, types_1.isParamSpec)(paramInfo.param.type));
|
6460
|
+
if (firstArgsParam >= paramIndex && firstArgsParam < positionalOnlyLimitIndex) {
|
6461
|
+
// If there is another args parameter beyond the current param index,
|
6462
|
+
// reduce the count by one because it's permitted to pass zero arguments
|
6463
|
+
// to *args.
|
6464
|
+
argsRemainingCount--;
|
6465
|
+
}
|
6435
6466
|
if (argsRemainingCount > 0) {
|
6436
6467
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, argsRemainingCount === 1
|
6437
6468
|
? localize_1.Localizer.Diagnostic.argMorePositionalExpectedOne()
|
@@ -8963,8 +8994,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8963
8994
|
// Remove any expected subtypes that don't satisfy the minimum
|
8964
8995
|
// parameter count requirement.
|
8965
8996
|
expectedFunctionTypes = expectedFunctionTypes.filter((functionType) => {
|
8966
|
-
const
|
8967
|
-
const
|
8997
|
+
const params = types_1.FunctionType.getFunctionParameters(functionType);
|
8998
|
+
const functionParamCount = params.filter((param) => !param.hasDefault).length;
|
8999
|
+
const hasVarArgs = params.some((param) => param.category !== 0 /* Simple */);
|
8968
9000
|
return (hasVarArgs ||
|
8969
9001
|
(functionParamCount >= minLambdaParamCount && functionParamCount <= maxLambdaParamCount));
|
8970
9002
|
});
|
@@ -9057,14 +9089,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9057
9089
|
function getTypeOfListComprehension(node, expectedType) {
|
9058
9090
|
let isIncomplete = false;
|
9059
9091
|
let typeErrors = false;
|
9060
|
-
const elementTypeResult = getElementTypeFromListComprehension(node);
|
9061
|
-
if (elementTypeResult.isIncomplete) {
|
9062
|
-
isIncomplete = true;
|
9063
|
-
}
|
9064
|
-
if (elementTypeResult.typeErrors) {
|
9065
|
-
typeErrors = true;
|
9066
|
-
}
|
9067
|
-
const elementType = elementTypeResult.type;
|
9068
9092
|
let isAsync = node.forIfNodes.some((comp) => {
|
9069
9093
|
return ((comp.nodeType === 33 /* ListComprehensionFor */ && comp.isAsync) ||
|
9070
9094
|
(comp.nodeType === 34 /* ListComprehensionIf */ &&
|
@@ -9074,6 +9098,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9074
9098
|
if (node.expression.nodeType === 6 /* Await */) {
|
9075
9099
|
isAsync = true;
|
9076
9100
|
}
|
9101
|
+
let expectedElementType;
|
9102
|
+
if (expectedType) {
|
9103
|
+
expectedElementType = getTypeOfIterator(expectedType, isAsync, /* errorNode */ undefined);
|
9104
|
+
}
|
9105
|
+
const elementTypeResult = getElementTypeFromListComprehension(node, expectedElementType);
|
9106
|
+
if (elementTypeResult.isIncomplete) {
|
9107
|
+
isIncomplete = true;
|
9108
|
+
}
|
9109
|
+
if (elementTypeResult.typeErrors) {
|
9110
|
+
typeErrors = true;
|
9111
|
+
}
|
9112
|
+
const elementType = elementTypeResult.type;
|
9077
9113
|
// Handle the special case where a generator function (e.g. `(await x for x in y)`)
|
9078
9114
|
// is expected to be an AsyncGenerator.
|
9079
9115
|
if (!isAsync &&
|
@@ -10386,7 +10422,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10386
10422
|
512 /* AllowGenericClassType */ |
|
10387
10423
|
262144 /* DisallowNakedGeneric */ |
|
10388
10424
|
2048 /* DisallowTypeVarsWithScopeId */ |
|
10389
|
-
8192 /* AssociateTypeVarsWithCurrentScope
|
10425
|
+
8192 /* AssociateTypeVarsWithCurrentScope */ |
|
10426
|
+
16384 /* EnforceTypeVarVarianceConsistency */;
|
10390
10427
|
if (fileInfo.isStubFile) {
|
10391
10428
|
exprFlags |= 4 /* AllowForwardReferences */;
|
10392
10429
|
}
|
@@ -10997,12 +11034,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10997
11034
|
// completed.
|
10998
11035
|
function runClassTypeHooks(type) {
|
10999
11036
|
classTypeHooks.forEach((hook) => {
|
11000
|
-
if (hook.dependency
|
11037
|
+
if (types_1.ClassType.isSameGenericClass(hook.dependency, type)) {
|
11001
11038
|
hook.callback();
|
11002
11039
|
}
|
11003
11040
|
});
|
11004
11041
|
// Remove any hooks that depend on this type.
|
11005
|
-
classTypeHooks = classTypeHooks.filter((hook) => hook.dependency
|
11042
|
+
classTypeHooks = classTypeHooks.filter((hook) => !types_1.ClassType.isSameGenericClass(hook.dependency, type));
|
11006
11043
|
}
|
11007
11044
|
// Recomputes the MRO and effective metaclass for the class after dependent
|
11008
11045
|
// classes have been fully constructed.
|
@@ -11326,9 +11363,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11326
11363
|
}
|
11327
11364
|
// If there was no annotation for the parameter, infer its type if possible.
|
11328
11365
|
let isTypeInferred = false;
|
11329
|
-
if (!
|
11366
|
+
if (!paramTypeNode) {
|
11330
11367
|
isTypeInferred = true;
|
11331
|
-
|
11368
|
+
const inferredType = inferParameterType(node, functionType.details.flags, index, containingClassType);
|
11369
|
+
if (inferredType) {
|
11370
|
+
paramType = inferredType;
|
11371
|
+
}
|
11332
11372
|
}
|
11333
11373
|
const functionParam = {
|
11334
11374
|
category: param.category,
|
@@ -12406,7 +12446,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12406
12446
|
// expression or statement that contains it. This contextual evaluation
|
12407
12447
|
// allows for bidirectional type evaluation.
|
12408
12448
|
function evaluateTypesForExpressionInContext(node) {
|
12409
|
-
var _a, _b, _c, _d, _e;
|
12449
|
+
var _a, _b, _c, _d, _e, _f;
|
12410
12450
|
// Check for a couple of special cases where the node is a NameNode but
|
12411
12451
|
// is technically not part of an expression. We'll handle these here so
|
12412
12452
|
// callers don't need to include special-case logic.
|
@@ -12467,7 +12507,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12467
12507
|
});
|
12468
12508
|
return;
|
12469
12509
|
}
|
12470
|
-
getTypeOfAnnotation(annotationNode
|
12510
|
+
getTypeOfAnnotation(annotationNode, {
|
12511
|
+
isVariableAnnotation: ((_a = annotationNode.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 54 /* TypeAnnotation */,
|
12512
|
+
});
|
12471
12513
|
return;
|
12472
12514
|
}
|
12473
12515
|
// See if the expression is part of a pattern used in a case statement.
|
@@ -12578,8 +12620,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12578
12620
|
// If this is the name node within a type parameter list, see if it's a type alias
|
12579
12621
|
// definition. If so, we need to evaluate the type alias contextually.
|
12580
12622
|
if (nodeToEvaluate === parent.name &&
|
12581
|
-
((
|
12582
|
-
((
|
12623
|
+
((_b = parent.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 76 /* TypeParameterList */ &&
|
12624
|
+
((_c = parent.parent.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 77 /* TypeAlias */) {
|
12583
12625
|
getTypeOfTypeAlias(parent.parent.parent);
|
12584
12626
|
return;
|
12585
12627
|
}
|
@@ -12590,10 +12632,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12590
12632
|
return;
|
12591
12633
|
}
|
12592
12634
|
case 13 /* Decorator */: {
|
12593
|
-
if (((
|
12635
|
+
if (((_d = parent.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 10 /* Class */) {
|
12594
12636
|
getTypeOfClass(parent.parent);
|
12595
12637
|
}
|
12596
|
-
else if (((
|
12638
|
+
else if (((_e = parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 28 /* Function */) {
|
12597
12639
|
getTypeOfFunction(parent.parent);
|
12598
12640
|
}
|
12599
12641
|
return;
|
@@ -12611,7 +12653,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12611
12653
|
// expression, so there's nothing we can evaluate here.
|
12612
12654
|
return;
|
12613
12655
|
}
|
12614
|
-
if (((
|
12656
|
+
if (((_f = parent.parent) === null || _f === void 0 ? void 0 : _f.nodeType) === 10 /* Class */) {
|
12615
12657
|
// A class argument must be evaluated in the context of the class declaration.
|
12616
12658
|
getTypeOfClass(parent.parent);
|
12617
12659
|
return;
|
@@ -13022,8 +13064,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13022
13064
|
received: typeArgCount,
|
13023
13065
|
}), typeArgs[typeParameters.length].node);
|
13024
13066
|
}
|
13067
|
+
typeArgCount = typeParameters.length;
|
13025
13068
|
}
|
13026
|
-
typeArgCount = typeParameters.length;
|
13027
13069
|
}
|
13028
13070
|
else if (typeArgCount < typeParameters.length) {
|
13029
13071
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
@@ -13143,7 +13185,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13143
13185
|
typeArgTypes = typeArgTypes.map((typeArgType, index) => {
|
13144
13186
|
if (index < typeArgCount) {
|
13145
13187
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
13146
|
-
|
13188
|
+
let adjustedTypeArgType = applyTypeArgToTypeVar(typeParameters[index], typeArgType, diag);
|
13189
|
+
// Determine if the variance must match.
|
13190
|
+
if (adjustedTypeArgType && (flags & 16384 /* EnforceTypeVarVarianceConsistency */) !== 0) {
|
13191
|
+
const destType = typeParameters[index];
|
13192
|
+
if ((0, types_1.isTypeVar)(adjustedTypeArgType) &&
|
13193
|
+
!adjustedTypeArgType.details.isParamSpec &&
|
13194
|
+
!adjustedTypeArgType.details.isVariadic &&
|
13195
|
+
destType.details.declaredVariance !== 0 /* Auto */ &&
|
13196
|
+
adjustedTypeArgType.details.declaredVariance !== 0 /* Auto */) {
|
13197
|
+
if (adjustedTypeArgType.details.declaredVariance !== 2 /* Invariant */ &&
|
13198
|
+
adjustedTypeArgType.details.declaredVariance !== destType.details.declaredVariance) {
|
13199
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.varianceMismatch().format({
|
13200
|
+
typeVarName: printType(adjustedTypeArgType),
|
13201
|
+
className: classType.details.name,
|
13202
|
+
}));
|
13203
|
+
adjustedTypeArgType = undefined;
|
13204
|
+
}
|
13205
|
+
}
|
13206
|
+
}
|
13147
13207
|
if (adjustedTypeArgType) {
|
13148
13208
|
typeArgType = adjustedTypeArgType;
|
13149
13209
|
}
|
@@ -13160,6 +13220,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13160
13220
|
}
|
13161
13221
|
return typeArgType;
|
13162
13222
|
});
|
13223
|
+
// If the class is partially constructed and doesn't yet have
|
13224
|
+
// type parameters, assume that the number and types of supplied type
|
13225
|
+
// arguments are correct.
|
13226
|
+
if (typeArgs && classType.details.typeParameters.length === 0 && types_1.ClassType.isPartiallyEvaluated(classType)) {
|
13227
|
+
typeArgTypes = typeArgs.map((t) => (0, typeUtils_1.convertToInstance)(t.type));
|
13228
|
+
}
|
13163
13229
|
const specializedClass = types_1.ClassType.cloneForSpecialization(classType, typeArgTypes, typeArgs !== undefined);
|
13164
13230
|
return specializedClass;
|
13165
13231
|
}
|
@@ -14111,6 +14177,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14111
14177
|
}
|
14112
14178
|
}
|
14113
14179
|
else {
|
14180
|
+
// If this resolves to a class decl, we can use a partially-evaluated
|
14181
|
+
// version of the class type.
|
14182
|
+
const resolvedDecl = resolveAliasDeclaration(decl,
|
14183
|
+
/* resolveLocalNames */ true,
|
14184
|
+
/* allowExternallyHiddenAccess */ AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile);
|
14185
|
+
if ((resolvedDecl === null || resolvedDecl === void 0 ? void 0 : resolvedDecl.type) === 6 /* Class */) {
|
14186
|
+
const classTypeInfo = getTypeOfClass(resolvedDecl.node);
|
14187
|
+
if (classTypeInfo === null || classTypeInfo === void 0 ? void 0 : classTypeInfo.decoratedType) {
|
14188
|
+
typesToCombine.push(classTypeInfo.decoratedType);
|
14189
|
+
}
|
14190
|
+
}
|
14114
14191
|
isIncomplete = true;
|
14115
14192
|
}
|
14116
14193
|
}
|
@@ -14542,7 +14619,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14542
14619
|
if ((flags & 1 /* EnforceInvariance */) === 0 || types_1.ClassType.isSameGenericClass(srcType, destType)) {
|
14543
14620
|
if (isDerivedFrom) {
|
14544
14621
|
(0, debug_1.assert)(inheritanceChain.length > 0);
|
14545
|
-
|
14622
|
+
if (assignClassWithTypeArgs(destType, srcType, inheritanceChain, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
14623
|
+
return true;
|
14624
|
+
}
|
14546
14625
|
}
|
14547
14626
|
}
|
14548
14627
|
// Everything is assignable to an object.
|
@@ -16296,10 +16375,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16296
16375
|
const effectiveDestType = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? destType : srcType;
|
16297
16376
|
const effectiveSrcType = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? srcType : destType;
|
16298
16377
|
if (effectiveDestType.details.paramSpec) {
|
16299
|
-
const requiredMatchParamCount =
|
16300
|
-
if (!p.name) {
|
16301
|
-
return false;
|
16302
|
-
}
|
16378
|
+
const requiredMatchParamCount = types_1.FunctionType.getFunctionParameters(effectiveDestType).filter((p) => {
|
16303
16379
|
if (p.category === 0 /* Simple */ && (0, types_1.isParamSpec)(p.type)) {
|
16304
16380
|
return false;
|
16305
16381
|
}
|
@@ -16748,26 +16824,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16748
16824
|
// Validates that the specified source type matches the constraints
|
16749
16825
|
// of the type variable. If successful, it returns the constraint
|
16750
16826
|
// type that applies. If unsuccessful, it returns undefined.
|
16751
|
-
function applyTypeArgToTypeVar(destType, srcType, diag
|
16752
|
-
if (recursionCount > types_1.maxTypeRecursionCount) {
|
16753
|
-
return srcType;
|
16754
|
-
}
|
16755
|
-
recursionCount++;
|
16827
|
+
function applyTypeArgToTypeVar(destType, srcType, diag) {
|
16756
16828
|
if ((0, types_1.isAnyOrUnknown)(srcType)) {
|
16757
16829
|
return srcType;
|
16758
16830
|
}
|
16759
16831
|
let effectiveSrcType = srcType;
|
16760
16832
|
if ((0, types_1.isTypeVar)(srcType)) {
|
16761
|
-
if ((0, types_1.isTypeSame)(srcType, destType
|
16833
|
+
if ((0, types_1.isTypeSame)(srcType, destType)) {
|
16762
16834
|
return srcType;
|
16763
16835
|
}
|
16764
16836
|
effectiveSrcType = makeTopLevelTypeVarsConcrete(srcType);
|
16765
16837
|
}
|
16838
|
+
// If this is a partially-evaluated class, don't perform any further
|
16839
|
+
// checks. Assume in this case that the type is compatible with the
|
16840
|
+
// bound or constraint.
|
16841
|
+
if ((0, types_1.isClass)(effectiveSrcType) && types_1.ClassType.isPartiallyEvaluated(effectiveSrcType)) {
|
16842
|
+
return srcType;
|
16843
|
+
}
|
16766
16844
|
// If there's a bound type, make sure the source is derived from it.
|
16767
16845
|
if (destType.details.boundType) {
|
16768
16846
|
if (!assignType(destType.details.boundType, effectiveSrcType, diag.createAddendum(),
|
16769
16847
|
/* destTypeVarContext */ undefined,
|
16770
|
-
/* srcTypeVarContext */ undefined
|
16848
|
+
/* srcTypeVarContext */ undefined)) {
|
16771
16849
|
// Avoid adding a message that will confuse users if the TypeVar was
|
16772
16850
|
// synthesized for internal purposes.
|
16773
16851
|
if (!destType.details.isSynthesized) {
|
@@ -16808,10 +16886,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16808
16886
|
if ((0, types_1.isTypeVar)(srcType) && srcType.details.constraints.length > 0) {
|
16809
16887
|
// Make sure all the source constraint types map to constraint types in the dest.
|
16810
16888
|
if (srcType.details.constraints.every((sourceConstraint) => {
|
16811
|
-
return constraints.some((destConstraint) => assignType(destConstraint, sourceConstraint
|
16812
|
-
/* diag */ undefined,
|
16813
|
-
/* destTypeVarContext */ undefined,
|
16814
|
-
/* srcTypeVarContext */ undefined, 0 /* Default */, recursionCount));
|
16889
|
+
return constraints.some((destConstraint) => assignType(destConstraint, sourceConstraint));
|
16815
16890
|
})) {
|
16816
16891
|
return srcType;
|
16817
16892
|
}
|
@@ -16820,15 +16895,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16820
16895
|
let bestConstraintSoFar;
|
16821
16896
|
// Try to find the best (narrowest) match among the constraints.
|
16822
16897
|
for (const constraint of constraints) {
|
16823
|
-
if (assignType(constraint, effectiveSrcType
|
16824
|
-
|
16825
|
-
/* destTypeVarContext */ undefined,
|
16826
|
-
/* srcTypeVarContext */ undefined, 0 /* Default */, recursionCount)) {
|
16827
|
-
if (!bestConstraintSoFar ||
|
16828
|
-
assignType(bestConstraintSoFar, constraint,
|
16829
|
-
/* diag */ undefined,
|
16830
|
-
/* destTypeVarContext */ undefined,
|
16831
|
-
/* srcTypeVarContext */ undefined, 0 /* Default */, recursionCount)) {
|
16898
|
+
if (assignType(constraint, effectiveSrcType)) {
|
16899
|
+
if (!bestConstraintSoFar || assignType(bestConstraintSoFar, constraint)) {
|
16832
16900
|
bestConstraintSoFar = constraint;
|
16833
16901
|
}
|
16834
16902
|
}
|