@zzzen/pyright-internal 1.2.0-dev.20240922 → 1.2.0-dev.20241006
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.d.ts +1 -0
- package/dist/analyzer/binder.js +19 -0
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +0 -1
- package/dist/analyzer/checker.js +75 -89
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +1 -1
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/commentUtils.js +2 -2
- package/dist/analyzer/commentUtils.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +6 -15
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constraintTracker.d.ts +0 -1
- package/dist/analyzer/constraintTracker.js +0 -6
- package/dist/analyzer/constraintTracker.js.map +1 -1
- package/dist/analyzer/constructors.js +14 -6
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +3 -3
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/importResolver.js +1 -1
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/operations.js +42 -28
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +4 -4
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/patternMatching.js +19 -5
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/protocols.js +9 -20
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.js +24 -10
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +5 -3
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/symbol.d.ts +3 -0
- package/dist/analyzer/symbol.js +6 -0
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +5 -5
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/tuples.d.ts +8 -3
- package/dist/analyzer/tuples.js +155 -0
- package/dist/analyzer/tuples.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +351 -403
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +9 -14
- package/dist/analyzer/typeEvaluatorTypes.js +7 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +7 -1
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +2 -1
- package/dist/analyzer/typePrinter.js +28 -22
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +1 -1
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +11 -3
- package/dist/analyzer/typeUtils.js +20 -16
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +8 -4
- package/dist/analyzer/types.js +20 -14
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/collectionUtils.d.ts +2 -0
- package/dist/common/collectionUtils.js +15 -0
- package/dist/common/collectionUtils.js.map +1 -1
- package/dist/common/configOptions.d.ts +3 -1
- package/dist/common/configOptions.js +17 -4
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/fileSystem.d.ts +8 -1
- package/dist/common/fileSystem.js +10 -1
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/memUtils.js +3 -0
- package/dist/common/memUtils.js.map +1 -1
- package/dist/common/pathUtils.d.ts +3 -3
- package/dist/common/realFileSystem.js +2 -0
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +9 -7
- package/dist/languageService/autoImporter.js +32 -34
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/completionProvider.js +1 -1
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.js +1 -1
- package/dist/languageService/completionProviderUtils.js.map +1 -1
- package/dist/languageService/hoverProvider.js +3 -2
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.d.ts +8 -1
- package/dist/languageService/symbolIndexer.js +17 -2
- package/dist/languageService/symbolIndexer.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.cs.json +2 -2
- package/dist/localization/package.nls.de.json +2 -2
- package/dist/localization/package.nls.en-us.json +4 -0
- package/dist/localization/package.nls.es.json +2 -2
- package/dist/localization/package.nls.fr.json +2 -2
- package/dist/localization/package.nls.it.json +2 -2
- package/dist/localization/package.nls.ja.json +2 -2
- package/dist/localization/package.nls.ko.json +2 -2
- package/dist/localization/package.nls.pl.json +2 -2
- package/dist/localization/package.nls.pt-br.json +2 -2
- package/dist/localization/package.nls.ru.json +2 -2
- package/dist/localization/package.nls.tr.json +2 -2
- package/dist/localization/package.nls.zh-cn.json +7 -7
- package/dist/localization/package.nls.zh-tw.json +7 -7
- package/dist/readonlyAugmentedFileSystem.js +2 -1
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +0 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +0 -3
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +1 -2
- package/dist/tests/harness/fourslash/testState.js +0 -7
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.js +8 -3
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +2 -2
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +7 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +5 -1
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +3 -3
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +12 -2
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +0 -6
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +7 -1
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/package.json +8 -8
@@ -152,15 +152,6 @@ const maxOverloadUnionExpansionCount = 64;
|
|
152
152
|
// Maximum number of recursive function return type inference attempts
|
153
153
|
// that can be concurrently pending before we give up.
|
154
154
|
const maxInferFunctionReturnRecursionCount = 12;
|
155
|
-
// In certain loops, it's possible to construct arbitrarily-deep containers
|
156
|
-
// (tuples, lists, sets, or dicts) which can lead to infinite type analysis.
|
157
|
-
// This limits the depth.
|
158
|
-
const maxInferredContainerDepth = 8;
|
159
|
-
// If a tuple expression with no declared type contains a large number
|
160
|
-
// of elements, it can cause performance issues. This value limits the
|
161
|
-
// number of elements that will be included in the tuple type before
|
162
|
-
// we default to tuple[Unknown, ...].
|
163
|
-
const maxInferredTupleEntryCount = 256;
|
164
155
|
// Maximum recursion amount when comparing two recursive type aliases.
|
165
156
|
// Increasing this can greatly increase the time required to evaluate
|
166
157
|
// two recursive type aliases that have the same definition. Decreasing
|
@@ -391,7 +382,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
391
382
|
// context, logging any errors in the process. This may require the
|
392
383
|
// type of surrounding statements to be evaluated.
|
393
384
|
function getType(node) {
|
394
|
-
var _a, _b;
|
385
|
+
var _a, _b, _c, _d;
|
395
386
|
initializePrefetchedTypes(node);
|
396
387
|
let type = (_a = evaluateTypeForSubnode(node, () => {
|
397
388
|
evaluateTypesForExpressionInContext(node);
|
@@ -406,8 +397,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
406
397
|
if (classTypeResult) {
|
407
398
|
inferVarianceForClass(classTypeResult.classType);
|
408
399
|
const typeParam = classTypeResult.classType.shared.typeParams.find((param) => (0, types_1.isTypeSame)(param, typeVarType, { ignoreTypeFlags: true }));
|
409
|
-
if (typeParam) {
|
410
|
-
type = types_1.
|
400
|
+
if ((typeParam === null || typeParam === void 0 ? void 0 : typeParam.priv.computedVariance) !== undefined) {
|
401
|
+
type = types_1.TypeVarType.cloneWithComputedVariance(type, typeParam.priv.computedVariance);
|
402
|
+
}
|
403
|
+
}
|
404
|
+
}
|
405
|
+
else if (((_c = typeParamListNode === null || typeParamListNode === void 0 ? void 0 : typeParamListNode.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 77 /* ParseNodeType.TypeAlias */) {
|
406
|
+
const typeAliasType = getTypeOfTypeAlias(typeParamListNode.parent);
|
407
|
+
const typeParamIndex = typeParamListNode.d.params.findIndex((param) => param.d.name === node);
|
408
|
+
if (typeParamIndex >= 0) {
|
409
|
+
inferVarianceForTypeAlias(typeAliasType);
|
410
|
+
const typeAliasInfo = (_d = typeAliasType.props) === null || _d === void 0 ? void 0 : _d.typeAliasInfo;
|
411
|
+
if (typeAliasInfo === null || typeAliasInfo === void 0 ? void 0 : typeAliasInfo.shared.computedVariance) {
|
412
|
+
const computedVariance = typeAliasInfo.shared.computedVariance[typeParamIndex];
|
413
|
+
type = types_1.TypeVarType.cloneWithComputedVariance(type, computedVariance);
|
411
414
|
}
|
412
415
|
}
|
413
416
|
}
|
@@ -627,7 +630,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
627
630
|
break;
|
628
631
|
}
|
629
632
|
case 52 /* ParseNodeType.Tuple */: {
|
630
|
-
typeResult = getTypeOfTuple(node, flags, inferenceContext);
|
633
|
+
typeResult = (0, tuples_1.getTypeOfTuple)(evaluatorInterface, node, flags, inferenceContext);
|
631
634
|
break;
|
632
635
|
}
|
633
636
|
case 14 /* ParseNodeType.Constant */: {
|
@@ -851,8 +854,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
851
854
|
typeResult = { type: types_1.AnyType.create(/* isEllipsis */ true) };
|
852
855
|
}
|
853
856
|
else {
|
854
|
-
|
855
|
-
|
857
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0 && (flags & 65536 /* EvalFlags.AllowEllipsis */) === 0) {
|
858
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.ellipsisContext(), node);
|
859
|
+
typeResult = { type: types_1.UnknownType.create() };
|
860
|
+
}
|
861
|
+
else {
|
862
|
+
const ellipsisType = (_b = (_a = getBuiltInObject(node, 'EllipsisType')) !== null && _a !== void 0 ? _a : getBuiltInObject(node, 'ellipsis')) !== null && _b !== void 0 ? _b : types_1.AnyType.create();
|
863
|
+
typeResult = { type: ellipsisType };
|
864
|
+
}
|
856
865
|
}
|
857
866
|
return typeResult;
|
858
867
|
}
|
@@ -994,7 +1003,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
994
1003
|
updatedFlags |= 524288 /* EvalFlags.NotParsed */;
|
995
1004
|
}
|
996
1005
|
updatedFlags &= ~1073741824 /* EvalFlags.TypeFormArg */;
|
997
|
-
if (node.d.annotation) {
|
1006
|
+
if (node.d.annotation && (flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
998
1007
|
return getTypeOfExpression(node.d.annotation, updatedFlags);
|
999
1008
|
}
|
1000
1009
|
if (node.d.strings.length === 1) {
|
@@ -2633,7 +2642,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2633
2642
|
var _a;
|
2634
2643
|
if ((0, types_1.isParamSpec)(subtype)) {
|
2635
2644
|
if (subtype.priv.paramSpecAccess === 'args') {
|
2636
|
-
return makeTupleObject([{ type: getObjectType(), isUnbounded: true }]);
|
2645
|
+
return (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type: getObjectType(), isUnbounded: true }]);
|
2637
2646
|
}
|
2638
2647
|
else if (subtype.priv.paramSpecAccess === 'kwargs') {
|
2639
2648
|
if (dictClass && (0, types_1.isInstantiableClass)(dictClass) && strClass && (0, types_1.isInstantiableClass)(strClass)) {
|
@@ -2664,7 +2673,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2664
2673
|
return types_1.AnyType.create();
|
2665
2674
|
}
|
2666
2675
|
// Fall back to "*tuple[object, ...]".
|
2667
|
-
return makeTupleObject([{ type: getObjectType(), isUnbounded: true }],
|
2676
|
+
return (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type: getObjectType(), isUnbounded: true }],
|
2677
|
+
/* isUnpacked */ true);
|
2668
2678
|
}
|
2669
2679
|
if ((0, types_1.isTypeVar)(subtype)) {
|
2670
2680
|
// If this is a recursive type alias placeholder
|
@@ -3259,7 +3269,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3259
3269
|
// Isinstance treats traditional (non-PEP 695) type aliases that are unions
|
3260
3270
|
// as tuples of classes rather than unions.
|
3261
3271
|
if ((flags & 536870912 /* EvalFlags.IsinstanceArg */) !== 0) {
|
3262
|
-
if ((0, types_1.isUnion)(type) && ((_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) && !type.props.typeAliasInfo.isPep695Syntax) {
|
3272
|
+
if ((0, types_1.isUnion)(type) && ((_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) && !type.props.typeAliasInfo.shared.isPep695Syntax) {
|
3263
3273
|
return type;
|
3264
3274
|
}
|
3265
3275
|
}
|
@@ -3607,7 +3617,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3607
3617
|
}
|
3608
3618
|
}
|
3609
3619
|
return {
|
3610
|
-
type: types_1.TypeVarType.cloneForScopeId(type, leftType.shared.recursiveAlias.
|
3620
|
+
type: types_1.TypeVarType.cloneForScopeId(type, leftType.shared.recursiveAlias.typeVarScopeId, leftType.shared.recursiveAlias.name, 2 /* TypeVarScopeType.TypeAlias */),
|
3611
3621
|
scopeNode,
|
3612
3622
|
foundInterveningClass: false,
|
3613
3623
|
};
|
@@ -4781,7 +4791,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4781
4791
|
}
|
4782
4792
|
});
|
4783
4793
|
}
|
4784
|
-
const tupleObject = makeTupleObject(variadicTypes, /* isUnpacked */ true);
|
4794
|
+
const tupleObject = (0, tuples_1.makeTupleObject)(evaluatorInterface, variadicTypes, /* isUnpacked */ true);
|
4785
4795
|
typeArgs = [
|
4786
4796
|
...typeArgs.slice(0, variadicIndex),
|
4787
4797
|
{ node: typeArgs[variadicIndex].node, type: tupleObject },
|
@@ -4793,7 +4803,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4793
4803
|
// Add an empty tuple that maps to the TypeVarTuple type parameter.
|
4794
4804
|
typeArgs.push({
|
4795
4805
|
node: errorNode,
|
4796
|
-
type: makeTupleObject([], /* isUnpacked */ true),
|
4806
|
+
type: (0, tuples_1.makeTupleObject)(evaluatorInterface, [], /* isUnpacked */ true),
|
4797
4807
|
});
|
4798
4808
|
}
|
4799
4809
|
}
|
@@ -4821,13 +4831,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4821
4831
|
return type;
|
4822
4832
|
}
|
4823
4833
|
// Is this a generic type alias that needs specializing?
|
4824
|
-
if (!aliasInfo.typeParams || aliasInfo.typeParams.length === 0 || aliasInfo.typeArgs) {
|
4834
|
+
if (!aliasInfo.shared.typeParams || aliasInfo.shared.typeParams.length === 0 || aliasInfo.typeArgs) {
|
4825
4835
|
return type;
|
4826
4836
|
}
|
4827
4837
|
let reportDiag = false;
|
4828
4838
|
const defaultTypeArgs = [];
|
4829
4839
|
const constraints = new constraintTracker_1.ConstraintTracker();
|
4830
|
-
aliasInfo.typeParams.forEach((param) => {
|
4840
|
+
aliasInfo.shared.typeParams.forEach((param) => {
|
4831
4841
|
if (!param.shared.isDefaultExplicit) {
|
4832
4842
|
reportDiag = true;
|
4833
4843
|
}
|
@@ -4835,13 +4845,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4835
4845
|
if (param.shared.isDefaultExplicit || (0, types_1.isParamSpec)(param)) {
|
4836
4846
|
defaultType = solveAndApplyConstraints(param, constraints, {
|
4837
4847
|
replaceUnsolved: {
|
4838
|
-
scopeIds: [aliasInfo.typeVarScopeId],
|
4848
|
+
scopeIds: [aliasInfo.shared.typeVarScopeId],
|
4839
4849
|
tupleClassType: getTupleClassType(),
|
4840
4850
|
},
|
4841
4851
|
});
|
4842
4852
|
}
|
4843
4853
|
else if ((0, types_1.isTypeVarTuple)(param) && tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
|
4844
|
-
defaultType = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }],
|
4854
|
+
defaultType = (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type: types_1.UnknownType.create(), isUnbounded: true }],
|
4845
4855
|
/* isUnpacked */ true);
|
4846
4856
|
}
|
4847
4857
|
else {
|
@@ -4852,12 +4862,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4852
4862
|
});
|
4853
4863
|
if (reportDiag && errorNode) {
|
4854
4864
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportMissingTypeArgument, localize_1.LocMessage.typeArgsMissingForAlias().format({
|
4855
|
-
name: aliasInfo.name,
|
4865
|
+
name: aliasInfo.shared.name,
|
4856
4866
|
}), errorNode);
|
4857
4867
|
}
|
4858
4868
|
type = types_1.TypeBase.cloneForTypeAlias(solveAndApplyConstraints(type, constraints, {
|
4859
4869
|
replaceUnsolved: {
|
4860
|
-
scopeIds: [aliasInfo.typeVarScopeId],
|
4870
|
+
scopeIds: [aliasInfo.shared.typeVarScopeId],
|
4861
4871
|
tupleClassType: getTupleClassType(),
|
4862
4872
|
},
|
4863
4873
|
}), { ...aliasInfo, typeArgs: defaultTypeArgs });
|
@@ -4873,7 +4883,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4873
4883
|
aliasInfo = (_d = (_c = baseType.props.typeForm) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.typeAliasInfo;
|
4874
4884
|
aliasBaseType = (0, typeUtils_1.convertToInstantiable)(baseType.props.typeForm);
|
4875
4885
|
}
|
4876
|
-
if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeParams) || (aliasInfo.typeParams.length === 0 && aliasInfo.typeArgs)) {
|
4886
|
+
if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.shared.typeParams) || (aliasInfo.shared.typeParams.length === 0 && aliasInfo.typeArgs)) {
|
4877
4887
|
return undefined;
|
4878
4888
|
}
|
4879
4889
|
// If this is not instantiable, then the index expression isn't a specialization.
|
@@ -4884,23 +4894,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4884
4894
|
if (aliasInfo.typeArgs) {
|
4885
4895
|
return undefined;
|
4886
4896
|
}
|
4887
|
-
|
4888
|
-
|
4897
|
+
inferVarianceForTypeAlias(baseType);
|
4898
|
+
const typeParams = aliasInfo.shared.typeParams;
|
4899
|
+
let typeArgs;
|
4900
|
+
typeArgs = adjustTypeArgsForTypeVarTuple(getTypeArgs(node, flags), typeParams, node);
|
4889
4901
|
let reportedError = false;
|
4890
|
-
|
4891
|
-
|
4892
|
-
|
4893
|
-
|
4894
|
-
if (typeParams.length === 1 && (0, types_1.isParamSpec)(typeParams[0]) && typeArgs) {
|
4895
|
-
if (typeArgs.every((typeArg) => !(0, typeUtils_1.isEllipsisType)(typeArg.type) && !typeArg.typeList && !(0, types_1.isParamSpec)(typeArg.type))) {
|
4896
|
-
typeArgs = [
|
4897
|
-
{
|
4898
|
-
type: types_1.UnknownType.create(),
|
4899
|
-
node: typeArgs.length > 0 ? typeArgs[0].node : node,
|
4900
|
-
typeList: typeArgs,
|
4901
|
-
},
|
4902
|
-
];
|
4903
|
-
}
|
4902
|
+
typeArgs = transformTypeArgsForParamSpec(typeParams, typeArgs, node);
|
4903
|
+
if (!typeArgs) {
|
4904
|
+
typeArgs = [];
|
4905
|
+
reportedError = true;
|
4904
4906
|
}
|
4905
4907
|
let minTypeArgCount = typeParams.length;
|
4906
4908
|
const firstDefaultParamIndex = typeParams.findIndex((param) => !!param.shared.isDefaultExplicit);
|
@@ -4937,8 +4939,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4937
4939
|
const typeList = typeArgs[index].typeList;
|
4938
4940
|
if (typeList) {
|
4939
4941
|
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
4940
|
-
typeList.forEach((
|
4941
|
-
|
4942
|
+
typeList.forEach((paramTypeResult, paramIndex) => {
|
4943
|
+
let paramType = paramTypeResult.type;
|
4944
|
+
if (!validateTypeArg(paramTypeResult)) {
|
4945
|
+
paramType = types_1.UnknownType.create();
|
4946
|
+
}
|
4947
|
+
types_1.FunctionType.addParam(functionType, types_1.FunctionParam.create(0 /* ParamCategory.Simple */, (0, typeUtils_1.convertToInstance)(paramType), types_1.FunctionParamFlags.NameSynthesized | types_1.FunctionParamFlags.TypeDeclared, `__p${paramIndex}`));
|
4942
4948
|
});
|
4943
4949
|
if (typeList.length > 0) {
|
4944
4950
|
types_1.FunctionType.addPositionOnlyParamSeparator(functionType);
|
@@ -4992,7 +4998,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4992
4998
|
else if (param.shared.isDefaultExplicit) {
|
4993
4999
|
typeArgType = solveAndApplyConstraints(param, constraints, {
|
4994
5000
|
replaceUnsolved: {
|
4995
|
-
scopeIds: [aliasInfo.typeVarScopeId],
|
5001
|
+
scopeIds: [aliasInfo.shared.typeVarScopeId],
|
4996
5002
|
tupleClassType: getTupleClassType(),
|
4997
5003
|
},
|
4998
5004
|
});
|
@@ -5029,7 +5035,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5029
5035
|
}
|
5030
5036
|
const solutionSet = (0, constraintSolver_1.solveConstraints)(evaluatorInterface, constraints).getMainSolutionSet();
|
5031
5037
|
const aliasTypeArgs = [];
|
5032
|
-
(_f = aliasInfo.typeParams) === null || _f === void 0 ? void 0 : _f.forEach((typeParam) => {
|
5038
|
+
(_f = aliasInfo.shared.typeParams) === null || _f === void 0 ? void 0 : _f.forEach((typeParam) => {
|
5033
5039
|
let typeVarType = solutionSet.getType(typeParam);
|
5034
5040
|
// Fill in any unsolved type arguments with unknown.
|
5035
5041
|
if (!typeVarType) {
|
@@ -5068,7 +5074,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5068
5074
|
types_1.ClassType.isBuiltIn(baseTypeResult.type, 'TypeAliasType') &&
|
5069
5075
|
((_b = baseTypeResult.type.props) === null || _b === void 0 ? void 0 : _b.typeForm)) {
|
5070
5076
|
const typeAliasInfo = (_c = baseTypeResult.type.props.typeForm.props) === null || _c === void 0 ? void 0 : _c.typeAliasInfo;
|
5071
|
-
if (typeAliasInfo && typeAliasInfo.typeParams) {
|
5077
|
+
if (typeAliasInfo && typeAliasInfo.shared.typeParams) {
|
5072
5078
|
const origTypeAlias = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.convertToInstantiable)(baseTypeResult.type.props.typeForm), { ...typeAliasInfo, typeArgs: undefined });
|
5073
5079
|
const typeFormType = createSpecializedTypeAlias(node, origTypeAlias, flags);
|
5074
5080
|
if (typeFormType) {
|
@@ -5081,14 +5087,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5081
5087
|
if ((0, types_1.isTypeVar)(baseTypeResult.type) && (0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
|
5082
5088
|
const typeArgTypes = getTypeArgs(node, flags).map((t) => (0, typeUtils_1.convertToInstance)(t.type));
|
5083
5089
|
const type = types_1.TypeBase.cloneForTypeAlias(baseTypeResult.type, {
|
5084
|
-
|
5085
|
-
fullName: '',
|
5086
|
-
moduleName: '',
|
5087
|
-
fileUri: uri_1.Uri.empty(),
|
5088
|
-
typeVarScopeId: baseTypeResult.type.shared.recursiveAlias.scopeId,
|
5089
|
-
isPep695Syntax: !!baseTypeResult.type.shared.recursiveAlias.isPep695Syntax,
|
5090
|
-
typeParams: baseTypeResult.type.shared.recursiveAlias.typeParams,
|
5091
|
-
usageVariance: undefined,
|
5090
|
+
shared: baseTypeResult.type.shared.recursiveAlias,
|
5092
5091
|
typeArgs: typeArgTypes,
|
5093
5092
|
});
|
5094
5093
|
return { type };
|
@@ -5256,31 +5255,41 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5256
5255
|
var _a;
|
5257
5256
|
const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
5258
5257
|
// If this isn't a generic type alias, there's nothing to do.
|
5259
|
-
if (!aliasInfo || !aliasInfo.typeParams) {
|
5258
|
+
if (!aliasInfo || !aliasInfo.shared.typeParams) {
|
5260
5259
|
return undefined;
|
5261
5260
|
}
|
5262
|
-
// Is the
|
5263
|
-
if (aliasInfo.
|
5264
|
-
return aliasInfo.
|
5261
|
+
// Is the computed variance info already cached?
|
5262
|
+
if (aliasInfo.shared.computedVariance) {
|
5263
|
+
return aliasInfo.shared.computedVariance;
|
5265
5264
|
}
|
5266
|
-
const typeParams = aliasInfo.typeParams;
|
5265
|
+
const typeParams = aliasInfo.shared.typeParams;
|
5267
5266
|
// Start with all of the usage variances unknown.
|
5268
5267
|
const usageVariances = typeParams.map(() => 1 /* Variance.Unknown */);
|
5269
5268
|
// Prepopulate the cached value for the type alias to handle
|
5270
5269
|
// recursive type aliases.
|
5271
|
-
aliasInfo.
|
5270
|
+
aliasInfo.shared.computedVariance = usageVariances;
|
5272
5271
|
// Traverse the type alias type definition and adjust the usage
|
5273
5272
|
// variances accordingly.
|
5274
|
-
updateUsageVariancesRecursive(type, typeParams, usageVariances);
|
5273
|
+
updateUsageVariancesRecursive(type, typeParams, usageVariances, 3 /* Variance.Covariant */);
|
5275
5274
|
return usageVariances;
|
5276
5275
|
}
|
5277
5276
|
// Looks at uses of the type parameters within the type and adjusts the
|
5278
5277
|
// variances accordingly. For example, if the type is `Mapping[T1, T2]`,
|
5279
5278
|
// then T1 will be set to invariant and T2 will be set to covariant.
|
5280
|
-
function updateUsageVariancesRecursive(type, typeAliasTypeParams, usageVariances, recursionCount = 0) {
|
5279
|
+
function updateUsageVariancesRecursive(type, typeAliasTypeParams, usageVariances, varianceContext, pendingTypes = [], recursionCount = 0) {
|
5281
5280
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
5282
5281
|
return;
|
5283
5282
|
}
|
5283
|
+
const transformedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(type);
|
5284
|
+
// If this is a recursive type alias, see if we've already recursed
|
5285
|
+
// seen it once before in the recursion stack. If so, don't recurse
|
5286
|
+
// further.
|
5287
|
+
if (transformedType !== type) {
|
5288
|
+
const pendingOverlaps = pendingTypes.filter((pendingType) => (0, types_1.isTypeSame)(pendingType, type));
|
5289
|
+
if (pendingOverlaps.length > 1) {
|
5290
|
+
return;
|
5291
|
+
}
|
5292
|
+
}
|
5284
5293
|
recursionCount++;
|
5285
5294
|
// Define a helper function that performs the actual usage variant update.
|
5286
5295
|
function updateUsageVarianceForType(type, variance) {
|
@@ -5290,20 +5299,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5290
5299
|
usageVariances[typeParamIndex] = (0, typeUtils_1.combineVariances)(usageVariances[typeParamIndex], variance);
|
5291
5300
|
}
|
5292
5301
|
else {
|
5293
|
-
|
5302
|
+
pendingTypes.push(type);
|
5303
|
+
updateUsageVariancesRecursive(subtype, typeAliasTypeParams, usageVariances, variance, pendingTypes, recursionCount);
|
5304
|
+
pendingTypes.pop();
|
5294
5305
|
}
|
5295
5306
|
});
|
5296
5307
|
}
|
5297
|
-
(0, typeUtils_1.doForEachSubtype)(
|
5308
|
+
(0, typeUtils_1.doForEachSubtype)(transformedType, (subtype) => {
|
5298
5309
|
if (subtype.category === 4 /* TypeCategory.Function */) {
|
5299
|
-
|
5300
|
-
|
5301
|
-
|
5302
|
-
|
5303
|
-
|
5304
|
-
|
5305
|
-
|
5306
|
-
}
|
5310
|
+
subtype.shared.parameters.forEach((param, index) => {
|
5311
|
+
const paramType = types_1.FunctionType.getParamType(subtype, index);
|
5312
|
+
updateUsageVarianceForType(paramType, (0, typeUtils_1.invertVariance)(varianceContext));
|
5313
|
+
});
|
5314
|
+
const returnType = types_1.FunctionType.getEffectiveReturnType(subtype);
|
5315
|
+
if (returnType) {
|
5316
|
+
updateUsageVarianceForType(returnType, varianceContext);
|
5307
5317
|
}
|
5308
5318
|
}
|
5309
5319
|
else if (subtype.category === 6 /* TypeCategory.Class */) {
|
@@ -5316,7 +5326,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5316
5326
|
subtype.priv.typeArgs.forEach((typeArg, classParamIndex) => {
|
5317
5327
|
var _a;
|
5318
5328
|
if ((0, typeUtils_1.isTupleClass)(subtype)) {
|
5319
|
-
updateUsageVarianceForType(typeArg,
|
5329
|
+
updateUsageVarianceForType(typeArg, varianceContext);
|
5320
5330
|
}
|
5321
5331
|
else if (classParamIndex < subtype.shared.typeParams.length) {
|
5322
5332
|
const classTypeParam = subtype.shared.typeParams[classParamIndex];
|
@@ -5326,7 +5336,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5326
5336
|
});
|
5327
5337
|
}
|
5328
5338
|
else {
|
5329
|
-
|
5339
|
+
const effectiveVariance = (_a = classTypeParam.priv.computedVariance) !== null && _a !== void 0 ? _a : classTypeParam.shared.declaredVariance;
|
5340
|
+
updateUsageVarianceForType(typeArg, varianceContext === 4 /* Variance.Contravariant */
|
5341
|
+
? (0, typeUtils_1.invertVariance)(effectiveVariance)
|
5342
|
+
: effectiveVariance);
|
5330
5343
|
}
|
5331
5344
|
}
|
5332
5345
|
});
|
@@ -5334,12 +5347,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5334
5347
|
}
|
5335
5348
|
});
|
5336
5349
|
}
|
5337
|
-
function makeTupleObject(typeArgs, isUnpacked = false) {
|
5338
|
-
if (tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
|
5339
|
-
return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClass, typeArgs, /* isTypeArgExplicit */ true, isUnpacked));
|
5340
|
-
}
|
5341
|
-
return types_1.UnknownType.create();
|
5342
|
-
}
|
5343
5350
|
function getIndexAccessMagicMethodName(usage) {
|
5344
5351
|
if (usage.method === 'get') {
|
5345
5352
|
return '__getitem__';
|
@@ -5428,7 +5435,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5428
5435
|
}
|
5429
5436
|
else if (positionalArgs.length === 0 && unpackedListArgs.length === 0) {
|
5430
5437
|
// Handle the case where there are no positionals provided but there are keywords.
|
5431
|
-
positionalIndexType = makeTupleObject([]);
|
5438
|
+
positionalIndexType = (0, tuples_1.makeTupleObject)(evaluatorInterface, []);
|
5432
5439
|
}
|
5433
5440
|
else {
|
5434
5441
|
// Package up all of the positionals into a tuple.
|
@@ -5449,7 +5456,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5449
5456
|
const iterableType = (_b = (_a = getTypeOfIterator(typeResult, /* isAsync */ false, arg.d.valueExpr)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
5450
5457
|
tupleTypeArgs.push({ type: iterableType, isUnbounded: true });
|
5451
5458
|
});
|
5452
|
-
positionalIndexType = makeTupleObject(tupleTypeArgs);
|
5459
|
+
positionalIndexType = (0, tuples_1.makeTupleObject)(evaluatorInterface, tupleTypeArgs);
|
5453
5460
|
}
|
5454
5461
|
const argList = [
|
5455
5462
|
{
|
@@ -5578,38 +5585,73 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5578
5585
|
});
|
5579
5586
|
// Set the node's type so it isn't reevaluated later.
|
5580
5587
|
setTypeResultForNode(node.d.items[0].d.valueExpr, { type: types_1.UnknownType.create() });
|
5581
|
-
|
5582
|
-
|
5583
|
-
|
5584
|
-
|
5585
|
-
|
5586
|
-
|
5587
|
-
|
5588
|
-
|
5589
|
-
|
5590
|
-
|
5591
|
-
|
5592
|
-
|
5593
|
-
|
5594
|
-
|
5588
|
+
return typeArgs;
|
5589
|
+
}
|
5590
|
+
node.d.items.forEach((arg, index) => {
|
5591
|
+
const typeResult = getTypeArgTypeResult(arg.d.valueExpr, index);
|
5592
|
+
if (arg.d.argCategory !== 0 /* ArgCategory.Simple */) {
|
5593
|
+
if (arg.d.argCategory === 1 /* ArgCategory.UnpackedList */) {
|
5594
|
+
if (!(options === null || options === void 0 ? void 0 : options.isAnnotatedClass) || index === 0) {
|
5595
|
+
const unpackedType = applyUnpackToTupleLike(typeResult.type);
|
5596
|
+
if (unpackedType) {
|
5597
|
+
typeResult.type = unpackedType;
|
5598
|
+
}
|
5599
|
+
else {
|
5600
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
5601
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.unpackNotAllowed(), arg.d.valueExpr);
|
5602
|
+
typeResult.typeErrors = true;
|
5595
5603
|
}
|
5596
5604
|
else {
|
5597
|
-
|
5605
|
+
typeResult.type = types_1.UnknownType.create();
|
5598
5606
|
}
|
5599
5607
|
}
|
5600
5608
|
}
|
5601
5609
|
}
|
5602
|
-
|
5610
|
+
}
|
5611
|
+
if (arg.d.name) {
|
5612
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
5603
5613
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.keywordArgInTypeArgument(), arg.d.valueExpr);
|
5614
|
+
typeResult.typeErrors = true;
|
5604
5615
|
}
|
5605
|
-
|
5606
|
-
|
5607
|
-
typeArgs.push(typeResult);
|
5616
|
+
else {
|
5617
|
+
typeResult.type = types_1.UnknownType.create();
|
5608
5618
|
}
|
5609
|
-
}
|
5610
|
-
|
5619
|
+
}
|
5620
|
+
if (arg.d.valueExpr.nodeType !== 0 /* ParseNodeType.Error */ ||
|
5621
|
+
arg.d.valueExpr.d.category !== 3 /* ErrorExpressionCategory.MissingIndexOrSlice */) {
|
5622
|
+
typeArgs.push(typeResult);
|
5623
|
+
}
|
5624
|
+
});
|
5611
5625
|
return typeArgs;
|
5612
5626
|
}
|
5627
|
+
function applyUnpackToTupleLike(type) {
|
5628
|
+
if ((0, types_1.isTypeVarTuple)(type)) {
|
5629
|
+
if (!type.priv.isUnpacked) {
|
5630
|
+
return types_1.TypeVarType.cloneForUnpacked(type);
|
5631
|
+
}
|
5632
|
+
return undefined;
|
5633
|
+
}
|
5634
|
+
if ((0, types_1.isParamSpec)(type)) {
|
5635
|
+
return undefined;
|
5636
|
+
}
|
5637
|
+
// Is this a TypeVar that has a tuple upper bound?
|
5638
|
+
if ((0, types_1.isTypeVar)(type)) {
|
5639
|
+
const upperBound = type.shared.boundType;
|
5640
|
+
if (upperBound && (0, types_1.isClassInstance)(upperBound) && (0, typeUtils_1.isTupleClass)(upperBound)) {
|
5641
|
+
const concrete = makeTopLevelTypeVarsConcrete(type);
|
5642
|
+
if ((0, types_1.isInstantiableClass)(concrete)) {
|
5643
|
+
return types_1.ClassType.cloneForUnpacked(concrete);
|
5644
|
+
}
|
5645
|
+
}
|
5646
|
+
return undefined;
|
5647
|
+
}
|
5648
|
+
if ((0, types_1.isInstantiableClass)(type) && !type.priv.includeSubclasses) {
|
5649
|
+
if ((0, typeUtils_1.isTupleClass)(type)) {
|
5650
|
+
return types_1.ClassType.cloneForUnpacked(type);
|
5651
|
+
}
|
5652
|
+
}
|
5653
|
+
return undefined;
|
5654
|
+
}
|
5613
5655
|
function getTypeArg(node, flags) {
|
5614
5656
|
let typeResult;
|
5615
5657
|
let adjustedFlags = flags | 128 /* EvalFlags.InstantiableType */ | 1 /* EvalFlags.ConvertEllipsisToAny */ | 8 /* EvalFlags.StrLiteralAsType */;
|
@@ -5642,138 +5684,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5642
5684
|
}
|
5643
5685
|
return typeResult;
|
5644
5686
|
}
|
5645
|
-
function getTypeOfTuple(node, flags, inferenceContext) {
|
5646
|
-
var _a;
|
5647
|
-
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0 && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
|
5648
|
-
// This is allowed inside of an index trailer, specifically
|
5649
|
-
// to support Tuple[()], which is the documented way to annotate
|
5650
|
-
// a zero-length tuple.
|
5651
|
-
const diag = new diagnostic_1.DiagnosticAddendum();
|
5652
|
-
diag.addMessage(localize_1.LocAddendum.useTupleInstead());
|
5653
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.tupleInAnnotation() + diag.getString(), node);
|
5654
|
-
return { type: types_1.UnknownType.create() };
|
5655
|
-
}
|
5656
|
-
if ((flags & 128 /* EvalFlags.InstantiableType */) !== 0 && node.d.items.length === 0 && !inferenceContext) {
|
5657
|
-
return { type: makeTupleObject([]), isEmptyTupleShorthand: true };
|
5658
|
-
}
|
5659
|
-
flags &= ~(256 /* EvalFlags.TypeExpression */ | 8 /* EvalFlags.StrLiteralAsType */ | 128 /* EvalFlags.InstantiableType */);
|
5660
|
-
// If the expected type is a union, recursively call for each of the subtypes
|
5661
|
-
// to find one that matches.
|
5662
|
-
let expectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
|
5663
|
-
let expectedTypeContainsAny = inferenceContext && (0, types_1.isAny)(inferenceContext.expectedType);
|
5664
|
-
if (inferenceContext && (0, types_1.isUnion)(inferenceContext.expectedType)) {
|
5665
|
-
let matchingSubtype;
|
5666
|
-
(0, typeUtils_1.doForEachSubtype)(inferenceContext.expectedType, (subtype) => {
|
5667
|
-
if ((0, types_1.isAny)(subtype)) {
|
5668
|
-
expectedTypeContainsAny = true;
|
5669
|
-
}
|
5670
|
-
if (!matchingSubtype) {
|
5671
|
-
const subtypeResult = useSpeculativeMode(node, () => {
|
5672
|
-
return getTypeOfTupleWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(subtype));
|
5673
|
-
});
|
5674
|
-
if (subtypeResult && assignType(subtype, subtypeResult.type)) {
|
5675
|
-
matchingSubtype = subtype;
|
5676
|
-
}
|
5677
|
-
}
|
5678
|
-
},
|
5679
|
-
/* sortSubtypes */ true);
|
5680
|
-
expectedType = matchingSubtype;
|
5681
|
-
}
|
5682
|
-
let expectedTypeDiagAddendum;
|
5683
|
-
if (expectedType) {
|
5684
|
-
const result = getTypeOfTupleWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(expectedType));
|
5685
|
-
if (result && !result.typeErrors) {
|
5686
|
-
return result;
|
5687
|
-
}
|
5688
|
-
expectedTypeDiagAddendum = result === null || result === void 0 ? void 0 : result.expectedTypeDiagAddendum;
|
5689
|
-
}
|
5690
|
-
const typeResult = getTypeOfTupleInferred(node, flags);
|
5691
|
-
// If there was an expected type of Any, replace the resulting type
|
5692
|
-
// with Any rather than return a type with unknowns.
|
5693
|
-
if (expectedTypeContainsAny) {
|
5694
|
-
typeResult.type = types_1.AnyType.create();
|
5695
|
-
}
|
5696
|
-
return { ...typeResult, expectedTypeDiagAddendum };
|
5697
|
-
}
|
5698
|
-
function getTypeOfTupleWithContext(node, flags, inferenceContext) {
|
5699
|
-
inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
|
5700
|
-
if (!(0, types_1.isClassInstance)(inferenceContext.expectedType)) {
|
5701
|
-
return undefined;
|
5702
|
-
}
|
5703
|
-
if (!tupleClass || !(0, types_1.isInstantiableClass)(tupleClass)) {
|
5704
|
-
return undefined;
|
5705
|
-
}
|
5706
|
-
// Build an array of expected types.
|
5707
|
-
let expectedTypes = [];
|
5708
|
-
if ((0, typeUtils_1.isTupleClass)(inferenceContext.expectedType) && inferenceContext.expectedType.priv.tupleTypeArgs) {
|
5709
|
-
expectedTypes = inferenceContext.expectedType.priv.tupleTypeArgs.map((t) => (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(t.type));
|
5710
|
-
const unboundedIndex = inferenceContext.expectedType.priv.tupleTypeArgs.findIndex((t) => t.isUnbounded);
|
5711
|
-
if (unboundedIndex >= 0) {
|
5712
|
-
if (expectedTypes.length > node.d.items.length) {
|
5713
|
-
expectedTypes.splice(unboundedIndex, 1);
|
5714
|
-
}
|
5715
|
-
else {
|
5716
|
-
while (expectedTypes.length < node.d.items.length) {
|
5717
|
-
expectedTypes.splice(unboundedIndex, 0, expectedTypes[unboundedIndex]);
|
5718
|
-
}
|
5719
|
-
}
|
5720
|
-
}
|
5721
|
-
}
|
5722
|
-
else {
|
5723
|
-
const tupleConstraints = new constraintTracker_1.ConstraintTracker();
|
5724
|
-
if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(tupleClass), inferenceContext.expectedType, tupleConstraints, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
|
5725
|
-
return undefined;
|
5726
|
-
}
|
5727
|
-
const specializedTuple = solveAndApplyConstraints(tupleClass, tupleConstraints);
|
5728
|
-
if (!specializedTuple.priv.typeArgs || specializedTuple.priv.typeArgs.length !== 1) {
|
5729
|
-
return undefined;
|
5730
|
-
}
|
5731
|
-
const homogenousType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(specializedTuple.priv.typeArgs[0]);
|
5732
|
-
for (let i = 0; i < node.d.items.length; i++) {
|
5733
|
-
expectedTypes.push(homogenousType);
|
5734
|
-
}
|
5735
|
-
}
|
5736
|
-
const entryTypeResults = node.d.items.map((expr, index) => getTypeOfExpression(expr, flags | 268435456 /* EvalFlags.StripTupleLiterals */, (0, typeUtils_1.makeInferenceContext)(index < expectedTypes.length ? expectedTypes[index] : undefined, inferenceContext.isTypeIncomplete)));
|
5737
|
-
const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
|
5738
|
-
// Copy any expected type diag addenda for precision error reporting.
|
5739
|
-
let expectedTypeDiagAddendum;
|
5740
|
-
if (entryTypeResults.some((result) => result.expectedTypeDiagAddendum)) {
|
5741
|
-
expectedTypeDiagAddendum = new diagnostic_1.DiagnosticAddendum();
|
5742
|
-
entryTypeResults.forEach((result) => {
|
5743
|
-
if (result.expectedTypeDiagAddendum) {
|
5744
|
-
expectedTypeDiagAddendum.addAddendum(result.expectedTypeDiagAddendum);
|
5745
|
-
}
|
5746
|
-
});
|
5747
|
-
}
|
5748
|
-
// If the tuple contains a very large number of entries, it's probably
|
5749
|
-
// generated code. If we encounter type errors, don't bother building
|
5750
|
-
// the full tuple type.
|
5751
|
-
let type;
|
5752
|
-
if (node.d.items.length > maxInferredTupleEntryCount && entryTypeResults.some((result) => result.typeErrors)) {
|
5753
|
-
type = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }]);
|
5754
|
-
}
|
5755
|
-
else {
|
5756
|
-
type = makeTupleObject(buildTupleTypesList(entryTypeResults, /* stripLiterals */ false));
|
5757
|
-
}
|
5758
|
-
return { type, expectedTypeDiagAddendum, isIncomplete };
|
5759
|
-
}
|
5760
|
-
function getTypeOfTupleInferred(node, flags) {
|
5761
|
-
const entryTypeResults = node.d.items.map((expr) => getTypeOfExpression(expr, flags | 268435456 /* EvalFlags.StripTupleLiterals */));
|
5762
|
-
const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
|
5763
|
-
// If the tuple contains a very large number of entries, it's probably
|
5764
|
-
// generated code. Rather than taking the time to evaluate every entry,
|
5765
|
-
// simply return an unknown type in this case.
|
5766
|
-
if (node.d.items.length > maxInferredTupleEntryCount) {
|
5767
|
-
return { type: makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }]) };
|
5768
|
-
}
|
5769
|
-
const type = makeTupleObject(buildTupleTypesList(entryTypeResults, (flags & 268435456 /* EvalFlags.StripTupleLiterals */) !== 0));
|
5770
|
-
if (isIncomplete) {
|
5771
|
-
if ((0, typeUtils_1.getContainerDepth)(type) > maxInferredContainerDepth) {
|
5772
|
-
return { type: types_1.UnknownType.create() };
|
5773
|
-
}
|
5774
|
-
}
|
5775
|
-
return { type, isIncomplete };
|
5776
|
-
}
|
5777
5687
|
function buildTupleTypesList(entryTypeResults, stripLiterals) {
|
5778
5688
|
const entryTypes = [];
|
5779
5689
|
for (const typeResult of entryTypeResults) {
|
@@ -5984,7 +5894,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5984
5894
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.typeFormArgs(), node);
|
5985
5895
|
return { type: types_1.UnknownType.create() };
|
5986
5896
|
}
|
5987
|
-
const typeFormResult = getTypeOfArgExpectingType(
|
5897
|
+
const typeFormResult = getTypeOfArgExpectingType(convertNodeToArg(node.d.args[0]), {
|
5988
5898
|
typeFormArg: isTypeFormSupported(node),
|
5989
5899
|
noNonTypeSpecialForms: true,
|
5990
5900
|
typeExpression: true,
|
@@ -6007,7 +5917,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6007
5917
|
if (arg0TypeResult.isIncomplete) {
|
6008
5918
|
return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
|
6009
5919
|
}
|
6010
|
-
const assertedType = (0, typeUtils_1.convertToInstance)(getTypeOfArgExpectingType(
|
5920
|
+
const assertedType = (0, typeUtils_1.convertToInstance)(getTypeOfArgExpectingType(convertNodeToArg(node.d.args[1]), {
|
6011
5921
|
typeExpression: true,
|
6012
5922
|
}).type);
|
6013
5923
|
// We'll replace TypeGuard and TypeIs with bool for purposes of assert_type testing.
|
@@ -6026,6 +5936,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6026
5936
|
}
|
6027
5937
|
return { type: arg0TypeResult.type };
|
6028
5938
|
}
|
5939
|
+
function convertNodeToArg(node) {
|
5940
|
+
return {
|
5941
|
+
argCategory: node.d.argCategory,
|
5942
|
+
name: node.d.name,
|
5943
|
+
valueExpression: node.d.valueExpr,
|
5944
|
+
};
|
5945
|
+
}
|
6029
5946
|
function getTypeOfRevealType(node, inferenceContext) {
|
6030
5947
|
let arg0Value;
|
6031
5948
|
let expectedRevealTypeNode;
|
@@ -6056,7 +5973,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6056
5973
|
}
|
6057
5974
|
else if (arg.d.name.d.value === 'expected_type') {
|
6058
5975
|
expectedRevealTypeNode = arg.d.valueExpr;
|
6059
|
-
expectedRevealType = (0, typeUtils_1.convertToInstance)(getTypeOfArgExpectingType(
|
5976
|
+
expectedRevealType = (0, typeUtils_1.convertToInstance)(getTypeOfArgExpectingType(convertNodeToArg(arg), {
|
6060
5977
|
typeExpression: true,
|
6061
5978
|
}).type);
|
6062
5979
|
}
|
@@ -7336,7 +7253,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7336
7253
|
argCategory: 1 /* ArgCategory.UnpackedList */,
|
7337
7254
|
valueExpression: undefined,
|
7338
7255
|
typeResult: {
|
7339
|
-
type: makeTupleObject([tupleTypeArg]),
|
7256
|
+
type: (0, tuples_1.makeTupleObject)(evaluatorInterface, [tupleTypeArg]),
|
7340
7257
|
},
|
7341
7258
|
});
|
7342
7259
|
}
|
@@ -7380,11 +7297,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7380
7297
|
paramDetails.params.forEach((paramInfo) => {
|
7381
7298
|
(0, debug_1.assert)(paramInfo !== undefined, 'paramInfo is undefined for param name map');
|
7382
7299
|
const param = paramInfo.param;
|
7383
|
-
if (param.name && param.category === 0 /* ParamCategory.Simple */) {
|
7300
|
+
if (param.name && param.category === 0 /* ParamCategory.Simple */ && paramInfo.kind !== parameterUtils_1.ParamKind.Positional) {
|
7384
7301
|
paramMap.set(param.name, {
|
7385
7302
|
argsNeeded: param.category === 0 /* ParamCategory.Simple */ && !paramInfo.defaultType ? 1 : 0,
|
7386
7303
|
argsReceived: 0,
|
7387
|
-
isPositionalOnly: paramInfo.kind === parameterUtils_1.ParamKind.Positional,
|
7388
7304
|
});
|
7389
7305
|
}
|
7390
7306
|
});
|
@@ -7696,19 +7612,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7696
7612
|
}
|
7697
7613
|
}
|
7698
7614
|
else {
|
7699
|
-
const
|
7615
|
+
const paramInfo = paramDetails.params[paramIndex];
|
7616
|
+
const paramName = paramInfo.param.name;
|
7700
7617
|
validateArgTypeParams.push({
|
7701
|
-
paramCategory:
|
7618
|
+
paramCategory: paramInfo.param.category,
|
7702
7619
|
paramType,
|
7703
7620
|
requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
|
7704
7621
|
argument: argList[argIndex],
|
7705
7622
|
errorNode: argList[argIndex].valueExpression || errorNode,
|
7706
7623
|
paramName,
|
7707
|
-
isParamNameSynthesized: types_1.FunctionParam.isNameSynthesized(
|
7624
|
+
isParamNameSynthesized: types_1.FunctionParam.isNameSynthesized(paramInfo.param),
|
7708
7625
|
});
|
7709
|
-
trySetActive(argList[argIndex],
|
7626
|
+
trySetActive(argList[argIndex], paramInfo.param);
|
7710
7627
|
// Note that the parameter has received an argument.
|
7711
|
-
if (paramName && paramMap.has(paramName)) {
|
7628
|
+
if (paramName && paramMap.has(paramName) && paramInfo.kind !== parameterUtils_1.ParamKind.Positional) {
|
7712
7629
|
paramMap.get(paramName).argsReceived++;
|
7713
7630
|
}
|
7714
7631
|
argIndex++;
|
@@ -7786,7 +7703,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7786
7703
|
tdEntries.knownItems.forEach((entry, name) => {
|
7787
7704
|
var _a, _b;
|
7788
7705
|
const paramEntry = paramMap.get(name);
|
7789
|
-
if (paramEntry
|
7706
|
+
if (paramEntry) {
|
7790
7707
|
if (paramEntry.argsReceived > 0) {
|
7791
7708
|
diag.addMessage(localize_1.LocMessage.paramAlreadyAssigned().format({ name }));
|
7792
7709
|
}
|
@@ -7825,7 +7742,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7825
7742
|
paramMap.set(name, {
|
7826
7743
|
argsNeeded: 1,
|
7827
7744
|
argsReceived: 1,
|
7828
|
-
isPositionalOnly: false,
|
7829
7745
|
});
|
7830
7746
|
}
|
7831
7747
|
else {
|
@@ -7944,7 +7860,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7944
7860
|
if (paramName) {
|
7945
7861
|
const paramNameValue = paramName.d.value;
|
7946
7862
|
const paramEntry = paramMap.get(paramNameValue);
|
7947
|
-
if (paramEntry
|
7863
|
+
if (paramEntry) {
|
7948
7864
|
if (paramEntry.argsReceived > 0) {
|
7949
7865
|
if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
|
7950
7866
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramAlreadyAssigned().format({ name: paramNameValue }), paramName);
|
@@ -7953,7 +7869,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7953
7869
|
}
|
7954
7870
|
else {
|
7955
7871
|
paramEntry.argsReceived++;
|
7956
|
-
const paramInfoIndex = paramDetails.params.findIndex((paramInfo) => paramInfo.param.name === paramNameValue
|
7872
|
+
const paramInfoIndex = paramDetails.params.findIndex((paramInfo) => paramInfo.param.name === paramNameValue &&
|
7873
|
+
paramInfo.kind !== parameterUtils_1.ParamKind.Positional);
|
7957
7874
|
(0, debug_1.assert)(paramInfoIndex >= 0);
|
7958
7875
|
const paramType = paramDetails.params[paramInfoIndex].type;
|
7959
7876
|
validateArgTypeParams.push({
|
@@ -7991,7 +7908,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7991
7908
|
paramMap.set(paramNameValue, {
|
7992
7909
|
argsNeeded: 1,
|
7993
7910
|
argsReceived: 1,
|
7994
|
-
isPositionalOnly: false,
|
7995
7911
|
});
|
7996
7912
|
(0, debug_1.assert)(paramDetails.params[paramDetails.kwargsIndex], 'paramDetails.kwargsIndex params entry is undefined');
|
7997
7913
|
}
|
@@ -8105,7 +8021,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8105
8021
|
const param = paramInfo.param;
|
8106
8022
|
if (param.category === 0 /* ParamCategory.Simple */ && param.name) {
|
8107
8023
|
const entry = paramMap.get(param.name);
|
8108
|
-
if (entry.argsNeeded === 0 && entry.argsReceived === 0) {
|
8024
|
+
if (entry && entry.argsNeeded === 0 && entry.argsReceived === 0) {
|
8109
8025
|
const defaultArgType = paramInfo.defaultType;
|
8110
8026
|
if (defaultArgType &&
|
8111
8027
|
!(0, typeUtils_1.isEllipsisType)(defaultArgType) &&
|
@@ -8177,7 +8093,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8177
8093
|
specializedTuple = tupleTypeArgs[0].type;
|
8178
8094
|
}
|
8179
8095
|
else {
|
8180
|
-
specializedTuple = makeTupleObject(tupleTypeArgs, /* isUnpacked */ true);
|
8096
|
+
specializedTuple = (0, tuples_1.makeTupleObject)(evaluatorInterface, tupleTypeArgs, /* isUnpacked */ true);
|
8181
8097
|
}
|
8182
8098
|
const combinedArg = {
|
8183
8099
|
paramCategory: 1 /* ParamCategory.ArgsList */,
|
@@ -9086,7 +9002,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9086
9002
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarFirstArg(), firstArg.valueExpression || errorNode);
|
9087
9003
|
}
|
9088
9004
|
const typeVar = types_1.TypeBase.cloneAsSpecialForm(types_1.TypeVarType.createInstantiable(typeVarName, types_1.TypeVarKind.TypeVarTuple), types_1.ClassType.cloneAsInstance(classType));
|
9089
|
-
typeVar.shared.defaultType =
|
9005
|
+
typeVar.shared.defaultType = (0, tuples_1.makeTupleObject)(evaluatorInterface, [
|
9006
|
+
{ type: types_1.UnknownType.create(), isUnbounded: true },
|
9007
|
+
]);
|
9090
9008
|
// Parse the remaining parameters.
|
9091
9009
|
for (let i = 1; i < argList.length; i++) {
|
9092
9010
|
const paramNameNode = argList[i].name;
|
@@ -9208,6 +9126,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9208
9126
|
const typeResult = getTypeOfExpressionExpectingType(node, {
|
9209
9127
|
allowParamSpec: true,
|
9210
9128
|
allowTypeVarsWithoutScopeId: true,
|
9129
|
+
allowEllipsis: true,
|
9211
9130
|
typeExpression: true,
|
9212
9131
|
});
|
9213
9132
|
if (typeResult.typeErrors) {
|
@@ -9738,7 +9657,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9738
9657
|
/* tupleTypeArgs */ undefined, isEmptyContainer))
|
9739
9658
|
: types_1.UnknownType.create();
|
9740
9659
|
if (isIncomplete) {
|
9741
|
-
if ((0, typeUtils_1.getContainerDepth)(type) > maxInferredContainerDepth) {
|
9660
|
+
if ((0, typeUtils_1.getContainerDepth)(type) > typeEvaluatorTypes_1.maxInferredContainerDepth) {
|
9742
9661
|
return { type: types_1.UnknownType.create() };
|
9743
9662
|
}
|
9744
9663
|
}
|
@@ -10105,7 +10024,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10105
10024
|
/* tupleTypeArgs */ undefined, isEmptyContainer))
|
10106
10025
|
: types_1.UnknownType.create();
|
10107
10026
|
if (isIncomplete) {
|
10108
|
-
if ((0, typeUtils_1.getContainerDepth)(type) > maxInferredContainerDepth) {
|
10027
|
+
if ((0, typeUtils_1.getContainerDepth)(type) > typeEvaluatorTypes_1.maxInferredContainerDepth) {
|
10109
10028
|
return { type: types_1.UnknownType.create() };
|
10110
10029
|
}
|
10111
10030
|
}
|
@@ -10505,7 +10424,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10505
10424
|
if (!expectedValueOrElementType || !(0, typeUtils_1.containsLiteralType)(expectedValueOrElementType)) {
|
10506
10425
|
valueType = stripLiteralValue(valueType);
|
10507
10426
|
}
|
10508
|
-
type = makeTupleObject([
|
10427
|
+
type = (0, tuples_1.makeTupleObject)(evaluatorInterface, [
|
10509
10428
|
{ type: keyType, isUnbounded: false },
|
10510
10429
|
{ type: valueType, isUnbounded: false },
|
10511
10430
|
]);
|
@@ -11073,16 +10992,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11073
10992
|
}
|
11074
10993
|
return classType;
|
11075
10994
|
}
|
11076
|
-
|
11077
|
-
if ((0, types_1.isUnion)(typeArgType) && typeArgType.priv.subtypes.length === 1) {
|
11078
|
-
typeArgType = typeArgType.priv.subtypes[0];
|
11079
|
-
}
|
10995
|
+
const typeArgType = typeArgs[0].type;
|
11080
10996
|
if ((flags & 2097152 /* EvalFlags.AllowUnpackedTuple */) !== 0) {
|
11081
|
-
|
11082
|
-
|
11083
|
-
|
11084
|
-
if ((0, types_1.isTypeVarTuple)(typeArgType) && !typeArgType.priv.isUnpacked) {
|
11085
|
-
return types_1.TypeVarType.cloneForUnpacked(typeArgType);
|
10997
|
+
const unpackedType = applyUnpackToTupleLike(typeArgType);
|
10998
|
+
if (unpackedType) {
|
10999
|
+
return unpackedType;
|
11086
11000
|
}
|
11087
11001
|
if ((flags & 256 /* EvalFlags.TypeExpression */) === 0) {
|
11088
11002
|
return classType;
|
@@ -11196,44 +11110,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11196
11110
|
}
|
11197
11111
|
// Determines whether the metadata object is compatible with the base type.
|
11198
11112
|
function validateTypeMetadata(errorNode, baseType, metaArg) {
|
11199
|
-
|
11200
|
-
//
|
11201
|
-
|
11202
|
-
return true;
|
11203
|
-
}
|
11204
|
-
if (!(0, types_1.isClass)(metaArg.type)) {
|
11205
|
-
return true;
|
11206
|
-
}
|
11207
|
-
const supportsTypeMethod = (_a = getTypeOfBoundMember(
|
11208
|
-
/* errorNode */ undefined, metaArg.type, '__supports_type__')) === null || _a === void 0 ? void 0 : _a.type;
|
11209
|
-
if (!supportsTypeMethod) {
|
11210
|
-
return true;
|
11211
|
-
}
|
11212
|
-
// "Call" the __supports_type__ method to determine if the type is supported.
|
11213
|
-
const callResult = useSpeculativeMode(errorNode, () => validateCallArgs(errorNode, [
|
11214
|
-
{
|
11215
|
-
argCategory: 0 /* ArgCategory.Simple */,
|
11216
|
-
typeResult: { type: (0, typeUtils_1.convertToInstance)(baseType) },
|
11217
|
-
},
|
11218
|
-
], { type: supportsTypeMethod },
|
11219
|
-
/* constraints */ undefined,
|
11220
|
-
/* skipUnknownArgCheck */ true,
|
11221
|
-
/* inferenceContext */ undefined));
|
11222
|
-
if (!callResult.returnType) {
|
11223
|
-
return true;
|
11224
|
-
}
|
11225
|
-
// If there are no errors and the return type is potentially truthy,
|
11226
|
-
// we know that the type is supported by this metadata object.
|
11227
|
-
if (!callResult.argumentErrors && canBeTruthy(callResult.returnType)) {
|
11228
|
-
return true;
|
11229
|
-
}
|
11230
|
-
if (!callResult.isTypeIncomplete) {
|
11231
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.annotatedMetadataInconsistent().format({
|
11232
|
-
metadataType: printType(metaArg.type),
|
11233
|
-
type: printType((0, typeUtils_1.convertToInstance)(baseType)),
|
11234
|
-
}), metaArg.node);
|
11235
|
-
}
|
11236
|
-
return false;
|
11113
|
+
// This function was added for draft PEP 746, but the functionality
|
11114
|
+
// has been removed for now while the PEP is being revised.
|
11115
|
+
return true;
|
11237
11116
|
}
|
11238
11117
|
// Creates one of several "special" types that are defined in typing.pyi
|
11239
11118
|
// but not declared in their entirety. This includes the likes of "Tuple",
|
@@ -11395,7 +11274,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11395
11274
|
// is allowed if it's an unpacked TypeVarTuple or tuple. None is also allowed
|
11396
11275
|
// since it is used to define NoReturn in typeshed stubs).
|
11397
11276
|
if (types.length === 1 && !allowSingleTypeArg && !(0, typeUtils_1.isNoneInstance)(types[0])) {
|
11398
|
-
|
11277
|
+
if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
|
11278
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.unionTypeArgCount(), errorNode);
|
11279
|
+
}
|
11399
11280
|
isValidTypeForm = false;
|
11400
11281
|
}
|
11401
11282
|
let unionType = (0, types_1.combineTypes)(types, { skipElideRedundantLiterals: true });
|
@@ -11446,16 +11327,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11446
11327
|
}
|
11447
11328
|
return createSpecialType(classType, typeArgs, /* paramLimit */ undefined, /* allowParamSpec */ true);
|
11448
11329
|
}
|
11449
|
-
function transformTypeForTypeAlias(type,
|
11330
|
+
function transformTypeForTypeAlias(type, errorNode, typeAliasPlaceholder, isPep695TypeVarType, typeParamNodes) {
|
11450
11331
|
var _a;
|
11451
|
-
if (!types_1.TypeBase.isInstantiable(type)) {
|
11452
|
-
return type;
|
11453
|
-
}
|
11454
11332
|
// If this is a recursive type alias that hasn't yet been fully resolved
|
11455
11333
|
// (i.e. there is no boundType associated with it), don't apply the transform.
|
11456
11334
|
if ((0, typeUtils_1.isTypeAliasPlaceholder)(type)) {
|
11457
11335
|
return type;
|
11458
11336
|
}
|
11337
|
+
const sharedInfo = typeAliasPlaceholder.shared.recursiveAlias;
|
11338
|
+
(0, debug_1.assert)(sharedInfo !== undefined);
|
11339
|
+
let typeParams = sharedInfo.typeParams;
|
11459
11340
|
if (!typeParams) {
|
11460
11341
|
// Determine if there are any generic type parameters associated
|
11461
11342
|
// with this type alias.
|
@@ -11480,10 +11361,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11480
11361
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarWithDefaultFollowsVariadic().format({
|
11481
11362
|
typeVarName: typeParams[typeVarWithDefaultIndex].shared.name,
|
11482
11363
|
variadicName: typeParams[firstTypeVarTupleIndex].shared.name,
|
11483
|
-
}), typeParamNodes ? typeParamNodes[typeVarWithDefaultIndex].d.name :
|
11364
|
+
}), typeParamNodes ? typeParamNodes[typeVarWithDefaultIndex].d.name : errorNode);
|
11484
11365
|
}
|
11485
11366
|
}
|
11486
|
-
const typeAliasScopeId = ParseTreeUtils.getScopeIdForNode(name);
|
11487
11367
|
// Validate the default types for all type parameters.
|
11488
11368
|
typeParams.forEach((typeParam, index) => {
|
11489
11369
|
var _a;
|
@@ -11492,7 +11372,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11492
11372
|
if (typeParamNodes && index < typeParamNodes.length) {
|
11493
11373
|
bestErrorNode = (_a = typeParamNodes[index].d.defaultExpr) !== null && _a !== void 0 ? _a : typeParamNodes[index].d.name;
|
11494
11374
|
}
|
11495
|
-
validateTypeParamDefault(bestErrorNode, typeParam, typeParams.slice(0, index),
|
11375
|
+
validateTypeParamDefault(bestErrorNode, typeParam, typeParams.slice(0, index), sharedInfo.typeVarScopeId);
|
11496
11376
|
});
|
11497
11377
|
// Verify that we have at most one TypeVarTuple.
|
11498
11378
|
const variadics = typeParams.filter((param) => (0, types_1.isTypeVarTuple)(param));
|
@@ -11501,29 +11381,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11501
11381
|
names: variadics.map((v) => `"${v.shared.name}"`).join(', '),
|
11502
11382
|
}), errorNode);
|
11503
11383
|
}
|
11504
|
-
if (!isPep695Syntax && !isPep695TypeVarType) {
|
11505
|
-
const boundTypeVars = typeParams.filter((typeVar) => typeVar.priv.scopeId !==
|
11384
|
+
if (!sharedInfo.isPep695Syntax && !isPep695TypeVarType) {
|
11385
|
+
const boundTypeVars = typeParams.filter((typeVar) => typeVar.priv.scopeId !== sharedInfo.typeVarScopeId &&
|
11386
|
+
typeVar.priv.scopeType === 0 /* TypeVarScopeType.Class */);
|
11506
11387
|
if (boundTypeVars.length > 0) {
|
11507
11388
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.genericTypeAliasBoundTypeVar().format({
|
11508
11389
|
names: boundTypeVars.map((t) => `${t.shared.name}`).join(', '),
|
11509
11390
|
}), errorNode);
|
11510
11391
|
}
|
11511
11392
|
}
|
11512
|
-
|
11393
|
+
if (!types_1.TypeBase.isInstantiable(type)) {
|
11394
|
+
return type;
|
11395
|
+
}
|
11396
|
+
sharedInfo.typeParams = typeParams.length > 0 ? typeParams : undefined;
|
11513
11397
|
let typeAlias = types_1.TypeBase.cloneForTypeAlias(type, {
|
11514
|
-
|
11515
|
-
fullName: ParseTreeUtils.getClassFullName(name, fileInfo.moduleName, name.d.value),
|
11516
|
-
moduleName: fileInfo.moduleName,
|
11517
|
-
fileUri: fileInfo.fileUri,
|
11518
|
-
typeVarScopeId: typeAliasScopeId,
|
11519
|
-
isPep695Syntax,
|
11520
|
-
typeParams: typeParams.length > 0 ? typeParams : undefined,
|
11521
|
-
usageVariance: undefined,
|
11398
|
+
shared: sharedInfo,
|
11522
11399
|
typeArgs: undefined,
|
11523
11400
|
});
|
11524
11401
|
// All PEP 695 type aliases are special forms because they are
|
11525
11402
|
// TypeAliasType objects at runtime.
|
11526
|
-
if (isPep695Syntax || isPep695TypeVarType) {
|
11403
|
+
if (sharedInfo.isPep695Syntax || isPep695TypeVarType) {
|
11527
11404
|
const typeAliasTypeClass = getTypingType(errorNode, 'TypeAliasType');
|
11528
11405
|
if (typeAliasTypeClass && (0, types_1.isInstantiableClass)(typeAliasTypeClass)) {
|
11529
11406
|
typeAlias = types_1.TypeBase.cloneAsSpecialForm(typeAlias, types_1.ClassType.cloneAsInstance(typeAliasTypeClass));
|
@@ -11654,7 +11531,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11654
11531
|
typeParamVariance: 2 /* Variance.Invariant */,
|
11655
11532
|
},
|
11656
11533
|
],
|
11657
|
-
[
|
11534
|
+
[
|
11535
|
+
'TypeForm',
|
11536
|
+
{
|
11537
|
+
alias: '',
|
11538
|
+
module: 'builtins',
|
11539
|
+
isSpecialForm: true,
|
11540
|
+
typeParamVariance: 3 /* Variance.Covariant */,
|
11541
|
+
isIllegalInIsinstance: true,
|
11542
|
+
},
|
11543
|
+
],
|
11658
11544
|
]);
|
11659
11545
|
const aliasMapEntry = specialTypes.get(assignedName);
|
11660
11546
|
if (aliasMapEntry) {
|
@@ -11793,7 +11679,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11793
11679
|
}
|
11794
11680
|
}
|
11795
11681
|
if (typeAliasNameNode) {
|
11796
|
-
typeAliasPlaceholder = synthesizeTypeAliasPlaceholder(typeAliasNameNode);
|
11682
|
+
typeAliasPlaceholder = synthesizeTypeAliasPlaceholder(typeAliasNameNode, /* isPep695Syntax */ false);
|
11797
11683
|
writeTypeCache(node, { type: typeAliasPlaceholder }, /* flags */ undefined);
|
11798
11684
|
writeTypeCache(node.d.leftExpr, { type: typeAliasPlaceholder }, /* flags */ undefined);
|
11799
11685
|
if (node.d.leftExpr.nodeType === 54 /* ParseNodeType.TypeAnnotation */) {
|
@@ -11814,8 +11700,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11814
11700
|
if (typeAliasNameNode) {
|
11815
11701
|
(0, debug_1.assert)(typeAliasPlaceholder !== undefined);
|
11816
11702
|
// If this is a type alias, record its name based on the assignment target.
|
11817
|
-
rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode,
|
11818
|
-
/* isPep695Syntax */ false,
|
11703
|
+
rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode, typeAliasPlaceholder,
|
11819
11704
|
/* isPep695TypeVarType */ false);
|
11820
11705
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasPlaceholder, rightHandType)) {
|
11821
11706
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasIsRecursiveDirect().format({
|
@@ -11828,7 +11713,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11828
11713
|
typeAliasPlaceholder.shared.boundType = rightHandType;
|
11829
11714
|
// Record the type parameters within the recursive type alias so it
|
11830
11715
|
// can be specialized.
|
11831
|
-
typeAliasPlaceholder.shared.recursiveAlias.typeParams =
|
11716
|
+
typeAliasPlaceholder.shared.recursiveAlias.typeParams =
|
11717
|
+
(_b = (_a = rightHandType.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) === null || _b === void 0 ? void 0 : _b.shared.typeParams;
|
11832
11718
|
}
|
11833
11719
|
else {
|
11834
11720
|
// If the RHS is a constant boolean expression, assign it a literal type.
|
@@ -11848,17 +11734,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11848
11734
|
}
|
11849
11735
|
// Synthesize a TypeVar that acts as a placeholder for a type alias. This allows
|
11850
11736
|
// the type alias definition to refer to itself.
|
11851
|
-
function synthesizeTypeAliasPlaceholder(nameNode) {
|
11737
|
+
function synthesizeTypeAliasPlaceholder(nameNode, isPep695Syntax) {
|
11852
11738
|
const placeholder = types_1.TypeVarType.createInstantiable(`__type_alias_${nameNode.d.value}`);
|
11853
11739
|
placeholder.shared.isSynthesized = true;
|
11854
|
-
const
|
11740
|
+
const typeVarScopeId = ParseTreeUtils.getScopeIdForNode(nameNode);
|
11741
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(nameNode);
|
11855
11742
|
placeholder.shared.recursiveAlias = {
|
11856
11743
|
name: nameNode.d.value,
|
11857
|
-
|
11858
|
-
|
11744
|
+
fullName: ParseTreeUtils.getClassFullName(nameNode, fileInfo.moduleName, nameNode.d.value),
|
11745
|
+
moduleName: fileInfo.moduleName,
|
11746
|
+
fileUri: fileInfo.fileUri,
|
11747
|
+
typeVarScopeId,
|
11748
|
+
isPep695Syntax,
|
11859
11749
|
typeParams: undefined,
|
11750
|
+
computedVariance: undefined,
|
11860
11751
|
};
|
11861
|
-
placeholder.priv.scopeId =
|
11752
|
+
placeholder.priv.scopeId = typeVarScopeId;
|
11862
11753
|
return placeholder;
|
11863
11754
|
}
|
11864
11755
|
// Evaluates the type of a type alias (i.e. "type") statement. This code
|
@@ -11883,7 +11774,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11883
11774
|
}
|
11884
11775
|
// Synthesize a type variable that represents the type alias while we're
|
11885
11776
|
// evaluating it. This allows us to handle recursive definitions.
|
11886
|
-
const typeAliasTypeVar = synthesizeTypeAliasPlaceholder(nameNode);
|
11777
|
+
const typeAliasTypeVar = synthesizeTypeAliasPlaceholder(nameNode, isPep695Syntax);
|
11887
11778
|
// Write the type to the type cache to support recursive type alias definitions.
|
11888
11779
|
writeTypeCache(nameNode, { type: typeAliasTypeVar }, /* flags */ undefined);
|
11889
11780
|
// Set a partial type to handle recursive (self-referential) type aliases.
|
@@ -11906,8 +11797,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11906
11797
|
if (aliasTypeResult.isIncomplete) {
|
11907
11798
|
isIncomplete = true;
|
11908
11799
|
}
|
11909
|
-
aliasType = transformTypeForTypeAlias(aliasType, nameNode,
|
11910
|
-
/* isPep695TypeVarType */ true,
|
11800
|
+
aliasType = transformTypeForTypeAlias(aliasType, nameNode, typeAliasTypeVar,
|
11801
|
+
/* isPep695TypeVarType */ true, typeParamNodes);
|
11911
11802
|
// See if the type alias relies on itself in a way that cannot be resolved.
|
11912
11803
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, aliasType)) {
|
11913
11804
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasIsRecursiveDirect().format({
|
@@ -12804,7 +12695,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12804
12695
|
const paramMap = new Map();
|
12805
12696
|
for (let i = paramListDetails.firstKeywordOnlyIndex; i < paramListDetails.params.length; i++) {
|
12806
12697
|
const paramInfo = paramListDetails.params[i];
|
12807
|
-
if (paramInfo.param.category === 0 /* ParamCategory.Simple */ &&
|
12698
|
+
if (paramInfo.param.category === 0 /* ParamCategory.Simple */ &&
|
12699
|
+
paramInfo.param.name &&
|
12700
|
+
paramInfo.kind !== parameterUtils_1.ParamKind.Positional) {
|
12808
12701
|
paramMap.set(paramInfo.param.name, i);
|
12809
12702
|
}
|
12810
12703
|
}
|
@@ -13437,7 +13330,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13437
13330
|
if ((0, types_1.isUnpackedClass)(type)) {
|
13438
13331
|
return types_1.ClassType.cloneForUnpacked(type, /* isUnpacked */ false);
|
13439
13332
|
}
|
13440
|
-
return makeTupleObject([{ type, isUnbounded: !(0, types_1.isTypeVarTuple)(type) }]);
|
13333
|
+
return (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type, isUnbounded: !(0, types_1.isTypeVarTuple)(type) }]);
|
13441
13334
|
}
|
13442
13335
|
case 2 /* ParamCategory.KwargsDict */: {
|
13443
13336
|
// Leave a ParamSpec alone.
|
@@ -13467,7 +13360,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13467
13360
|
awaitableFunctionType.shared.declaredReturnType = createAwaitableReturnType(node, functionType.shared.declaredReturnType, types_1.FunctionType.isGenerator(functionType));
|
13468
13361
|
}
|
13469
13362
|
else {
|
13470
|
-
awaitableFunctionType.priv.inferredReturnType = createAwaitableReturnType(node,
|
13363
|
+
awaitableFunctionType.priv.inferredReturnType = createAwaitableReturnType(node, getInferredReturnType(functionType), types_1.FunctionType.isGenerator(functionType));
|
13471
13364
|
}
|
13472
13365
|
return awaitableFunctionType;
|
13473
13366
|
}
|
@@ -14857,39 +14750,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14857
14750
|
// Handle ParamSpec arguments and fill in any missing type arguments with Unknown.
|
14858
14751
|
let typeArgTypes = [];
|
14859
14752
|
const fullTypeParams = types_1.ClassType.getTypeParams(classType);
|
14860
|
-
|
14861
|
-
|
14862
|
-
|
14863
|
-
if (fullTypeParams.length === 1 && (0, types_1.isParamSpec)(fullTypeParams[0]) && typeArgs) {
|
14864
|
-
if (typeArgs.every((typeArg) => !(0, typeUtils_1.isEllipsisType)(typeArg.type) && !typeArg.typeList && !(0, types_1.isParamSpec)(typeArg.type))) {
|
14865
|
-
if (typeArgs.length !== 1 ||
|
14866
|
-
!(0, types_1.isInstantiableClass)(typeArgs[0].type) ||
|
14867
|
-
!types_1.ClassType.isBuiltIn(typeArgs[0].type, 'Concatenate')) {
|
14868
|
-
// Package up the type arguments into a typeList.
|
14869
|
-
typeArgs =
|
14870
|
-
typeArgs.length > 0
|
14871
|
-
? [
|
14872
|
-
{
|
14873
|
-
type: types_1.UnknownType.create(),
|
14874
|
-
node: typeArgs[0].node,
|
14875
|
-
typeList: typeArgs,
|
14876
|
-
},
|
14877
|
-
]
|
14878
|
-
: [];
|
14879
|
-
}
|
14880
|
-
}
|
14881
|
-
else if (typeArgs.length > 1) {
|
14882
|
-
const paramSpecTypeArg = typeArgs.find((typeArg) => (0, types_1.isParamSpec)(typeArg.type));
|
14883
|
-
if (paramSpecTypeArg) {
|
14884
|
-
isValidTypeForm = false;
|
14885
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.paramSpecContext(), paramSpecTypeArg.node);
|
14886
|
-
}
|
14887
|
-
const listTypeArg = typeArgs.find((typeArg) => !!typeArg.typeList);
|
14888
|
-
if (listTypeArg) {
|
14889
|
-
isValidTypeForm = false;
|
14890
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeArgListNotAllowed(), listTypeArg.node);
|
14891
|
-
}
|
14892
|
-
}
|
14753
|
+
typeArgs = transformTypeArgsForParamSpec(fullTypeParams, typeArgs, errorNode);
|
14754
|
+
if (!typeArgs) {
|
14755
|
+
isValidTypeForm = false;
|
14893
14756
|
}
|
14894
14757
|
const constraints = new constraintTracker_1.ConstraintTracker();
|
14895
14758
|
fullTypeParams.forEach((typeParam, index) => {
|
@@ -14996,6 +14859,57 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14996
14859
|
}
|
14997
14860
|
return { type: specializedClass };
|
14998
14861
|
}
|
14862
|
+
// PEP 612 says that if the class has only one type parameter consisting
|
14863
|
+
// of a ParamSpec, the list of arguments does not need to be enclosed in
|
14864
|
+
// a list. We'll handle that case specially here.
|
14865
|
+
function transformTypeArgsForParamSpec(typeParams, typeArgs, errorNode) {
|
14866
|
+
if (typeParams.length !== 1 || !(0, types_1.isParamSpec)(typeParams[0]) || !typeArgs) {
|
14867
|
+
return typeArgs;
|
14868
|
+
}
|
14869
|
+
if (typeArgs.length > 1) {
|
14870
|
+
for (const typeArg of typeArgs) {
|
14871
|
+
if ((0, types_1.isParamSpec)(typeArg.type)) {
|
14872
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.paramSpecContext(), typeArg.node);
|
14873
|
+
return undefined;
|
14874
|
+
}
|
14875
|
+
if ((0, typeUtils_1.isEllipsisType)(typeArg.type)) {
|
14876
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.ellipsisContext(), typeArg.node);
|
14877
|
+
return undefined;
|
14878
|
+
}
|
14879
|
+
if ((0, types_1.isInstantiableClass)(typeArg.type) && types_1.ClassType.isBuiltIn(typeArg.type, 'Concatenate')) {
|
14880
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.concatenateContext(), typeArg.node);
|
14881
|
+
return undefined;
|
14882
|
+
}
|
14883
|
+
if (typeArg.typeList) {
|
14884
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeArgListNotAllowed(), typeArg.node);
|
14885
|
+
return undefined;
|
14886
|
+
}
|
14887
|
+
}
|
14888
|
+
}
|
14889
|
+
if (typeArgs.length === 1) {
|
14890
|
+
// Don't transform a type list.
|
14891
|
+
if (typeArgs[0].typeList) {
|
14892
|
+
return typeArgs;
|
14893
|
+
}
|
14894
|
+
const typeArgType = typeArgs[0].type;
|
14895
|
+
// Don't transform a single ParamSpec or ellipsis.
|
14896
|
+
if ((0, types_1.isParamSpec)(typeArgType) || (0, typeUtils_1.isEllipsisType)(typeArgType)) {
|
14897
|
+
return typeArgs;
|
14898
|
+
}
|
14899
|
+
// Don't transform a Concatenate.
|
14900
|
+
if ((0, types_1.isInstantiableClass)(typeArgType) && types_1.ClassType.isBuiltIn(typeArgType, 'Concatenate')) {
|
14901
|
+
return typeArgs;
|
14902
|
+
}
|
14903
|
+
}
|
14904
|
+
// Package up the type arguments into a type list.
|
14905
|
+
return [
|
14906
|
+
{
|
14907
|
+
type: types_1.UnknownType.create(),
|
14908
|
+
node: typeArgs.length > 0 ? typeArgs[0].node : errorNode,
|
14909
|
+
typeList: typeArgs,
|
14910
|
+
},
|
14911
|
+
];
|
14912
|
+
}
|
14999
14913
|
function getTypeOfArg(arg, inferenceContext) {
|
15000
14914
|
var _a, _b;
|
15001
14915
|
if (arg.typeResult) {
|
@@ -15065,6 +14979,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15065
14979
|
if (options === null || options === void 0 ? void 0 : options.convertEllipsisToAny) {
|
15066
14980
|
flags |= 1 /* EvalFlags.ConvertEllipsisToAny */;
|
15067
14981
|
}
|
14982
|
+
if (options === null || options === void 0 ? void 0 : options.allowEllipsis) {
|
14983
|
+
flags |= 65536 /* EvalFlags.AllowEllipsis */;
|
14984
|
+
}
|
15068
14985
|
if (options === null || options === void 0 ? void 0 : options.noNonTypeSpecialForms) {
|
15069
14986
|
flags |= 67108864 /* EvalFlags.NoNonTypeSpecialForms */;
|
15070
14987
|
}
|
@@ -15757,7 +15674,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15757
15674
|
typeVar.shared.isDefaultExplicit = true;
|
15758
15675
|
}
|
15759
15676
|
else {
|
15760
|
-
typeVar.shared.defaultType =
|
15677
|
+
typeVar.shared.defaultType = (0, tuples_1.makeTupleObject)(evaluatorInterface, [
|
15678
|
+
{ type: types_1.UnknownType.create(), isUnbounded: true },
|
15679
|
+
]);
|
15761
15680
|
}
|
15762
15681
|
}
|
15763
15682
|
else {
|
@@ -15787,7 +15706,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15787
15706
|
if (scopeNode.nodeType === 10 /* ParseNodeType.Class */) {
|
15788
15707
|
scopeType = 0 /* TypeVarScopeType.Class */;
|
15789
15708
|
// Set the variance to "auto" for class-scoped TypeVars.
|
15790
|
-
typeVar.shared.declaredVariance =
|
15709
|
+
typeVar.shared.declaredVariance =
|
15710
|
+
(0, types_1.isParamSpec)(typeVar) || (0, types_1.isTypeVarTuple)(typeVar) ? 2 /* Variance.Invariant */ : 0 /* Variance.Auto */;
|
15791
15711
|
}
|
15792
15712
|
else if (scopeNode.nodeType === 31 /* ParseNodeType.Function */) {
|
15793
15713
|
scopeType = 1 /* TypeVarScopeType.Function */;
|
@@ -15795,6 +15715,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15795
15715
|
else {
|
15796
15716
|
(0, debug_1.assert)(scopeNode.nodeType === 77 /* ParseNodeType.TypeAlias */);
|
15797
15717
|
scopeType = 2 /* TypeVarScopeType.TypeAlias */;
|
15718
|
+
typeVar.shared.declaredVariance =
|
15719
|
+
(0, types_1.isParamSpec)(typeVar) || (0, types_1.isTypeVarTuple)(typeVar) ? 2 /* Variance.Invariant */ : 0 /* Variance.Auto */;
|
15798
15720
|
}
|
15799
15721
|
typeVar = types_1.TypeVarType.cloneForScopeId(typeVar, ParseTreeUtils.getScopeIdForNode(scopeNode.nodeType === 77 /* ParseNodeType.TypeAlias */ ? scopeNode.d.name : scopeNode), scopeNode.d.name.d.value, scopeType);
|
15800
15722
|
}
|
@@ -15931,8 +15853,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15931
15853
|
// in the event that its inferred type is instantiable or explicitly Any
|
15932
15854
|
// (but not an ellipsis).
|
15933
15855
|
if (isLegalImplicitTypeAliasType(inferredType)) {
|
15934
|
-
|
15935
|
-
/* isPep695Syntax */ false
|
15856
|
+
const typeAliasTypeVar = synthesizeTypeAliasPlaceholder(resolvedDecl.typeAliasName,
|
15857
|
+
/* isPep695Syntax */ false);
|
15858
|
+
inferredType = transformTypeForTypeAlias(inferredType, resolvedDecl.node, typeAliasTypeVar,
|
15936
15859
|
/* isPep695TypeVarType */ false);
|
15937
15860
|
isUnambiguousType = true;
|
15938
15861
|
}
|
@@ -16398,7 +16321,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16398
16321
|
return specializedReturnType;
|
16399
16322
|
}
|
16400
16323
|
if (!(options === null || options === void 0 ? void 0 : options.skipInferReturnType)) {
|
16401
|
-
return
|
16324
|
+
return getInferredReturnType(type, options === null || options === void 0 ? void 0 : options.callSiteInfo);
|
16402
16325
|
}
|
16403
16326
|
return types_1.UnknownType.create();
|
16404
16327
|
}
|
@@ -17015,7 +16938,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17015
16938
|
const typeParam = destType.shared.typeParams[i];
|
17016
16939
|
const variance = types_1.TypeVarType.getVariance(typeParam);
|
17017
16940
|
if (curSrcType.priv.tupleTypeArgs) {
|
17018
|
-
typeArgType = (0, typeUtils_1.convertToInstance)(makeTupleObject(curSrcType.priv.tupleTypeArgs, /* isUnpacked */ true));
|
16941
|
+
typeArgType = (0, typeUtils_1.convertToInstance)((0, tuples_1.makeTupleObject)(evaluatorInterface, curSrcType.priv.tupleTypeArgs, /* isUnpacked */ true));
|
17019
16942
|
}
|
17020
16943
|
else {
|
17021
16944
|
typeArgType = i < srcTypeArgs.length ? srcTypeArgs[i] : types_1.UnknownType.create();
|
@@ -17179,16 +17102,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17179
17102
|
// Do the source and dest refer to the same recursive type alias?
|
17180
17103
|
if ((destAliasInfo === null || destAliasInfo === void 0 ? void 0 : destAliasInfo.typeArgs) &&
|
17181
17104
|
(srcAliasInfo === null || srcAliasInfo === void 0 ? void 0 : srcAliasInfo.typeArgs) &&
|
17182
|
-
destType.shared.recursiveAlias.
|
17183
|
-
|
17184
|
-
const srcTypeArgs = srcAliasInfo.typeArgs;
|
17185
|
-
destAliasInfo.typeArgs.forEach((destTypeArg, index) => {
|
17186
|
-
const srcTypeArg = index < srcTypeArgs.length ? srcTypeArgs[index] : types_1.UnknownType.create();
|
17187
|
-
if (!assignType(destTypeArg, srcTypeArg, diag, constraints, flags, recursionCount)) {
|
17188
|
-
isAssignable = false;
|
17189
|
-
}
|
17190
|
-
});
|
17191
|
-
return isAssignable;
|
17105
|
+
destType.shared.recursiveAlias.typeVarScopeId === srcType.shared.recursiveAlias.typeVarScopeId) {
|
17106
|
+
return assignRecursiveTypeAliasToSelf(destAliasInfo, srcAliasInfo, diag, constraints, flags, recursionCount);
|
17192
17107
|
}
|
17193
17108
|
else {
|
17194
17109
|
// Have we already recursed once?
|
@@ -17704,6 +17619,31 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17704
17619
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
17705
17620
|
return false;
|
17706
17621
|
}
|
17622
|
+
// Determines whether a recursive type alias can be assigned to itself
|
17623
|
+
// given the source and dest type args and computed variance for its
|
17624
|
+
// type params.
|
17625
|
+
function assignRecursiveTypeAliasToSelf(destAliasInfo, srcAliasInfo, diag, constraints, flags = 0 /* AssignTypeFlags.Default */, recursionCount = 0) {
|
17626
|
+
(0, debug_1.assert)(destAliasInfo.typeArgs !== undefined);
|
17627
|
+
(0, debug_1.assert)(srcAliasInfo.typeArgs !== undefined);
|
17628
|
+
let isAssignable = true;
|
17629
|
+
const srcTypeArgs = srcAliasInfo.typeArgs;
|
17630
|
+
const variances = destAliasInfo.shared.computedVariance;
|
17631
|
+
destAliasInfo.typeArgs.forEach((destTypeArg, index) => {
|
17632
|
+
const srcTypeArg = index < srcTypeArgs.length ? srcTypeArgs[index] : types_1.UnknownType.create();
|
17633
|
+
let adjFlags = flags;
|
17634
|
+
const variance = variances && index < variances.length ? variances[index] : 3 /* Variance.Covariant */;
|
17635
|
+
if (variance === 2 /* Variance.Invariant */) {
|
17636
|
+
adjFlags |= 1 /* AssignTypeFlags.Invariant */;
|
17637
|
+
}
|
17638
|
+
else if (variance === 4 /* Variance.Contravariant */) {
|
17639
|
+
adjFlags ^= 2 /* AssignTypeFlags.Contravariant */;
|
17640
|
+
}
|
17641
|
+
if (!assignType(destTypeArg, srcTypeArg, diag, constraints, adjFlags, recursionCount)) {
|
17642
|
+
isAssignable = false;
|
17643
|
+
}
|
17644
|
+
});
|
17645
|
+
return isAssignable;
|
17646
|
+
}
|
17707
17647
|
// If the expected type is an explicit TypeForm type, see if the source
|
17708
17648
|
// type has an implicit TypeForm type that can be assigned to it. If so,
|
17709
17649
|
// convert to an explicit TypeForm type.
|
@@ -18315,7 +18255,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18315
18255
|
}
|
18316
18256
|
});
|
18317
18257
|
if (srcTupleTypes.length !== 1 || !(0, types_1.isTypeVarTuple)(srcTupleTypes[0].type)) {
|
18318
|
-
const srcPositionalsType = makeTupleObject(srcTupleTypes, /* isUnpacked */ true);
|
18258
|
+
const srcPositionalsType = (0, tuples_1.makeTupleObject)(evaluatorInterface, srcTupleTypes, /* isUnpacked */ true);
|
18319
18259
|
// Snip out the portion of the source positionals that map to the variadic
|
18320
18260
|
// dest parameter and replace it with a single parameter that is typed as a
|
18321
18261
|
// tuple containing the individual types of the replaced parameters.
|
@@ -18571,10 +18511,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18571
18511
|
let destArgsType = destParamDetails.params[destParamDetails.argsIndex].type;
|
18572
18512
|
let srcArgsType = srcParamDetails.params[srcParamDetails.argsIndex].type;
|
18573
18513
|
if (!(0, types_1.isUnpacked)(destArgsType)) {
|
18574
|
-
destArgsType = makeTupleObject([{ type: destArgsType, isUnbounded: true }],
|
18514
|
+
destArgsType = (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type: destArgsType, isUnbounded: true }],
|
18515
|
+
/* isUnpacked */ true);
|
18575
18516
|
}
|
18576
18517
|
if (!(0, types_1.isUnpacked)(srcArgsType)) {
|
18577
|
-
srcArgsType = makeTupleObject([{ type: srcArgsType, isUnbounded: true }],
|
18518
|
+
srcArgsType = (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type: srcArgsType, isUnbounded: true }],
|
18519
|
+
/* isUnpacked */ true);
|
18578
18520
|
}
|
18579
18521
|
if (!assignParam(destArgsType, srcArgsType, destParamDetails.params[destParamDetails.argsIndex].index, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints, flags, recursionCount)) {
|
18580
18522
|
canAssign = false;
|
@@ -18599,7 +18541,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18599
18541
|
if (destParamDetails.firstKeywordOnlyIndex !== undefined) {
|
18600
18542
|
destParamDetails.params.forEach((param, index) => {
|
18601
18543
|
if (index >= destParamDetails.firstKeywordOnlyIndex) {
|
18602
|
-
if (param.param.name &&
|
18544
|
+
if (param.param.name &&
|
18545
|
+
param.param.category === 0 /* ParamCategory.Simple */ &&
|
18546
|
+
param.kind !== parameterUtils_1.ParamKind.Positional) {
|
18603
18547
|
destParamMap.set(param.param.name, param);
|
18604
18548
|
}
|
18605
18549
|
}
|
@@ -18926,7 +18870,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18926
18870
|
}
|
18927
18871
|
return assignedSubtype;
|
18928
18872
|
}
|
18929
|
-
if (!(0, types_1.isTypeVar)(declaredSubtype) &&
|
18873
|
+
if (!(0, types_1.isTypeVar)(declaredSubtype) &&
|
18874
|
+
(0, types_1.isTypeVar)(assignedSubtype) &&
|
18875
|
+
!types_1.TypeVarType.isBound(assignedSubtype)) {
|
18930
18876
|
// If the source is an unsolved TypeVar but the declared type is concrete,
|
18931
18877
|
// use the concrete type.
|
18932
18878
|
return declaredSubtype;
|
@@ -19821,7 +19767,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19821
19767
|
return codeFlowEngine.printControlFlowGraph(flowNode, reference, callName, logger);
|
19822
19768
|
}
|
19823
19769
|
// Track these apis internal usages when logging is on. otherwise, it should be noop.
|
19824
|
-
const
|
19770
|
+
const getInferredReturnType = wrapWithLogger(_getInferredReturnType);
|
19825
19771
|
const evaluatorInterface = {
|
19826
19772
|
runWithCancellationToken,
|
19827
19773
|
getType,
|
@@ -19839,7 +19785,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19839
19785
|
evaluateTypesForStatement,
|
19840
19786
|
evaluateTypesForMatchStatement,
|
19841
19787
|
evaluateTypesForCaseStatement,
|
19842
|
-
evaluateTypeOfParam
|
19788
|
+
evaluateTypeOfParam,
|
19843
19789
|
canBeTruthy,
|
19844
19790
|
canBeFalsy,
|
19845
19791
|
stripLiteralValue,
|
@@ -19866,7 +19812,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19866
19812
|
getTypeOfIterable,
|
19867
19813
|
getTypeOfIterator,
|
19868
19814
|
getGetterTypeFromProperty,
|
19869
|
-
getTypeOfArg
|
19815
|
+
getTypeOfArg,
|
19816
|
+
convertNodeToArg,
|
19817
|
+
buildTupleTypesList,
|
19870
19818
|
markNamesAccessed,
|
19871
19819
|
expandPromotionTypes,
|
19872
19820
|
makeTopLevelTypeVarsConcrete,
|
@@ -19878,8 +19826,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19878
19826
|
getEffectiveTypeOfSymbolForUsage,
|
19879
19827
|
getInferredTypeOfDeclaration,
|
19880
19828
|
getDeclaredTypeForExpression,
|
19881
|
-
|
19882
|
-
|
19829
|
+
getDeclaredReturnType,
|
19830
|
+
getInferredReturnType,
|
19883
19831
|
getBestOverloadForArgs,
|
19884
19832
|
getBuiltInType,
|
19885
19833
|
getTypeOfMember,
|