@zzzen/pyright-internal 1.2.0-dev.20240602 → 1.2.0-dev.20240609
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 +14 -8
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +47 -30
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +26 -34
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +1 -1
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +2 -5
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +1 -1
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/enums.d.ts +1 -1
- package/dist/analyzer/enums.js +19 -16
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/operations.js +6 -7
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +1 -13
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +4 -4
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/properties.js +2 -2
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +2 -2
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceFile.js +3 -3
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +279 -209
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -3
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +3 -2
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +21 -14
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +3 -4
- package/dist/analyzer/typeUtils.js +89 -124
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +4 -0
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/types.d.ts +11 -12
- package/dist/analyzer/types.js +137 -169
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +1 -1
- package/dist/backgroundAnalysisBase.js +3 -3
- package/dist/commands/dumpFileDebugInfoCommand.js +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/configOptions.d.ts +2 -1
- package/dist/common/configOptions.js +12 -3
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +3 -3
- package/dist/common/realFileSystem.js +6 -6
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/languageServerBase.js +1 -1
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.js +1 -1
- package/dist/localization/localize.d.ts +6 -0
- package/dist/localization/localize.js +3 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +2 -2
- package/dist/localization/package.nls.de.json +2 -2
- package/dist/localization/package.nls.en-us.json +3 -0
- 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 +2 -2
- package/dist/localization/package.nls.ja.json +2 -2
- package/dist/localization/package.nls.ko.json +3 -3
- package/dist/localization/package.nls.pl.json +2 -2
- package/dist/localization/package.nls.pt-br.json +2 -2
- 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 +2 -2
- package/dist/localization/package.nls.zh-cn.json +2 -2
- package/dist/localization/package.nls.zh-tw.json +2 -2
- package/dist/pyright.js +3 -0
- package/dist/pyright.js.map +1 -1
- package/dist/tests/config.test.js +2 -2
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/diagnosticOverrides.test.js +7 -6
- package/dist/tests/diagnosticOverrides.test.js.map +1 -1
- package/dist/tests/testState.test.js +1 -1
- package/dist/tests/testState.test.js.map +1 -1
- package/dist/tests/testUtils.js +1 -1
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +8 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +7 -3
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +15 -9
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +2 -2
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/package.json +1 -1
@@ -679,7 +679,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
679
679
|
}
|
680
680
|
case 3 /* ParseNodeType.Assignment */: {
|
681
681
|
typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext, signatureTracker);
|
682
|
-
assignTypeToExpression(node.leftExpression, typeResult
|
682
|
+
assignTypeToExpression(node.leftExpression, typeResult, node.rightExpression,
|
683
683
|
/* ignoreEmptyContainers */ true,
|
684
684
|
/* allowAssignmentToFinalVar */ true);
|
685
685
|
break;
|
@@ -689,8 +689,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
689
689
|
addError(localize_1.LocMessage.walrusNotAllowed(), node);
|
690
690
|
}
|
691
691
|
typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext, signatureTracker);
|
692
|
-
assignTypeToExpression(node.name, typeResult
|
693
|
-
/* ignoreEmptyContainers */ true);
|
692
|
+
assignTypeToExpression(node.name, typeResult, node.rightExpression, /* ignoreEmptyContainers */ true);
|
694
693
|
break;
|
695
694
|
}
|
696
695
|
case 60 /* ParseNodeType.Yield */: {
|
@@ -1271,9 +1270,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1271
1270
|
const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
|
1272
1271
|
if ((0, types_1.isClassInstance)(concreteSubtype)) {
|
1273
1272
|
if (concreteSubtype.literalValue !== undefined) {
|
1273
|
+
let isLiteralFalsy;
|
1274
|
+
if (concreteSubtype.literalValue instanceof types_1.EnumLiteral) {
|
1275
|
+
isLiteralFalsy = !canBeTruthy(concreteSubtype);
|
1276
|
+
}
|
1277
|
+
else {
|
1278
|
+
isLiteralFalsy = !concreteSubtype.literalValue;
|
1279
|
+
}
|
1274
1280
|
// If the object is already definitely falsy, it's fine to
|
1275
1281
|
// include, otherwise it should be removed.
|
1276
|
-
return
|
1282
|
+
return isLiteralFalsy ? subtype : undefined;
|
1277
1283
|
}
|
1278
1284
|
// If the object is a bool, make it "false", since
|
1279
1285
|
// "true" is a truthy value.
|
@@ -1307,9 +1313,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1307
1313
|
const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
|
1308
1314
|
if ((0, types_1.isClassInstance)(concreteSubtype)) {
|
1309
1315
|
if (concreteSubtype.literalValue !== undefined) {
|
1316
|
+
let isLiteralTruthy;
|
1317
|
+
if (concreteSubtype.literalValue instanceof types_1.EnumLiteral) {
|
1318
|
+
isLiteralTruthy = !canBeFalsy(concreteSubtype);
|
1319
|
+
}
|
1320
|
+
else {
|
1321
|
+
isLiteralTruthy = !!concreteSubtype.literalValue;
|
1322
|
+
}
|
1310
1323
|
// If the object is already definitely truthy, it's fine to
|
1311
1324
|
// include, otherwise it should be removed.
|
1312
|
-
return
|
1325
|
+
return isLiteralTruthy ? subtype : undefined;
|
1313
1326
|
}
|
1314
1327
|
// If the object is a bool, make it "true", since
|
1315
1328
|
// "false" is a falsy value.
|
@@ -2022,7 +2035,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2022
2035
|
errorRange = { start: 0, length: 0 };
|
2023
2036
|
}
|
2024
2037
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
2025
|
-
addDiagnosticForTextRange(fileInfo,
|
2038
|
+
addDiagnosticForTextRange(fileInfo, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.codeTooComplexToAnalyze(), errorRange);
|
2026
2039
|
return true;
|
2027
2040
|
}
|
2028
2041
|
return false;
|
@@ -2163,7 +2176,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2163
2176
|
}
|
2164
2177
|
return diagnostic;
|
2165
2178
|
}
|
2166
|
-
function addDiagnosticForTextRange(fileInfo,
|
2179
|
+
function addDiagnosticForTextRange(fileInfo, rule, message, range) {
|
2180
|
+
const diagLevel = fileInfo.diagnosticRuleSet[rule];
|
2167
2181
|
if (diagLevel === 'none') {
|
2168
2182
|
return undefined;
|
2169
2183
|
}
|
@@ -2184,7 +2198,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2184
2198
|
}
|
2185
2199
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeExpectedClass().format({ type: printType(type) }) + diag.getString(), node);
|
2186
2200
|
}
|
2187
|
-
function assignTypeToNameNode(nameNode,
|
2201
|
+
function assignTypeToNameNode(nameNode, typeResult, ignoreEmptyContainers, srcExpression, allowAssignmentToFinalVar = false, expectedTypeDiagAddendum) {
|
2188
2202
|
var _a, _b, _c;
|
2189
2203
|
const nameValue = nameNode.value;
|
2190
2204
|
const symbolWithScope = lookUpSymbolRecursive(nameNode, nameValue, /* honorCodeFlow */ false);
|
@@ -2211,18 +2225,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2211
2225
|
}
|
2212
2226
|
}
|
2213
2227
|
// We found an existing declared type. Make sure the type is assignable.
|
2214
|
-
let destType = type;
|
2228
|
+
let destType = typeResult.type;
|
2215
2229
|
const isTypeAlias = !!declaredType && (0, types_1.isClassInstance)(declaredType) && types_1.ClassType.isBuiltIn(declaredType, 'TypeAlias');
|
2216
2230
|
if (declaredType && !isTypeAlias) {
|
2217
2231
|
let diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
2218
|
-
if (!assignType(declaredType, type, diagAddendum)) {
|
2232
|
+
if (!assignType(declaredType, typeResult.type, diagAddendum)) {
|
2219
2233
|
// If there was an expected type mismatch, use that diagnostic
|
2220
2234
|
// addendum because it will be more informative.
|
2221
2235
|
if (expectedTypeDiagAddendum) {
|
2222
2236
|
diagAddendum = expectedTypeDiagAddendum;
|
2223
2237
|
}
|
2224
|
-
if (!
|
2225
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, localize_1.LocMessage.typeAssignmentMismatch().format(printSrcDestTypes(type, declaredType)) +
|
2238
|
+
if (!typeResult.isIncomplete) {
|
2239
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, localize_1.LocMessage.typeAssignmentMismatch().format(printSrcDestTypes(typeResult.type, declaredType)) +
|
2226
2240
|
diagAddendum.getString(), srcExpression !== null && srcExpression !== void 0 ? srcExpression : nameNode, (_c = (_b = diagAddendum.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : srcExpression) !== null && _c !== void 0 ? _c : nameNode);
|
2227
2241
|
}
|
2228
2242
|
// Replace the assigned type with the (unnarrowed) declared type.
|
@@ -2230,7 +2244,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2230
2244
|
}
|
2231
2245
|
else {
|
2232
2246
|
// Constrain the resulting type to match the declared type.
|
2233
|
-
destType = narrowTypeBasedOnAssignment(nameNode, declaredType, type
|
2247
|
+
destType = narrowTypeBasedOnAssignment(nameNode, declaredType, typeResult).type;
|
2234
2248
|
}
|
2235
2249
|
}
|
2236
2250
|
else {
|
@@ -2263,12 +2277,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2263
2277
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalReassigned().format({ name: nameValue }), nameNode);
|
2264
2278
|
}
|
2265
2279
|
}
|
2266
|
-
if (!
|
2280
|
+
if (!typeResult.isIncomplete) {
|
2267
2281
|
reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, nameNode, destType, nameNode, ignoreEmptyContainers);
|
2268
2282
|
}
|
2269
|
-
writeTypeCache(nameNode, { type: destType, isIncomplete:
|
2283
|
+
writeTypeCache(nameNode, { type: destType, isIncomplete: typeResult.isIncomplete }, 0 /* EvaluatorFlags.None */);
|
2270
2284
|
}
|
2271
|
-
function assignTypeToMemberAccessNode(target,
|
2285
|
+
function assignTypeToMemberAccessNode(target, typeResult, srcExpr, expectedTypeDiagAddendum) {
|
2272
2286
|
var _a;
|
2273
2287
|
const baseTypeResult = getTypeOfExpression(target.leftExpression, 2 /* EvaluatorFlags.MemberAccessBaseDefaults */);
|
2274
2288
|
const baseType = makeTopLevelTypeVarsConcrete(baseTypeResult.type);
|
@@ -2281,14 +2295,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2281
2295
|
if (classTypeResults && (0, types_1.isInstantiableClass)(classTypeResults.classType)) {
|
2282
2296
|
if ((0, types_1.isClassInstance)(baseType)) {
|
2283
2297
|
if (types_1.ClassType.isSameGenericClass(baseType, classTypeResults.classType)) {
|
2284
|
-
assignTypeToMemberVariable(target,
|
2285
|
-
/* isInstanceMember */ true, srcExpr);
|
2298
|
+
assignTypeToMemberVariable(target, typeResult, /* isInstanceMember */ true, srcExpr);
|
2286
2299
|
}
|
2287
2300
|
}
|
2288
2301
|
else if ((0, types_1.isInstantiableClass)(baseType)) {
|
2289
2302
|
if (types_1.ClassType.isSameGenericClass(baseType, classTypeResults.classType)) {
|
2290
|
-
assignTypeToMemberVariable(target,
|
2291
|
-
/* isInstanceMember */ false, srcExpr);
|
2303
|
+
assignTypeToMemberVariable(target, typeResult, /* isInstanceMember */ false, srcExpr);
|
2292
2304
|
}
|
2293
2305
|
}
|
2294
2306
|
// Assignments to instance or class variables through "self" or "cls" is not
|
@@ -2309,7 +2321,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2309
2321
|
}
|
2310
2322
|
const setTypeResult = getTypeOfMemberAccessWithBaseType(target, baseTypeResult, {
|
2311
2323
|
method: 'set',
|
2312
|
-
setType:
|
2324
|
+
setType: typeResult,
|
2313
2325
|
setErrorNode: srcExpr,
|
2314
2326
|
setExpectedTypeDiag: expectedTypeDiagAddendum,
|
2315
2327
|
}, 0 /* EvaluatorFlags.None */);
|
@@ -2317,14 +2329,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2317
2329
|
setAsymmetricDescriptorAssignment(target);
|
2318
2330
|
}
|
2319
2331
|
const resultToCache = {
|
2320
|
-
type: (_a = setTypeResult.narrowedTypeForSet) !== null && _a !== void 0 ? _a : type,
|
2321
|
-
isIncomplete:
|
2332
|
+
type: (_a = setTypeResult.narrowedTypeForSet) !== null && _a !== void 0 ? _a : typeResult.type,
|
2333
|
+
isIncomplete: typeResult.isIncomplete,
|
2322
2334
|
memberAccessDeprecationInfo: setTypeResult.memberAccessDeprecationInfo,
|
2323
2335
|
};
|
2324
2336
|
writeTypeCache(target.memberName, resultToCache, 0 /* EvaluatorFlags.None */);
|
2325
2337
|
writeTypeCache(target, resultToCache, 0 /* EvaluatorFlags.None */);
|
2326
2338
|
}
|
2327
|
-
function assignTypeToMemberVariable(node,
|
2339
|
+
function assignTypeToMemberVariable(node, typeResult, isInstanceMember, srcExprNode) {
|
2328
2340
|
var _a;
|
2329
2341
|
const memberName = node.memberName.value;
|
2330
2342
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -2394,20 +2406,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2394
2406
|
// The class variable is accessed in this case.
|
2395
2407
|
setSymbolAccessed(fileInfo, memberInfo.symbol, node.memberName);
|
2396
2408
|
const memberType = getTypeOfMember(memberInfo);
|
2397
|
-
|
2409
|
+
typeResult = { ...typeResult, type: (0, types_1.combineTypes)([typeResult.type, memberType]) };
|
2398
2410
|
}
|
2399
2411
|
}
|
2400
2412
|
}
|
2401
2413
|
}
|
2402
2414
|
// Look up the member info again, now that we've potentially updated it.
|
2403
2415
|
memberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, memberName, 64 /* MemberAccessFlags.DeclaredTypesOnly */);
|
2404
|
-
if (!memberInfo && srcExprNode && !
|
2405
|
-
reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownMemberType, diagnosticRules_1.DiagnosticRule.reportUnknownMemberType, node.memberName,
|
2416
|
+
if (!memberInfo && srcExprNode && !typeResult.isIncomplete) {
|
2417
|
+
reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownMemberType, diagnosticRules_1.DiagnosticRule.reportUnknownMemberType, node.memberName, typeResult.type, node,
|
2406
2418
|
/* ignoreEmptyContainers */ true);
|
2407
2419
|
}
|
2408
2420
|
}
|
2409
2421
|
}
|
2410
|
-
function assignTypeToTupleOrListNode(target,
|
2422
|
+
function assignTypeToTupleOrListNode(target, typeResult, srcExpr) {
|
2411
2423
|
const targetExpressions = target.nodeType === 34 /* ParseNodeType.List */ ? target.entries : target.expressions;
|
2412
2424
|
// Initialize the array of target types, one for each target.
|
2413
2425
|
const targetTypes = new Array(targetExpressions.length);
|
@@ -2418,9 +2430,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2418
2430
|
// Do any of the targets use an unpack operator? If so, it will consume all of the
|
2419
2431
|
// entries at that location.
|
2420
2432
|
const unpackIndex = targetExpressions.findIndex((expr) => expr.nodeType === 56 /* ParseNodeType.Unpack */);
|
2421
|
-
|
2433
|
+
typeResult = { ...typeResult, type: makeTopLevelTypeVarsConcrete(typeResult.type) };
|
2422
2434
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
2423
|
-
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
2435
|
+
(0, typeUtils_1.doForEachSubtype)(typeResult.type, (subtype) => {
|
2424
2436
|
var _a, _b;
|
2425
2437
|
// Is this subtype a tuple?
|
2426
2438
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(subtype);
|
@@ -2475,7 +2487,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2475
2487
|
else {
|
2476
2488
|
// The assigned expression isn't a tuple, so it had better
|
2477
2489
|
// be some iterable type.
|
2478
|
-
const iterableType = (_b = (_a = getTypeOfIterator({ type: subtype, isIncomplete:
|
2490
|
+
const iterableType = (_b = (_a = getTypeOfIterator({ type: subtype, isIncomplete: typeResult.isIncomplete },
|
2491
|
+
/* isAsync */ false, srcExpr)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
2479
2492
|
for (let index = 0; index < targetExpressions.length; index++) {
|
2480
2493
|
targetTypes[index].push((0, typeUtils_1.addConditionToType)(iterableType, (0, typeUtils_1.getTypeCondition)(subtype)));
|
2481
2494
|
}
|
@@ -2485,7 +2498,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2485
2498
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, (target.nodeType === 34 /* ParseNodeType.List */
|
2486
2499
|
? localize_1.LocMessage.listAssignmentMismatch()
|
2487
2500
|
: localize_1.LocMessage.tupleAssignmentMismatch()).format({
|
2488
|
-
type: printType(type),
|
2501
|
+
type: printType(typeResult.type),
|
2489
2502
|
}) + diagAddendum.getString(), target);
|
2490
2503
|
}
|
2491
2504
|
// Assign the resulting types to the individual names in the tuple
|
@@ -2493,9 +2506,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2493
2506
|
targetExpressions.forEach((expr, index) => {
|
2494
2507
|
const typeList = targetTypes[index];
|
2495
2508
|
const targetType = typeList.length === 0 ? types_1.UnknownType.create() : (0, types_1.combineTypes)(typeList);
|
2496
|
-
assignTypeToExpression(expr, targetType,
|
2509
|
+
assignTypeToExpression(expr, { type: targetType, isIncomplete: typeResult.isIncomplete }, srcExpr,
|
2510
|
+
/* ignoreEmptyContainers */ true);
|
2497
2511
|
});
|
2498
|
-
writeTypeCache(target,
|
2512
|
+
writeTypeCache(target, typeResult, 0 /* EvaluatorFlags.None */);
|
2499
2513
|
}
|
2500
2514
|
// If the type includes promotion types, expand these to their constituent types.
|
2501
2515
|
function expandPromotionTypes(node, type, excludeBytes = false) {
|
@@ -2546,11 +2560,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2546
2560
|
}
|
2547
2561
|
// If this is a function that contains only a ParamSpec (no additional
|
2548
2562
|
// parameters), convert it to a concrete type of (*args: Any, **kwargs: Any).
|
2549
|
-
if (makeParamSpecsConcrete &&
|
2550
|
-
(0,
|
2551
|
-
|
2552
|
-
|
2553
|
-
|
2563
|
+
if (makeParamSpecsConcrete && (0, types_1.isFunction)(subtype)) {
|
2564
|
+
const convertedType = (0, typeUtils_1.convertParamSpecValueToType)(subtype);
|
2565
|
+
if ((0, types_1.isParamSpec)(convertedType)) {
|
2566
|
+
return types_1.FunctionType.applyParamSpecValue(subtype, (0, typeUtils_1.getUnknownTypeForCallable)());
|
2567
|
+
}
|
2554
2568
|
}
|
2555
2569
|
if ((0, types_1.isTypeVar)(subtype) && subtype.details.isVariadic) {
|
2556
2570
|
// If it's in a union, convert to type or object.
|
@@ -2719,9 +2733,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2719
2733
|
});
|
2720
2734
|
}
|
2721
2735
|
}
|
2722
|
-
function assignTypeToExpression(target,
|
2736
|
+
function assignTypeToExpression(target, typeResult, srcExpr, ignoreEmptyContainers = false, allowAssignmentToFinalVar = false, expectedTypeDiagAddendum) {
|
2723
2737
|
// Is the source expression a TypeVar() call?
|
2724
|
-
if ((0, types_1.isTypeVar)(type)) {
|
2738
|
+
if ((0, types_1.isTypeVar)(typeResult.type)) {
|
2725
2739
|
if (srcExpr && srcExpr.nodeType === 9 /* ParseNodeType.Call */) {
|
2726
2740
|
const callType = getTypeOfExpression(srcExpr.leftExpression, 2 /* EvaluatorFlags.CallBaseDefaults */).type;
|
2727
2741
|
if ((0, types_1.isInstantiableClass)(callType) &&
|
@@ -2729,13 +2743,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2729
2743
|
types_1.ClassType.isBuiltIn(callType, 'TypeVarTuple') ||
|
2730
2744
|
types_1.ClassType.isBuiltIn(callType, 'ParamSpec'))) {
|
2731
2745
|
const typeVarTarget = target.nodeType === 54 /* ParseNodeType.TypeAnnotation */ ? target.valueExpression : target;
|
2732
|
-
if (typeVarTarget.nodeType !== 38 /* ParseNodeType.Name */ ||
|
2733
|
-
|
2746
|
+
if (typeVarTarget.nodeType !== 38 /* ParseNodeType.Name */ ||
|
2747
|
+
typeVarTarget.value !== typeResult.type.details.name) {
|
2748
|
+
addError(typeResult.type.details.isParamSpec
|
2734
2749
|
? localize_1.LocMessage.paramSpecAssignedName().format({
|
2735
|
-
name: types_1.TypeVarType.getReadableName(type),
|
2750
|
+
name: types_1.TypeVarType.getReadableName(typeResult.type),
|
2736
2751
|
})
|
2737
2752
|
: localize_1.LocMessage.typeVarAssignedName().format({
|
2738
|
-
name: types_1.TypeVarType.getReadableName(type),
|
2753
|
+
name: types_1.TypeVarType.getReadableName(typeResult.type),
|
2739
2754
|
}), typeVarTarget);
|
2740
2755
|
}
|
2741
2756
|
}
|
@@ -2744,30 +2759,32 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2744
2759
|
// If the type was partially unbound, an error will have already been logged.
|
2745
2760
|
// Remove the unbound before assigning to the target expression so the unbound
|
2746
2761
|
// error doesn't propagate.
|
2747
|
-
type
|
2762
|
+
if ((0, types_1.findSubtype)(typeResult.type, (subtype) => (0, types_1.isUnbound)(subtype))) {
|
2763
|
+
typeResult = { ...typeResult, type: (0, types_1.removeUnbound)(typeResult.type) };
|
2764
|
+
}
|
2748
2765
|
switch (target.nodeType) {
|
2749
2766
|
case 38 /* ParseNodeType.Name */: {
|
2750
|
-
assignTypeToNameNode(target,
|
2767
|
+
assignTypeToNameNode(target, typeResult, ignoreEmptyContainers, srcExpr, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
|
2751
2768
|
break;
|
2752
2769
|
}
|
2753
2770
|
case 35 /* ParseNodeType.MemberAccess */: {
|
2754
|
-
assignTypeToMemberAccessNode(target,
|
2771
|
+
assignTypeToMemberAccessNode(target, typeResult, srcExpr, expectedTypeDiagAddendum);
|
2755
2772
|
break;
|
2756
2773
|
}
|
2757
2774
|
case 27 /* ParseNodeType.Index */: {
|
2758
2775
|
const baseTypeResult = getTypeOfExpression(target.baseExpression, 2 /* EvaluatorFlags.IndexBaseDefaults */);
|
2759
2776
|
getTypeOfIndexWithBaseType(target, baseTypeResult, {
|
2760
2777
|
method: 'set',
|
2761
|
-
setType:
|
2778
|
+
setType: typeResult,
|
2762
2779
|
setErrorNode: srcExpr,
|
2763
2780
|
setExpectedTypeDiag: expectedTypeDiagAddendum,
|
2764
2781
|
}, 0 /* EvaluatorFlags.None */);
|
2765
|
-
writeTypeCache(target,
|
2782
|
+
writeTypeCache(target, typeResult, 0 /* EvaluatorFlags.None */);
|
2766
2783
|
break;
|
2767
2784
|
}
|
2768
2785
|
case 34 /* ParseNodeType.List */:
|
2769
2786
|
case 52 /* ParseNodeType.Tuple */: {
|
2770
|
-
assignTypeToTupleOrListNode(target,
|
2787
|
+
assignTypeToTupleOrListNode(target, typeResult, srcExpr);
|
2771
2788
|
break;
|
2772
2789
|
}
|
2773
2790
|
case 54 /* ParseNodeType.TypeAnnotation */: {
|
@@ -2782,23 +2799,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2782
2799
|
if (!isBareFinalOrClassVar) {
|
2783
2800
|
const isTypeAliasAnnotation = (0, types_1.isClassInstance)(annotationType) && types_1.ClassType.isBuiltIn(annotationType, 'TypeAlias');
|
2784
2801
|
if (!isTypeAliasAnnotation) {
|
2785
|
-
if (assignType(annotationType, type)) {
|
2802
|
+
if (assignType(annotationType, typeResult.type)) {
|
2786
2803
|
// Don't attempt to narrow based on the annotated type if the type
|
2787
2804
|
// is a enum because the annotated type in an enum doesn't reflect
|
2788
2805
|
// the type of the symbol.
|
2789
|
-
if (!(0, types_1.isClassInstance)(type) || !types_1.ClassType.isEnumClass(type)) {
|
2790
|
-
|
2806
|
+
if (!(0, types_1.isClassInstance)(typeResult.type) || !types_1.ClassType.isEnumClass(typeResult.type)) {
|
2807
|
+
typeResult = narrowTypeBasedOnAssignment(target, annotationType, typeResult);
|
2791
2808
|
}
|
2792
2809
|
}
|
2793
2810
|
}
|
2794
2811
|
}
|
2795
|
-
assignTypeToExpression(target.valueExpression,
|
2812
|
+
assignTypeToExpression(target.valueExpression, typeResult, srcExpr, ignoreEmptyContainers, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
|
2796
2813
|
break;
|
2797
2814
|
}
|
2798
2815
|
case 56 /* ParseNodeType.Unpack */: {
|
2799
2816
|
if (target.expression.nodeType === 38 /* ParseNodeType.Name */) {
|
2800
|
-
assignTypeToNameNode(target.expression,
|
2801
|
-
|
2817
|
+
assignTypeToNameNode(target.expression, {
|
2818
|
+
type: getBuiltInObject(target.expression, 'list', [typeResult.type]),
|
2819
|
+
isIncomplete: typeResult.isIncomplete,
|
2820
|
+
}, ignoreEmptyContainers, srcExpr);
|
2802
2821
|
}
|
2803
2822
|
break;
|
2804
2823
|
}
|
@@ -4014,7 +4033,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4014
4033
|
// descriptor-based accesses.
|
4015
4034
|
narrowedTypeForSet = isDescriptorApplied
|
4016
4035
|
? usage.setType.type
|
4017
|
-
: narrowTypeBasedOnAssignment(errorNode, type, usage.setType.type
|
4036
|
+
: narrowTypeBasedOnAssignment(errorNode, type, usage.setType).type;
|
4018
4037
|
}
|
4019
4038
|
// Verify that the assigned type is compatible.
|
4020
4039
|
if (!assignType(type, usage.setType.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum())) {
|
@@ -4301,7 +4320,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4301
4320
|
// If there's no declared return type on the getter, assume it's symmetric.
|
4302
4321
|
if (setterType.details.parameters.length >= 3 && getterType.details.declaredReturnType) {
|
4303
4322
|
const setterValueType = types_1.FunctionType.getEffectiveParameterType(setterType, 2);
|
4304
|
-
const getterReturnType = (_a = types_1.FunctionType.
|
4323
|
+
const getterReturnType = (_a = types_1.FunctionType.getEffectiveReturnType(getterType)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
4305
4324
|
if (!(0, types_1.isTypeSame)(setterValueType, getterReturnType)) {
|
4306
4325
|
isAsymmetric = true;
|
4307
4326
|
}
|
@@ -4333,7 +4352,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4333
4352
|
// If there's no declared return type on the getter, assume it's symmetric.
|
4334
4353
|
if (setterType.details.parameters.length >= 3 && getterType.details.declaredReturnType) {
|
4335
4354
|
const setterValueType = types_1.FunctionType.getEffectiveParameterType(setterType, 2);
|
4336
|
-
const getterReturnType = (_a = types_1.FunctionType.
|
4355
|
+
const getterReturnType = (_a = types_1.FunctionType.getEffectiveReturnType(getterType)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
4337
4356
|
if (!(0, types_1.isTypeSame)(setterValueType, getterReturnType)) {
|
4338
4357
|
isAsymmetric = true;
|
4339
4358
|
}
|
@@ -4699,11 +4718,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4699
4718
|
if (index === concatTypeArgs.length - 1) {
|
4700
4719
|
types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
|
4701
4720
|
if ((0, types_1.isParamSpec)(typeArg)) {
|
4702
|
-
|
4721
|
+
types_1.FunctionType.addParamSpecVariadics(functionType, typeArg);
|
4703
4722
|
}
|
4704
4723
|
else if ((0, typeUtils_1.isEllipsisType)(typeArg)) {
|
4705
4724
|
types_1.FunctionType.addDefaultParameters(functionType);
|
4706
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
4725
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
4707
4726
|
}
|
4708
4727
|
}
|
4709
4728
|
else {
|
@@ -4720,7 +4739,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4720
4739
|
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
|
4721
4740
|
}
|
4722
4741
|
else if ((0, typeUtils_1.isEllipsisType)(typeArgType)) {
|
4723
|
-
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.
|
4742
|
+
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.GradualCallableForm */);
|
4724
4743
|
types_1.FunctionType.addDefaultParameters(functionType);
|
4725
4744
|
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext);
|
4726
4745
|
}
|
@@ -5822,24 +5841,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5822
5841
|
const type = typeResult.type;
|
5823
5842
|
const exprString = ParseTreeUtils.printExpression(arg0Value);
|
5824
5843
|
const typeString = printType(type, { expandTypeAlias: true });
|
5825
|
-
if (
|
5826
|
-
if (expectedText !==
|
5827
|
-
|
5828
|
-
|
5829
|
-
|
5830
|
-
|
5844
|
+
if (!typeResult.isIncomplete) {
|
5845
|
+
if (expectedText !== undefined) {
|
5846
|
+
if (expectedText !== typeString) {
|
5847
|
+
addError(localize_1.LocMessage.revealTypeExpectedTextMismatch().format({
|
5848
|
+
expected: expectedText,
|
5849
|
+
received: typeString,
|
5850
|
+
}), expectedTextNode !== null && expectedTextNode !== void 0 ? expectedTextNode : arg0Value);
|
5851
|
+
}
|
5831
5852
|
}
|
5832
|
-
|
5833
|
-
|
5834
|
-
|
5835
|
-
|
5836
|
-
|
5837
|
-
|
5838
|
-
|
5839
|
-
}
|
5853
|
+
if (expectedRevealType) {
|
5854
|
+
if (!(0, types_1.isTypeSame)(expectedRevealType, type, { ignorePseudoGeneric: true })) {
|
5855
|
+
const expectedRevealTypeText = printType(expectedRevealType);
|
5856
|
+
addError(localize_1.LocMessage.revealTypeExpectedTypeMismatch().format({
|
5857
|
+
expected: expectedRevealTypeText,
|
5858
|
+
received: typeString,
|
5859
|
+
}), expectedRevealTypeNode !== null && expectedRevealTypeNode !== void 0 ? expectedRevealTypeNode : arg0Value);
|
5860
|
+
}
|
5840
5861
|
}
|
5862
|
+
addInformation(localize_1.LocAddendum.typeOfSymbol().format({ name: exprString, type: typeString }), node.arguments[0]);
|
5841
5863
|
}
|
5842
|
-
addInformation(localize_1.LocAddendum.typeOfSymbol().format({ name: exprString, type: typeString }), node.arguments[0]);
|
5843
5864
|
return { type, isIncomplete: typeResult.isIncomplete };
|
5844
5865
|
}
|
5845
5866
|
function getTypeOfRevealLocals(node) {
|
@@ -7074,6 +7095,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7074
7095
|
let reportedArgError = false;
|
7075
7096
|
let isTypeIncomplete = !!typeResult.isIncomplete;
|
7076
7097
|
let isVariadicTypeVarFullyMatched = false;
|
7098
|
+
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(typeResult.type);
|
7077
7099
|
// Expand any unpacked tuples in the arg list.
|
7078
7100
|
argList = expandArgList(argList, signatureTracker);
|
7079
7101
|
// Build a map of parameters by name.
|
@@ -7099,6 +7121,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7099
7121
|
let paramSpecArgList;
|
7100
7122
|
let paramSpecTarget;
|
7101
7123
|
let hasParamSpecArgsKwargs = false;
|
7124
|
+
// Determine how many positional args are being passed before
|
7125
|
+
// we see a keyword arg.
|
7126
|
+
let positionalArgCount = argList.findIndex((arg) => arg.argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */ || arg.name !== undefined);
|
7127
|
+
if (positionalArgCount < 0) {
|
7128
|
+
positionalArgCount = argList.length;
|
7129
|
+
}
|
7102
7130
|
if (varArgListParamIndex !== undefined && varArgDictParamIndex !== undefined) {
|
7103
7131
|
(0, debug_1.assert)(paramDetails.params[varArgListParamIndex], 'varArgListParamIndex params entry is undefined');
|
7104
7132
|
const varArgListParam = paramDetails.params[varArgListParamIndex].param;
|
@@ -7120,16 +7148,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7120
7148
|
}
|
7121
7149
|
else {
|
7122
7150
|
positionalOnlyLimitIndex = varArgListParamIndex;
|
7151
|
+
positionalArgCount = varArgListParamIndex;
|
7152
|
+
positionParamLimitIndex = varArgListParamIndex;
|
7123
7153
|
}
|
7124
7154
|
}
|
7125
7155
|
}
|
7126
|
-
else if (
|
7127
|
-
|
7128
|
-
if ((_c = (0, typeUtils_1.getTypeVarScopeIds)(typeResult.type)) === null || _c === void 0 ? void 0 : _c.some((id) => id === paramSpecScopeId)) {
|
7156
|
+
else if (paramSpec) {
|
7157
|
+
if ((_c = (0, typeUtils_1.getTypeVarScopeIds)(typeResult.type)) === null || _c === void 0 ? void 0 : _c.some((id) => id === paramSpec.scopeId)) {
|
7129
7158
|
hasParamSpecArgsKwargs = true;
|
7130
7159
|
paramSpecArgList = [];
|
7131
|
-
paramSpecTarget =
|
7132
|
-
/* access */ undefined);
|
7160
|
+
paramSpecTarget = paramSpec;
|
7133
7161
|
}
|
7134
7162
|
}
|
7135
7163
|
// If there are keyword arguments present after a *args argument,
|
@@ -7159,12 +7187,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7159
7187
|
if (positionParamLimitIndex < 0) {
|
7160
7188
|
positionParamLimitIndex = paramDetails.params.length;
|
7161
7189
|
}
|
7162
|
-
// Determine how many positional args are being passed before
|
7163
|
-
// we see a keyword arg.
|
7164
|
-
let positionalArgCount = argList.findIndex((arg) => arg.argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */ || arg.name !== undefined);
|
7165
|
-
if (positionalArgCount < 0) {
|
7166
|
-
positionalArgCount = argList.length;
|
7167
|
-
}
|
7168
7190
|
let validateArgTypeParams = [];
|
7169
7191
|
let activeParam;
|
7170
7192
|
function trySetActive(arg, param) {
|
@@ -7541,13 +7563,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7541
7563
|
reportedArgError = true;
|
7542
7564
|
}
|
7543
7565
|
}
|
7544
|
-
else if (
|
7545
|
-
(0, parameterUtils_1.isParamSpecKwargsArgument)(typeResult.type.details.paramSpec, argType)) {
|
7566
|
+
else if (paramSpec && (0, parameterUtils_1.isParamSpecKwargsArgument)(paramSpec, argType)) {
|
7546
7567
|
unpackedDictionaryArgType = types_1.AnyType.create();
|
7547
7568
|
if (!paramSpecArgList) {
|
7548
7569
|
validateArgTypeParams.push({
|
7549
7570
|
paramCategory: 2 /* ParameterCategory.KwargsDict */,
|
7550
|
-
paramType:
|
7571
|
+
paramType: paramSpec,
|
7551
7572
|
requiresTypeVarMatching: false,
|
7552
7573
|
argument: argList[argIndex],
|
7553
7574
|
argType: (0, types_1.isParamSpec)(argType) ? undefined : types_1.AnyType.create(),
|
@@ -7685,17 +7706,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7685
7706
|
else if (argList[argIndex].argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
|
7686
7707
|
// Handle the case where a *args: P.args (or *args: Any) is passed as an
|
7687
7708
|
// argument to a function that accepts a ParamSpec.
|
7688
|
-
if (
|
7709
|
+
if (paramSpec) {
|
7689
7710
|
const argTypeResult = getTypeOfArgument(argList[argIndex],
|
7690
7711
|
/* inferenceContext */ undefined, signatureTracker);
|
7691
7712
|
const argType = argTypeResult.type;
|
7692
7713
|
if (argTypeResult.isIncomplete) {
|
7693
7714
|
isTypeIncomplete = true;
|
7694
7715
|
}
|
7695
|
-
if ((0, parameterUtils_1.isParamSpecArgsArgument)(
|
7716
|
+
if ((0, parameterUtils_1.isParamSpecArgsArgument)(paramSpec, argType)) {
|
7696
7717
|
validateArgTypeParams.push({
|
7697
7718
|
paramCategory: 1 /* ParameterCategory.ArgsList */,
|
7698
|
-
paramType:
|
7719
|
+
paramType: paramSpec,
|
7699
7720
|
requiresTypeVarMatching: false,
|
7700
7721
|
argument: argList[argIndex],
|
7701
7722
|
argType: (0, types_1.isParamSpec)(argType) ? undefined : types_1.AnyType.create(),
|
@@ -7904,7 +7925,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7904
7925
|
(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) ||
|
7905
7926
|
(0, types_1.isNever)(inferenceContext.expectedType) ||
|
7906
7927
|
!type.details.declaredReturnType ||
|
7907
|
-
!(0, typeUtils_1.requiresSpecialization)((_a = types_1.FunctionType.
|
7928
|
+
!(0, typeUtils_1.requiresSpecialization)((_a = types_1.FunctionType.getEffectiveReturnType(type)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create())) {
|
7908
7929
|
return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck);
|
7909
7930
|
}
|
7910
7931
|
const effectiveReturnType = getFunctionEffectiveReturnType(type);
|
@@ -7995,6 +8016,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7995
8016
|
let specializedInitSelfType;
|
7996
8017
|
let anyOrUnknownArgument;
|
7997
8018
|
const typeCondition = (0, typeUtils_1.getTypeCondition)(type);
|
8019
|
+
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
|
7998
8020
|
// Check for an attempt to invoke an unimplemented abstract method.
|
7999
8021
|
if (type.boundToType && !type.boundToType.includeSubclasses && type.details.methodClass) {
|
8000
8022
|
const abstractSymbolInfo = getAbstractSymbolInfo(type.details.methodClass, type.details.name);
|
@@ -8015,7 +8037,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8015
8037
|
}
|
8016
8038
|
}
|
8017
8039
|
// The type annotation for the "self" parameter in an __init__ method to
|
8018
|
-
// can
|
8040
|
+
// can influence the type being constructed.
|
8019
8041
|
if (type.details.name === '__init__' &&
|
8020
8042
|
type.strippedFirstParamType &&
|
8021
8043
|
type.boundToType &&
|
@@ -8124,14 +8146,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8124
8146
|
? (0, typeUtils_1.preserveUnknown)(argResult.argType, anyOrUnknownArgument)
|
8125
8147
|
: argResult.argType;
|
8126
8148
|
}
|
8127
|
-
if (
|
8149
|
+
if (paramSpec) {
|
8128
8150
|
if (argParam.argument.argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
|
8129
|
-
if ((0, parameterUtils_1.isParamSpecArgsArgument)(
|
8151
|
+
if ((0, parameterUtils_1.isParamSpecArgsArgument)(paramSpec, argResult.argType)) {
|
8130
8152
|
sawParamSpecArgs = true;
|
8131
8153
|
}
|
8132
8154
|
}
|
8133
8155
|
if (argParam.argument.argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */) {
|
8134
|
-
if ((0, parameterUtils_1.isParamSpecKwargsArgument)(
|
8156
|
+
if ((0, parameterUtils_1.isParamSpecKwargsArgument)(paramSpec, argResult.argType)) {
|
8135
8157
|
sawParamSpecKwargs = true;
|
8136
8158
|
}
|
8137
8159
|
}
|
@@ -8147,10 +8169,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8147
8169
|
}
|
8148
8170
|
paramSpecTypeVarContext = paramSpecArgResult.typeVarContexts;
|
8149
8171
|
}
|
8150
|
-
else if (
|
8172
|
+
else if (paramSpec) {
|
8151
8173
|
if (!sawParamSpecArgs || !sawParamSpecKwargs) {
|
8152
8174
|
if (!isTypeIncomplete) {
|
8153
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramSpecArgsMissing().format({ type: printType(
|
8175
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramSpecArgsMissing().format({ type: printType(paramSpec) }), errorNode);
|
8154
8176
|
}
|
8155
8177
|
argumentErrors = true;
|
8156
8178
|
argumentMatchScore += 1;
|
@@ -8373,39 +8395,42 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8373
8395
|
});
|
8374
8396
|
return { argumentErrors: true, typeVarContexts: [srcTypeVarContext] };
|
8375
8397
|
}
|
8398
|
+
const functionParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(functionType);
|
8399
|
+
const functionWithoutParamSpec = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(functionType);
|
8376
8400
|
// Handle the recursive case where we're passing (*args: P.args, **kwargs: P.args)
|
8377
8401
|
// a remaining function of type (*P).
|
8378
|
-
if (
|
8379
|
-
|
8380
|
-
(0, types_1.isTypeSame)(
|
8402
|
+
if (functionParamSpec &&
|
8403
|
+
functionWithoutParamSpec.details.parameters.length === 0 &&
|
8404
|
+
(0, types_1.isTypeSame)(functionParamSpec, paramSpec)) {
|
8381
8405
|
// If there are any arguments other than *args: P.args or **kwargs: P.kwargs,
|
8382
8406
|
// report an error.
|
8383
|
-
let
|
8384
|
-
let
|
8407
|
+
let argsCount = 0;
|
8408
|
+
let kwargsCount = 0;
|
8385
8409
|
let argumentErrors = false;
|
8386
8410
|
let argErrorNode;
|
8387
8411
|
for (const arg of argList) {
|
8388
8412
|
const argType = (_a = getTypeOfArgument(arg, /* inferenceContext */ undefined, signatureTracker)) === null || _a === void 0 ? void 0 : _a.type;
|
8389
|
-
|
8390
|
-
|
8391
|
-
|
8413
|
+
if (arg.argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
|
8414
|
+
if ((0, parameterUtils_1.isParamSpecArgsArgument)(paramSpec, argType)) {
|
8415
|
+
argsCount++;
|
8416
|
+
}
|
8392
8417
|
}
|
8393
|
-
else if (arg.argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */
|
8394
|
-
|
8395
|
-
|
8396
|
-
|
8418
|
+
else if (arg.argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */) {
|
8419
|
+
if ((0, parameterUtils_1.isParamSpecKwargsArgument)(paramSpec, argType)) {
|
8420
|
+
kwargsCount++;
|
8421
|
+
}
|
8397
8422
|
}
|
8398
8423
|
else {
|
8399
8424
|
argErrorNode = argErrorNode !== null && argErrorNode !== void 0 ? argErrorNode : arg.valueExpression;
|
8400
8425
|
argumentErrors = true;
|
8401
8426
|
}
|
8402
8427
|
}
|
8403
|
-
if (
|
8428
|
+
if (argsCount !== 1 || kwargsCount !== 1) {
|
8404
8429
|
argumentErrors = true;
|
8405
8430
|
}
|
8406
8431
|
if (argumentErrors) {
|
8407
8432
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramSpecArgsMissing().format({
|
8408
|
-
type: printType(
|
8433
|
+
type: printType(functionParamSpec),
|
8409
8434
|
}), argErrorNode !== null && argErrorNode !== void 0 ? argErrorNode : errorNode);
|
8410
8435
|
}
|
8411
8436
|
return { argumentErrors, typeVarContexts: [srcTypeVarContext] };
|
@@ -8438,7 +8463,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8438
8463
|
// the solved TypeVars if the typeVarContext has more than one signature.
|
8439
8464
|
// This will expand the ParamSpec into an overload, which will cause problems.
|
8440
8465
|
const skipApplySolvedTypeVars = (0, types_1.isFunction)(argParam.paramType) &&
|
8441
|
-
|
8466
|
+
types_1.FunctionType.getParamSpecFromArgsKwargs(argParam.paramType) &&
|
8442
8467
|
typeVarContext.getSignatureContexts().length > 1;
|
8443
8468
|
if (!skipApplySolvedTypeVars) {
|
8444
8469
|
expectedType = (0, typeUtils_1.applySolvedTypeVars)(expectedType, typeVarContext, {
|
@@ -8957,7 +8982,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8957
8982
|
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
8958
8983
|
if (node.nodeType === 21 /* ParseNodeType.Ellipsis */) {
|
8959
8984
|
types_1.FunctionType.addDefaultParameters(functionType);
|
8960
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
8985
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
8961
8986
|
return functionType;
|
8962
8987
|
}
|
8963
8988
|
if (node.nodeType === 34 /* ParseNodeType.List */) {
|
@@ -8991,7 +9016,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8991
9016
|
return undefined;
|
8992
9017
|
}
|
8993
9018
|
if ((0, types_1.isParamSpec)(typeResult.type)) {
|
8994
|
-
|
9019
|
+
types_1.FunctionType.addParamSpecVariadics(functionType, typeResult.type);
|
8995
9020
|
return functionType;
|
8996
9021
|
}
|
8997
9022
|
if ((0, types_1.isClassInstance)(typeResult.type) &&
|
@@ -9944,7 +9969,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9944
9969
|
if (enclosingFunction) {
|
9945
9970
|
const functionTypeInfo = getTypeOfFunction(enclosingFunction);
|
9946
9971
|
if (functionTypeInfo) {
|
9947
|
-
const returnType = types_1.FunctionType.
|
9972
|
+
const returnType = types_1.FunctionType.getEffectiveReturnType(functionTypeInfo.functionType);
|
9948
9973
|
if (returnType) {
|
9949
9974
|
expectedYieldType = (0, typeUtils_1.getGeneratorYieldType)(returnType, !!enclosingFunction.isAsync);
|
9950
9975
|
const generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(returnType);
|
@@ -10229,16 +10254,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10229
10254
|
const iterableType = stripLiteralValue(iterableTypeResult.type);
|
10230
10255
|
const itemTypeResult = (_a = getTypeOfIterator({ type: iterableType, isIncomplete: iterableTypeResult.isIncomplete }, !!node.isAsync, node.iterableExpression)) !== null && _a !== void 0 ? _a : { type: types_1.UnknownType.create(), isIncomplete: iterableTypeResult.isIncomplete };
|
10231
10256
|
const targetExpr = node.targetExpression;
|
10232
|
-
assignTypeToExpression(targetExpr, itemTypeResult
|
10257
|
+
assignTypeToExpression(targetExpr, itemTypeResult, node.iterableExpression);
|
10233
10258
|
}
|
10234
10259
|
else {
|
10235
10260
|
(0, debug_1.assert)(node.nodeType === 13 /* ParseNodeType.ComprehensionIf */);
|
10236
10261
|
// Evaluate the test expression to validate it and mark symbols
|
10237
|
-
// as referenced.
|
10238
|
-
//
|
10239
|
-
|
10240
|
-
|
10241
|
-
|
10262
|
+
// as referenced. This doesn't affect the type of the evaluated
|
10263
|
+
// comprehension, but it is important for evaluating intermediate
|
10264
|
+
// expressions such as assignment expressions that can affect other
|
10265
|
+
// subexpressions.
|
10266
|
+
getTypeOfExpression(node.testExpression);
|
10242
10267
|
}
|
10243
10268
|
return isIncomplete;
|
10244
10269
|
}
|
@@ -10370,6 +10395,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10370
10395
|
// The second argument, if present, should specify the return type.
|
10371
10396
|
function createCallableType(classType, typeArgs, errorNode) {
|
10372
10397
|
const functionType = types_1.FunctionType.createInstantiable(0 /* FunctionTypeFlags.None */);
|
10398
|
+
let paramSpec;
|
10373
10399
|
functionType.specialForm = classType;
|
10374
10400
|
functionType.details.declaredReturnType = types_1.UnknownType.create();
|
10375
10401
|
functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(errorNode);
|
@@ -10424,10 +10450,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10424
10450
|
}
|
10425
10451
|
else if ((0, typeUtils_1.isEllipsisType)(typeArgs[0].type)) {
|
10426
10452
|
types_1.FunctionType.addDefaultParameters(functionType);
|
10427
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
10453
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
10428
10454
|
}
|
10429
10455
|
else if ((0, types_1.isParamSpec)(typeArgs[0].type)) {
|
10430
|
-
|
10456
|
+
paramSpec = typeArgs[0].type;
|
10431
10457
|
}
|
10432
10458
|
else {
|
10433
10459
|
if ((0, types_1.isInstantiableClass)(typeArgs[0].type) && types_1.ClassType.isBuiltIn(typeArgs[0].type, 'Concatenate')) {
|
@@ -10437,11 +10463,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10437
10463
|
if (index === concatTypeArgs.length - 1) {
|
10438
10464
|
types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
|
10439
10465
|
if ((0, types_1.isParamSpec)(typeArg)) {
|
10440
|
-
|
10466
|
+
paramSpec = typeArg;
|
10441
10467
|
}
|
10442
10468
|
else if ((0, typeUtils_1.isEllipsisType)(typeArg)) {
|
10443
10469
|
types_1.FunctionType.addDefaultParameters(functionType);
|
10444
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
10470
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
10445
10471
|
}
|
10446
10472
|
}
|
10447
10473
|
else {
|
@@ -10477,7 +10503,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10477
10503
|
}
|
10478
10504
|
else {
|
10479
10505
|
types_1.FunctionType.addDefaultParameters(functionType, /* useUnknown */ true);
|
10480
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
10506
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
10507
|
+
}
|
10508
|
+
if (paramSpec) {
|
10509
|
+
types_1.FunctionType.addParamSpecVariadics(functionType, paramSpec);
|
10481
10510
|
}
|
10482
10511
|
return functionType;
|
10483
10512
|
}
|
@@ -10866,8 +10895,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10866
10895
|
return createSpecialType(classType, typeArgs, /* paramLimit */ undefined, /* allowParamSpec */ true);
|
10867
10896
|
}
|
10868
10897
|
function createAnnotatedType(classType, errorNode, typeArgs) {
|
10869
|
-
if (typeArgs
|
10870
|
-
|
10898
|
+
if (typeArgs) {
|
10899
|
+
if (typeArgs.length < 2) {
|
10900
|
+
addError(localize_1.LocMessage.annotatedTypeArgMissing(), errorNode);
|
10901
|
+
}
|
10902
|
+
else {
|
10903
|
+
validateAnnotatedMetadata(errorNode, typeArgs[0].type, typeArgs.slice(1));
|
10904
|
+
}
|
10871
10905
|
}
|
10872
10906
|
if (!typeArgs || typeArgs.length === 0) {
|
10873
10907
|
return { type: types_1.AnyType.create() };
|
@@ -10882,6 +10916,46 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10882
10916
|
isNotRequired: typeArgs[0].isNotRequired,
|
10883
10917
|
};
|
10884
10918
|
}
|
10919
|
+
// Enforces metadata consistency as specified in PEP 746.
|
10920
|
+
function validateAnnotatedMetadata(errorNode, annotatedType, metaArgs) {
|
10921
|
+
var _a;
|
10922
|
+
// This is an experimental feature because PEP 746 hasn't been accepted.
|
10923
|
+
if (!AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.enableExperimentalFeatures) {
|
10924
|
+
return;
|
10925
|
+
}
|
10926
|
+
for (const metaArg of metaArgs) {
|
10927
|
+
if ((0, types_1.isClass)(metaArg.type)) {
|
10928
|
+
const supportsTypeMethod = (_a = getTypeOfBoundMember(
|
10929
|
+
/* errorNode */ undefined, metaArg.type, '__supports_type__')) === null || _a === void 0 ? void 0 : _a.type;
|
10930
|
+
if (!supportsTypeMethod) {
|
10931
|
+
continue;
|
10932
|
+
}
|
10933
|
+
// "Call" the __supports_type__ method to determine if the type is supported.
|
10934
|
+
const callResult = useSpeculativeMode(errorNode, () => validateCallArguments(errorNode, [
|
10935
|
+
{
|
10936
|
+
argumentCategory: 0 /* ArgumentCategory.Simple */,
|
10937
|
+
typeResult: { type: (0, typeUtils_1.convertToInstance)(annotatedType) },
|
10938
|
+
},
|
10939
|
+
], { type: supportsTypeMethod },
|
10940
|
+
/* typeVarContext */ undefined,
|
10941
|
+
/* skipUnknownArgCheck */ true,
|
10942
|
+
/* inferenceContext */ undefined,
|
10943
|
+
/* signatureTracker */ undefined));
|
10944
|
+
if (callResult.isTypeIncomplete || !callResult.returnType) {
|
10945
|
+
continue;
|
10946
|
+
}
|
10947
|
+
// If there are no errors and the return type is potentially truthy,
|
10948
|
+
// we know that the type is supported by this metadata object.
|
10949
|
+
if (!callResult.argumentErrors && canBeTruthy(callResult.returnType)) {
|
10950
|
+
continue;
|
10951
|
+
}
|
10952
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.annotatedMetadataInconsistent().format({
|
10953
|
+
metadataType: printType(metaArg.type),
|
10954
|
+
type: printType((0, typeUtils_1.convertToInstance)(annotatedType)),
|
10955
|
+
}), metaArg.node);
|
10956
|
+
}
|
10957
|
+
}
|
10958
|
+
}
|
10885
10959
|
// Creates one of several "special" types that are defined in typing.pyi
|
10886
10960
|
// but not declared in their entirety. This includes the likes of "Tuple",
|
10887
10961
|
// "Dict", etc.
|
@@ -11113,10 +11187,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11113
11187
|
// Determine if there are any generic type parameters associated
|
11114
11188
|
// with this type alias.
|
11115
11189
|
typeParameters = [];
|
11116
|
-
(0, typeUtils_1.
|
11117
|
-
(0, debug_1.assert)(typeParameters !== undefined);
|
11118
|
-
(0, typeUtils_1.addTypeVarsToListIfUnique)(typeParameters, (0, typeUtils_1.getTypeVarArgumentsRecursive)(subtype));
|
11119
|
-
});
|
11190
|
+
(0, typeUtils_1.addTypeVarsToListIfUnique)(typeParameters, (0, typeUtils_1.getTypeVarArgumentsRecursive)(type));
|
11120
11191
|
// Don't include any synthesized type variables.
|
11121
11192
|
typeParameters = typeParameters.filter((typeVar) => !typeVar.details.isSynthesized);
|
11122
11193
|
}
|
@@ -11461,7 +11532,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11461
11532
|
}
|
11462
11533
|
}
|
11463
11534
|
}
|
11464
|
-
assignTypeToExpression(node.leftExpression, rightHandType, isIncomplete, node.rightExpression,
|
11535
|
+
assignTypeToExpression(node.leftExpression, { type: rightHandType, isIncomplete }, node.rightExpression,
|
11465
11536
|
/* ignoreEmptyContainers */ true,
|
11466
11537
|
/* allowAssignmentToFinalVar */ true, expectedTypeDiagAddendum);
|
11467
11538
|
writeTypeCache(node, { type: rightHandType, isIncomplete }, 0 /* EvaluatorFlags.None */);
|
@@ -12843,7 +12914,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12843
12914
|
paramType1.paramSpecAccess === 'args' &&
|
12844
12915
|
(0, types_1.isParamSpec)(paramType2) &&
|
12845
12916
|
paramType2.paramSpecAccess === 'kwargs') {
|
12846
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
12917
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
12847
12918
|
}
|
12848
12919
|
}
|
12849
12920
|
// If the function contains an *args and a **kwargs parameter and both
|
@@ -12851,7 +12922,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12851
12922
|
// args/kwargs compatibility checks.
|
12852
12923
|
const variadicsWithAnyType = functionType.details.parameters.filter((param) => param.category !== 0 /* ParameterCategory.Simple */ && param.name && (0, types_1.isAnyOrUnknown)(param.type));
|
12853
12924
|
if (variadicsWithAnyType.length >= 2) {
|
12854
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
12925
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
12855
12926
|
}
|
12856
12927
|
// If there was a defined return type, analyze that first so when we
|
12857
12928
|
// walk the contents of the function, return statements can be
|
@@ -13322,7 +13393,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13322
13393
|
}
|
13323
13394
|
const iteratorTypeResult = getTypeOfExpression(node.iterableExpression);
|
13324
13395
|
const iteratedType = (_b = (_a = getTypeOfIterator(iteratorTypeResult, !!node.isAsync, node.iterableExpression)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
13325
|
-
assignTypeToExpression(node.targetExpression, iteratedType,
|
13396
|
+
assignTypeToExpression(node.targetExpression, { type: iteratedType, isIncomplete: iteratorTypeResult.isIncomplete }, node.targetExpression);
|
13326
13397
|
writeTypeCache(node, { type: iteratedType, isIncomplete: !!iteratorTypeResult.isIncomplete }, 0 /* EvaluatorFlags.None */);
|
13327
13398
|
}
|
13328
13399
|
function evaluateTypesForExceptStatement(node) {
|
@@ -13371,7 +13442,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13371
13442
|
targetType = getBuiltInObject(node, 'BaseExceptionGroup', [targetType]);
|
13372
13443
|
}
|
13373
13444
|
if (node.name) {
|
13374
|
-
assignTypeToExpression(node.name,
|
13445
|
+
assignTypeToExpression(node.name, { type: targetType }, node.name);
|
13375
13446
|
}
|
13376
13447
|
writeTypeCache(node, { type: targetType }, 0 /* EvaluatorFlags.None */);
|
13377
13448
|
}
|
@@ -13433,7 +13504,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13433
13504
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeNotUsableWith().format({ type: printType(subtype), method: exitMethodName }), node.expression);
|
13434
13505
|
});
|
13435
13506
|
if (node.target) {
|
13436
|
-
assignTypeToExpression(node.target, scopedType,
|
13507
|
+
assignTypeToExpression(node.target, { type: scopedType, isIncomplete: exprTypeResult.isIncomplete }, node.target);
|
13437
13508
|
}
|
13438
13509
|
writeTypeCache(node, { type: scopedType, isIncomplete: !!exprTypeResult.isIncomplete }, 0 /* EvaluatorFlags.None */);
|
13439
13510
|
}
|
@@ -13466,7 +13537,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13466
13537
|
symbolType = cachedModuleType;
|
13467
13538
|
}
|
13468
13539
|
}
|
13469
|
-
assignTypeToNameNode(symbolNameNode,
|
13540
|
+
assignTypeToNameNode(symbolNameNode, { type: symbolType }, /* ignoreEmptyContainers */ false);
|
13470
13541
|
writeTypeCache(node, { type: symbolType }, 0 /* EvaluatorFlags.None */);
|
13471
13542
|
}
|
13472
13543
|
function evaluateTypesForImportFromAs(node) {
|
@@ -13532,7 +13603,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13532
13603
|
symbolType = types_1.UnknownType.create();
|
13533
13604
|
}
|
13534
13605
|
}
|
13535
|
-
assignTypeToNameNode(aliasNode,
|
13606
|
+
assignTypeToNameNode(aliasNode, { type: symbolType }, /* ignoreEmptyContainers */ false);
|
13536
13607
|
writeTypeCache(node, { type: symbolType }, 0 /* EvaluatorFlags.None */);
|
13537
13608
|
}
|
13538
13609
|
function evaluateTypesForMatchStatement(node) {
|
@@ -13630,9 +13701,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13630
13701
|
symbolType = cachedModuleType;
|
13631
13702
|
}
|
13632
13703
|
}
|
13633
|
-
assignTypeToNameNode(symbolNameNode, symbolType,
|
13634
|
-
/* isIncomplete */ false,
|
13635
|
-
/* ignoreEmptyContainers */ false);
|
13704
|
+
assignTypeToNameNode(symbolNameNode, { type: symbolType }, /* ignoreEmptyContainers */ false);
|
13636
13705
|
writeTypeCache(node, { type: symbolType }, 0 /* EvaluatorFlags.None */);
|
13637
13706
|
}
|
13638
13707
|
}
|
@@ -14052,7 +14121,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14052
14121
|
return;
|
14053
14122
|
}
|
14054
14123
|
case 4 /* ParseNodeType.AssignmentExpression */: {
|
14055
|
-
|
14124
|
+
evaluateTypesForExpressionInContext(curNode);
|
14056
14125
|
return;
|
14057
14126
|
}
|
14058
14127
|
case 5 /* ParseNodeType.AugmentedAssignment */: {
|
@@ -14469,7 +14538,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14469
14538
|
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
14470
14539
|
if ((0, typeUtils_1.isEllipsisType)(typeArg.type)) {
|
14471
14540
|
types_1.FunctionType.addDefaultParameters(functionType);
|
14472
|
-
functionType.details.flags |= 32768 /* FunctionTypeFlags.
|
14541
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
14473
14542
|
typeArgTypes.push(functionType);
|
14474
14543
|
typeVarContext.setTypeVarType(typeParam, (0, typeUtils_1.convertTypeToParamSpecValue)(functionType));
|
14475
14544
|
return;
|
@@ -14497,12 +14566,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14497
14566
|
concatTypeArgs.forEach((typeArg, index) => {
|
14498
14567
|
if (index === concatTypeArgs.length - 1) {
|
14499
14568
|
if ((0, types_1.isParamSpec)(typeArg)) {
|
14500
|
-
|
14569
|
+
types_1.FunctionType.addParamSpecVariadics(functionType, typeArg);
|
14501
14570
|
}
|
14502
14571
|
else if ((0, typeUtils_1.isEllipsisType)(typeArg)) {
|
14503
14572
|
types_1.FunctionType.addDefaultParameters(functionType);
|
14504
|
-
functionType.details.flags |=
|
14505
|
-
32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
|
14573
|
+
functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
14506
14574
|
}
|
14507
14575
|
}
|
14508
14576
|
else {
|
@@ -15865,7 +15933,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15865
15933
|
// the return type. If a list of args is provided, the inference logic may take
|
15866
15934
|
// into account argument types to infer the return type.
|
15867
15935
|
function getFunctionEffectiveReturnType(type, callSiteInfo, inferTypeIfNeeded = true) {
|
15868
|
-
const specializedReturnType = types_1.FunctionType.
|
15936
|
+
const specializedReturnType = types_1.FunctionType.getEffectiveReturnType(type, /* includeInferred */ false);
|
15869
15937
|
if (specializedReturnType && !(0, types_1.isUnknown)(specializedReturnType)) {
|
15870
15938
|
const liveTypeVarScopes = (callSiteInfo === null || callSiteInfo === void 0 ? void 0 : callSiteInfo.errorNode)
|
15871
15939
|
? ParseTreeUtils.getTypeVarScopesForNode(callSiteInfo === null || callSiteInfo === void 0 ? void 0 : callSiteInfo.errorNode)
|
@@ -16136,20 +16204,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16136
16204
|
// and cache the return type if necessary. This needs to be done
|
16137
16205
|
// prior to specializing.
|
16138
16206
|
inferReturnTypeIfNecessary(typeResult.type);
|
16139
|
-
|
16140
|
-
|
16141
|
-
|
16142
|
-
(0,
|
16143
|
-
|
16144
|
-
|
16145
|
-
|
16146
|
-
|
16147
|
-
|
16148
|
-
|
16149
|
-
|
16150
|
-
}
|
16151
|
-
});
|
16152
|
-
if (isGenericNonCallable && errorNode) {
|
16207
|
+
// Check for ambiguous accesses to attributes with generic types?
|
16208
|
+
if (errorNode &&
|
16209
|
+
selfClass &&
|
16210
|
+
(0, types_1.isClass)(selfClass) &&
|
16211
|
+
member.isInstanceMember &&
|
16212
|
+
(0, types_1.isClass)(member.unspecializedClassType) &&
|
16213
|
+
(flags & 1024 /* MemberAccessFlags.DisallowGenericInstanceVariableAccess */) !== 0 &&
|
16214
|
+
(0, typeUtils_1.requiresSpecialization)(typeResult.type, { ignoreSelf: true, ignoreImplicitTypeArgs: true })) {
|
16215
|
+
const specializedType = (0, typeUtils_1.partiallySpecializeType)(typeResult.type, member.unspecializedClassType, (0, typeUtils_1.selfSpecializeClass)(selfClass, /* overrideTypeArgs */ true));
|
16216
|
+
if ((0, types_1.findSubtype)(specializedType, (subtype) => !(0, types_1.isFunction)(subtype) &&
|
16217
|
+
!(0, types_1.isOverloadedFunction)(subtype) &&
|
16218
|
+
(0, typeUtils_1.requiresSpecialization)(subtype, { ignoreSelf: true, ignoreImplicitTypeArgs: true }))) {
|
16153
16219
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.genericInstanceVariableAccess(), errorNode);
|
16154
16220
|
}
|
16155
16221
|
}
|
@@ -16963,7 +17029,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16963
17029
|
// it's Any.
|
16964
17030
|
if ((0, types_1.isParamSpec)(srcType) &&
|
16965
17031
|
(0, types_1.isFunction)(destType) &&
|
16966
|
-
types_1.FunctionType.
|
17032
|
+
types_1.FunctionType.isGradualCallableForm(destType) &&
|
16967
17033
|
destType.details.parameters.length <= 2) {
|
16968
17034
|
return true;
|
16969
17035
|
}
|
@@ -17245,7 +17311,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17245
17311
|
/* selfType */ undefined,
|
17246
17312
|
/* diag */ undefined, recursionCount);
|
17247
17313
|
if (boundMethod) {
|
17248
|
-
concreteSrcType =
|
17314
|
+
concreteSrcType = boundMethod;
|
17249
17315
|
}
|
17250
17316
|
}
|
17251
17317
|
// If it's a class, use the constructor for type compatibility checking.
|
@@ -17789,13 +17855,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17789
17855
|
}
|
17790
17856
|
}
|
17791
17857
|
}
|
17792
|
-
|
17793
|
-
/* selfType */ undefined,
|
17794
|
-
/* diag */ undefined, recursionCount);
|
17795
|
-
if (boundMethod) {
|
17796
|
-
return (0, typeUtils_1.removeParamSpecVariadicsFromSignature)(boundMethod);
|
17797
|
-
}
|
17798
|
-
return undefined;
|
17858
|
+
return getBoundMagicMethod(objType, '__call__', /* selfType */ undefined, /* diag */ undefined, recursionCount);
|
17799
17859
|
}
|
17800
17860
|
function assignFunctionParameter(destType, srcType, paramIndex, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
|
17801
17861
|
// Handle the special case where the dest type is a synthesized
|
@@ -17927,17 +17987,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17927
17987
|
}
|
17928
17988
|
}
|
17929
17989
|
function assignFunction(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
|
17930
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
17990
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
17931
17991
|
let canAssign = true;
|
17932
17992
|
const checkReturnType = (flags & 64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */) === 0;
|
17933
17993
|
const reverseMatching = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) !== 0;
|
17934
17994
|
flags &= ~64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */;
|
17935
|
-
|
17936
|
-
|
17995
|
+
const destParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(destType);
|
17996
|
+
if (destParamSpec) {
|
17997
|
+
destType = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(destType);
|
17998
|
+
}
|
17999
|
+
const srcParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(srcType);
|
18000
|
+
if (srcParamSpec) {
|
18001
|
+
srcType = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(srcType);
|
18002
|
+
}
|
17937
18003
|
const destParamDetails = (0, parameterUtils_1.getParameterListDetails)(destType);
|
17938
18004
|
const srcParamDetails = (0, parameterUtils_1.getParameterListDetails)(srcType);
|
17939
18005
|
adjustSourceParamDetailsForDestVariadic(reverseMatching ? destParamDetails : srcParamDetails, reverseMatching ? srcParamDetails : destParamDetails);
|
17940
|
-
const targetIncludesParamSpec = reverseMatching ? !!
|
18006
|
+
const targetIncludesParamSpec = reverseMatching ? !!srcParamSpec : !!destParamSpec;
|
17941
18007
|
const destPositionalCount = (_a = destParamDetails.firstKeywordOnlyIndex) !== null && _a !== void 0 ? _a : destParamDetails.params.length;
|
17942
18008
|
const srcPositionalCount = (_b = srcParamDetails.firstKeywordOnlyIndex) !== null && _b !== void 0 ? _b : srcParamDetails.params.length;
|
17943
18009
|
const positionalsToMatch = Math.min(destPositionalCount, srcPositionalCount);
|
@@ -18025,7 +18091,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18025
18091
|
canAssign = false;
|
18026
18092
|
}
|
18027
18093
|
}
|
18028
|
-
if (!types_1.FunctionType.
|
18094
|
+
if (!types_1.FunctionType.isGradualCallableForm(destType) &&
|
18029
18095
|
destParamDetails.firstPositionOrKeywordIndex < srcParamDetails.positionOnlyParamCount &&
|
18030
18096
|
!targetIncludesParamSpec) {
|
18031
18097
|
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.argsPositionOnly().format({
|
@@ -18061,7 +18127,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18061
18127
|
}
|
18062
18128
|
continue;
|
18063
18129
|
}
|
18064
|
-
// If the source parameter is also
|
18130
|
+
// If the source parameter is also addressable by keyword, it is OK
|
18065
18131
|
// that there is no matching positional parameter in the dest.
|
18066
18132
|
if (srcParam.kind === parameterUtils_1.ParameterKind.Standard) {
|
18067
18133
|
continue;
|
@@ -18128,7 +18194,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18128
18194
|
// their types are compatible.
|
18129
18195
|
if (srcParamDetails.argsIndex !== undefined &&
|
18130
18196
|
destParamDetails.argsIndex !== undefined &&
|
18131
|
-
!types_1.FunctionType.
|
18197
|
+
!types_1.FunctionType.isGradualCallableForm(destType)) {
|
18132
18198
|
let destArgsType = destParamDetails.params[destParamDetails.argsIndex].type;
|
18133
18199
|
let srcArgsType = srcParamDetails.params[srcParamDetails.argsIndex].type;
|
18134
18200
|
if (!(0, types_1.isUnpacked)(destArgsType)) {
|
@@ -18143,9 +18209,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18143
18209
|
}
|
18144
18210
|
// If the dest has an "*args" but the source doesn't, report the incompatibility.
|
18145
18211
|
// The converse situation is OK.
|
18146
|
-
if (!types_1.FunctionType.
|
18212
|
+
if (!types_1.FunctionType.isGradualCallableForm(destType) &&
|
18147
18213
|
srcParamDetails.argsIndex === undefined &&
|
18148
|
-
|
18214
|
+
srcParamSpec === undefined &&
|
18149
18215
|
destParamDetails.argsIndex !== undefined &&
|
18150
18216
|
!destParamDetails.hasUnpackedVariadicTypeVar) {
|
18151
18217
|
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.argsParamMissing().format({
|
@@ -18260,9 +18326,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18260
18326
|
}
|
18261
18327
|
// If the dest has a "**kwargs" but the source doesn't, report the incompatibility.
|
18262
18328
|
// The converse situation is OK.
|
18263
|
-
if (!types_1.FunctionType.
|
18329
|
+
if (!types_1.FunctionType.isGradualCallableForm(destType) &&
|
18264
18330
|
srcParamDetails.kwargsIndex === undefined &&
|
18265
|
-
|
18331
|
+
srcParamSpec === undefined &&
|
18266
18332
|
destParamDetails.kwargsIndex !== undefined) {
|
18267
18333
|
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.kwargsParamMissing().format({
|
18268
18334
|
paramName: destParamDetails.params[destParamDetails.kwargsIndex].param.name,
|
@@ -18272,8 +18338,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18272
18338
|
}
|
18273
18339
|
// If the source and the dest are using the same ParamSpec, any additional
|
18274
18340
|
// concatenated parameters must match.
|
18275
|
-
if (targetIncludesParamSpec &&
|
18276
|
-
((_j = srcType.details.paramSpec) === null || _j === void 0 ? void 0 : _j.nameWithScope) === ((_k = destType.details.paramSpec) === null || _k === void 0 ? void 0 : _k.nameWithScope)) {
|
18341
|
+
if (targetIncludesParamSpec && (srcParamSpec === null || srcParamSpec === void 0 ? void 0 : srcParamSpec.nameWithScope) === (destParamSpec === null || destParamSpec === void 0 ? void 0 : destParamSpec.nameWithScope)) {
|
18277
18342
|
if (srcParamDetails.params.length !== destParamDetails.params.length) {
|
18278
18343
|
canAssign = false;
|
18279
18344
|
}
|
@@ -18288,9 +18353,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18288
18353
|
});
|
18289
18354
|
// Are we assigning to a function with a ParamSpec?
|
18290
18355
|
if (targetIncludesParamSpec) {
|
18291
|
-
const effectiveDestType = reverseMatching ? srcType : destType;
|
18292
18356
|
const effectiveSrcType = reverseMatching ? destType : srcType;
|
18293
|
-
|
18357
|
+
const effectiveDestType = reverseMatching ? srcType : destType;
|
18358
|
+
const effectiveSrcParamSpec = reverseMatching ? destParamSpec : srcParamSpec;
|
18359
|
+
const effectiveDestParamSpec = reverseMatching ? srcParamSpec : destParamSpec;
|
18360
|
+
if (effectiveDestParamSpec) {
|
18294
18361
|
const requiredMatchParamCount = effectiveDestType.details.parameters.filter((p) => {
|
18295
18362
|
if (!p.name) {
|
18296
18363
|
return false;
|
@@ -18327,13 +18394,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18327
18394
|
});
|
18328
18395
|
}
|
18329
18396
|
});
|
18330
|
-
const srcParamSpec = effectiveSrcType.details.paramSpec;
|
18331
|
-
const destParamSpec = effectiveDestType.details.paramSpec;
|
18332
18397
|
// If there are remaining parameters and the source and dest do not contain
|
18333
18398
|
// the same ParamSpec, synthesize a function for the remaining parameters.
|
18334
18399
|
if (remainingParams.length > 0 ||
|
18335
|
-
!
|
18336
|
-
!(0, types_1.isTypeSame)(
|
18400
|
+
!effectiveSrcParamSpec ||
|
18401
|
+
!(0, types_1.isTypeSame)(effectiveSrcParamSpec, effectiveDestParamSpec, { ignoreTypeFlags: true })) {
|
18337
18402
|
const remainingFunction = types_1.FunctionType.createInstance('', '', '', effectiveSrcType.details.flags | 64 /* FunctionTypeFlags.SynthesizedMethod */, effectiveSrcType.details.docString);
|
18338
18403
|
remainingFunction.details.deprecatedMessage = effectiveSrcType.details.deprecatedMessage;
|
18339
18404
|
remainingFunction.details.typeVarScopeId = effectiveSrcType.details.typeVarScopeId;
|
@@ -18343,16 +18408,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18343
18408
|
remainingParams.forEach((param) => {
|
18344
18409
|
types_1.FunctionType.addParameter(remainingFunction, param);
|
18345
18410
|
});
|
18346
|
-
|
18411
|
+
if (effectiveSrcParamSpec) {
|
18412
|
+
types_1.FunctionType.addParamSpecVariadics(remainingFunction, (0, typeUtils_1.convertToInstance)(effectiveSrcParamSpec));
|
18413
|
+
}
|
18347
18414
|
types_1.FunctionType.addHigherOrderTypeVarScopeIds(remainingFunction, effectiveSrcType.details.higherOrderTypeVarScopeIds);
|
18348
|
-
if (!assignType(
|
18415
|
+
if (!assignType(effectiveDestParamSpec, remainingFunction,
|
18349
18416
|
/* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags)) {
|
18350
18417
|
// If we couldn't assign the function to the ParamSpec, see if we can
|
18351
18418
|
// assign only the ParamSpec. This is possible if there were no
|
18352
18419
|
// remaining parameters.
|
18353
18420
|
if (remainingParams.length > 0 ||
|
18354
|
-
!
|
18355
|
-
!assignType((0, typeUtils_1.convertToInstance)(
|
18421
|
+
!effectiveSrcParamSpec ||
|
18422
|
+
!assignType((0, typeUtils_1.convertToInstance)(effectiveDestParamSpec), (0, typeUtils_1.convertToInstance)(effectiveSrcParamSpec),
|
18356
18423
|
/* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags)) {
|
18357
18424
|
canAssign = false;
|
18358
18425
|
}
|
@@ -18473,13 +18540,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18473
18540
|
}
|
18474
18541
|
// When a value is assigned to a variable with a declared type,
|
18475
18542
|
// we may be able to narrow the type based on the assignment.
|
18476
|
-
function narrowTypeBasedOnAssignment(node, declaredType,
|
18477
|
-
// TODO: The rules for narrowing types on assignment are defined in
|
18543
|
+
function narrowTypeBasedOnAssignment(node, declaredType, assignedTypeResult) {
|
18544
|
+
// TODO: The rules for narrowing types on assignment are not defined in
|
18478
18545
|
// the typing spec. Pyright's current logic is currently not even internally
|
18479
18546
|
// consistent and probably not sound from a type theory perspective. It
|
18480
18547
|
// should be completely reworked once there has been a public discussion
|
18481
18548
|
// about the correct behavior.
|
18482
|
-
|
18549
|
+
// If the result is incomplete, do not attempt to narrow the type.
|
18550
|
+
if (assignedTypeResult.isIncomplete) {
|
18551
|
+
return assignedTypeResult;
|
18552
|
+
}
|
18553
|
+
const narrowedType = (0, typeUtils_1.mapSubtypes)(assignedTypeResult.type, (assignedSubtype) => {
|
18483
18554
|
// Handle the special case where the assigned type is a literal type.
|
18484
18555
|
// Some types include very large unions of literal types, and we don't
|
18485
18556
|
// want to use an n^2 loop to compare them.
|
@@ -18541,12 +18612,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18541
18612
|
// with the declared type. In strict mode, this will retain the "unknown type"
|
18542
18613
|
// diagnostics while still providing reasonable completion suggestions.
|
18543
18614
|
if ((0, typeUtils_1.isIncompleteUnknown)(narrowedType)) {
|
18544
|
-
return narrowedType;
|
18615
|
+
return { type: narrowedType };
|
18545
18616
|
}
|
18546
18617
|
else if ((0, types_1.isUnknown)(narrowedType)) {
|
18547
|
-
return (0, types_1.combineTypes)([narrowedType, declaredType]);
|
18618
|
+
return { type: (0, types_1.combineTypes)([narrowedType, declaredType]) };
|
18548
18619
|
}
|
18549
|
-
return narrowedType;
|
18620
|
+
return { type: narrowedType };
|
18550
18621
|
}
|
18551
18622
|
function validateOverrideMethod(baseMethod, overrideMethod, baseClass, diag, enforceParamNames = true) {
|
18552
18623
|
// If we're overriding a non-method with a method, report it as an error.
|
@@ -18676,8 +18747,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18676
18747
|
const baseParamDetails = (0, parameterUtils_1.getParameterListDetails)(baseMethod);
|
18677
18748
|
const overrideParamDetails = (0, parameterUtils_1.getParameterListDetails)(overrideMethod);
|
18678
18749
|
let canOverride = true;
|
18679
|
-
if (!types_1.FunctionType.
|
18680
|
-
!types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(overrideMethod)) {
|
18750
|
+
if (!types_1.FunctionType.isGradualCallableForm(baseMethod) && !types_1.FunctionType.isGradualCallableForm(overrideMethod)) {
|
18681
18751
|
// Verify that we're not overriding a static, class or instance method with
|
18682
18752
|
// an incompatible type.
|
18683
18753
|
if (types_1.FunctionType.isStaticMethod(baseMethod)) {
|
@@ -19137,7 +19207,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19137
19207
|
memberTypeFirstParam.hasDeclaredType) {
|
19138
19208
|
if (subDiag) {
|
19139
19209
|
subDiag.addMessage(localize_1.LocMessage.bindTypeMismatch().format({
|
19140
|
-
type: printType(
|
19210
|
+
type: printType(firstParamType),
|
19141
19211
|
methodName: memberType.details.name || '<anonymous>',
|
19142
19212
|
paramName: memberTypeFirstParam.name,
|
19143
19213
|
}));
|