@zzzen/pyright-internal 1.2.0-dev.20220710 → 1.2.0-dev.20220731
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/analysis.js +1 -1
- package/dist/analyzer/analysis.js.map +1 -1
- package/dist/analyzer/binder.js +14 -0
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -0
- package/dist/analyzer/checker.js +100 -46
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +0 -1
- package/dist/analyzer/codeFlowEngine.js +190 -196
- 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 +5 -3
- 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/enums.d.ts +13 -0
- package/dist/analyzer/enums.js +207 -0
- package/dist/analyzer/enums.js.map +1 -0
- package/dist/analyzer/importResolver.js +5 -4
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.d.ts +3 -1
- package/dist/analyzer/importStatementUtils.js +96 -19
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +5 -0
- package/dist/analyzer/parseTreeUtils.js +111 -3
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +3 -3
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/properties.js +1 -1
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/service.d.ts +1 -1
- package/dist/analyzer/service.js +37 -37
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.js +40 -9
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +1 -1
- package/dist/analyzer/typeEvaluator.js +733 -709
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +18 -16
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeEvaluatorWithTracker.js +9 -7
- package/dist/analyzer/typeEvaluatorWithTracker.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +2 -0
- package/dist/analyzer/typeGuards.js +43 -15
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +7 -1
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +4 -3
- package/dist/analyzer/typeUtils.js +99 -38
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +1 -0
- package/dist/analyzer/typedDicts.js +24 -3
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +9 -0
- package/dist/analyzer/types.js +99 -0
- 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/commands/commandResult.js +1 -1
- package/dist/commands/commandResult.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/common/workspaceEditUtils.d.ts +1 -0
- package/dist/common/workspaceEditUtils.js +10 -6
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +17 -16
- package/dist/languageServerBase.js +73 -59
- 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 +75 -5
- package/dist/languageService/completionProvider.js.map +1 -1
- 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/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.js +9 -1
- package/dist/parser/parser.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 +2 -0
- 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 +59 -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/hover.init.fourslash.js +2 -2
- package/dist/tests/fourslash/hover.init.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/fourSlashParser.js +5 -1
- package/dist/tests/harness/fourslash/fourSlashParser.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 +18 -9
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- 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/testState.test.js +1 -1
- package/dist/tests/testState.test.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 +9 -6
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +7 -7
- 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 +16 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/workspaceMap.d.ts +1 -0
- package/dist/workspaceMap.js +11 -1
- package/dist/workspaceMap.js.map +1 -1
- package/package.json +3 -3
@@ -55,6 +55,7 @@ const constraintSolver_1 = require("./constraintSolver");
|
|
55
55
|
const constructorTransform_1 = require("./constructorTransform");
|
56
56
|
const dataClasses_1 = require("./dataClasses");
|
57
57
|
const declarationUtils_1 = require("./declarationUtils");
|
58
|
+
const enums_1 = require("./enums");
|
58
59
|
const functionTransform_1 = require("./functionTransform");
|
59
60
|
const namedTuples_1 = require("./namedTuples");
|
60
61
|
const ParseTreeUtils = __importStar(require("./parseTreeUtils"));
|
@@ -106,33 +107,31 @@ var MemberAccessFlags;
|
|
106
107
|
MemberAccessFlags[MemberAccessFlags["SkipTypeBaseClass"] = 256] = "SkipTypeBaseClass";
|
107
108
|
})(MemberAccessFlags || (MemberAccessFlags = {}));
|
108
109
|
// Maps binary operators to the magic methods that implement them.
|
109
|
-
// The boolean indicates whether the operators "chain" together.
|
110
110
|
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__'
|
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__'],
|
130
130
|
};
|
131
|
-
//
|
132
|
-
// the operators "chain" together with other comparison operators.
|
131
|
+
// Map of operators that always return a bool result.
|
133
132
|
const booleanOperatorMap = {
|
134
|
-
[36 /* And */]:
|
135
|
-
[37 /* Or */]:
|
133
|
+
[36 /* And */]: true,
|
134
|
+
[37 /* Or */]: true,
|
136
135
|
[39 /* Is */]: true,
|
137
136
|
[40 /* IsNot */]: true,
|
138
137
|
[41 /* In */]: true,
|
@@ -182,6 +181,9 @@ const maxReturnTypeInferenceArgumentCount = 6;
|
|
182
181
|
// when its parameters are unannotated? We want to keep this
|
183
182
|
// pretty low because this can be very costly.
|
184
183
|
const maxReturnTypeInferenceCodeFlowComplexity = 8;
|
184
|
+
// What is the max number of return types cached per function
|
185
|
+
// when using call-site inference?
|
186
|
+
const maxCallSiteReturnTypeCacheSize = 8;
|
185
187
|
// How many entries in a list, set, or dict should we examine
|
186
188
|
// when inferring the type? We need to cut it off at some point
|
187
189
|
// to avoid excessive computation.
|
@@ -209,7 +211,7 @@ const maxLiteralMathSubtypeCount = 64;
|
|
209
211
|
// off code flow analysis at some point for code flow graphs that are too
|
210
212
|
// complex. Otherwise we risk overflowing the stack or incurring extremely
|
211
213
|
// long analysis times. This number has been tuned empirically.
|
212
|
-
exports.maxCodeComplexity =
|
214
|
+
exports.maxCodeComplexity = 768;
|
213
215
|
function createTypeEvaluator(importLookup, evaluatorOptions) {
|
214
216
|
const symbolResolutionStack = [];
|
215
217
|
const typeCacheFlags = new Map();
|
@@ -231,6 +233,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
231
233
|
let functionObj;
|
232
234
|
let tupleClassType;
|
233
235
|
let boolClassType;
|
236
|
+
let intClassType;
|
234
237
|
let strClassType;
|
235
238
|
let dictClassType;
|
236
239
|
let typedDictClassType;
|
@@ -279,6 +282,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
279
282
|
return cachedType !== undefined;
|
280
283
|
}
|
281
284
|
function readTypeCache(node, flags) {
|
285
|
+
var _a, _b;
|
282
286
|
let cachedType;
|
283
287
|
// Should we use a temporary cache associated with a contextual
|
284
288
|
// analysis of a function, contextualized based on call-site argument types?
|
@@ -295,8 +299,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
295
299
|
if (flags !== undefined) {
|
296
300
|
const expectedFlags = typeCacheFlags.get(node.id);
|
297
301
|
if (expectedFlags !== undefined && flags !== expectedFlags) {
|
298
|
-
|
299
|
-
|
302
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
303
|
+
const position = (0, positionUtils_1.convertOffsetToPosition)(node.start, fileInfo.lines);
|
304
|
+
const message = `Type cache flag mismatch for node type ${node.nodeType} ` +
|
305
|
+
`(parent ${(_b = (_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== null && _b !== void 0 ? _b : 'none'}): ` +
|
306
|
+
`cached flags = ${expectedFlags}, access flags = ${flags}, ` +
|
307
|
+
`file = {${fileInfo.filePath} [${position.line + 1}:${position.character + 1}]}`;
|
308
|
+
if (evaluatorOptions.verifyTypeCacheEvaluatorFlags) {
|
309
|
+
(0, debug_1.fail)(message);
|
310
|
+
}
|
311
|
+
else {
|
312
|
+
console.log(message);
|
313
|
+
}
|
300
314
|
}
|
301
315
|
}
|
302
316
|
}
|
@@ -424,9 +438,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
424
438
|
// context. For example, if it's a subexpression of an argument expression,
|
425
439
|
// the associated parameter type might inform the expected type.
|
426
440
|
function getExpectedType(node) {
|
427
|
-
|
441
|
+
// Scan up the parse tree to find the top-most expression node
|
442
|
+
// so we can evaluate the entire expression.
|
443
|
+
let topExpression = node;
|
428
444
|
let curNode = node;
|
429
|
-
while (curNode
|
445
|
+
while (curNode) {
|
446
|
+
if ((0, parseNodes_1.isExpressionNode)(curNode)) {
|
447
|
+
topExpression = curNode;
|
448
|
+
}
|
449
|
+
curNode = curNode.parent;
|
450
|
+
}
|
451
|
+
// Evaluate the expression. This will have the side effect of
|
452
|
+
// storing an expected type in the expected type cache.
|
453
|
+
evaluateTypesForExpressionInContext(topExpression);
|
454
|
+
// Look for the resulting expected type by scanning up the parse tree.
|
455
|
+
curNode = node;
|
456
|
+
while (curNode) {
|
430
457
|
const expectedType = expectedTypeCache.get(curNode.id);
|
431
458
|
if (expectedType) {
|
432
459
|
return {
|
@@ -434,6 +461,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
434
461
|
node: curNode,
|
435
462
|
};
|
436
463
|
}
|
464
|
+
if (curNode === topExpression) {
|
465
|
+
break;
|
466
|
+
}
|
437
467
|
curNode = curNode.parent;
|
438
468
|
}
|
439
469
|
return undefined;
|
@@ -452,6 +482,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
452
482
|
noneType = getTypeshedType(node, 'NoneType') || types_1.AnyType.create();
|
453
483
|
tupleClassType = getBuiltInType(node, 'tuple');
|
454
484
|
boolClassType = getBuiltInType(node, 'bool');
|
485
|
+
intClassType = getBuiltInType(node, 'int');
|
455
486
|
strClassType = getBuiltInType(node, 'str');
|
456
487
|
dictClassType = getBuiltInType(node, 'dict');
|
457
488
|
typedDictClassType = getTypingType(node, '_TypedDict');
|
@@ -465,7 +496,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
465
496
|
if (printExpressionTypes) {
|
466
497
|
console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Cached ${printType(cachedType)}`);
|
467
498
|
}
|
468
|
-
return { type: cachedType
|
499
|
+
return { type: cachedType };
|
469
500
|
}
|
470
501
|
else {
|
471
502
|
// Is it cached in the speculative type cache?
|
@@ -474,7 +505,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
474
505
|
if (printExpressionTypes) {
|
475
506
|
console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Speculative ${printType(speculativeCachedType)}`);
|
476
507
|
}
|
477
|
-
return { type: speculativeCachedType
|
508
|
+
return { type: speculativeCachedType };
|
478
509
|
}
|
479
510
|
}
|
480
511
|
if (printExpressionTypes) {
|
@@ -626,7 +657,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
626
657
|
getTypeOfExpression(node.child);
|
627
658
|
}
|
628
659
|
});
|
629
|
-
typeResult = { type: types_1.UnknownType.create()
|
660
|
+
typeResult = { type: types_1.UnknownType.create() };
|
630
661
|
break;
|
631
662
|
}
|
632
663
|
default:
|
@@ -678,7 +709,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
678
709
|
const exprTypeResult = getTypeOfExpression(node.expression, flags, effectiveExpectedType);
|
679
710
|
const typeResult = {
|
680
711
|
type: getTypeOfAwaitable(exprTypeResult.type, node.expression),
|
681
|
-
node,
|
682
712
|
};
|
683
713
|
if (exprTypeResult.isIncomplete) {
|
684
714
|
typeResult.isIncomplete = true;
|
@@ -687,26 +717,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
687
717
|
}
|
688
718
|
function getTypeOfEllipsis(flags, typeResult, node) {
|
689
719
|
if ((flags & 1 /* ConvertEllipsisToAny */) !== 0) {
|
690
|
-
typeResult = { type: types_1.AnyType.create(/* isEllipsis */ true)
|
720
|
+
typeResult = { type: types_1.AnyType.create(/* isEllipsis */ true) };
|
691
721
|
}
|
692
722
|
else if ((flags & 256 /* ConvertEllipsisToUnknown */) !== 0) {
|
693
|
-
typeResult = { type: types_1.UnknownType.create()
|
723
|
+
typeResult = { type: types_1.UnknownType.create() };
|
694
724
|
}
|
695
725
|
else {
|
696
726
|
const ellipsisType = getBuiltInObject(node, 'ellipsis') || types_1.AnyType.create();
|
697
|
-
typeResult = { type: ellipsisType
|
727
|
+
typeResult = { type: ellipsisType };
|
698
728
|
}
|
699
729
|
return typeResult;
|
700
730
|
}
|
701
731
|
function getTypeOfNumber(node, typeResult) {
|
702
732
|
if (node.isImaginary) {
|
703
|
-
typeResult = {
|
733
|
+
typeResult = { type: getBuiltInObject(node, 'complex') };
|
704
734
|
}
|
705
735
|
else if (node.isInteger) {
|
706
|
-
typeResult = {
|
736
|
+
typeResult = { type: cloneBuiltinObjectWithLiteral(node, 'int', node.value) };
|
707
737
|
}
|
708
738
|
else {
|
709
|
-
typeResult = {
|
739
|
+
typeResult = { type: getBuiltInObject(node, 'float') };
|
710
740
|
}
|
711
741
|
return typeResult;
|
712
742
|
}
|
@@ -725,17 +755,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
725
755
|
if ((flags & 128 /* TypeVarTupleDisallowed */) === 0 &&
|
726
756
|
(0, types_1.isVariadicTypeVar)(iterType) &&
|
727
757
|
!iterType.isVariadicUnpacked) {
|
728
|
-
typeResult = { type: types_1.TypeVarType.cloneForUnpacked(iterType)
|
758
|
+
typeResult = { type: types_1.TypeVarType.cloneForUnpacked(iterType) };
|
729
759
|
}
|
730
760
|
else {
|
731
761
|
if ((flags & 2097152 /* AllowUnpackedTupleOrTypeVarTuple */) !== 0 &&
|
732
762
|
(0, types_1.isInstantiableClass)(iterType) &&
|
733
763
|
types_1.ClassType.isBuiltIn(iterType, 'tuple')) {
|
734
|
-
typeResult = { type: types_1.ClassType.cloneForUnpacked(iterType)
|
764
|
+
typeResult = { type: types_1.ClassType.cloneForUnpacked(iterType) };
|
735
765
|
}
|
736
766
|
else {
|
737
767
|
const type = (_a = getTypeOfIterator(iterType, /* isAsync */ false, node)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create(!!iterTypeResult.isIncomplete);
|
738
|
-
typeResult = { type, unpackedType: iterType,
|
768
|
+
typeResult = { type, unpackedType: iterType, isIncomplete: iterTypeResult.isIncomplete };
|
739
769
|
}
|
740
770
|
}
|
741
771
|
return typeResult;
|
@@ -764,30 +794,51 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
764
794
|
if (!typeResult) {
|
765
795
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
766
796
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.expectedTypeNotString(), node);
|
767
|
-
typeResult = {
|
797
|
+
typeResult = { type: types_1.UnknownType.create() };
|
768
798
|
}
|
769
799
|
}
|
770
800
|
else {
|
771
801
|
// Evaluate the format string expressions in this context.
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
802
|
+
let isLiteralString = true;
|
803
|
+
let isIncomplete = false;
|
804
|
+
node.strings.forEach((expr) => {
|
805
|
+
const typeResult = getTypeOfString(expr);
|
806
|
+
if (typeResult.isIncomplete) {
|
807
|
+
isIncomplete = true;
|
808
|
+
}
|
809
|
+
let isExprLiteralString = false;
|
810
|
+
if ((0, types_1.isClassInstance)(typeResult.type)) {
|
811
|
+
if (types_1.ClassType.isBuiltIn(typeResult.type, 'str') && typeResult.type.literalValue !== undefined) {
|
812
|
+
isExprLiteralString = true;
|
813
|
+
}
|
814
|
+
else if (types_1.ClassType.isBuiltIn(typeResult === null || typeResult === void 0 ? void 0 : typeResult.type, 'LiteralString')) {
|
815
|
+
isExprLiteralString = true;
|
816
|
+
}
|
817
|
+
}
|
818
|
+
if (!isExprLiteralString) {
|
819
|
+
isLiteralString = false;
|
777
820
|
}
|
778
821
|
});
|
779
822
|
const isBytes = (node.strings[0].token.flags & 32 /* Bytes */) !== 0;
|
780
823
|
// Don't create a literal type if it's an f-string.
|
781
824
|
if (node.strings.some((str) => str.nodeType === 27 /* FormatString */)) {
|
782
|
-
|
783
|
-
node,
|
784
|
-
|
785
|
-
|
825
|
+
if (isLiteralString) {
|
826
|
+
const literalStringType = getTypingType(node, 'LiteralString');
|
827
|
+
if (literalStringType && (0, types_1.isInstantiableClass)(literalStringType)) {
|
828
|
+
typeResult = { type: types_1.ClassType.cloneAsInstance(literalStringType) };
|
829
|
+
}
|
830
|
+
}
|
831
|
+
if (!typeResult) {
|
832
|
+
typeResult = {
|
833
|
+
type: getBuiltInObject(node, isBytes ? 'bytes' : 'str'),
|
834
|
+
isIncomplete,
|
835
|
+
};
|
836
|
+
}
|
786
837
|
}
|
787
838
|
else {
|
788
839
|
typeResult = {
|
789
|
-
node,
|
790
840
|
type: cloneBuiltinObjectWithLiteral(node, isBytes ? 'bytes' : 'str', node.strings.map((s) => s.value).join('')),
|
841
|
+
isIncomplete,
|
791
842
|
};
|
792
843
|
}
|
793
844
|
}
|
@@ -798,19 +849,62 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
798
849
|
let typeResult;
|
799
850
|
// Don't create a literal type if it's an f-string.
|
800
851
|
if (node.nodeType === 27 /* FormatString */) {
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
852
|
+
let isLiteralString = true;
|
853
|
+
// If all of the format expressions are of type LiteralString, then
|
854
|
+
// the resulting formatted string is also LiteralString.
|
855
|
+
node.expressions.forEach((expr) => {
|
856
|
+
const exprType = getTypeOfExpression(expr).type;
|
857
|
+
if (!(0, types_1.isClassInstance)(exprType)) {
|
858
|
+
isLiteralString = false;
|
859
|
+
return;
|
860
|
+
}
|
861
|
+
if (types_1.ClassType.isBuiltIn(exprType, 'LiteralString')) {
|
862
|
+
return;
|
863
|
+
}
|
864
|
+
if (types_1.ClassType.isBuiltIn(exprType, 'str') && exprType.literalValue !== undefined) {
|
865
|
+
return;
|
866
|
+
}
|
867
|
+
isLiteralString = false;
|
868
|
+
});
|
869
|
+
if (!isBytes && isLiteralString) {
|
870
|
+
const literalStringType = getTypingType(node, 'LiteralString');
|
871
|
+
if (literalStringType && (0, types_1.isInstantiableClass)(literalStringType)) {
|
872
|
+
typeResult = { type: types_1.ClassType.cloneAsInstance(literalStringType) };
|
873
|
+
}
|
874
|
+
}
|
875
|
+
if (!typeResult) {
|
876
|
+
typeResult = {
|
877
|
+
type: getBuiltInObject(node, isBytes ? 'bytes' : 'str'),
|
878
|
+
};
|
879
|
+
}
|
805
880
|
}
|
806
881
|
else {
|
807
882
|
typeResult = {
|
808
|
-
node,
|
809
883
|
type: cloneBuiltinObjectWithLiteral(node, isBytes ? 'bytes' : 'str', node.value),
|
810
884
|
};
|
811
885
|
}
|
812
886
|
return typeResult;
|
813
887
|
}
|
888
|
+
function stripLiteralValue(type) {
|
889
|
+
if ((0, types_1.isClass)(type)) {
|
890
|
+
if (type.literalValue !== undefined) {
|
891
|
+
type = types_1.ClassType.cloneWithLiteral(type, /* value */ undefined);
|
892
|
+
}
|
893
|
+
else if (types_1.ClassType.isBuiltIn(type, 'LiteralString')) {
|
894
|
+
// Handle "LiteralString" specially.
|
895
|
+
if (strClassType && (0, types_1.isInstantiableClass)(strClassType)) {
|
896
|
+
type = types_1.ClassType.cloneAsInstance(strClassType);
|
897
|
+
}
|
898
|
+
}
|
899
|
+
return type;
|
900
|
+
}
|
901
|
+
if ((0, types_1.isUnion)(type)) {
|
902
|
+
return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
903
|
+
return stripLiteralValue(subtype);
|
904
|
+
});
|
905
|
+
}
|
906
|
+
return type;
|
907
|
+
}
|
814
908
|
function getTypeOfParameterAnnotation(paramTypeNode, paramCategory) {
|
815
909
|
return getTypeOfAnnotation(paramTypeNode, {
|
816
910
|
associateTypeVarsWithScope: true,
|
@@ -1138,8 +1232,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1138
1232
|
/* isAccessedThroughObject */ true, memberName, usage, diag, memberAccessFlags | 8 /* DisallowClassVarWrites */, bindToType);
|
1139
1233
|
if (memberInfo) {
|
1140
1234
|
return {
|
1141
|
-
node: errorNode,
|
1142
1235
|
type: memberInfo.type,
|
1236
|
+
classType: memberInfo.classType,
|
1143
1237
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
1144
1238
|
isAsymmetricDescriptor: memberInfo.isAsymmetricDescriptor,
|
1145
1239
|
};
|
@@ -1152,7 +1246,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1152
1246
|
let memberInfo;
|
1153
1247
|
if (types_1.ClassType.isPartiallyEvaluated(classType)) {
|
1154
1248
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classDefinitionCycle().format({ name: classType.details.name }), errorNode);
|
1155
|
-
return {
|
1249
|
+
return { type: types_1.UnknownType.create() };
|
1156
1250
|
}
|
1157
1251
|
if ((memberAccessFlags & 32 /* ConsiderMetaclassOnly */) === 0) {
|
1158
1252
|
memberInfo = getTypeOfClassMemberName(errorNode, classType,
|
@@ -1184,7 +1278,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1184
1278
|
}
|
1185
1279
|
if (memberInfo) {
|
1186
1280
|
return {
|
1187
|
-
node: errorNode,
|
1188
1281
|
type: memberInfo.type,
|
1189
1282
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
1190
1283
|
isAsymmetricDescriptor: memberInfo.isAsymmetricDescriptor,
|
@@ -1272,10 +1365,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1272
1365
|
addOneFunctionToSignature(type);
|
1273
1366
|
}
|
1274
1367
|
else {
|
1275
|
-
type.
|
1276
|
-
|
1277
|
-
addOneFunctionToSignature(func);
|
1278
|
-
}
|
1368
|
+
types_1.OverloadedFunctionType.getOverloads(type).forEach((func) => {
|
1369
|
+
addOneFunctionToSignature(func);
|
1279
1370
|
});
|
1280
1371
|
}
|
1281
1372
|
}
|
@@ -1477,13 +1568,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1477
1568
|
return subtype;
|
1478
1569
|
}
|
1479
1570
|
if ((0, types_1.isClassInstance)(subtype)) {
|
1480
|
-
const awaitReturnType = getSpecializedReturnType(subtype, '__await__', errorNode);
|
1571
|
+
const awaitReturnType = getSpecializedReturnType(subtype, '__await__', [], errorNode);
|
1481
1572
|
if (awaitReturnType) {
|
1482
1573
|
if ((0, types_1.isAnyOrUnknown)(awaitReturnType)) {
|
1483
1574
|
return awaitReturnType;
|
1484
1575
|
}
|
1485
1576
|
if ((0, types_1.isClassInstance)(awaitReturnType)) {
|
1486
|
-
const iterReturnType = getSpecializedReturnType(awaitReturnType, '__iter__', errorNode);
|
1577
|
+
const iterReturnType = getSpecializedReturnType(awaitReturnType, '__iter__', [], errorNode);
|
1487
1578
|
if (iterReturnType) {
|
1488
1579
|
const generatorReturnType = getReturnTypeFromGenerator(awaitReturnType);
|
1489
1580
|
if (generatorReturnType) {
|
@@ -1506,6 +1597,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1506
1597
|
const iterMethodName = isAsync ? '__aiter__' : '__iter__';
|
1507
1598
|
const nextMethodName = isAsync ? '__anext__' : '__next__';
|
1508
1599
|
let isValidIterator = true;
|
1600
|
+
type = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(type);
|
1509
1601
|
type = makeTopLevelTypeVarsConcrete(type);
|
1510
1602
|
if ((0, typeUtils_1.isOptionalType)(type)) {
|
1511
1603
|
if (errorNode) {
|
@@ -1528,18 +1620,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1528
1620
|
subtype.tupleTypeArguments.length === 0) {
|
1529
1621
|
return types_1.NeverType.createNever();
|
1530
1622
|
}
|
1531
|
-
iterReturnType = getSpecializedReturnType(subtype, iterMethodName, errorNode);
|
1623
|
+
iterReturnType = getSpecializedReturnType(subtype, iterMethodName, [], errorNode);
|
1532
1624
|
}
|
1533
1625
|
else if (types_1.TypeBase.isInstantiable(subtype) &&
|
1534
1626
|
subtype.details.effectiveMetaclass &&
|
1535
1627
|
(0, types_1.isInstantiableClass)(subtype.details.effectiveMetaclass)) {
|
1536
|
-
iterReturnType = getSpecializedReturnType(types_1.ClassType.cloneAsInstance(subtype.details.effectiveMetaclass), iterMethodName, errorNode, subtype);
|
1628
|
+
iterReturnType = getSpecializedReturnType(types_1.ClassType.cloneAsInstance(subtype.details.effectiveMetaclass), iterMethodName, [], errorNode, subtype);
|
1537
1629
|
}
|
1538
1630
|
if (!iterReturnType) {
|
1539
1631
|
// There was no __iter__. See if we can fall back to
|
1540
1632
|
// the __getitem__ method instead.
|
1541
|
-
if ((0, types_1.isClassInstance)(subtype)) {
|
1542
|
-
const getItemReturnType = getSpecializedReturnType(subtype, '__getitem__',
|
1633
|
+
if (!isAsync && (0, types_1.isClassInstance)(subtype)) {
|
1634
|
+
const getItemReturnType = getSpecializedReturnType(subtype, '__getitem__', [
|
1635
|
+
{
|
1636
|
+
argumentCategory: 0 /* Simple */,
|
1637
|
+
typeResult: {
|
1638
|
+
type: intClassType && (0, types_1.isInstantiableClass)(intClassType)
|
1639
|
+
? types_1.ClassType.cloneAsInstance(intClassType)
|
1640
|
+
: types_1.UnknownType.create(),
|
1641
|
+
},
|
1642
|
+
},
|
1643
|
+
], errorNode);
|
1543
1644
|
if (getItemReturnType) {
|
1544
1645
|
return getItemReturnType;
|
1545
1646
|
}
|
@@ -1554,7 +1655,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1554
1655
|
return subtype;
|
1555
1656
|
}
|
1556
1657
|
if ((0, types_1.isClassInstance)(subtype)) {
|
1557
|
-
const nextReturnType = getSpecializedReturnType(subtype, nextMethodName, errorNode);
|
1658
|
+
const nextReturnType = getSpecializedReturnType(subtype, nextMethodName, [], errorNode);
|
1558
1659
|
if (!nextReturnType) {
|
1559
1660
|
iterReturnTypeDiag.addMessage(localize_1.Localizer.Diagnostic.methodNotDefinedOnType().format({
|
1560
1661
|
name: nextMethodName,
|
@@ -1607,12 +1708,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1607
1708
|
if ((0, types_1.isClass)(subtype)) {
|
1608
1709
|
let iterReturnType;
|
1609
1710
|
if (types_1.TypeBase.isInstance(subtype)) {
|
1610
|
-
iterReturnType = getSpecializedReturnType(subtype, iterMethodName, errorNode);
|
1711
|
+
iterReturnType = getSpecializedReturnType(subtype, iterMethodName, [], errorNode);
|
1611
1712
|
}
|
1612
1713
|
else if (types_1.TypeBase.isInstantiable(subtype) &&
|
1613
1714
|
subtype.details.effectiveMetaclass &&
|
1614
1715
|
(0, types_1.isInstantiableClass)(subtype.details.effectiveMetaclass)) {
|
1615
|
-
iterReturnType = getSpecializedReturnType(types_1.ClassType.cloneAsInstance(subtype.details.effectiveMetaclass), iterMethodName, errorNode, subtype);
|
1716
|
+
iterReturnType = getSpecializedReturnType(types_1.ClassType.cloneAsInstance(subtype.details.effectiveMetaclass), iterMethodName, [], errorNode, subtype);
|
1616
1717
|
}
|
1617
1718
|
if (iterReturnType) {
|
1618
1719
|
return makeTopLevelTypeVarsConcrete(iterReturnType);
|
@@ -1760,6 +1861,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1760
1861
|
fileInfo.diagnosticSink.addUnusedCodeWithTextRange(localize_1.Localizer.Diagnostic.unreachableCode(), textRange);
|
1761
1862
|
}
|
1762
1863
|
}
|
1864
|
+
function addUnreachableCode(node, textRange) {
|
1865
|
+
if (!isDiagnosticSuppressedForNode(node)) {
|
1866
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
1867
|
+
fileInfo.diagnosticSink.addUnreachableCodeWithTextRange(localize_1.Localizer.Diagnostic.unreachableCode(), textRange);
|
1868
|
+
}
|
1869
|
+
}
|
1763
1870
|
function addDeprecated(message, node) {
|
1764
1871
|
if (!isDiagnosticSuppressedForNode(node)) {
|
1765
1872
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -1866,7 +1973,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1866
1973
|
if (types_1.TypeBase.isInstance(destType) &&
|
1867
1974
|
!(0, symbolNameUtils_1.isConstantName)(nameValue) &&
|
1868
1975
|
!(0, symbolUtils_1.isFinalVariable)(symbolWithScope.symbol)) {
|
1869
|
-
destType =
|
1976
|
+
destType = stripLiteralValue(destType);
|
1870
1977
|
}
|
1871
1978
|
}
|
1872
1979
|
}
|
@@ -1886,9 +1993,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1886
1993
|
if (!isTypeIncomplete) {
|
1887
1994
|
reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, nameNode, destType, nameNode, ignoreEmptyContainers);
|
1888
1995
|
}
|
1889
|
-
writeTypeCache(nameNode, destType, 0 /* None */, isTypeIncomplete
|
1890
|
-
/* expectedType */ undefined,
|
1891
|
-
/* allowSpeculativeCaching */ false);
|
1996
|
+
writeTypeCache(nameNode, destType, 0 /* None */, isTypeIncomplete);
|
1892
1997
|
}
|
1893
1998
|
function assignTypeToMemberAccessNode(target, type, isTypeIncomplete, srcExpr, expectedTypeDiagAddendum) {
|
1894
1999
|
const baseTypeResult = getTypeOfExpression(target.leftExpression, 2 /* DoNotSpecialize */);
|
@@ -1932,12 +2037,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1932
2037
|
if (setTypeResult.isAsymmetricDescriptor) {
|
1933
2038
|
setAsymmetricDescriptorAssignment(target);
|
1934
2039
|
}
|
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);
|
2040
|
+
writeTypeCache(target.memberName, type, 0 /* None */, isTypeIncomplete);
|
2041
|
+
writeTypeCache(target, type, 0 /* None */, isTypeIncomplete);
|
1941
2042
|
}
|
1942
2043
|
function assignTypeToMemberVariable(node, srcType, isTypeIncomplete, isInstanceMember, srcExprNode) {
|
1943
2044
|
const memberName = node.memberName.value;
|
@@ -2059,7 +2160,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2059
2160
|
const removedEntries = sourceEntryTypes.splice(targetUnpackIndex, sourceEntryTypes.length - targetTypes.length + 1);
|
2060
2161
|
let combinedTypes = (0, types_1.combineTypes)(removedEntries);
|
2061
2162
|
if (target.nodeType === 31 /* List */) {
|
2062
|
-
combinedTypes =
|
2163
|
+
combinedTypes = stripLiteralValue(combinedTypes);
|
2063
2164
|
}
|
2064
2165
|
sourceEntryTypes.splice(targetUnpackIndex, 0, combinedTypes);
|
2065
2166
|
}
|
@@ -2146,7 +2247,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2146
2247
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
2147
2248
|
return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [],
|
2148
2249
|
/* isTypeArgumentExplicit */ true,
|
2149
|
-
/* stripLiterals */ true,
|
2150
2250
|
/* isUnpackedTuple */ true));
|
2151
2251
|
}
|
2152
2252
|
}
|
@@ -2458,7 +2558,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2458
2558
|
break;
|
2459
2559
|
}
|
2460
2560
|
case 35 /* MemberAccess */: {
|
2461
|
-
const baseTypeResult = getTypeOfExpression(node.leftExpression);
|
2561
|
+
const baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /* DoNotSpecialize */);
|
2462
2562
|
const memberType = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* None */);
|
2463
2563
|
writeTypeCache(node.memberName, memberType.type, 0 /* None */, /* isIncomplete */ false);
|
2464
2564
|
writeTypeCache(node, memberType.type, 0 /* None */, /* isIncomplete */ false);
|
@@ -2514,7 +2614,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2514
2614
|
}
|
2515
2615
|
return undefined;
|
2516
2616
|
}
|
2517
|
-
function getSpecializedReturnType(objType, memberName, errorNode, bindToClass) {
|
2617
|
+
function getSpecializedReturnType(objType, memberName, argList, errorNode, bindToClass) {
|
2518
2618
|
const classMember = (0, typeUtils_1.lookUpObjectMember)(objType, memberName, 8 /* SkipInstanceVariables */);
|
2519
2619
|
if (!classMember) {
|
2520
2620
|
return undefined;
|
@@ -2523,13 +2623,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2523
2623
|
if ((0, types_1.isAnyOrUnknown)(memberType)) {
|
2524
2624
|
return memberType;
|
2525
2625
|
}
|
2526
|
-
if ((0, types_1.isFunction)(memberType)) {
|
2626
|
+
if ((0, types_1.isFunction)(memberType) || (0, types_1.isOverloadedFunction)(memberType)) {
|
2527
2627
|
const methodType = bindFunctionToClassOrObject(bindToClass || objType, memberType, classMember && (0, types_1.isInstantiableClass)(classMember.classType) ? classMember.classType : undefined, errorNode,
|
2528
2628
|
/* recursionCount */ undefined,
|
2529
2629
|
/* treatConstructorAsClassMember */ false,
|
2530
2630
|
/* firstParamType */ bindToClass);
|
2531
2631
|
if (methodType) {
|
2532
|
-
|
2632
|
+
if ((0, types_1.isOverloadedFunction)(methodType)) {
|
2633
|
+
if (errorNode) {
|
2634
|
+
const bestOverload = getBestOverloadForArguments(errorNode, methodType, argList);
|
2635
|
+
if (bestOverload) {
|
2636
|
+
return getFunctionEffectiveReturnType(bestOverload);
|
2637
|
+
}
|
2638
|
+
}
|
2639
|
+
}
|
2640
|
+
else {
|
2641
|
+
return getFunctionEffectiveReturnType(methodType);
|
2642
|
+
}
|
2533
2643
|
}
|
2534
2644
|
}
|
2535
2645
|
return undefined;
|
@@ -2546,7 +2656,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2546
2656
|
const containingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
2547
2657
|
if (containingFunction && ParseTreeUtils.isUnannotatedFunction(containingFunction)) {
|
2548
2658
|
return {
|
2549
|
-
node,
|
2550
2659
|
type: types_1.AnyType.create(),
|
2551
2660
|
isIncomplete: false,
|
2552
2661
|
};
|
@@ -2690,7 +2799,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2690
2799
|
if ((0, types_1.isTypeVar)(type) && !type.details.isSynthesized) {
|
2691
2800
|
type = validateTypeVarUsage(node, type, flags);
|
2692
2801
|
}
|
2693
|
-
return { type,
|
2802
|
+
return { type, isIncomplete };
|
2694
2803
|
}
|
2695
2804
|
// Handles the case where a variable or parameter is defined in an outer
|
2696
2805
|
// scope and captured by an inner scope (either a function or a lambda).
|
@@ -2988,7 +3097,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2988
3097
|
const baseTypeResult = getTypeOfExpression(node.leftExpression, baseTypeFlags);
|
2989
3098
|
if ((0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
|
2990
3099
|
return {
|
2991
|
-
node,
|
2992
3100
|
type: types_1.UnknownType.create(/* isIncomplete */ true),
|
2993
3101
|
isIncomplete: true,
|
2994
3102
|
};
|
@@ -3048,7 +3156,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3048
3156
|
// If the base type was incomplete and unbound, don't proceed
|
3049
3157
|
// because false positive errors will be generated.
|
3050
3158
|
if (baseTypeResult.isIncomplete && (0, types_1.isUnbound)(baseTypeResult.type)) {
|
3051
|
-
return { type: types_1.UnknownType.create(/* isIncomplete */ true),
|
3159
|
+
return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
|
3052
3160
|
}
|
3053
3161
|
// Handle the special case where the expression is an actual
|
3054
3162
|
// UnionType special form.
|
@@ -3084,22 +3192,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3084
3192
|
const paramNode = ParseTreeUtils.getEnclosingParameter(node);
|
3085
3193
|
if (!paramNode || paramNode.category !== 1 /* VarArgList */) {
|
3086
3194
|
addError(localize_1.Localizer.Diagnostic.paramSpecArgsUsage(), node);
|
3087
|
-
return { type: types_1.UnknownType.create(isIncomplete),
|
3195
|
+
return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
|
3088
3196
|
}
|
3089
|
-
return { type: types_1.TypeVarType.cloneForParamSpecAccess(baseType, 'args'),
|
3197
|
+
return { type: types_1.TypeVarType.cloneForParamSpecAccess(baseType, 'args'), isIncomplete };
|
3090
3198
|
}
|
3091
3199
|
if (memberName === 'kwargs') {
|
3092
3200
|
const paramNode = ParseTreeUtils.getEnclosingParameter(node);
|
3093
3201
|
if (!paramNode || paramNode.category !== 2 /* VarArgDictionary */) {
|
3094
3202
|
addError(localize_1.Localizer.Diagnostic.paramSpecKwargsUsage(), node);
|
3095
|
-
return { type: types_1.UnknownType.create(isIncomplete),
|
3203
|
+
return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
|
3096
3204
|
}
|
3097
|
-
return { type: types_1.TypeVarType.cloneForParamSpecAccess(baseType, 'kwargs'),
|
3205
|
+
return { type: types_1.TypeVarType.cloneForParamSpecAccess(baseType, 'kwargs'), isIncomplete };
|
3098
3206
|
}
|
3099
3207
|
if (!isIncomplete) {
|
3100
3208
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecUnknownMember().format({ name: memberName }), node);
|
3101
3209
|
}
|
3102
|
-
return { type: types_1.UnknownType.create(isIncomplete),
|
3210
|
+
return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
|
3103
3211
|
}
|
3104
3212
|
if (flags & 64 /* ExpectingType */) {
|
3105
3213
|
if (!isIncomplete) {
|
@@ -3108,14 +3216,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3108
3216
|
name: memberName,
|
3109
3217
|
}), node.leftExpression);
|
3110
3218
|
}
|
3111
|
-
return { type: types_1.UnknownType.create(isIncomplete),
|
3219
|
+
return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
|
3112
3220
|
}
|
3113
3221
|
if (baseType.details.recursiveTypeAliasName) {
|
3114
|
-
return { type: types_1.UnknownType.create(/* isIncomplete */ true),
|
3222
|
+
return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
|
3115
3223
|
}
|
3116
3224
|
return getTypeOfMemberAccessWithBaseType(node, {
|
3117
3225
|
type: makeTopLevelTypeVarsConcrete(baseType),
|
3118
|
-
node,
|
3119
3226
|
bindToType: baseType,
|
3120
3227
|
isIncomplete,
|
3121
3228
|
}, usage, 0 /* None */);
|
@@ -3139,23 +3246,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3139
3246
|
baseType = types_1.ClassType.cloneAsInstance(strClassType);
|
3140
3247
|
}
|
3141
3248
|
// Handle the special case of 'name' and 'value' members within an enum.
|
3142
|
-
|
3143
|
-
|
3144
|
-
|
3145
|
-
if (memberName === 'name' || memberName === '_name_') {
|
3146
|
-
const strClass = getBuiltInType(node, 'str');
|
3147
|
-
if ((0, types_1.isInstantiableClass)(strClass)) {
|
3148
|
-
return {
|
3149
|
-
node,
|
3150
|
-
type: types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneWithLiteral(strClass, literalValue.itemName)),
|
3151
|
-
isIncomplete,
|
3152
|
-
};
|
3153
|
-
}
|
3154
|
-
}
|
3155
|
-
else if (memberName === 'value' || memberName === '_value_') {
|
3156
|
-
return { node, type: literalValue.itemType, isIncomplete };
|
3157
|
-
}
|
3158
|
-
}
|
3249
|
+
const enumMemberResult = (0, enums_1.getTypeOfEnumMember)(evaluatorInterface, node, baseType, memberName, isIncomplete);
|
3250
|
+
if (enumMemberResult) {
|
3251
|
+
return enumMemberResult;
|
3159
3252
|
}
|
3160
3253
|
const typeResult = getTypeOfObjectMember(node.memberName, baseType, memberName, usage, diag,
|
3161
3254
|
/* memberAccessFlags */ undefined, baseTypeResult.bindToType);
|
@@ -3257,7 +3350,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3257
3350
|
else {
|
3258
3351
|
const typeResult = getTypeOfMemberAccessWithBaseType(node, {
|
3259
3352
|
type: subtype,
|
3260
|
-
node,
|
3261
3353
|
isIncomplete: baseTypeResult.isIncomplete,
|
3262
3354
|
}, usage, 0 /* None */);
|
3263
3355
|
if (typeResult.isIncomplete) {
|
@@ -3289,7 +3381,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3289
3381
|
type = types_1.AnyType.create();
|
3290
3382
|
}
|
3291
3383
|
else {
|
3292
|
-
type = getTypeOfMemberAccessWithBaseType(node, { type: functionObj
|
3384
|
+
type = getTypeOfMemberAccessWithBaseType(node, { type: functionObj }, usage, flags).type;
|
3293
3385
|
}
|
3294
3386
|
}
|
3295
3387
|
break;
|
@@ -3359,7 +3451,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3359
3451
|
/* ignoreEmptyContainers */ false);
|
3360
3452
|
}
|
3361
3453
|
}
|
3362
|
-
return { type,
|
3454
|
+
return { type, isIncomplete, isAsymmetricDescriptor };
|
3363
3455
|
}
|
3364
3456
|
function getTypeOfClassMemberName(errorNode, classType, isAccessedThroughObject, memberName, usage, diag, flags, bindToType) {
|
3365
3457
|
var _a, _b;
|
@@ -3416,7 +3508,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3416
3508
|
// because that case is used for super() calls where we want
|
3417
3509
|
// to leave the Self type generic (not specialized).
|
3418
3510
|
const selfClass = bindToType ? undefined : classType;
|
3419
|
-
const typeResult = getTypeOfMemberInternal(
|
3511
|
+
const typeResult = getTypeOfMemberInternal(memberInfo, selfClass);
|
3420
3512
|
if (typeResult) {
|
3421
3513
|
type = typeResult.type;
|
3422
3514
|
if (typeResult.isIncomplete) {
|
@@ -3701,7 +3793,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3701
3793
|
isFinal = types_1.FunctionType.isFinal(concreteSubtype);
|
3702
3794
|
}
|
3703
3795
|
else {
|
3704
|
-
const impl =
|
3796
|
+
const impl = types_1.OverloadedFunctionType.getImplementation(concreteSubtype);
|
3705
3797
|
if (impl) {
|
3706
3798
|
isFinal = types_1.FunctionType.isFinal(impl);
|
3707
3799
|
}
|
@@ -3998,7 +4090,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3998
4090
|
}
|
3999
4091
|
const tupleObject = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, variadicTypes,
|
4000
4092
|
/* isTypeArgumentExplicit */ true,
|
4001
|
-
/* stripLiterals */ true,
|
4002
4093
|
/* isUnpackedTuple */ true));
|
4003
4094
|
typeArgs = [
|
4004
4095
|
...typeArgs.slice(0, variadicIndex),
|
@@ -4013,7 +4104,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4013
4104
|
node: errorNode,
|
4014
4105
|
type: (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [],
|
4015
4106
|
/* isTypeArgumentExplicit */ true,
|
4016
|
-
/* stripLiterals */ true,
|
4017
4107
|
/* isUnpackedTuple */ true)),
|
4018
4108
|
});
|
4019
4109
|
}
|
@@ -4174,9 +4264,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4174
4264
|
if ((0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
|
4175
4265
|
const typeArgTypes = getTypeArgs(node, flags).map((t) => (0, typeUtils_1.convertToInstance)(t.type));
|
4176
4266
|
const type = types_1.TypeBase.cloneForTypeAlias(baseTypeResult.type, baseTypeResult.type.details.recursiveTypeAliasName, '', baseTypeResult.type.details.recursiveTypeAliasScopeId, baseTypeResult.type.details.recursiveTypeParameters, typeArgTypes);
|
4177
|
-
return { type
|
4267
|
+
return { type };
|
4178
4268
|
}
|
4179
|
-
let isIncomplete =
|
4269
|
+
let isIncomplete = baseTypeResult.isIncomplete;
|
4180
4270
|
const type = mapSubtypesExpandTypeVars(baseTypeResult.type,
|
4181
4271
|
/* conditionFilter */ undefined, (concreteSubtype, unexpandedSubtype) => {
|
4182
4272
|
var _a;
|
@@ -4271,11 +4361,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4271
4361
|
if ((0, types_1.isNever)(concreteSubtype)) {
|
4272
4362
|
return types_1.UnknownType.create();
|
4273
4363
|
}
|
4274
|
-
if ((0, types_1.isNoneInstance)(concreteSubtype)) {
|
4364
|
+
if ((0, types_1.isNoneInstance)(concreteSubtype) && !isIncomplete) {
|
4275
4365
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportOptionalSubscript, diagnosticRules_1.DiagnosticRule.reportOptionalSubscript, localize_1.Localizer.Diagnostic.noneNotSubscriptable(), node.baseExpression);
|
4276
4366
|
return types_1.UnknownType.create();
|
4277
4367
|
}
|
4278
|
-
if (!(0, types_1.isUnbound)(concreteSubtype)) {
|
4368
|
+
if (!(0, types_1.isUnbound)(concreteSubtype) && !isIncomplete) {
|
4279
4369
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
4280
4370
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotSubscriptable().format({ type: printType(concreteSubtype) }), node.baseExpression);
|
4281
4371
|
}
|
@@ -4290,7 +4380,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4290
4380
|
}
|
4291
4381
|
});
|
4292
4382
|
}
|
4293
|
-
return { type,
|
4383
|
+
return { type, isIncomplete };
|
4294
4384
|
}
|
4295
4385
|
function makeTupleObject(entryTypes, isUnspecifiedLength = false) {
|
4296
4386
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
@@ -4335,7 +4425,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4335
4425
|
name: magicMethodName,
|
4336
4426
|
type: printType(baseType),
|
4337
4427
|
}), node.baseExpression);
|
4338
|
-
return {
|
4428
|
+
return { type: types_1.UnknownType.create() };
|
4339
4429
|
}
|
4340
4430
|
// Handle the special case where the object is a Tuple and
|
4341
4431
|
// the index is a constant number (integer) or a slice with integer
|
@@ -4356,11 +4446,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4356
4446
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(baseType);
|
4357
4447
|
if (tupleType && tupleType.tupleTypeArguments && !(0, typeUtils_1.isUnboundedTupleClass)(tupleType)) {
|
4358
4448
|
if (indexValue >= 0 && indexValue < tupleType.tupleTypeArguments.length) {
|
4359
|
-
return {
|
4449
|
+
return { type: tupleType.tupleTypeArguments[indexValue].type };
|
4360
4450
|
}
|
4361
4451
|
else if (indexValue < 0 && tupleType.tupleTypeArguments.length + indexValue >= 0) {
|
4362
4452
|
return {
|
4363
|
-
node,
|
4364
4453
|
type: tupleType.tupleTypeArguments[tupleType.tupleTypeArguments.length + indexValue].type,
|
4365
4454
|
};
|
4366
4455
|
}
|
@@ -4398,7 +4487,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4398
4487
|
tupleClassType &&
|
4399
4488
|
(0, types_1.isInstantiableClass)(tupleClassType)) {
|
4400
4489
|
return {
|
4401
|
-
node,
|
4402
4490
|
type: types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, tupleType.tupleTypeArguments.slice(startValue, endValue))),
|
4403
4491
|
};
|
4404
4492
|
}
|
@@ -4444,7 +4532,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4444
4532
|
if (typeResult.isIncomplete) {
|
4445
4533
|
isPositionalIndexTypeIncomplete = true;
|
4446
4534
|
}
|
4447
|
-
const iterableType = getTypeOfIterator(exprType, /* isAsync */ false, arg) || types_1.UnknownType.create();
|
4535
|
+
const iterableType = getTypeOfIterator(exprType, /* isAsync */ false, arg.valueExpression) || types_1.UnknownType.create();
|
4448
4536
|
tupleEntries.push(iterableType);
|
4449
4537
|
});
|
4450
4538
|
positionalIndexType = makeTupleObject(tupleEntries, unpackedListArgs.length > 0);
|
@@ -4513,7 +4601,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4513
4601
|
}
|
4514
4602
|
callResult = validateCallArguments(node, argList, { type: itemMethodType });
|
4515
4603
|
return {
|
4516
|
-
node,
|
4517
4604
|
type: (_c = callResult.returnType) !== null && _c !== void 0 ? _c : types_1.UnknownType.create(),
|
4518
4605
|
isIncomplete: !!callResult.isTypeIncomplete,
|
4519
4606
|
};
|
@@ -4541,10 +4628,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4541
4628
|
// treated as types. If it's an Annotated[a, b, c], only the first index
|
4542
4629
|
// should be treated as a type. The others can be regular (non-type) objects.
|
4543
4630
|
if (hasCustomClassGetItem || (isAnnotatedClass && argIndex > 0)) {
|
4544
|
-
typeResult =
|
4545
|
-
|
4546
|
-
|
4547
|
-
|
4631
|
+
typeResult = {
|
4632
|
+
...getTypeOfExpression(expr, 32 /* ParamSpecDisallowed */ |
|
4633
|
+
128 /* TypeVarTupleDisallowed */ |
|
4634
|
+
2 /* DoNotSpecialize */ |
|
4635
|
+
131072 /* ClassVarDisallowed */),
|
4636
|
+
node: expr,
|
4637
|
+
};
|
4548
4638
|
}
|
4549
4639
|
else {
|
4550
4640
|
typeResult = getTypeArg(expr, adjFlags);
|
@@ -4590,7 +4680,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4590
4680
|
let typeResult;
|
4591
4681
|
let adjustedFlags = flags |
|
4592
4682
|
64 /* ExpectingType */ |
|
4593
|
-
1024 /* ExpectingTypeAnnotation */ |
|
4594
4683
|
1 /* ConvertEllipsisToAny */ |
|
4595
4684
|
8 /* EvaluateStringLiteralAsType */;
|
4596
4685
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -4600,14 +4689,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4600
4689
|
if (node.nodeType === 31 /* List */) {
|
4601
4690
|
typeResult = {
|
4602
4691
|
type: types_1.UnknownType.create(),
|
4603
|
-
typeList: node.entries.map((entry) =>
|
4692
|
+
typeList: node.entries.map((entry) => {
|
4693
|
+
return { ...getTypeOfExpression(entry, adjustedFlags), node: entry };
|
4694
|
+
}),
|
4604
4695
|
node,
|
4605
4696
|
};
|
4606
4697
|
// Set the node's type so it isn't reevaluated later.
|
4607
4698
|
setTypeForNode(node, types_1.UnknownType.create());
|
4608
4699
|
}
|
4609
4700
|
else {
|
4610
|
-
typeResult = getTypeOfExpression(node, adjustedFlags);
|
4701
|
+
typeResult = { ...getTypeOfExpression(node, adjustedFlags), node };
|
4611
4702
|
// "Protocol" is not allowed as a type argument.
|
4612
4703
|
if ((0, types_1.isClass)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'Protocol')) {
|
4613
4704
|
addError(localize_1.Localizer.Diagnostic.protocolNotAllowedInTypeArgument(), node);
|
@@ -4623,7 +4714,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4623
4714
|
}
|
4624
4715
|
function getTypeOfTuple(node, expectedType, flags) {
|
4625
4716
|
if ((flags & 64 /* ExpectingType */) !== 0 && node.expressions.length === 0 && !expectedType) {
|
4626
|
-
return { type: makeTupleObject([]),
|
4717
|
+
return { type: makeTupleObject([]), isEmptyTupleShorthand: true };
|
4627
4718
|
}
|
4628
4719
|
// If the expected type is a union, recursively call for each of the subtypes
|
4629
4720
|
// to find one that matches.
|
@@ -4700,20 +4791,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4700
4791
|
}
|
4701
4792
|
const entryTypeResults = node.expressions.map((expr, index) => getTypeOfExpression(expr,
|
4702
4793
|
/* flags */ undefined, index < expectedTypes.length ? expectedTypes[index] : undefined));
|
4703
|
-
const expectedTypesContainLiterals = expectedTypes.some((type) => (0, typeUtils_1.isLiteralTypeOrUnion)(type));
|
4704
4794
|
const type = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, buildTupleTypesList(entryTypeResults),
|
4705
|
-
/* isTypeArgumentExplicit */ true
|
4706
|
-
|
4707
|
-
return { type, node };
|
4795
|
+
/* isTypeArgumentExplicit */ true));
|
4796
|
+
return { type };
|
4708
4797
|
}
|
4709
4798
|
function getTypeOfTupleInferred(node) {
|
4710
4799
|
const entryTypeResults = node.expressions.map((expr) => getTypeOfExpression(expr));
|
4711
4800
|
const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
|
4712
4801
|
if (!tupleClassType || !(0, types_1.isInstantiableClass)(tupleClassType)) {
|
4713
|
-
return { type: types_1.UnknownType.create()
|
4802
|
+
return { type: types_1.UnknownType.create() };
|
4714
4803
|
}
|
4715
4804
|
const type = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, buildTupleTypesList(entryTypeResults)));
|
4716
|
-
return { type,
|
4805
|
+
return { type, isIncomplete };
|
4717
4806
|
}
|
4718
4807
|
function buildTupleTypesList(entryTypeResults) {
|
4719
4808
|
const entryTypes = [];
|
@@ -4769,7 +4858,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4769
4858
|
};
|
4770
4859
|
return functionArg;
|
4771
4860
|
});
|
4772
|
-
let typeResult = {
|
4861
|
+
let typeResult = { type: types_1.UnknownType.create() };
|
4773
4862
|
if (!(0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
|
4774
4863
|
if (node.leftExpression.nodeType === 38 /* Name */ && node.leftExpression.value === 'super') {
|
4775
4864
|
// Handle the built-in "super" call specially.
|
@@ -4843,7 +4932,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4843
4932
|
}
|
4844
4933
|
if ((flags & 1024 /* ExpectingTypeAnnotation */) !== 0) {
|
4845
4934
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAnnotationCall(), node);
|
4846
|
-
typeResult = {
|
4935
|
+
typeResult = { type: types_1.UnknownType.create() };
|
4847
4936
|
}
|
4848
4937
|
return typeResult;
|
4849
4938
|
}
|
@@ -4854,12 +4943,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4854
4943
|
node.arguments[0].argumentCategory !== 0 /* Simple */ ||
|
4855
4944
|
node.arguments[1].name !== undefined) {
|
4856
4945
|
addError(localize_1.Localizer.Diagnostic.assertTypeArgs(), node);
|
4857
|
-
return {
|
4946
|
+
return { type: types_1.UnknownType.create() };
|
4858
4947
|
}
|
4859
4948
|
const arg0TypeResult = getTypeOfExpression(node.arguments[0].valueExpression,
|
4860
4949
|
/* flags */ undefined, expectedType);
|
4861
4950
|
if (arg0TypeResult.isIncomplete) {
|
4862
|
-
return {
|
4951
|
+
return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
|
4863
4952
|
}
|
4864
4953
|
const assertedType = (0, typeUtils_1.convertToInstance)(getTypeOfArgumentExpectingType(node.arguments[1]).type);
|
4865
4954
|
if (!(0, types_1.isTypeSame)(assertedType, arg0TypeResult.type)) {
|
@@ -4868,7 +4957,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4868
4957
|
received: printType(arg0TypeResult.type),
|
4869
4958
|
}), node.arguments[0].valueExpression);
|
4870
4959
|
}
|
4871
|
-
return {
|
4960
|
+
return { type: arg0TypeResult.type };
|
4872
4961
|
}
|
4873
4962
|
function getTypeOfRevealType(node, expectedType) {
|
4874
4963
|
let arg0Value;
|
@@ -4905,7 +4994,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4905
4994
|
});
|
4906
4995
|
if (!arg0Value) {
|
4907
4996
|
addError(localize_1.Localizer.Diagnostic.revealTypeArgs(), node);
|
4908
|
-
return {
|
4997
|
+
return { type: types_1.UnknownType.create() };
|
4909
4998
|
}
|
4910
4999
|
const typeResult = getTypeOfExpression(arg0Value, /* flags */ undefined, expectedType);
|
4911
5000
|
const type = typeResult.type;
|
@@ -4929,11 +5018,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4929
5018
|
}
|
4930
5019
|
}
|
4931
5020
|
addInformation(localize_1.Localizer.DiagnosticAddendum.typeOfSymbol().format({ name: exprString, type: typeString }), node.arguments[0]);
|
4932
|
-
return {
|
4933
|
-
node,
|
4934
|
-
type,
|
4935
|
-
isIncomplete: typeResult.isIncomplete,
|
4936
|
-
};
|
5021
|
+
return { type, isIncomplete: typeResult.isIncomplete };
|
4937
5022
|
}
|
4938
5023
|
function getTypeOfRevealLocals(node) {
|
4939
5024
|
let curNode = node;
|
@@ -5082,11 +5167,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5082
5167
|
type: resultIsInstance
|
5083
5168
|
? types_1.ClassType.cloneAsInstance(lookupResults.classType)
|
5084
5169
|
: lookupResults.classType,
|
5085
|
-
node,
|
5086
5170
|
bindToType: resultIsInstance && bindToType && (0, types_1.isInstantiableClass)(bindToType)
|
5087
5171
|
? types_1.ClassType.cloneAsInstance(bindToType)
|
5088
5172
|
: bindToType,
|
5089
|
-
isSuperCall: true,
|
5090
5173
|
};
|
5091
5174
|
}
|
5092
5175
|
}
|
@@ -5096,11 +5179,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5096
5179
|
// If the class derives from one or more unknown classes,
|
5097
5180
|
// return unknown here to prevent spurious errors.
|
5098
5181
|
if (targetClassType.details.mro.some((mroBase) => (0, types_1.isAnyOrUnknown)(mroBase))) {
|
5099
|
-
return {
|
5100
|
-
type: types_1.UnknownType.create(),
|
5101
|
-
isSuperCall: true,
|
5102
|
-
node,
|
5103
|
-
};
|
5182
|
+
return { type: types_1.UnknownType.create() };
|
5104
5183
|
}
|
5105
5184
|
const baseClasses = targetClassType.details.baseClasses;
|
5106
5185
|
if (baseClasses.length > 0) {
|
@@ -5108,17 +5187,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5108
5187
|
if ((0, types_1.isInstantiableClass)(baseClassType)) {
|
5109
5188
|
return {
|
5110
5189
|
type: resultIsInstance ? types_1.ClassType.cloneAsInstance(baseClassType) : baseClassType,
|
5111
|
-
isSuperCall: true,
|
5112
|
-
node,
|
5113
5190
|
};
|
5114
5191
|
}
|
5115
5192
|
}
|
5116
5193
|
}
|
5117
|
-
return {
|
5118
|
-
type: types_1.UnknownType.create(),
|
5119
|
-
isSuperCall: true,
|
5120
|
-
node,
|
5121
|
-
};
|
5194
|
+
return { type: types_1.UnknownType.create() };
|
5122
5195
|
}
|
5123
5196
|
// Attempts to find an overloaded function for each set of argument
|
5124
5197
|
// types in the expandedArgTypes list. If an argument type is undefined,
|
@@ -5128,6 +5201,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5128
5201
|
// (one for each argument) will be undefined. On subsequent calls, this
|
5129
5202
|
// list will grow to include union expansions.
|
5130
5203
|
function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, expectedType) {
|
5204
|
+
var _a;
|
5131
5205
|
const returnTypes = [];
|
5132
5206
|
const matchedOverloads = [];
|
5133
5207
|
let isTypeIncomplete = false;
|
@@ -5149,11 +5223,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5149
5223
|
return argParamCopy;
|
5150
5224
|
});
|
5151
5225
|
}
|
5152
|
-
// Clone the typeVarContext so we don't modify the original.
|
5153
|
-
|
5154
|
-
|
5155
|
-
|
5226
|
+
// Clone the typeVarContext so we don't modify the original. If this is
|
5227
|
+
// not the first time through the loop, clone the type var context
|
5228
|
+
// from the previous successful match.
|
5229
|
+
const typeVarContextToClone = matchedOverloads.length > 0
|
5230
|
+
? matchedOverloads[matchedOverloads.length - 1].typeVarContext.clone()
|
5231
|
+
: typeVarContext;
|
5232
|
+
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));
|
5156
5233
|
effectiveTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(overload));
|
5234
|
+
effectiveTypeVarContext.unlock();
|
5157
5235
|
// Use speculative mode so we don't output any diagnostics or
|
5158
5236
|
// record any final types in the type cache.
|
5159
5237
|
const callResult = useSpeculativeMode(errorNode, () => {
|
@@ -5178,24 +5256,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5178
5256
|
return { argumentErrors: true, isTypeIncomplete };
|
5179
5257
|
}
|
5180
5258
|
}
|
5181
|
-
// We found a match for all of the expanded argument lists.
|
5182
|
-
//
|
5259
|
+
// We found a match for all of the expanded argument lists. Copy the
|
5260
|
+
// resulting type var context back into the caller's type var context.
|
5261
|
+
// Use the type var context from the last matched overload because it
|
5262
|
+
// includes the type var solutions for all earlier matched overloads.
|
5183
5263
|
if (typeVarContext) {
|
5184
|
-
|
5185
|
-
const overload = matchedOverloads[expandedTypesIndex].overload;
|
5186
|
-
const matchResults = matchedOverloads[expandedTypesIndex].matchResults;
|
5187
|
-
useSpeculativeMode(errorNode, () => {
|
5188
|
-
typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(overload));
|
5189
|
-
typeVarContext.unlock();
|
5190
|
-
return validateFunctionArgumentTypesWithExpectedType(errorNode, matchResults, typeVarContext,
|
5191
|
-
/* skipUnknownArgCheck */ true, expectedType);
|
5192
|
-
});
|
5193
|
-
}
|
5264
|
+
typeVarContext.copyFromClone(matchedOverloads[matchedOverloads.length - 1].typeVarContext);
|
5194
5265
|
}
|
5195
5266
|
// And run through the first expanded argument list one more time to
|
5196
5267
|
// populate the type cache.
|
5197
|
-
matchedOverloads[0].typeVarContext
|
5198
|
-
|
5268
|
+
const finalTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : matchedOverloads[0].typeVarContext;
|
5269
|
+
finalTypeVarContext.unlock();
|
5270
|
+
finalTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(matchedOverloads[0].overload));
|
5271
|
+
const finalCallResult = validateFunctionArgumentTypesWithExpectedType(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck, expectedType);
|
5199
5272
|
if (finalCallResult.isTypeIncomplete) {
|
5200
5273
|
isTypeIncomplete = true;
|
5201
5274
|
}
|
@@ -5210,15 +5283,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5210
5283
|
let overloadIndex = 0;
|
5211
5284
|
let matches = [];
|
5212
5285
|
// Create a list of potential overload matches based on arguments.
|
5213
|
-
type.
|
5286
|
+
types_1.OverloadedFunctionType.getOverloads(type).forEach((overload) => {
|
5214
5287
|
useSpeculativeMode(errorNode, () => {
|
5215
|
-
|
5216
|
-
|
5217
|
-
|
5218
|
-
matches.push(matchResults);
|
5219
|
-
}
|
5220
|
-
overloadIndex++;
|
5288
|
+
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, overload, overloadIndex);
|
5289
|
+
if (!matchResults.argumentErrors) {
|
5290
|
+
matches.push(matchResults);
|
5221
5291
|
}
|
5292
|
+
overloadIndex++;
|
5222
5293
|
});
|
5223
5294
|
});
|
5224
5295
|
matches = sortOverloadsByBestMatch(matches);
|
@@ -5255,17 +5326,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5255
5326
|
// cache or record any diagnostics at this stage.
|
5256
5327
|
useSpeculativeMode(errorNode, () => {
|
5257
5328
|
let overloadIndex = 0;
|
5258
|
-
type.
|
5329
|
+
types_1.OverloadedFunctionType.getOverloads(type).forEach((overload) => {
|
5259
5330
|
// Consider only the functions that have the @overload decorator,
|
5260
5331
|
// not the final function that omits the overload. This is the
|
5261
5332
|
// intended behavior according to PEP 484.
|
5262
|
-
|
5263
|
-
|
5264
|
-
|
5265
|
-
filteredMatchResults.push(matchResults);
|
5266
|
-
}
|
5267
|
-
overloadIndex++;
|
5333
|
+
const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, overload, overloadIndex);
|
5334
|
+
if (!matchResults.argumentErrors) {
|
5335
|
+
filteredMatchResults.push(matchResults);
|
5268
5336
|
}
|
5337
|
+
overloadIndex++;
|
5269
5338
|
});
|
5270
5339
|
});
|
5271
5340
|
filteredMatchResults = sortOverloadsByBestMatch(filteredMatchResults);
|
@@ -5841,7 +5910,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5841
5910
|
if ((0, types_1.isClassInstance)(subtype) ||
|
5842
5911
|
((0, types_1.isTypeVar)(subtype) && types_1.TypeBase.isInstance(subtype)) ||
|
5843
5912
|
(0, types_1.isNoneInstance)(subtype)) {
|
5844
|
-
return (0, typeUtils_1.convertToInstantiable)(
|
5913
|
+
return (0, typeUtils_1.convertToInstantiable)(stripLiteralValue(subtype));
|
5845
5914
|
}
|
5846
5915
|
return types_1.AnyType.create();
|
5847
5916
|
});
|
@@ -5880,18 +5949,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5880
5949
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotIntantiable().format({ type: className }), errorNode);
|
5881
5950
|
return types_1.AnyType.create();
|
5882
5951
|
}
|
5883
|
-
if (className
|
5884
|
-
|
5885
|
-
className === 'StrEnum' ||
|
5886
|
-
className === 'Flag' ||
|
5887
|
-
className === 'IntFlag') {
|
5888
|
-
return createEnumType(errorNode, expandedSubtype, argList);
|
5952
|
+
if ((0, enums_1.isKnownEnumType)(className)) {
|
5953
|
+
return (0, enums_1.createEnumType)(errorNode, expandedSubtype, argList);
|
5889
5954
|
}
|
5890
5955
|
if (className === 'TypedDict') {
|
5891
5956
|
return (0, typedDicts_1.createTypedDictType)(evaluatorInterface, errorNode, expandedSubtype, argList);
|
5892
5957
|
}
|
5893
5958
|
if (className === 'auto' && argList.length === 0) {
|
5894
|
-
return
|
5959
|
+
return (0, enums_1.getEnumAutoValueType)(evaluatorInterface, errorNode);
|
5895
5960
|
}
|
5896
5961
|
}
|
5897
5962
|
if (types_1.ClassType.supportsAbstractMethods(expandedSubtype)) {
|
@@ -6682,13 +6747,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6682
6747
|
reportedArgError = true;
|
6683
6748
|
}
|
6684
6749
|
return {
|
6685
|
-
type:
|
6750
|
+
type: stripLiteralValue(argType),
|
6686
6751
|
isUnbounded: argParam.argument.argumentCategory === 1 /* UnpackedList */,
|
6687
6752
|
};
|
6688
6753
|
});
|
6689
6754
|
const specializedTuple = types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, tupleTypeArgs,
|
6690
6755
|
/* isTypeArgumentExplicit */ true,
|
6691
|
-
/* stripLiterals */ true,
|
6692
6756
|
/* isUnpackedTuple */ true));
|
6693
6757
|
const combinedArg = {
|
6694
6758
|
paramCategory: 1 /* VarArgList */,
|
@@ -7220,7 +7284,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7220
7284
|
// strip literals before performing the assignment. This is used in
|
7221
7285
|
// places like a dict constructor.
|
7222
7286
|
if (argParam.paramCategory === 2 /* VarArgDictionary */ && (0, types_1.isTypeVar)(argParam.paramType)) {
|
7223
|
-
argType =
|
7287
|
+
argType = stripLiteralValue(argType);
|
7224
7288
|
}
|
7225
7289
|
// If there's a constraint filter, apply it to top-level type variables
|
7226
7290
|
// if appropriate. This doesn't properly handle non-top-level constrained
|
@@ -7407,9 +7471,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7407
7471
|
addError(localize_1.Localizer.Diagnostic.typeVarBoundAndConstrained(), argList[i].valueExpression || errorNode);
|
7408
7472
|
}
|
7409
7473
|
else {
|
7410
|
-
const argType = (_b = (_a = argList[i].typeResult) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : getTypeOfExpressionExpectingType(argList[i].valueExpression
|
7411
|
-
/* allowFinal */ undefined,
|
7412
|
-
/* allowRequired */ undefined).type;
|
7474
|
+
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;
|
7413
7475
|
if ((0, typeUtils_1.requiresSpecialization)(argType, /* ignorePseudoGeneric */ true)) {
|
7414
7476
|
addError(localize_1.Localizer.Diagnostic.typeVarGeneric(), argList[i].valueExpression || errorNode);
|
7415
7477
|
}
|
@@ -7446,9 +7508,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7446
7508
|
addError(localize_1.Localizer.Diagnostic.typeVarBoundAndConstrained(), argList[i].valueExpression || errorNode);
|
7447
7509
|
}
|
7448
7510
|
else {
|
7449
|
-
const argType = (_e = (_d = argList[i].typeResult) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : getTypeOfExpressionExpectingType(argList[i].valueExpression
|
7450
|
-
/* allowFinal */ undefined,
|
7451
|
-
/* allowRequired */ undefined).type;
|
7511
|
+
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;
|
7452
7512
|
if ((0, typeUtils_1.requiresSpecialization)(argType, /* ignorePseudoGeneric */ true)) {
|
7453
7513
|
addError(localize_1.Localizer.Diagnostic.typeVarGeneric(), argList[i].valueExpression || errorNode);
|
7454
7514
|
}
|
@@ -7538,80 +7598,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7538
7598
|
nameParts.push(moduleName);
|
7539
7599
|
return nameParts.reverse().join('.');
|
7540
7600
|
}
|
7541
|
-
// Creates a new custom enum class with named values.
|
7542
|
-
function createEnumType(errorNode, enumClass, argList) {
|
7543
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
7544
|
-
let className = 'enum';
|
7545
|
-
if (argList.length === 0) {
|
7546
|
-
return undefined;
|
7547
|
-
}
|
7548
|
-
else {
|
7549
|
-
const nameArg = argList[0];
|
7550
|
-
if (nameArg.argumentCategory === 0 /* Simple */ &&
|
7551
|
-
nameArg.valueExpression &&
|
7552
|
-
nameArg.valueExpression.nodeType === 48 /* StringList */) {
|
7553
|
-
className = nameArg.valueExpression.strings.map((s) => s.value).join('');
|
7554
|
-
}
|
7555
|
-
else {
|
7556
|
-
return undefined;
|
7557
|
-
}
|
7558
|
-
}
|
7559
|
-
const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.filePath, 1048576 /* EnumClass */, ParseTreeUtils.getTypeSourceId(errorNode),
|
7560
|
-
/* declaredMetaclass */ undefined, enumClass.details.effectiveMetaclass);
|
7561
|
-
classType.details.baseClasses.push(enumClass);
|
7562
|
-
(0, typeUtils_1.computeMroLinearization)(classType);
|
7563
|
-
const classFields = classType.details.fields;
|
7564
|
-
classFields.set('__class__', symbol_1.Symbol.createWithType(4 /* ClassMember */ | 64 /* IgnoredForProtocolMatch */, classType));
|
7565
|
-
if (argList.length < 2) {
|
7566
|
-
return undefined;
|
7567
|
-
}
|
7568
|
-
else {
|
7569
|
-
const entriesArg = argList[1];
|
7570
|
-
if (entriesArg.argumentCategory !== 0 /* Simple */ ||
|
7571
|
-
!entriesArg.valueExpression ||
|
7572
|
-
entriesArg.valueExpression.nodeType !== 48 /* StringList */) {
|
7573
|
-
// Technically, the Enum constructor supports a bunch of different
|
7574
|
-
// ways to specify the items: space-delimited string, a string
|
7575
|
-
// iterator, an iterator of name/value tuples, and a dictionary
|
7576
|
-
// of name/value pairs. We support only the simple space-delimited
|
7577
|
-
// string here. For users who are interested in type checking, we
|
7578
|
-
// recommend using the more standard class declaration syntax.
|
7579
|
-
return undefined;
|
7580
|
-
}
|
7581
|
-
else {
|
7582
|
-
const entries = entriesArg.valueExpression.strings
|
7583
|
-
.map((s) => s.value)
|
7584
|
-
.join('')
|
7585
|
-
.split(' ');
|
7586
|
-
entries.forEach((entryName) => {
|
7587
|
-
entryName = entryName.trim();
|
7588
|
-
if (entryName) {
|
7589
|
-
const entryType = types_1.UnknownType.create();
|
7590
|
-
const newSymbol = symbol_1.Symbol.createWithType(4 /* ClassMember */, entryType);
|
7591
|
-
// We need to associate the declaration with a parse node.
|
7592
|
-
// In this case it's just part of a string literal value.
|
7593
|
-
// The definition provider won't necessarily take the
|
7594
|
-
// user to the exact spot in the string, but it's close enough.
|
7595
|
-
const stringNode = entriesArg.valueExpression;
|
7596
|
-
(0, debug_1.assert)(stringNode.nodeType === 48 /* StringList */);
|
7597
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
7598
|
-
const declaration = {
|
7599
|
-
type: 1 /* Variable */,
|
7600
|
-
node: stringNode,
|
7601
|
-
isRuntimeTypeExpression: true,
|
7602
|
-
path: fileInfo.filePath,
|
7603
|
-
range: (0, positionUtils_1.convertOffsetsToRange)(stringNode.start, textRange_1.TextRange.getEnd(stringNode), fileInfo.lines),
|
7604
|
-
moduleName: fileInfo.moduleName,
|
7605
|
-
isInExceptSuite: false,
|
7606
|
-
};
|
7607
|
-
newSymbol.addDeclaration(declaration);
|
7608
|
-
classFields.set(entryName, newSymbol);
|
7609
|
-
}
|
7610
|
-
});
|
7611
|
-
}
|
7612
|
-
}
|
7613
|
-
return classType;
|
7614
|
-
}
|
7615
7601
|
// Implements the semantics of the NewType call as documented
|
7616
7602
|
// in the Python specification: The static type checker will treat
|
7617
7603
|
// the new type as if it were a subclass of the original type.
|
@@ -7726,14 +7712,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7726
7712
|
if (!type) {
|
7727
7713
|
return undefined;
|
7728
7714
|
}
|
7729
|
-
return { type
|
7715
|
+
return { type };
|
7730
7716
|
}
|
7731
7717
|
function getTypeOfUnaryOperation(node, expectedType) {
|
7732
7718
|
const exprTypeResult = getTypeOfExpression(node.expression);
|
7733
7719
|
let exprType = makeTopLevelTypeVarsConcrete(exprTypeResult.type);
|
7734
7720
|
const isIncomplete = exprTypeResult.isIncomplete;
|
7735
7721
|
if ((0, types_1.isNever)(exprType)) {
|
7736
|
-
return {
|
7722
|
+
return { type: types_1.NeverType.createNever(), isIncomplete };
|
7737
7723
|
}
|
7738
7724
|
// Map unary operators to magic functions. Note that the bitwise
|
7739
7725
|
// invert has two magic functions that are aliases of each other.
|
@@ -7812,16 +7798,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7812
7798
|
}
|
7813
7799
|
}
|
7814
7800
|
}
|
7815
|
-
return { type,
|
7816
|
-
}
|
7817
|
-
function operatorSupportsComparisonChaining(op) {
|
7818
|
-
if (binaryOperatorMap[op] && binaryOperatorMap[op][2]) {
|
7819
|
-
return true;
|
7820
|
-
}
|
7821
|
-
if (booleanOperatorMap[op]) {
|
7822
|
-
return true;
|
7823
|
-
}
|
7824
|
-
return false;
|
7801
|
+
return { type, isIncomplete };
|
7825
7802
|
}
|
7826
7803
|
function getTypeOfBinaryOperation(node, expectedType, flags) {
|
7827
7804
|
const leftExpression = node.leftExpression;
|
@@ -7830,10 +7807,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7830
7807
|
// If this is a comparison and the left expression is also a comparison,
|
7831
7808
|
// we need to change the behavior to accommodate python's "chained
|
7832
7809
|
// comparisons" feature.
|
7833
|
-
if (
|
7810
|
+
if (ParseTreeUtils.operatorSupportsChaining(node.operator)) {
|
7834
7811
|
if (rightExpression.nodeType === 7 /* BinaryOperation */ &&
|
7835
7812
|
!rightExpression.parenthesized &&
|
7836
|
-
|
7813
|
+
ParseTreeUtils.operatorSupportsChaining(rightExpression.operator)) {
|
7837
7814
|
// Evaluate the right expression so it is type checked.
|
7838
7815
|
getTypeOfBinaryOperation(rightExpression, expectedType, flags);
|
7839
7816
|
// Use the left side of the right expression for comparison purposes.
|
@@ -7910,15 +7887,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7910
7887
|
addError(localize_1.Localizer.Diagnostic.unionSyntaxIllegal(), node, node.operatorToken);
|
7911
7888
|
}
|
7912
7889
|
}
|
7913
|
-
if (!validateTypeArg(leftTypeResult, { allowVariadicTypeVar: true, allowUnpackedTuples: true }) ||
|
7914
|
-
!validateTypeArg(rightTypeResult, { allowVariadicTypeVar: true, allowUnpackedTuples: true })) {
|
7915
|
-
return { type: types_1.UnknownType.create()
|
7890
|
+
if (!validateTypeArg({ ...leftTypeResult, node: leftExpression }, { allowVariadicTypeVar: true, allowUnpackedTuples: true }) ||
|
7891
|
+
!validateTypeArg({ ...rightTypeResult, node: rightExpression }, { allowVariadicTypeVar: true, allowUnpackedTuples: true })) {
|
7892
|
+
return { type: types_1.UnknownType.create() };
|
7916
7893
|
}
|
7917
7894
|
const newUnion = (0, types_1.combineTypes)([adjustedLeftType, adjustedRightType]);
|
7918
7895
|
if ((0, types_1.isUnion)(newUnion)) {
|
7919
7896
|
types_1.TypeBase.setSpecialForm(newUnion);
|
7920
7897
|
}
|
7921
|
-
return { type: newUnion
|
7898
|
+
return { type: newUnion };
|
7922
7899
|
}
|
7923
7900
|
}
|
7924
7901
|
// Optional checks apply to all operations except for boolean operations.
|
@@ -7964,7 +7941,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7964
7941
|
}
|
7965
7942
|
type = types_1.UnknownType.create();
|
7966
7943
|
}
|
7967
|
-
return { type,
|
7944
|
+
return { type, isIncomplete };
|
7968
7945
|
}
|
7969
7946
|
function customMetaclassSupportsMethod(type, methodName) {
|
7970
7947
|
if (!(0, types_1.isInstantiableClass)(type)) {
|
@@ -8017,7 +7994,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8017
7994
|
const rightType = rightTypeResult.type;
|
8018
7995
|
const isIncomplete = !!rightTypeResult.isIncomplete || !!leftTypeResult.isIncomplete;
|
8019
7996
|
if ((0, types_1.isNever)(leftType) || (0, types_1.isNever)(rightType)) {
|
8020
|
-
typeResult = {
|
7997
|
+
typeResult = { type: types_1.NeverType.createNever(), isIncomplete };
|
8021
7998
|
}
|
8022
7999
|
else {
|
8023
8000
|
type = mapSubtypesExpandTypeVars(leftType,
|
@@ -8065,7 +8042,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8065
8042
|
}
|
8066
8043
|
type = types_1.UnknownType.create();
|
8067
8044
|
}
|
8068
|
-
typeResult = {
|
8045
|
+
typeResult = { type, isIncomplete };
|
8069
8046
|
}
|
8070
8047
|
assignTypeToExpression(node.destExpression, typeResult.type, !!typeResult.isIncomplete, node.rightExpression);
|
8071
8048
|
return typeResult;
|
@@ -8467,7 +8444,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8467
8444
|
if (resultTypedDict) {
|
8468
8445
|
return {
|
8469
8446
|
type: resultTypedDict,
|
8470
|
-
node,
|
8471
8447
|
isIncomplete,
|
8472
8448
|
};
|
8473
8449
|
}
|
@@ -8505,7 +8481,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8505
8481
|
return undefined;
|
8506
8482
|
}
|
8507
8483
|
const type = getBuiltInObject(node, 'dict', [specializedKeyType, specializedValueType]);
|
8508
|
-
return { type,
|
8484
|
+
return { type, isIncomplete };
|
8509
8485
|
}
|
8510
8486
|
// Attempts to infer the type of a dictionary statement. If hasExpectedType
|
8511
8487
|
// is true, strict inference is used for the subexpressions.
|
@@ -8522,8 +8498,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8522
8498
|
isIncomplete = true;
|
8523
8499
|
}
|
8524
8500
|
// Strip any literal values.
|
8525
|
-
keyTypes = keyTypes.map((t) =>
|
8526
|
-
valueTypes = valueTypes.map((t) =>
|
8501
|
+
keyTypes = keyTypes.map((t) => stripLiteralValue(t));
|
8502
|
+
valueTypes = valueTypes.map((t) => stripLiteralValue(t));
|
8527
8503
|
keyType = keyTypes.length > 0 ? (0, types_1.combineTypes)(keyTypes) : fallbackType;
|
8528
8504
|
// If the value type differs and we're not using "strict inference mode",
|
8529
8505
|
// we need to back off because we can't properly represent the mappings
|
@@ -8549,7 +8525,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8549
8525
|
/* includeSubclasses */ undefined,
|
8550
8526
|
/* TupleTypeArguments */ undefined, isEmptyContainer))
|
8551
8527
|
: types_1.UnknownType.create();
|
8552
|
-
return { type,
|
8528
|
+
return { type, isIncomplete };
|
8553
8529
|
}
|
8554
8530
|
function getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes, forceStrictInference, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum) {
|
8555
8531
|
let isIncomplete = false;
|
@@ -8727,7 +8703,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8727
8703
|
return undefined;
|
8728
8704
|
}
|
8729
8705
|
const type = getBuiltInObject(node, builtInClassName, [specializedEntryType]);
|
8730
|
-
return { type,
|
8706
|
+
return { type, isIncomplete };
|
8731
8707
|
}
|
8732
8708
|
// Attempts to infer the type of a list or set statement with no "expected type".
|
8733
8709
|
function getTypeOfListOrSetInferred(node, hasExpectedType) {
|
@@ -8751,7 +8727,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8751
8727
|
entryTypes.push(entryTypeResult.type);
|
8752
8728
|
}
|
8753
8729
|
});
|
8754
|
-
entryTypes = entryTypes.map((t) =>
|
8730
|
+
entryTypes = entryTypes.map((t) => stripLiteralValue(t));
|
8755
8731
|
let inferredEntryType = hasExpectedType ? types_1.AnyType.create() : types_1.UnknownType.create();
|
8756
8732
|
if (entryTypes.length > 0) {
|
8757
8733
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -8779,7 +8755,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8779
8755
|
/* includeSubclasses */ undefined,
|
8780
8756
|
/* TupleTypeArguments */ undefined, isEmptyContainer))
|
8781
8757
|
: types_1.UnknownType.create();
|
8782
|
-
return { type,
|
8758
|
+
return { type, isIncomplete };
|
8783
8759
|
}
|
8784
8760
|
function inferTypeArgFromExpectedType(expectedType, entryTypes, isNarrowable) {
|
8785
8761
|
let targetTypeVar;
|
@@ -8809,7 +8785,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8809
8785
|
if (useSynthesizedTypeVar) {
|
8810
8786
|
typeVarContext.setTypeVarType(targetTypeVar, isNarrowable ? undefined : expectedType, expectedType);
|
8811
8787
|
}
|
8812
|
-
if (entryTypes.every((entryType) => assignType(targetTypeVar,
|
8788
|
+
if (entryTypes.every((entryType) => assignType(targetTypeVar, stripLiteralValue(entryType), /* diag */ undefined, typeVarContext))) {
|
8813
8789
|
return (0, typeUtils_1.applySolvedTypeVars)(targetTypeVar, typeVarContext);
|
8814
8790
|
}
|
8815
8791
|
// Allocate a fresh typeVarContext before we try again with literals not stripped.
|
@@ -8841,7 +8817,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8841
8817
|
isIncomplete = true;
|
8842
8818
|
}
|
8843
8819
|
}
|
8844
|
-
return { type: (0, types_1.combineTypes)(typesToCombine),
|
8820
|
+
return { type: (0, types_1.combineTypes)(typesToCombine), isIncomplete };
|
8845
8821
|
}
|
8846
8822
|
function getTypeOfYield(node) {
|
8847
8823
|
let expectedYieldType;
|
@@ -8871,7 +8847,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8871
8847
|
isIncomplete = true;
|
8872
8848
|
}
|
8873
8849
|
}
|
8874
|
-
return { type: sentType || types_1.UnknownType.create(),
|
8850
|
+
return { type: sentType || types_1.UnknownType.create(), isIncomplete };
|
8875
8851
|
}
|
8876
8852
|
function getTypeOfYieldFrom(node) {
|
8877
8853
|
var _a;
|
@@ -8894,7 +8870,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8894
8870
|
returnedType = generatorTypeArgs.length >= 2 ? generatorTypeArgs[2] : types_1.UnknownType.create();
|
8895
8871
|
}
|
8896
8872
|
}
|
8897
|
-
return { type: returnedType || types_1.UnknownType.create()
|
8873
|
+
return { type: returnedType || types_1.UnknownType.create() };
|
8898
8874
|
}
|
8899
8875
|
function getTypeOfLambda(node, expectedType) {
|
8900
8876
|
let isIncomplete = false;
|
@@ -9013,7 +8989,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9013
8989
|
}
|
9014
8990
|
// Mark the function type as no longer being evaluated.
|
9015
8991
|
functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
|
9016
|
-
return { type: functionType,
|
8992
|
+
return { type: functionType, isIncomplete };
|
9017
8993
|
}
|
9018
8994
|
function getTypeOfListComprehension(node, expectedType) {
|
9019
8995
|
let isIncomplete = false;
|
@@ -9046,7 +9022,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9046
9022
|
: [elementType, types_1.NoneType.createInstance(), types_1.NoneType.createInstance()],
|
9047
9023
|
/* isTypeArgumentExplicit */ true));
|
9048
9024
|
}
|
9049
|
-
return { type,
|
9025
|
+
return { type, isIncomplete };
|
9050
9026
|
}
|
9051
9027
|
function reportPossibleUnknownAssignment(diagLevel, rule, target, type, errorNode, ignoreEmptyContainers) {
|
9052
9028
|
// Don't bother if the feature is disabled.
|
@@ -9083,7 +9059,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9083
9059
|
if (iterableTypeResult.isIncomplete) {
|
9084
9060
|
isIncomplete = true;
|
9085
9061
|
}
|
9086
|
-
const iterableType =
|
9062
|
+
const iterableType = stripLiteralValue(iterableTypeResult.type);
|
9087
9063
|
const itemType = (_a = getTypeOfIterator(iterableType, !!node.isAsync, node.iterableExpression)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
9088
9064
|
const targetExpr = node.targetExpression;
|
9089
9065
|
assignTypeToExpression(targetExpr, itemType, !!iterableTypeResult.isIncomplete, node.iterableExpression);
|
@@ -9119,7 +9095,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9119
9095
|
}
|
9120
9096
|
let keyType = keyTypeResult.type;
|
9121
9097
|
if (!expectedKeyType || !(0, typeUtils_1.containsLiteralType)(expectedKeyType)) {
|
9122
|
-
keyType =
|
9098
|
+
keyType = stripLiteralValue(keyType);
|
9123
9099
|
}
|
9124
9100
|
const valueTypeResult = getTypeOfExpression(node.expression.valueExpression,
|
9125
9101
|
/* flags */ undefined, expectedValueOrElementType);
|
@@ -9128,7 +9104,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9128
9104
|
}
|
9129
9105
|
let valueType = valueTypeResult.type;
|
9130
9106
|
if (!expectedValueOrElementType || !(0, typeUtils_1.containsLiteralType)(expectedValueOrElementType)) {
|
9131
|
-
valueType =
|
9107
|
+
valueType = stripLiteralValue(valueType);
|
9132
9108
|
}
|
9133
9109
|
type = makeTupleObject([keyType, valueType]);
|
9134
9110
|
}
|
@@ -9144,7 +9120,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9144
9120
|
}
|
9145
9121
|
type = exprTypeResult.type;
|
9146
9122
|
}
|
9147
|
-
return { type,
|
9123
|
+
return { type, isIncomplete };
|
9148
9124
|
}
|
9149
9125
|
function getTypeOfSlice(node) {
|
9150
9126
|
// Evaluate the expressions to report errors and record symbol
|
@@ -9160,7 +9136,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9160
9136
|
getTypeOfExpression(node.stepValue);
|
9161
9137
|
}
|
9162
9138
|
}
|
9163
|
-
return { type: getBuiltInObject(node, 'slice')
|
9139
|
+
return { type: getBuiltInObject(node, 'slice') };
|
9164
9140
|
}
|
9165
9141
|
// Verifies that a type argument's type is not disallowed.
|
9166
9142
|
function validateTypeArg(argResult, options) {
|
@@ -9765,8 +9741,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9765
9741
|
}
|
9766
9742
|
});
|
9767
9743
|
}
|
9768
|
-
returnType = (0, typeUtils_1.specializeTupleClass)(classType, tupleTypeArgTypes, typeArgs !== undefined
|
9769
|
-
/* stripLiterals */ false);
|
9744
|
+
returnType = (0, typeUtils_1.specializeTupleClass)(classType, tupleTypeArgTypes, typeArgs !== undefined);
|
9770
9745
|
}
|
9771
9746
|
else {
|
9772
9747
|
returnType = types_1.ClassType.cloneForSpecialization(classType, typeArgTypes, typeArgs !== undefined);
|
@@ -9860,49 +9835,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9860
9835
|
}
|
9861
9836
|
return createSpecialType(classType, typeArgs, /* paramLimit */ undefined, /* allowParamSpec */ true);
|
9862
9837
|
}
|
9863
|
-
function transformTypeForPossibleEnumClass(node, getValueType) {
|
9864
|
-
var _a, _b, _c, _d;
|
9865
|
-
// If the node is within a class that derives from the metaclass
|
9866
|
-
// "EnumMeta", we need to treat assignments differently.
|
9867
|
-
const enclosingClassNode = ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true);
|
9868
|
-
if (enclosingClassNode) {
|
9869
|
-
const enumClassInfo = getTypeOfClass(enclosingClassNode);
|
9870
|
-
if (enumClassInfo && types_1.ClassType.isEnumClass(enumClassInfo.classType)) {
|
9871
|
-
// In ".py" files, the transform applies only to members that are
|
9872
|
-
// assigned within the class. In stub files, it applies to most variables
|
9873
|
-
// even if they are not assigned. This unfortunate convention means
|
9874
|
-
// there is no way in a stub to specify both enum members and instance
|
9875
|
-
// variables used within each enum instance. Unless/until there is
|
9876
|
-
// a change to this convention and all type checkers and stubs adopt
|
9877
|
-
// it, we're stuck with this limitation.
|
9878
|
-
let isMemberOfEnumeration = (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* Assignment */ && node.parent.leftExpression === node) ||
|
9879
|
-
(((_b = node.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 54 /* TypeAnnotation */ &&
|
9880
|
-
node.parent.valueExpression === node &&
|
9881
|
-
((_c = node.parent.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 3 /* Assignment */) ||
|
9882
|
-
(AnalyzerNodeInfo.getFileInfo(node).isStubFile &&
|
9883
|
-
((_d = node.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 54 /* TypeAnnotation */ &&
|
9884
|
-
node.parent.valueExpression === node);
|
9885
|
-
// The spec specifically excludes names that start and end with a single underscore.
|
9886
|
-
// This also includes dunder names.
|
9887
|
-
if ((0, symbolNameUtils_1.isSingleDunderName)(node.value)) {
|
9888
|
-
isMemberOfEnumeration = false;
|
9889
|
-
}
|
9890
|
-
// Specifically exclude "value" and "name". These are reserved by the enum metaclass.
|
9891
|
-
if (node.value === 'name' || node.value === 'value') {
|
9892
|
-
isMemberOfEnumeration = false;
|
9893
|
-
}
|
9894
|
-
const valueType = getValueType();
|
9895
|
-
// The spec excludes descriptors.
|
9896
|
-
if ((0, types_1.isClassInstance)(valueType) && valueType.details.fields.get('__get__')) {
|
9897
|
-
isMemberOfEnumeration = false;
|
9898
|
-
}
|
9899
|
-
if (isMemberOfEnumeration) {
|
9900
|
-
return types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneWithLiteral(enumClassInfo.classType, new types_1.EnumLiteral(enumClassInfo.classType.details.name, node.value, valueType)));
|
9901
|
-
}
|
9902
|
-
}
|
9903
|
-
}
|
9904
|
-
return undefined;
|
9905
|
-
}
|
9906
9838
|
function transformTypeForTypeAlias(type, name, errorNode, typeParameters) {
|
9907
9839
|
if (!types_1.TypeBase.isInstantiable(type)) {
|
9908
9840
|
return type;
|
@@ -10192,7 +10124,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10192
10124
|
rightHandType = srcType;
|
10193
10125
|
if (node.leftExpression.nodeType === 38 /* Name */ && !node.typeAnnotationComment) {
|
10194
10126
|
rightHandType =
|
10195
|
-
transformTypeForPossibleEnumClass(node.leftExpression, () => rightHandType) || rightHandType;
|
10127
|
+
(0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node.leftExpression, () => rightHandType) || rightHandType;
|
10196
10128
|
}
|
10197
10129
|
if (typeAliasNameNode) {
|
10198
10130
|
// Clear out the temporary types we wrote above.
|
@@ -10296,6 +10228,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10296
10228
|
const destTypeResult = getTypeOfAugmentedAssignment(node, /* expectedType */ undefined);
|
10297
10229
|
writeTypeCache(node, destTypeResult.type, 0 /* None */, !!destTypeResult.isIncomplete);
|
10298
10230
|
}
|
10231
|
+
function getPseudoGenericTypeVarName(paramName) {
|
10232
|
+
return `__type_of_${paramName}`;
|
10233
|
+
}
|
10299
10234
|
function getTypeOfClass(node) {
|
10300
10235
|
// Is this type already cached?
|
10301
10236
|
const cachedClassType = readTypeCache(node.name, 0 /* None */);
|
@@ -10609,13 +10544,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10609
10544
|
const initParams = initDeclNode.parameters;
|
10610
10545
|
if (initParams.length > 1 &&
|
10611
10546
|
!initParams.some((param, index) => !!ParseTreeUtils.getTypeAnnotationForParameter(initDeclNode, index))) {
|
10612
|
-
const genericParams = initParams.filter((param, index) => index > 0 &&
|
10547
|
+
const genericParams = initParams.filter((param, index) => index > 0 &&
|
10548
|
+
param.name &&
|
10549
|
+
param.category === 0 /* Simple */ &&
|
10550
|
+
!param.defaultValue);
|
10613
10551
|
if (genericParams.length > 0) {
|
10614
10552
|
classType.details.flags |= 16384 /* PseudoGenericClass */;
|
10615
10553
|
// Create a type parameter for each simple, named parameter
|
10616
10554
|
// in the __init__ method.
|
10617
10555
|
classType.details.typeParameters = genericParams.map((param) => {
|
10618
|
-
const typeVar = types_1.TypeVarType.createInstance(
|
10556
|
+
const typeVar = types_1.TypeVarType.createInstance(getPseudoGenericTypeVarName(param.name.value));
|
10619
10557
|
typeVar.details.isSynthesized = true;
|
10620
10558
|
typeVar.scopeId = getScopeIdForNode(initDeclNode);
|
10621
10559
|
typeVar.details.boundType = types_1.UnknownType.create();
|
@@ -11149,7 +11087,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11149
11087
|
types_1.ClassType.isPseudoGenericClass(containingClassType) &&
|
11150
11088
|
node.name.value === '__init__';
|
11151
11089
|
const paramTypes = [];
|
11152
|
-
let typeParamIndex = 0;
|
11153
11090
|
// Determine if the first parameter should be skipped for comment-based
|
11154
11091
|
// function annotations.
|
11155
11092
|
let firstCommentAnnotationIndex = 0;
|
@@ -11232,9 +11169,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11232
11169
|
}
|
11233
11170
|
}
|
11234
11171
|
if (!annotatedType && addGenericParamTypes) {
|
11235
|
-
if (index > 0 && param.category === 0 /* Simple */ && param.name) {
|
11236
|
-
|
11237
|
-
|
11172
|
+
if (index > 0 && param.category === 0 /* Simple */ && param.name && !param.defaultValue) {
|
11173
|
+
const typeParamName = getPseudoGenericTypeVarName(param.name.value);
|
11174
|
+
annotatedType = containingClassType.details.typeParameters.find((param) => param.details.name === typeParamName);
|
11238
11175
|
}
|
11239
11176
|
}
|
11240
11177
|
if (annotatedType) {
|
@@ -11523,7 +11460,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11523
11460
|
// more restrictive (narrower) than intended.
|
11524
11461
|
if (!(0, types_1.isClassInstance)(defaultValueType) ||
|
11525
11462
|
!types_1.ClassType.isBuiltIn(defaultValueType, ['tuple', 'list', 'set', 'dict'])) {
|
11526
|
-
inferredParamType =
|
11463
|
+
inferredParamType = stripLiteralValue(defaultValueType);
|
11527
11464
|
}
|
11528
11465
|
}
|
11529
11466
|
if (inferredParamType) {
|
@@ -11553,8 +11490,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11553
11490
|
}
|
11554
11491
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
11555
11492
|
return types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type, isUnbounded: !(0, types_1.isVariadicTypeVar)(type) }],
|
11556
|
-
/* isTypeArgumentExplicit */ true
|
11557
|
-
/* stripLiterals */ true));
|
11493
|
+
/* isTypeArgumentExplicit */ true));
|
11558
11494
|
}
|
11559
11495
|
return types_1.UnknownType.create();
|
11560
11496
|
}
|
@@ -11869,7 +11805,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11869
11805
|
if (inferredReturnType) {
|
11870
11806
|
return { type: inferredReturnType, isIncomplete };
|
11871
11807
|
}
|
11872
|
-
if (functionRecursionMap.has(node.id)
|
11808
|
+
if (functionRecursionMap.has(node.id) || functionRecursionMap.size >= maxInferFunctionReturnRecursionCount) {
|
11873
11809
|
inferredReturnType = types_1.UnknownType.create();
|
11874
11810
|
isIncomplete = true;
|
11875
11811
|
}
|
@@ -12110,7 +12046,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12110
12046
|
}
|
12111
12047
|
// For "async while", an implicit "await" is performed.
|
12112
12048
|
if (isAsync) {
|
12113
|
-
memberReturnType = getTypeOfAwaitable(memberReturnType, node);
|
12049
|
+
memberReturnType = getTypeOfAwaitable(memberReturnType, node.expression);
|
12114
12050
|
}
|
12115
12051
|
return memberReturnType;
|
12116
12052
|
}
|
@@ -12308,6 +12244,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12308
12244
|
assignTypeToNameNode(symbolNameNode, symbolType, /* isIncomplete */ false, /* ignoreEmptyContainers */ false);
|
12309
12245
|
writeTypeCache(node, symbolType, 0 /* None */, /* isIncomplete */ false);
|
12310
12246
|
}
|
12247
|
+
function evaluateTypesForTypeAnnotationNode(node) {
|
12248
|
+
var _a;
|
12249
|
+
// If this node is part of an assignment statement, use specialized
|
12250
|
+
// logic that performs bidirectional inference and assignment
|
12251
|
+
// type narrowing.
|
12252
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* Assignment */) {
|
12253
|
+
evaluateTypesForAssignmentStatement(node.parent);
|
12254
|
+
}
|
12255
|
+
else {
|
12256
|
+
const annotationType = getTypeOfAnnotation(node.typeAnnotation, {
|
12257
|
+
isVariableAnnotation: true,
|
12258
|
+
allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(node.valueExpression),
|
12259
|
+
allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(node.valueExpression),
|
12260
|
+
});
|
12261
|
+
writeTypeCache(node.valueExpression, annotationType, 0 /* None */, /* isIncomplete */ false);
|
12262
|
+
}
|
12263
|
+
}
|
12311
12264
|
function getAliasedSymbolTypeForName(node, name) {
|
12312
12265
|
const symbolWithScope = lookUpSymbolRecursive(node, name, /* honorCodeFlow */ true);
|
12313
12266
|
if (!symbolWithScope) {
|
@@ -12368,62 +12321,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12368
12321
|
// allows for bidirectional type evaluation.
|
12369
12322
|
function evaluateTypesForExpressionInContext(node) {
|
12370
12323
|
var _a, _b, _c, _d, _e;
|
12371
|
-
let lastContextualExpression = node;
|
12372
|
-
let curNode = node;
|
12373
|
-
function isContextual(node) {
|
12374
|
-
var _a, _b, _c, _d, _e;
|
12375
|
-
// Parameters are contextual only for lambdas.
|
12376
|
-
if (node.nodeType === 41 /* Parameter */ && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 30 /* Lambda */) {
|
12377
|
-
return true;
|
12378
|
-
}
|
12379
|
-
// Arguments are contextual only for call and index nodes.
|
12380
|
-
if (node.nodeType === 1 /* Argument */ &&
|
12381
|
-
(((_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 */)) {
|
12382
|
-
return true;
|
12383
|
-
}
|
12384
|
-
// All nodes within a type annotation need to be evaluated
|
12385
|
-
// contextually so we pass the "type expected" flag to
|
12386
|
-
// the evaluator.
|
12387
|
-
if (((_d = node.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 54 /* TypeAnnotation */) {
|
12388
|
-
return true;
|
12389
|
-
}
|
12390
|
-
if (((_e = node.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 41 /* Parameter */ &&
|
12391
|
-
(node === node.parent.typeAnnotation || node === node.parent.typeAnnotationComment)) {
|
12392
|
-
return true;
|
12393
|
-
}
|
12394
|
-
// The | operator is contextual in cases where it is used to describe a
|
12395
|
-
// union in type annotations.
|
12396
|
-
if (node.nodeType === 7 /* BinaryOperation */ && node.operator === 6 /* BitwiseOr */) {
|
12397
|
-
return true;
|
12398
|
-
}
|
12399
|
-
return (node.nodeType === 9 /* Call */ ||
|
12400
|
-
node.nodeType === 24 /* Index */ ||
|
12401
|
-
node.nodeType === 15 /* Dictionary */ ||
|
12402
|
-
node.nodeType === 27 /* FormatString */ ||
|
12403
|
-
node.nodeType === 31 /* List */ ||
|
12404
|
-
node.nodeType === 30 /* Lambda */ ||
|
12405
|
-
node.nodeType === 35 /* MemberAccess */ ||
|
12406
|
-
node.nodeType === 45 /* Set */ ||
|
12407
|
-
node.nodeType === 49 /* String */ ||
|
12408
|
-
node.nodeType === 48 /* StringList */ ||
|
12409
|
-
node.nodeType === 52 /* Tuple */ ||
|
12410
|
-
node.nodeType === 56 /* Unpack */ ||
|
12411
|
-
node.nodeType === 17 /* DictionaryKeyEntry */ ||
|
12412
|
-
node.nodeType === 16 /* DictionaryExpandEntry */ ||
|
12413
|
-
node.nodeType === 32 /* ListComprehension */ ||
|
12414
|
-
node.nodeType === 33 /* ListComprehensionFor */ ||
|
12415
|
-
node.nodeType === 34 /* ListComprehensionIf */ ||
|
12416
|
-
node.nodeType === 65 /* PatternSequence */ ||
|
12417
|
-
node.nodeType === 67 /* PatternLiteral */ ||
|
12418
|
-
node.nodeType === 68 /* PatternClass */ ||
|
12419
|
-
node.nodeType === 74 /* PatternClassArgument */ ||
|
12420
|
-
node.nodeType === 66 /* PatternAs */ ||
|
12421
|
-
node.nodeType === 69 /* PatternCapture */ ||
|
12422
|
-
node.nodeType === 70 /* PatternMapping */ ||
|
12423
|
-
node.nodeType === 73 /* PatternValue */ ||
|
12424
|
-
node.nodeType === 71 /* PatternMappingKeyEntry */ ||
|
12425
|
-
node.nodeType === 72 /* PatternMappingExpandEntry */);
|
12426
|
-
}
|
12427
12324
|
// Check for a couple of special cases where the node is a NameNode but
|
12428
12325
|
// is technically not part of an expression. We'll handle these here so
|
12429
12326
|
// callers don't need to include special-case logic.
|
@@ -12432,154 +12329,235 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12432
12329
|
getTypeOfFunction(node.parent);
|
12433
12330
|
return;
|
12434
12331
|
}
|
12435
|
-
|
12332
|
+
if (node.parent.nodeType === 10 /* Class */ && node.parent.name === node) {
|
12436
12333
|
getTypeOfClass(node.parent);
|
12437
12334
|
return;
|
12438
12335
|
}
|
12439
|
-
|
12336
|
+
if (node.parent.nodeType === 77 /* TypeAlias */ && node.parent.name === node) {
|
12440
12337
|
getTypeOfTypeAlias(node.parent);
|
12441
12338
|
return;
|
12442
12339
|
}
|
12443
|
-
|
12444
|
-
node.parent.nodeType === 39 /* Nonlocal */) {
|
12340
|
+
if (node.parent.nodeType === 29 /* Global */ || node.parent.nodeType === 39 /* Nonlocal */) {
|
12445
12341
|
// For global and nonlocal statements, allow forward references so
|
12446
12342
|
// we don't use code flow during symbol lookups.
|
12447
12343
|
getTypeOfExpression(node, 4 /* AllowForwardReferences */);
|
12448
12344
|
return;
|
12449
12345
|
}
|
12346
|
+
if (node.parent.nodeType === 37 /* ModuleName */) {
|
12347
|
+
// A name within a module name isn't an expression,
|
12348
|
+
// so there's nothing we can evaluate here.
|
12349
|
+
return;
|
12350
|
+
}
|
12450
12351
|
}
|
12451
|
-
//
|
12452
|
-
//
|
12453
|
-
|
12454
|
-
|
12455
|
-
|
12456
|
-
|
12352
|
+
// If the expression is part of a type annotation, we need to evaluate
|
12353
|
+
// it with special evaluation flags.
|
12354
|
+
const annotationNode = ParseTreeUtils.getParentAnnotationNode(node);
|
12355
|
+
if (annotationNode) {
|
12356
|
+
// Annotations need to be evaluated with specialized evaluation flags.
|
12357
|
+
const annotationParent = annotationNode.parent;
|
12358
|
+
(0, debug_1.assert)(annotationParent !== undefined);
|
12359
|
+
if (annotationParent.nodeType === 3 /* Assignment */) {
|
12360
|
+
if (annotationNode === annotationParent.typeAnnotationComment) {
|
12361
|
+
getTypeOfAnnotation(annotationNode, {
|
12362
|
+
isVariableAnnotation: true,
|
12363
|
+
allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(annotationParent.leftExpression),
|
12364
|
+
allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(annotationParent.leftExpression),
|
12365
|
+
});
|
12366
|
+
}
|
12367
|
+
else {
|
12368
|
+
evaluateTypesForAssignmentStatement(annotationParent);
|
12369
|
+
}
|
12370
|
+
return;
|
12457
12371
|
}
|
12458
|
-
if (
|
12459
|
-
|
12372
|
+
if (annotationParent.nodeType === 54 /* TypeAnnotation */) {
|
12373
|
+
evaluateTypesForTypeAnnotationNode(annotationParent);
|
12374
|
+
return;
|
12460
12375
|
}
|
12461
|
-
|
12462
|
-
|
12463
|
-
|
12464
|
-
|
12465
|
-
|
12466
|
-
getTypeOfAnnotation(lastContextualExpression, {
|
12467
|
-
isVariableAnnotation: true,
|
12468
|
-
allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(parent.leftExpression),
|
12469
|
-
allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(parent.leftExpression),
|
12376
|
+
if (annotationParent.nodeType === 28 /* Function */ &&
|
12377
|
+
annotationNode === annotationParent.returnTypeAnnotation) {
|
12378
|
+
getTypeOfAnnotation(annotationNode, {
|
12379
|
+
associateTypeVarsWithScope: true,
|
12380
|
+
disallowRecursiveTypeAlias: true,
|
12470
12381
|
});
|
12382
|
+
return;
|
12471
12383
|
}
|
12472
|
-
|
12473
|
-
evaluateTypesForAssignmentStatement(parent);
|
12474
|
-
}
|
12384
|
+
getTypeOfAnnotation(annotationNode);
|
12475
12385
|
return;
|
12476
12386
|
}
|
12477
|
-
|
12478
|
-
|
12479
|
-
|
12480
|
-
|
12481
|
-
|
12482
|
-
|
12483
|
-
if (parent.nodeType === 75 /* TypeParameter */ && lastContextualExpression === parent.name) {
|
12484
|
-
if (((_a = parent.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 76 /* TypeParameterList */ &&
|
12485
|
-
((_b = parent.parent.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 77 /* TypeAlias */) {
|
12486
|
-
getTypeOfTypeAlias(parent.parent.parent);
|
12387
|
+
// See if the expression is part of a pattern used in a case statement.
|
12388
|
+
const possibleCaseNode = ParseTreeUtils.getParentNodeOfType(node, 64 /* Case */);
|
12389
|
+
if (possibleCaseNode) {
|
12390
|
+
const caseNode = possibleCaseNode;
|
12391
|
+
if (ParseTreeUtils.isNodeContainedWithin(node, caseNode.pattern)) {
|
12392
|
+
evaluateTypesForCaseStatement(caseNode);
|
12487
12393
|
return;
|
12488
12394
|
}
|
12489
12395
|
}
|
12490
|
-
|
12491
|
-
|
12492
|
-
|
12493
|
-
|
12494
|
-
|
12495
|
-
|
12496
|
-
|
12497
|
-
|
12498
|
-
|
12499
|
-
|
12500
|
-
|
12501
|
-
|
12502
|
-
|
12503
|
-
|
12504
|
-
|
12396
|
+
// Scan up the parse tree until we find a node that doesn't
|
12397
|
+
// require any context to be evaluated.
|
12398
|
+
let nodeToEvaluate = node;
|
12399
|
+
let flags = 0 /* None */;
|
12400
|
+
while (true) {
|
12401
|
+
// If we're within an argument node in a call or index expression, skip
|
12402
|
+
// all of the nodes between because the entire argument expression
|
12403
|
+
// needs to be evaluated contextually.
|
12404
|
+
const argumentNode = ParseTreeUtils.getParentNodeOfType(nodeToEvaluate, 1 /* Argument */);
|
12405
|
+
if (argumentNode && argumentNode !== nodeToEvaluate) {
|
12406
|
+
(0, debug_1.assert)(argumentNode.parent !== undefined);
|
12407
|
+
if (argumentNode.parent.nodeType === 9 /* Call */ ||
|
12408
|
+
argumentNode.parent.nodeType === 24 /* Index */) {
|
12409
|
+
nodeToEvaluate = argumentNode.parent;
|
12410
|
+
continue;
|
12411
|
+
}
|
12505
12412
|
}
|
12506
|
-
|
12507
|
-
|
12413
|
+
let parent = nodeToEvaluate.parent;
|
12414
|
+
if (!parent) {
|
12415
|
+
break;
|
12508
12416
|
}
|
12509
|
-
|
12510
|
-
|
12511
|
-
|
12512
|
-
|
12513
|
-
|
12514
|
-
|
12417
|
+
// If this is the target of an assignment expression, evaluate the
|
12418
|
+
// assignment expression node instead.
|
12419
|
+
if (parent.nodeType === 4 /* AssignmentExpression */ && nodeToEvaluate === parent.name) {
|
12420
|
+
nodeToEvaluate = parent;
|
12421
|
+
continue;
|
12422
|
+
}
|
12423
|
+
// The left expression of a call or member access expression is not contextual.
|
12424
|
+
if (parent.nodeType === 9 /* Call */ || parent.nodeType === 35 /* MemberAccess */) {
|
12425
|
+
if (nodeToEvaluate === parent.leftExpression) {
|
12426
|
+
// Handle the special case where the LHS is a call to super().
|
12427
|
+
if (nodeToEvaluate.nodeType === 9 /* Call */ &&
|
12428
|
+
nodeToEvaluate.leftExpression.nodeType === 38 /* Name */ &&
|
12429
|
+
nodeToEvaluate.leftExpression.value === 'super') {
|
12430
|
+
nodeToEvaluate = parent;
|
12431
|
+
continue;
|
12432
|
+
}
|
12433
|
+
flags = 2 /* DoNotSpecialize */;
|
12434
|
+
break;
|
12435
|
+
}
|
12436
|
+
}
|
12437
|
+
else if (parent.nodeType === 24 /* Index */) {
|
12438
|
+
// The base expression of an index expression is not contextual.
|
12439
|
+
if (nodeToEvaluate === parent.baseExpression) {
|
12440
|
+
flags = 2 /* DoNotSpecialize */;
|
12441
|
+
break;
|
12442
|
+
}
|
12515
12443
|
}
|
12516
12444
|
else {
|
12517
|
-
|
12518
|
-
|
12519
|
-
|
12520
|
-
|
12521
|
-
|
12522
|
-
|
12445
|
+
// Check for expression types that are always contextual.
|
12446
|
+
if (nodeToEvaluate.nodeType !== 15 /* Dictionary */ &&
|
12447
|
+
nodeToEvaluate.nodeType !== 31 /* List */ &&
|
12448
|
+
nodeToEvaluate.nodeType !== 30 /* Lambda */ &&
|
12449
|
+
nodeToEvaluate.nodeType !== 45 /* Set */ &&
|
12450
|
+
nodeToEvaluate.nodeType !== 52 /* Tuple */ &&
|
12451
|
+
nodeToEvaluate.nodeType !== 56 /* Unpack */ &&
|
12452
|
+
nodeToEvaluate.nodeType !== 32 /* ListComprehension */) {
|
12453
|
+
break;
|
12454
|
+
}
|
12523
12455
|
}
|
12524
|
-
|
12525
|
-
|
12526
|
-
|
12527
|
-
|
12528
|
-
|
12529
|
-
|
12530
|
-
|
12531
|
-
|
12532
|
-
|
12533
|
-
|
12534
|
-
|
12535
|
-
|
12456
|
+
if (!(0, parseNodes_1.isExpressionNode)(parent)) {
|
12457
|
+
// If we've hit a non-expression node, we generally want to
|
12458
|
+
// stop. However, there are a few special "pass through"
|
12459
|
+
// node types that we can skip over to get to a known
|
12460
|
+
// expression node.
|
12461
|
+
if (parent.nodeType === 17 /* DictionaryKeyEntry */ ||
|
12462
|
+
parent.nodeType === 16 /* DictionaryExpandEntry */ ||
|
12463
|
+
parent.nodeType === 33 /* ListComprehensionFor */ ||
|
12464
|
+
parent.nodeType === 34 /* ListComprehensionIf */) {
|
12465
|
+
(0, debug_1.assert)(parent.parent !== undefined && (0, parseNodes_1.isExpressionNode)(parent.parent));
|
12466
|
+
parent = parent.parent;
|
12467
|
+
}
|
12468
|
+
else if (parent.nodeType === 41 /* Parameter */) {
|
12469
|
+
(0, debug_1.assert)(parent.parent !== undefined);
|
12470
|
+
// Parameters are contextual for lambdas.
|
12471
|
+
if (parent.parent.nodeType === 30 /* Lambda */) {
|
12472
|
+
parent = parent.parent;
|
12473
|
+
}
|
12474
|
+
else {
|
12475
|
+
break;
|
12476
|
+
}
|
12477
|
+
}
|
12478
|
+
else {
|
12479
|
+
break;
|
12480
|
+
}
|
12481
|
+
}
|
12482
|
+
nodeToEvaluate = parent;
|
12536
12483
|
}
|
12537
|
-
|
12538
|
-
|
12539
|
-
|
12540
|
-
|
12541
|
-
|
12542
|
-
|
12484
|
+
const parent = nodeToEvaluate.parent;
|
12485
|
+
(0, debug_1.assert)(parent !== undefined);
|
12486
|
+
switch (parent.nodeType) {
|
12487
|
+
case 14 /* Del */: {
|
12488
|
+
verifyDeleteExpression(nodeToEvaluate);
|
12489
|
+
return;
|
12490
|
+
}
|
12491
|
+
case 75 /* TypeParameter */: {
|
12492
|
+
// If this is the name node within a type parameter list, see if it's a type alias
|
12493
|
+
// definition. If so, we need to evaluate the type alias contextually.
|
12494
|
+
if (nodeToEvaluate === parent.name &&
|
12495
|
+
((_a = parent.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 76 /* TypeParameterList */ &&
|
12496
|
+
((_b = parent.parent.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 77 /* TypeAlias */) {
|
12497
|
+
getTypeOfTypeAlias(parent.parent.parent);
|
12498
|
+
return;
|
12499
|
+
}
|
12500
|
+
break;
|
12501
|
+
}
|
12502
|
+
case 77 /* TypeAlias */: {
|
12503
|
+
getTypeOfTypeAlias(parent);
|
12504
|
+
return;
|
12505
|
+
}
|
12506
|
+
case 13 /* Decorator */: {
|
12507
|
+
if (((_c = parent.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 10 /* Class */) {
|
12508
|
+
getTypeOfClass(parent.parent);
|
12509
|
+
}
|
12510
|
+
else if (((_d = parent.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 28 /* Function */) {
|
12511
|
+
getTypeOfFunction(parent.parent);
|
12512
|
+
}
|
12513
|
+
return;
|
12514
|
+
}
|
12515
|
+
case 41 /* Parameter */: {
|
12516
|
+
if (nodeToEvaluate !== parent.defaultValue) {
|
12517
|
+
evaluateTypeOfParameter(parent);
|
12518
|
+
return;
|
12519
|
+
}
|
12520
|
+
break;
|
12521
|
+
}
|
12522
|
+
case 1 /* Argument */: {
|
12523
|
+
if (nodeToEvaluate === parent.name) {
|
12524
|
+
// A name used to specify a named parameter in an argument isn't an
|
12525
|
+
// expression, so there's nothing we can evaluate here.
|
12526
|
+
return;
|
12527
|
+
}
|
12528
|
+
if (((_e = parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 10 /* Class */) {
|
12529
|
+
// A class argument must be evaluated in the context of the class declaration.
|
12530
|
+
getTypeOfClass(parent.parent);
|
12531
|
+
return;
|
12532
|
+
}
|
12533
|
+
break;
|
12534
|
+
}
|
12535
|
+
case 44 /* Return */: {
|
12536
|
+
// Return expressions must be evaluated in the context of the expected return type.
|
12537
|
+
if (parent.returnExpression) {
|
12538
|
+
const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(node);
|
12539
|
+
const declaredReturnType = enclosingFunctionNode
|
12540
|
+
? getFunctionDeclaredReturnType(enclosingFunctionNode)
|
12541
|
+
: undefined;
|
12542
|
+
getTypeOfExpression(parent.returnExpression, 0 /* None */, declaredReturnType);
|
12543
|
+
return;
|
12544
|
+
}
|
12545
|
+
break;
|
12546
|
+
}
|
12547
|
+
case 54 /* TypeAnnotation */: {
|
12548
|
+
evaluateTypesForTypeAnnotationNode(parent);
|
12549
|
+
return;
|
12550
|
+
}
|
12551
|
+
case 3 /* Assignment */: {
|
12552
|
+
evaluateTypesForAssignmentStatement(parent);
|
12543
12553
|
return;
|
12544
12554
|
}
|
12545
12555
|
}
|
12546
|
-
if (parent.nodeType === 37 /* ModuleName */) {
|
12547
|
-
// A name within a module name isn't an expression,
|
12548
|
-
// so there's nothing we can evaluate here.
|
12549
|
-
return;
|
12550
|
-
}
|
12551
|
-
if (parent.nodeType === 1 /* Argument */ && lastContextualExpression === parent.name) {
|
12552
|
-
// A name used to specify a named parameter in an argument isn't an
|
12553
|
-
// expression, so there's nothing we can evaluate here.
|
12554
|
-
return;
|
12555
|
-
}
|
12556
|
-
// A class argument must be evaluated in the context of the class declaration.
|
12557
|
-
if (parent.nodeType === 1 /* Argument */ && ((_e = parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 10 /* Class */) {
|
12558
|
-
getTypeOfClass(parent.parent);
|
12559
|
-
return;
|
12560
|
-
}
|
12561
|
-
if (parent.nodeType === 44 /* Return */ && parent.returnExpression) {
|
12562
|
-
const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(node);
|
12563
|
-
const declaredReturnType = enclosingFunctionNode
|
12564
|
-
? getFunctionDeclaredReturnType(enclosingFunctionNode)
|
12565
|
-
: undefined;
|
12566
|
-
getTypeOfExpression(parent.returnExpression, 0 /* None */, declaredReturnType);
|
12567
|
-
return;
|
12568
|
-
}
|
12569
|
-
// If the parent is an expression, we'll evaluate it to provide
|
12570
|
-
// the context for its child. If it's not, we'll evaluate the
|
12571
|
-
// child directly without any context.
|
12572
|
-
const nodeToEvaluate = (0, parseNodes_1.isExpressionNode)(parent) && parent.nodeType !== 0 /* Error */
|
12573
|
-
? parent
|
12574
|
-
: lastContextualExpression;
|
12575
12556
|
if (nodeToEvaluate.nodeType === 54 /* TypeAnnotation */) {
|
12576
|
-
|
12577
|
-
|
12578
|
-
else {
|
12579
|
-
const fileInfo = AnalyzerNodeInfo.getFileInfo(nodeToEvaluate);
|
12580
|
-
const flags = fileInfo.isStubFile ? 4 /* AllowForwardReferences */ : 0 /* None */;
|
12581
|
-
getTypeOfExpression(nodeToEvaluate, flags);
|
12557
|
+
evaluateTypesForTypeAnnotationNode(nodeToEvaluate);
|
12558
|
+
return;
|
12582
12559
|
}
|
12560
|
+
getTypeOfExpression(nodeToEvaluate, flags);
|
12583
12561
|
}
|
12584
12562
|
function evaluateTypeOfParameter(node) {
|
12585
12563
|
// If this parameter has no name, we have nothing to do.
|
@@ -12607,24 +12585,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12607
12585
|
return;
|
12608
12586
|
}
|
12609
12587
|
const containingClassNode = ParseTreeUtils.getEnclosingClass(functionNode, /* stopAtFunction */ true);
|
12610
|
-
|
12611
|
-
|
12612
|
-
|
12613
|
-
|
12614
|
-
|
12615
|
-
|
12616
|
-
|
12617
|
-
|
12618
|
-
|
12619
|
-
writeTypeCache(node.name, transformVariadicParamType(node, node.category, inferredParamType), 0 /* None */,
|
12620
|
-
/* isIncomplete */ false);
|
12621
|
-
return;
|
12622
|
-
}
|
12588
|
+
const classInfo = containingClassNode ? getTypeOfClass(containingClassNode) : undefined;
|
12589
|
+
if (classInfo &&
|
12590
|
+
types_1.ClassType.isPseudoGenericClass(classInfo === null || classInfo === void 0 ? void 0 : classInfo.classType) &&
|
12591
|
+
functionNode.name.value === '__init__') {
|
12592
|
+
const typeParamName = getPseudoGenericTypeVarName(node.name.value);
|
12593
|
+
const paramType = classInfo.classType.details.typeParameters.find((param) => param.details.name === typeParamName);
|
12594
|
+
if (paramType) {
|
12595
|
+
writeTypeCache(node.name, paramType, 0 /* None */, /* isIncomplete */ false);
|
12596
|
+
return;
|
12623
12597
|
}
|
12624
12598
|
}
|
12625
|
-
//
|
12626
|
-
// type
|
12627
|
-
|
12599
|
+
// See if the function is a method in a child class. We may be able to
|
12600
|
+
// infer the type of the parameter from a method of the same name in
|
12601
|
+
// a parent class if it has an annotated type.
|
12602
|
+
const functionFlags = getFunctionFlagsFromDecorators(functionNode, /* isInClass */ true);
|
12603
|
+
const inferredParamType = inferParameterType(functionNode, functionFlags, paramIndex, classInfo === null || classInfo === void 0 ? void 0 : classInfo.classType);
|
12604
|
+
writeTypeCache(node.name, transformVariadicParamType(node, node.category, inferredParamType !== null && inferredParamType !== void 0 ? inferredParamType : types_1.UnknownType.create()), 0 /* None */,
|
12628
12605
|
/* isIncomplete */ false);
|
12629
12606
|
}
|
12630
12607
|
// Evaluates the types that are assigned within the statement that contains
|
@@ -12739,7 +12716,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12739
12716
|
// doing additional work.
|
12740
12717
|
let subnodeType = readTypeCache(subnode, /* flags */ undefined);
|
12741
12718
|
if (subnodeType) {
|
12742
|
-
return {
|
12719
|
+
return { type: subnodeType };
|
12743
12720
|
}
|
12744
12721
|
const oldIncompleteCache = incompleteTypeCache;
|
12745
12722
|
try {
|
@@ -12752,11 +12729,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12752
12729
|
callback();
|
12753
12730
|
subnodeType = readTypeCache(subnode, /* flags */ undefined);
|
12754
12731
|
if (subnodeType) {
|
12755
|
-
return {
|
12732
|
+
return { type: subnodeType };
|
12756
12733
|
}
|
12757
12734
|
subnodeType = incompleteTypeCache.get(subnode.id);
|
12758
12735
|
if (subnodeType) {
|
12759
|
-
return {
|
12736
|
+
return { type: subnodeType, isIncomplete: true };
|
12760
12737
|
}
|
12761
12738
|
incompleteTypeCache = oldIncompleteCache;
|
12762
12739
|
}
|
@@ -13376,7 +13353,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13376
13353
|
else if (node.parent &&
|
13377
13354
|
node.parent.nodeType === 35 /* MemberAccess */ &&
|
13378
13355
|
node === node.parent.memberName) {
|
13379
|
-
let baseType =
|
13356
|
+
let baseType = getType(node.parent.leftExpression);
|
13380
13357
|
if (baseType) {
|
13381
13358
|
baseType = makeTopLevelTypeVarsConcrete(baseType);
|
13382
13359
|
const memberName = node.parent.memberName.value;
|
@@ -13451,7 +13428,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13451
13428
|
const argNode = node.parent;
|
13452
13429
|
const paramName = node.value;
|
13453
13430
|
if (argNode.parent && argNode.parent.nodeType === 9 /* Call */) {
|
13454
|
-
const baseType =
|
13431
|
+
const baseType = getType(argNode.parent.leftExpression);
|
13455
13432
|
if (baseType) {
|
13456
13433
|
if ((0, types_1.isFunction)(baseType) && baseType.details.declaration) {
|
13457
13434
|
const paramDecl = getDeclarationFromFunctionNamedParameter(baseType, paramName);
|
@@ -13665,7 +13642,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13665
13642
|
// Apply enum transform if appropriate.
|
13666
13643
|
if (declaration.node.nodeType === 38 /* Name */) {
|
13667
13644
|
declaredType =
|
13668
|
-
transformTypeForPossibleEnumClass(declaration.node, () => declaredType) || declaredType;
|
13645
|
+
(0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, declaration.node, () => declaredType) || declaredType;
|
13669
13646
|
}
|
13670
13647
|
if (typeAliasNode && typeAliasNode.valueExpression.nodeType === 38 /* Name */) {
|
13671
13648
|
declaredType = transformTypeForTypeAlias(declaredType, typeAliasNode.valueExpression, declaration.node);
|
@@ -13796,7 +13773,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13796
13773
|
})) === null || _b === void 0 ? void 0 : _b.type;
|
13797
13774
|
if (inferredType && resolvedDecl.node.nodeType === 38 /* Name */) {
|
13798
13775
|
// See if this is an enum member. If so, we need to handle it as a special case.
|
13799
|
-
const enumMemberType = transformTypeForPossibleEnumClass(resolvedDecl.node, () => {
|
13776
|
+
const enumMemberType = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, resolvedDecl.node, () => {
|
13800
13777
|
var _a, _b;
|
13801
13778
|
return ((_b = (_a = evaluateTypeForSubnode(resolvedDecl.inferredTypeSource, () => {
|
13802
13779
|
evaluateTypesForStatement(resolvedDecl.inferredTypeSource);
|
@@ -14021,13 +13998,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14021
13998
|
let isConstant = decl.type === 1 /* Variable */ && !!decl.isConstant;
|
14022
13999
|
// Treat enum values declared within an enum class as though they are const even
|
14023
14000
|
// though they may not be named as such.
|
14024
|
-
if ((0, types_1.isClassInstance)(type) &&
|
14001
|
+
if ((0, types_1.isClassInstance)(type) &&
|
14002
|
+
types_1.ClassType.isEnumClass(type) &&
|
14003
|
+
(0, enums_1.isDeclInEnumClass)(evaluatorInterface, decl)) {
|
14025
14004
|
isConstant = true;
|
14026
14005
|
}
|
14027
14006
|
// If the symbol is constant, we can retain the literal
|
14028
14007
|
// value. Otherwise, strip literal values to widen the type.
|
14029
14008
|
if (types_1.TypeBase.isInstance(type) && !isExplicitTypeAlias && !isConstant && !isFinalVar) {
|
14030
|
-
type =
|
14009
|
+
type = stripLiteralValue(type);
|
14031
14010
|
}
|
14032
14011
|
}
|
14033
14012
|
typesToCombine.push(type);
|
@@ -14148,17 +14127,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14148
14127
|
}
|
14149
14128
|
return undefined;
|
14150
14129
|
}
|
14151
|
-
function isDeclInEnumClass(decl) {
|
14152
|
-
const classNode = ParseTreeUtils.getEnclosingClass(decl.node, /* stopAtFunction */ true);
|
14153
|
-
if (!classNode) {
|
14154
|
-
return false;
|
14155
|
-
}
|
14156
|
-
const classInfo = getTypeOfClass(classNode);
|
14157
|
-
if (!classInfo) {
|
14158
|
-
return false;
|
14159
|
-
}
|
14160
|
-
return types_1.ClassType.isEnumClass(classInfo.classType);
|
14161
|
-
}
|
14162
14130
|
function inferReturnTypeIfNecessary(type) {
|
14163
14131
|
if ((0, types_1.isFunction)(type)) {
|
14164
14132
|
getFunctionEffectiveReturnType(type);
|
@@ -14292,9 +14260,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14292
14260
|
if (returnTypeInferenceContextStack.length >= maxReturnTypeInferenceStackSize) {
|
14293
14261
|
return undefined;
|
14294
14262
|
}
|
14263
|
+
const paramTypes = [];
|
14264
|
+
let isResultFromCache = false;
|
14295
14265
|
// Suppress diagnostics because we don't want to generate errors.
|
14296
14266
|
suppressDiagnostics(functionNode, () => {
|
14297
|
-
var _a;
|
14267
|
+
var _a, _b;
|
14298
14268
|
// Allocate a new temporary type cache for the context of just
|
14299
14269
|
// this function so we can analyze it separately without polluting
|
14300
14270
|
// the main type cache.
|
@@ -14337,13 +14307,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14337
14307
|
if (!paramType) {
|
14338
14308
|
paramType = types_1.UnknownType.create();
|
14339
14309
|
}
|
14310
|
+
paramTypes.push(paramType);
|
14340
14311
|
writeTypeCache(param.name, paramType, 0 /* None */, /* isIncomplete */ false);
|
14341
14312
|
}
|
14342
14313
|
});
|
14343
14314
|
// Don't bother trying to determine the contextual return
|
14344
14315
|
// type if none of the argument types are known.
|
14345
14316
|
if (!allArgTypesAreUnknown) {
|
14346
|
-
|
14317
|
+
// See if the return type is already cached. If so, skip the
|
14318
|
+
// inference step, which is potentially very expensive.
|
14319
|
+
const cacheEntry = (_a = functionType.functionType.callSiteReturnTypeCache) === null || _a === void 0 ? void 0 : _a.find((entry) => {
|
14320
|
+
return (entry.paramTypes.length === paramTypes.length &&
|
14321
|
+
entry.paramTypes.every((t, i) => (0, types_1.isTypeSame)(t, paramTypes[i])));
|
14322
|
+
});
|
14323
|
+
if (cacheEntry) {
|
14324
|
+
contextualReturnType = cacheEntry.returnType;
|
14325
|
+
isResultFromCache = true;
|
14326
|
+
}
|
14327
|
+
else {
|
14328
|
+
contextualReturnType = (_b = inferFunctionReturnType(functionNode, types_1.FunctionType.isAbstractMethod(type))) === null || _b === void 0 ? void 0 : _b.type;
|
14329
|
+
}
|
14347
14330
|
}
|
14348
14331
|
}
|
14349
14332
|
finally {
|
@@ -14357,6 +14340,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14357
14340
|
if (types_1.FunctionType.isWrapReturnTypeInAwait(type) && !(0, types_1.isNever)(contextualReturnType)) {
|
14358
14341
|
contextualReturnType = createAwaitableReturnType(functionNode, contextualReturnType, !!((_a = type.details.declaration) === null || _a === void 0 ? void 0 : _a.isGenerator));
|
14359
14342
|
}
|
14343
|
+
if (!isResultFromCache) {
|
14344
|
+
// Cache the resulting type.
|
14345
|
+
if (!functionType.functionType.callSiteReturnTypeCache) {
|
14346
|
+
functionType.functionType.callSiteReturnTypeCache = [];
|
14347
|
+
}
|
14348
|
+
if (functionType.functionType.callSiteReturnTypeCache.length >= maxCallSiteReturnTypeCacheSize) {
|
14349
|
+
functionType.functionType.callSiteReturnTypeCache =
|
14350
|
+
functionType.functionType.callSiteReturnTypeCache.slice(1);
|
14351
|
+
}
|
14352
|
+
functionType.functionType.callSiteReturnTypeCache.push({
|
14353
|
+
paramTypes,
|
14354
|
+
returnType: contextualReturnType,
|
14355
|
+
});
|
14356
|
+
}
|
14360
14357
|
return contextualReturnType;
|
14361
14358
|
}
|
14362
14359
|
return undefined;
|
@@ -14384,7 +14381,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14384
14381
|
}
|
14385
14382
|
return types_1.UnknownType.create();
|
14386
14383
|
}
|
14387
|
-
function getTypeOfMemberInternal(
|
14384
|
+
function getTypeOfMemberInternal(member, selfClass) {
|
14388
14385
|
if ((0, types_1.isInstantiableClass)(member.classType)) {
|
14389
14386
|
const typeResult = getEffectiveTypeOfSymbolForUsage(member.symbol);
|
14390
14387
|
if (typeResult) {
|
@@ -14393,7 +14390,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14393
14390
|
// prior to specializing.
|
14394
14391
|
inferReturnTypeIfNecessary(typeResult.type);
|
14395
14392
|
return {
|
14396
|
-
node,
|
14397
14393
|
type: (0, typeUtils_1.partiallySpecializeType)(typeResult.type, member.classType, selfClass),
|
14398
14394
|
isIncomplete: !!typeResult.isIncomplete,
|
14399
14395
|
};
|
@@ -14573,10 +14569,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14573
14569
|
const removedArgs = srcTypeArgs.splice(destVariadicIndex, srcArgsToCapture);
|
14574
14570
|
// Package up the remaining type arguments into a tuple object.
|
14575
14571
|
const variadicTuple = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, removedArgs.map((typeArg) => {
|
14576
|
-
return { type:
|
14572
|
+
return { type: stripLiteralValue(typeArg.type), isUnbounded: false };
|
14577
14573
|
}),
|
14578
14574
|
/* isTypeArgumentExplicit */ true,
|
14579
|
-
/* stripLiterals */ true,
|
14580
14575
|
/* isUnpackedTuple */ true));
|
14581
14576
|
srcTypeArgs.splice(destVariadicIndex, 0, {
|
14582
14577
|
type: variadicTuple,
|
@@ -15134,7 +15129,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15134
15129
|
}
|
15135
15130
|
}
|
15136
15131
|
}
|
15137
|
-
|
15132
|
+
let concreteSrcType = makeTopLevelTypeVarsConcrete(srcType);
|
15138
15133
|
if ((0, types_1.isClass)(concreteSrcType) && types_1.TypeBase.isInstance(concreteSrcType)) {
|
15139
15134
|
if (destType.literalValue !== undefined) {
|
15140
15135
|
const srcLiteral = concreteSrcType.literalValue;
|
@@ -15147,15 +15142,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15147
15142
|
}
|
15148
15143
|
}
|
15149
15144
|
// Handle LiteralString special form.
|
15150
|
-
if (types_1.ClassType.isBuiltIn(destType, 'LiteralString')
|
15151
|
-
if (concreteSrcType.literalValue !== undefined) {
|
15145
|
+
if (types_1.ClassType.isBuiltIn(destType, 'LiteralString')) {
|
15146
|
+
if (types_1.ClassType.isBuiltIn(concreteSrcType, 'str') && concreteSrcType.literalValue !== undefined) {
|
15147
|
+
return true;
|
15148
|
+
}
|
15149
|
+
else if (types_1.ClassType.isBuiltIn(concreteSrcType, 'LiteralString')) {
|
15152
15150
|
return true;
|
15153
15151
|
}
|
15154
15152
|
}
|
15155
15153
|
else if (types_1.ClassType.isBuiltIn(concreteSrcType, 'LiteralString') &&
|
15156
|
-
|
15157
|
-
|
15158
|
-
|
15154
|
+
strClassType &&
|
15155
|
+
(0, types_1.isInstantiableClass)(strClassType)) {
|
15156
|
+
concreteSrcType = types_1.ClassType.cloneAsInstance(strClassType);
|
15159
15157
|
}
|
15160
15158
|
if (!assignClass(types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstantiable(concreteSrcType), diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
|
15161
15159
|
/* reportErrorsUsingObjType */ true)) {
|
@@ -15240,11 +15238,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15240
15238
|
// Find first overloaded function that matches the parameters.
|
15241
15239
|
// We don't want to pollute the current typeVarContext, so we'll
|
15242
15240
|
// make a copy of the existing one if it's specified.
|
15243
|
-
const overloads = concreteSrcType
|
15241
|
+
const overloads = types_1.OverloadedFunctionType.getOverloads(concreteSrcType);
|
15244
15242
|
const overloadIndex = overloads.findIndex((overload) => {
|
15245
|
-
if (!types_1.FunctionType.isOverloaded(overload)) {
|
15246
|
-
return false;
|
15247
|
-
}
|
15248
15243
|
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);
|
15249
15244
|
});
|
15250
15245
|
if (overloadIndex < 0) {
|
@@ -15268,10 +15263,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15268
15263
|
if ((0, types_1.isOverloadedFunction)(destType)) {
|
15269
15264
|
const overloadDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
|
15270
15265
|
// All overloads in the dest must be assignable.
|
15271
|
-
const isAssignable = destType.
|
15272
|
-
if (!types_1.FunctionType.isOverloaded(destOverload)) {
|
15273
|
-
return true;
|
15274
|
-
}
|
15266
|
+
const isAssignable = types_1.OverloadedFunctionType.getOverloads(destType).every((destOverload) => {
|
15275
15267
|
if (destTypeVarContext) {
|
15276
15268
|
destTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(destOverload));
|
15277
15269
|
}
|
@@ -15403,6 +15395,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15403
15395
|
}
|
15404
15396
|
// For union sources, all of the types need to be assignable to the dest.
|
15405
15397
|
let isIncompatible = false;
|
15398
|
+
// Sort the subtypes so we have a deterministic order for unions.
|
15406
15399
|
(0, typeUtils_1.doForEachSubtype)(srcType, (subtype, subtypeIndex) => {
|
15407
15400
|
if (isIncompatible) {
|
15408
15401
|
return;
|
@@ -15427,7 +15420,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15427
15420
|
isIncompatible = true;
|
15428
15421
|
}
|
15429
15422
|
}
|
15430
|
-
}
|
15423
|
+
},
|
15424
|
+
/* sortSubtypes */ true);
|
15431
15425
|
if (isIncompatible) {
|
15432
15426
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
|
15433
15427
|
sourceType: printType(srcType),
|
@@ -15504,54 +15498,69 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15504
15498
|
// For union destinations, we just need to match one of the types.
|
15505
15499
|
const diagAddendum = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
|
15506
15500
|
let foundMatch = false;
|
15507
|
-
//
|
15508
|
-
//
|
15509
|
-
|
15510
|
-
|
15511
|
-
|
15512
|
-
|
15501
|
+
// Does the union contain any type variables that need to be solved?
|
15502
|
+
// If so, we need to use a slower path.
|
15503
|
+
if (!(0, typeUtils_1.requiresSpecialization)(destType)) {
|
15504
|
+
for (const subtype of destType.subtypes) {
|
15505
|
+
if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(),
|
15506
|
+
/* destTypeVarContextClone */ undefined,
|
15507
|
+
/* srcTypeVarContextClone */ undefined, flags, recursionCount)) {
|
15508
|
+
foundMatch = true;
|
15509
|
+
break;
|
15510
|
+
}
|
15511
|
+
}
|
15513
15512
|
}
|
15514
15513
|
else {
|
15515
|
-
|
15516
|
-
|
15517
|
-
|
15518
|
-
//
|
15519
|
-
|
15520
|
-
|
15521
|
-
(0, typeUtils_1.isLiteralType)(srcType) &&
|
15522
|
-
types_1.UnionType.containsType(destType, srcType, recursionCount)) {
|
15523
|
-
return true;
|
15514
|
+
// Run through all subtypes in the union. Don't stop at the first
|
15515
|
+
// match we find because we may need to match TypeVars in other
|
15516
|
+
// subtypes. We special-case "None" so we can handle Optional[T]
|
15517
|
+
// without matching the None to the type var.
|
15518
|
+
if ((0, types_1.isNoneInstance)(srcType) && (0, typeUtils_1.isOptionalType)(destType)) {
|
15519
|
+
foundMatch = true;
|
15524
15520
|
}
|
15525
|
-
|
15526
|
-
|
15527
|
-
|
15528
|
-
|
15529
|
-
|
15530
|
-
|
15531
|
-
|
15532
|
-
|
15533
|
-
|
15534
|
-
|
15535
|
-
|
15536
|
-
|
15537
|
-
|
15538
|
-
|
15539
|
-
|
15540
|
-
|
15541
|
-
|
15542
|
-
|
15543
|
-
|
15544
|
-
|
15521
|
+
else {
|
15522
|
+
let bestDestTypeVarContext;
|
15523
|
+
let bestSrcTypeVarContext;
|
15524
|
+
let bestTypeVarContextScore;
|
15525
|
+
// If the srcType is a literal, try to use the fast-path lookup
|
15526
|
+
// in case the destType is a union with hundreds of literals.
|
15527
|
+
if ((0, types_1.isClassInstance)(srcType) &&
|
15528
|
+
(0, typeUtils_1.isLiteralType)(srcType) &&
|
15529
|
+
types_1.UnionType.containsType(destType, srcType, recursionCount)) {
|
15530
|
+
return true;
|
15531
|
+
}
|
15532
|
+
(0, typeUtils_1.doForEachSubtype)(destType, (subtype) => {
|
15533
|
+
// Make a temporary clone of the typeVarContext. We don't want to modify
|
15534
|
+
// the original typeVarContext until we find the "optimal" typeVar mapping.
|
15535
|
+
const destTypeVarContextClone = destTypeVarContext === null || destTypeVarContext === void 0 ? void 0 : destTypeVarContext.clone();
|
15536
|
+
const srcTypeVarContextClone = srcTypeVarContext === null || srcTypeVarContext === void 0 ? void 0 : srcTypeVarContext.clone();
|
15537
|
+
if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(), destTypeVarContextClone, srcTypeVarContextClone, flags, recursionCount)) {
|
15538
|
+
foundMatch = true;
|
15539
|
+
if (destTypeVarContextClone) {
|
15540
|
+
// Ask the typeVarContext to compute a "score" for the current
|
15541
|
+
// contents of the table.
|
15542
|
+
let typeVarContextScore = destTypeVarContextClone.getScore();
|
15543
|
+
// If the type matches exactly, prefer it over other types.
|
15544
|
+
if ((0, types_1.isTypeSame)(subtype, stripLiteralValue(srcType))) {
|
15545
|
+
typeVarContextScore = Number.POSITIVE_INFINITY;
|
15546
|
+
}
|
15547
|
+
if (bestTypeVarContextScore === undefined ||
|
15548
|
+
bestTypeVarContextScore <= typeVarContextScore) {
|
15549
|
+
// We found a typeVar mapping with a higher score than before.
|
15550
|
+
bestTypeVarContextScore = typeVarContextScore;
|
15551
|
+
bestDestTypeVarContext = destTypeVarContextClone;
|
15552
|
+
bestSrcTypeVarContext = srcTypeVarContextClone;
|
15553
|
+
}
|
15545
15554
|
}
|
15546
15555
|
}
|
15556
|
+
});
|
15557
|
+
// If we found a winning type var mapping, copy it back to typeVarContext.
|
15558
|
+
if (destTypeVarContext && bestDestTypeVarContext) {
|
15559
|
+
destTypeVarContext.copyFromClone(bestDestTypeVarContext);
|
15560
|
+
}
|
15561
|
+
if (srcTypeVarContext && bestSrcTypeVarContext) {
|
15562
|
+
srcTypeVarContext.copyFromClone(bestSrcTypeVarContext);
|
15547
15563
|
}
|
15548
|
-
});
|
15549
|
-
// If we found a winning type var mapping, copy it back to typeVarContext.
|
15550
|
-
if (destTypeVarContext && bestDestTypeVarContext) {
|
15551
|
-
destTypeVarContext.copyFromClone(bestDestTypeVarContext);
|
15552
|
-
}
|
15553
|
-
if (srcTypeVarContext && bestSrcTypeVarContext) {
|
15554
|
-
srcTypeVarContext.copyFromClone(bestSrcTypeVarContext);
|
15555
15564
|
}
|
15556
15565
|
}
|
15557
15566
|
// If the source is a constrained TypeVar, see if we can assign all of the
|
@@ -15839,7 +15848,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15839
15848
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
15840
15849
|
srcPositionalsType = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, srcTupleTypes,
|
15841
15850
|
/* isTypeArgumentExplicit */ true,
|
15842
|
-
/* stripLiterals */ true,
|
15843
15851
|
/* isUnpackedTuple */ true));
|
15844
15852
|
}
|
15845
15853
|
else {
|
@@ -16025,13 +16033,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16025
16033
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
16026
16034
|
if (!(0, types_1.isUnpacked)(destArgsType)) {
|
16027
16035
|
destArgsType = types_1.ClassType.cloneForUnpacked(types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type: destArgsType, isUnbounded: true }],
|
16028
|
-
/* isTypeArgumentExplicit */ true
|
16029
|
-
/* stripLiterals */ true)));
|
16036
|
+
/* isTypeArgumentExplicit */ true)));
|
16030
16037
|
}
|
16031
16038
|
if (!(0, types_1.isUnpacked)(srcArgsType)) {
|
16032
16039
|
srcArgsType = types_1.ClassType.cloneForUnpacked(types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type: srcArgsType, isUnbounded: true }],
|
16033
|
-
/* isTypeArgumentExplicit */ true
|
16034
|
-
/* stripLiterals */ true)));
|
16040
|
+
/* isTypeArgumentExplicit */ true)));
|
16035
16041
|
}
|
16036
16042
|
}
|
16037
16043
|
if (!assignFunctionParameter(destArgsType, srcArgsType, destParamDetails.params[destParamDetails.argsIndex].index, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
@@ -16402,22 +16408,41 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16402
16408
|
return narrowedType;
|
16403
16409
|
}
|
16404
16410
|
function validateOverrideMethod(baseMethod, overrideMethod, diag, enforceParamNames = true) {
|
16405
|
-
var _a, _b;
|
16406
|
-
// If we're overriding an overloaded method, uses the implementation.
|
16407
|
-
if ((0, types_1.isOverloadedFunction)(baseMethod)) {
|
16408
|
-
const implementation = baseMethod.overloads.find((overload) => !types_1.FunctionType.isOverloaded(overload));
|
16409
|
-
// If the overloaded method doesn't have an implementation, skip the check.
|
16410
|
-
if (!implementation) {
|
16411
|
-
return true;
|
16412
|
-
}
|
16413
|
-
baseMethod = implementation;
|
16414
|
-
}
|
16415
16411
|
// If we're overriding a non-method with a method, report it as an error.
|
16416
16412
|
// This occurs when a non-property overrides a property.
|
16417
|
-
if (!(0, types_1.isFunction)(baseMethod)) {
|
16413
|
+
if (!(0, types_1.isFunction)(baseMethod) && !(0, types_1.isOverloadedFunction)(baseMethod)) {
|
16418
16414
|
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideType().format({ type: printType(baseMethod) }));
|
16419
16415
|
return false;
|
16420
16416
|
}
|
16417
|
+
if ((0, types_1.isFunction)(baseMethod)) {
|
16418
|
+
// Handle the easy case - a simple function overriding another simple function.
|
16419
|
+
if ((0, types_1.isFunction)(overrideMethod)) {
|
16420
|
+
return validateOverrideMethodInternal(baseMethod, overrideMethod, diag, enforceParamNames);
|
16421
|
+
}
|
16422
|
+
// For an overload overriding a base method, at least one overload
|
16423
|
+
// must be compatible with the base method.
|
16424
|
+
if (types_1.OverloadedFunctionType.getOverloads(overrideMethod).some((overrideOverload) => {
|
16425
|
+
return validateOverrideMethodInternal(baseMethod, overrideOverload,
|
16426
|
+
/* diag */ undefined, enforceParamNames);
|
16427
|
+
})) {
|
16428
|
+
return true;
|
16429
|
+
}
|
16430
|
+
// Or the implementation must be compatible.
|
16431
|
+
const overrideImplementation = types_1.OverloadedFunctionType.getImplementation(overrideMethod);
|
16432
|
+
if (overrideImplementation) {
|
16433
|
+
if (validateOverrideMethodInternal(baseMethod, overrideImplementation,
|
16434
|
+
/* diag */ undefined, enforceParamNames)) {
|
16435
|
+
return true;
|
16436
|
+
}
|
16437
|
+
}
|
16438
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNoOverloadMatches());
|
16439
|
+
return false;
|
16440
|
+
}
|
16441
|
+
// TODO - need to implement the case where the base method is overloaded
|
16442
|
+
return true;
|
16443
|
+
}
|
16444
|
+
function validateOverrideMethodInternal(baseMethod, overrideMethod, diag, enforceParamNames) {
|
16445
|
+
var _a, _b;
|
16421
16446
|
const baseParamDetails = (0, typeUtils_1.getParameterListDetails)(baseMethod);
|
16422
16447
|
const overrideParamDetails = (0, typeUtils_1.getParameterListDetails)(overrideMethod);
|
16423
16448
|
let canOverride = true;
|
@@ -16425,19 +16450,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16425
16450
|
// an incompatible type.
|
16426
16451
|
if (types_1.FunctionType.isStaticMethod(baseMethod)) {
|
16427
16452
|
if (!types_1.FunctionType.isStaticMethod(overrideMethod)) {
|
16428
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotStaticMethod());
|
16453
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotStaticMethod());
|
16429
16454
|
canOverride = false;
|
16430
16455
|
}
|
16431
16456
|
}
|
16432
16457
|
else if (types_1.FunctionType.isClassMethod(baseMethod)) {
|
16433
16458
|
if (!types_1.FunctionType.isClassMethod(overrideMethod)) {
|
16434
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotClassMethod());
|
16459
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotClassMethod());
|
16435
16460
|
canOverride = false;
|
16436
16461
|
}
|
16437
16462
|
}
|
16438
16463
|
if (types_1.FunctionType.isInstanceMethod(baseMethod)) {
|
16439
16464
|
if (!types_1.FunctionType.isInstanceMethod(overrideMethod)) {
|
16440
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotInstanceMethod());
|
16465
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotInstanceMethod());
|
16441
16466
|
canOverride = false;
|
16442
16467
|
}
|
16443
16468
|
}
|
@@ -16462,7 +16487,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16462
16487
|
}
|
16463
16488
|
}
|
16464
16489
|
if (foundParamCountMismatch) {
|
16465
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overridePositionalParamCount().format({
|
16490
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overridePositionalParamCount().format({
|
16466
16491
|
baseCount: baseParamDetails.params.length,
|
16467
16492
|
overrideCount: overrideParamDetails.params.length,
|
16468
16493
|
}));
|
@@ -16489,13 +16514,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16489
16514
|
if (overrideParam.category === 0 /* Simple */) {
|
16490
16515
|
if (enforceParamNames) {
|
16491
16516
|
if (overrideParamDetails.params[i].source === typeUtils_1.ParameterSource.PositionOnly) {
|
16492
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
|
16517
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
|
16493
16518
|
index: i + 1,
|
16494
16519
|
baseName: baseParam.name || '*',
|
16495
16520
|
}));
|
16496
16521
|
}
|
16497
16522
|
else {
|
16498
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamName().format({
|
16523
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamName().format({
|
16499
16524
|
index: i + 1,
|
16500
16525
|
baseName: baseParam.name || '*',
|
16501
16526
|
overrideName: overrideParam.name || '*',
|
@@ -16507,7 +16532,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16507
16532
|
}
|
16508
16533
|
else if (i < overrideParamDetails.positionOnlyParamCount &&
|
16509
16534
|
i >= baseParamDetails.positionOnlyParamCount) {
|
16510
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
|
16535
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
|
16511
16536
|
index: i + 1,
|
16512
16537
|
baseName: baseParam.name || '*',
|
16513
16538
|
}));
|
@@ -16520,8 +16545,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16520
16545
|
const overrideIsSynthesizedTypeVar = (0, types_1.isTypeVar)(overrideParamType) && overrideParamType.details.isSynthesized;
|
16521
16546
|
if (!baseIsSynthesizedTypeVar && !overrideIsSynthesizedTypeVar) {
|
16522
16547
|
if (baseParam.category !== overrideParam.category ||
|
16523
|
-
!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 */)) {
|
16524
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamType().format({
|
16548
|
+
!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 */)) {
|
16549
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamType().format({
|
16525
16550
|
index: i + 1,
|
16526
16551
|
baseType: printType(baseParamType),
|
16527
16552
|
overrideType: printType(overrideParamType),
|
@@ -16530,7 +16555,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16530
16555
|
}
|
16531
16556
|
}
|
16532
16557
|
if (baseParamDetails.params[i].param.hasDefault && !overrideParamDetails.params[i].param.hasDefault) {
|
16533
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNoDefault().format({
|
16558
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNoDefault().format({
|
16534
16559
|
index: i + 1,
|
16535
16560
|
}));
|
16536
16561
|
canOverride = false;
|
@@ -16540,7 +16565,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16540
16565
|
// Check for a *args match.
|
16541
16566
|
if (baseParamDetails.argsIndex !== undefined) {
|
16542
16567
|
if (overrideParamDetails.argsIndex === undefined) {
|
16543
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameMissing().format({
|
16568
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameMissing().format({
|
16544
16569
|
name: (_a = baseParamDetails.params[baseParamDetails.argsIndex].param.name) !== null && _a !== void 0 ? _a : '?',
|
16545
16570
|
}));
|
16546
16571
|
canOverride = false;
|
@@ -16548,9 +16573,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16548
16573
|
else {
|
16549
16574
|
const overrideParamType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
|
16550
16575
|
const baseParamType = baseParamDetails.params[baseParamDetails.argsIndex].type;
|
16551
|
-
if (!assignType(overrideParamType, baseParamType, diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
|
16576
|
+
if (!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
|
16552
16577
|
/* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
|
16553
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
|
16578
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
|
16554
16579
|
name: (_b = overrideParamDetails.params[overrideParamDetails.argsIndex].param.name) !== null && _b !== void 0 ? _b : '?',
|
16555
16580
|
baseType: printType(baseParamType),
|
16556
16581
|
overrideType: printType(overrideParamType),
|
@@ -16568,7 +16593,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16568
16593
|
var _a, _b, _c;
|
16569
16594
|
const overrideParamInfo = overrideWkOnlyParams.find((pi) => paramInfo.param.name === pi.param.name);
|
16570
16595
|
if (!overrideParamInfo && overrideParamDetails.kwargsIndex === undefined) {
|
16571
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameMissing().format({
|
16596
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameMissing().format({
|
16572
16597
|
name: (_a = paramInfo.param.name) !== null && _a !== void 0 ? _a : '?',
|
16573
16598
|
}));
|
16574
16599
|
canOverride = false;
|
@@ -16578,9 +16603,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16578
16603
|
if (!targetParamType) {
|
16579
16604
|
targetParamType = overrideParamDetails.params[overrideParamDetails.kwargsIndex].type;
|
16580
16605
|
}
|
16581
|
-
if (!assignType(targetParamType, paramInfo.type, diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
|
16606
|
+
if (!assignType(targetParamType, paramInfo.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
|
16582
16607
|
/* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
|
16583
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
|
16608
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
|
16584
16609
|
name: (_b = paramInfo.param.name) !== null && _b !== void 0 ? _b : '?',
|
16585
16610
|
baseType: printType(paramInfo.type),
|
16586
16611
|
overrideType: printType(targetParamType),
|
@@ -16589,7 +16614,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16589
16614
|
}
|
16590
16615
|
if (overrideParamInfo) {
|
16591
16616
|
if (paramInfo.param.hasDefault && !overrideParamInfo.param.hasDefault) {
|
16592
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordNoDefault().format({
|
16617
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordNoDefault().format({
|
16593
16618
|
name: (_c = overrideParamInfo.param.name) !== null && _c !== void 0 ? _c : '?',
|
16594
16619
|
}));
|
16595
16620
|
canOverride = false;
|
@@ -16605,7 +16630,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16605
16630
|
if (!baseParamInfo) {
|
16606
16631
|
if (baseParamDetails.kwargsIndex === undefined) {
|
16607
16632
|
if (!paramInfo.param.hasDefault) {
|
16608
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameExtra().format({
|
16633
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameExtra().format({
|
16609
16634
|
name: (_a = paramInfo.param.name) !== null && _a !== void 0 ? _a : '?',
|
16610
16635
|
}));
|
16611
16636
|
canOverride = false;
|
@@ -16616,9 +16641,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16616
16641
|
// Now check the return type.
|
16617
16642
|
const baseReturnType = getFunctionEffectiveReturnType(baseMethod);
|
16618
16643
|
const overrideReturnType = getFunctionEffectiveReturnType(overrideMethod);
|
16619
|
-
if (!assignType(baseReturnType, overrideReturnType, diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)),
|
16644
|
+
if (!assignType(baseReturnType, overrideReturnType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)),
|
16620
16645
|
/* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
|
16621
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideReturnType().format({
|
16646
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideReturnType().format({
|
16622
16647
|
baseType: printType(baseReturnType),
|
16623
16648
|
overrideType: printType(overrideReturnType),
|
16624
16649
|
}));
|
@@ -16853,9 +16878,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16853
16878
|
if (firstParamType && memberType.details.parameters.length > 0) {
|
16854
16879
|
const memberTypeFirstParam = memberType.details.parameters[0];
|
16855
16880
|
const memberTypeFirstParamType = types_1.FunctionType.getEffectiveParameterType(memberType, 0);
|
16856
|
-
// If the type has a literal associated with it, strip it now. This
|
16857
|
-
// is needed to handle generic functions in the enum.Flag class.
|
16858
|
-
const nonLiteralFirstParamType = (0, typeUtils_1.stripLiteralValue)(firstParamType);
|
16859
16881
|
// Fill out the typeVarContext for the "self" or "cls" parameter.
|
16860
16882
|
typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(memberType));
|
16861
16883
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
@@ -16869,11 +16891,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16869
16891
|
// Instead, we'll assume it's assignable.
|
16870
16892
|
if (!typeVarContext.isLocked()) {
|
16871
16893
|
typeVarContext.setTypeVarType(memberTypeFirstParamType, types_1.TypeBase.isInstantiable(memberTypeFirstParamType)
|
16872
|
-
? (0, typeUtils_1.convertToInstance)(
|
16873
|
-
:
|
16894
|
+
? (0, typeUtils_1.convertToInstance)(firstParamType)
|
16895
|
+
: firstParamType);
|
16874
16896
|
}
|
16875
16897
|
}
|
16876
|
-
else if (!assignType(memberTypeFirstParamType,
|
16898
|
+
else if (!assignType(memberTypeFirstParamType, firstParamType, diag, typeVarContext,
|
16877
16899
|
/* srcTypeVarContext */ undefined, 0 /* Default */, recursionCount)) {
|
16878
16900
|
if (memberTypeFirstParam.name &&
|
16879
16901
|
!memberTypeFirstParam.isNameSynthesized &&
|
@@ -16978,6 +17000,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16978
17000
|
evaluateTypeOfParameter,
|
16979
17001
|
canBeTruthy,
|
16980
17002
|
canBeFalsy,
|
17003
|
+
stripLiteralValue,
|
16981
17004
|
removeTruthinessFromType,
|
16982
17005
|
removeFalsinessFromType,
|
16983
17006
|
verifyRaiseExceptionType,
|
@@ -17033,6 +17056,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17033
17056
|
addWarning,
|
17034
17057
|
addInformation,
|
17035
17058
|
addUnusedCode,
|
17059
|
+
addUnreachableCode,
|
17036
17060
|
addDeprecated,
|
17037
17061
|
addDiagnostic,
|
17038
17062
|
addDiagnosticForTextRange,
|