@zzzen/pyright-internal 1.2.0-dev.20260906 → 1.2.0-dev.20260913
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/checker.d.ts +2 -1
- package/dist/analyzer/checker.js +78 -2
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +10 -2
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +7 -18
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/decorators.js +45 -2
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/sourceFileInfo.d.ts +0 -1
- package/dist/analyzer/sourceFileInfo.js +0 -3
- package/dist/analyzer/sourceFileInfo.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +56 -379
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/common/extensibility.d.ts +0 -1
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileSystem.d.ts +1 -0
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +1 -0
- package/dist/common/realFileSystem.js +12 -0
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/fileSystemMapping.d.ts +1 -1
- package/dist/fileSystemMapping.js +3 -0
- package/dist/fileSystemMapping.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +2 -1
- package/dist/languageService/completionProvider.js +4 -1
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/localization/package.nls.cs.json +1 -0
- package/dist/localization/package.nls.de.json +1 -0
- package/dist/localization/package.nls.es.json +1 -0
- package/dist/localization/package.nls.fr.json +1 -0
- package/dist/localization/package.nls.it.json +1 -0
- package/dist/localization/package.nls.ja.json +1 -0
- package/dist/localization/package.nls.ko.json +1 -0
- package/dist/localization/package.nls.pl.json +1 -0
- package/dist/localization/package.nls.pt-br.json +1 -0
- package/dist/localization/package.nls.qps-ploc.json +1 -0
- package/dist/localization/package.nls.ru.json +1 -0
- package/dist/localization/package.nls.tr.json +1 -0
- package/dist/localization/package.nls.zh-cn.json +1 -0
- package/dist/localization/package.nls.zh-tw.json +1 -0
- package/dist/readonlyAugmentedFileSystem.d.ts +1 -0
- package/dist/readonlyAugmentedFileSystem.js +3 -0
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/tests/checker.test.js +8 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/fileSystemMapping.test.js +3 -0
- package/dist/tests/fileSystemMapping.test.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +1 -0
- package/dist/tests/harness/vfs/filesystem.js +3 -0
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importResolver.test.js +5 -0
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/mypyPrimerAnalysis.test.d.ts +1 -0
- package/dist/tests/mypyPrimerAnalysis.test.js +633 -0
- package/dist/tests/mypyPrimerAnalysis.test.js.map +1 -0
- package/dist/tests/typeEvaluator1.test.js +2 -2
- package/dist/tests/typeEvaluator6.test.js +155 -3
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeUtils.test.js +15 -0
- package/dist/tests/typeUtils.test.js.map +1 -1
- package/dist/typeServer/typeServerFileSystem.d.ts +1 -0
- package/dist/typeServer/typeServerFileSystem.js +3 -0
- package/dist/typeServer/typeServerFileSystem.js.map +1 -1
- package/dist/typeServer/virtualFileOverlayFileSystem.d.ts +1 -0
- package/dist/typeServer/virtualFileOverlayFileSystem.js +3 -0
- package/dist/typeServer/virtualFileOverlayFileSystem.js.map +1 -1
- package/package.json +1 -1
|
@@ -4151,7 +4151,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4151
4151
|
writeTypeCache(node.d.member, typeResult, flags);
|
|
4152
4152
|
return typeResult;
|
|
4153
4153
|
}
|
|
4154
|
-
function getTypeOfMemberAccessWithBaseType(node, baseTypeResult, usage, flags) {
|
|
4154
|
+
function getTypeOfMemberAccessWithBaseType(node, baseTypeResult, usage, flags, allowFunctionSignatureAssignment = true) {
|
|
4155
4155
|
let baseType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(baseTypeResult.type);
|
|
4156
4156
|
const memberName = node.d.member.d.value;
|
|
4157
4157
|
let diag = new diagnostic_1.DiagnosticAddendum();
|
|
@@ -4413,6 +4413,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4413
4413
|
case 4 /* TypeCategory.Function */:
|
|
4414
4414
|
case 5 /* TypeCategory.Overloaded */: {
|
|
4415
4415
|
const hasSelf = (0, types_1.isMethodType)(baseType);
|
|
4416
|
+
const functionTypes = (0, types_1.isFunction)(baseType) ? [baseType] : types_1.OverloadedType.getOverloads(baseType);
|
|
4417
|
+
const isBuiltinsFunction = functionTypes.some((functionType) => types_1.FunctionType.isBuiltIn(functionType) && functionType.shared.moduleName === 'builtins');
|
|
4416
4418
|
if (memberName === '__self__' && hasSelf) {
|
|
4417
4419
|
// Handle "__self__" specially because MethodType defines
|
|
4418
4420
|
// it simply as "object". We can do better here.
|
|
@@ -4430,7 +4432,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4430
4432
|
}
|
|
4431
4433
|
else {
|
|
4432
4434
|
const altType = hasSelf ? prefetched?.methodClass : prefetched?.functionClass;
|
|
4433
|
-
type = getTypeOfMemberAccessWithBaseType(node, { type: altType ? (0, typeUtils_1.convertToInstance)(altType) : types_1.UnknownType.create() }, usage, flags).type;
|
|
4435
|
+
type = getTypeOfMemberAccessWithBaseType(node, { type: altType ? (0, typeUtils_1.convertToInstance)(altType) : types_1.UnknownType.create() }, usage, flags, !hasSelf && !isBuiltinsFunction).type;
|
|
4434
4436
|
}
|
|
4435
4437
|
break;
|
|
4436
4438
|
}
|
|
@@ -4442,7 +4444,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
4442
4444
|
if (!type) {
|
|
4443
4445
|
const isFunctionRule = (0, types_1.isFunctionOrOverloaded)(baseType) ||
|
|
4444
4446
|
((0, types_1.isClassInstance)(baseType) && types_1.ClassType.isBuiltIn(baseType, ['function', 'FunctionType']));
|
|
4445
|
-
|
|
4447
|
+
// These signature metadata attributes can be assigned on function objects at runtime.
|
|
4448
|
+
const isFunctionSignatureAssignment = allowFunctionSignatureAssignment &&
|
|
4449
|
+
usage.method === 'set' &&
|
|
4450
|
+
(memberName === '__signature__' || memberName === '__text_signature__') &&
|
|
4451
|
+
(0, types_1.isClassInstance)(baseType) &&
|
|
4452
|
+
types_1.ClassType.isBuiltIn(baseType, ['function', 'FunctionType']);
|
|
4453
|
+
if (!baseTypeResult.isIncomplete && !isFunctionSignatureAssignment) {
|
|
4446
4454
|
let diagMessage = localize_1.LocMessage.memberAccess();
|
|
4447
4455
|
if (usage.method === 'set') {
|
|
4448
4456
|
diagMessage = localize_1.LocMessage.memberSet();
|
|
@@ -7018,15 +7026,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7018
7026
|
const specializedInitSelfTypes = [];
|
|
7019
7027
|
let matchedOverloads = [];
|
|
7020
7028
|
let isTypeIncomplete = false;
|
|
7021
|
-
|
|
7029
|
+
let overloadsUsedForCall = [];
|
|
7022
7030
|
let isDefinitiveMatchFound = false;
|
|
7023
|
-
let hasInitSelfMaterializationAmbiguity = false;
|
|
7024
|
-
let hasEffectiveInitSelfType = false;
|
|
7025
7031
|
const speculativeNode = getSpeculativeNodeForCall(errorNode);
|
|
7026
7032
|
for (let expandedTypesIndex = 0; expandedTypesIndex < expandedArgTypes.length; expandedTypesIndex++) {
|
|
7027
|
-
const overloadsUsedStartIndex = overloadsUsedForCall.length;
|
|
7028
7033
|
let matchedOverload;
|
|
7029
|
-
let effectiveInitSelfType;
|
|
7030
7034
|
const argTypeOverride = expandedArgTypes[expandedTypesIndex];
|
|
7031
7035
|
const hasArgTypeOverride = argTypeOverride.some((a) => a !== undefined);
|
|
7032
7036
|
let possibleMatchResults = [];
|
|
@@ -7066,12 +7070,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7066
7070
|
constraints: effectiveConstraints,
|
|
7067
7071
|
returnType: callResult.returnType,
|
|
7068
7072
|
argResults: callResult.argResults ?? [],
|
|
7069
|
-
specializedInitSelfType: callResult.specializedInitSelfType,
|
|
7070
7073
|
};
|
|
7071
7074
|
matchedOverloads.push(matchedOverloadInfo);
|
|
7072
|
-
if (callResult.anyOrUnknownArg ||
|
|
7073
|
-
matchResults.unpackedArgOfUnknownLength ||
|
|
7074
|
-
possibleMatchResults.length > 0) {
|
|
7075
|
+
if (callResult.anyOrUnknownArg || matchResults.unpackedArgOfUnknownLength) {
|
|
7075
7076
|
possibleMatchResults.push(matchedOverloadInfo);
|
|
7076
7077
|
if (callResult.anyOrUnknownArg) {
|
|
7077
7078
|
if ((0, typeUtils_1.isIncompleteUnknown)(callResult.anyOrUnknownArg)) {
|
|
@@ -7081,7 +7082,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7081
7082
|
}
|
|
7082
7083
|
else {
|
|
7083
7084
|
returnTypes.push(callResult.returnType);
|
|
7084
|
-
|
|
7085
|
+
// Each definitive union branch needs its own constructed type;
|
|
7086
|
+
// __init__ return types alone cannot represent the specialization.
|
|
7087
|
+
const boundToType = overload.priv.boundToType;
|
|
7088
|
+
if (expandedArgTypes.length > 1 &&
|
|
7089
|
+
overload.shared.name === '__init__' &&
|
|
7090
|
+
boundToType &&
|
|
7091
|
+
(0, types_1.isClassInstance)(boundToType)) {
|
|
7092
|
+
specializedInitSelfTypes.push(callResult.specializedInitSelfType ??
|
|
7093
|
+
solveAndApplyConstraints(boundToType, effectiveConstraints, {
|
|
7094
|
+
replaceUnsolved: {
|
|
7095
|
+
scopeIds: (0, typeUtils_1.getTypeVarScopeIds)(boundToType),
|
|
7096
|
+
tupleClassType: getTupleClassType(),
|
|
7097
|
+
},
|
|
7098
|
+
}));
|
|
7099
|
+
}
|
|
7085
7100
|
isDefinitiveMatchFound = true;
|
|
7086
7101
|
break;
|
|
7087
7102
|
}
|
|
@@ -7095,53 +7110,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7095
7110
|
if (!isDefinitiveMatchFound && possibleMatchResults.length > 0) {
|
|
7096
7111
|
possibleMatchResults = filterOverloadMatchesForUnpackedArgs(possibleMatchResults);
|
|
7097
7112
|
possibleMatchResults = filterOverloadMatchesForAnyArgs(possibleMatchResults);
|
|
7098
|
-
// Keep diagnostic bookkeeping aligned with the candidates that remain possible.
|
|
7099
|
-
// This applies to both top-level gradual arguments and nested materialization,
|
|
7100
|
-
// so deprecation diagnostics are reported only for retained overloads.
|
|
7101
|
-
overloadsUsedForCall.splice(overloadsUsedStartIndex, overloadsUsedForCall.length - overloadsUsedStartIndex, ...possibleMatchResults.map((result) => result.overload));
|
|
7102
7113
|
// Did the filtering produce a single result? If so, we're done.
|
|
7103
7114
|
if (possibleMatchResults.length === 1) {
|
|
7115
|
+
overloadsUsedForCall = [possibleMatchResults[0].overload];
|
|
7104
7116
|
returnTypes.push(possibleMatchResults[0].returnType);
|
|
7105
|
-
effectiveInitSelfType = getEffectiveInitSelfType(possibleMatchResults[0]);
|
|
7106
7117
|
matchedOverloads = [possibleMatchResults[0]];
|
|
7107
7118
|
}
|
|
7108
7119
|
else {
|
|
7109
|
-
const firstArgParamPairs = getOverloadArgParamPairs(possibleMatchResults[0]);
|
|
7110
|
-
let ambiguousMatchIncludesNestedAny = false;
|
|
7111
|
-
let ambiguousMatchIncludesNestedUnknown = false;
|
|
7112
|
-
let ambiguousMatchIncludesTopLevelAnyOrUnknown = false;
|
|
7113
|
-
firstArgParamPairs.forEach((pair, index) => {
|
|
7114
|
-
const paramTypes = possibleMatchResults.map((match) => {
|
|
7115
|
-
const argParamPairs = getOverloadArgParamPairs(match);
|
|
7116
|
-
return index < argParamPairs.length ? argParamPairs[index].paramType : types_1.UnknownType.create();
|
|
7117
|
-
});
|
|
7118
|
-
if (!(0, typeUtils_1.areTypesSame)(paramTypes, { treatAnySameAsUnknown: true })) {
|
|
7119
|
-
if ((0, types_1.isAnyOrUnknown)(pair.argType)) {
|
|
7120
|
-
ambiguousMatchIncludesTopLevelAnyOrUnknown = true;
|
|
7121
|
-
}
|
|
7122
|
-
else {
|
|
7123
|
-
const anyOrUnknown = getAnyOrUnknownInInvariantPosition(pair.argType);
|
|
7124
|
-
if (anyOrUnknown && (0, types_1.isAny)(anyOrUnknown)) {
|
|
7125
|
-
ambiguousMatchIncludesNestedAny = true;
|
|
7126
|
-
}
|
|
7127
|
-
else if (anyOrUnknown && (0, types_1.isUnknown)(anyOrUnknown)) {
|
|
7128
|
-
ambiguousMatchIncludesNestedUnknown = true;
|
|
7129
|
-
}
|
|
7130
|
-
}
|
|
7131
|
-
}
|
|
7132
|
-
});
|
|
7133
7120
|
// Eliminate any return types that are subsumed by other return types.
|
|
7134
7121
|
let dedupedMatchResults = [];
|
|
7135
7122
|
let dedupedResultsIncludeAny = false;
|
|
7136
|
-
const isInitSelfMaterializationAmbiguity = (ambiguousMatchIncludesNestedAny || ambiguousMatchIncludesNestedUnknown) &&
|
|
7137
|
-
possibleMatchResults.some((result) => !!result.specializedInitSelfType);
|
|
7138
7123
|
possibleMatchResults.forEach((result) => {
|
|
7139
|
-
const resultType = isInitSelfMaterializationAmbiguity
|
|
7140
|
-
? getEffectiveOverloadReturnType(result)
|
|
7141
|
-
: result.returnType;
|
|
7142
7124
|
let isSubtypeSubsumed = false;
|
|
7143
7125
|
for (let dedupedIndex = 0; dedupedIndex < dedupedMatchResults.length; dedupedIndex++) {
|
|
7144
|
-
if (assignType(dedupedMatchResults[dedupedIndex],
|
|
7126
|
+
if (assignType(dedupedMatchResults[dedupedIndex], result.returnType)) {
|
|
7145
7127
|
const anyOrUnknown = (0, typeUtils_1.containsAnyOrUnknown)(dedupedMatchResults[dedupedIndex],
|
|
7146
7128
|
/* recurse */ false);
|
|
7147
7129
|
if (!anyOrUnknown) {
|
|
@@ -7152,8 +7134,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7152
7134
|
}
|
|
7153
7135
|
break;
|
|
7154
7136
|
}
|
|
7155
|
-
else if (assignType(
|
|
7156
|
-
const anyOrUnknown = (0, typeUtils_1.containsAnyOrUnknown)(
|
|
7137
|
+
else if (assignType(result.returnType, dedupedMatchResults[dedupedIndex])) {
|
|
7138
|
+
const anyOrUnknown = (0, typeUtils_1.containsAnyOrUnknown)(result.returnType, /* recurse */ false);
|
|
7157
7139
|
if (!anyOrUnknown) {
|
|
7158
7140
|
dedupedMatchResults[dedupedIndex] = types_1.NeverType.createNever();
|
|
7159
7141
|
}
|
|
@@ -7164,19 +7146,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7164
7146
|
}
|
|
7165
7147
|
}
|
|
7166
7148
|
if (!isSubtypeSubsumed) {
|
|
7167
|
-
dedupedMatchResults.push(
|
|
7149
|
+
dedupedMatchResults.push(result.returnType);
|
|
7168
7150
|
}
|
|
7169
7151
|
});
|
|
7170
7152
|
dedupedMatchResults = dedupedMatchResults.filter((t) => !(0, types_1.isNever)(t));
|
|
7171
7153
|
const combinedTypes = (0, types_1.combineTypes)(dedupedMatchResults);
|
|
7172
7154
|
let returnType = combinedTypes;
|
|
7173
|
-
if (
|
|
7174
|
-
returnType = types_1.UnknownType.createPossibleType(combinedTypes, possibleMatchInvolvesIncompleteUnknown);
|
|
7175
|
-
}
|
|
7176
|
-
else if (ambiguousMatchIncludesNestedAny && !ambiguousMatchIncludesTopLevelAnyOrUnknown) {
|
|
7177
|
-
returnType = types_1.AnyType.create();
|
|
7178
|
-
}
|
|
7179
|
-
else if (dedupedMatchResults.length > 1) {
|
|
7155
|
+
if (dedupedMatchResults.length > 1) {
|
|
7180
7156
|
// If one or more of the deduped types is Any or contains Any,
|
|
7181
7157
|
// we will assume that the person who defined the overload really
|
|
7182
7158
|
// wanted Any rather than Unknown. In cases where the deduped types
|
|
@@ -7189,43 +7165,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7189
7165
|
returnType = types_1.UnknownType.createPossibleType(combinedTypes, possibleMatchInvolvesIncompleteUnknown);
|
|
7190
7166
|
}
|
|
7191
7167
|
}
|
|
7192
|
-
|
|
7193
|
-
// Overloaded __init__ methods normally return None. Preserve that
|
|
7194
|
-
// ordinary return as a placeholder while union-expanded calls are
|
|
7195
|
-
// combined, and carry the effective constructed types separately.
|
|
7196
|
-
// validateInitMethod consumes specializedInitSelfType to reconstruct
|
|
7197
|
-
// the constructor result after call validation is complete.
|
|
7198
|
-
effectiveInitSelfType = returnType;
|
|
7199
|
-
hasInitSelfMaterializationAmbiguity = true;
|
|
7200
|
-
returnTypes.push(possibleMatchResults[0].returnType);
|
|
7201
|
-
}
|
|
7202
|
-
else {
|
|
7203
|
-
returnTypes.push(returnType);
|
|
7204
|
-
}
|
|
7168
|
+
returnTypes.push(returnType);
|
|
7205
7169
|
}
|
|
7206
7170
|
}
|
|
7207
|
-
if (effectiveInitSelfType) {
|
|
7208
|
-
specializedInitSelfTypes.push(effectiveInitSelfType);
|
|
7209
|
-
hasEffectiveInitSelfType = true;
|
|
7210
|
-
}
|
|
7211
7171
|
if (!matchedOverload) {
|
|
7212
7172
|
return { argumentErrors: true, isTypeIncomplete, overloadsUsedForCall };
|
|
7213
7173
|
}
|
|
7214
7174
|
}
|
|
7215
|
-
// Union expansion requires one constructor handoff per expanded argument list.
|
|
7216
|
-
// Materialization ambiguity requires a combined handoff even when there is only
|
|
7217
|
-
// one argument list because multiple overload candidates contribute to its result.
|
|
7218
|
-
const shouldCombineInitSelfTypes = hasInitSelfMaterializationAmbiguity || (expandedArgTypes.length > 1 && hasEffectiveInitSelfType);
|
|
7219
7175
|
// We found a match for all of the expanded argument lists. Copy the
|
|
7220
7176
|
// resulting type var context back into the caller's type var context.
|
|
7221
|
-
//
|
|
7222
|
-
//
|
|
7177
|
+
// Constructor results for separate union branches are carried through
|
|
7178
|
+
// specializedInitSelfTypes rather than the last branch's constraints.
|
|
7223
7179
|
if (constraints && isDefinitiveMatchFound) {
|
|
7224
7180
|
constraints.copyFromClone(matchedOverloads[matchedOverloads.length - 1].constraints);
|
|
7225
7181
|
}
|
|
7226
7182
|
// And run through the first expanded argument list one more time to
|
|
7227
|
-
// populate the type cache.
|
|
7228
|
-
const finalConstraints =
|
|
7183
|
+
// populate the type cache, without applying a different branch's constraints.
|
|
7184
|
+
const finalConstraints = expandedArgTypes.length > 1
|
|
7229
7185
|
? matchedOverloads[0].constraints
|
|
7230
7186
|
: constraints ?? matchedOverloads[0].constraints;
|
|
7231
7187
|
const finalCallResult = validateArgTypesWithContext(errorNode, matchedOverloads[0].matchResults, finalConstraints, skipUnknownArgCheck, inferenceContext);
|
|
@@ -7237,7 +7193,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7237
7193
|
anyOrUnknownArg: finalCallResult.anyOrUnknownArg,
|
|
7238
7194
|
returnType: (0, types_1.combineTypes)(returnTypes),
|
|
7239
7195
|
isTypeIncomplete,
|
|
7240
|
-
specializedInitSelfType: specializedInitSelfTypes.length
|
|
7196
|
+
specializedInitSelfType: specializedInitSelfTypes.length === expandedArgTypes.length
|
|
7241
7197
|
? (0, types_1.combineTypes)(specializedInitSelfTypes)
|
|
7242
7198
|
: finalCallResult.specializedInitSelfType,
|
|
7243
7199
|
overloadsUsedForCall,
|
|
@@ -7257,303 +7213,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7257
7213
|
}
|
|
7258
7214
|
return unpackedArgsOverloads;
|
|
7259
7215
|
}
|
|
7260
|
-
// assignType cannot be used for this detection because it accepts Any and Unknown
|
|
7261
|
-
// without exposing whether acceptance depends on a gradual invariant type argument.
|
|
7262
|
-
function getAnyOrUnknownInInvariantPosition(type, recursionCount = 0) {
|
|
7263
|
-
if (recursionCount > types_1.maxTypeRecursionCount) {
|
|
7264
|
-
return undefined;
|
|
7265
|
-
}
|
|
7266
|
-
recursionCount++;
|
|
7267
|
-
let result;
|
|
7268
|
-
const addResult = (newResult) => {
|
|
7269
|
-
if (newResult) {
|
|
7270
|
-
result = result ? (0, typeUtils_1.preserveUnknown)(result, newResult) : newResult;
|
|
7271
|
-
}
|
|
7272
|
-
};
|
|
7273
|
-
if ((0, types_1.isUnion)(type)) {
|
|
7274
|
-
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
|
7275
|
-
addResult(getAnyOrUnknownInInvariantPosition(subtype, recursionCount));
|
|
7276
|
-
});
|
|
7277
|
-
return result;
|
|
7278
|
-
}
|
|
7279
|
-
if (!(0, types_1.isClass)(type)) {
|
|
7280
|
-
return undefined;
|
|
7281
|
-
}
|
|
7282
|
-
// Tuple entries are covariant, but they can contain an invariant type.
|
|
7283
|
-
if (type.priv.tupleTypeArgs) {
|
|
7284
|
-
type.priv.tupleTypeArgs.forEach((typeArg) => {
|
|
7285
|
-
addResult(getAnyOrUnknownInInvariantPosition(typeArg.type, recursionCount));
|
|
7286
|
-
});
|
|
7287
|
-
return result;
|
|
7288
|
-
}
|
|
7289
|
-
if (!type.priv.typeArgs) {
|
|
7290
|
-
return undefined;
|
|
7291
|
-
}
|
|
7292
|
-
inferVarianceForClass(type);
|
|
7293
|
-
const typeParams = types_1.ClassType.getTypeParams(type);
|
|
7294
|
-
type.priv.typeArgs.forEach((typeArg, index) => {
|
|
7295
|
-
const typeParam = index < typeParams.length ? typeParams[index] : undefined;
|
|
7296
|
-
const variance = typeParam ? types_1.TypeVarType.getVariance(typeParam) : 2 /* Variance.Invariant */;
|
|
7297
|
-
if (variance === 2 /* Variance.Invariant */) {
|
|
7298
|
-
addResult((0, typeUtils_1.containsAnyOrUnknown)(typeArg, /* recurse */ true));
|
|
7299
|
-
}
|
|
7300
|
-
else {
|
|
7301
|
-
addResult(getAnyOrUnknownInInvariantPosition(typeArg, recursionCount));
|
|
7302
|
-
}
|
|
7303
|
-
});
|
|
7304
|
-
return result;
|
|
7305
|
-
}
|
|
7306
|
-
function getEffectiveOverloadReturnType(match) {
|
|
7307
|
-
return getEffectiveInitSelfType(match) ?? match.returnType;
|
|
7308
|
-
}
|
|
7309
|
-
function getEffectiveInitSelfType(match) {
|
|
7310
|
-
if (match.specializedInitSelfType) {
|
|
7311
|
-
return match.specializedInitSelfType;
|
|
7312
|
-
}
|
|
7313
|
-
const boundToType = match.overload.priv.boundToType;
|
|
7314
|
-
if (match.overload.shared.name === '__init__' && boundToType && (0, types_1.isClassInstance)(boundToType)) {
|
|
7315
|
-
return solveAndApplyConstraints(boundToType, match.constraints, {
|
|
7316
|
-
replaceUnsolved: {
|
|
7317
|
-
scopeIds: (0, typeUtils_1.getTypeVarScopeIds)(boundToType),
|
|
7318
|
-
tupleClassType: getTupleClassType(),
|
|
7319
|
-
},
|
|
7320
|
-
});
|
|
7321
|
-
}
|
|
7322
|
-
return undefined;
|
|
7323
|
-
}
|
|
7324
|
-
function getOverloadArgParamPairs(match) {
|
|
7325
|
-
const pairs = [];
|
|
7326
|
-
// argResults and argParams share validation order: supplied arguments in caller
|
|
7327
|
-
// order, followed by synthesized defaults. Preserve that order so the same index
|
|
7328
|
-
// across overloads represents the same supplied argument, even for keyword calls.
|
|
7329
|
-
match.argResults.forEach((argResult, index) => {
|
|
7330
|
-
const argParam = index < match.matchResults.argParams.length ? match.matchResults.argParams[index] : undefined;
|
|
7331
|
-
if (!argParam?.isDefaultArg) {
|
|
7332
|
-
pairs.push({
|
|
7333
|
-
argType: argResult.argType,
|
|
7334
|
-
paramType: argParam?.paramType ?? types_1.UnknownType.create(),
|
|
7335
|
-
});
|
|
7336
|
-
}
|
|
7337
|
-
});
|
|
7338
|
-
if (match.overload.priv.boundToType && match.overload.priv.strippedFirstParamType) {
|
|
7339
|
-
pairs.unshift({
|
|
7340
|
-
argType: match.overload.priv.boundToType,
|
|
7341
|
-
paramType: match.overload.priv.strippedFirstParamType,
|
|
7342
|
-
});
|
|
7343
|
-
}
|
|
7344
|
-
return pairs;
|
|
7345
|
-
}
|
|
7346
|
-
function combineMaterializationCoverage(results) {
|
|
7347
|
-
if (results.some((result) => result === false)) {
|
|
7348
|
-
return false;
|
|
7349
|
-
}
|
|
7350
|
-
return results.some((result) => result === undefined) ? undefined : true;
|
|
7351
|
-
}
|
|
7352
|
-
function areAllMaterializationsEquivalent(destType, srcType, recursionCount = 0) {
|
|
7353
|
-
if (recursionCount > types_1.maxTypeRecursionCount) {
|
|
7354
|
-
return undefined;
|
|
7355
|
-
}
|
|
7356
|
-
recursionCount++;
|
|
7357
|
-
if (!(0, typeUtils_1.containsAnyOrUnknown)(srcType, /* recurse */ true)) {
|
|
7358
|
-
return (0, types_1.isTypeSame)(destType, srcType, { treatAnySameAsUnknown: true });
|
|
7359
|
-
}
|
|
7360
|
-
if ((0, types_1.isAnyOrUnknown)(destType)) {
|
|
7361
|
-
return true;
|
|
7362
|
-
}
|
|
7363
|
-
if ((0, types_1.isTypeSame)(destType, srcType, { treatAnySameAsUnknown: true })) {
|
|
7364
|
-
return true;
|
|
7365
|
-
}
|
|
7366
|
-
if ((0, types_1.isTypeVar)(destType) ||
|
|
7367
|
-
(0, types_1.isUnion)(destType) ||
|
|
7368
|
-
(0, types_1.isFunction)(destType) ||
|
|
7369
|
-
(0, types_1.isOverloaded)(destType) ||
|
|
7370
|
-
((0, types_1.isClass)(destType) && types_1.ClassType.isProtocolClass(destType))) {
|
|
7371
|
-
return undefined;
|
|
7372
|
-
}
|
|
7373
|
-
if ((0, types_1.isAnyOrUnknown)(srcType)) {
|
|
7374
|
-
return false;
|
|
7375
|
-
}
|
|
7376
|
-
if ((0, types_1.isUnion)(srcType) || (0, types_1.isUnion)(destType) || (0, types_1.isFunction)(srcType) || (0, types_1.isFunction)(destType)) {
|
|
7377
|
-
return undefined;
|
|
7378
|
-
}
|
|
7379
|
-
if (!(0, types_1.isClass)(destType) || !(0, types_1.isClass)(srcType)) {
|
|
7380
|
-
return false;
|
|
7381
|
-
}
|
|
7382
|
-
if (!types_1.ClassType.isSameGenericClass(destType, srcType)) {
|
|
7383
|
-
return false;
|
|
7384
|
-
}
|
|
7385
|
-
if (destType.priv.tupleTypeArgs || srcType.priv.tupleTypeArgs) {
|
|
7386
|
-
const destTupleTypeArgs = destType.priv.tupleTypeArgs;
|
|
7387
|
-
const srcTupleTypeArgs = srcType.priv.tupleTypeArgs;
|
|
7388
|
-
if (!destTupleTypeArgs ||
|
|
7389
|
-
!srcTupleTypeArgs ||
|
|
7390
|
-
destTupleTypeArgs.length !== srcTupleTypeArgs.length ||
|
|
7391
|
-
destTupleTypeArgs.some((destTypeArg, index) => destTypeArg.isUnbounded !== srcTupleTypeArgs[index].isUnbounded)) {
|
|
7392
|
-
return false;
|
|
7393
|
-
}
|
|
7394
|
-
return combineMaterializationCoverage(srcTupleTypeArgs.map((srcTypeArg, index) => areAllMaterializationsEquivalent(destTupleTypeArgs[index].type, srcTypeArg.type, recursionCount)));
|
|
7395
|
-
}
|
|
7396
|
-
const destTypeArgs = destType.priv.typeArgs;
|
|
7397
|
-
const srcTypeArgs = srcType.priv.typeArgs;
|
|
7398
|
-
if (!destTypeArgs || !srcTypeArgs || destTypeArgs.length !== srcTypeArgs.length) {
|
|
7399
|
-
return false;
|
|
7400
|
-
}
|
|
7401
|
-
return combineMaterializationCoverage(srcTypeArgs.map((srcTypeArg, index) => areAllMaterializationsEquivalent(destTypeArgs[index], srcTypeArg, recursionCount)));
|
|
7402
|
-
}
|
|
7403
|
-
function areAllMaterializationsAssignable(destType, srcType, recursionCount = 0) {
|
|
7404
|
-
if (recursionCount > types_1.maxTypeRecursionCount) {
|
|
7405
|
-
return undefined;
|
|
7406
|
-
}
|
|
7407
|
-
recursionCount++;
|
|
7408
|
-
if (!(0, typeUtils_1.containsAnyOrUnknown)(srcType, /* recurse */ true)) {
|
|
7409
|
-
return assignType(destType, srcType);
|
|
7410
|
-
}
|
|
7411
|
-
if ((0, types_1.isAnyOrUnknown)(destType)) {
|
|
7412
|
-
return true;
|
|
7413
|
-
}
|
|
7414
|
-
if ((0, types_1.isTypeSame)(destType, srcType, { treatAnySameAsUnknown: true })) {
|
|
7415
|
-
return true;
|
|
7416
|
-
}
|
|
7417
|
-
if ((0, types_1.isTypeVar)(destType) ||
|
|
7418
|
-
(0, types_1.isUnion)(destType) ||
|
|
7419
|
-
(0, types_1.isFunction)(destType) ||
|
|
7420
|
-
(0, types_1.isOverloaded)(destType) ||
|
|
7421
|
-
((0, types_1.isClass)(destType) && types_1.ClassType.isProtocolClass(destType))) {
|
|
7422
|
-
return undefined;
|
|
7423
|
-
}
|
|
7424
|
-
if ((0, types_1.isAnyOrUnknown)(srcType)) {
|
|
7425
|
-
return assignType(destType, getObjectType());
|
|
7426
|
-
}
|
|
7427
|
-
if ((0, types_1.isUnion)(srcType) ||
|
|
7428
|
-
(0, types_1.isUnion)(destType) ||
|
|
7429
|
-
(0, types_1.isFunction)(srcType) ||
|
|
7430
|
-
(0, types_1.isFunction)(destType) ||
|
|
7431
|
-
(0, types_1.isOverloaded)(srcType) ||
|
|
7432
|
-
(0, types_1.isOverloaded)(destType)) {
|
|
7433
|
-
return undefined;
|
|
7434
|
-
}
|
|
7435
|
-
if (!(0, types_1.isClass)(destType) || !(0, types_1.isClass)(srcType)) {
|
|
7436
|
-
return false;
|
|
7437
|
-
}
|
|
7438
|
-
if ((0, typeUtils_1.isTupleClass)(destType) && (0, typeUtils_1.isTupleClass)(srcType)) {
|
|
7439
|
-
const destTupleTypeArgs = destType.priv.tupleTypeArgs;
|
|
7440
|
-
const srcTupleTypeArgs = srcType.priv.tupleTypeArgs;
|
|
7441
|
-
if (!destTupleTypeArgs || !srcTupleTypeArgs) {
|
|
7442
|
-
return undefined;
|
|
7443
|
-
}
|
|
7444
|
-
if (destTupleTypeArgs.length === 1 && destTupleTypeArgs[0].isUnbounded) {
|
|
7445
|
-
return combineMaterializationCoverage(srcTupleTypeArgs.map((srcTypeArg) => areAllMaterializationsAssignable(destTupleTypeArgs[0].type, srcTypeArg.type, recursionCount)));
|
|
7446
|
-
}
|
|
7447
|
-
if (destTupleTypeArgs.length !== srcTupleTypeArgs.length ||
|
|
7448
|
-
destTupleTypeArgs.some((destTypeArg, index) => destTypeArg.isUnbounded !== srcTupleTypeArgs[index].isUnbounded)) {
|
|
7449
|
-
return false;
|
|
7450
|
-
}
|
|
7451
|
-
return combineMaterializationCoverage(srcTupleTypeArgs.map((srcTypeArg, index) => areAllMaterializationsAssignable(destTupleTypeArgs[index].type, srcTypeArg.type, recursionCount)));
|
|
7452
|
-
}
|
|
7453
|
-
let specializedSrcType;
|
|
7454
|
-
if (types_1.ClassType.isSameGenericClass(destType, srcType)) {
|
|
7455
|
-
specializedSrcType = srcType;
|
|
7456
|
-
}
|
|
7457
|
-
else {
|
|
7458
|
-
const instantiableDestType = (0, types_1.isClassInstance)(destType) ? types_1.ClassType.cloneAsInstantiable(destType) : destType;
|
|
7459
|
-
const baseClass = srcType.shared.mro.find((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isSameGenericClass(instantiableDestType, mroClass));
|
|
7460
|
-
if (baseClass && (0, types_1.isClass)(baseClass)) {
|
|
7461
|
-
specializedSrcType = (0, typeUtils_1.specializeForBaseClass)(srcType, baseClass);
|
|
7462
|
-
}
|
|
7463
|
-
}
|
|
7464
|
-
if (!specializedSrcType) {
|
|
7465
|
-
return types_1.ClassType.isBuiltIn(destType, 'object') ? true : undefined;
|
|
7466
|
-
}
|
|
7467
|
-
const typeParams = types_1.ClassType.getTypeParams(destType);
|
|
7468
|
-
if (typeParams.length === 0) {
|
|
7469
|
-
return true;
|
|
7470
|
-
}
|
|
7471
|
-
const destTypeArgs = destType.priv.typeArgs;
|
|
7472
|
-
const srcTypeArgs = specializedSrcType.priv.typeArgs;
|
|
7473
|
-
if (!destTypeArgs) {
|
|
7474
|
-
return true;
|
|
7475
|
-
}
|
|
7476
|
-
if (!srcTypeArgs) {
|
|
7477
|
-
return false;
|
|
7478
|
-
}
|
|
7479
|
-
inferVarianceForClass(destType);
|
|
7480
|
-
return combineMaterializationCoverage(srcTypeArgs.map((srcTypeArg, index) => {
|
|
7481
|
-
const destTypeArg = index < destTypeArgs.length ? destTypeArgs[index] : types_1.UnknownType.create();
|
|
7482
|
-
const typeParam = index < typeParams.length ? typeParams[index] : undefined;
|
|
7483
|
-
const variance = typeParam ? types_1.TypeVarType.getVariance(typeParam) : 2 /* Variance.Invariant */;
|
|
7484
|
-
if (variance === 3 /* Variance.Covariant */) {
|
|
7485
|
-
return areAllMaterializationsAssignable(destTypeArg, srcTypeArg, recursionCount);
|
|
7486
|
-
}
|
|
7487
|
-
if (variance === 2 /* Variance.Invariant */) {
|
|
7488
|
-
return areAllMaterializationsEquivalent(destTypeArg, srcTypeArg, recursionCount);
|
|
7489
|
-
}
|
|
7490
|
-
return undefined;
|
|
7491
|
-
}));
|
|
7492
|
-
}
|
|
7493
7216
|
// Determines whether multiple incompatible overloads match
|
|
7494
7217
|
// due to an Any or Unknown argument type.
|
|
7495
7218
|
function filterOverloadMatchesForAnyArgs(matches) {
|
|
7496
7219
|
if (matches.length < 2) {
|
|
7497
7220
|
return matches;
|
|
7498
7221
|
}
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
// If all of the effective return types match, select the first one.
|
|
7502
|
-
if ((0, typeUtils_1.areTypesSame)(matches.map((match) => hasInvariantAnyOrUnknownArg ? getEffectiveOverloadReturnType(match) : match.returnType), { treatAnySameAsUnknown: true })) {
|
|
7222
|
+
// If all of the return types match, select the first one.
|
|
7223
|
+
if ((0, typeUtils_1.areTypesSame)(matches.map((match) => match.returnType), { treatAnySameAsUnknown: true })) {
|
|
7503
7224
|
return [matches[0]];
|
|
7504
7225
|
}
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7508
|
-
if (hasInvariantAnyOrUnknownArg) {
|
|
7509
|
-
let materializationCheckSupported = true;
|
|
7510
|
-
for (let matchIndex = 0; matchIndex < matches.length; matchIndex++) {
|
|
7511
|
-
const argParamPairs = getOverloadArgParamPairs(matches[matchIndex]);
|
|
7512
|
-
const coverage = argParamPairs.length === firstArgParamPairs.length
|
|
7513
|
-
? combineMaterializationCoverage(argParamPairs.map((pair, index) => {
|
|
7514
|
-
const argType = firstArgParamPairs[index].argType;
|
|
7515
|
-
return areAllMaterializationsAssignable(pair.paramType, argType);
|
|
7516
|
-
}))
|
|
7517
|
-
: false;
|
|
7518
|
-
if (coverage === undefined) {
|
|
7519
|
-
materializationCheckSupported = false;
|
|
7520
|
-
break;
|
|
7521
|
-
}
|
|
7522
|
-
if (coverage) {
|
|
7523
|
-
matches = matches.slice(0, matchIndex + 1);
|
|
7524
|
-
break;
|
|
7525
|
-
}
|
|
7526
|
-
}
|
|
7527
|
-
if (materializationCheckSupported) {
|
|
7528
|
-
if (matches.length < 2) {
|
|
7529
|
-
return matches;
|
|
7530
|
-
}
|
|
7531
|
-
if ((0, typeUtils_1.areTypesSame)(matches.map((match) => getEffectiveOverloadReturnType(match)), { treatAnySameAsUnknown: true })) {
|
|
7532
|
-
return [matches[0]];
|
|
7533
|
-
}
|
|
7534
|
-
firstArgParamPairs = getOverloadArgParamPairs(matches[0]);
|
|
7535
|
-
for (let i = 0; i < firstArgParamPairs.length; i++) {
|
|
7536
|
-
if (getAnyOrUnknownInInvariantPosition(firstArgParamPairs[i].argType)) {
|
|
7537
|
-
const paramTypes = matches.map((match) => {
|
|
7538
|
-
const argParamPairs = getOverloadArgParamPairs(match);
|
|
7539
|
-
return i < argParamPairs.length ? argParamPairs[i].paramType : types_1.UnknownType.create();
|
|
7540
|
-
});
|
|
7541
|
-
if (!(0, typeUtils_1.areTypesSame)(paramTypes, { treatAnySameAsUnknown: true })) {
|
|
7542
|
-
return matches;
|
|
7543
|
-
}
|
|
7544
|
-
}
|
|
7545
|
-
}
|
|
7546
|
-
}
|
|
7226
|
+
const firstArgResults = matches[0].argResults;
|
|
7227
|
+
if (!firstArgResults) {
|
|
7228
|
+
return matches;
|
|
7547
7229
|
}
|
|
7548
7230
|
let foundAmbiguousAnyArg = false;
|
|
7549
|
-
for (let i = 0; i <
|
|
7231
|
+
for (let i = 0; i < firstArgResults.length; i++) {
|
|
7550
7232
|
// If the arg is Any or Unknown, see if the corresponding
|
|
7551
7233
|
// parameter types differ in any way.
|
|
7552
|
-
if ((0, types_1.isAnyOrUnknown)(
|
|
7553
|
-
const paramTypes = matches.map((match) =>
|
|
7554
|
-
|
|
7555
|
-
|
|
7556
|
-
});
|
|
7234
|
+
if ((0, types_1.isAnyOrUnknown)(firstArgResults[i].argType)) {
|
|
7235
|
+
const paramTypes = matches.map((match) => i < match.matchResults.argParams.length
|
|
7236
|
+
? match.matchResults.argParams[i].paramType
|
|
7237
|
+
: types_1.UnknownType.create());
|
|
7557
7238
|
if (!(0, typeUtils_1.areTypesSame)(paramTypes, { treatAnySameAsUnknown: true })) {
|
|
7558
7239
|
foundAmbiguousAnyArg = true;
|
|
7559
7240
|
}
|
|
@@ -7564,8 +7245,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
7564
7245
|
// that one of the arguments is an unpacked iterator, and it maps to
|
|
7565
7246
|
// an indeterminate number of parameters, which means that the overload
|
|
7566
7247
|
// selection is ambiguous.
|
|
7567
|
-
if (foundAmbiguousAnyArg ||
|
|
7568
|
-
matches.some((match) => getOverloadArgParamPairs(match).length !== firstArgParamPairs.length)) {
|
|
7248
|
+
if (foundAmbiguousAnyArg || matches.some((match) => match.argResults.length !== firstArgResults.length)) {
|
|
7569
7249
|
return matches;
|
|
7570
7250
|
}
|
|
7571
7251
|
return [matches[0]];
|
|
@@ -9341,9 +9021,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9341
9021
|
let argumentErrors = false;
|
|
9342
9022
|
let argumentMatchScore = 0;
|
|
9343
9023
|
let specializedInitSelfType;
|
|
9344
|
-
let anyOrUnknownArg
|
|
9345
|
-
? getAnyOrUnknownInInvariantPosition(type.priv.boundToType)
|
|
9346
|
-
: undefined;
|
|
9024
|
+
let anyOrUnknownArg;
|
|
9347
9025
|
const speculativeNode = getSpeculativeNodeForCall(errorNode);
|
|
9348
9026
|
const typeCondition = (0, typeUtils_1.getTypeCondition)(type);
|
|
9349
9027
|
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
|
|
@@ -9441,11 +9119,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
|
9441
9119
|
if (argResult.condition) {
|
|
9442
9120
|
condition = types_1.TypeCondition.combine(condition, argResult.condition) ?? [];
|
|
9443
9121
|
}
|
|
9444
|
-
|
|
9445
|
-
|
|
9446
|
-
|
|
9447
|
-
|
|
9448
|
-
anyOrUnknownArg = anyOrUnknownArg ? (0, typeUtils_1.preserveUnknown)(argAnyOrUnknown, anyOrUnknownArg) : argAnyOrUnknown;
|
|
9122
|
+
if ((0, types_1.isAnyOrUnknown)(argResult.argType)) {
|
|
9123
|
+
anyOrUnknownArg = anyOrUnknownArg
|
|
9124
|
+
? (0, typeUtils_1.preserveUnknown)(argResult.argType, anyOrUnknownArg)
|
|
9125
|
+
: argResult.argType;
|
|
9449
9126
|
}
|
|
9450
9127
|
if (paramSpec) {
|
|
9451
9128
|
if (argParam.argument.argCategory === 1 /* ArgCategory.UnpackedList */) {
|