@zzzen/pyright-internal 1.2.0-dev.20250309 → 1.2.0-dev.20250316
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/binder.js +1 -1
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +1 -1
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/operations.js +10 -2
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/service.d.ts +2 -0
- package/dist/analyzer/service.js +15 -3
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +84 -49
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -0
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/languageServerBase.d.ts +7 -3
- package/dist/languageServerBase.js +124 -2
- package/dist/languageServerBase.js.map +1 -1
- package/dist/pyright.js +9 -3
- package/dist/pyright.js.map +1 -1
- package/dist/tests/languageServer.test.js +97 -57
- package/dist/tests/languageServer.test.js.map +1 -1
- package/dist/tests/lsp/customLsp.d.ts +8 -1
- package/dist/tests/lsp/customLsp.js +1 -0
- package/dist/tests/lsp/customLsp.js.map +1 -1
- package/dist/tests/lsp/languageServer.js +12 -0
- package/dist/tests/lsp/languageServer.js.map +1 -1
- package/dist/tests/lsp/languageServerTestUtils.d.ts +7 -3
- package/dist/tests/lsp/languageServerTestUtils.js +90 -6
- package/dist/tests/lsp/languageServerTestUtils.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +1 -1
- package/dist/types.d.ts +6 -2
- package/package.json +1 -1
@@ -194,7 +194,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
194
194
|
let deferredClassCompletions = [];
|
195
195
|
let cancellationToken;
|
196
196
|
let printExpressionSpaceCount = 0;
|
197
|
-
let
|
197
|
+
let incompleteGenCount = 0;
|
198
198
|
const returnTypeInferenceContextStack = [];
|
199
199
|
let returnTypeInferenceTypeCache;
|
200
200
|
const signatureTrackerStack = [];
|
@@ -255,7 +255,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
255
255
|
if (!cacheEntry) {
|
256
256
|
return false;
|
257
257
|
}
|
258
|
-
return
|
258
|
+
return !cacheEntry.typeResult.isIncomplete || cacheEntry.incompleteGenCount === incompleteGenCount;
|
259
259
|
}
|
260
260
|
function readTypeCache(node, flags) {
|
261
261
|
const cacheEntry = readTypeCacheEntry(node);
|
@@ -290,22 +290,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
290
290
|
? returnTypeInferenceTypeCache
|
291
291
|
: typeCache;
|
292
292
|
if (!typeResult.isIncomplete) {
|
293
|
-
|
293
|
+
incompleteGenCount++;
|
294
294
|
}
|
295
295
|
else {
|
296
296
|
const oldValue = typeCacheToUse.get(node.id);
|
297
297
|
if (oldValue !== undefined && !(0, types_1.isTypeSame)(typeResult.type, oldValue.typeResult.type)) {
|
298
|
-
|
298
|
+
incompleteGenCount++;
|
299
299
|
}
|
300
300
|
}
|
301
|
-
typeCacheToUse.set(node.id, { typeResult, flags,
|
301
|
+
typeCacheToUse.set(node.id, { typeResult, flags, incompleteGenCount });
|
302
302
|
// If the entry is located within a part of the parse tree that is currently being
|
303
303
|
// "speculatively" evaluated, track it so we delete the cached entry when we leave
|
304
304
|
// this speculative context.
|
305
305
|
if (isSpeculativeModeInUse(node)) {
|
306
306
|
speculativeTypeTracker.trackEntry(typeCacheToUse, node.id);
|
307
307
|
if (allowSpeculativeCaching) {
|
308
|
-
speculativeTypeTracker.addSpeculativeType(node, typeResult,
|
308
|
+
speculativeTypeTracker.addSpeculativeType(node, typeResult, incompleteGenCount, inferenceContext?.expectedType);
|
309
309
|
}
|
310
310
|
}
|
311
311
|
}
|
@@ -531,23 +531,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
531
531
|
function getTypeOfExpression(node, flags = 0 /* EvalFlags.None */, inferenceContext) {
|
532
532
|
// Is this type already cached?
|
533
533
|
const cacheEntry = readTypeCacheEntry(node);
|
534
|
-
if (cacheEntry
|
535
|
-
(!cacheEntry.typeResult.isIncomplete || cacheEntry.
|
536
|
-
|
537
|
-
|
534
|
+
if (cacheEntry) {
|
535
|
+
if (!cacheEntry.typeResult.isIncomplete || cacheEntry.incompleteGenCount === incompleteGenCount) {
|
536
|
+
if (printExpressionTypes) {
|
537
|
+
console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Cached ${printType(cacheEntry.typeResult.type)} ${cacheEntry.typeResult.typeErrors ? ' Errors' : ''}`);
|
538
|
+
}
|
539
|
+
return cacheEntry.typeResult;
|
538
540
|
}
|
539
|
-
return cacheEntry.typeResult;
|
540
541
|
}
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
if (
|
545
|
-
|
546
|
-
cacheEntry.incompleteGenerationCount === incompleteGenerationCount)) {
|
542
|
+
// Is it cached in the speculative type cache?
|
543
|
+
const specCacheEntry = speculativeTypeTracker.getSpeculativeType(node, inferenceContext?.expectedType);
|
544
|
+
if (specCacheEntry) {
|
545
|
+
if (!specCacheEntry.typeResult.isIncomplete ||
|
546
|
+
specCacheEntry.incompleteGenerationCount === incompleteGenCount) {
|
547
547
|
if (printExpressionTypes) {
|
548
|
-
console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Speculative ${printType(
|
548
|
+
console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Speculative ${printType(specCacheEntry.typeResult.type)}`);
|
549
549
|
}
|
550
|
-
return
|
550
|
+
return specCacheEntry.typeResult;
|
551
551
|
}
|
552
552
|
}
|
553
553
|
if (printExpressionTypes) {
|
@@ -6904,11 +6904,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6904
6904
|
case 3 /* TypeCategory.Never */:
|
6905
6905
|
case 1 /* TypeCategory.Unknown */:
|
6906
6906
|
case 2 /* TypeCategory.Any */: {
|
6907
|
-
//
|
6908
|
-
//
|
6909
|
-
|
6910
|
-
|
6911
|
-
|
6907
|
+
// Create a dummy callable that accepts all arguments and validate
|
6908
|
+
// that the argument expressions are valid.
|
6909
|
+
const dummyFunctionType = types_1.FunctionType.createInstance('', '', '', 0 /* FunctionTypeFlags.None */);
|
6910
|
+
types_1.FunctionType.addDefaultParams(dummyFunctionType);
|
6911
|
+
const dummyCallResult = validateCallForFunction(errorNode, argList, dummyFunctionType, isCallTypeIncomplete, constraints, skipUnknownArgCheck, inferenceContext);
|
6912
|
+
return { ...dummyCallResult, returnType: expandedCallType };
|
6912
6913
|
}
|
6913
6914
|
case 4 /* TypeCategory.Function */: {
|
6914
6915
|
return validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, constraints, skipUnknownArgCheck, inferenceContext);
|
@@ -7563,6 +7564,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7563
7564
|
let isArgCompatibleWithVariadic = false;
|
7564
7565
|
const argTypeResult = getTypeOfArg(argList[argIndex], /* inferenceContext */ undefined);
|
7565
7566
|
let listElementType;
|
7567
|
+
let enforceIterable = false;
|
7566
7568
|
let advanceToNextArg = false;
|
7567
7569
|
// Handle the case where *args is being passed to a function defined
|
7568
7570
|
// with a ParamSpec and a Concatenate operator. PEP 612 indicates that
|
@@ -7622,6 +7624,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7622
7624
|
listElementType = getTypeOfIterator({ type: argType, isIncomplete: argTypeResult.isIncomplete },
|
7623
7625
|
/* isAsync */ false, errorNode,
|
7624
7626
|
/* emitNotIterableError */ false)?.type;
|
7627
|
+
if (!listElementType) {
|
7628
|
+
enforceIterable = true;
|
7629
|
+
}
|
7625
7630
|
if (paramInfo.param.category === 1 /* ParamCategory.ArgsList */) {
|
7626
7631
|
matchedUnpackedListOfUnknownLength = true;
|
7627
7632
|
}
|
@@ -7636,7 +7641,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7636
7641
|
argCategory: 0 /* ArgCategory.Simple */,
|
7637
7642
|
typeResult: { type: listElementType, isIncomplete: argTypeResult.isIncomplete },
|
7638
7643
|
}
|
7639
|
-
: { ...argList[argIndex] };
|
7644
|
+
: { ...argList[argIndex], enforceIterable };
|
7640
7645
|
if (argTypeResult.isIncomplete) {
|
7641
7646
|
isTypeIncomplete = true;
|
7642
7647
|
}
|
@@ -8761,9 +8766,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8761
8766
|
else {
|
8762
8767
|
skippedBareTypeVarExpectedType = true;
|
8763
8768
|
}
|
8764
|
-
// If the expected type is
|
8769
|
+
// If the expected type is Any, don't use an expected type. Instead,
|
8765
8770
|
// use default rules for evaluating the expression type.
|
8766
|
-
if (expectedType && (0, types_1.
|
8771
|
+
if (expectedType && (0, types_1.isAnyOrUnknown)(expectedType)) {
|
8767
8772
|
expectedType = undefined;
|
8768
8773
|
}
|
8769
8774
|
// Was the argument's type precomputed by the caller?
|
@@ -8776,13 +8781,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8776
8781
|
: 16 /* EvalFlags.NoFinal */ | 2 /* EvalFlags.NoSpecialize */;
|
8777
8782
|
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!typeResult?.isIncomplete));
|
8778
8783
|
argType = exprTypeResult.type;
|
8784
|
+
// If the argument is unpacked and we are supposed to enforce
|
8785
|
+
// that it's an iterator, do so now.
|
8786
|
+
if (argParam.argument.argCategory === 1 /* ArgCategory.UnpackedList */ && argParam.argument.enforceIterable) {
|
8787
|
+
const iteratorType = getTypeOfIterator(exprTypeResult,
|
8788
|
+
/* isAsync */ false, argParam.argument.valueExpression);
|
8789
|
+
// Try to prevent cascading errors if it was not iterable.
|
8790
|
+
argType = iteratorType?.type ?? types_1.UnknownType.create();
|
8791
|
+
}
|
8779
8792
|
if (exprTypeResult.isIncomplete) {
|
8780
8793
|
isTypeIncomplete = true;
|
8781
8794
|
}
|
8782
|
-
if (
|
8783
|
-
isCompatible = false;
|
8784
|
-
}
|
8785
|
-
else if (expectedType && (0, typeUtils_1.requiresSpecialization)(expectedType)) {
|
8795
|
+
if (expectedType && (0, typeUtils_1.requiresSpecialization)(expectedType)) {
|
8786
8796
|
// Assign the argument type back to the expected type to assign
|
8787
8797
|
// values to any unification variables.
|
8788
8798
|
const clonedConstraints = constraints.clone();
|
@@ -15737,11 +15747,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15737
15747
|
if (declaration.intrinsicType === 'int') {
|
15738
15748
|
return { type: intType };
|
15739
15749
|
}
|
15740
|
-
if (declaration.intrinsicType === '
|
15741
|
-
const
|
15742
|
-
if ((0, types_1.isInstantiableClass)(
|
15750
|
+
if (declaration.intrinsicType === 'MutableSequence[str]') {
|
15751
|
+
const sequenceType = getBuiltInType(declaration.node, 'MutableSequence');
|
15752
|
+
if ((0, types_1.isInstantiableClass)(sequenceType)) {
|
15743
15753
|
return {
|
15744
|
-
type: types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(
|
15754
|
+
type: types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(sequenceType, [strType])),
|
15745
15755
|
};
|
15746
15756
|
}
|
15747
15757
|
}
|
@@ -16014,18 +16024,30 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16014
16024
|
}
|
16015
16025
|
if (loaderActions.implicitImports) {
|
16016
16026
|
loaderActions.implicitImports.forEach((implicitImport, name) => {
|
16027
|
+
const existingLoaderField = moduleType.priv.loaderFields.get(name);
|
16017
16028
|
// Recursively apply loader actions.
|
16018
16029
|
let symbolType;
|
16019
16030
|
if (implicitImport.isUnresolved) {
|
16020
16031
|
symbolType = types_1.UnknownType.create();
|
16021
16032
|
}
|
16022
16033
|
else {
|
16023
|
-
|
16024
|
-
const
|
16034
|
+
let importedModuleType;
|
16035
|
+
const existingType = existingLoaderField?.getSynthesizedType();
|
16036
|
+
if (existingType?.type && (0, types_1.isModule)(existingType.type)) {
|
16037
|
+
importedModuleType = existingType.type;
|
16038
|
+
}
|
16039
|
+
else {
|
16040
|
+
const moduleName = moduleType.priv.moduleName
|
16041
|
+
? moduleType.priv.moduleName + '.' + name
|
16042
|
+
: '';
|
16043
|
+
importedModuleType = types_1.ModuleType.create(moduleName, implicitImport.uri);
|
16044
|
+
}
|
16025
16045
|
symbolType = applyLoaderActionsToModuleType(importedModuleType, implicitImport, importLookup);
|
16026
16046
|
}
|
16027
|
-
|
16028
|
-
|
16047
|
+
if (!existingLoaderField) {
|
16048
|
+
const importedModuleSymbol = symbol_1.Symbol.createWithType(0 /* SymbolFlags.None */, symbolType);
|
16049
|
+
moduleType.priv.loaderFields.set(name, importedModuleSymbol);
|
16050
|
+
}
|
16029
16051
|
});
|
16030
16052
|
}
|
16031
16053
|
return moduleType;
|
@@ -16034,15 +16056,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16034
16056
|
// is pointing at a module, and we need to synthesize a
|
16035
16057
|
// module type.
|
16036
16058
|
if (resolvedDecl.type === 8 /* DeclarationType.Alias */) {
|
16037
|
-
|
16038
|
-
//
|
16039
|
-
|
16040
|
-
|
16041
|
-
|
16059
|
+
let moduleType;
|
16060
|
+
// See if this is an import that shares a ModuleType with another
|
16061
|
+
// import statement. If so, used the cached type. This happens when
|
16062
|
+
// multiple import statements start with the same module name, such
|
16063
|
+
// as "import a.b" and "import a.c".
|
16064
|
+
if (resolvedDecl.node.nodeType === 24 /* ParseNodeType.ImportAs */) {
|
16065
|
+
const cachedType = readTypeCache(resolvedDecl.node.d.module, 0 /* EvalFlags.None */);
|
16066
|
+
if (cachedType && (0, types_1.isModule)(cachedType)) {
|
16067
|
+
moduleType = cachedType;
|
16068
|
+
}
|
16042
16069
|
}
|
16043
|
-
|
16044
|
-
|
16070
|
+
if (!moduleType) {
|
16071
|
+
// Build a module type that corresponds to the declaration and
|
16072
|
+
// its associated loader actions.
|
16073
|
+
moduleType = types_1.ModuleType.create(resolvedDecl.moduleName, resolvedDecl.uri);
|
16074
|
+
if (resolvedDecl.node.nodeType === 24 /* ParseNodeType.ImportAs */) {
|
16075
|
+
writeTypeCache(resolvedDecl.node.d.module, { type: moduleType }, 0 /* EvalFlags.None */);
|
16076
|
+
}
|
16045
16077
|
}
|
16078
|
+
return applyLoaderActionsToModuleType(moduleType, resolvedDecl.symbolName && resolvedDecl.submoduleFallback
|
16079
|
+
? resolvedDecl.submoduleFallback
|
16080
|
+
: resolvedDecl, importLookup);
|
16046
16081
|
}
|
16047
16082
|
const declaredType = getTypeForDeclaration(resolvedDecl);
|
16048
16083
|
if (declaredType.type) {
|
@@ -19332,12 +19367,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19332
19367
|
// with the declared type. In strict mode, this will retain the "unknown type"
|
19333
19368
|
// diagnostics while still providing reasonable completion suggestions.
|
19334
19369
|
if ((0, typeUtils_1.isIncompleteUnknown)(narrowedType)) {
|
19335
|
-
return { type: narrowedType };
|
19370
|
+
return { type: narrowedType, isIncomplete: assignedTypeResult.isIncomplete };
|
19336
19371
|
}
|
19337
19372
|
else if ((0, types_1.isUnknown)(narrowedType)) {
|
19338
|
-
return { type: (0, types_1.combineTypes)([narrowedType, declaredType]) };
|
19373
|
+
return { type: (0, types_1.combineTypes)([narrowedType, declaredType]), isIncomplete: assignedTypeResult.isIncomplete };
|
19339
19374
|
}
|
19340
|
-
return { type: narrowedType };
|
19375
|
+
return { type: narrowedType, isIncomplete: assignedTypeResult.isIncomplete };
|
19341
19376
|
}
|
19342
19377
|
function validateOverrideMethod(baseMethod, overrideMethod, baseClass, diag, enforceParamNames = true) {
|
19343
19378
|
// If we're overriding a non-method with a method, report it as an error.
|