@zzzen/pyright-internal 1.2.0-dev.20250223 → 1.2.0-dev.20250309
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/analyzerNodeInfo.js +0 -3
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +1 -1
- package/dist/analyzer/importResolver.js +1 -2
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +1 -1
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/tuples.js +3 -2
- package/dist/analyzer/tuples.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +60 -46
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -1
- package/dist/analyzer/typeGuards.js +2 -2
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/types.js +11 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +2 -2
- package/dist/backgroundAnalysisBase.js +23 -15
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/common/cancellationUtils.d.ts +2 -1
- package/dist/common/cancellationUtils.js +8 -1
- 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/serviceProviderExtensions.d.ts +2 -2
- package/dist/common/serviceProviderExtensions.js +8 -4
- package/dist/common/serviceProviderExtensions.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.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/tests/serialization.test.js +7 -0
- package/dist/tests/serialization.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator6.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");
|
@@ -86,7 +87,6 @@ const typeGuards_1 = require("./typeGuards");
|
|
86
87
|
const TypePrinter = __importStar(require("./typePrinter"));
|
87
88
|
const types_1 = require("./types");
|
88
89
|
const typeUtils_1 = require("./typeUtils");
|
89
|
-
const core_1 = require("../common/core");
|
90
90
|
// This table contains the names of several built-in types that
|
91
91
|
// are not subscriptable at runtime on older versions of Python.
|
92
92
|
// It lists the first version of Python where subscripting is
|
@@ -5778,7 +5778,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5778
5778
|
}
|
5779
5779
|
return typeResult;
|
5780
5780
|
}
|
5781
|
-
function buildTupleTypesList(entryTypeResults, stripLiterals) {
|
5781
|
+
function buildTupleTypesList(entryTypeResults, stripLiterals, convertModule) {
|
5782
5782
|
const entryTypes = [];
|
5783
5783
|
for (const typeResult of entryTypeResults) {
|
5784
5784
|
let possibleUnpackedTuple;
|
@@ -5807,8 +5807,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5807
5807
|
entryTypes.push({ type: types_1.UnknownType.create(/* isIncomplete */ true), isUnbounded: false });
|
5808
5808
|
}
|
5809
5809
|
else {
|
5810
|
-
let entryType = convertSpecialFormToRuntimeValue(typeResult.type, 0 /* EvalFlags.None */,
|
5811
|
-
/* convertModule */ true);
|
5810
|
+
let entryType = convertSpecialFormToRuntimeValue(typeResult.type, 0 /* EvalFlags.None */, convertModule);
|
5812
5811
|
entryType = stripLiterals ? (0, typeUtils_1.stripTypeForm)(stripLiteralValue(entryType)) : entryType;
|
5813
5812
|
entryTypes.push({ type: entryType, isUnbounded: !!typeResult.unpackedType });
|
5814
5813
|
}
|
@@ -6892,6 +6891,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6892
6891
|
};
|
6893
6892
|
}
|
6894
6893
|
function validateCallArgsForSubtype(errorNode, argList, expandedCallType, unexpandedCallType, isCallTypeIncomplete, constraints, skipUnknownArgCheck, inferenceContext, recursionCount) {
|
6894
|
+
function touchArgTypes() {
|
6895
|
+
if (!isCallTypeIncomplete) {
|
6896
|
+
argList.forEach((arg) => {
|
6897
|
+
if (arg.valueExpression && !isSpeculativeModeInUse(arg.valueExpression)) {
|
6898
|
+
getTypeOfArg(arg, /* inferenceContext */ undefined);
|
6899
|
+
}
|
6900
|
+
});
|
6901
|
+
}
|
6902
|
+
}
|
6895
6903
|
switch (expandedCallType.category) {
|
6896
6904
|
case 3 /* TypeCategory.Never */:
|
6897
6905
|
case 1 /* TypeCategory.Unknown */:
|
@@ -6899,13 +6907,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6899
6907
|
// Touch all of the args so they're marked accessed. Don't bother
|
6900
6908
|
// doing this if the call type is incomplete because this will need
|
6901
6909
|
// to be done again once it is complete.
|
6902
|
-
|
6903
|
-
argList.forEach((arg) => {
|
6904
|
-
if (arg.valueExpression && !isSpeculativeModeInUse(arg.valueExpression)) {
|
6905
|
-
getTypeOfArg(arg, /* inferenceContext */ undefined);
|
6906
|
-
}
|
6907
|
-
});
|
6908
|
-
}
|
6910
|
+
touchArgTypes();
|
6909
6911
|
return { returnType: expandedCallType };
|
6910
6912
|
}
|
6911
6913
|
case 4 /* TypeCategory.Function */: {
|
@@ -6936,6 +6938,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6936
6938
|
return { argumentErrors: true };
|
6937
6939
|
}
|
6938
6940
|
}
|
6941
|
+
touchArgTypes();
|
6939
6942
|
return { argumentErrors: true };
|
6940
6943
|
}
|
6941
6944
|
function validateCallForFunction(errorNode, argList, type, isCallTypeIncomplete, constraints, skipUnknownArgCheck, inferenceContext) {
|
@@ -7622,6 +7625,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7622
7625
|
if (paramInfo.param.category === 1 /* ParamCategory.ArgsList */) {
|
7623
7626
|
matchedUnpackedListOfUnknownLength = true;
|
7624
7627
|
}
|
7628
|
+
if (isParamVariadic && listElementType) {
|
7629
|
+
isArgCompatibleWithVariadic = true;
|
7630
|
+
listElementType = (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type: listElementType, isUnbounded: true }],
|
7631
|
+
/* isUnpacked */ true);
|
7632
|
+
}
|
7625
7633
|
}
|
7626
7634
|
const funcArg = listElementType
|
7627
7635
|
? {
|
@@ -8126,20 +8134,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8126
8134
|
const param = paramInfo.param;
|
8127
8135
|
if (param.category === 0 /* ParamCategory.Simple */ && param.name) {
|
8128
8136
|
const entry = paramMap.get(param.name);
|
8129
|
-
if (entry && entry.argsNeeded === 0 && entry.argsReceived === 0
|
8130
|
-
|
8131
|
-
|
8132
|
-
|
8133
|
-
|
8134
|
-
|
8135
|
-
|
8136
|
-
|
8137
|
-
|
8138
|
-
|
8139
|
-
|
8140
|
-
|
8141
|
-
|
8142
|
-
|
8137
|
+
if (entry && entry.argsNeeded === 0 && entry.argsReceived === 0) {
|
8138
|
+
const defaultArgType = paramInfo.defaultType;
|
8139
|
+
if (defaultArgType &&
|
8140
|
+
!(0, typeUtils_1.isEllipsisType)(defaultArgType) &&
|
8141
|
+
(0, typeUtils_1.requiresSpecialization)(paramInfo.declaredType, { ignorePseudoGeneric: true })) {
|
8142
|
+
validateArgTypeParams.push({
|
8143
|
+
paramCategory: param.category,
|
8144
|
+
paramType: paramInfo.type,
|
8145
|
+
requiresTypeVarMatching: true,
|
8146
|
+
argument: {
|
8147
|
+
argCategory: 0 /* ArgCategory.Simple */,
|
8148
|
+
typeResult: { type: defaultArgType },
|
8149
|
+
},
|
8150
|
+
isDefaultArg: true,
|
8151
|
+
errorNode,
|
8152
|
+
paramName: param.name,
|
8153
|
+
isParamNameSynthesized: types_1.FunctionParam.isNameSynthesized(param),
|
8154
|
+
});
|
8155
|
+
}
|
8143
8156
|
}
|
8144
8157
|
}
|
8145
8158
|
});
|
@@ -8612,7 +8625,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8612
8625
|
getTypeOfExpression(arg.valueExpression);
|
8613
8626
|
}
|
8614
8627
|
});
|
8628
|
+
// Use a return type of Unknown but attach a "possible type" to it
|
8629
|
+
// so the completion provider can suggest better completions.
|
8630
|
+
const possibleType = types_1.FunctionType.getEffectiveReturnType(typeResult.type);
|
8615
8631
|
return {
|
8632
|
+
returnType: possibleType && !(0, types_1.isAnyOrUnknown)(possibleType)
|
8633
|
+
? types_1.UnknownType.createPossibleType(possibleType, /* isIncomplete */ false)
|
8634
|
+
: undefined,
|
8616
8635
|
argumentErrors: true,
|
8617
8636
|
activeParam: matchResults.activeParam,
|
8618
8637
|
overloadsUsedForCall: [],
|
@@ -9736,8 +9755,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9736
9755
|
typeErrors = true;
|
9737
9756
|
}
|
9738
9757
|
// Strip any literal values and TypeForm types.
|
9739
|
-
const keyTypes = keyTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags,
|
9740
|
-
const valueTypes = valueTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags,
|
9758
|
+
const keyTypes = keyTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, !hasExpectedType)));
|
9759
|
+
const valueTypes = valueTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, !hasExpectedType)));
|
9741
9760
|
if (keyTypes.length > 0) {
|
9742
9761
|
if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.strictDictionaryInference || hasExpectedType) {
|
9743
9762
|
keyType = (0, types_1.combineTypes)(keyTypes);
|
@@ -10106,7 +10125,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10106
10125
|
else {
|
10107
10126
|
entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvalFlags.StripTupleLiterals */);
|
10108
10127
|
}
|
10109
|
-
entryTypeResult.type = (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(entryTypeResult.type, flags,
|
10128
|
+
entryTypeResult.type = (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(entryTypeResult.type, flags, !hasExpectedType));
|
10110
10129
|
if (entryTypeResult.isIncomplete) {
|
10111
10130
|
isIncomplete = true;
|
10112
10131
|
}
|
@@ -12610,6 +12629,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12610
12629
|
}
|
12611
12630
|
}
|
12612
12631
|
};
|
12632
|
+
// If Any is defined using a class statement, treat it as a special form.
|
12633
|
+
if (node.d.name.d.value === 'Any' && fileInfo.isTypingStubFile) {
|
12634
|
+
decoratedType = types_1.AnyType.createSpecialForm();
|
12635
|
+
}
|
12613
12636
|
// Update the undecorated class type.
|
12614
12637
|
writeTypeCache(node.d.name, { type: classType }, 0 /* EvalFlags.None */);
|
12615
12638
|
// Update the decorated class type.
|
@@ -13353,21 +13376,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13353
13376
|
if (functionType.shared.declaredReturnType && returnTypeAnnotationNode) {
|
13354
13377
|
(0, typeUtils_1.addTypeVarsToListIfUnique)(typeParamsSeen, (0, typeUtils_1.getTypeVarArgsRecursive)(functionType.shared.declaredReturnType), functionType.shared.typeVarScopeId);
|
13355
13378
|
}
|
13356
|
-
// If the return type is explicitly annotated as a generator, mark the
|
13357
|
-
// function as a generator even though it may not contain a "yield" statement.
|
13358
|
-
// This is important for generator functions declared in stub files, abstract
|
13359
|
-
// methods or protocol definitions.
|
13360
|
-
if (fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.d.suite)) {
|
13361
|
-
if (functionType.shared.declaredReturnType &&
|
13362
|
-
(0, types_1.isClassInstance)(functionType.shared.declaredReturnType) &&
|
13363
|
-
types_1.ClassType.isBuiltIn(functionType.shared.declaredReturnType, [
|
13364
|
-
'Generator',
|
13365
|
-
'AsyncGenerator',
|
13366
|
-
'AwaitableGenerator',
|
13367
|
-
])) {
|
13368
|
-
functionType.shared.flags |= 16 /* FunctionTypeFlags.Generator */;
|
13369
|
-
}
|
13370
|
-
}
|
13371
13379
|
// Validate the default types for all type parameters.
|
13372
13380
|
functionType.shared.typeParams.forEach((typeParam, index) => {
|
13373
13381
|
let bestErrorNode = node.d.name;
|
@@ -13576,11 +13584,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13576
13584
|
awaitableReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(asyncGeneratorType, typeArgs));
|
13577
13585
|
}
|
13578
13586
|
}
|
13579
|
-
else if (['
|
13580
|
-
// If it's already an
|
13581
|
-
// leave it as is.
|
13587
|
+
else if (['AsyncIterator', 'AsyncIterable'].some((name) => name === returnType.shared.name)) {
|
13588
|
+
// If it's already an AsyncIterator or AsyncIterable, leave it as is.
|
13582
13589
|
awaitableReturnType = returnType;
|
13583
13590
|
}
|
13591
|
+
else if (returnType.shared.name === 'AsyncGenerator') {
|
13592
|
+
// If it's already an AsyncGenerator and the function is a generator,
|
13593
|
+
// leave it as is.
|
13594
|
+
if (isGenerator) {
|
13595
|
+
awaitableReturnType = returnType;
|
13596
|
+
}
|
13597
|
+
}
|
13584
13598
|
}
|
13585
13599
|
}
|
13586
13600
|
if (!awaitableReturnType || !isGenerator) {
|