@zzzen/pyright-internal 1.2.0-dev.20220703 → 1.2.0-dev.20220724
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/README.md +82 -1
- package/dist/analyzer/analysis.js +1 -1
- package/dist/analyzer/analysis.js.map +1 -1
- package/dist/analyzer/analyzerFileInfo.d.ts +2 -1
- package/dist/analyzer/analyzerFileInfo.js.map +1 -1
- package/dist/analyzer/binder.js +15 -1
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -0
- package/dist/analyzer/checker.js +100 -51
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +0 -1
- package/dist/analyzer/codeFlowEngine.js +196 -197
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.d.ts +1 -1
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +6 -7
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/dataClasses.js +13 -4
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/functionTransform.js +2 -1
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.js +5 -4
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.d.ts +1 -1
- package/dist/analyzer/importStatementUtils.js +47 -18
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +6 -1
- package/dist/analyzer/parseTreeUtils.js +118 -10
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +2 -2
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +2 -2
- package/dist/analyzer/program.js +1 -1
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/service.d.ts +4 -3
- package/dist/analyzer/service.js +40 -39
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +6 -1
- package/dist/analyzer/sourceFile.js +57 -14
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +1 -1
- package/dist/analyzer/typeEvaluator.js +754 -618
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +15 -15
- package/dist/analyzer/typeEvaluatorWithTracker.js +8 -7
- package/dist/analyzer/typeEvaluatorWithTracker.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +2 -0
- package/dist/analyzer/typeGuards.js +47 -14
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +5 -3
- package/dist/analyzer/typeUtils.js +103 -27
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +1 -0
- package/dist/analyzer/typedDicts.js +27 -4
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +15 -5
- package/dist/analyzer/types.js +107 -9
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +2 -1
- package/dist/backgroundAnalysisBase.js +7 -0
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.js +1 -0
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/common/chokidarFileWatcherProvider.d.ts +1 -2
- package/dist/common/chokidarFileWatcherProvider.js +0 -3
- package/dist/common/chokidarFileWatcherProvider.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -0
- package/dist/common/configOptions.js +4 -0
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/diagnostic.d.ts +2 -1
- package/dist/common/diagnostic.js +2 -1
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/diagnosticRules.d.ts +1 -0
- package/dist/common/diagnosticRules.js +1 -0
- package/dist/common/diagnosticRules.js.map +1 -1
- package/dist/common/diagnosticSink.d.ts +3 -0
- package/dist/common/diagnosticSink.js +15 -2
- package/dist/common/diagnosticSink.js.map +1 -1
- package/dist/common/editAction.d.ts +6 -0
- package/dist/common/editAction.js +15 -0
- package/dist/common/editAction.js.map +1 -1
- package/dist/common/fileSystem.d.ts +4 -1
- package/dist/common/fileSystem.js +6 -4
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +2 -2
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/textEditUtils.d.ts +22 -2
- package/dist/common/textEditUtils.js +138 -1
- package/dist/common/textEditUtils.js.map +1 -1
- package/dist/common/uriParser.d.ts +2 -0
- package/dist/common/uriParser.js +11 -0
- package/dist/common/uriParser.js.map +1 -1
- package/dist/languageServerBase.d.ts +19 -18
- package/dist/languageServerBase.js +75 -61
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/codeActionProvider.d.ts +2 -2
- package/dist/languageService/codeActionProvider.js +1 -1
- package/dist/languageService/codeActionProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +15 -11
- package/dist/languageService/completionProvider.js +76 -5
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/indentationUtils.js +3 -2
- package/dist/languageService/indentationUtils.js.map +1 -1
- package/dist/languageService/insertionPointUtils.d.ts +9 -0
- package/dist/languageService/insertionPointUtils.js +110 -0
- package/dist/languageService/insertionPointUtils.js.map +1 -0
- package/dist/languageService/renameModuleProvider.d.ts +1 -4
- package/dist/languageService/renameModuleProvider.js +10 -46
- package/dist/languageService/renameModuleProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +4 -2
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +1 -3
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +13 -0
- package/dist/localization/localize.js +4 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +4 -0
- package/dist/parser/parser.d.ts +2 -1
- package/dist/parser/parser.js +11 -2
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.d.ts +2 -1
- package/dist/parser/tokenizer.js +3 -2
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/pyright.js +3 -1
- package/dist/pyright.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +20 -2
- package/dist/pyrightFileSystem.js +29 -2
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/server.js +4 -4
- package/dist/server.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +4 -1
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/checker.test.js +9 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/fourslash/completions.commitChars.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.commitChars.fourslash.js +47 -0
- package/dist/tests/fourslash/completions.commitChars.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.triggers.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.triggers.fourslash.js +29 -0
- package/dist/tests/fourslash/completions.triggers.fourslash.js.map +1 -0
- package/dist/tests/fourslash/fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.multipart.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.multipart.fourslash.js +18 -0
- package/dist/tests/fourslash/import.multipart.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.simple.fourslash.js +16 -0
- package/dist/tests/fourslash/signature.simple.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +12 -3
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/insertionPointUtils.test.d.ts +1 -0
- package/dist/tests/insertionPointUtils.test.js +74 -0
- package/dist/tests/insertionPointUtils.test.js.map +1 -0
- package/dist/tests/pyrightFileSystem.test.js +28 -0
- package/dist/tests/pyrightFileSystem.test.js.map +1 -1
- package/dist/tests/renameModuleTestUtils.js +5 -87
- package/dist/tests/renameModuleTestUtils.js.map +1 -1
- package/dist/tests/testStateUtils.d.ts +8 -0
- package/dist/tests/testStateUtils.js +110 -0
- package/dist/tests/testStateUtils.js.map +1 -0
- package/dist/tests/testUtils.d.ts +2 -1
- package/dist/tests/testUtils.js +11 -7
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +2 -6
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +16 -4
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +9 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +26 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +6 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/workspaceMap.d.ts +1 -0
- package/dist/workspaceMap.js +10 -0
- package/dist/workspaceMap.js.map +1 -1
- package/package.json +4 -3
@@ -106,33 +106,31 @@ var MemberAccessFlags;
|
|
106
106
|
MemberAccessFlags[MemberAccessFlags["SkipTypeBaseClass"] = 256] = "SkipTypeBaseClass";
|
107
107
|
})(MemberAccessFlags || (MemberAccessFlags = {}));
|
108
108
|
// Maps binary operators to the magic methods that implement them.
|
109
|
-
// The boolean indicates whether the operators "chain" together.
|
110
109
|
const binaryOperatorMap = {
|
111
|
-
[0 /* Add */]: ['__add__', '__radd__'
|
112
|
-
[33 /* Subtract */]: ['__sub__', '__rsub__'
|
113
|
-
[26 /* Multiply */]: ['__mul__', '__rmul__'
|
114
|
-
[13 /* FloorDivide */]: ['__floordiv__', '__rfloordiv__'
|
115
|
-
[10 /* Divide */]: ['__truediv__', '__rtruediv__'
|
116
|
-
[24 /* Mod */]: ['__mod__', '__rmod__'
|
117
|
-
[29 /* Power */]: ['__pow__', '__rpow__'
|
118
|
-
[22 /* MatrixMultiply */]: ['__matmul__', '__rmatmul__'
|
119
|
-
[3 /* BitwiseAnd */]: ['__and__', '__rand__'
|
120
|
-
[6 /* BitwiseOr */]: ['__or__', '__ror__'
|
121
|
-
[8 /* BitwiseXor */]: ['__xor__', '__rxor__'
|
122
|
-
[17 /* LeftShift */]: ['__lshift__', '__rlshift__'
|
123
|
-
[31 /* RightShift */]: ['__rshift__', '__rrshift__'
|
124
|
-
[12 /* Equals */]: ['__eq__', '__ne__'
|
125
|
-
[28 /* NotEquals */]: ['__ne__', '__eq__'
|
126
|
-
[20 /* LessThan */]: ['__lt__', '__ge__'
|
127
|
-
[21 /* LessThanOrEqual */]: ['__le__', '__gt__'
|
128
|
-
[15 /* GreaterThan */]: ['__gt__', '__le__'
|
129
|
-
[16 /* GreaterThanOrEqual */]: ['__ge__', '__lt__'
|
110
|
+
[0 /* Add */]: ['__add__', '__radd__'],
|
111
|
+
[33 /* Subtract */]: ['__sub__', '__rsub__'],
|
112
|
+
[26 /* Multiply */]: ['__mul__', '__rmul__'],
|
113
|
+
[13 /* FloorDivide */]: ['__floordiv__', '__rfloordiv__'],
|
114
|
+
[10 /* Divide */]: ['__truediv__', '__rtruediv__'],
|
115
|
+
[24 /* Mod */]: ['__mod__', '__rmod__'],
|
116
|
+
[29 /* Power */]: ['__pow__', '__rpow__'],
|
117
|
+
[22 /* MatrixMultiply */]: ['__matmul__', '__rmatmul__'],
|
118
|
+
[3 /* BitwiseAnd */]: ['__and__', '__rand__'],
|
119
|
+
[6 /* BitwiseOr */]: ['__or__', '__ror__'],
|
120
|
+
[8 /* BitwiseXor */]: ['__xor__', '__rxor__'],
|
121
|
+
[17 /* LeftShift */]: ['__lshift__', '__rlshift__'],
|
122
|
+
[31 /* RightShift */]: ['__rshift__', '__rrshift__'],
|
123
|
+
[12 /* Equals */]: ['__eq__', '__ne__'],
|
124
|
+
[28 /* NotEquals */]: ['__ne__', '__eq__'],
|
125
|
+
[20 /* LessThan */]: ['__lt__', '__ge__'],
|
126
|
+
[21 /* LessThanOrEqual */]: ['__le__', '__gt__'],
|
127
|
+
[15 /* GreaterThan */]: ['__gt__', '__le__'],
|
128
|
+
[16 /* GreaterThanOrEqual */]: ['__ge__', '__lt__'],
|
130
129
|
};
|
131
|
-
//
|
132
|
-
// the operators "chain" together with other comparison operators.
|
130
|
+
// Map of operators that always return a bool result.
|
133
131
|
const booleanOperatorMap = {
|
134
|
-
[36 /* And */]:
|
135
|
-
[37 /* Or */]:
|
132
|
+
[36 /* And */]: true,
|
133
|
+
[37 /* Or */]: true,
|
136
134
|
[39 /* Is */]: true,
|
137
135
|
[40 /* IsNot */]: true,
|
138
136
|
[41 /* In */]: true,
|
@@ -182,6 +180,9 @@ const maxReturnTypeInferenceArgumentCount = 6;
|
|
182
180
|
// when its parameters are unannotated? We want to keep this
|
183
181
|
// pretty low because this can be very costly.
|
184
182
|
const maxReturnTypeInferenceCodeFlowComplexity = 8;
|
183
|
+
// What is the max number of return types cached per function
|
184
|
+
// when using call-site inference?
|
185
|
+
const maxCallSiteReturnTypeCacheSize = 8;
|
185
186
|
// How many entries in a list, set, or dict should we examine
|
186
187
|
// when inferring the type? We need to cut it off at some point
|
187
188
|
// to avoid excessive computation.
|
@@ -209,7 +210,7 @@ const maxLiteralMathSubtypeCount = 64;
|
|
209
210
|
// off code flow analysis at some point for code flow graphs that are too
|
210
211
|
// complex. Otherwise we risk overflowing the stack or incurring extremely
|
211
212
|
// long analysis times. This number has been tuned empirically.
|
212
|
-
exports.maxCodeComplexity =
|
213
|
+
exports.maxCodeComplexity = 768;
|
213
214
|
function createTypeEvaluator(importLookup, evaluatorOptions) {
|
214
215
|
const symbolResolutionStack = [];
|
215
216
|
const typeCacheFlags = new Map();
|
@@ -231,6 +232,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
231
232
|
let functionObj;
|
232
233
|
let tupleClassType;
|
233
234
|
let boolClassType;
|
235
|
+
let intClassType;
|
234
236
|
let strClassType;
|
235
237
|
let dictClassType;
|
236
238
|
let typedDictClassType;
|
@@ -279,6 +281,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
279
281
|
return cachedType !== undefined;
|
280
282
|
}
|
281
283
|
function readTypeCache(node, flags) {
|
284
|
+
var _a, _b;
|
282
285
|
let cachedType;
|
283
286
|
// Should we use a temporary cache associated with a contextual
|
284
287
|
// analysis of a function, contextualized based on call-site argument types?
|
@@ -295,8 +298,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
295
298
|
if (flags !== undefined) {
|
296
299
|
const expectedFlags = typeCacheFlags.get(node.id);
|
297
300
|
if (expectedFlags !== undefined && flags !== expectedFlags) {
|
298
|
-
|
299
|
-
|
301
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
302
|
+
const position = (0, positionUtils_1.convertOffsetToPosition)(node.start, fileInfo.lines);
|
303
|
+
const message = `Type cache flag mismatch for node type ${node.nodeType} ` +
|
304
|
+
`(parent ${(_b = (_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== null && _b !== void 0 ? _b : 'none'}): ` +
|
305
|
+
`cached flags = ${expectedFlags}, access flags = ${flags}, ` +
|
306
|
+
`file = {${fileInfo.filePath} [${position.line + 1}:${position.character + 1}]}`;
|
307
|
+
if (evaluatorOptions.verifyTypeCacheEvaluatorFlags) {
|
308
|
+
(0, debug_1.fail)(message);
|
309
|
+
}
|
310
|
+
else {
|
311
|
+
console.log(message);
|
312
|
+
}
|
300
313
|
}
|
301
314
|
}
|
302
315
|
}
|
@@ -424,9 +437,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
424
437
|
// context. For example, if it's a subexpression of an argument expression,
|
425
438
|
// the associated parameter type might inform the expected type.
|
426
439
|
function getExpectedType(node) {
|
427
|
-
|
440
|
+
// Scan up the parse tree to find the top-most expression node
|
441
|
+
// so we can evaluate the entire expression.
|
442
|
+
let topExpression = node;
|
428
443
|
let curNode = node;
|
429
|
-
while (curNode
|
444
|
+
while (curNode) {
|
445
|
+
if ((0, parseNodes_1.isExpressionNode)(curNode)) {
|
446
|
+
topExpression = curNode;
|
447
|
+
}
|
448
|
+
curNode = curNode.parent;
|
449
|
+
}
|
450
|
+
// Evaluate the expression. This will have the side effect of
|
451
|
+
// storing an expected type in the expected type cache.
|
452
|
+
evaluateTypesForExpressionInContext(topExpression);
|
453
|
+
// Look for the resulting expected type by scanning up the parse tree.
|
454
|
+
curNode = node;
|
455
|
+
while (curNode) {
|
430
456
|
const expectedType = expectedTypeCache.get(curNode.id);
|
431
457
|
if (expectedType) {
|
432
458
|
return {
|
@@ -434,6 +460,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
434
460
|
node: curNode,
|
435
461
|
};
|
436
462
|
}
|
463
|
+
if (curNode === topExpression) {
|
464
|
+
break;
|
465
|
+
}
|
437
466
|
curNode = curNode.parent;
|
438
467
|
}
|
439
468
|
return undefined;
|
@@ -452,6 +481,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
452
481
|
noneType = getTypeshedType(node, 'NoneType') || types_1.AnyType.create();
|
453
482
|
tupleClassType = getBuiltInType(node, 'tuple');
|
454
483
|
boolClassType = getBuiltInType(node, 'bool');
|
484
|
+
intClassType = getBuiltInType(node, 'int');
|
455
485
|
strClassType = getBuiltInType(node, 'str');
|
456
486
|
dictClassType = getBuiltInType(node, 'dict');
|
457
487
|
typedDictClassType = getTypingType(node, '_TypedDict');
|
@@ -465,7 +495,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
465
495
|
if (printExpressionTypes) {
|
466
496
|
console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Cached ${printType(cachedType)}`);
|
467
497
|
}
|
468
|
-
return { type: cachedType
|
498
|
+
return { type: cachedType };
|
469
499
|
}
|
470
500
|
else {
|
471
501
|
// Is it cached in the speculative type cache?
|
@@ -474,7 +504,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
474
504
|
if (printExpressionTypes) {
|
475
505
|
console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Speculative ${printType(speculativeCachedType)}`);
|
476
506
|
}
|
477
|
-
return { type: speculativeCachedType
|
507
|
+
return { type: speculativeCachedType };
|
478
508
|
}
|
479
509
|
}
|
480
510
|
if (printExpressionTypes) {
|
@@ -626,7 +656,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
626
656
|
getTypeOfExpression(node.child);
|
627
657
|
}
|
628
658
|
});
|
629
|
-
typeResult = { type: types_1.UnknownType.create()
|
659
|
+
typeResult = { type: types_1.UnknownType.create() };
|
630
660
|
break;
|
631
661
|
}
|
632
662
|
default:
|
@@ -678,7 +708,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
678
708
|
const exprTypeResult = getTypeOfExpression(node.expression, flags, effectiveExpectedType);
|
679
709
|
const typeResult = {
|
680
710
|
type: getTypeOfAwaitable(exprTypeResult.type, node.expression),
|
681
|
-
node,
|
682
711
|
};
|
683
712
|
if (exprTypeResult.isIncomplete) {
|
684
713
|
typeResult.isIncomplete = true;
|
@@ -687,26 +716,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
687
716
|
}
|
688
717
|
function getTypeOfEllipsis(flags, typeResult, node) {
|
689
718
|
if ((flags & 1 /* ConvertEllipsisToAny */) !== 0) {
|
690
|
-
typeResult = { type: types_1.AnyType.create(/* isEllipsis */ true)
|
719
|
+
typeResult = { type: types_1.AnyType.create(/* isEllipsis */ true) };
|
691
720
|
}
|
692
721
|
else if ((flags & 256 /* ConvertEllipsisToUnknown */) !== 0) {
|
693
|
-
typeResult = { type: types_1.UnknownType.create()
|
722
|
+
typeResult = { type: types_1.UnknownType.create() };
|
694
723
|
}
|
695
724
|
else {
|
696
725
|
const ellipsisType = getBuiltInObject(node, 'ellipsis') || types_1.AnyType.create();
|
697
|
-
typeResult = { type: ellipsisType
|
726
|
+
typeResult = { type: ellipsisType };
|
698
727
|
}
|
699
728
|
return typeResult;
|
700
729
|
}
|
701
730
|
function getTypeOfNumber(node, typeResult) {
|
702
731
|
if (node.isImaginary) {
|
703
|
-
typeResult = {
|
732
|
+
typeResult = { type: getBuiltInObject(node, 'complex') };
|
704
733
|
}
|
705
734
|
else if (node.isInteger) {
|
706
|
-
typeResult = {
|
735
|
+
typeResult = { type: cloneBuiltinObjectWithLiteral(node, 'int', node.value) };
|
707
736
|
}
|
708
737
|
else {
|
709
|
-
typeResult = {
|
738
|
+
typeResult = { type: getBuiltInObject(node, 'float') };
|
710
739
|
}
|
711
740
|
return typeResult;
|
712
741
|
}
|
@@ -725,17 +754,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
725
754
|
if ((flags & 128 /* TypeVarTupleDisallowed */) === 0 &&
|
726
755
|
(0, types_1.isVariadicTypeVar)(iterType) &&
|
727
756
|
!iterType.isVariadicUnpacked) {
|
728
|
-
typeResult = { type: types_1.TypeVarType.cloneForUnpacked(iterType)
|
757
|
+
typeResult = { type: types_1.TypeVarType.cloneForUnpacked(iterType) };
|
729
758
|
}
|
730
759
|
else {
|
731
760
|
if ((flags & 2097152 /* AllowUnpackedTupleOrTypeVarTuple */) !== 0 &&
|
732
761
|
(0, types_1.isInstantiableClass)(iterType) &&
|
733
762
|
types_1.ClassType.isBuiltIn(iterType, 'tuple')) {
|
734
|
-
typeResult = { type: types_1.ClassType.cloneForUnpacked(iterType)
|
763
|
+
typeResult = { type: types_1.ClassType.cloneForUnpacked(iterType) };
|
735
764
|
}
|
736
765
|
else {
|
737
766
|
const type = (_a = getTypeOfIterator(iterType, /* isAsync */ false, node)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create(!!iterTypeResult.isIncomplete);
|
738
|
-
typeResult = { type, unpackedType: iterType,
|
767
|
+
typeResult = { type, unpackedType: iterType, isIncomplete: iterTypeResult.isIncomplete };
|
739
768
|
}
|
740
769
|
}
|
741
770
|
return typeResult;
|
@@ -764,7 +793,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
764
793
|
if (!typeResult) {
|
765
794
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
766
795
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.expectedTypeNotString(), node);
|
767
|
-
typeResult = {
|
796
|
+
typeResult = { type: types_1.UnknownType.create() };
|
768
797
|
}
|
769
798
|
}
|
770
799
|
else {
|
@@ -780,13 +809,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
780
809
|
// Don't create a literal type if it's an f-string.
|
781
810
|
if (node.strings.some((str) => str.nodeType === 27 /* FormatString */)) {
|
782
811
|
typeResult = {
|
783
|
-
node,
|
784
812
|
type: getBuiltInObject(node, isBytes ? 'bytes' : 'str'),
|
785
813
|
};
|
786
814
|
}
|
787
815
|
else {
|
788
816
|
typeResult = {
|
789
|
-
node,
|
790
817
|
type: cloneBuiltinObjectWithLiteral(node, isBytes ? 'bytes' : 'str', node.strings.map((s) => s.value).join('')),
|
791
818
|
};
|
792
819
|
}
|
@@ -799,13 +826,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
799
826
|
// Don't create a literal type if it's an f-string.
|
800
827
|
if (node.nodeType === 27 /* FormatString */) {
|
801
828
|
typeResult = {
|
802
|
-
node,
|
803
829
|
type: getBuiltInObject(node, isBytes ? 'bytes' : 'str'),
|
804
830
|
};
|
805
831
|
}
|
806
832
|
else {
|
807
833
|
typeResult = {
|
808
|
-
node,
|
809
834
|
type: cloneBuiltinObjectWithLiteral(node, isBytes ? 'bytes' : 'str', node.value),
|
810
835
|
};
|
811
836
|
}
|
@@ -915,7 +940,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
915
940
|
const argList = [
|
916
941
|
{
|
917
942
|
argumentCategory: 0 /* Simple */,
|
918
|
-
type: functionOrClassType,
|
943
|
+
typeResult: { type: functionOrClassType },
|
919
944
|
},
|
920
945
|
];
|
921
946
|
const returnType = validateCallArguments(node.expression, argList, decoratorTypeResult,
|
@@ -1138,7 +1163,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1138
1163
|
/* isAccessedThroughObject */ true, memberName, usage, diag, memberAccessFlags | 8 /* DisallowClassVarWrites */, bindToType);
|
1139
1164
|
if (memberInfo) {
|
1140
1165
|
return {
|
1141
|
-
node: errorNode,
|
1142
1166
|
type: memberInfo.type,
|
1143
1167
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
1144
1168
|
isAsymmetricDescriptor: memberInfo.isAsymmetricDescriptor,
|
@@ -1152,7 +1176,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1152
1176
|
let memberInfo;
|
1153
1177
|
if (types_1.ClassType.isPartiallyEvaluated(classType)) {
|
1154
1178
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classDefinitionCycle().format({ name: classType.details.name }), errorNode);
|
1155
|
-
return {
|
1179
|
+
return { type: types_1.UnknownType.create() };
|
1156
1180
|
}
|
1157
1181
|
if ((memberAccessFlags & 32 /* ConsiderMetaclassOnly */) === 0) {
|
1158
1182
|
memberInfo = getTypeOfClassMemberName(errorNode, classType,
|
@@ -1184,7 +1208,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1184
1208
|
}
|
1185
1209
|
if (memberInfo) {
|
1186
1210
|
return {
|
1187
|
-
node: errorNode,
|
1188
1211
|
type: memberInfo.type,
|
1189
1212
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
1190
1213
|
isAsymmetricDescriptor: memberInfo.isAsymmetricDescriptor,
|
@@ -1230,7 +1253,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1230
1253
|
function addFakeArg() {
|
1231
1254
|
argList.push({
|
1232
1255
|
argumentCategory: previousCategory,
|
1233
|
-
type: types_1.UnknownType.create(),
|
1256
|
+
typeResult: { type: types_1.UnknownType.create() },
|
1234
1257
|
active: true,
|
1235
1258
|
});
|
1236
1259
|
}
|
@@ -1272,10 +1295,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1272
1295
|
addOneFunctionToSignature(type);
|
1273
1296
|
}
|
1274
1297
|
else {
|
1275
|
-
type.
|
1276
|
-
|
1277
|
-
addOneFunctionToSignature(func);
|
1278
|
-
}
|
1298
|
+
types_1.OverloadedFunctionType.getOverloads(type).forEach((func) => {
|
1299
|
+
addOneFunctionToSignature(func);
|
1279
1300
|
});
|
1280
1301
|
}
|
1281
1302
|
}
|
@@ -1477,13 +1498,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1477
1498
|
return subtype;
|
1478
1499
|
}
|
1479
1500
|
if ((0, types_1.isClassInstance)(subtype)) {
|
1480
|
-
const awaitReturnType = getSpecializedReturnType(subtype, '__await__', errorNode);
|
1501
|
+
const awaitReturnType = getSpecializedReturnType(subtype, '__await__', [], errorNode);
|
1481
1502
|
if (awaitReturnType) {
|
1482
1503
|
if ((0, types_1.isAnyOrUnknown)(awaitReturnType)) {
|
1483
1504
|
return awaitReturnType;
|
1484
1505
|
}
|
1485
1506
|
if ((0, types_1.isClassInstance)(awaitReturnType)) {
|
1486
|
-
const iterReturnType = getSpecializedReturnType(awaitReturnType, '__iter__', errorNode);
|
1507
|
+
const iterReturnType = getSpecializedReturnType(awaitReturnType, '__iter__', [], errorNode);
|
1487
1508
|
if (iterReturnType) {
|
1488
1509
|
const generatorReturnType = getReturnTypeFromGenerator(awaitReturnType);
|
1489
1510
|
if (generatorReturnType) {
|
@@ -1506,6 +1527,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1506
1527
|
const iterMethodName = isAsync ? '__aiter__' : '__iter__';
|
1507
1528
|
const nextMethodName = isAsync ? '__anext__' : '__next__';
|
1508
1529
|
let isValidIterator = true;
|
1530
|
+
type = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(type);
|
1509
1531
|
type = makeTopLevelTypeVarsConcrete(type);
|
1510
1532
|
if ((0, typeUtils_1.isOptionalType)(type)) {
|
1511
1533
|
if (errorNode) {
|
@@ -1528,18 +1550,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1528
1550
|
subtype.tupleTypeArguments.length === 0) {
|
1529
1551
|
return types_1.NeverType.createNever();
|
1530
1552
|
}
|
1531
|
-
iterReturnType = getSpecializedReturnType(subtype, iterMethodName, errorNode);
|
1553
|
+
iterReturnType = getSpecializedReturnType(subtype, iterMethodName, [], errorNode);
|
1532
1554
|
}
|
1533
1555
|
else if (types_1.TypeBase.isInstantiable(subtype) &&
|
1534
1556
|
subtype.details.effectiveMetaclass &&
|
1535
1557
|
(0, types_1.isInstantiableClass)(subtype.details.effectiveMetaclass)) {
|
1536
|
-
iterReturnType = getSpecializedReturnType(types_1.ClassType.cloneAsInstance(subtype.details.effectiveMetaclass), iterMethodName, errorNode, subtype);
|
1558
|
+
iterReturnType = getSpecializedReturnType(types_1.ClassType.cloneAsInstance(subtype.details.effectiveMetaclass), iterMethodName, [], errorNode, subtype);
|
1537
1559
|
}
|
1538
1560
|
if (!iterReturnType) {
|
1539
1561
|
// There was no __iter__. See if we can fall back to
|
1540
1562
|
// the __getitem__ method instead.
|
1541
|
-
if ((0, types_1.isClassInstance)(subtype)) {
|
1542
|
-
const getItemReturnType = getSpecializedReturnType(subtype, '__getitem__',
|
1563
|
+
if (!isAsync && (0, types_1.isClassInstance)(subtype)) {
|
1564
|
+
const getItemReturnType = getSpecializedReturnType(subtype, '__getitem__', [
|
1565
|
+
{
|
1566
|
+
argumentCategory: 0 /* Simple */,
|
1567
|
+
typeResult: {
|
1568
|
+
type: intClassType && (0, types_1.isInstantiableClass)(intClassType)
|
1569
|
+
? types_1.ClassType.cloneAsInstance(intClassType)
|
1570
|
+
: types_1.UnknownType.create(),
|
1571
|
+
},
|
1572
|
+
},
|
1573
|
+
], errorNode);
|
1543
1574
|
if (getItemReturnType) {
|
1544
1575
|
return getItemReturnType;
|
1545
1576
|
}
|
@@ -1554,7 +1585,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1554
1585
|
return subtype;
|
1555
1586
|
}
|
1556
1587
|
if ((0, types_1.isClassInstance)(subtype)) {
|
1557
|
-
const nextReturnType = getSpecializedReturnType(subtype, nextMethodName, errorNode);
|
1588
|
+
const nextReturnType = getSpecializedReturnType(subtype, nextMethodName, [], errorNode);
|
1558
1589
|
if (!nextReturnType) {
|
1559
1590
|
iterReturnTypeDiag.addMessage(localize_1.Localizer.Diagnostic.methodNotDefinedOnType().format({
|
1560
1591
|
name: nextMethodName,
|
@@ -1607,12 +1638,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1607
1638
|
if ((0, types_1.isClass)(subtype)) {
|
1608
1639
|
let iterReturnType;
|
1609
1640
|
if (types_1.TypeBase.isInstance(subtype)) {
|
1610
|
-
iterReturnType = getSpecializedReturnType(subtype, iterMethodName, errorNode);
|
1641
|
+
iterReturnType = getSpecializedReturnType(subtype, iterMethodName, [], errorNode);
|
1611
1642
|
}
|
1612
1643
|
else if (types_1.TypeBase.isInstantiable(subtype) &&
|
1613
1644
|
subtype.details.effectiveMetaclass &&
|
1614
1645
|
(0, types_1.isInstantiableClass)(subtype.details.effectiveMetaclass)) {
|
1615
|
-
iterReturnType = getSpecializedReturnType(types_1.ClassType.cloneAsInstance(subtype.details.effectiveMetaclass), iterMethodName, errorNode, subtype);
|
1646
|
+
iterReturnType = getSpecializedReturnType(types_1.ClassType.cloneAsInstance(subtype.details.effectiveMetaclass), iterMethodName, [], errorNode, subtype);
|
1616
1647
|
}
|
1617
1648
|
if (iterReturnType) {
|
1618
1649
|
return makeTopLevelTypeVarsConcrete(iterReturnType);
|
@@ -1760,6 +1791,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1760
1791
|
fileInfo.diagnosticSink.addUnusedCodeWithTextRange(localize_1.Localizer.Diagnostic.unreachableCode(), textRange);
|
1761
1792
|
}
|
1762
1793
|
}
|
1794
|
+
function addUnreachableCode(node, textRange) {
|
1795
|
+
if (!isDiagnosticSuppressedForNode(node)) {
|
1796
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
1797
|
+
fileInfo.diagnosticSink.addUnreachableCodeWithTextRange(localize_1.Localizer.Diagnostic.unreachableCode(), textRange);
|
1798
|
+
}
|
1799
|
+
}
|
1763
1800
|
function addDeprecated(message, node) {
|
1764
1801
|
if (!isDiagnosticSuppressedForNode(node)) {
|
1765
1802
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -1886,9 +1923,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1886
1923
|
if (!isTypeIncomplete) {
|
1887
1924
|
reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, nameNode, destType, nameNode, ignoreEmptyContainers);
|
1888
1925
|
}
|
1889
|
-
writeTypeCache(nameNode, destType, 0 /* None */, isTypeIncomplete
|
1890
|
-
/* expectedType */ undefined,
|
1891
|
-
/* allowSpeculativeCaching */ false);
|
1926
|
+
writeTypeCache(nameNode, destType, 0 /* None */, isTypeIncomplete);
|
1892
1927
|
}
|
1893
1928
|
function assignTypeToMemberAccessNode(target, type, isTypeIncomplete, srcExpr, expectedTypeDiagAddendum) {
|
1894
1929
|
const baseTypeResult = getTypeOfExpression(target.leftExpression, 2 /* DoNotSpecialize */);
|
@@ -1932,12 +1967,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1932
1967
|
if (setTypeResult.isAsymmetricDescriptor) {
|
1933
1968
|
setAsymmetricDescriptorAssignment(target);
|
1934
1969
|
}
|
1935
|
-
writeTypeCache(target.memberName, type, 0 /* None */, isTypeIncomplete
|
1936
|
-
/*
|
1937
|
-
/* allowSpeculativeCaching */ false);
|
1938
|
-
writeTypeCache(target, type, 0 /* None */, isTypeIncomplete,
|
1939
|
-
/* expectedType */ undefined,
|
1940
|
-
/* allowSpeculativeCaching */ false);
|
1970
|
+
writeTypeCache(target.memberName, type, 0 /* None */, isTypeIncomplete);
|
1971
|
+
writeTypeCache(target, type, 0 /* None */, isTypeIncomplete);
|
1941
1972
|
}
|
1942
1973
|
function assignTypeToMemberVariable(node, srcType, isTypeIncomplete, isInstanceMember, srcExprNode) {
|
1943
1974
|
const memberName = node.memberName.value;
|
@@ -2146,7 +2177,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2146
2177
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
2147
2178
|
return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [],
|
2148
2179
|
/* isTypeArgumentExplicit */ true,
|
2149
|
-
/* stripLiterals */ true,
|
2150
2180
|
/* isUnpackedTuple */ true));
|
2151
2181
|
}
|
2152
2182
|
}
|
@@ -2458,7 +2488,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2458
2488
|
break;
|
2459
2489
|
}
|
2460
2490
|
case 35 /* MemberAccess */: {
|
2461
|
-
const baseTypeResult = getTypeOfExpression(node.leftExpression);
|
2491
|
+
const baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /* DoNotSpecialize */);
|
2462
2492
|
const memberType = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* None */);
|
2463
2493
|
writeTypeCache(node.memberName, memberType.type, 0 /* None */, /* isIncomplete */ false);
|
2464
2494
|
writeTypeCache(node, memberType.type, 0 /* None */, /* isIncomplete */ false);
|
@@ -2514,7 +2544,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2514
2544
|
}
|
2515
2545
|
return undefined;
|
2516
2546
|
}
|
2517
|
-
function getSpecializedReturnType(objType, memberName, errorNode, bindToClass) {
|
2547
|
+
function getSpecializedReturnType(objType, memberName, argList, errorNode, bindToClass) {
|
2518
2548
|
const classMember = (0, typeUtils_1.lookUpObjectMember)(objType, memberName, 8 /* SkipInstanceVariables */);
|
2519
2549
|
if (!classMember) {
|
2520
2550
|
return undefined;
|
@@ -2523,13 +2553,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2523
2553
|
if ((0, types_1.isAnyOrUnknown)(memberType)) {
|
2524
2554
|
return memberType;
|
2525
2555
|
}
|
2526
|
-
if ((0, types_1.isFunction)(memberType)) {
|
2556
|
+
if ((0, types_1.isFunction)(memberType) || (0, types_1.isOverloadedFunction)(memberType)) {
|
2527
2557
|
const methodType = bindFunctionToClassOrObject(bindToClass || objType, memberType, classMember && (0, types_1.isInstantiableClass)(classMember.classType) ? classMember.classType : undefined, errorNode,
|
2528
2558
|
/* recursionCount */ undefined,
|
2529
2559
|
/* treatConstructorAsClassMember */ false,
|
2530
2560
|
/* firstParamType */ bindToClass);
|
2531
2561
|
if (methodType) {
|
2532
|
-
|
2562
|
+
if ((0, types_1.isOverloadedFunction)(methodType)) {
|
2563
|
+
if (errorNode) {
|
2564
|
+
const bestOverload = getBestOverloadForArguments(errorNode, methodType, argList);
|
2565
|
+
if (bestOverload) {
|
2566
|
+
return getFunctionEffectiveReturnType(bestOverload);
|
2567
|
+
}
|
2568
|
+
}
|
2569
|
+
}
|
2570
|
+
else {
|
2571
|
+
return getFunctionEffectiveReturnType(methodType);
|
2572
|
+
}
|
2533
2573
|
}
|
2534
2574
|
}
|
2535
2575
|
return undefined;
|
@@ -2546,7 +2586,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2546
2586
|
const containingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
2547
2587
|
if (containingFunction && ParseTreeUtils.isUnannotatedFunction(containingFunction)) {
|
2548
2588
|
return {
|
2549
|
-
node,
|
2550
2589
|
type: types_1.AnyType.create(),
|
2551
2590
|
isIncomplete: false,
|
2552
2591
|
};
|
@@ -2690,7 +2729,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2690
2729
|
if ((0, types_1.isTypeVar)(type) && !type.details.isSynthesized) {
|
2691
2730
|
type = validateTypeVarUsage(node, type, flags);
|
2692
2731
|
}
|
2693
|
-
return { type,
|
2732
|
+
return { type, isIncomplete };
|
2694
2733
|
}
|
2695
2734
|
// Handles the case where a variable or parameter is defined in an outer
|
2696
2735
|
// scope and captured by an inner scope (either a function or a lambda).
|
@@ -2988,7 +3027,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2988
3027
|
const baseTypeResult = getTypeOfExpression(node.leftExpression, baseTypeFlags);
|
2989
3028
|
if ((0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
|
2990
3029
|
return {
|
2991
|
-
node,
|
2992
3030
|
type: types_1.UnknownType.create(/* isIncomplete */ true),
|
2993
3031
|
isIncomplete: true,
|
2994
3032
|
};
|
@@ -3048,7 +3086,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3048
3086
|
// If the base type was incomplete and unbound, don't proceed
|
3049
3087
|
// because false positive errors will be generated.
|
3050
3088
|
if (baseTypeResult.isIncomplete && (0, types_1.isUnbound)(baseTypeResult.type)) {
|
3051
|
-
return { type: types_1.UnknownType.create(/* isIncomplete */ true),
|
3089
|
+
return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
|
3052
3090
|
}
|
3053
3091
|
// Handle the special case where the expression is an actual
|
3054
3092
|
// UnionType special form.
|
@@ -3084,22 +3122,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3084
3122
|
const paramNode = ParseTreeUtils.getEnclosingParameter(node);
|
3085
3123
|
if (!paramNode || paramNode.category !== 1 /* VarArgList */) {
|
3086
3124
|
addError(localize_1.Localizer.Diagnostic.paramSpecArgsUsage(), node);
|
3087
|
-
return { type: types_1.UnknownType.create(isIncomplete),
|
3125
|
+
return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
|
3088
3126
|
}
|
3089
|
-
return { type: types_1.TypeVarType.cloneForParamSpecAccess(baseType, 'args'),
|
3127
|
+
return { type: types_1.TypeVarType.cloneForParamSpecAccess(baseType, 'args'), isIncomplete };
|
3090
3128
|
}
|
3091
3129
|
if (memberName === 'kwargs') {
|
3092
3130
|
const paramNode = ParseTreeUtils.getEnclosingParameter(node);
|
3093
3131
|
if (!paramNode || paramNode.category !== 2 /* VarArgDictionary */) {
|
3094
3132
|
addError(localize_1.Localizer.Diagnostic.paramSpecKwargsUsage(), node);
|
3095
|
-
return { type: types_1.UnknownType.create(isIncomplete),
|
3133
|
+
return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
|
3096
3134
|
}
|
3097
|
-
return { type: types_1.TypeVarType.cloneForParamSpecAccess(baseType, 'kwargs'),
|
3135
|
+
return { type: types_1.TypeVarType.cloneForParamSpecAccess(baseType, 'kwargs'), isIncomplete };
|
3098
3136
|
}
|
3099
3137
|
if (!isIncomplete) {
|
3100
3138
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecUnknownMember().format({ name: memberName }), node);
|
3101
3139
|
}
|
3102
|
-
return { type: types_1.UnknownType.create(isIncomplete),
|
3140
|
+
return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
|
3103
3141
|
}
|
3104
3142
|
if (flags & 64 /* ExpectingType */) {
|
3105
3143
|
if (!isIncomplete) {
|
@@ -3108,14 +3146,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3108
3146
|
name: memberName,
|
3109
3147
|
}), node.leftExpression);
|
3110
3148
|
}
|
3111
|
-
return { type: types_1.UnknownType.create(isIncomplete),
|
3149
|
+
return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
|
3112
3150
|
}
|
3113
3151
|
if (baseType.details.recursiveTypeAliasName) {
|
3114
|
-
return { type: types_1.UnknownType.create(/* isIncomplete */ true),
|
3152
|
+
return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
|
3115
3153
|
}
|
3116
3154
|
return getTypeOfMemberAccessWithBaseType(node, {
|
3117
3155
|
type: makeTopLevelTypeVarsConcrete(baseType),
|
3118
|
-
node,
|
3119
3156
|
bindToType: baseType,
|
3120
3157
|
isIncomplete,
|
3121
3158
|
}, usage, 0 /* None */);
|
@@ -3146,14 +3183,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3146
3183
|
const strClass = getBuiltInType(node, 'str');
|
3147
3184
|
if ((0, types_1.isInstantiableClass)(strClass)) {
|
3148
3185
|
return {
|
3149
|
-
node,
|
3150
3186
|
type: types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneWithLiteral(strClass, literalValue.itemName)),
|
3151
3187
|
isIncomplete,
|
3152
3188
|
};
|
3153
3189
|
}
|
3154
3190
|
}
|
3155
3191
|
else if (memberName === 'value' || memberName === '_value_') {
|
3156
|
-
return {
|
3192
|
+
return { type: literalValue.itemType, isIncomplete };
|
3157
3193
|
}
|
3158
3194
|
}
|
3159
3195
|
}
|
@@ -3257,7 +3293,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3257
3293
|
else {
|
3258
3294
|
const typeResult = getTypeOfMemberAccessWithBaseType(node, {
|
3259
3295
|
type: subtype,
|
3260
|
-
node,
|
3261
3296
|
isIncomplete: baseTypeResult.isIncomplete,
|
3262
3297
|
}, usage, 0 /* None */);
|
3263
3298
|
if (typeResult.isIncomplete) {
|
@@ -3289,7 +3324,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3289
3324
|
type = types_1.AnyType.create();
|
3290
3325
|
}
|
3291
3326
|
else {
|
3292
|
-
type = getTypeOfMemberAccessWithBaseType(node, { type: functionObj
|
3327
|
+
type = getTypeOfMemberAccessWithBaseType(node, { type: functionObj }, usage, flags).type;
|
3293
3328
|
}
|
3294
3329
|
}
|
3295
3330
|
break;
|
@@ -3359,7 +3394,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3359
3394
|
/* ignoreEmptyContainers */ false);
|
3360
3395
|
}
|
3361
3396
|
}
|
3362
|
-
return { type,
|
3397
|
+
return { type, isIncomplete, isAsymmetricDescriptor };
|
3363
3398
|
}
|
3364
3399
|
function getTypeOfClassMemberName(errorNode, classType, isAccessedThroughObject, memberName, usage, diag, flags, bindToType) {
|
3365
3400
|
var _a, _b;
|
@@ -3569,25 +3604,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3569
3604
|
{
|
3570
3605
|
// Provide "obj" argument.
|
3571
3606
|
argumentCategory: 0 /* Simple */,
|
3572
|
-
|
3573
|
-
|
3574
|
-
|
3575
|
-
|
3576
|
-
|
3607
|
+
typeResult: {
|
3608
|
+
type: types_1.ClassType.isClassProperty(lookupClass)
|
3609
|
+
? baseTypeClass
|
3610
|
+
: isAccessedThroughObject
|
3611
|
+
? bindToType || types_1.ClassType.cloneAsInstance(baseTypeClass)
|
3612
|
+
: types_1.NoneType.createInstance(),
|
3613
|
+
},
|
3577
3614
|
},
|
3578
3615
|
];
|
3579
3616
|
if (usage.method === 'get') {
|
3580
3617
|
// Provide "objtype" argument.
|
3581
3618
|
argList.push({
|
3582
3619
|
argumentCategory: 0 /* Simple */,
|
3583
|
-
type: baseTypeClass,
|
3620
|
+
typeResult: { type: baseTypeClass },
|
3584
3621
|
});
|
3585
3622
|
}
|
3586
3623
|
else if (usage.method === 'set') {
|
3587
3624
|
// Provide "value" argument.
|
3588
3625
|
argList.push({
|
3589
3626
|
argumentCategory: 0 /* Simple */,
|
3590
|
-
type: (_a = usage.setType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create(),
|
3627
|
+
typeResult: { type: (_a = usage.setType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create() },
|
3591
3628
|
});
|
3592
3629
|
}
|
3593
3630
|
if (types_1.ClassType.isPropertyClass(lookupClass) &&
|
@@ -3699,7 +3736,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3699
3736
|
isFinal = types_1.FunctionType.isFinal(concreteSubtype);
|
3700
3737
|
}
|
3701
3738
|
else {
|
3702
|
-
const impl =
|
3739
|
+
const impl = types_1.OverloadedFunctionType.getImplementation(concreteSubtype);
|
3703
3740
|
if (impl) {
|
3704
3741
|
isFinal = types_1.FunctionType.isFinal(impl);
|
3705
3742
|
}
|
@@ -3821,55 +3858,57 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3821
3858
|
}
|
3822
3859
|
// Applies the __getattr__, __setattr__ or __delattr__ method if present.
|
3823
3860
|
function applyAttributeAccessOverride(classType, errorNode, usage, memberName) {
|
3824
|
-
var _a, _b, _c
|
3825
|
-
|
3861
|
+
var _a, _b, _c;
|
3862
|
+
const getAttributeAccessMember = (name) => {
|
3863
|
+
var _a;
|
3826
3864
|
// See if the class has a "__getattribute__" or "__getattr__" method.
|
3827
3865
|
// If so, arbitrary members are supported.
|
3828
|
-
|
3866
|
+
return (_a = getTypeOfClassMember(errorNode, classType, name, { method: 'get' },
|
3829
3867
|
/* diag */ undefined, 4 /* SkipObjectBaseClass */ | 64 /* SkipAttributeAccessOverride */)) === null || _a === void 0 ? void 0 : _a.type;
|
3830
|
-
|
3831
|
-
|
3832
|
-
|
3833
|
-
|
3834
|
-
// If it's an overload, it might be based on the member name. Create
|
3835
|
-
// a literal str type based on the member name and find the best overload.
|
3836
|
-
if (getAttrType && (0, types_1.isOverloadedFunction)(getAttrType)) {
|
3837
|
-
let nameLiteralType = types_1.AnyType.create();
|
3838
|
-
if (strClassType && (0, types_1.isInstantiableClass)(strClassType)) {
|
3839
|
-
nameLiteralType = types_1.ClassType.cloneWithLiteral(types_1.ClassType.cloneAsInstance(strClassType), memberName);
|
3840
|
-
}
|
3841
|
-
getAttrType = getBestOverloadForArguments(errorNode, getAttrType, [
|
3842
|
-
{
|
3843
|
-
argumentCategory: 0 /* Simple */,
|
3844
|
-
type: types_1.AnyType.create(),
|
3845
|
-
},
|
3846
|
-
{
|
3847
|
-
argumentCategory: 0 /* Simple */,
|
3848
|
-
type: nameLiteralType,
|
3849
|
-
},
|
3850
|
-
]);
|
3851
|
-
}
|
3852
|
-
if (getAttrType && (0, types_1.isFunction)(getAttrType)) {
|
3853
|
-
return getFunctionEffectiveReturnType(getAttrType);
|
3854
|
-
}
|
3868
|
+
};
|
3869
|
+
let accessMemberType;
|
3870
|
+
if (usage.method === 'get') {
|
3871
|
+
accessMemberType = (_a = getAttributeAccessMember('__getattribute__')) !== null && _a !== void 0 ? _a : getAttributeAccessMember('__getattr__');
|
3855
3872
|
}
|
3856
3873
|
else if (usage.method === 'set') {
|
3857
|
-
|
3858
|
-
/* diag */ undefined, 4 /* SkipObjectBaseClass */ | 64 /* SkipAttributeAccessOverride */)) === null || _c === void 0 ? void 0 : _c.type;
|
3859
|
-
if (setAttrType) {
|
3860
|
-
// The type doesn't matter for a set usage. We just need
|
3861
|
-
// to return a defined type.
|
3862
|
-
return types_1.AnyType.create();
|
3863
|
-
}
|
3874
|
+
accessMemberType = getAttributeAccessMember('__setattr__');
|
3864
3875
|
}
|
3865
3876
|
else {
|
3866
3877
|
(0, debug_1.assert)(usage.method === 'del');
|
3867
|
-
|
3868
|
-
|
3869
|
-
|
3870
|
-
|
3871
|
-
|
3872
|
-
|
3878
|
+
accessMemberType = getAttributeAccessMember('__delattr__');
|
3879
|
+
}
|
3880
|
+
if (accessMemberType) {
|
3881
|
+
let nameLiteralType = types_1.AnyType.create();
|
3882
|
+
if (strClassType && (0, types_1.isInstantiableClass)(strClassType)) {
|
3883
|
+
nameLiteralType = types_1.ClassType.cloneWithLiteral(types_1.ClassType.cloneAsInstance(strClassType), memberName);
|
3884
|
+
}
|
3885
|
+
const argList = [
|
3886
|
+
{
|
3887
|
+
// Provide "self" argument.
|
3888
|
+
argumentCategory: 0 /* Simple */,
|
3889
|
+
typeResult: { type: types_1.ClassType.cloneAsInstance(classType) },
|
3890
|
+
},
|
3891
|
+
{
|
3892
|
+
// Provide "name" argument.
|
3893
|
+
argumentCategory: 0 /* Simple */,
|
3894
|
+
typeResult: { type: nameLiteralType },
|
3895
|
+
},
|
3896
|
+
];
|
3897
|
+
if (usage.method === 'set') {
|
3898
|
+
argList.push({
|
3899
|
+
// Provide "value" argument.
|
3900
|
+
argumentCategory: 0 /* Simple */,
|
3901
|
+
typeResult: { type: (_b = usage.setType) !== null && _b !== void 0 ? _b : types_1.UnknownType.create() },
|
3902
|
+
});
|
3903
|
+
}
|
3904
|
+
if ((0, types_1.isFunction)(accessMemberType) || (0, types_1.isOverloadedFunction)(accessMemberType)) {
|
3905
|
+
const boundMethodType = bindFunctionToClassOrObject(classType, accessMemberType, classType, errorNode);
|
3906
|
+
if (boundMethodType && ((0, types_1.isFunction)(boundMethodType) || (0, types_1.isOverloadedFunction)(boundMethodType))) {
|
3907
|
+
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(boundMethodType));
|
3908
|
+
const callResult = validateCallArguments(errorNode, argList, { type: boundMethodType }, typeVarContext,
|
3909
|
+
/* skipUnknownArgCheck */ true);
|
3910
|
+
return (_c = callResult.returnType) !== null && _c !== void 0 ? _c : types_1.UnknownType.create();
|
3911
|
+
}
|
3873
3912
|
}
|
3874
3913
|
}
|
3875
3914
|
return undefined;
|
@@ -3994,7 +4033,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3994
4033
|
}
|
3995
4034
|
const tupleObject = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, variadicTypes,
|
3996
4035
|
/* isTypeArgumentExplicit */ true,
|
3997
|
-
/* stripLiterals */ true,
|
3998
4036
|
/* isUnpackedTuple */ true));
|
3999
4037
|
typeArgs = [
|
4000
4038
|
...typeArgs.slice(0, variadicIndex),
|
@@ -4009,7 +4047,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4009
4047
|
node: errorNode,
|
4010
4048
|
type: (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [],
|
4011
4049
|
/* isTypeArgumentExplicit */ true,
|
4012
|
-
/* stripLiterals */ true,
|
4013
4050
|
/* isUnpackedTuple */ true)),
|
4014
4051
|
});
|
4015
4052
|
}
|
@@ -4170,9 +4207,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4170
4207
|
if ((0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
|
4171
4208
|
const typeArgTypes = getTypeArgs(node, flags).map((t) => (0, typeUtils_1.convertToInstance)(t.type));
|
4172
4209
|
const type = types_1.TypeBase.cloneForTypeAlias(baseTypeResult.type, baseTypeResult.type.details.recursiveTypeAliasName, '', baseTypeResult.type.details.recursiveTypeAliasScopeId, baseTypeResult.type.details.recursiveTypeParameters, typeArgTypes);
|
4173
|
-
return { type
|
4210
|
+
return { type };
|
4174
4211
|
}
|
4175
|
-
let isIncomplete =
|
4212
|
+
let isIncomplete = baseTypeResult.isIncomplete;
|
4176
4213
|
const type = mapSubtypesExpandTypeVars(baseTypeResult.type,
|
4177
4214
|
/* conditionFilter */ undefined, (concreteSubtype, unexpandedSubtype) => {
|
4178
4215
|
var _a;
|
@@ -4267,11 +4304,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4267
4304
|
if ((0, types_1.isNever)(concreteSubtype)) {
|
4268
4305
|
return types_1.UnknownType.create();
|
4269
4306
|
}
|
4270
|
-
if ((0, types_1.isNoneInstance)(concreteSubtype)) {
|
4307
|
+
if ((0, types_1.isNoneInstance)(concreteSubtype) && !isIncomplete) {
|
4271
4308
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportOptionalSubscript, diagnosticRules_1.DiagnosticRule.reportOptionalSubscript, localize_1.Localizer.Diagnostic.noneNotSubscriptable(), node.baseExpression);
|
4272
4309
|
return types_1.UnknownType.create();
|
4273
4310
|
}
|
4274
|
-
if (!(0, types_1.isUnbound)(concreteSubtype)) {
|
4311
|
+
if (!(0, types_1.isUnbound)(concreteSubtype) && !isIncomplete) {
|
4275
4312
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
4276
4313
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotSubscriptable().format({ type: printType(concreteSubtype) }), node.baseExpression);
|
4277
4314
|
}
|
@@ -4286,7 +4323,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4286
4323
|
}
|
4287
4324
|
});
|
4288
4325
|
}
|
4289
|
-
return { type,
|
4326
|
+
return { type, isIncomplete };
|
4290
4327
|
}
|
4291
4328
|
function makeTupleObject(entryTypes, isUnspecifiedLength = false) {
|
4292
4329
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
@@ -4331,7 +4368,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4331
4368
|
name: magicMethodName,
|
4332
4369
|
type: printType(baseType),
|
4333
4370
|
}), node.baseExpression);
|
4334
|
-
return {
|
4371
|
+
return { type: types_1.UnknownType.create() };
|
4335
4372
|
}
|
4336
4373
|
// Handle the special case where the object is a Tuple and
|
4337
4374
|
// the index is a constant number (integer) or a slice with integer
|
@@ -4352,11 +4389,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4352
4389
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(baseType);
|
4353
4390
|
if (tupleType && tupleType.tupleTypeArguments && !(0, typeUtils_1.isUnboundedTupleClass)(tupleType)) {
|
4354
4391
|
if (indexValue >= 0 && indexValue < tupleType.tupleTypeArguments.length) {
|
4355
|
-
return {
|
4392
|
+
return { type: tupleType.tupleTypeArguments[indexValue].type };
|
4356
4393
|
}
|
4357
4394
|
else if (indexValue < 0 && tupleType.tupleTypeArguments.length + indexValue >= 0) {
|
4358
4395
|
return {
|
4359
|
-
node,
|
4360
4396
|
type: tupleType.tupleTypeArguments[tupleType.tupleTypeArguments.length + indexValue].type,
|
4361
4397
|
};
|
4362
4398
|
}
|
@@ -4394,7 +4430,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4394
4430
|
tupleClassType &&
|
4395
4431
|
(0, types_1.isInstantiableClass)(tupleClassType)) {
|
4396
4432
|
return {
|
4397
|
-
node,
|
4398
4433
|
type: types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, tupleType.tupleTypeArguments.slice(startValue, endValue))),
|
4399
4434
|
};
|
4400
4435
|
}
|
@@ -4408,9 +4443,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4408
4443
|
const keywordArgs = node.items.filter((item) => item.argumentCategory === 0 /* Simple */ && !!item.name);
|
4409
4444
|
const unpackedDictArgs = node.items.filter((item) => item.argumentCategory === 2 /* UnpackedDictionary */);
|
4410
4445
|
let positionalIndexType;
|
4446
|
+
let isPositionalIndexTypeIncomplete = false;
|
4411
4447
|
if (positionalArgs.length === 1 && unpackedListArgs.length === 0 && !node.trailingComma) {
|
4412
4448
|
// Handle the common case where there is a single positional argument.
|
4413
|
-
|
4449
|
+
const typeResult = getTypeOfExpression(positionalArgs[0].valueExpression);
|
4450
|
+
positionalIndexType = typeResult.type;
|
4451
|
+
if (typeResult.isIncomplete) {
|
4452
|
+
isPositionalIndexTypeIncomplete = true;
|
4453
|
+
}
|
4414
4454
|
}
|
4415
4455
|
else if (positionalArgs.length === 0 && unpackedListArgs.length === 0) {
|
4416
4456
|
// Handle the case where there are no positionals provided but there are keywords.
|
@@ -4423,11 +4463,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4423
4463
|
// Package up all of the positionals into a tuple.
|
4424
4464
|
const tupleEntries = [];
|
4425
4465
|
positionalArgs.forEach((arg) => {
|
4426
|
-
|
4466
|
+
const typeResult = getTypeOfExpression(arg.valueExpression);
|
4467
|
+
tupleEntries.push(typeResult.type);
|
4468
|
+
if (typeResult.isIncomplete) {
|
4469
|
+
isPositionalIndexTypeIncomplete = true;
|
4470
|
+
}
|
4427
4471
|
});
|
4428
4472
|
unpackedListArgs.forEach((arg) => {
|
4429
|
-
const
|
4430
|
-
const
|
4473
|
+
const typeResult = getTypeOfExpression(arg.valueExpression);
|
4474
|
+
const exprType = typeResult.type;
|
4475
|
+
if (typeResult.isIncomplete) {
|
4476
|
+
isPositionalIndexTypeIncomplete = true;
|
4477
|
+
}
|
4478
|
+
const iterableType = getTypeOfIterator(exprType, /* isAsync */ false, arg.valueExpression) || types_1.UnknownType.create();
|
4431
4479
|
tupleEntries.push(iterableType);
|
4432
4480
|
});
|
4433
4481
|
positionalIndexType = makeTupleObject(tupleEntries, unpackedListArgs.length > 0);
|
@@ -4435,7 +4483,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4435
4483
|
let argList = [
|
4436
4484
|
{
|
4437
4485
|
argumentCategory: 0 /* Simple */,
|
4438
|
-
type: positionalIndexType,
|
4486
|
+
typeResult: { type: positionalIndexType, isIncomplete: isPositionalIndexTypeIncomplete },
|
4439
4487
|
},
|
4440
4488
|
];
|
4441
4489
|
if (usage.method === 'set') {
|
@@ -4447,7 +4495,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4447
4495
|
}
|
4448
4496
|
argList.push({
|
4449
4497
|
argumentCategory: 0 /* Simple */,
|
4450
|
-
type: setType,
|
4498
|
+
typeResult: { type: setType, isIncomplete: isPositionalIndexTypeIncomplete },
|
4451
4499
|
});
|
4452
4500
|
}
|
4453
4501
|
keywordArgs.forEach((arg) => {
|
@@ -4469,32 +4517,33 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4469
4517
|
// Speculatively attempt the call. We may need to replace the index
|
4470
4518
|
// type with 'int', and we don't want to emit errors before we know
|
4471
4519
|
// which type to use.
|
4472
|
-
|
4473
|
-
|
4474
|
-
|
4475
|
-
|
4476
|
-
|
4477
|
-
|
4478
|
-
|
4479
|
-
|
4480
|
-
|
4481
|
-
|
4482
|
-
|
4483
|
-
|
4484
|
-
|
4520
|
+
if (keywordArgs.length === 0 && unpackedDictArgs.length === 0 && positionalArgs.length === 1) {
|
4521
|
+
useSpeculativeMode(node, () => {
|
4522
|
+
callResult = validateCallArguments(node, argList, { type: itemMethodType });
|
4523
|
+
if (callResult.argumentErrors) {
|
4524
|
+
// If the object supports "__index__" magic method, convert
|
4525
|
+
// the index to an int and try again.
|
4526
|
+
if ((0, types_1.isClassInstance)(positionalIndexType)) {
|
4527
|
+
const altArgList = [...argList];
|
4528
|
+
altArgList[0] = { ...altArgList[0] };
|
4529
|
+
const indexMethod = getTypeOfObjectMember(node, positionalIndexType, '__index__');
|
4530
|
+
if (indexMethod) {
|
4531
|
+
const intType = getBuiltInObject(node, 'int');
|
4532
|
+
if ((0, types_1.isClassInstance)(intType)) {
|
4533
|
+
altArgList[0].typeResult = { type: intType };
|
4534
|
+
}
|
4535
|
+
}
|
4536
|
+
callResult = validateCallArguments(node, altArgList, { type: itemMethodType });
|
4537
|
+
// We were successful, so replace the arg list.
|
4538
|
+
if (!callResult.argumentErrors) {
|
4539
|
+
argList = altArgList;
|
4485
4540
|
}
|
4486
|
-
}
|
4487
|
-
callResult = validateCallArguments(node, altArgList, { type: itemMethodType });
|
4488
|
-
// We were successful, so replace the arg list.
|
4489
|
-
if (!callResult.argumentErrors) {
|
4490
|
-
argList = altArgList;
|
4491
4541
|
}
|
4492
4542
|
}
|
4493
|
-
}
|
4494
|
-
}
|
4543
|
+
});
|
4544
|
+
}
|
4495
4545
|
callResult = validateCallArguments(node, argList, { type: itemMethodType });
|
4496
4546
|
return {
|
4497
|
-
node,
|
4498
4547
|
type: (_c = callResult.returnType) !== null && _c !== void 0 ? _c : types_1.UnknownType.create(),
|
4499
4548
|
isIncomplete: !!callResult.isTypeIncomplete,
|
4500
4549
|
};
|
@@ -4522,10 +4571,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4522
4571
|
// treated as types. If it's an Annotated[a, b, c], only the first index
|
4523
4572
|
// should be treated as a type. The others can be regular (non-type) objects.
|
4524
4573
|
if (hasCustomClassGetItem || (isAnnotatedClass && argIndex > 0)) {
|
4525
|
-
typeResult =
|
4526
|
-
|
4527
|
-
|
4528
|
-
|
4574
|
+
typeResult = {
|
4575
|
+
...getTypeOfExpression(expr, 32 /* ParamSpecDisallowed */ |
|
4576
|
+
128 /* TypeVarTupleDisallowed */ |
|
4577
|
+
2 /* DoNotSpecialize */ |
|
4578
|
+
131072 /* ClassVarDisallowed */),
|
4579
|
+
node: expr,
|
4580
|
+
};
|
4529
4581
|
}
|
4530
4582
|
else {
|
4531
4583
|
typeResult = getTypeArg(expr, adjFlags);
|
@@ -4571,7 +4623,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4571
4623
|
let typeResult;
|
4572
4624
|
let adjustedFlags = flags |
|
4573
4625
|
64 /* ExpectingType */ |
|
4574
|
-
1024 /* ExpectingTypeAnnotation */ |
|
4575
4626
|
1 /* ConvertEllipsisToAny */ |
|
4576
4627
|
8 /* EvaluateStringLiteralAsType */;
|
4577
4628
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -4581,14 +4632,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4581
4632
|
if (node.nodeType === 31 /* List */) {
|
4582
4633
|
typeResult = {
|
4583
4634
|
type: types_1.UnknownType.create(),
|
4584
|
-
typeList: node.entries.map((entry) =>
|
4635
|
+
typeList: node.entries.map((entry) => {
|
4636
|
+
return { ...getTypeOfExpression(entry, adjustedFlags), node: entry };
|
4637
|
+
}),
|
4585
4638
|
node,
|
4586
4639
|
};
|
4587
4640
|
// Set the node's type so it isn't reevaluated later.
|
4588
4641
|
setTypeForNode(node, types_1.UnknownType.create());
|
4589
4642
|
}
|
4590
4643
|
else {
|
4591
|
-
typeResult = getTypeOfExpression(node, adjustedFlags);
|
4644
|
+
typeResult = { ...getTypeOfExpression(node, adjustedFlags), node };
|
4592
4645
|
// "Protocol" is not allowed as a type argument.
|
4593
4646
|
if ((0, types_1.isClass)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'Protocol')) {
|
4594
4647
|
addError(localize_1.Localizer.Diagnostic.protocolNotAllowedInTypeArgument(), node);
|
@@ -4604,7 +4657,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4604
4657
|
}
|
4605
4658
|
function getTypeOfTuple(node, expectedType, flags) {
|
4606
4659
|
if ((flags & 64 /* ExpectingType */) !== 0 && node.expressions.length === 0 && !expectedType) {
|
4607
|
-
return { type: makeTupleObject([]),
|
4660
|
+
return { type: makeTupleObject([]), isEmptyTupleShorthand: true };
|
4608
4661
|
}
|
4609
4662
|
// If the expected type is a union, recursively call for each of the subtypes
|
4610
4663
|
// to find one that matches.
|
@@ -4681,20 +4734,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4681
4734
|
}
|
4682
4735
|
const entryTypeResults = node.expressions.map((expr, index) => getTypeOfExpression(expr,
|
4683
4736
|
/* flags */ undefined, index < expectedTypes.length ? expectedTypes[index] : undefined));
|
4684
|
-
const expectedTypesContainLiterals = expectedTypes.some((type) => (0, typeUtils_1.isLiteralTypeOrUnion)(type));
|
4685
4737
|
const type = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, buildTupleTypesList(entryTypeResults),
|
4686
|
-
/* isTypeArgumentExplicit */ true
|
4687
|
-
|
4688
|
-
return { type, node };
|
4738
|
+
/* isTypeArgumentExplicit */ true));
|
4739
|
+
return { type };
|
4689
4740
|
}
|
4690
4741
|
function getTypeOfTupleInferred(node) {
|
4691
4742
|
const entryTypeResults = node.expressions.map((expr) => getTypeOfExpression(expr));
|
4692
4743
|
const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
|
4693
4744
|
if (!tupleClassType || !(0, types_1.isInstantiableClass)(tupleClassType)) {
|
4694
|
-
return { type: types_1.UnknownType.create()
|
4745
|
+
return { type: types_1.UnknownType.create() };
|
4695
4746
|
}
|
4696
4747
|
const type = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, buildTupleTypesList(entryTypeResults)));
|
4697
|
-
return { type,
|
4748
|
+
return { type, isIncomplete };
|
4698
4749
|
}
|
4699
4750
|
function buildTupleTypesList(entryTypeResults) {
|
4700
4751
|
const entryTypes = [];
|
@@ -4750,7 +4801,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4750
4801
|
};
|
4751
4802
|
return functionArg;
|
4752
4803
|
});
|
4753
|
-
let typeResult = {
|
4804
|
+
let typeResult = { type: types_1.UnknownType.create() };
|
4754
4805
|
if (!(0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
|
4755
4806
|
if (node.leftExpression.nodeType === 38 /* Name */ && node.leftExpression.value === 'super') {
|
4756
4807
|
// Handle the built-in "super" call specially.
|
@@ -4824,7 +4875,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4824
4875
|
}
|
4825
4876
|
if ((flags & 1024 /* ExpectingTypeAnnotation */) !== 0) {
|
4826
4877
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAnnotationCall(), node);
|
4827
|
-
typeResult = {
|
4878
|
+
typeResult = { type: types_1.UnknownType.create() };
|
4828
4879
|
}
|
4829
4880
|
return typeResult;
|
4830
4881
|
}
|
@@ -4835,12 +4886,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4835
4886
|
node.arguments[0].argumentCategory !== 0 /* Simple */ ||
|
4836
4887
|
node.arguments[1].name !== undefined) {
|
4837
4888
|
addError(localize_1.Localizer.Diagnostic.assertTypeArgs(), node);
|
4838
|
-
return {
|
4889
|
+
return { type: types_1.UnknownType.create() };
|
4839
4890
|
}
|
4840
4891
|
const arg0TypeResult = getTypeOfExpression(node.arguments[0].valueExpression,
|
4841
4892
|
/* flags */ undefined, expectedType);
|
4842
4893
|
if (arg0TypeResult.isIncomplete) {
|
4843
|
-
return {
|
4894
|
+
return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
|
4844
4895
|
}
|
4845
4896
|
const assertedType = (0, typeUtils_1.convertToInstance)(getTypeOfArgumentExpectingType(node.arguments[1]).type);
|
4846
4897
|
if (!(0, types_1.isTypeSame)(assertedType, arg0TypeResult.type)) {
|
@@ -4849,7 +4900,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4849
4900
|
received: printType(arg0TypeResult.type),
|
4850
4901
|
}), node.arguments[0].valueExpression);
|
4851
4902
|
}
|
4852
|
-
return {
|
4903
|
+
return { type: arg0TypeResult.type };
|
4853
4904
|
}
|
4854
4905
|
function getTypeOfRevealType(node, expectedType) {
|
4855
4906
|
let arg0Value;
|
@@ -4886,7 +4937,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4886
4937
|
});
|
4887
4938
|
if (!arg0Value) {
|
4888
4939
|
addError(localize_1.Localizer.Diagnostic.revealTypeArgs(), node);
|
4889
|
-
return {
|
4940
|
+
return { type: types_1.UnknownType.create() };
|
4890
4941
|
}
|
4891
4942
|
const typeResult = getTypeOfExpression(arg0Value, /* flags */ undefined, expectedType);
|
4892
4943
|
const type = typeResult.type;
|
@@ -4910,11 +4961,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4910
4961
|
}
|
4911
4962
|
}
|
4912
4963
|
addInformation(localize_1.Localizer.DiagnosticAddendum.typeOfSymbol().format({ name: exprString, type: typeString }), node.arguments[0]);
|
4913
|
-
return {
|
4914
|
-
node,
|
4915
|
-
type,
|
4916
|
-
isIncomplete: typeResult.isIncomplete,
|
4917
|
-
};
|
4964
|
+
return { type, isIncomplete: typeResult.isIncomplete };
|
4918
4965
|
}
|
4919
4966
|
function getTypeOfRevealLocals(node) {
|
4920
4967
|
let curNode = node;
|
@@ -5063,11 +5110,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5063
5110
|
type: resultIsInstance
|
5064
5111
|
? types_1.ClassType.cloneAsInstance(lookupResults.classType)
|
5065
5112
|
: lookupResults.classType,
|
5066
|
-
node,
|
5067
5113
|
bindToType: resultIsInstance && bindToType && (0, types_1.isInstantiableClass)(bindToType)
|
5068
5114
|
? types_1.ClassType.cloneAsInstance(bindToType)
|
5069
5115
|
: bindToType,
|
5070
|
-
isSuperCall: true,
|
5071
5116
|
};
|
5072
5117
|
}
|
5073
5118
|
}
|
@@ -5077,11 +5122,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5077
5122
|
// If the class derives from one or more unknown classes,
|
5078
5123
|
// return unknown here to prevent spurious errors.
|
5079
5124
|
if (targetClassType.details.mro.some((mroBase) => (0, types_1.isAnyOrUnknown)(mroBase))) {
|
5080
|
-
return {
|
5081
|
-
type: types_1.UnknownType.create(),
|
5082
|
-
isSuperCall: true,
|
5083
|
-
node,
|
5084
|
-
};
|
5125
|
+
return { type: types_1.UnknownType.create() };
|
5085
5126
|
}
|
5086
5127
|
const baseClasses = targetClassType.details.baseClasses;
|
5087
5128
|
if (baseClasses.length > 0) {
|
@@ -5089,17 +5130,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5089
5130
|
if ((0, types_1.isInstantiableClass)(baseClassType)) {
|
5090
5131
|
return {
|
5091
5132
|
type: resultIsInstance ? types_1.ClassType.cloneAsInstance(baseClassType) : baseClassType,
|
5092
|
-
isSuperCall: true,
|
5093
|
-
node,
|
5094
5133
|
};
|
5095
5134
|
}
|
5096
5135
|
}
|
5097
5136
|
}
|
5098
|
-
return {
|
5099
|
-
type: types_1.UnknownType.create(),
|
5100
|
-
isSuperCall: true,
|
5101
|
-
node,
|
5102
|
-
};
|
5137
|
+
return { type: types_1.UnknownType.create() };
|
5103
5138
|
}
|
5104
5139
|
// Attempts to find an overloaded function for each set of argument
|
5105
5140
|
// types in the expandedArgTypes list. If an argument type is undefined,
|
@@ -5109,6 +5144,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5109
5144
|
// (one for each argument) will be undefined. On subsequent calls, this
|
5110
5145
|
// list will grow to include union expansions.
|
5111
5146
|
function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, expectedType) {
|
5147
|
+
var _a;
|
5112
5148
|
const returnTypes = [];
|
5113
5149
|
const matchedOverloads = [];
|
5114
5150
|
let isTypeIncomplete = false;
|
@@ -5130,11 +5166,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5130
5166
|
return argParamCopy;
|
5131
5167
|
});
|
5132
5168
|
}
|
5133
|
-
// Clone the typeVarContext so we don't modify the original.
|
5134
|
-
|
5135
|
-
|
5136
|
-
|
5169
|
+
// Clone the typeVarContext so we don't modify the original. If this is
|
5170
|
+
// not the first time through the loop, clone the type var context
|
5171
|
+
// from the previous successful match.
|
5172
|
+
const typeVarContextToClone = matchedOverloads.length > 0
|
5173
|
+
? matchedOverloads[matchedOverloads.length - 1].typeVarContext.clone()
|
5174
|
+
: typeVarContext;
|
5175
|
+
const effectiveTypeVarContext = (_a = typeVarContextToClone === null || typeVarContextToClone === void 0 ? void 0 : typeVarContextToClone.clone()) !== null && _a !== void 0 ? _a : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overload));
|
5137
5176
|
effectiveTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(overload));
|
5177
|
+
effectiveTypeVarContext.unlock();
|
5138
5178
|
// Use speculative mode so we don't output any diagnostics or
|
5139
5179
|
// record any final types in the type cache.
|
5140
5180
|
const callResult = useSpeculativeMode(errorNode, () => {
|
@@ -5159,24 +5199,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5159
5199
|
return { argumentErrors: true, isTypeIncomplete };
|
5160
5200
|
}
|
5161
5201
|
}
|
5162
|
-
// We found a match for all of the expanded argument lists.
|
5163
|
-
//
|
5202
|
+
// We found a match for all of the expanded argument lists. Copy the
|
5203
|
+
// resulting type var context back into the caller's type var context.
|
5204
|
+
// Use the type var context from the last matched overload because it
|
5205
|
+
// includes the type var solutions for all earlier matched overloads.
|
5164
5206
|
if (typeVarContext) {
|
5165
|
-
|
5166
|
-
const overload = matchedOverloads[expandedTypesIndex].overload;
|
5167
|
-
const matchResults = matchedOverloads[expandedTypesIndex].matchResults;
|
5168
|
-
useSpeculativeMode(errorNode, () => {
|
5169
|
-
typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(overload));
|
5170
|
-
typeVarContext.unlock();
|
5171
|
-
return validateFunctionArgumentTypesWithExpectedType(errorNode, matchResults, typeVarContext,
|
5172
|
-
/* skipUnknownArgCheck */ true, expectedType);
|
5173
|
-
});
|
5174
|
-
}
|
5207
|
+
typeVarContext.copyFromClone(matchedOverloads[matchedOverloads.length - 1].typeVarContext);
|
5175
5208
|
}
|
5176
5209
|
// And run through the first expanded argument list one more time to
|
5177
5210
|
// populate the type cache.
|
5178
|
-
matchedOverloads[0].typeVarContext
|
5179
|
-
|
5211
|
+
const finalTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : matchedOverloads[0].typeVarContext;
|
5212
|
+
finalTypeVarContext.unlock();
|
5213
|
+
finalTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(matchedOverloads[0].overload));
|
5214
|
+
const finalCallResult = validateFunctionArgumentTypesWithExpectedType(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck, expectedType);
|
5180
5215
|
if (finalCallResult.isTypeIncomplete) {
|
5181
5216
|
isTypeIncomplete = true;
|
5182
5217
|
}
|
@@ -5191,15 +5226,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5191
5226
|
let overloadIndex = 0;
|
5192
5227
|
let matches = [];
|
5193
5228
|
// Create a list of potential overload matches based on arguments.
|
5194
|
-
type.
|
5229
|
+
types_1.OverloadedFunctionType.getOverloads(type).forEach((overload) => {
|
5195
5230
|
useSpeculativeMode(errorNode, () => {
|
5196
|
-
|
5197
|
-
|
5198
|
-
|
5199
|
-
matches.push(matchResults);
|
5200
|
-
}
|
5201
|
-
overloadIndex++;
|
5231
|
+
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, overload, overloadIndex);
|
5232
|
+
if (!matchResults.argumentErrors) {
|
5233
|
+
matches.push(matchResults);
|
5202
5234
|
}
|
5235
|
+
overloadIndex++;
|
5203
5236
|
});
|
5204
5237
|
});
|
5205
5238
|
matches = sortOverloadsByBestMatch(matches);
|
@@ -5236,17 +5269,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5236
5269
|
// cache or record any diagnostics at this stage.
|
5237
5270
|
useSpeculativeMode(errorNode, () => {
|
5238
5271
|
let overloadIndex = 0;
|
5239
|
-
type.
|
5272
|
+
types_1.OverloadedFunctionType.getOverloads(type).forEach((overload) => {
|
5240
5273
|
// Consider only the functions that have the @overload decorator,
|
5241
5274
|
// not the final function that omits the overload. This is the
|
5242
5275
|
// intended behavior according to PEP 484.
|
5243
|
-
|
5244
|
-
|
5245
|
-
|
5246
|
-
filteredMatchResults.push(matchResults);
|
5247
|
-
}
|
5248
|
-
overloadIndex++;
|
5276
|
+
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, overload, overloadIndex);
|
5277
|
+
if (!matchResults.argumentErrors) {
|
5278
|
+
filteredMatchResults.push(matchResults);
|
5249
5279
|
}
|
5280
|
+
overloadIndex++;
|
5250
5281
|
});
|
5251
5282
|
});
|
5252
5283
|
filteredMatchResults = sortOverloadsByBestMatch(filteredMatchResults);
|
@@ -5301,8 +5332,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5301
5332
|
// the expectedType. We'll use this to determine whether we need to do
|
5302
5333
|
// union expansion.
|
5303
5334
|
contextFreeArgTypes = argList.map((arg) => {
|
5304
|
-
if (arg.
|
5305
|
-
return arg.type;
|
5335
|
+
if (arg.typeResult) {
|
5336
|
+
return arg.typeResult.type;
|
5306
5337
|
}
|
5307
5338
|
if (arg.valueExpression) {
|
5308
5339
|
const valueExpressionNode = arg.valueExpression;
|
@@ -6204,7 +6235,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6204
6235
|
const funcArg = listElementType
|
6205
6236
|
? {
|
6206
6237
|
argumentCategory: 0 /* Simple */,
|
6207
|
-
type: listElementType,
|
6238
|
+
typeResult: { type: listElementType, isIncomplete: argTypeResult.isIncomplete },
|
6208
6239
|
}
|
6209
6240
|
: undefined;
|
6210
6241
|
if (funcArg && argTypeResult.isIncomplete) {
|
@@ -6369,7 +6400,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6369
6400
|
requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
|
6370
6401
|
argument: {
|
6371
6402
|
argumentCategory: 0 /* Simple */,
|
6372
|
-
type: entry.valueType,
|
6403
|
+
typeResult: { type: entry.valueType },
|
6373
6404
|
},
|
6374
6405
|
errorNode: argList[argIndex].valueExpression || errorNode,
|
6375
6406
|
paramName: name,
|
@@ -6384,7 +6415,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6384
6415
|
requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
|
6385
6416
|
argument: {
|
6386
6417
|
argumentCategory: 0 /* Simple */,
|
6387
|
-
type: entry.valueType,
|
6418
|
+
typeResult: { type: entry.valueType },
|
6388
6419
|
},
|
6389
6420
|
errorNode: argList[argIndex].valueExpression || errorNode,
|
6390
6421
|
paramName: name,
|
@@ -6574,7 +6605,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6574
6605
|
requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
|
6575
6606
|
argument: {
|
6576
6607
|
argumentCategory: 0 /* Simple */,
|
6577
|
-
type: unpackedDictionaryArgType,
|
6608
|
+
typeResult: { type: unpackedDictionaryArgType },
|
6578
6609
|
},
|
6579
6610
|
errorNode: (_b = (_a = argList.find((arg) => arg.argumentCategory === 2 /* UnpackedDictionary */)) === null || _a === void 0 ? void 0 : _a.valueExpression) !== null && _b !== void 0 ? _b : errorNode,
|
6580
6611
|
paramName: param.name,
|
@@ -6621,7 +6652,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6621
6652
|
requiresTypeVarMatching: true,
|
6622
6653
|
argument: {
|
6623
6654
|
argumentCategory: 0 /* Simple */,
|
6624
|
-
type: defaultArgType,
|
6655
|
+
typeResult: { type: defaultArgType },
|
6625
6656
|
},
|
6626
6657
|
errorNode: errorNode,
|
6627
6658
|
paramName: param.name,
|
@@ -6669,13 +6700,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6669
6700
|
});
|
6670
6701
|
const specializedTuple = types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, tupleTypeArgs,
|
6671
6702
|
/* isTypeArgumentExplicit */ true,
|
6672
|
-
/* stripLiterals */ true,
|
6673
6703
|
/* isUnpackedTuple */ true));
|
6674
6704
|
const combinedArg = {
|
6675
6705
|
paramCategory: 1 /* VarArgList */,
|
6676
6706
|
paramType,
|
6677
6707
|
requiresTypeVarMatching: true,
|
6678
|
-
argument: {
|
6708
|
+
argument: {
|
6709
|
+
argumentCategory: 0 /* Simple */,
|
6710
|
+
typeResult: { type: specializedTuple },
|
6711
|
+
},
|
6679
6712
|
errorNode,
|
6680
6713
|
paramName: paramDetails.params[paramDetails.argsIndex].param.name,
|
6681
6714
|
isParamNameSynthesized: paramDetails.params[paramDetails.argsIndex].param.isNameSynthesized,
|
@@ -7177,7 +7210,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7177
7210
|
if (argParam.argType) {
|
7178
7211
|
argType = argParam.argType;
|
7179
7212
|
}
|
7180
|
-
else if (argParam.expectingType && !argParam.argument.
|
7213
|
+
else if (argParam.expectingType && !argParam.argument.typeResult && argParam.argument.valueExpression) {
|
7181
7214
|
const argTypeResult = getTypeOfExpression(argParam.argument.valueExpression, 8 /* EvaluateStringLiteralAsType */ |
|
7182
7215
|
32 /* ParamSpecDisallowed */ |
|
7183
7216
|
128 /* TypeVarTupleDisallowed */);
|
@@ -7356,7 +7389,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7356
7389
|
return { isCompatible, argType, isTypeIncomplete, condition };
|
7357
7390
|
}
|
7358
7391
|
function createTypeVarType(errorNode, argList) {
|
7359
|
-
var _a, _b, _c;
|
7392
|
+
var _a, _b, _c, _d, _e;
|
7360
7393
|
let typeVarName = '';
|
7361
7394
|
let firstConstraintArg;
|
7362
7395
|
if (argList.length === 0) {
|
@@ -7385,9 +7418,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7385
7418
|
addError(localize_1.Localizer.Diagnostic.typeVarBoundAndConstrained(), argList[i].valueExpression || errorNode);
|
7386
7419
|
}
|
7387
7420
|
else {
|
7388
|
-
const argType = (_a = argList[i].type) !== null &&
|
7389
|
-
/* allowFinal */ undefined,
|
7390
|
-
/* allowRequired */ undefined).type;
|
7421
|
+
const argType = (_b = (_a = argList[i].typeResult) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : getTypeOfExpressionExpectingType(argList[i].valueExpression).type;
|
7391
7422
|
if ((0, typeUtils_1.requiresSpecialization)(argType, /* ignorePseudoGeneric */ true)) {
|
7392
7423
|
addError(localize_1.Localizer.Diagnostic.typeVarGeneric(), argList[i].valueExpression || errorNode);
|
7393
7424
|
}
|
@@ -7396,26 +7427,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7396
7427
|
}
|
7397
7428
|
else if (paramName === 'covariant') {
|
7398
7429
|
if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
|
7399
|
-
if (typeVar.details.declaredVariance ===
|
7430
|
+
if (typeVar.details.declaredVariance === 4 /* Contravariant */) {
|
7400
7431
|
addError(localize_1.Localizer.Diagnostic.typeVarVariance(), argList[i].valueExpression);
|
7401
7432
|
}
|
7402
7433
|
else {
|
7403
|
-
typeVar.details.declaredVariance =
|
7434
|
+
typeVar.details.declaredVariance = 3 /* Covariant */;
|
7404
7435
|
}
|
7405
7436
|
}
|
7406
7437
|
}
|
7407
7438
|
else if (paramName === 'contravariant') {
|
7408
7439
|
if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
|
7409
|
-
if (typeVar.details.declaredVariance ===
|
7440
|
+
if (typeVar.details.declaredVariance === 3 /* Covariant */) {
|
7410
7441
|
addError(localize_1.Localizer.Diagnostic.typeVarVariance(), argList[i].valueExpression);
|
7411
7442
|
}
|
7412
7443
|
else {
|
7413
|
-
typeVar.details.declaredVariance =
|
7444
|
+
typeVar.details.declaredVariance = 4 /* Contravariant */;
|
7414
7445
|
}
|
7415
7446
|
}
|
7416
7447
|
}
|
7417
7448
|
else {
|
7418
|
-
addError(localize_1.Localizer.Diagnostic.typeVarUnknownParam().format({ name: paramName }), ((
|
7449
|
+
addError(localize_1.Localizer.Diagnostic.typeVarUnknownParam().format({ name: paramName }), ((_c = argList[i].node) === null || _c === void 0 ? void 0 : _c.name) || argList[i].valueExpression || errorNode);
|
7419
7450
|
}
|
7420
7451
|
paramNameMap.set(paramName, paramName);
|
7421
7452
|
}
|
@@ -7424,9 +7455,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7424
7455
|
addError(localize_1.Localizer.Diagnostic.typeVarBoundAndConstrained(), argList[i].valueExpression || errorNode);
|
7425
7456
|
}
|
7426
7457
|
else {
|
7427
|
-
const argType = (
|
7428
|
-
/* allowFinal */ undefined,
|
7429
|
-
/* allowRequired */ undefined).type;
|
7458
|
+
const argType = (_e = (_d = argList[i].typeResult) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : getTypeOfExpressionExpectingType(argList[i].valueExpression).type;
|
7430
7459
|
if ((0, typeUtils_1.requiresSpecialization)(argType, /* ignorePseudoGeneric */ true)) {
|
7431
7460
|
addError(localize_1.Localizer.Diagnostic.typeVarGeneric(), argList[i].valueExpression || errorNode);
|
7432
7461
|
}
|
@@ -7704,14 +7733,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7704
7733
|
if (!type) {
|
7705
7734
|
return undefined;
|
7706
7735
|
}
|
7707
|
-
return { type
|
7736
|
+
return { type };
|
7708
7737
|
}
|
7709
7738
|
function getTypeOfUnaryOperation(node, expectedType) {
|
7710
7739
|
const exprTypeResult = getTypeOfExpression(node.expression);
|
7711
7740
|
let exprType = makeTopLevelTypeVarsConcrete(exprTypeResult.type);
|
7712
7741
|
const isIncomplete = exprTypeResult.isIncomplete;
|
7713
7742
|
if ((0, types_1.isNever)(exprType)) {
|
7714
|
-
return {
|
7743
|
+
return { type: types_1.NeverType.createNever(), isIncomplete };
|
7715
7744
|
}
|
7716
7745
|
// Map unary operators to magic functions. Note that the bitwise
|
7717
7746
|
// invert has two magic functions that are aliases of each other.
|
@@ -7790,16 +7819,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7790
7819
|
}
|
7791
7820
|
}
|
7792
7821
|
}
|
7793
|
-
return { type,
|
7794
|
-
}
|
7795
|
-
function operatorSupportsComparisonChaining(op) {
|
7796
|
-
if (binaryOperatorMap[op] && binaryOperatorMap[op][2]) {
|
7797
|
-
return true;
|
7798
|
-
}
|
7799
|
-
if (booleanOperatorMap[op]) {
|
7800
|
-
return true;
|
7801
|
-
}
|
7802
|
-
return false;
|
7822
|
+
return { type, isIncomplete };
|
7803
7823
|
}
|
7804
7824
|
function getTypeOfBinaryOperation(node, expectedType, flags) {
|
7805
7825
|
const leftExpression = node.leftExpression;
|
@@ -7808,10 +7828,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7808
7828
|
// If this is a comparison and the left expression is also a comparison,
|
7809
7829
|
// we need to change the behavior to accommodate python's "chained
|
7810
7830
|
// comparisons" feature.
|
7811
|
-
if (
|
7831
|
+
if (ParseTreeUtils.operatorSupportsChaining(node.operator)) {
|
7812
7832
|
if (rightExpression.nodeType === 7 /* BinaryOperation */ &&
|
7813
7833
|
!rightExpression.parenthesized &&
|
7814
|
-
|
7834
|
+
ParseTreeUtils.operatorSupportsChaining(rightExpression.operator)) {
|
7815
7835
|
// Evaluate the right expression so it is type checked.
|
7816
7836
|
getTypeOfBinaryOperation(rightExpression, expectedType, flags);
|
7817
7837
|
// Use the left side of the right expression for comparison purposes.
|
@@ -7888,15 +7908,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7888
7908
|
addError(localize_1.Localizer.Diagnostic.unionSyntaxIllegal(), node, node.operatorToken);
|
7889
7909
|
}
|
7890
7910
|
}
|
7891
|
-
if (!validateTypeArg(leftTypeResult, { allowVariadicTypeVar: true, allowUnpackedTuples: true }) ||
|
7892
|
-
!validateTypeArg(rightTypeResult, { allowVariadicTypeVar: true, allowUnpackedTuples: true })) {
|
7893
|
-
return { type: types_1.UnknownType.create()
|
7911
|
+
if (!validateTypeArg({ ...leftTypeResult, node: leftExpression }, { allowVariadicTypeVar: true, allowUnpackedTuples: true }) ||
|
7912
|
+
!validateTypeArg({ ...rightTypeResult, node: rightExpression }, { allowVariadicTypeVar: true, allowUnpackedTuples: true })) {
|
7913
|
+
return { type: types_1.UnknownType.create() };
|
7894
7914
|
}
|
7895
7915
|
const newUnion = (0, types_1.combineTypes)([adjustedLeftType, adjustedRightType]);
|
7896
7916
|
if ((0, types_1.isUnion)(newUnion)) {
|
7897
7917
|
types_1.TypeBase.setSpecialForm(newUnion);
|
7898
7918
|
}
|
7899
|
-
return { type: newUnion
|
7919
|
+
return { type: newUnion };
|
7900
7920
|
}
|
7901
7921
|
}
|
7902
7922
|
// Optional checks apply to all operations except for boolean operations.
|
@@ -7919,7 +7939,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7919
7939
|
// incomplete because we may be evaluating types within a loop,
|
7920
7940
|
// so the literal values may change each time.
|
7921
7941
|
const isLiteralMathAllowed = !ParseTreeUtils.isWithinLoop(node);
|
7922
|
-
let type = validateBinaryOperation(node.operator, leftType, rightType, node, expectedType, diag, isLiteralMathAllowed);
|
7942
|
+
let type = validateBinaryOperation(node.operator, { type: leftType, isIncomplete: leftTypeResult.isIncomplete }, { type: rightType, isIncomplete: rightTypeResult.isIncomplete }, node, expectedType, diag, isLiteralMathAllowed);
|
7923
7943
|
if (!diag.isEmpty() || !type) {
|
7924
7944
|
if (!isIncomplete) {
|
7925
7945
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -7942,7 +7962,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7942
7962
|
}
|
7943
7963
|
type = types_1.UnknownType.create();
|
7944
7964
|
}
|
7945
|
-
return { type,
|
7965
|
+
return { type, isIncomplete };
|
7946
7966
|
}
|
7947
7967
|
function customMetaclassSupportsMethod(type, methodName) {
|
7948
7968
|
if (!(0, types_1.isInstantiableClass)(type)) {
|
@@ -7995,7 +8015,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7995
8015
|
const rightType = rightTypeResult.type;
|
7996
8016
|
const isIncomplete = !!rightTypeResult.isIncomplete || !!leftTypeResult.isIncomplete;
|
7997
8017
|
if ((0, types_1.isNever)(leftType) || (0, types_1.isNever)(rightType)) {
|
7998
|
-
typeResult = {
|
8018
|
+
typeResult = { type: types_1.NeverType.createNever(), isIncomplete };
|
7999
8019
|
}
|
8000
8020
|
else {
|
8001
8021
|
type = mapSubtypesExpandTypeVars(leftType,
|
@@ -8005,14 +8025,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8005
8025
|
return (0, typeUtils_1.preserveUnknown)(leftSubtypeUnexpanded, rightSubtypeUnexpanded);
|
8006
8026
|
}
|
8007
8027
|
const magicMethodName = operatorMap[node.operator][0];
|
8008
|
-
let returnType = getTypeOfMagicMethodReturn(leftSubtypeUnexpanded, [rightSubtypeUnexpanded], magicMethodName, node, expectedType);
|
8028
|
+
let returnType = getTypeOfMagicMethodReturn(leftSubtypeUnexpanded, [{ type: rightSubtypeUnexpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, node, expectedType);
|
8009
8029
|
if (!returnType && leftSubtypeUnexpanded !== leftSubtypeExpanded) {
|
8010
8030
|
// Try with the expanded left type.
|
8011
|
-
returnType = getTypeOfMagicMethodReturn(leftSubtypeExpanded, [rightSubtypeUnexpanded], magicMethodName, node, expectedType);
|
8031
|
+
returnType = getTypeOfMagicMethodReturn(leftSubtypeExpanded, [{ type: rightSubtypeUnexpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, node, expectedType);
|
8012
8032
|
}
|
8013
8033
|
if (!returnType && rightSubtypeUnexpanded !== rightSubtypeExpanded) {
|
8014
8034
|
// Try with the expanded left and right type.
|
8015
|
-
returnType = getTypeOfMagicMethodReturn(leftSubtypeExpanded, [rightSubtypeExpanded], magicMethodName, node, expectedType);
|
8035
|
+
returnType = getTypeOfMagicMethodReturn(leftSubtypeExpanded, [{ type: rightSubtypeExpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, node, expectedType);
|
8016
8036
|
}
|
8017
8037
|
if (!returnType) {
|
8018
8038
|
// If the LHS class didn't support the magic method for augmented
|
@@ -8025,7 +8045,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8025
8045
|
!rightTypeResult.isIncomplete &&
|
8026
8046
|
(0, typeUtils_1.getUnionSubtypeCount)(leftType) * (0, typeUtils_1.getUnionSubtypeCount)(rightType) <
|
8027
8047
|
maxLiteralMathSubtypeCount;
|
8028
|
-
returnType = validateBinaryOperation(binaryOperator, leftSubtypeUnexpanded, rightSubtypeUnexpanded, node, expectedType, diag, isLiteralMathAllowed);
|
8048
|
+
returnType = validateBinaryOperation(binaryOperator, { type: leftSubtypeUnexpanded, isIncomplete: leftTypeResult.isIncomplete }, { type: rightSubtypeUnexpanded, isIncomplete: rightTypeResult.isIncomplete }, node, expectedType, diag, isLiteralMathAllowed);
|
8029
8049
|
}
|
8030
8050
|
return returnType;
|
8031
8051
|
});
|
@@ -8043,12 +8063,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8043
8063
|
}
|
8044
8064
|
type = types_1.UnknownType.create();
|
8045
8065
|
}
|
8046
|
-
typeResult = {
|
8066
|
+
typeResult = { type, isIncomplete };
|
8047
8067
|
}
|
8048
8068
|
assignTypeToExpression(node.destExpression, typeResult.type, !!typeResult.isIncomplete, node.rightExpression);
|
8049
8069
|
return typeResult;
|
8050
8070
|
}
|
8051
|
-
function validateBinaryOperation(operator,
|
8071
|
+
function validateBinaryOperation(operator, leftTypeResult, rightTypeResult, errorNode, expectedType, diag, isLiteralMathAllowed) {
|
8072
|
+
const leftType = leftTypeResult.type;
|
8073
|
+
const rightType = rightTypeResult.type;
|
8052
8074
|
let type;
|
8053
8075
|
let concreteLeftType = makeTopLevelTypeVarsConcrete(leftType);
|
8054
8076
|
if (booleanOperatorMap[operator] !== undefined) {
|
@@ -8098,7 +8120,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8098
8120
|
if ((0, types_1.isAnyOrUnknown)(leftSubtype) || (0, types_1.isAnyOrUnknown)(rightSubtypeUnexpanded)) {
|
8099
8121
|
return (0, typeUtils_1.preserveUnknown)(leftSubtype, rightSubtypeExpanded);
|
8100
8122
|
}
|
8101
|
-
let returnType = getTypeOfMagicMethodReturn(rightSubtypeExpanded, [leftSubtype], '__contains__', errorNode,
|
8123
|
+
let returnType = getTypeOfMagicMethodReturn(rightSubtypeExpanded, [{ type: leftSubtype, isIncomplete: leftTypeResult.isIncomplete }], '__contains__', errorNode,
|
8102
8124
|
/* expectedType */ undefined);
|
8103
8125
|
if (!returnType) {
|
8104
8126
|
// If __contains__ was not supported, fall back
|
@@ -8255,26 +8277,31 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8255
8277
|
]));
|
8256
8278
|
}
|
8257
8279
|
const magicMethodName = binaryOperatorMap[operator][0];
|
8258
|
-
let resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(leftSubtypeUnexpanded), [rightSubtypeUnexpanded], magicMethodName, errorNode, expectedType);
|
8280
|
+
let resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(leftSubtypeUnexpanded), [{ type: rightSubtypeUnexpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, errorNode, expectedType);
|
8259
8281
|
if (!resultType && leftSubtypeUnexpanded !== leftSubtypeExpanded) {
|
8260
8282
|
// Try the expanded left type.
|
8261
|
-
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(leftSubtypeExpanded), [rightSubtypeUnexpanded], magicMethodName, errorNode, expectedType);
|
8283
|
+
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(leftSubtypeExpanded), [{ type: rightSubtypeUnexpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, errorNode, expectedType);
|
8262
8284
|
}
|
8263
8285
|
if (!resultType && rightSubtypeUnexpanded !== rightSubtypeExpanded) {
|
8264
8286
|
// Try the expanded left and right type.
|
8265
|
-
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(leftSubtypeExpanded), [rightSubtypeExpanded], magicMethodName, errorNode, expectedType);
|
8287
|
+
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(leftSubtypeExpanded), [{ type: rightSubtypeExpanded, isIncomplete: rightTypeResult.isIncomplete }], magicMethodName, errorNode, expectedType);
|
8266
8288
|
}
|
8267
8289
|
if (!resultType) {
|
8268
8290
|
// Try the alternate form (swapping right and left).
|
8269
8291
|
const altMagicMethodName = binaryOperatorMap[operator][1];
|
8270
|
-
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(rightSubtypeUnexpanded), [leftSubtypeUnexpanded], altMagicMethodName, errorNode, expectedType);
|
8292
|
+
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(rightSubtypeUnexpanded), [{ type: leftSubtypeUnexpanded, isIncomplete: leftTypeResult.isIncomplete }], altMagicMethodName, errorNode, expectedType);
|
8271
8293
|
if (!resultType && rightSubtypeUnexpanded !== rightSubtypeExpanded) {
|
8272
8294
|
// Try the expanded right type.
|
8273
|
-
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(rightSubtypeExpanded), [
|
8295
|
+
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(rightSubtypeExpanded), [
|
8296
|
+
{
|
8297
|
+
type: leftSubtypeUnexpanded,
|
8298
|
+
isIncomplete: leftTypeResult.isIncomplete,
|
8299
|
+
},
|
8300
|
+
], altMagicMethodName, errorNode, expectedType);
|
8274
8301
|
}
|
8275
8302
|
if (!resultType && leftSubtypeUnexpanded !== leftSubtypeExpanded) {
|
8276
8303
|
// Try the expanded right and left type.
|
8277
|
-
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(rightSubtypeExpanded), [leftSubtypeExpanded], altMagicMethodName, errorNode, expectedType);
|
8304
|
+
resultType = getTypeOfMagicMethodReturn(convertFunctionToObject(rightSubtypeExpanded), [{ type: leftSubtypeExpanded, isIncomplete: leftTypeResult.isIncomplete }], altMagicMethodName, errorNode, expectedType);
|
8278
8305
|
}
|
8279
8306
|
}
|
8280
8307
|
if (!resultType) {
|
@@ -8322,7 +8349,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8322
8349
|
const functionArgs = args.map((arg) => {
|
8323
8350
|
return {
|
8324
8351
|
argumentCategory: 0 /* Simple */,
|
8325
|
-
|
8352
|
+
typeResult: arg,
|
8326
8353
|
};
|
8327
8354
|
});
|
8328
8355
|
let callResult;
|
@@ -8438,7 +8465,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8438
8465
|
if (resultTypedDict) {
|
8439
8466
|
return {
|
8440
8467
|
type: resultTypedDict,
|
8441
|
-
node,
|
8442
8468
|
isIncomplete,
|
8443
8469
|
};
|
8444
8470
|
}
|
@@ -8476,7 +8502,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8476
8502
|
return undefined;
|
8477
8503
|
}
|
8478
8504
|
const type = getBuiltInObject(node, 'dict', [specializedKeyType, specializedValueType]);
|
8479
|
-
return { type,
|
8505
|
+
return { type, isIncomplete };
|
8480
8506
|
}
|
8481
8507
|
// Attempts to infer the type of a dictionary statement. If hasExpectedType
|
8482
8508
|
// is true, strict inference is used for the subexpressions.
|
@@ -8520,7 +8546,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8520
8546
|
/* includeSubclasses */ undefined,
|
8521
8547
|
/* TupleTypeArguments */ undefined, isEmptyContainer))
|
8522
8548
|
: types_1.UnknownType.create();
|
8523
|
-
return { type,
|
8549
|
+
return { type, isIncomplete };
|
8524
8550
|
}
|
8525
8551
|
function getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes, forceStrictInference, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum) {
|
8526
8552
|
let isIncomplete = false;
|
@@ -8698,7 +8724,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8698
8724
|
return undefined;
|
8699
8725
|
}
|
8700
8726
|
const type = getBuiltInObject(node, builtInClassName, [specializedEntryType]);
|
8701
|
-
return { type,
|
8727
|
+
return { type, isIncomplete };
|
8702
8728
|
}
|
8703
8729
|
// Attempts to infer the type of a list or set statement with no "expected type".
|
8704
8730
|
function getTypeOfListOrSetInferred(node, hasExpectedType) {
|
@@ -8750,7 +8776,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8750
8776
|
/* includeSubclasses */ undefined,
|
8751
8777
|
/* TupleTypeArguments */ undefined, isEmptyContainer))
|
8752
8778
|
: types_1.UnknownType.create();
|
8753
|
-
return { type,
|
8779
|
+
return { type, isIncomplete };
|
8754
8780
|
}
|
8755
8781
|
function inferTypeArgFromExpectedType(expectedType, entryTypes, isNarrowable) {
|
8756
8782
|
let targetTypeVar;
|
@@ -8812,7 +8838,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8812
8838
|
isIncomplete = true;
|
8813
8839
|
}
|
8814
8840
|
}
|
8815
|
-
return { type: (0, types_1.combineTypes)(typesToCombine),
|
8841
|
+
return { type: (0, types_1.combineTypes)(typesToCombine), isIncomplete };
|
8816
8842
|
}
|
8817
8843
|
function getTypeOfYield(node) {
|
8818
8844
|
let expectedYieldType;
|
@@ -8842,7 +8868,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8842
8868
|
isIncomplete = true;
|
8843
8869
|
}
|
8844
8870
|
}
|
8845
|
-
return { type: sentType || types_1.UnknownType.create(),
|
8871
|
+
return { type: sentType || types_1.UnknownType.create(), isIncomplete };
|
8846
8872
|
}
|
8847
8873
|
function getTypeOfYieldFrom(node) {
|
8848
8874
|
var _a;
|
@@ -8865,7 +8891,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8865
8891
|
returnedType = generatorTypeArgs.length >= 2 ? generatorTypeArgs[2] : types_1.UnknownType.create();
|
8866
8892
|
}
|
8867
8893
|
}
|
8868
|
-
return { type: returnedType || types_1.UnknownType.create()
|
8894
|
+
return { type: returnedType || types_1.UnknownType.create() };
|
8869
8895
|
}
|
8870
8896
|
function getTypeOfLambda(node, expectedType) {
|
8871
8897
|
let isIncomplete = false;
|
@@ -8984,7 +9010,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8984
9010
|
}
|
8985
9011
|
// Mark the function type as no longer being evaluated.
|
8986
9012
|
functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
|
8987
|
-
return { type: functionType,
|
9013
|
+
return { type: functionType, isIncomplete };
|
8988
9014
|
}
|
8989
9015
|
function getTypeOfListComprehension(node, expectedType) {
|
8990
9016
|
let isIncomplete = false;
|
@@ -9017,7 +9043,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9017
9043
|
: [elementType, types_1.NoneType.createInstance(), types_1.NoneType.createInstance()],
|
9018
9044
|
/* isTypeArgumentExplicit */ true));
|
9019
9045
|
}
|
9020
|
-
return { type,
|
9046
|
+
return { type, isIncomplete };
|
9021
9047
|
}
|
9022
9048
|
function reportPossibleUnknownAssignment(diagLevel, rule, target, type, errorNode, ignoreEmptyContainers) {
|
9023
9049
|
// Don't bother if the feature is disabled.
|
@@ -9115,20 +9141,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9115
9141
|
}
|
9116
9142
|
type = exprTypeResult.type;
|
9117
9143
|
}
|
9118
|
-
return { type,
|
9144
|
+
return { type, isIncomplete };
|
9119
9145
|
}
|
9120
9146
|
function getTypeOfSlice(node) {
|
9121
|
-
// Evaluate the expressions to report errors and record symbol
|
9122
|
-
if
|
9123
|
-
|
9124
|
-
|
9125
|
-
|
9126
|
-
|
9127
|
-
|
9128
|
-
|
9129
|
-
|
9147
|
+
// Evaluate the expressions to report errors and record symbol
|
9148
|
+
// references. We can skip this if we're executing speculatively.
|
9149
|
+
if (!speculativeTypeTracker.isSpeculative(node)) {
|
9150
|
+
if (node.startValue) {
|
9151
|
+
getTypeOfExpression(node.startValue);
|
9152
|
+
}
|
9153
|
+
if (node.endValue) {
|
9154
|
+
getTypeOfExpression(node.endValue);
|
9155
|
+
}
|
9156
|
+
if (node.stepValue) {
|
9157
|
+
getTypeOfExpression(node.stepValue);
|
9158
|
+
}
|
9130
9159
|
}
|
9131
|
-
return { type: getBuiltInObject(node, 'slice')
|
9160
|
+
return { type: getBuiltInObject(node, 'slice') };
|
9132
9161
|
}
|
9133
9162
|
// Verifies that a type argument's type is not disallowed.
|
9134
9163
|
function validateTypeArg(argResult, options) {
|
@@ -9733,8 +9762,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9733
9762
|
}
|
9734
9763
|
});
|
9735
9764
|
}
|
9736
|
-
returnType = (0, typeUtils_1.specializeTupleClass)(classType, tupleTypeArgTypes, typeArgs !== undefined
|
9737
|
-
/* stripLiterals */ false);
|
9765
|
+
returnType = (0, typeUtils_1.specializeTupleClass)(classType, tupleTypeArgTypes, typeArgs !== undefined);
|
9738
9766
|
}
|
9739
9767
|
else {
|
9740
9768
|
returnType = types_1.ClassType.cloneForSpecialization(classType, typeArgTypes, typeArgs !== undefined);
|
@@ -10622,6 +10650,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10622
10650
|
}
|
10623
10651
|
}
|
10624
10652
|
const effectiveMetaclass = computeEffectiveMetaclass(classType, node.name);
|
10653
|
+
// Clear the "partially constructed" flag.
|
10654
|
+
classType.details.flags &= ~131072 /* PartiallyEvaluated */;
|
10625
10655
|
// Now determine the decorated type of the class.
|
10626
10656
|
let decoratedType = classType;
|
10627
10657
|
let foundUnknown = false;
|
@@ -10658,8 +10688,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10658
10688
|
(0, dataClasses_1.applyDataClassDefaultBehaviors)(classType, dataClassBehaviors);
|
10659
10689
|
(0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, classType, initSubclassArgs);
|
10660
10690
|
}
|
10661
|
-
// Clear the "partially constructed" flag.
|
10662
|
-
classType.details.flags &= ~131072 /* PartiallyEvaluated */;
|
10663
10691
|
// Run any class hooks that depend on this class.
|
10664
10692
|
runClassTypeHooks(classType);
|
10665
10693
|
// Synthesize TypedDict methods.
|
@@ -10742,6 +10770,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10742
10770
|
if (!objectType || !(0, types_1.isClassInstance)(objectType)) {
|
10743
10771
|
return;
|
10744
10772
|
}
|
10773
|
+
// Presumptively mark the variance inference as complete. This
|
10774
|
+
// prevents potential recursion.
|
10775
|
+
classType.details.requiresVarianceInference = false;
|
10776
|
+
// Presumptively mark the computed variance to "in progress". We'll
|
10777
|
+
// replace this below once the variance has been inferred.
|
10778
|
+
classType.details.typeParameters.forEach((param) => {
|
10779
|
+
if (param.details.declaredVariance === 0 /* Auto */) {
|
10780
|
+
param.computedVariance = 1 /* Unknown */;
|
10781
|
+
}
|
10782
|
+
});
|
10745
10783
|
// Replace all of the type parameters with invariant TypeVars.
|
10746
10784
|
const updatedTypeParams = classType.details.typeParameters.map((typeParam) => types_1.TypeVarType.cloneAsInvariant(typeParam));
|
10747
10785
|
const updatedClassType = types_1.ClassType.cloneWithNewTypeParameters(classType, updatedTypeParams);
|
@@ -10775,15 +10813,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10775
10813
|
const isDestSubtypeOfSrc = assignClassToSelf(srcType, destType);
|
10776
10814
|
let inferredVariance;
|
10777
10815
|
if (isDestSubtypeOfSrc) {
|
10778
|
-
inferredVariance =
|
10816
|
+
inferredVariance = 3 /* Covariant */;
|
10779
10817
|
}
|
10780
10818
|
else {
|
10781
10819
|
const isSrcSubtypeOfDest = assignClassToSelf(destType, srcType);
|
10782
10820
|
if (isSrcSubtypeOfDest) {
|
10783
|
-
inferredVariance =
|
10821
|
+
inferredVariance = 4 /* Contravariant */;
|
10784
10822
|
}
|
10785
10823
|
else {
|
10786
|
-
inferredVariance =
|
10824
|
+
inferredVariance = 2 /* Invariant */;
|
10787
10825
|
}
|
10788
10826
|
}
|
10789
10827
|
// We assume here that we don't need to clone the type var object
|
@@ -10791,8 +10829,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10791
10829
|
// class scope.
|
10792
10830
|
classType.details.typeParameters[paramIndex].computedVariance = inferredVariance;
|
10793
10831
|
});
|
10794
|
-
// Note that variance inference is complete.
|
10795
|
-
classType.details.requiresVarianceInference = false;
|
10796
10832
|
}
|
10797
10833
|
function evaluateTypeParameterList(node) {
|
10798
10834
|
const paramTypes = [];
|
@@ -11513,8 +11549,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11513
11549
|
}
|
11514
11550
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
11515
11551
|
return types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type, isUnbounded: !(0, types_1.isVariadicTypeVar)(type) }],
|
11516
|
-
/* isTypeArgumentExplicit */ true
|
11517
|
-
/* stripLiterals */ true));
|
11552
|
+
/* isTypeArgumentExplicit */ true));
|
11518
11553
|
}
|
11519
11554
|
return types_1.UnknownType.create();
|
11520
11555
|
}
|
@@ -12070,7 +12105,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12070
12105
|
}
|
12071
12106
|
// For "async while", an implicit "await" is performed.
|
12072
12107
|
if (isAsync) {
|
12073
|
-
memberReturnType = getTypeOfAwaitable(memberReturnType, node);
|
12108
|
+
memberReturnType = getTypeOfAwaitable(memberReturnType, node.expression);
|
12074
12109
|
}
|
12075
12110
|
return memberReturnType;
|
12076
12111
|
}
|
@@ -12268,6 +12303,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12268
12303
|
assignTypeToNameNode(symbolNameNode, symbolType, /* isIncomplete */ false, /* ignoreEmptyContainers */ false);
|
12269
12304
|
writeTypeCache(node, symbolType, 0 /* None */, /* isIncomplete */ false);
|
12270
12305
|
}
|
12306
|
+
function evaluateTypesForTypeAnnotationNode(node) {
|
12307
|
+
var _a;
|
12308
|
+
// If this node is part of an assignment statement, use specialized
|
12309
|
+
// logic that performs bidirectional inference and assignment
|
12310
|
+
// type narrowing.
|
12311
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* Assignment */) {
|
12312
|
+
evaluateTypesForAssignmentStatement(node.parent);
|
12313
|
+
}
|
12314
|
+
else {
|
12315
|
+
const annotationType = getTypeOfAnnotation(node.typeAnnotation, {
|
12316
|
+
isVariableAnnotation: true,
|
12317
|
+
allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(node.valueExpression),
|
12318
|
+
allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(node.valueExpression),
|
12319
|
+
});
|
12320
|
+
writeTypeCache(node.valueExpression, annotationType, 0 /* None */, /* isIncomplete */ false);
|
12321
|
+
}
|
12322
|
+
}
|
12271
12323
|
function getAliasedSymbolTypeForName(node, name) {
|
12272
12324
|
const symbolWithScope = lookUpSymbolRecursive(node, name, /* honorCodeFlow */ true);
|
12273
12325
|
if (!symbolWithScope) {
|
@@ -12328,62 +12380,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12328
12380
|
// allows for bidirectional type evaluation.
|
12329
12381
|
function evaluateTypesForExpressionInContext(node) {
|
12330
12382
|
var _a, _b, _c, _d, _e;
|
12331
|
-
let lastContextualExpression = node;
|
12332
|
-
let curNode = node;
|
12333
|
-
function isContextual(node) {
|
12334
|
-
var _a, _b, _c, _d, _e;
|
12335
|
-
// Parameters are contextual only for lambdas.
|
12336
|
-
if (node.nodeType === 41 /* Parameter */ && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 30 /* Lambda */) {
|
12337
|
-
return true;
|
12338
|
-
}
|
12339
|
-
// Arguments are contextual only for call and index nodes.
|
12340
|
-
if (node.nodeType === 1 /* Argument */ &&
|
12341
|
-
(((_b = node.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 9 /* Call */ || ((_c = node.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 24 /* Index */)) {
|
12342
|
-
return true;
|
12343
|
-
}
|
12344
|
-
// All nodes within a type annotation need to be evaluated
|
12345
|
-
// contextually so we pass the "type expected" flag to
|
12346
|
-
// the evaluator.
|
12347
|
-
if (((_d = node.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 54 /* TypeAnnotation */) {
|
12348
|
-
return true;
|
12349
|
-
}
|
12350
|
-
if (((_e = node.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 41 /* Parameter */ &&
|
12351
|
-
(node === node.parent.typeAnnotation || node === node.parent.typeAnnotationComment)) {
|
12352
|
-
return true;
|
12353
|
-
}
|
12354
|
-
// The | operator is contextual in cases where it is used to describe a
|
12355
|
-
// union in type annotations.
|
12356
|
-
if (node.nodeType === 7 /* BinaryOperation */ && node.operator === 6 /* BitwiseOr */) {
|
12357
|
-
return true;
|
12358
|
-
}
|
12359
|
-
return (node.nodeType === 9 /* Call */ ||
|
12360
|
-
node.nodeType === 24 /* Index */ ||
|
12361
|
-
node.nodeType === 15 /* Dictionary */ ||
|
12362
|
-
node.nodeType === 27 /* FormatString */ ||
|
12363
|
-
node.nodeType === 31 /* List */ ||
|
12364
|
-
node.nodeType === 30 /* Lambda */ ||
|
12365
|
-
node.nodeType === 35 /* MemberAccess */ ||
|
12366
|
-
node.nodeType === 45 /* Set */ ||
|
12367
|
-
node.nodeType === 49 /* String */ ||
|
12368
|
-
node.nodeType === 48 /* StringList */ ||
|
12369
|
-
node.nodeType === 52 /* Tuple */ ||
|
12370
|
-
node.nodeType === 56 /* Unpack */ ||
|
12371
|
-
node.nodeType === 17 /* DictionaryKeyEntry */ ||
|
12372
|
-
node.nodeType === 16 /* DictionaryExpandEntry */ ||
|
12373
|
-
node.nodeType === 32 /* ListComprehension */ ||
|
12374
|
-
node.nodeType === 33 /* ListComprehensionFor */ ||
|
12375
|
-
node.nodeType === 34 /* ListComprehensionIf */ ||
|
12376
|
-
node.nodeType === 65 /* PatternSequence */ ||
|
12377
|
-
node.nodeType === 67 /* PatternLiteral */ ||
|
12378
|
-
node.nodeType === 68 /* PatternClass */ ||
|
12379
|
-
node.nodeType === 74 /* PatternClassArgument */ ||
|
12380
|
-
node.nodeType === 66 /* PatternAs */ ||
|
12381
|
-
node.nodeType === 69 /* PatternCapture */ ||
|
12382
|
-
node.nodeType === 70 /* PatternMapping */ ||
|
12383
|
-
node.nodeType === 73 /* PatternValue */ ||
|
12384
|
-
node.nodeType === 71 /* PatternMappingKeyEntry */ ||
|
12385
|
-
node.nodeType === 72 /* PatternMappingExpandEntry */);
|
12386
|
-
}
|
12387
12383
|
// Check for a couple of special cases where the node is a NameNode but
|
12388
12384
|
// is technically not part of an expression. We'll handle these here so
|
12389
12385
|
// callers don't need to include special-case logic.
|
@@ -12392,154 +12388,228 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12392
12388
|
getTypeOfFunction(node.parent);
|
12393
12389
|
return;
|
12394
12390
|
}
|
12395
|
-
|
12391
|
+
if (node.parent.nodeType === 10 /* Class */ && node.parent.name === node) {
|
12396
12392
|
getTypeOfClass(node.parent);
|
12397
12393
|
return;
|
12398
12394
|
}
|
12399
|
-
|
12395
|
+
if (node.parent.nodeType === 77 /* TypeAlias */ && node.parent.name === node) {
|
12400
12396
|
getTypeOfTypeAlias(node.parent);
|
12401
12397
|
return;
|
12402
12398
|
}
|
12403
|
-
|
12404
|
-
node.parent.nodeType === 39 /* Nonlocal */) {
|
12399
|
+
if (node.parent.nodeType === 29 /* Global */ || node.parent.nodeType === 39 /* Nonlocal */) {
|
12405
12400
|
// For global and nonlocal statements, allow forward references so
|
12406
12401
|
// we don't use code flow during symbol lookups.
|
12407
12402
|
getTypeOfExpression(node, 4 /* AllowForwardReferences */);
|
12408
12403
|
return;
|
12409
12404
|
}
|
12405
|
+
if (node.parent.nodeType === 37 /* ModuleName */) {
|
12406
|
+
// A name within a module name isn't an expression,
|
12407
|
+
// so there's nothing we can evaluate here.
|
12408
|
+
return;
|
12409
|
+
}
|
12410
12410
|
}
|
12411
|
-
//
|
12412
|
-
//
|
12413
|
-
|
12414
|
-
|
12415
|
-
|
12416
|
-
|
12411
|
+
// If the expression is part of a type annotation, we need to evaluate
|
12412
|
+
// it with special evaluation flags.
|
12413
|
+
const annotationNode = ParseTreeUtils.getParentAnnotationNode(node);
|
12414
|
+
if (annotationNode) {
|
12415
|
+
// Annotations need to be evaluated with specialized evaluation flags.
|
12416
|
+
const annotationParent = annotationNode.parent;
|
12417
|
+
(0, debug_1.assert)(annotationParent !== undefined);
|
12418
|
+
if (annotationParent.nodeType === 3 /* Assignment */) {
|
12419
|
+
if (annotationNode === annotationParent.typeAnnotationComment) {
|
12420
|
+
getTypeOfAnnotation(annotationNode, {
|
12421
|
+
isVariableAnnotation: true,
|
12422
|
+
allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(annotationParent.leftExpression),
|
12423
|
+
allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(annotationParent.leftExpression),
|
12424
|
+
});
|
12425
|
+
}
|
12426
|
+
else {
|
12427
|
+
evaluateTypesForAssignmentStatement(annotationParent);
|
12428
|
+
}
|
12429
|
+
return;
|
12417
12430
|
}
|
12418
|
-
if (
|
12419
|
-
|
12431
|
+
if (annotationParent.nodeType === 54 /* TypeAnnotation */) {
|
12432
|
+
evaluateTypesForTypeAnnotationNode(annotationParent);
|
12433
|
+
return;
|
12420
12434
|
}
|
12421
|
-
|
12422
|
-
|
12423
|
-
|
12424
|
-
|
12425
|
-
|
12426
|
-
getTypeOfAnnotation(lastContextualExpression, {
|
12427
|
-
isVariableAnnotation: true,
|
12428
|
-
allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(parent.leftExpression),
|
12429
|
-
allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(parent.leftExpression),
|
12435
|
+
if (annotationParent.nodeType === 28 /* Function */ &&
|
12436
|
+
annotationNode === annotationParent.returnTypeAnnotation) {
|
12437
|
+
getTypeOfAnnotation(annotationNode, {
|
12438
|
+
associateTypeVarsWithScope: true,
|
12439
|
+
disallowRecursiveTypeAlias: true,
|
12430
12440
|
});
|
12441
|
+
return;
|
12431
12442
|
}
|
12432
|
-
|
12433
|
-
evaluateTypesForAssignmentStatement(parent);
|
12434
|
-
}
|
12443
|
+
getTypeOfAnnotation(annotationNode);
|
12435
12444
|
return;
|
12436
12445
|
}
|
12437
|
-
|
12438
|
-
|
12439
|
-
|
12440
|
-
|
12441
|
-
|
12442
|
-
|
12443
|
-
if (parent.nodeType === 75 /* TypeParameter */ && lastContextualExpression === parent.name) {
|
12444
|
-
if (((_a = parent.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 76 /* TypeParameterList */ &&
|
12445
|
-
((_b = parent.parent.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 77 /* TypeAlias */) {
|
12446
|
-
getTypeOfTypeAlias(parent.parent.parent);
|
12446
|
+
// See if the expression is part of a pattern used in a case statement.
|
12447
|
+
const possibleCaseNode = ParseTreeUtils.getParentNodeOfType(node, 64 /* Case */);
|
12448
|
+
if (possibleCaseNode) {
|
12449
|
+
const caseNode = possibleCaseNode;
|
12450
|
+
if (ParseTreeUtils.isNodeContainedWithin(node, caseNode.pattern)) {
|
12451
|
+
evaluateTypesForCaseStatement(caseNode);
|
12447
12452
|
return;
|
12448
12453
|
}
|
12449
12454
|
}
|
12450
|
-
|
12451
|
-
|
12452
|
-
|
12453
|
-
|
12454
|
-
|
12455
|
-
|
12456
|
-
|
12457
|
-
|
12458
|
-
|
12459
|
-
|
12460
|
-
|
12461
|
-
|
12462
|
-
|
12463
|
-
|
12464
|
-
|
12455
|
+
// Scan up the parse tree until we find a node that doesn't
|
12456
|
+
// require any context to be evaluated.
|
12457
|
+
let nodeToEvaluate = node;
|
12458
|
+
let flags = 0 /* None */;
|
12459
|
+
while (true) {
|
12460
|
+
// If we're within an argument node in a call or index expression, skip
|
12461
|
+
// all of the nodes between because the entire argument expression
|
12462
|
+
// needs to be evaluated contextually.
|
12463
|
+
const argumentNode = ParseTreeUtils.getParentNodeOfType(nodeToEvaluate, 1 /* Argument */);
|
12464
|
+
if (argumentNode && argumentNode !== nodeToEvaluate) {
|
12465
|
+
(0, debug_1.assert)(argumentNode.parent !== undefined);
|
12466
|
+
if (argumentNode.parent.nodeType === 9 /* Call */ ||
|
12467
|
+
argumentNode.parent.nodeType === 24 /* Index */) {
|
12468
|
+
nodeToEvaluate = argumentNode.parent;
|
12469
|
+
continue;
|
12470
|
+
}
|
12465
12471
|
}
|
12466
|
-
|
12467
|
-
|
12472
|
+
let parent = nodeToEvaluate.parent;
|
12473
|
+
if (!parent) {
|
12474
|
+
break;
|
12468
12475
|
}
|
12469
|
-
|
12470
|
-
|
12471
|
-
|
12472
|
-
|
12473
|
-
|
12474
|
-
|
12476
|
+
// If this is the target of an assignment expression, evaluate the
|
12477
|
+
// assignment expression node instead.
|
12478
|
+
if (parent.nodeType === 4 /* AssignmentExpression */ && nodeToEvaluate === parent.name) {
|
12479
|
+
nodeToEvaluate = parent;
|
12480
|
+
continue;
|
12481
|
+
}
|
12482
|
+
// The left expression of a call or member access expression is not contextual.
|
12483
|
+
if (parent.nodeType === 9 /* Call */ || parent.nodeType === 35 /* MemberAccess */) {
|
12484
|
+
if (nodeToEvaluate === parent.leftExpression) {
|
12485
|
+
flags = 2 /* DoNotSpecialize */;
|
12486
|
+
break;
|
12487
|
+
}
|
12488
|
+
}
|
12489
|
+
else if (parent.nodeType === 24 /* Index */) {
|
12490
|
+
// The base expression of an index expression is not contextual.
|
12491
|
+
if (nodeToEvaluate === parent.baseExpression) {
|
12492
|
+
flags = 2 /* DoNotSpecialize */;
|
12493
|
+
break;
|
12494
|
+
}
|
12475
12495
|
}
|
12476
12496
|
else {
|
12477
|
-
|
12478
|
-
|
12479
|
-
|
12480
|
-
|
12481
|
-
|
12482
|
-
|
12497
|
+
// Check for expression types that are always contextual.
|
12498
|
+
if (nodeToEvaluate.nodeType !== 15 /* Dictionary */ &&
|
12499
|
+
nodeToEvaluate.nodeType !== 31 /* List */ &&
|
12500
|
+
nodeToEvaluate.nodeType !== 30 /* Lambda */ &&
|
12501
|
+
nodeToEvaluate.nodeType !== 45 /* Set */ &&
|
12502
|
+
nodeToEvaluate.nodeType !== 52 /* Tuple */ &&
|
12503
|
+
nodeToEvaluate.nodeType !== 56 /* Unpack */ &&
|
12504
|
+
nodeToEvaluate.nodeType !== 32 /* ListComprehension */) {
|
12505
|
+
break;
|
12506
|
+
}
|
12483
12507
|
}
|
12484
|
-
|
12485
|
-
|
12486
|
-
|
12487
|
-
|
12488
|
-
|
12489
|
-
|
12490
|
-
|
12491
|
-
|
12492
|
-
|
12493
|
-
|
12494
|
-
|
12495
|
-
|
12508
|
+
if (!(0, parseNodes_1.isExpressionNode)(parent)) {
|
12509
|
+
// If we've hit a non-expression node, we generally want to
|
12510
|
+
// stop. However, there are a few special "pass through"
|
12511
|
+
// node types that we can skip over to get to a known
|
12512
|
+
// expression node.
|
12513
|
+
if (parent.nodeType === 17 /* DictionaryKeyEntry */ ||
|
12514
|
+
parent.nodeType === 16 /* DictionaryExpandEntry */ ||
|
12515
|
+
parent.nodeType === 33 /* ListComprehensionFor */ ||
|
12516
|
+
parent.nodeType === 34 /* ListComprehensionIf */) {
|
12517
|
+
(0, debug_1.assert)(parent.parent !== undefined && (0, parseNodes_1.isExpressionNode)(parent.parent));
|
12518
|
+
parent = parent.parent;
|
12519
|
+
}
|
12520
|
+
else if (parent.nodeType === 41 /* Parameter */) {
|
12521
|
+
(0, debug_1.assert)(parent.parent !== undefined);
|
12522
|
+
// Parameters are contextual for lambdas.
|
12523
|
+
if (parent.parent.nodeType === 30 /* Lambda */) {
|
12524
|
+
parent = parent.parent;
|
12525
|
+
}
|
12526
|
+
else {
|
12527
|
+
break;
|
12528
|
+
}
|
12529
|
+
}
|
12530
|
+
else {
|
12531
|
+
break;
|
12532
|
+
}
|
12533
|
+
}
|
12534
|
+
nodeToEvaluate = parent;
|
12496
12535
|
}
|
12497
|
-
|
12498
|
-
|
12499
|
-
|
12500
|
-
|
12501
|
-
|
12502
|
-
|
12536
|
+
const parent = nodeToEvaluate.parent;
|
12537
|
+
(0, debug_1.assert)(parent !== undefined);
|
12538
|
+
switch (parent.nodeType) {
|
12539
|
+
case 14 /* Del */: {
|
12540
|
+
verifyDeleteExpression(nodeToEvaluate);
|
12541
|
+
return;
|
12542
|
+
}
|
12543
|
+
case 75 /* TypeParameter */: {
|
12544
|
+
// If this is the name node within a type parameter list, see if it's a type alias
|
12545
|
+
// definition. If so, we need to evaluate the type alias contextually.
|
12546
|
+
if (nodeToEvaluate === parent.name &&
|
12547
|
+
((_a = parent.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 76 /* TypeParameterList */ &&
|
12548
|
+
((_b = parent.parent.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 77 /* TypeAlias */) {
|
12549
|
+
getTypeOfTypeAlias(parent.parent.parent);
|
12550
|
+
return;
|
12551
|
+
}
|
12552
|
+
break;
|
12553
|
+
}
|
12554
|
+
case 77 /* TypeAlias */: {
|
12555
|
+
getTypeOfTypeAlias(parent);
|
12556
|
+
return;
|
12557
|
+
}
|
12558
|
+
case 13 /* Decorator */: {
|
12559
|
+
if (((_c = parent.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 10 /* Class */) {
|
12560
|
+
getTypeOfClass(parent.parent);
|
12561
|
+
}
|
12562
|
+
else if (((_d = parent.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 28 /* Function */) {
|
12563
|
+
getTypeOfFunction(parent.parent);
|
12564
|
+
}
|
12565
|
+
return;
|
12566
|
+
}
|
12567
|
+
case 41 /* Parameter */: {
|
12568
|
+
if (nodeToEvaluate !== parent.defaultValue) {
|
12569
|
+
evaluateTypeOfParameter(parent);
|
12570
|
+
return;
|
12571
|
+
}
|
12572
|
+
break;
|
12573
|
+
}
|
12574
|
+
case 1 /* Argument */: {
|
12575
|
+
if (nodeToEvaluate === parent.name) {
|
12576
|
+
// A name used to specify a named parameter in an argument isn't an
|
12577
|
+
// expression, so there's nothing we can evaluate here.
|
12578
|
+
return;
|
12579
|
+
}
|
12580
|
+
if (((_e = parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 10 /* Class */) {
|
12581
|
+
// A class argument must be evaluated in the context of the class declaration.
|
12582
|
+
getTypeOfClass(parent.parent);
|
12583
|
+
return;
|
12584
|
+
}
|
12585
|
+
break;
|
12586
|
+
}
|
12587
|
+
case 44 /* Return */: {
|
12588
|
+
// Return expressions must be evaluated in the context of the expected return type.
|
12589
|
+
if (parent.returnExpression) {
|
12590
|
+
const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(node);
|
12591
|
+
const declaredReturnType = enclosingFunctionNode
|
12592
|
+
? getFunctionDeclaredReturnType(enclosingFunctionNode)
|
12593
|
+
: undefined;
|
12594
|
+
getTypeOfExpression(parent.returnExpression, 0 /* None */, declaredReturnType);
|
12595
|
+
return;
|
12596
|
+
}
|
12597
|
+
break;
|
12598
|
+
}
|
12599
|
+
case 54 /* TypeAnnotation */: {
|
12600
|
+
evaluateTypesForTypeAnnotationNode(parent);
|
12601
|
+
return;
|
12602
|
+
}
|
12603
|
+
case 3 /* Assignment */: {
|
12604
|
+
evaluateTypesForAssignmentStatement(parent);
|
12503
12605
|
return;
|
12504
12606
|
}
|
12505
12607
|
}
|
12506
|
-
if (parent.nodeType === 37 /* ModuleName */) {
|
12507
|
-
// A name within a module name isn't an expression,
|
12508
|
-
// so there's nothing we can evaluate here.
|
12509
|
-
return;
|
12510
|
-
}
|
12511
|
-
if (parent.nodeType === 1 /* Argument */ && lastContextualExpression === parent.name) {
|
12512
|
-
// A name used to specify a named parameter in an argument isn't an
|
12513
|
-
// expression, so there's nothing we can evaluate here.
|
12514
|
-
return;
|
12515
|
-
}
|
12516
|
-
// A class argument must be evaluated in the context of the class declaration.
|
12517
|
-
if (parent.nodeType === 1 /* Argument */ && ((_e = parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 10 /* Class */) {
|
12518
|
-
getTypeOfClass(parent.parent);
|
12519
|
-
return;
|
12520
|
-
}
|
12521
|
-
if (parent.nodeType === 44 /* Return */ && parent.returnExpression) {
|
12522
|
-
const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(node);
|
12523
|
-
const declaredReturnType = enclosingFunctionNode
|
12524
|
-
? getFunctionDeclaredReturnType(enclosingFunctionNode)
|
12525
|
-
: undefined;
|
12526
|
-
getTypeOfExpression(parent.returnExpression, 0 /* None */, declaredReturnType);
|
12527
|
-
return;
|
12528
|
-
}
|
12529
|
-
// If the parent is an expression, we'll evaluate it to provide
|
12530
|
-
// the context for its child. If it's not, we'll evaluate the
|
12531
|
-
// child directly without any context.
|
12532
|
-
const nodeToEvaluate = (0, parseNodes_1.isExpressionNode)(parent) && parent.nodeType !== 0 /* Error */
|
12533
|
-
? parent
|
12534
|
-
: lastContextualExpression;
|
12535
12608
|
if (nodeToEvaluate.nodeType === 54 /* TypeAnnotation */) {
|
12536
|
-
|
12537
|
-
|
12538
|
-
else {
|
12539
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(nodeToEvaluate);
|
12540
|
-
const flags = fileInfo.isStubFile ? 4 /* AllowForwardReferences */ : 0 /* None */;
|
12541
|
-
getTypeOfExpression(nodeToEvaluate, flags);
|
12609
|
+
evaluateTypesForTypeAnnotationNode(nodeToEvaluate);
|
12610
|
+
return;
|
12542
12611
|
}
|
12612
|
+
getTypeOfExpression(nodeToEvaluate, flags);
|
12543
12613
|
}
|
12544
12614
|
function evaluateTypeOfParameter(node) {
|
12545
12615
|
// If this parameter has no name, we have nothing to do.
|
@@ -12699,7 +12769,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12699
12769
|
// doing additional work.
|
12700
12770
|
let subnodeType = readTypeCache(subnode, /* flags */ undefined);
|
12701
12771
|
if (subnodeType) {
|
12702
|
-
return {
|
12772
|
+
return { type: subnodeType };
|
12703
12773
|
}
|
12704
12774
|
const oldIncompleteCache = incompleteTypeCache;
|
12705
12775
|
try {
|
@@ -12712,11 +12782,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12712
12782
|
callback();
|
12713
12783
|
subnodeType = readTypeCache(subnode, /* flags */ undefined);
|
12714
12784
|
if (subnodeType) {
|
12715
|
-
return {
|
12785
|
+
return { type: subnodeType };
|
12716
12786
|
}
|
12717
12787
|
subnodeType = incompleteTypeCache.get(subnode.id);
|
12718
12788
|
if (subnodeType) {
|
12719
|
-
return {
|
12789
|
+
return { type: subnodeType, isIncomplete: true };
|
12720
12790
|
}
|
12721
12791
|
incompleteTypeCache = oldIncompleteCache;
|
12722
12792
|
}
|
@@ -13061,8 +13131,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13061
13131
|
return specializedClass;
|
13062
13132
|
}
|
13063
13133
|
function getTypeOfArgument(arg) {
|
13064
|
-
if (arg.
|
13065
|
-
return { type: arg.type };
|
13134
|
+
if (arg.typeResult) {
|
13135
|
+
return { type: arg.typeResult.type, isIncomplete: arg.typeResult.isIncomplete };
|
13066
13136
|
}
|
13067
13137
|
if (!arg.valueExpression) {
|
13068
13138
|
// We shouldn't ever get here, but just in case.
|
@@ -13077,8 +13147,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13077
13147
|
// and therefore follows the normal rules of types (e.g. they
|
13078
13148
|
// can be forward-declared in stubs, etc.).
|
13079
13149
|
function getTypeOfArgumentExpectingType(arg) {
|
13080
|
-
if (arg.
|
13081
|
-
return { type: arg.type };
|
13150
|
+
if (arg.typeResult) {
|
13151
|
+
return { type: arg.typeResult.type, isIncomplete: arg.typeResult.isIncomplete };
|
13082
13152
|
}
|
13083
13153
|
// If there was no defined type provided, there should always
|
13084
13154
|
// be a value expression from which we can retrieve the type.
|
@@ -13336,7 +13406,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13336
13406
|
else if (node.parent &&
|
13337
13407
|
node.parent.nodeType === 35 /* MemberAccess */ &&
|
13338
13408
|
node === node.parent.memberName) {
|
13339
|
-
let baseType =
|
13409
|
+
let baseType = getType(node.parent.leftExpression);
|
13340
13410
|
if (baseType) {
|
13341
13411
|
baseType = makeTopLevelTypeVarsConcrete(baseType);
|
13342
13412
|
const memberName = node.parent.memberName.value;
|
@@ -13411,7 +13481,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13411
13481
|
const argNode = node.parent;
|
13412
13482
|
const paramName = node.value;
|
13413
13483
|
if (argNode.parent && argNode.parent.nodeType === 9 /* Call */) {
|
13414
|
-
const baseType =
|
13484
|
+
const baseType = getType(argNode.parent.leftExpression);
|
13415
13485
|
if (baseType) {
|
13416
13486
|
if ((0, types_1.isFunction)(baseType) && baseType.details.declaration) {
|
13417
13487
|
const paramDecl = getDeclarationFromFunctionNamedParameter(baseType, paramName);
|
@@ -14252,9 +14322,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14252
14322
|
if (returnTypeInferenceContextStack.length >= maxReturnTypeInferenceStackSize) {
|
14253
14323
|
return undefined;
|
14254
14324
|
}
|
14325
|
+
const paramTypes = [];
|
14326
|
+
let isResultFromCache = false;
|
14255
14327
|
// Suppress diagnostics because we don't want to generate errors.
|
14256
14328
|
suppressDiagnostics(functionNode, () => {
|
14257
|
-
var _a;
|
14329
|
+
var _a, _b;
|
14258
14330
|
// Allocate a new temporary type cache for the context of just
|
14259
14331
|
// this function so we can analyze it separately without polluting
|
14260
14332
|
// the main type cache.
|
@@ -14297,13 +14369,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14297
14369
|
if (!paramType) {
|
14298
14370
|
paramType = types_1.UnknownType.create();
|
14299
14371
|
}
|
14372
|
+
paramTypes.push(paramType);
|
14300
14373
|
writeTypeCache(param.name, paramType, 0 /* None */, /* isIncomplete */ false);
|
14301
14374
|
}
|
14302
14375
|
});
|
14303
14376
|
// Don't bother trying to determine the contextual return
|
14304
14377
|
// type if none of the argument types are known.
|
14305
14378
|
if (!allArgTypesAreUnknown) {
|
14306
|
-
|
14379
|
+
// See if the return type is already cached. If so, skip the
|
14380
|
+
// inference step, which is potentially very expensive.
|
14381
|
+
const cacheEntry = (_a = functionType.functionType.callSiteReturnTypeCache) === null || _a === void 0 ? void 0 : _a.find((entry) => {
|
14382
|
+
return (entry.paramTypes.length === paramTypes.length &&
|
14383
|
+
entry.paramTypes.every((t, i) => (0, types_1.isTypeSame)(t, paramTypes[i])));
|
14384
|
+
});
|
14385
|
+
if (cacheEntry) {
|
14386
|
+
contextualReturnType = cacheEntry.returnType;
|
14387
|
+
isResultFromCache = true;
|
14388
|
+
}
|
14389
|
+
else {
|
14390
|
+
contextualReturnType = (_b = inferFunctionReturnType(functionNode, types_1.FunctionType.isAbstractMethod(type))) === null || _b === void 0 ? void 0 : _b.type;
|
14391
|
+
}
|
14307
14392
|
}
|
14308
14393
|
}
|
14309
14394
|
finally {
|
@@ -14317,6 +14402,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14317
14402
|
if (types_1.FunctionType.isWrapReturnTypeInAwait(type) && !(0, types_1.isNever)(contextualReturnType)) {
|
14318
14403
|
contextualReturnType = createAwaitableReturnType(functionNode, contextualReturnType, !!((_a = type.details.declaration) === null || _a === void 0 ? void 0 : _a.isGenerator));
|
14319
14404
|
}
|
14405
|
+
if (!isResultFromCache) {
|
14406
|
+
// Cache the resulting type.
|
14407
|
+
if (!functionType.functionType.callSiteReturnTypeCache) {
|
14408
|
+
functionType.functionType.callSiteReturnTypeCache = [];
|
14409
|
+
}
|
14410
|
+
if (functionType.functionType.callSiteReturnTypeCache.length >= maxCallSiteReturnTypeCacheSize) {
|
14411
|
+
functionType.functionType.callSiteReturnTypeCache =
|
14412
|
+
functionType.functionType.callSiteReturnTypeCache.slice(1);
|
14413
|
+
}
|
14414
|
+
functionType.functionType.callSiteReturnTypeCache.push({
|
14415
|
+
paramTypes,
|
14416
|
+
returnType: contextualReturnType,
|
14417
|
+
});
|
14418
|
+
}
|
14320
14419
|
return contextualReturnType;
|
14321
14420
|
}
|
14322
14421
|
return undefined;
|
@@ -14353,7 +14452,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14353
14452
|
// prior to specializing.
|
14354
14453
|
inferReturnTypeIfNecessary(typeResult.type);
|
14355
14454
|
return {
|
14356
|
-
node,
|
14357
14455
|
type: (0, typeUtils_1.partiallySpecializeType)(typeResult.type, member.classType, selfClass),
|
14358
14456
|
isIncomplete: !!typeResult.isIncomplete,
|
14359
14457
|
};
|
@@ -14536,7 +14634,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14536
14634
|
return { type: (0, typeUtils_1.stripLiteralValue)(typeArg.type), isUnbounded: false };
|
14537
14635
|
}),
|
14538
14636
|
/* isTypeArgumentExplicit */ true,
|
14539
|
-
/* stripLiterals */ true,
|
14540
14637
|
/* isUnpackedTuple */ true));
|
14541
14638
|
srcTypeArgs.splice(destVariadicIndex, 0, {
|
14542
14639
|
type: variadicTuple,
|
@@ -14702,7 +14799,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14702
14799
|
const destTypeArg = destArgIndex >= 0 ? destTypeArgs[destArgIndex] : types_1.UnknownType.create();
|
14703
14800
|
const destTypeParam = destArgIndex < destTypeParams.length ? destTypeParams[destArgIndex] : undefined;
|
14704
14801
|
const assignmentDiag = new diagnostic_1.DiagnosticAddendum();
|
14705
|
-
if (!destTypeParam || types_1.TypeVarType.getVariance(destTypeParam) ===
|
14802
|
+
if (!destTypeParam || types_1.TypeVarType.getVariance(destTypeParam) === 3 /* Covariant */) {
|
14706
14803
|
if (!assignType(destTypeArg, srcTypeArg, assignmentDiag, destTypeVarContext, srcTypeVarContext, flags | 128 /* RetainLiteralsForTypeVar */, recursionCount)) {
|
14707
14804
|
if (diag) {
|
14708
14805
|
if (destTypeParam) {
|
@@ -14719,7 +14816,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14719
14816
|
return false;
|
14720
14817
|
}
|
14721
14818
|
}
|
14722
|
-
else if (types_1.TypeVarType.getVariance(destTypeParam) ===
|
14819
|
+
else if (types_1.TypeVarType.getVariance(destTypeParam) === 4 /* Contravariant */) {
|
14723
14820
|
if (!assignType(srcTypeArg, destTypeArg, assignmentDiag, srcTypeVarContext, destTypeVarContext, (flags ^ 2 /* ReverseTypeVarMatching */) | 128 /* RetainLiteralsForTypeVar */, recursionCount)) {
|
14724
14821
|
if (diag) {
|
14725
14822
|
const childDiag = diag.createAddendum();
|
@@ -15200,11 +15297,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15200
15297
|
// Find first overloaded function that matches the parameters.
|
15201
15298
|
// We don't want to pollute the current typeVarContext, so we'll
|
15202
15299
|
// make a copy of the existing one if it's specified.
|
15203
|
-
const overloads = concreteSrcType
|
15300
|
+
const overloads = types_1.OverloadedFunctionType.getOverloads(concreteSrcType);
|
15204
15301
|
const overloadIndex = overloads.findIndex((overload) => {
|
15205
|
-
if (!types_1.FunctionType.isOverloaded(overload)) {
|
15206
|
-
return false;
|
15207
|
-
}
|
15208
15302
|
return assignType(destType, overload, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext === null || destTypeVarContext === void 0 ? void 0 : destTypeVarContext.clone(), srcTypeVarContext === null || srcTypeVarContext === void 0 ? void 0 : srcTypeVarContext.clone(), flags, recursionCount);
|
15209
15303
|
});
|
15210
15304
|
if (overloadIndex < 0) {
|
@@ -15228,10 +15322,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15228
15322
|
if ((0, types_1.isOverloadedFunction)(destType)) {
|
15229
15323
|
const overloadDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
|
15230
15324
|
// All overloads in the dest must be assignable.
|
15231
|
-
const isAssignable = destType.
|
15232
|
-
if (!types_1.FunctionType.isOverloaded(destOverload)) {
|
15233
|
-
return true;
|
15234
|
-
}
|
15325
|
+
const isAssignable = types_1.OverloadedFunctionType.getOverloads(destType).every((destOverload) => {
|
15235
15326
|
if (destTypeVarContext) {
|
15236
15327
|
destTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(destOverload));
|
15237
15328
|
}
|
@@ -15363,6 +15454,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15363
15454
|
}
|
15364
15455
|
// For union sources, all of the types need to be assignable to the dest.
|
15365
15456
|
let isIncompatible = false;
|
15457
|
+
// Sort the subtypes so we have a deterministic order for unions.
|
15366
15458
|
(0, typeUtils_1.doForEachSubtype)(srcType, (subtype, subtypeIndex) => {
|
15367
15459
|
if (isIncompatible) {
|
15368
15460
|
return;
|
@@ -15387,7 +15479,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15387
15479
|
isIncompatible = true;
|
15388
15480
|
}
|
15389
15481
|
}
|
15390
|
-
}
|
15482
|
+
},
|
15483
|
+
/* sortSubtypes */ true);
|
15391
15484
|
if (isIncompatible) {
|
15392
15485
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
|
15393
15486
|
sourceType: printType(srcType),
|
@@ -15402,6 +15495,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15402
15495
|
// matches for types like `tuple[Any]` and `tuple[int]` from being considered
|
15403
15496
|
// proper subtypes of each other.
|
15404
15497
|
function isProperSubtype(destType, srcType, recursionCount) {
|
15498
|
+
// Shortcut the check if either type is Any or Unknown.
|
15499
|
+
if ((0, types_1.isAnyOrUnknown)(destType) || (0, types_1.isAnyOrUnknown)(srcType)) {
|
15500
|
+
return true;
|
15501
|
+
}
|
15502
|
+
// Shortcut the check if either type is a class whose hierarchy contains an unknown type.
|
15503
|
+
if ((0, types_1.isClass)(destType) && destType.details.mro.some((mro) => (0, types_1.isAnyOrUnknown)(mro))) {
|
15504
|
+
return true;
|
15505
|
+
}
|
15506
|
+
if ((0, types_1.isClass)(srcType) && srcType.details.mro.some((mro) => (0, types_1.isAnyOrUnknown)(mro))) {
|
15507
|
+
return true;
|
15508
|
+
}
|
15405
15509
|
return (assignType(destType, srcType,
|
15406
15510
|
/* diag */ undefined,
|
15407
15511
|
/* destTypeVarContext */ undefined,
|
@@ -15453,54 +15557,69 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15453
15557
|
// For union destinations, we just need to match one of the types.
|
15454
15558
|
const diagAddendum = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
|
15455
15559
|
let foundMatch = false;
|
15456
|
-
//
|
15457
|
-
//
|
15458
|
-
|
15459
|
-
|
15460
|
-
|
15461
|
-
|
15560
|
+
// Does the union contain any type variables that need to be solved?
|
15561
|
+
// If so, we need to use a slower path.
|
15562
|
+
if (!(0, typeUtils_1.requiresSpecialization)(destType)) {
|
15563
|
+
for (const subtype of destType.subtypes) {
|
15564
|
+
if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(),
|
15565
|
+
/* destTypeVarContextClone */ undefined,
|
15566
|
+
/* srcTypeVarContextClone */ undefined, flags, recursionCount)) {
|
15567
|
+
foundMatch = true;
|
15568
|
+
break;
|
15569
|
+
}
|
15570
|
+
}
|
15462
15571
|
}
|
15463
15572
|
else {
|
15464
|
-
|
15465
|
-
|
15466
|
-
|
15467
|
-
//
|
15468
|
-
|
15469
|
-
|
15470
|
-
(0, typeUtils_1.isLiteralType)(srcType) &&
|
15471
|
-
types_1.UnionType.containsType(destType, srcType, recursionCount)) {
|
15472
|
-
return true;
|
15573
|
+
// Run through all subtypes in the union. Don't stop at the first
|
15574
|
+
// match we find because we may need to match TypeVars in other
|
15575
|
+
// subtypes. We special-case "None" so we can handle Optional[T]
|
15576
|
+
// without matching the None to the type var.
|
15577
|
+
if ((0, types_1.isNoneInstance)(srcType) && (0, typeUtils_1.isOptionalType)(destType)) {
|
15578
|
+
foundMatch = true;
|
15473
15579
|
}
|
15474
|
-
|
15475
|
-
|
15476
|
-
|
15477
|
-
|
15478
|
-
|
15479
|
-
|
15480
|
-
|
15481
|
-
|
15482
|
-
|
15483
|
-
|
15484
|
-
|
15485
|
-
|
15486
|
-
|
15487
|
-
|
15488
|
-
|
15489
|
-
|
15490
|
-
|
15491
|
-
|
15492
|
-
|
15493
|
-
|
15580
|
+
else {
|
15581
|
+
let bestDestTypeVarContext;
|
15582
|
+
let bestSrcTypeVarContext;
|
15583
|
+
let bestTypeVarContextScore;
|
15584
|
+
// If the srcType is a literal, try to use the fast-path lookup
|
15585
|
+
// in case the destType is a union with hundreds of literals.
|
15586
|
+
if ((0, types_1.isClassInstance)(srcType) &&
|
15587
|
+
(0, typeUtils_1.isLiteralType)(srcType) &&
|
15588
|
+
types_1.UnionType.containsType(destType, srcType, recursionCount)) {
|
15589
|
+
return true;
|
15590
|
+
}
|
15591
|
+
(0, typeUtils_1.doForEachSubtype)(destType, (subtype) => {
|
15592
|
+
// Make a temporary clone of the typeVarContext. We don't want to modify
|
15593
|
+
// the original typeVarContext until we find the "optimal" typeVar mapping.
|
15594
|
+
const destTypeVarContextClone = destTypeVarContext === null || destTypeVarContext === void 0 ? void 0 : destTypeVarContext.clone();
|
15595
|
+
const srcTypeVarContextClone = srcTypeVarContext === null || srcTypeVarContext === void 0 ? void 0 : srcTypeVarContext.clone();
|
15596
|
+
if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(), destTypeVarContextClone, srcTypeVarContextClone, flags, recursionCount)) {
|
15597
|
+
foundMatch = true;
|
15598
|
+
if (destTypeVarContextClone) {
|
15599
|
+
// Ask the typeVarContext to compute a "score" for the current
|
15600
|
+
// contents of the table.
|
15601
|
+
let typeVarContextScore = destTypeVarContextClone.getScore();
|
15602
|
+
// If the type matches exactly, prefer it over other types.
|
15603
|
+
if ((0, types_1.isTypeSame)(subtype, (0, typeUtils_1.stripLiteralValue)(srcType))) {
|
15604
|
+
typeVarContextScore = Number.POSITIVE_INFINITY;
|
15605
|
+
}
|
15606
|
+
if (bestTypeVarContextScore === undefined ||
|
15607
|
+
bestTypeVarContextScore <= typeVarContextScore) {
|
15608
|
+
// We found a typeVar mapping with a higher score than before.
|
15609
|
+
bestTypeVarContextScore = typeVarContextScore;
|
15610
|
+
bestDestTypeVarContext = destTypeVarContextClone;
|
15611
|
+
bestSrcTypeVarContext = srcTypeVarContextClone;
|
15612
|
+
}
|
15494
15613
|
}
|
15495
15614
|
}
|
15615
|
+
});
|
15616
|
+
// If we found a winning type var mapping, copy it back to typeVarContext.
|
15617
|
+
if (destTypeVarContext && bestDestTypeVarContext) {
|
15618
|
+
destTypeVarContext.copyFromClone(bestDestTypeVarContext);
|
15619
|
+
}
|
15620
|
+
if (srcTypeVarContext && bestSrcTypeVarContext) {
|
15621
|
+
srcTypeVarContext.copyFromClone(bestSrcTypeVarContext);
|
15496
15622
|
}
|
15497
|
-
});
|
15498
|
-
// If we found a winning type var mapping, copy it back to typeVarContext.
|
15499
|
-
if (destTypeVarContext && bestDestTypeVarContext) {
|
15500
|
-
destTypeVarContext.copyFromClone(bestDestTypeVarContext);
|
15501
|
-
}
|
15502
|
-
if (srcTypeVarContext && bestSrcTypeVarContext) {
|
15503
|
-
srcTypeVarContext.copyFromClone(bestSrcTypeVarContext);
|
15504
15623
|
}
|
15505
15624
|
}
|
15506
15625
|
// If the source is a constrained TypeVar, see if we can assign all of the
|
@@ -15788,7 +15907,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15788
15907
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
15789
15908
|
srcPositionalsType = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, srcTupleTypes,
|
15790
15909
|
/* isTypeArgumentExplicit */ true,
|
15791
|
-
/* stripLiterals */ true,
|
15792
15910
|
/* isUnpackedTuple */ true));
|
15793
15911
|
}
|
15794
15912
|
else {
|
@@ -15974,13 +16092,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15974
16092
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
15975
16093
|
if (!(0, types_1.isUnpacked)(destArgsType)) {
|
15976
16094
|
destArgsType = types_1.ClassType.cloneForUnpacked(types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type: destArgsType, isUnbounded: true }],
|
15977
|
-
/* isTypeArgumentExplicit */ true
|
15978
|
-
/* stripLiterals */ true)));
|
16095
|
+
/* isTypeArgumentExplicit */ true)));
|
15979
16096
|
}
|
15980
16097
|
if (!(0, types_1.isUnpacked)(srcArgsType)) {
|
15981
16098
|
srcArgsType = types_1.ClassType.cloneForUnpacked(types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type: srcArgsType, isUnbounded: true }],
|
15982
|
-
/* isTypeArgumentExplicit */ true
|
15983
|
-
/* stripLiterals */ true)));
|
16099
|
+
/* isTypeArgumentExplicit */ true)));
|
15984
16100
|
}
|
15985
16101
|
}
|
15986
16102
|
if (!assignFunctionParameter(destArgsType, srcArgsType, destParamDetails.params[destParamDetails.argsIndex].index, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
@@ -16351,22 +16467,41 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16351
16467
|
return narrowedType;
|
16352
16468
|
}
|
16353
16469
|
function validateOverrideMethod(baseMethod, overrideMethod, diag, enforceParamNames = true) {
|
16354
|
-
var _a, _b;
|
16355
|
-
// If we're overriding an overloaded method, uses the implementation.
|
16356
|
-
if ((0, types_1.isOverloadedFunction)(baseMethod)) {
|
16357
|
-
const implementation = baseMethod.overloads.find((overload) => !types_1.FunctionType.isOverloaded(overload));
|
16358
|
-
// If the overloaded method doesn't have an implementation, skip the check.
|
16359
|
-
if (!implementation) {
|
16360
|
-
return true;
|
16361
|
-
}
|
16362
|
-
baseMethod = implementation;
|
16363
|
-
}
|
16364
16470
|
// If we're overriding a non-method with a method, report it as an error.
|
16365
16471
|
// This occurs when a non-property overrides a property.
|
16366
|
-
if (!(0, types_1.isFunction)(baseMethod)) {
|
16472
|
+
if (!(0, types_1.isFunction)(baseMethod) && !(0, types_1.isOverloadedFunction)(baseMethod)) {
|
16367
16473
|
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideType().format({ type: printType(baseMethod) }));
|
16368
16474
|
return false;
|
16369
16475
|
}
|
16476
|
+
if ((0, types_1.isFunction)(baseMethod)) {
|
16477
|
+
// Handle the easy case - a simple function overriding another simple function.
|
16478
|
+
if ((0, types_1.isFunction)(overrideMethod)) {
|
16479
|
+
return validateOverrideMethodInternal(baseMethod, overrideMethod, diag, enforceParamNames);
|
16480
|
+
}
|
16481
|
+
// For an overload overriding a base method, at least one overload
|
16482
|
+
// must be compatible with the base method.
|
16483
|
+
if (types_1.OverloadedFunctionType.getOverloads(overrideMethod).some((overrideOverload) => {
|
16484
|
+
return validateOverrideMethodInternal(baseMethod, overrideOverload,
|
16485
|
+
/* diag */ undefined, enforceParamNames);
|
16486
|
+
})) {
|
16487
|
+
return true;
|
16488
|
+
}
|
16489
|
+
// Or the implementation must be compatible.
|
16490
|
+
const overrideImplementation = types_1.OverloadedFunctionType.getImplementation(overrideMethod);
|
16491
|
+
if (overrideImplementation) {
|
16492
|
+
if (validateOverrideMethodInternal(baseMethod, overrideImplementation,
|
16493
|
+
/* diag */ undefined, enforceParamNames)) {
|
16494
|
+
return true;
|
16495
|
+
}
|
16496
|
+
}
|
16497
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNoOverloadMatches());
|
16498
|
+
return false;
|
16499
|
+
}
|
16500
|
+
// TODO - need to implement the case where the base method is overloaded
|
16501
|
+
return true;
|
16502
|
+
}
|
16503
|
+
function validateOverrideMethodInternal(baseMethod, overrideMethod, diag, enforceParamNames) {
|
16504
|
+
var _a, _b;
|
16370
16505
|
const baseParamDetails = (0, typeUtils_1.getParameterListDetails)(baseMethod);
|
16371
16506
|
const overrideParamDetails = (0, typeUtils_1.getParameterListDetails)(overrideMethod);
|
16372
16507
|
let canOverride = true;
|
@@ -16374,19 +16509,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16374
16509
|
// an incompatible type.
|
16375
16510
|
if (types_1.FunctionType.isStaticMethod(baseMethod)) {
|
16376
16511
|
if (!types_1.FunctionType.isStaticMethod(overrideMethod)) {
|
16377
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotStaticMethod());
|
16512
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotStaticMethod());
|
16378
16513
|
canOverride = false;
|
16379
16514
|
}
|
16380
16515
|
}
|
16381
16516
|
else if (types_1.FunctionType.isClassMethod(baseMethod)) {
|
16382
16517
|
if (!types_1.FunctionType.isClassMethod(overrideMethod)) {
|
16383
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotClassMethod());
|
16518
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotClassMethod());
|
16384
16519
|
canOverride = false;
|
16385
16520
|
}
|
16386
16521
|
}
|
16387
16522
|
if (types_1.FunctionType.isInstanceMethod(baseMethod)) {
|
16388
16523
|
if (!types_1.FunctionType.isInstanceMethod(overrideMethod)) {
|
16389
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotInstanceMethod());
|
16524
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotInstanceMethod());
|
16390
16525
|
canOverride = false;
|
16391
16526
|
}
|
16392
16527
|
}
|
@@ -16411,7 +16546,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16411
16546
|
}
|
16412
16547
|
}
|
16413
16548
|
if (foundParamCountMismatch) {
|
16414
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overridePositionalParamCount().format({
|
16549
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overridePositionalParamCount().format({
|
16415
16550
|
baseCount: baseParamDetails.params.length,
|
16416
16551
|
overrideCount: overrideParamDetails.params.length,
|
16417
16552
|
}));
|
@@ -16438,13 +16573,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16438
16573
|
if (overrideParam.category === 0 /* Simple */) {
|
16439
16574
|
if (enforceParamNames) {
|
16440
16575
|
if (overrideParamDetails.params[i].source === typeUtils_1.ParameterSource.PositionOnly) {
|
16441
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
|
16576
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
|
16442
16577
|
index: i + 1,
|
16443
16578
|
baseName: baseParam.name || '*',
|
16444
16579
|
}));
|
16445
16580
|
}
|
16446
16581
|
else {
|
16447
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamName().format({
|
16582
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamName().format({
|
16448
16583
|
index: i + 1,
|
16449
16584
|
baseName: baseParam.name || '*',
|
16450
16585
|
overrideName: overrideParam.name || '*',
|
@@ -16456,7 +16591,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16456
16591
|
}
|
16457
16592
|
else if (i < overrideParamDetails.positionOnlyParamCount &&
|
16458
16593
|
i >= baseParamDetails.positionOnlyParamCount) {
|
16459
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
|
16594
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
|
16460
16595
|
index: i + 1,
|
16461
16596
|
baseName: baseParam.name || '*',
|
16462
16597
|
}));
|
@@ -16469,8 +16604,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16469
16604
|
const overrideIsSynthesizedTypeVar = (0, types_1.isTypeVar)(overrideParamType) && overrideParamType.details.isSynthesized;
|
16470
16605
|
if (!baseIsSynthesizedTypeVar && !overrideIsSynthesizedTypeVar) {
|
16471
16606
|
if (baseParam.category !== overrideParam.category ||
|
16472
|
-
!assignType(overrideParamType, baseParamType, diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), 8 /* SkipSolveTypeVars */)) {
|
16473
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamType().format({
|
16607
|
+
!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), 8 /* SkipSolveTypeVars */)) {
|
16608
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamType().format({
|
16474
16609
|
index: i + 1,
|
16475
16610
|
baseType: printType(baseParamType),
|
16476
16611
|
overrideType: printType(overrideParamType),
|
@@ -16479,7 +16614,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16479
16614
|
}
|
16480
16615
|
}
|
16481
16616
|
if (baseParamDetails.params[i].param.hasDefault && !overrideParamDetails.params[i].param.hasDefault) {
|
16482
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNoDefault().format({
|
16617
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNoDefault().format({
|
16483
16618
|
index: i + 1,
|
16484
16619
|
}));
|
16485
16620
|
canOverride = false;
|
@@ -16489,7 +16624,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16489
16624
|
// Check for a *args match.
|
16490
16625
|
if (baseParamDetails.argsIndex !== undefined) {
|
16491
16626
|
if (overrideParamDetails.argsIndex === undefined) {
|
16492
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameMissing().format({
|
16627
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameMissing().format({
|
16493
16628
|
name: (_a = baseParamDetails.params[baseParamDetails.argsIndex].param.name) !== null && _a !== void 0 ? _a : '?',
|
16494
16629
|
}));
|
16495
16630
|
canOverride = false;
|
@@ -16497,9 +16632,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16497
16632
|
else {
|
16498
16633
|
const overrideParamType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
|
16499
16634
|
const baseParamType = baseParamDetails.params[baseParamDetails.argsIndex].type;
|
16500
|
-
if (!assignType(overrideParamType, baseParamType, diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
|
16635
|
+
if (!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
|
16501
16636
|
/* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
|
16502
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
|
16637
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
|
16503
16638
|
name: (_b = overrideParamDetails.params[overrideParamDetails.argsIndex].param.name) !== null && _b !== void 0 ? _b : '?',
|
16504
16639
|
baseType: printType(baseParamType),
|
16505
16640
|
overrideType: printType(overrideParamType),
|
@@ -16517,7 +16652,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16517
16652
|
var _a, _b, _c;
|
16518
16653
|
const overrideParamInfo = overrideWkOnlyParams.find((pi) => paramInfo.param.name === pi.param.name);
|
16519
16654
|
if (!overrideParamInfo && overrideParamDetails.kwargsIndex === undefined) {
|
16520
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameMissing().format({
|
16655
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameMissing().format({
|
16521
16656
|
name: (_a = paramInfo.param.name) !== null && _a !== void 0 ? _a : '?',
|
16522
16657
|
}));
|
16523
16658
|
canOverride = false;
|
@@ -16527,9 +16662,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16527
16662
|
if (!targetParamType) {
|
16528
16663
|
targetParamType = overrideParamDetails.params[overrideParamDetails.kwargsIndex].type;
|
16529
16664
|
}
|
16530
|
-
if (!assignType(targetParamType, paramInfo.type, diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
|
16665
|
+
if (!assignType(targetParamType, paramInfo.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
|
16531
16666
|
/* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
|
16532
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
|
16667
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
|
16533
16668
|
name: (_b = paramInfo.param.name) !== null && _b !== void 0 ? _b : '?',
|
16534
16669
|
baseType: printType(paramInfo.type),
|
16535
16670
|
overrideType: printType(targetParamType),
|
@@ -16538,7 +16673,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16538
16673
|
}
|
16539
16674
|
if (overrideParamInfo) {
|
16540
16675
|
if (paramInfo.param.hasDefault && !overrideParamInfo.param.hasDefault) {
|
16541
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordNoDefault().format({
|
16676
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordNoDefault().format({
|
16542
16677
|
name: (_c = overrideParamInfo.param.name) !== null && _c !== void 0 ? _c : '?',
|
16543
16678
|
}));
|
16544
16679
|
canOverride = false;
|
@@ -16554,7 +16689,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16554
16689
|
if (!baseParamInfo) {
|
16555
16690
|
if (baseParamDetails.kwargsIndex === undefined) {
|
16556
16691
|
if (!paramInfo.param.hasDefault) {
|
16557
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameExtra().format({
|
16692
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameExtra().format({
|
16558
16693
|
name: (_a = paramInfo.param.name) !== null && _a !== void 0 ? _a : '?',
|
16559
16694
|
}));
|
16560
16695
|
canOverride = false;
|
@@ -16565,9 +16700,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16565
16700
|
// Now check the return type.
|
16566
16701
|
const baseReturnType = getFunctionEffectiveReturnType(baseMethod);
|
16567
16702
|
const overrideReturnType = getFunctionEffectiveReturnType(overrideMethod);
|
16568
|
-
if (!assignType(baseReturnType, overrideReturnType, diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)),
|
16703
|
+
if (!assignType(baseReturnType, overrideReturnType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)),
|
16569
16704
|
/* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
|
16570
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideReturnType().format({
|
16705
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideReturnType().format({
|
16571
16706
|
baseType: printType(baseReturnType),
|
16572
16707
|
overrideType: printType(overrideReturnType),
|
16573
16708
|
}));
|
@@ -16982,6 +17117,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16982
17117
|
addWarning,
|
16983
17118
|
addInformation,
|
16984
17119
|
addUnusedCode,
|
17120
|
+
addUnreachableCode,
|
16985
17121
|
addDeprecated,
|
16986
17122
|
addDiagnostic,
|
16987
17123
|
addDiagnosticForTextRange,
|