@zzzen/pyright-internal 1.2.0-dev.20240225 → 1.2.0-dev.20240307
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 +4 -3
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +3 -1
- package/dist/analyzer/codeFlowEngine.js +19 -14
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/enums.js +9 -2
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/operations.js +12 -3
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +14 -6
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +4 -3
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/service.js +1 -1
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +63 -49
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +2 -0
- package/dist/analyzer/typeUtils.js +41 -5
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.js +1 -1
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/configOptions.d.ts +2 -2
- package/dist/common/configOptions.js +21 -4
- package/dist/common/configOptions.js.map +1 -1
- package/dist/localization/localize.d.ts +1 -0
- package/dist/localization/localize.js +1 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +1 -0
- package/dist/localization/package.nls.fr.json +2 -2
- package/dist/tests/fourslash/import.nameconflict.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.nameconflict.fourslash.js +17 -0
- package/dist/tests/fourslash/import.nameconflict.fourslash.js.map +1 -0
- package/dist/tests/typeEvaluator1.test.js +1 -1
- package/dist/tests/typeEvaluator2.test.js +1 -1
- package/dist/tests/typeEvaluator3.test.js +21 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator5.test.js +1 -3
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/package.json +1 -1
@@ -805,6 +805,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
805
805
|
const exprTypeResult = getTypeOfExpression(node.expression, flags, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType));
|
806
806
|
const typeResult = {
|
807
807
|
type: getTypeOfAwaitable(exprTypeResult.type, node.expression),
|
808
|
+
isIncomplete: exprTypeResult.isIncomplete,
|
809
|
+
typeErrors: exprTypeResult.typeErrors,
|
808
810
|
};
|
809
811
|
if (exprTypeResult.isIncomplete) {
|
810
812
|
typeResult.isIncomplete = true;
|
@@ -1549,7 +1551,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1549
1551
|
// see if we can find a better signature from the `__new__` method.
|
1550
1552
|
if (!constructorType || isObjectInit || isDefaultParams) {
|
1551
1553
|
const newMethodResult = (0, constructors_1.getBoundNewMethod)(evaluatorInterface, callNode, subtype, 0 /* MemberAccessFlags.Default */);
|
1552
|
-
if (newMethodResult && !newMethodResult.typeErrors
|
1554
|
+
if (newMethodResult && !newMethodResult.typeErrors) {
|
1553
1555
|
if ((0, types_1.isFunction)(newMethodResult.type) &&
|
1554
1556
|
newMethodResult.type.details.fullName !== 'builtins.object.__new__') {
|
1555
1557
|
constructorType = newMethodResult.type;
|
@@ -2036,10 +2038,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2036
2038
|
if (checkCodeFlowTooComplex(node)) {
|
2037
2039
|
return true;
|
2038
2040
|
}
|
2039
|
-
const codeFlowResult = analyzer.getTypeFromCodeFlow(flowNode,
|
2040
|
-
|
2041
|
-
|
2042
|
-
/* typeAtStart */ types_1.UnboundType.create());
|
2041
|
+
const codeFlowResult = analyzer.getTypeFromCodeFlow(flowNode, /* reference */ undefined, {
|
2042
|
+
typeAtStart: types_1.UnboundType.create(),
|
2043
|
+
});
|
2043
2044
|
return codeFlowResult.type !== undefined && !(0, types_1.isNever)(codeFlowResult.type);
|
2044
2045
|
}
|
2045
2046
|
// Determines whether there is a code flow path from sourceNode to sinkNode.
|
@@ -2194,8 +2195,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2194
2195
|
if (expectedTypeDiagAddendum) {
|
2195
2196
|
diagAddendum = expectedTypeDiagAddendum;
|
2196
2197
|
}
|
2197
|
-
|
2198
|
-
|
2198
|
+
if (!isTypeIncomplete) {
|
2199
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, localize_1.LocMessage.typeAssignmentMismatch().format(printSrcDestTypes(type, declaredType)) +
|
2200
|
+
diagAddendum.getString(), srcExpression !== null && srcExpression !== void 0 ? srcExpression : nameNode, (_c = (_b = diagAddendum.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : srcExpression) !== null && _c !== void 0 ? _c : nameNode);
|
2201
|
+
}
|
2199
2202
|
// Replace the assigned type with the (unnarrowed) declared type.
|
2200
2203
|
destType = declaredType;
|
2201
2204
|
}
|
@@ -2979,8 +2982,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2979
2982
|
}
|
2980
2983
|
}
|
2981
2984
|
}
|
2982
|
-
const codeFlowTypeResult = getFlowTypeOfReference(node,
|
2983
|
-
|
2985
|
+
const codeFlowTypeResult = getFlowTypeOfReference(node, /* startNode */ undefined, {
|
2986
|
+
targetSymbolId: symbol.id,
|
2987
|
+
typeAtStart,
|
2984
2988
|
skipConditionalNarrowing: (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0,
|
2985
2989
|
});
|
2986
2990
|
if (codeFlowTypeResult.type) {
|
@@ -3133,7 +3137,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3133
3137
|
if (symbolWithScope.symbol.isInitiallyUnbound()) {
|
3134
3138
|
typeAtStart = types_1.UnboundType.create();
|
3135
3139
|
}
|
3136
|
-
return getFlowTypeOfReference(node,
|
3140
|
+
return getFlowTypeOfReference(node, innerScopeNode, {
|
3141
|
+
targetSymbolId: symbolWithScope.symbol.id,
|
3142
|
+
typeAtStart,
|
3143
|
+
});
|
3137
3144
|
}
|
3138
3145
|
}
|
3139
3146
|
}
|
@@ -3457,8 +3464,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3457
3464
|
}
|
3458
3465
|
}
|
3459
3466
|
// See if we can refine the type based on code flow analysis.
|
3460
|
-
const codeFlowTypeResult = getFlowTypeOfReference(node,
|
3461
|
-
|
3467
|
+
const codeFlowTypeResult = getFlowTypeOfReference(node, /* startNode */ undefined, {
|
3468
|
+
targetSymbolId: symbol_1.indeterminateSymbolId,
|
3469
|
+
typeAtStart,
|
3462
3470
|
isTypeAtStartIncomplete,
|
3463
3471
|
skipConditionalNarrowing: (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0,
|
3464
3472
|
});
|
@@ -4385,10 +4393,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4385
4393
|
});
|
4386
4394
|
if (baseTypeSupportsIndexNarrowing) {
|
4387
4395
|
// Before performing code flow analysis, update the cache to prevent recursion.
|
4388
|
-
writeTypeCache(node, indexTypeResult, flags);
|
4396
|
+
writeTypeCache(node, { ...indexTypeResult, isIncomplete: true }, flags);
|
4389
4397
|
// See if we can refine the type based on code flow analysis.
|
4390
|
-
const codeFlowTypeResult = getFlowTypeOfReference(node,
|
4391
|
-
|
4398
|
+
const codeFlowTypeResult = getFlowTypeOfReference(node, /* startNode */ undefined, {
|
4399
|
+
targetSymbolId: symbol_1.indeterminateSymbolId,
|
4400
|
+
typeAtStart: indexTypeResult.type,
|
4392
4401
|
isTypeAtStartIncomplete: !!baseTypeResult.isIncomplete || !!indexTypeResult.isIncomplete,
|
4393
4402
|
skipConditionalNarrowing: (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0,
|
4394
4403
|
});
|
@@ -4750,8 +4759,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4750
4759
|
return createLiteralType(concreteSubtype, node, flags);
|
4751
4760
|
}
|
4752
4761
|
if (types_1.ClassType.isBuiltIn(concreteSubtype, 'InitVar')) {
|
4753
|
-
// Special-case InitVar, used in
|
4762
|
+
// Special-case InitVar, used in dataclasses.
|
4754
4763
|
const typeArgs = getTypeArgs(node, flags);
|
4764
|
+
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
4765
|
+
if ((flags & 32768 /* EvaluatorFlags.VariableTypeAnnotation */) === 0) {
|
4766
|
+
addError(localize_1.LocMessage.initVarNotAllowed(), node.baseExpression);
|
4767
|
+
}
|
4768
|
+
}
|
4755
4769
|
if (typeArgs.length === 1) {
|
4756
4770
|
return typeArgs[0].type;
|
4757
4771
|
}
|
@@ -8981,6 +8995,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8981
8995
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeAnyOrUnknown(), (_c = argList[1].node) !== null && _c !== void 0 ? _c : errorNode);
|
8982
8996
|
isBaseClassAny = true;
|
8983
8997
|
}
|
8998
|
+
// Specifically disallow Annotated.
|
8999
|
+
if (baseClass.specialForm &&
|
9000
|
+
(0, types_1.isInstantiableClass)(baseClass.specialForm) &&
|
9001
|
+
types_1.ClassType.isBuiltIn(baseClass.specialForm, 'Annotated')) {
|
9002
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeNotAClass(), argList[1].node || errorNode);
|
9003
|
+
return undefined;
|
9004
|
+
}
|
8984
9005
|
if (!(0, types_1.isInstantiableClass)(baseClass)) {
|
8985
9006
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeNotAClass(), argList[1].node || errorNode);
|
8986
9007
|
return undefined;
|
@@ -13872,7 +13893,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13872
13893
|
// flow analysis starts from the reference node, but startNode can be
|
13873
13894
|
// specified to override this in a few special cases (functions and
|
13874
13895
|
// lambdas) to support analysis of captured variables.
|
13875
|
-
function getFlowTypeOfReference(reference,
|
13896
|
+
function getFlowTypeOfReference(reference, startNode, options) {
|
13876
13897
|
var _a;
|
13877
13898
|
// See if this execution scope requires code flow for this reference expression.
|
13878
13899
|
const referenceKey = (0, codeFlowTypes_1.createKeyForReference)(reference);
|
@@ -13901,7 +13922,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13901
13922
|
if (flowNode === undefined) {
|
13902
13923
|
return { type: undefined, isIncomplete: false };
|
13903
13924
|
}
|
13904
|
-
return analyzer.getTypeFromCodeFlow(flowNode, reference,
|
13925
|
+
return analyzer.getTypeFromCodeFlow(flowNode, reference, options);
|
13905
13926
|
}
|
13906
13927
|
// Specializes the specified (potentially generic) class type using
|
13907
13928
|
// the specified type arguments, reporting errors as appropriate.
|
@@ -14006,10 +14027,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14006
14027
|
return createRequiredOrReadOnlyType(classType, errorNode, typeArgs, flags);
|
14007
14028
|
}
|
14008
14029
|
case 'ReadOnly': {
|
14009
|
-
|
14010
|
-
return createRequiredOrReadOnlyType(classType, errorNode, typeArgs, flags);
|
14011
|
-
}
|
14012
|
-
break;
|
14030
|
+
return createRequiredOrReadOnlyType(classType, errorNode, typeArgs, flags);
|
14013
14031
|
}
|
14014
14032
|
case 'Self': {
|
14015
14033
|
return { type: createSelfType(classType, errorNode, typeArgs, flags) };
|
@@ -15561,7 +15579,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15561
15579
|
// into account argument types to infer the return type.
|
15562
15580
|
function getFunctionEffectiveReturnType(type, args, inferTypeIfNeeded = true) {
|
15563
15581
|
const specializedReturnType = types_1.FunctionType.getSpecializedReturnType(type, /* includeInferred */ false);
|
15564
|
-
if (specializedReturnType) {
|
15582
|
+
if (specializedReturnType && !(0, types_1.isUnknown)(specializedReturnType)) {
|
15565
15583
|
return adjustCallableReturnType(specializedReturnType, /* trackedSignatures */ undefined);
|
15566
15584
|
}
|
15567
15585
|
if (inferTypeIfNeeded) {
|
@@ -15906,22 +15924,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15906
15924
|
}
|
15907
15925
|
}
|
15908
15926
|
}
|
15909
|
-
// See if the dest type is a TypedDict class and the source is a compatible dict.
|
15910
|
-
if (types_1.ClassType.isTypedDictClass(destType) && types_1.ClassType.isBuiltIn(srcType, 'dict')) {
|
15911
|
-
if (srcType.typeArguments &&
|
15912
|
-
srcType.typeArguments.length === 2 &&
|
15913
|
-
(0, types_1.isClassInstance)(srcType.typeArguments[0]) &&
|
15914
|
-
types_1.ClassType.isBuiltIn(srcType.typeArguments[0], 'str')) {
|
15915
|
-
const dictValueType = (0, typedDicts_1.getTypedDictDictEquivalent)(evaluatorInterface, destType, recursionCount);
|
15916
|
-
if (dictValueType &&
|
15917
|
-
assignType(dictValueType, srcType.typeArguments[1],
|
15918
|
-
/* diag */ undefined,
|
15919
|
-
/* destTypeVarContext */ undefined,
|
15920
|
-
/* srcTypeVarContext */ undefined, 1 /* AssignTypeFlags.EnforceInvariance */, recursionCount + 1)) {
|
15921
|
-
return true;
|
15922
|
-
}
|
15923
|
-
}
|
15924
|
-
}
|
15925
15927
|
// Handle special-case type promotions.
|
15926
15928
|
if (destType.includePromotions) {
|
15927
15929
|
const promotionList = typePromotions.get(destType.details.fullName);
|
@@ -16168,15 +16170,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16168
16170
|
if ((0, types_1.isVariadicTypeVar)(destTypeArgs[destUnboundedOrVariadicIndex].type)) {
|
16169
16171
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
16170
16172
|
const removedArgs = srcTypeArgs.splice(destUnboundedOrVariadicIndex, srcArgsToCapture);
|
16171
|
-
|
16172
|
-
|
16173
|
-
|
16174
|
-
|
16175
|
-
|
16176
|
-
|
16177
|
-
|
16178
|
-
|
16179
|
-
|
16173
|
+
let variadicTuple;
|
16174
|
+
// If we're left with a single unpacked variadic type var, there's no
|
16175
|
+
// need to wrap it in a nested tuple.
|
16176
|
+
if (removedArgs.length === 1 && (0, types_1.isUnpackedVariadicTypeVar)(removedArgs[0].type)) {
|
16177
|
+
variadicTuple = removedArgs[0].type;
|
16178
|
+
}
|
16179
|
+
else {
|
16180
|
+
// Package up the remaining type arguments into a tuple object.
|
16181
|
+
variadicTuple = makeTupleObject(removedArgs.map((typeArg) => {
|
16182
|
+
return {
|
16183
|
+
type: typeArg.type,
|
16184
|
+
isUnbounded: typeArg.isUnbounded,
|
16185
|
+
isOptional: typeArg.isOptional,
|
16186
|
+
};
|
16187
|
+
}),
|
16188
|
+
/* isUnpackedTuple */ true);
|
16189
|
+
}
|
16180
16190
|
srcTypeArgs.splice(destUnboundedOrVariadicIndex, 0, {
|
16181
16191
|
type: variadicTuple,
|
16182
16192
|
isUnbounded: false,
|
@@ -17396,6 +17406,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17396
17406
|
if ((0, types_1.isTypeSame)(destType, srcSubtype, { ignorePseudoGeneric: true }, recursionCount)) {
|
17397
17407
|
return false;
|
17398
17408
|
}
|
17409
|
+
if ((0, typeUtils_1.isIncompleteUnknown)(srcSubtype)) {
|
17410
|
+
return false;
|
17411
|
+
}
|
17399
17412
|
const destTypeVarName = types_1.TypeVarType.getNameWithScope(destType);
|
17400
17413
|
// Determine which conditions on this type apply to this type variable.
|
17401
17414
|
// There might be more than one of them.
|
@@ -18373,9 +18386,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18373
18386
|
!(0, symbolNameUtils_1.isPrivateOrProtectedName)(baseParam.name || '') &&
|
18374
18387
|
baseParamDetails.params[i].source !== parameterUtils_1.ParameterSource.PositionOnly &&
|
18375
18388
|
baseParam.category === 0 /* ParameterCategory.Simple */ &&
|
18389
|
+
enforceParamNames &&
|
18376
18390
|
baseParam.name !== overrideParam.name) {
|
18377
18391
|
if (overrideParam.category === 0 /* ParameterCategory.Simple */) {
|
18378
|
-
if (
|
18392
|
+
if (!baseParam.isNameSynthesized) {
|
18379
18393
|
if (overrideParamDetails.params[i].source === parameterUtils_1.ParameterSource.PositionOnly) {
|
18380
18394
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
|
18381
18395
|
index: i + 1,
|