@zzzen/pyright-internal 1.2.0-dev.20250216 → 1.2.0-dev.20250302
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/backgroundAnalysisProgram.d.ts +4 -4
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/cacheManager.d.ts +5 -2
- package/dist/analyzer/cacheManager.js +1 -0
- package/dist/analyzer/cacheManager.js.map +1 -1
- package/dist/analyzer/checker.js +170 -163
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +1 -1
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +1 -1
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +1 -1
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +2 -1
- package/dist/analyzer/parseTreeUtils.js +12 -0
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/program.d.ts +0 -1
- package/dist/analyzer/program.js +13 -29
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/service.d.ts +3 -3
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +1 -1
- package/dist/analyzer/sourceFile.js +1 -1
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/tracePrinter.d.ts +1 -1
- package/dist/analyzer/tracePrinter.js +3 -2
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/tuples.js +3 -2
- package/dist/analyzer/tuples.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +144 -94
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -1
- package/dist/analyzer/typePrinter.d.ts +2 -0
- package/dist/analyzer/typePrinter.js +20 -0
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.js +3 -3
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeWalker.js +1 -1
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.js +6 -7
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +4 -1
- package/dist/analyzer/types.js +20 -4
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +26 -4
- package/dist/backgroundAnalysisBase.js +23 -15
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/common/cancellationUtils.d.ts +4 -1
- package/dist/common/cancellationUtils.js +27 -2
- package/dist/common/cancellationUtils.js.map +1 -1
- package/dist/common/core.d.ts +1 -0
- package/dist/common/core.js +10 -0
- package/dist/common/core.js.map +1 -1
- package/dist/common/fileBasedCancellationUtils.js +4 -0
- package/dist/common/fileBasedCancellationUtils.js.map +1 -1
- package/dist/common/languageServerInterface.d.ts +3 -3
- package/dist/languageServerBase.d.ts +3 -3
- package/dist/languageServerBase.js.map +1 -1
- package/dist/localization/localize.d.ts +4 -0
- package/dist/localization/localize.js +2 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +2 -0
- package/dist/localization/package.nls.de.json +2 -0
- package/dist/localization/package.nls.en-us.json +5 -0
- package/dist/localization/package.nls.es.json +2 -0
- package/dist/localization/package.nls.fr.json +2 -0
- package/dist/localization/package.nls.it.json +2 -0
- package/dist/localization/package.nls.ja.json +2 -0
- package/dist/localization/package.nls.ko.json +2 -0
- package/dist/localization/package.nls.pl.json +2 -0
- package/dist/localization/package.nls.pt-br.json +2 -0
- package/dist/localization/package.nls.qps-ploc.json +2 -0
- package/dist/localization/package.nls.ru.json +2 -0
- package/dist/localization/package.nls.tr.json +2 -0
- package/dist/localization/package.nls.zh-cn.json +2 -0
- package/dist/localization/package.nls.zh-tw.json +2 -0
- package/dist/parser/tokenizer.js +3 -2
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js +2 -2
- package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.wildcardimports.fourslash.js +2 -2
- package/dist/tests/fourslash/completions.wildcardimports.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.wildcardimports.fourslash.js +2 -2
- package/dist/tests/fourslash/hover.wildcardimports.fourslash.js.map +1 -1
- package/dist/tests/fourslash/signature.docstrings.wildcardimports.fourslash.js +2 -2
- package/dist/tests/fourslash/signature.docstrings.wildcardimports.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +2 -2
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/serialization.test.js +7 -0
- package/dist/tests/serialization.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +2 -2
- package/dist/tests/typeEvaluator5.test.js +1 -1
- package/dist/tests/typeEvaluator6.test.js +1 -1
- package/dist/tests/typeEvaluator8.test.js +1 -1
- package/package.json +1 -1
@@ -42,6 +42,7 @@ exports.maxCodeComplexity = void 0;
|
|
42
42
|
exports.createTypeEvaluator = createTypeEvaluator;
|
43
43
|
const cancellationUtils_1 = require("../common/cancellationUtils");
|
44
44
|
const collectionUtils_1 = require("../common/collectionUtils");
|
45
|
+
const core_1 = require("../common/core");
|
45
46
|
const debug_1 = require("../common/debug");
|
46
47
|
const diagnostic_1 = require("../common/diagnostic");
|
47
48
|
const diagnosticRules_1 = require("../common/diagnosticRules");
|
@@ -199,12 +200,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
199
200
|
const signatureTrackerStack = [];
|
200
201
|
let prefetched;
|
201
202
|
function runWithCancellationToken(token, callback) {
|
203
|
+
// Save the current token and restore it after the callback to support nested calls
|
204
|
+
const oldToken = cancellationToken;
|
205
|
+
let result = undefined;
|
202
206
|
try {
|
203
207
|
cancellationToken = token;
|
204
|
-
|
208
|
+
result = callback();
|
209
|
+
if (!(0, core_1.isThenable)(result)) {
|
210
|
+
return result;
|
211
|
+
}
|
212
|
+
return result.finally(() => {
|
213
|
+
cancellationToken = oldToken;
|
214
|
+
});
|
205
215
|
}
|
206
216
|
finally {
|
207
|
-
|
217
|
+
if (!(0, core_1.isThenable)(result)) {
|
218
|
+
cancellationToken = oldToken;
|
219
|
+
}
|
208
220
|
}
|
209
221
|
}
|
210
222
|
function checkForCancellation() {
|
@@ -590,7 +602,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
590
602
|
// Make sure the resulting type is assignable to the expected type.
|
591
603
|
if (!assignType(inferenceContext.expectedType, typeResult.type, diag,
|
592
604
|
/* constraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
|
593
|
-
|
605
|
+
// Set the typeErrors to true, but first make a copy of the
|
606
|
+
// type result because the (non-error) version may already
|
607
|
+
// be cached.
|
608
|
+
typeResult = { ...typeResult, typeErrors: true };
|
594
609
|
typeResult.expectedTypeDiagAddendum = diag;
|
595
610
|
diag.addTextRange(node);
|
596
611
|
}
|
@@ -5763,7 +5778,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5763
5778
|
}
|
5764
5779
|
return typeResult;
|
5765
5780
|
}
|
5766
|
-
function buildTupleTypesList(entryTypeResults, stripLiterals) {
|
5781
|
+
function buildTupleTypesList(entryTypeResults, stripLiterals, convertModule) {
|
5767
5782
|
const entryTypes = [];
|
5768
5783
|
for (const typeResult of entryTypeResults) {
|
5769
5784
|
let possibleUnpackedTuple;
|
@@ -5792,8 +5807,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5792
5807
|
entryTypes.push({ type: types_1.UnknownType.create(/* isIncomplete */ true), isUnbounded: false });
|
5793
5808
|
}
|
5794
5809
|
else {
|
5795
|
-
let entryType = convertSpecialFormToRuntimeValue(typeResult.type, 0 /* EvalFlags.None */,
|
5796
|
-
/* convertModule */ true);
|
5810
|
+
let entryType = convertSpecialFormToRuntimeValue(typeResult.type, 0 /* EvalFlags.None */, convertModule);
|
5797
5811
|
entryType = stripLiterals ? (0, typeUtils_1.stripTypeForm)(stripLiteralValue(entryType)) : entryType;
|
5798
5812
|
entryTypes.push({ type: entryType, isUnbounded: !!typeResult.unpackedType });
|
5799
5813
|
}
|
@@ -7607,6 +7621,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7607
7621
|
if (paramInfo.param.category === 1 /* ParamCategory.ArgsList */) {
|
7608
7622
|
matchedUnpackedListOfUnknownLength = true;
|
7609
7623
|
}
|
7624
|
+
if (isParamVariadic && listElementType) {
|
7625
|
+
isArgCompatibleWithVariadic = true;
|
7626
|
+
listElementType = (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type: listElementType, isUnbounded: true }],
|
7627
|
+
/* isUnpacked */ true);
|
7628
|
+
}
|
7610
7629
|
}
|
7611
7630
|
const funcArg = listElementType
|
7612
7631
|
? {
|
@@ -8111,20 +8130,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8111
8130
|
const param = paramInfo.param;
|
8112
8131
|
if (param.category === 0 /* ParamCategory.Simple */ && param.name) {
|
8113
8132
|
const entry = paramMap.get(param.name);
|
8114
|
-
if (entry && entry.argsNeeded === 0 && entry.argsReceived === 0
|
8115
|
-
|
8116
|
-
|
8117
|
-
|
8118
|
-
|
8119
|
-
|
8120
|
-
|
8121
|
-
|
8122
|
-
|
8123
|
-
|
8124
|
-
|
8125
|
-
|
8126
|
-
|
8127
|
-
|
8133
|
+
if (entry && entry.argsNeeded === 0 && entry.argsReceived === 0) {
|
8134
|
+
const defaultArgType = paramInfo.defaultType;
|
8135
|
+
if (defaultArgType &&
|
8136
|
+
!(0, typeUtils_1.isEllipsisType)(defaultArgType) &&
|
8137
|
+
(0, typeUtils_1.requiresSpecialization)(paramInfo.declaredType)) {
|
8138
|
+
validateArgTypeParams.push({
|
8139
|
+
paramCategory: param.category,
|
8140
|
+
paramType: paramInfo.type,
|
8141
|
+
requiresTypeVarMatching: true,
|
8142
|
+
argument: {
|
8143
|
+
argCategory: 0 /* ArgCategory.Simple */,
|
8144
|
+
typeResult: { type: defaultArgType },
|
8145
|
+
},
|
8146
|
+
isDefaultArg: true,
|
8147
|
+
errorNode,
|
8148
|
+
paramName: param.name,
|
8149
|
+
isParamNameSynthesized: types_1.FunctionParam.isNameSynthesized(param),
|
8150
|
+
});
|
8151
|
+
}
|
8128
8152
|
}
|
8129
8153
|
}
|
8130
8154
|
});
|
@@ -9244,6 +9268,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9244
9268
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeMustBeAssigned(), errorNode);
|
9245
9269
|
return undefined;
|
9246
9270
|
}
|
9271
|
+
const scope = ScopeUtils.getScopeForNode(errorNode);
|
9272
|
+
if (scope) {
|
9273
|
+
if (scope.type !== 3 /* ScopeType.Class */ && scope.type !== 4 /* ScopeType.Module */ && scope.type !== 5 /* ScopeType.Builtin */) {
|
9274
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeBadScope(), errorNode.parent.d.leftExpr);
|
9275
|
+
}
|
9276
|
+
}
|
9247
9277
|
const nameNode = errorNode.parent.d.leftExpr;
|
9248
9278
|
const firstArg = argList[0];
|
9249
9279
|
if (firstArg.valueExpression && firstArg.valueExpression.nodeType === 48 /* ParseNodeType.StringList */) {
|
@@ -9715,8 +9745,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9715
9745
|
typeErrors = true;
|
9716
9746
|
}
|
9717
9747
|
// Strip any literal values and TypeForm types.
|
9718
|
-
const keyTypes = keyTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags,
|
9719
|
-
const valueTypes = valueTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags,
|
9748
|
+
const keyTypes = keyTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, !hasExpectedType)));
|
9749
|
+
const valueTypes = valueTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, !hasExpectedType)));
|
9720
9750
|
if (keyTypes.length > 0) {
|
9721
9751
|
if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.strictDictionaryInference || hasExpectedType) {
|
9722
9752
|
keyType = (0, types_1.combineTypes)(keyTypes);
|
@@ -10085,7 +10115,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10085
10115
|
else {
|
10086
10116
|
entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvalFlags.StripTupleLiterals */);
|
10087
10117
|
}
|
10088
|
-
entryTypeResult.type = (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(entryTypeResult.type, flags,
|
10118
|
+
entryTypeResult.type = (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(entryTypeResult.type, flags, !hasExpectedType));
|
10089
10119
|
if (entryTypeResult.isIncomplete) {
|
10090
10120
|
isIncomplete = true;
|
10091
10121
|
}
|
@@ -10373,7 +10403,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10373
10403
|
: undefined, () => {
|
10374
10404
|
const returnTypeResult = getTypeOfExpression(node.d.expr,
|
10375
10405
|
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
|
10376
|
-
functionType.priv.inferredReturnType =
|
10406
|
+
functionType.priv.inferredReturnType = {
|
10407
|
+
type: returnTypeResult.type,
|
10408
|
+
};
|
10377
10409
|
if (returnTypeResult.isIncomplete) {
|
10378
10410
|
isIncomplete = true;
|
10379
10411
|
}
|
@@ -12252,16 +12284,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12252
12284
|
else if (arg.d.name.d.value === 'total' && !constArgValue) {
|
12253
12285
|
classType.shared.flags |= 32 /* ClassTypeFlags.CanOmitDictValues */;
|
12254
12286
|
}
|
12255
|
-
else if (arg.d.name.d.value === 'closed'
|
12287
|
+
else if (arg.d.name.d.value === 'closed' &&
|
12288
|
+
AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
|
12256
12289
|
if (constArgValue) {
|
12257
|
-
|
12258
|
-
|
12259
|
-
|
12260
|
-
|
12261
|
-
16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
|
12262
|
-
if (classType.shared.typedDictExtraItemsExpr) {
|
12263
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
|
12264
|
-
}
|
12290
|
+
classType.shared.flags |=
|
12291
|
+
8 /* ClassTypeFlags.TypedDictMarkedClosed */ | 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
|
12292
|
+
if (classType.shared.typedDictExtraItemsExpr) {
|
12293
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
|
12265
12294
|
}
|
12266
12295
|
}
|
12267
12296
|
if (sawClosedOrExtraItems) {
|
@@ -12270,16 +12299,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12270
12299
|
sawClosedOrExtraItems = true;
|
12271
12300
|
}
|
12272
12301
|
}
|
12273
|
-
else if (arg.d.name.d.value === 'extra_items'
|
12274
|
-
|
12275
|
-
|
12276
|
-
|
12277
|
-
|
12278
|
-
|
12279
|
-
|
12280
|
-
|
12281
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
|
12282
|
-
}
|
12302
|
+
else if (arg.d.name.d.value === 'extra_items' &&
|
12303
|
+
AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
|
12304
|
+
// Record a reference to the expression but don't evaluate it yet.
|
12305
|
+
// It may refer to the class itself.
|
12306
|
+
classType.shared.typedDictExtraItemsExpr = arg.d.valueExpr;
|
12307
|
+
classType.shared.flags |= 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
|
12308
|
+
if (types_1.ClassType.isTypedDictMarkedClosed(classType)) {
|
12309
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
|
12283
12310
|
}
|
12284
12311
|
if (sawClosedOrExtraItems) {
|
12285
12312
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), arg.d.valueExpr);
|
@@ -12592,6 +12619,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12592
12619
|
}
|
12593
12620
|
}
|
12594
12621
|
};
|
12622
|
+
// If Any is defined using a class statement, treat it as a special form.
|
12623
|
+
if (node.d.name.d.value === 'Any' && fileInfo.isTypingStubFile) {
|
12624
|
+
decoratedType = types_1.AnyType.createSpecialForm();
|
12625
|
+
}
|
12595
12626
|
// Update the undecorated class type.
|
12596
12627
|
writeTypeCache(node.d.name, { type: classType }, 0 /* EvalFlags.None */);
|
12597
12628
|
// Update the decorated class type.
|
@@ -13335,21 +13366,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13335
13366
|
if (functionType.shared.declaredReturnType && returnTypeAnnotationNode) {
|
13336
13367
|
(0, typeUtils_1.addTypeVarsToListIfUnique)(typeParamsSeen, (0, typeUtils_1.getTypeVarArgsRecursive)(functionType.shared.declaredReturnType), functionType.shared.typeVarScopeId);
|
13337
13368
|
}
|
13338
|
-
// If the return type is explicitly annotated as a generator, mark the
|
13339
|
-
// function as a generator even though it may not contain a "yield" statement.
|
13340
|
-
// This is important for generator functions declared in stub files, abstract
|
13341
|
-
// methods or protocol definitions.
|
13342
|
-
if (fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.d.suite)) {
|
13343
|
-
if (functionType.shared.declaredReturnType &&
|
13344
|
-
(0, types_1.isClassInstance)(functionType.shared.declaredReturnType) &&
|
13345
|
-
types_1.ClassType.isBuiltIn(functionType.shared.declaredReturnType, [
|
13346
|
-
'Generator',
|
13347
|
-
'AsyncGenerator',
|
13348
|
-
'AwaitableGenerator',
|
13349
|
-
])) {
|
13350
|
-
functionType.shared.flags |= 16 /* FunctionTypeFlags.Generator */;
|
13351
|
-
}
|
13352
|
-
}
|
13353
13369
|
// Validate the default types for all type parameters.
|
13354
13370
|
functionType.shared.typeParams.forEach((typeParam, index) => {
|
13355
13371
|
let bestErrorNode = node.d.name;
|
@@ -13533,7 +13549,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13533
13549
|
awaitableFunctionType.shared.declaredReturnType = createAwaitableReturnType(node, functionType.shared.declaredReturnType, types_1.FunctionType.isGenerator(functionType));
|
13534
13550
|
}
|
13535
13551
|
else {
|
13536
|
-
awaitableFunctionType.priv.inferredReturnType =
|
13552
|
+
awaitableFunctionType.priv.inferredReturnType = {
|
13553
|
+
type: createAwaitableReturnType(node, getInferredReturnType(functionType), types_1.FunctionType.isGenerator(functionType)),
|
13554
|
+
};
|
13537
13555
|
}
|
13538
13556
|
return awaitableFunctionType;
|
13539
13557
|
}
|
@@ -13556,11 +13574,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13556
13574
|
awaitableReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(asyncGeneratorType, typeArgs));
|
13557
13575
|
}
|
13558
13576
|
}
|
13559
|
-
else if (['
|
13560
|
-
// If it's already an
|
13561
|
-
// leave it as is.
|
13577
|
+
else if (['AsyncIterator', 'AsyncIterable'].some((name) => name === returnType.shared.name)) {
|
13578
|
+
// If it's already an AsyncIterator or AsyncIterable, leave it as is.
|
13562
13579
|
awaitableReturnType = returnType;
|
13563
13580
|
}
|
13581
|
+
else if (returnType.shared.name === 'AsyncGenerator') {
|
13582
|
+
// If it's already an AsyncGenerator and the function is a generator,
|
13583
|
+
// leave it as is.
|
13584
|
+
if (isGenerator) {
|
13585
|
+
awaitableReturnType = returnType;
|
13586
|
+
}
|
13587
|
+
}
|
13564
13588
|
}
|
13565
13589
|
}
|
13566
13590
|
if (!awaitableReturnType || !isGenerator) {
|
@@ -16594,8 +16618,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16594
16618
|
}
|
16595
16619
|
// If the return type has already been lazily evaluated,
|
16596
16620
|
// don't bother computing it again.
|
16597
|
-
if (type.priv.inferredReturnType) {
|
16598
|
-
returnType = type.priv.inferredReturnType;
|
16621
|
+
if (type.priv.inferredReturnType && !type.priv.inferredReturnType.isIncomplete) {
|
16622
|
+
returnType = type.priv.inferredReturnType.type;
|
16599
16623
|
}
|
16600
16624
|
else {
|
16601
16625
|
// Don't bother inferring the return type of __init__ because it's
|
@@ -16642,9 +16666,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16642
16666
|
}
|
16643
16667
|
returnType = (0, typeUtils_1.makeTypeVarsFree)(returnType, typeVarScopes);
|
16644
16668
|
// Cache the type for next time.
|
16645
|
-
|
16646
|
-
type.priv.inferredReturnType = returnType;
|
16647
|
-
}
|
16669
|
+
type.priv.inferredReturnType = { type: returnType, isIncomplete };
|
16648
16670
|
}
|
16649
16671
|
// If the type is partially unknown and the function has one or more unannotated
|
16650
16672
|
// params, try to analyze the function with the provided argument types and
|
@@ -17640,6 +17662,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17640
17662
|
}
|
17641
17663
|
}
|
17642
17664
|
let concreteSrcType = makeTopLevelTypeVarsConcrete(srcType);
|
17665
|
+
// Handle the TypeForm special form. Add a special case for
|
17666
|
+
// type[T] to be assignable to TypeForm[T].
|
17667
|
+
if (types_1.ClassType.isBuiltIn(destType, 'TypeForm')) {
|
17668
|
+
const destTypeArg = destType.priv.typeArgs && destType.priv.typeArgs.length > 0
|
17669
|
+
? destType.priv.typeArgs[0]
|
17670
|
+
: types_1.UnknownType.create();
|
17671
|
+
let srcTypeArg;
|
17672
|
+
if ((0, types_1.isClassInstance)(concreteSrcType) && types_1.ClassType.isBuiltIn(concreteSrcType, 'type')) {
|
17673
|
+
srcTypeArg = concreteSrcType;
|
17674
|
+
}
|
17675
|
+
else if ((0, types_1.isInstantiableClass)(concreteSrcType)) {
|
17676
|
+
srcTypeArg = (0, typeUtils_1.convertToInstance)(concreteSrcType);
|
17677
|
+
}
|
17678
|
+
if (srcTypeArg) {
|
17679
|
+
return assignType(destTypeArg, srcTypeArg, diag, constraints, flags, recursionCount);
|
17680
|
+
}
|
17681
|
+
}
|
17643
17682
|
if ((0, types_1.isClass)(concreteSrcType) && types_1.TypeBase.isInstance(concreteSrcType)) {
|
17644
17683
|
// Handle the case where the source is an unpacked tuple.
|
17645
17684
|
if (!destType.priv.isUnpacked &&
|
@@ -19850,37 +19889,48 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19850
19889
|
// is the type used to reference the member.
|
19851
19890
|
function partiallySpecializeBoundMethod(baseType, memberType, diag, recursionCount, firstParamType, stripFirstParam = true) {
|
19852
19891
|
const constraints = new constraintTracker_1.ConstraintTracker();
|
19853
|
-
if (firstParamType
|
19854
|
-
|
19855
|
-
|
19856
|
-
|
19857
|
-
memberTypeFirstParamType
|
19858
|
-
|
19859
|
-
|
19860
|
-
|
19861
|
-
|
19862
|
-
|
19863
|
-
|
19864
|
-
|
19865
|
-
|
19866
|
-
|
19892
|
+
if (firstParamType) {
|
19893
|
+
if (memberType.shared.parameters.length > 0) {
|
19894
|
+
const memberTypeFirstParam = memberType.shared.parameters[0];
|
19895
|
+
const memberTypeFirstParamType = types_1.FunctionType.getParamType(memberType, 0);
|
19896
|
+
if ((0, types_1.isTypeVar)(memberTypeFirstParamType) &&
|
19897
|
+
memberTypeFirstParamType.shared.boundType &&
|
19898
|
+
(0, types_1.isClassInstance)(memberTypeFirstParamType.shared.boundType) &&
|
19899
|
+
types_1.ClassType.isProtocolClass(memberTypeFirstParamType.shared.boundType)) {
|
19900
|
+
// Handle the protocol class specially. Some protocol classes
|
19901
|
+
// contain references to themselves or their subclasses, so if
|
19902
|
+
// we attempt to call assignType, we'll risk infinite recursion.
|
19903
|
+
// Instead, we'll assume it's assignable.
|
19904
|
+
constraints.setBounds(memberTypeFirstParamType, types_1.TypeBase.isInstantiable(memberTypeFirstParamType)
|
19905
|
+
? (0, typeUtils_1.convertToInstance)(firstParamType)
|
19906
|
+
: firstParamType);
|
19907
|
+
}
|
19908
|
+
else {
|
19909
|
+
const subDiag = diag?.createAddendum();
|
19910
|
+
if (!assignType(memberTypeFirstParamType, firstParamType, subDiag?.createAddendum(), constraints, 8192 /* AssignTypeFlags.AllowUnspecifiedTypeArgs */, recursionCount)) {
|
19911
|
+
if (memberTypeFirstParam.name &&
|
19912
|
+
!types_1.FunctionParam.isNameSynthesized(memberTypeFirstParam) &&
|
19913
|
+
types_1.FunctionParam.isTypeDeclared(memberTypeFirstParam)) {
|
19914
|
+
if (subDiag) {
|
19915
|
+
subDiag.addMessage(localize_1.LocMessage.bindTypeMismatch().format({
|
19916
|
+
type: printType(firstParamType),
|
19917
|
+
methodName: memberType.shared.name || '<anonymous>',
|
19918
|
+
paramName: memberTypeFirstParam.name,
|
19919
|
+
}));
|
19920
|
+
}
|
19921
|
+
return undefined;
|
19922
|
+
}
|
19923
|
+
}
|
19924
|
+
}
|
19867
19925
|
}
|
19868
19926
|
else {
|
19869
19927
|
const subDiag = diag?.createAddendum();
|
19870
|
-
if (
|
19871
|
-
|
19872
|
-
|
19873
|
-
|
19874
|
-
if (subDiag) {
|
19875
|
-
subDiag.addMessage(localize_1.LocMessage.bindTypeMismatch().format({
|
19876
|
-
type: printType(firstParamType),
|
19877
|
-
methodName: memberType.shared.name || '<anonymous>',
|
19878
|
-
paramName: memberTypeFirstParam.name,
|
19879
|
-
}));
|
19880
|
-
}
|
19881
|
-
return undefined;
|
19882
|
-
}
|
19928
|
+
if (subDiag) {
|
19929
|
+
subDiag.addMessage(localize_1.LocMessage.bindParamMissing().format({
|
19930
|
+
methodName: memberType.shared.name || '<anonymous>',
|
19931
|
+
}));
|
19883
19932
|
}
|
19933
|
+
return undefined;
|
19884
19934
|
}
|
19885
19935
|
}
|
19886
19936
|
// Get the effective return type, which will have the side effect of lazily
|