@zzzen/pyright-internal 1.2.0-dev.20240728 → 1.2.0-dev.20240804
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 +7 -4
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +2 -1
- package/dist/analyzer/checker.js +135 -83
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +4 -4
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolution.d.ts +21 -0
- package/dist/analyzer/constraintSolution.js +71 -0
- package/dist/analyzer/constraintSolution.js.map +1 -0
- package/dist/analyzer/constraintSolver.d.ts +9 -5
- package/dist/analyzer/constraintSolver.js +420 -322
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constraintTracker.d.ts +44 -0
- package/dist/analyzer/constraintTracker.js +230 -0
- package/dist/analyzer/constraintTracker.js.map +1 -0
- package/dist/analyzer/constructorTransform.js +15 -15
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +1 -1
- package/dist/analyzer/constructors.js +59 -38
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +35 -32
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/decorators.js +1 -1
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/functionTransform.js +1 -1
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/operations.d.ts +1 -2
- package/dist/analyzer/operations.js +95 -72
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +8 -4
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +3 -3
- package/dist/analyzer/parameterUtils.js +19 -21
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +21 -19
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/properties.d.ts +3 -2
- package/dist/analyzer/properties.js +11 -11
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.d.ts +3 -3
- package/dist/analyzer/protocols.js +50 -48
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/tuples.d.ts +2 -2
- package/dist/analyzer/tuples.js +10 -9
- package/dist/analyzer/tuples.js.map +1 -1
- package/dist/analyzer/typeComplexity.js +12 -4
- package/dist/analyzer/typeComplexity.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +806 -778
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +28 -8
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +46 -39
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +17 -15
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +32 -30
- package/dist/analyzer/typeUtils.js +331 -563
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeWalker.js +1 -1
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +2 -2
- package/dist/analyzer/typedDicts.js +25 -25
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +24 -21
- package/dist/analyzer/types.js +110 -113
- package/dist/analyzer/types.js.map +1 -1
- package/dist/languageServerBase.d.ts +2 -2
- package/dist/languageServerBase.js +5 -2
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/completionProvider.js +2 -2
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/tests/checker.test.js +10 -2
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +1 -1
- package/dist/tests/typeEvaluator2.test.js +12 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +4 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator5.test.js +1 -1
- package/dist/tests/typeEvaluator7.test.js +4 -0
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +4 -0
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/package.json +1 -1
- package/dist/analyzer/typeVarContext.d.ts +0 -48
- package/dist/analyzer/typeVarContext.js +0 -288
- package/dist/analyzer/typeVarContext.js.map +0 -1
@@ -9,14 +9,14 @@
|
|
9
9
|
*/
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
11
11
|
exports.isTupleClass = exports.isTupleGradualForm = exports.isMaybeDescriptorInstance = exports.isDescriptorInstance = exports.isCallableType = exports.isProperty = exports.isEllipsisType = exports.getUnionSubtypeCount = exports.getLiteralTypeClassName = exports.containsLiteralType = exports.isLiteralTypeOrUnion = exports.isLiteralType = exports.getSpecializedTupleType = exports.selfSpecializeClass = exports.getUnknownTypeForCallable = exports.getUnknownForTypeVarTuple = exports.getUnknownForTypeVar = exports.specializeWithUnknownTypeArgs = exports.specializeWithDefaultTypeArgs = exports.getTypeVarScopeIds = exports.getTypeVarScopeId = exports.transformPossibleRecursiveTypeAlias = exports.isTypeAliasRecursive = exports.isTypeAliasPlaceholder = exports.getTypeCondition = exports.addConditionToType = exports.getFullNameOfType = exports.derivesFromAnyOrUnknown = exports.isUnionableType = exports.preserveUnknown = exports.areTypesSame = exports.doForEachSignature = exports.allSubtypes = exports.someSubtypes = exports.doForEachSubtype = exports.sortTypes = exports.cleanIncompleteUnknown = exports.mapSignatures = exports.mapSubtypes = exports.makeInferenceContext = exports.isTypeVarSame = exports.isIncompleteUnknown = exports.removeNoneFromUnion = exports.isNoneTypeClass = exports.isNoneInstance = exports.isOptionalType = exports.UniqueSignatureTracker = exports.AssignTypeFlags = exports.ClassIteratorFlags = exports.MemberAccessFlags = void 0;
|
12
|
-
exports.requiresTypeArgs = exports.getGeneratorTypeArgs = exports.specializeTupleClass = exports.combineTupleTypeArgs = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsAnyOrUnknown = exports.containsAnyRecursive = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.isMetaclassInstance = exports.isInstantiableMetaclass = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.derivesFromStdlibClass = exports.specializeForBaseClass = exports.
|
13
|
-
exports.
|
12
|
+
exports.combineVariances = exports.requiresSpecialization = exports.requiresTypeArgs = exports.getGeneratorTypeArgs = exports.specializeTupleClass = exports.combineTupleTypeArgs = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsAnyOrUnknown = exports.containsAnyRecursive = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.isMetaclassInstance = exports.isInstantiableMetaclass = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.derivesFromStdlibClass = exports.specializeForBaseClass = exports.buildSolution = exports.buildSolutionFromSpecializedClass = exports.setTypeArgsRecursive = exports.specializeClassType = exports.getTypeVarArgsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = exports.lookUpClassMember = exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbolsRecursive = exports.getProtocolSymbols = exports.transformExpectedType = exports.validateTypeVarDefault = exports.applySourceContextTypeVarsToSignature = exports.applySourceContextTypeVars = exports.applySolvedTypeVars = exports.makeTypeVarsFree = exports.makeTypeVarsBound = exports.ensureSignaturesAreUnique = exports.addSolutionForSelfType = exports.partiallySpecializeType = exports.isTupleIndexUnambiguous = exports.isUnboundedTupleClass = void 0;
|
13
|
+
exports.TypeVarTransformer = exports.simplifyFunctionToParamSpec = exports.convertTypeToParamSpecValue = exports.convertNodeToArg = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgCompatible = void 0;
|
14
14
|
const collectionUtils_1 = require("../common/collectionUtils");
|
15
15
|
const debug_1 = require("../common/debug");
|
16
|
+
const constraintSolution_1 = require("./constraintSolution");
|
16
17
|
const symbol_1 = require("./symbol");
|
17
18
|
const symbolUtils_1 = require("./symbolUtils");
|
18
19
|
const types_1 = require("./types");
|
19
|
-
const typeVarContext_1 = require("./typeVarContext");
|
20
20
|
const typeWalker_1 = require("./typeWalker");
|
21
21
|
var MemberAccessFlags;
|
22
22
|
(function (MemberAccessFlags) {
|
@@ -88,10 +88,10 @@ var AssignTypeFlags;
|
|
88
88
|
// This has the potential of recursing infinitely. This flag allows us
|
89
89
|
// to detect the recursion after the first level of checking.
|
90
90
|
AssignTypeFlags[AssignTypeFlags["SkipRecursiveTypeCheck"] = 4] = "SkipRecursiveTypeCheck";
|
91
|
-
//
|
92
|
-
//
|
93
|
-
//
|
94
|
-
AssignTypeFlags[AssignTypeFlags["
|
91
|
+
// During TypeVar solving for a function call, this flag is set if
|
92
|
+
// this is the first of multiple passes. It adjusts certain heuristics
|
93
|
+
// for constraint solving.
|
94
|
+
AssignTypeFlags[AssignTypeFlags["ArgAssignmentFirstPass"] = 8] = "ArgAssignmentFirstPass";
|
95
95
|
// If the dest is not Any but the src is Any, treat it
|
96
96
|
// as incompatible. Also, treat all source TypeVars as their
|
97
97
|
// concrete counterparts. This option is used for validating
|
@@ -111,11 +111,7 @@ var AssignTypeFlags;
|
|
111
111
|
// because overloads can provide explicit type annotations for self
|
112
112
|
// or cls.
|
113
113
|
AssignTypeFlags[AssignTypeFlags["SkipSelfClsTypeCheck"] = 512] = "SkipSelfClsTypeCheck";
|
114
|
-
//
|
115
|
-
// do not generate an error. This is used for populating the
|
116
|
-
// typeVarContext when handling contravariant parameters in a callable.
|
117
|
-
AssignTypeFlags[AssignTypeFlags["IgnoreTypeVarScope"] = 1024] = "IgnoreTypeVarScope";
|
118
|
-
// We're initially populating the typeVarContext with an expected type,
|
114
|
+
// We're initially populating the constraints with an expected type,
|
119
115
|
// so TypeVars should match the specified type exactly rather than
|
120
116
|
// employing narrowing or widening, and don't strip literals.
|
121
117
|
AssignTypeFlags[AssignTypeFlags["PopulatingExpectedType"] = 2048] = "PopulatingExpectedType";
|
@@ -214,7 +210,7 @@ function isTypeVarSame(type1, type2) {
|
|
214
210
|
return true;
|
215
211
|
}
|
216
212
|
// If this isn't a bound TypeVar, return false.
|
217
|
-
if ((0, types_1.isParamSpec)(type1) || (0, types_1.isTypeVarTuple)(type1) || !
|
213
|
+
if ((0, types_1.isParamSpec)(type1) || (0, types_1.isTypeVarTuple)(type1) || !types_1.TypeVarType.hasBound(type1)) {
|
218
214
|
return false;
|
219
215
|
}
|
220
216
|
// If the second type isn't a union, return false.
|
@@ -267,17 +263,17 @@ function mapSubtypes(type, callback, options) {
|
|
267
263
|
for (i++; i < subtypes.length; i++) {
|
268
264
|
accumulateSubtype(callback(subtypes[i]));
|
269
265
|
}
|
270
|
-
|
266
|
+
let newType = (0, types_1.combineTypes)(typesToCombine, {
|
271
267
|
skipElideRedundantLiterals: options === null || options === void 0 ? void 0 : options.skipElideRedundantLiterals,
|
272
268
|
});
|
273
269
|
if (options === null || options === void 0 ? void 0 : options.retainTypeAlias) {
|
274
270
|
if ((_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) {
|
275
|
-
types_1.TypeBase.
|
271
|
+
newType = types_1.TypeBase.cloneForTypeAlias(newType, type.props.typeAliasInfo);
|
276
272
|
}
|
277
273
|
}
|
278
274
|
else {
|
279
275
|
// Do our best to retain type aliases.
|
280
|
-
if (
|
276
|
+
if ((0, types_1.isUnion)(newType)) {
|
281
277
|
types_1.UnionType.addTypeAliasSource(newType, type);
|
282
278
|
}
|
283
279
|
}
|
@@ -422,7 +418,7 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
422
418
|
if (aParam.category !== bParam.category) {
|
423
419
|
return bParam.category - aParam.category;
|
424
420
|
}
|
425
|
-
const typeComparison = compareTypes(types_1.FunctionType.
|
421
|
+
const typeComparison = compareTypes(types_1.FunctionType.getParamType(a, i), types_1.FunctionType.getParamType(bFunc, i));
|
426
422
|
if (typeComparison !== 0) {
|
427
423
|
return typeComparison;
|
428
424
|
}
|
@@ -667,7 +663,7 @@ function addConditionToType(type, condition, skipSelfCondition = false) {
|
|
667
663
|
return type;
|
668
664
|
}
|
669
665
|
if (skipSelfCondition) {
|
670
|
-
condition = condition.filter((c) => !c.typeVar
|
666
|
+
condition = condition.filter((c) => !types_1.TypeVarType.isSelf(c.typeVar));
|
671
667
|
if (condition.length === 0) {
|
672
668
|
return type;
|
673
669
|
}
|
@@ -745,14 +741,14 @@ function transformPossibleRecursiveTypeAlias(type) {
|
|
745
741
|
if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArgs) || !type.shared.recursiveAlias.typeParams) {
|
746
742
|
return unspecializedType;
|
747
743
|
}
|
748
|
-
const
|
749
|
-
return applySolvedTypeVars(unspecializedType,
|
744
|
+
const solution = buildSolution(type.shared.recursiveAlias.typeParams, aliasInfo.typeArgs);
|
745
|
+
return applySolvedTypeVars(unspecializedType, solution);
|
750
746
|
}
|
751
747
|
if ((0, types_1.isUnion)(type) && type.priv.includesRecursiveTypeAlias) {
|
752
748
|
let newType = mapSubtypes(type, (subtype) => transformPossibleRecursiveTypeAlias(subtype));
|
753
749
|
if (newType !== type && aliasInfo) {
|
754
750
|
// Copy the type alias information if present.
|
755
|
-
newType = types_1.TypeBase.cloneForTypeAlias(newType, aliasInfo
|
751
|
+
newType = types_1.TypeBase.cloneForTypeAlias(newType, aliasInfo);
|
756
752
|
}
|
757
753
|
return newType;
|
758
754
|
}
|
@@ -785,9 +781,6 @@ function getTypeVarScopeIds(type) {
|
|
785
781
|
if (type.priv.constructorTypeVarScopeId) {
|
786
782
|
scopeIds.push(type.priv.constructorTypeVarScopeId);
|
787
783
|
}
|
788
|
-
if (type.priv.higherOrderTypeVarScopeIds) {
|
789
|
-
scopeIds.push(...type.priv.higherOrderTypeVarScopeIds);
|
790
|
-
}
|
791
784
|
}
|
792
785
|
return scopeIds;
|
793
786
|
}
|
@@ -856,7 +849,7 @@ function selfSpecializeClass(type, options) {
|
|
856
849
|
return type;
|
857
850
|
}
|
858
851
|
const typeParams = type.shared.typeParams.map((typeParam) => {
|
859
|
-
return (options === null || options === void 0 ? void 0 : options.
|
852
|
+
return (options === null || options === void 0 ? void 0 : options.useBoundTypeVars) ? types_1.TypeVarType.cloneAsBound(typeParam) : typeParam;
|
860
853
|
});
|
861
854
|
return types_1.ClassType.specialize(type, typeParams);
|
862
855
|
}
|
@@ -883,8 +876,8 @@ function getSpecializedTupleType(type) {
|
|
883
876
|
if (types_1.ClassType.isSameGenericClass(classType, tupleClass)) {
|
884
877
|
return classType;
|
885
878
|
}
|
886
|
-
const
|
887
|
-
return applySolvedTypeVars(tupleClass,
|
879
|
+
const solution = buildSolutionFromSpecializedClass(classType);
|
880
|
+
return applySolvedTypeVars(tupleClass, solution);
|
888
881
|
}
|
889
882
|
exports.getSpecializedTupleType = getSpecializedTupleType;
|
890
883
|
function isLiteralType(type) {
|
@@ -1069,11 +1062,11 @@ function partiallySpecializeType(type, contextClassType, typeClassType, selfClas
|
|
1069
1062
|
return type;
|
1070
1063
|
}
|
1071
1064
|
// Partially specialize the type using the specialized class type vars.
|
1072
|
-
const
|
1065
|
+
const solution = buildSolutionFromSpecializedClass(contextClassType);
|
1073
1066
|
if (selfClass) {
|
1074
|
-
|
1067
|
+
addSolutionForSelfType(solution, contextClassType, selfClass);
|
1075
1068
|
}
|
1076
|
-
let result = applySolvedTypeVars(type,
|
1069
|
+
let result = applySolvedTypeVars(type, solution, { typeClassType });
|
1077
1070
|
// If this is a property, we may need to partially specialize the
|
1078
1071
|
// access methods associated with it.
|
1079
1072
|
if ((0, types_1.isClass)(result)) {
|
@@ -1096,7 +1089,7 @@ function partiallySpecializeType(type, contextClassType, typeClassType, selfClas
|
|
1096
1089
|
return result;
|
1097
1090
|
}
|
1098
1091
|
exports.partiallySpecializeType = partiallySpecializeType;
|
1099
|
-
function
|
1092
|
+
function addSolutionForSelfType(solution, contextClassType, selfClass) {
|
1100
1093
|
const synthesizedSelfTypeVar = synthesizeTypeVarForSelfCls(contextClassType, /* isClsParam */ false);
|
1101
1094
|
const selfInstance = convertToInstance(selfClass);
|
1102
1095
|
// We can't call stripLiteralValue here because that method requires the type evaluator.
|
@@ -1109,89 +1102,58 @@ function populateTypeVarContextForSelfType(typeVarContext, contextClassType, sel
|
|
1109
1102
|
}
|
1110
1103
|
return subtype;
|
1111
1104
|
});
|
1112
|
-
|
1113
|
-
setTypeVarType(typeVarContext, synthesizedSelfTypeVar, selfInstance, selfWithoutLiteral);
|
1114
|
-
}
|
1105
|
+
solution.setType(synthesizedSelfTypeVar, selfWithoutLiteral);
|
1115
1106
|
}
|
1116
|
-
exports.
|
1107
|
+
exports.addSolutionForSelfType = addSolutionForSelfType;
|
1117
1108
|
// Looks for duplicate function types within the type and ensures that
|
1118
1109
|
// if they are generic, they have unique type variables.
|
1119
|
-
function
|
1110
|
+
function ensureSignaturesAreUnique(type, signatureTracker, expressionOffset) {
|
1120
1111
|
const transformer = new UniqueFunctionSignatureTransformer(signatureTracker, expressionOffset);
|
1121
1112
|
return transformer.apply(type, 0);
|
1122
1113
|
}
|
1123
|
-
exports.
|
1124
|
-
function
|
1125
|
-
const transformer = new
|
1114
|
+
exports.ensureSignaturesAreUnique = ensureSignaturesAreUnique;
|
1115
|
+
function makeTypeVarsBound(type, scopeIds) {
|
1116
|
+
const transformer = new BoundTypeVarTransform(scopeIds);
|
1126
1117
|
return transformer.apply(type, 0);
|
1127
1118
|
}
|
1128
|
-
exports.
|
1129
|
-
function
|
1130
|
-
const transformer = new
|
1119
|
+
exports.makeTypeVarsBound = makeTypeVarsBound;
|
1120
|
+
function makeTypeVarsFree(type, scopeIds) {
|
1121
|
+
const transformer = new FreeTypeVarTransform(scopeIds);
|
1131
1122
|
return transformer.apply(type, 0);
|
1132
1123
|
}
|
1133
|
-
exports.
|
1124
|
+
exports.makeTypeVarsFree = makeTypeVarsFree;
|
1134
1125
|
// Specializes a (potentially generic) type by substituting
|
1135
1126
|
// type variables from a type var map.
|
1136
|
-
function applySolvedTypeVars(type,
|
1137
|
-
// Use a shortcut if
|
1138
|
-
if (
|
1139
|
-
!options.unknownIfNotFound &&
|
1140
|
-
!options.eliminateUnsolvedInUnions &&
|
1141
|
-
!options.applyInScopePlaceholders) {
|
1127
|
+
function applySolvedTypeVars(type, solution, options = {}) {
|
1128
|
+
// Use a shortcut if constraints is empty and no transform is necessary.
|
1129
|
+
if (solution.isEmpty() && !options.replaceUnsolved) {
|
1142
1130
|
return type;
|
1143
1131
|
}
|
1144
|
-
|
1145
|
-
applyInScopePlaceholders(typeVarContext);
|
1146
|
-
}
|
1147
|
-
const transformer = new ApplySolvedTypeVarsTransformer(typeVarContext, options);
|
1132
|
+
const transformer = new ApplySolvedTypeVarsTransformer(solution, options);
|
1148
1133
|
return transformer.apply(type, 0);
|
1149
1134
|
}
|
1150
1135
|
exports.applySolvedTypeVars = applySolvedTypeVars;
|
1151
1136
|
// Applies solved TypeVars from one context to this context.
|
1152
|
-
function applySourceContextTypeVars(destContext,
|
1153
|
-
if (
|
1137
|
+
function applySourceContextTypeVars(destContext, srcSolution) {
|
1138
|
+
if (srcSolution.isEmpty()) {
|
1154
1139
|
return;
|
1155
1140
|
}
|
1156
|
-
destContext.
|
1157
|
-
applySourceContextTypeVarsToSignature(
|
1141
|
+
destContext.doForEachConstraintSet((set) => {
|
1142
|
+
applySourceContextTypeVarsToSignature(set, srcSolution);
|
1158
1143
|
});
|
1159
1144
|
}
|
1160
1145
|
exports.applySourceContextTypeVars = applySourceContextTypeVars;
|
1161
|
-
function applySourceContextTypeVarsToSignature(
|
1162
|
-
|
1163
|
-
const newLowerBound = entry.lowerBound ? applySolvedTypeVars(entry.lowerBound,
|
1146
|
+
function applySourceContextTypeVarsToSignature(set, srcSolution) {
|
1147
|
+
set.getTypeVars().forEach((entry) => {
|
1148
|
+
const newLowerBound = entry.lowerBound ? applySolvedTypeVars(entry.lowerBound, srcSolution) : undefined;
|
1164
1149
|
const newLowerBoundNoLiterals = entry.lowerBoundNoLiterals
|
1165
|
-
? applySolvedTypeVars(entry.lowerBoundNoLiterals,
|
1150
|
+
? applySolvedTypeVars(entry.lowerBoundNoLiterals, srcSolution)
|
1166
1151
|
: undefined;
|
1167
|
-
const newUpperBound = entry.upperBound ? applySolvedTypeVars(entry.upperBound,
|
1168
|
-
|
1152
|
+
const newUpperBound = entry.upperBound ? applySolvedTypeVars(entry.upperBound, srcSolution) : undefined;
|
1153
|
+
set.setBounds(entry.typeVar, newLowerBound, newLowerBoundNoLiterals, newUpperBound);
|
1169
1154
|
});
|
1170
1155
|
}
|
1171
1156
|
exports.applySourceContextTypeVarsToSignature = applySourceContextTypeVarsToSignature;
|
1172
|
-
// If the TypeVarContext contains any type variables whose types depend on
|
1173
|
-
// in-scope placeholders used for bidirectional type inference, replace those
|
1174
|
-
// with the solved type associated with those in-scope placeholders.
|
1175
|
-
function applyInScopePlaceholders(typeVarContext) {
|
1176
|
-
typeVarContext.doForEachSolutionSet((solutionSet) => {
|
1177
|
-
solutionSet.getTypeVars().forEach((entry) => {
|
1178
|
-
const typeVar = entry.typeVar;
|
1179
|
-
if (!typeVar.priv.isInScopePlaceholder) {
|
1180
|
-
const newLowerBound = entry.lowerBound
|
1181
|
-
? applyInScopePlaceholdersToType(entry.lowerBound, solutionSet)
|
1182
|
-
: undefined;
|
1183
|
-
const newLowerBoundNoLiterals = entry.lowerBoundNoLiterals
|
1184
|
-
? applyInScopePlaceholdersToType(entry.lowerBoundNoLiterals, solutionSet)
|
1185
|
-
: undefined;
|
1186
|
-
const newUpperBound = entry.upperBound
|
1187
|
-
? applyInScopePlaceholdersToType(entry.upperBound, solutionSet)
|
1188
|
-
: undefined;
|
1189
|
-
solutionSet.setTypeVarType(entry.typeVar, newLowerBound, newLowerBoundNoLiterals, newUpperBound);
|
1190
|
-
}
|
1191
|
-
});
|
1192
|
-
});
|
1193
|
-
}
|
1194
|
-
exports.applyInScopePlaceholders = applyInScopePlaceholders;
|
1195
1157
|
// Validates that a default type associated with a TypeVar does not refer to
|
1196
1158
|
// other TypeVars or ParamSpecs that are out of scope.
|
1197
1159
|
function validateTypeVarDefault(typeVar, liveTypeParams, invalidTypeVars) {
|
@@ -1203,11 +1165,6 @@ function validateTypeVarDefault(typeVar, liveTypeParams, invalidTypeVars) {
|
|
1203
1165
|
}
|
1204
1166
|
}
|
1205
1167
|
exports.validateTypeVarDefault = validateTypeVarDefault;
|
1206
|
-
function replaceTypeVarsWithAny(type) {
|
1207
|
-
const transformer = new TypeVarAnyReplacer();
|
1208
|
-
return transformer.apply(type, 0);
|
1209
|
-
}
|
1210
|
-
exports.replaceTypeVarsWithAny = replaceTypeVarsWithAny;
|
1211
1168
|
// During bidirectional type inference for constructors, an "expected type"
|
1212
1169
|
// is used to prepopulate the type var map. This is problematic when the
|
1213
1170
|
// expected type uses TypeVars that are not part of the context of the
|
@@ -1593,7 +1550,7 @@ function getTypeVarArgsRecursive(type, recursionCount = 0) {
|
|
1593
1550
|
if ((0, types_1.isFunction)(type)) {
|
1594
1551
|
const combinedList = [];
|
1595
1552
|
for (let i = 0; i < type.shared.parameters.length; i++) {
|
1596
|
-
addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(types_1.FunctionType.
|
1553
|
+
addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(types_1.FunctionType.getParamType(type, i), recursionCount));
|
1597
1554
|
}
|
1598
1555
|
const returnType = types_1.FunctionType.getEffectiveReturnType(type);
|
1599
1556
|
if (returnType) {
|
@@ -1607,68 +1564,68 @@ exports.getTypeVarArgsRecursive = getTypeVarArgsRecursive;
|
|
1607
1564
|
// Creates a specialized version of the class, filling in any unspecified
|
1608
1565
|
// type arguments with Unknown.
|
1609
1566
|
function specializeClassType(type) {
|
1610
|
-
const
|
1567
|
+
const solution = new constraintSolution_1.ConstraintSolution();
|
1611
1568
|
const typeParams = types_1.ClassType.getTypeParams(type);
|
1612
1569
|
typeParams.forEach((typeParam) => {
|
1613
|
-
|
1570
|
+
solution.setType(typeParam, applySolvedTypeVars(typeParam.shared.defaultType, solution));
|
1614
1571
|
});
|
1615
|
-
return applySolvedTypeVars(type,
|
1572
|
+
return applySolvedTypeVars(type, solution);
|
1616
1573
|
}
|
1617
1574
|
exports.specializeClassType = specializeClassType;
|
1618
1575
|
// Recursively finds all of the type arguments and sets them
|
1619
1576
|
// to the specified srcType.
|
1620
|
-
function setTypeArgsRecursive(destType, srcType,
|
1577
|
+
function setTypeArgsRecursive(destType, srcType, constraints, recursionCount = 0) {
|
1621
1578
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
1622
1579
|
return;
|
1623
1580
|
}
|
1624
1581
|
recursionCount++;
|
1625
|
-
if (
|
1582
|
+
if (constraints.isLocked()) {
|
1626
1583
|
return;
|
1627
1584
|
}
|
1628
1585
|
switch (destType.category) {
|
1629
1586
|
case 8 /* TypeCategory.Union */:
|
1630
1587
|
doForEachSubtype(destType, (subtype) => {
|
1631
|
-
setTypeArgsRecursive(subtype, srcType,
|
1588
|
+
setTypeArgsRecursive(subtype, srcType, constraints, recursionCount);
|
1632
1589
|
});
|
1633
1590
|
break;
|
1634
1591
|
case 6 /* TypeCategory.Class */:
|
1635
1592
|
if (destType.priv.typeArgs) {
|
1636
1593
|
destType.priv.typeArgs.forEach((typeArg) => {
|
1637
|
-
setTypeArgsRecursive(typeArg, srcType,
|
1594
|
+
setTypeArgsRecursive(typeArg, srcType, constraints, recursionCount);
|
1638
1595
|
});
|
1639
1596
|
}
|
1640
1597
|
if (destType.priv.tupleTypeArgs) {
|
1641
1598
|
destType.priv.tupleTypeArgs.forEach((typeArg) => {
|
1642
|
-
setTypeArgsRecursive(typeArg.type, srcType,
|
1599
|
+
setTypeArgsRecursive(typeArg.type, srcType, constraints, recursionCount);
|
1643
1600
|
});
|
1644
1601
|
}
|
1645
1602
|
break;
|
1646
1603
|
case 4 /* TypeCategory.Function */:
|
1647
1604
|
if (destType.priv.specializedTypes) {
|
1648
1605
|
destType.priv.specializedTypes.parameterTypes.forEach((paramType) => {
|
1649
|
-
setTypeArgsRecursive(paramType, srcType,
|
1606
|
+
setTypeArgsRecursive(paramType, srcType, constraints, recursionCount);
|
1650
1607
|
});
|
1651
1608
|
if (destType.priv.specializedTypes.returnType) {
|
1652
|
-
setTypeArgsRecursive(destType.priv.specializedTypes.returnType, srcType,
|
1609
|
+
setTypeArgsRecursive(destType.priv.specializedTypes.returnType, srcType, constraints, recursionCount);
|
1653
1610
|
}
|
1654
1611
|
}
|
1655
1612
|
else {
|
1656
|
-
destType.shared.parameters.forEach((
|
1657
|
-
setTypeArgsRecursive(
|
1613
|
+
destType.shared.parameters.forEach((_, index) => {
|
1614
|
+
setTypeArgsRecursive(types_1.FunctionType.getParamType(destType, index), srcType, constraints, recursionCount);
|
1658
1615
|
});
|
1659
1616
|
if (destType.shared.declaredReturnType) {
|
1660
|
-
setTypeArgsRecursive(destType.shared.declaredReturnType, srcType,
|
1617
|
+
setTypeArgsRecursive(destType.shared.declaredReturnType, srcType, constraints, recursionCount);
|
1661
1618
|
}
|
1662
1619
|
}
|
1663
1620
|
break;
|
1664
1621
|
case 5 /* TypeCategory.OverloadedFunction */:
|
1665
1622
|
destType.priv.overloads.forEach((subtype) => {
|
1666
|
-
setTypeArgsRecursive(subtype, srcType,
|
1623
|
+
setTypeArgsRecursive(subtype, srcType, constraints, recursionCount);
|
1667
1624
|
});
|
1668
1625
|
break;
|
1669
1626
|
case 9 /* TypeCategory.TypeVar */:
|
1670
|
-
if (!
|
1671
|
-
|
1627
|
+
if (!constraints.getMainConstraintSet().getTypeVar(destType)) {
|
1628
|
+
constraints.setBounds(destType, srcType);
|
1672
1629
|
}
|
1673
1630
|
break;
|
1674
1631
|
}
|
@@ -1678,7 +1635,7 @@ exports.setTypeArgsRecursive = setTypeArgsRecursive;
|
|
1678
1635
|
// types. For example, if the generic type is Dict[_T1, _T2] and the
|
1679
1636
|
// specialized type is Dict[str, int], it returns a map that associates
|
1680
1637
|
// _T1 with str and _T2 with int.
|
1681
|
-
function
|
1638
|
+
function buildSolutionFromSpecializedClass(classType) {
|
1682
1639
|
const typeParams = types_1.ClassType.getTypeParams(classType);
|
1683
1640
|
let typeArgs;
|
1684
1641
|
if (classType.priv.tupleTypeArgs) {
|
@@ -1690,45 +1647,22 @@ function buildTypeVarContextFromSpecializedClass(classType) {
|
|
1690
1647
|
else {
|
1691
1648
|
typeArgs = classType.priv.typeArgs;
|
1692
1649
|
}
|
1693
|
-
return
|
1650
|
+
return buildSolution(typeParams, typeArgs);
|
1694
1651
|
}
|
1695
|
-
exports.
|
1696
|
-
function
|
1697
|
-
const
|
1652
|
+
exports.buildSolutionFromSpecializedClass = buildSolutionFromSpecializedClass;
|
1653
|
+
function buildSolution(typeParams, typeArgs) {
|
1654
|
+
const solution = new constraintSolution_1.ConstraintSolution();
|
1655
|
+
if (!typeArgs) {
|
1656
|
+
return solution;
|
1657
|
+
}
|
1698
1658
|
typeParams.forEach((typeParam, index) => {
|
1699
|
-
|
1700
|
-
|
1701
|
-
if ((0, types_1.isParamSpec)(typeParam)) {
|
1702
|
-
if (index < typeArgs.length) {
|
1703
|
-
typeArgType = typeArgs[index];
|
1704
|
-
if ((0, types_1.isFunction)(typeArgType) && types_1.FunctionType.isParamSpecValue(typeArgType)) {
|
1705
|
-
const parameters = [];
|
1706
|
-
const typeArgFunctionType = typeArgType;
|
1707
|
-
typeArgType.shared.parameters.forEach((param, paramIndex) => {
|
1708
|
-
parameters.push(types_1.FunctionParam.create(param.category, types_1.FunctionType.getEffectiveParamType(typeArgFunctionType, paramIndex), param.flags & types_1.FunctionParamFlags.NameSynthesized, param.name, param.defaultType));
|
1709
|
-
});
|
1710
|
-
setTypeVarType(typeVarContext, typeParam, typeArgType);
|
1711
|
-
}
|
1712
|
-
else if ((0, types_1.isParamSpec)(typeArgType) || (0, types_1.isAnyOrUnknown)(typeArgType)) {
|
1713
|
-
setTypeVarType(typeVarContext, typeParam, typeArgType);
|
1714
|
-
}
|
1715
|
-
}
|
1716
|
-
}
|
1717
|
-
else {
|
1718
|
-
if (index >= typeArgs.length) {
|
1719
|
-
typeArgType = types_1.AnyType.create();
|
1720
|
-
}
|
1721
|
-
else {
|
1722
|
-
typeArgType = typeArgs[index];
|
1723
|
-
}
|
1724
|
-
setTypeVarType(typeVarContext, typeParam, typeArgType,
|
1725
|
-
/* lowerBoundNoLiterals */ undefined, typeArgType);
|
1726
|
-
}
|
1659
|
+
if (index < typeArgs.length) {
|
1660
|
+
solution.setType(typeParam, typeArgs[index]);
|
1727
1661
|
}
|
1728
1662
|
});
|
1729
|
-
return
|
1663
|
+
return solution;
|
1730
1664
|
}
|
1731
|
-
exports.
|
1665
|
+
exports.buildSolution = buildSolution;
|
1732
1666
|
// Determines the specialized base class type that srcType derives from.
|
1733
1667
|
function specializeForBaseClass(srcType, baseClass) {
|
1734
1668
|
const typeParams = types_1.ClassType.getTypeParams(baseClass);
|
@@ -1737,8 +1671,8 @@ function specializeForBaseClass(srcType, baseClass) {
|
|
1737
1671
|
if (typeParams.length === 0) {
|
1738
1672
|
return baseClass;
|
1739
1673
|
}
|
1740
|
-
const
|
1741
|
-
const specializedType = applySolvedTypeVars(baseClass,
|
1674
|
+
const solution = buildSolutionFromSpecializedClass(srcType);
|
1675
|
+
const specializedType = applySolvedTypeVars(baseClass, solution);
|
1742
1676
|
(0, debug_1.assert)((0, types_1.isInstantiableClass)(specializedType));
|
1743
1677
|
return specializedType;
|
1744
1678
|
}
|
@@ -1921,7 +1855,7 @@ function convertToInstance(type, includeSubclasses = true) {
|
|
1921
1855
|
// Copy over any type alias information.
|
1922
1856
|
const aliasInfo = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo;
|
1923
1857
|
if (aliasInfo && type !== result) {
|
1924
|
-
result = types_1.TypeBase.cloneForTypeAlias(result, aliasInfo
|
1858
|
+
result = types_1.TypeBase.cloneForTypeAlias(result, aliasInfo);
|
1925
1859
|
}
|
1926
1860
|
if (type !== result && includeSubclasses) {
|
1927
1861
|
// Cache the converted value for next time.
|
@@ -2147,7 +2081,7 @@ function isPartlyUnknown(type, recursionCount = 0) {
|
|
2147
2081
|
for (let i = 0; i < type.shared.parameters.length; i++) {
|
2148
2082
|
// Ignore parameters such as "*" that have no name.
|
2149
2083
|
if (type.shared.parameters[i].name) {
|
2150
|
-
const paramType = types_1.FunctionType.
|
2084
|
+
const paramType = types_1.FunctionType.getParamType(type, i);
|
2151
2085
|
if (isPartlyUnknown(paramType, recursionCount)) {
|
2152
2086
|
return true;
|
2153
2087
|
}
|
@@ -2247,7 +2181,7 @@ function specializeTupleClass(classType, typeArgs, isTypeArgExplicit = true, isU
|
|
2247
2181
|
return clonedClassType;
|
2248
2182
|
}
|
2249
2183
|
exports.specializeTupleClass = specializeTupleClass;
|
2250
|
-
function
|
2184
|
+
function _expandUnpackedTypeVarTupleUnion(type) {
|
2251
2185
|
if ((0, types_1.isClassInstance)(type) && isTupleClass(type) && type.priv.tupleTypeArgs && type.priv.isUnpacked) {
|
2252
2186
|
return (0, types_1.combineTypes)(type.priv.tupleTypeArgs.map((t) => t.type));
|
2253
2187
|
}
|
@@ -2350,7 +2284,7 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
|
|
2350
2284
|
}
|
2351
2285
|
case 4 /* TypeCategory.Function */: {
|
2352
2286
|
for (let i = 0; i < type.shared.parameters.length; i++) {
|
2353
|
-
if (requiresSpecialization(types_1.FunctionType.
|
2287
|
+
if (requiresSpecialization(types_1.FunctionType.getParamType(type, i), options, recursionCount)) {
|
2354
2288
|
return true;
|
2355
2289
|
}
|
2356
2290
|
}
|
@@ -2378,7 +2312,7 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
|
|
2378
2312
|
case 9 /* TypeCategory.TypeVar */: {
|
2379
2313
|
// Most TypeVar types need to be specialized.
|
2380
2314
|
if (!type.shared.recursiveAlias) {
|
2381
|
-
if (
|
2315
|
+
if (types_1.TypeVarType.isSelf(type) && (options === null || options === void 0 ? void 0 : options.ignoreSelf)) {
|
2382
2316
|
return false;
|
2383
2317
|
}
|
2384
2318
|
return true;
|
@@ -2492,9 +2426,9 @@ function computeMroLinearization(classType) {
|
|
2492
2426
|
const classListsToMerge = [];
|
2493
2427
|
filteredBaseClasses.forEach((baseClass) => {
|
2494
2428
|
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
2495
|
-
const
|
2429
|
+
const solution = buildSolutionFromSpecializedClass(baseClass);
|
2496
2430
|
classListsToMerge.push(baseClass.shared.mro.map((mroClass) => {
|
2497
|
-
return applySolvedTypeVars(mroClass,
|
2431
|
+
return applySolvedTypeVars(mroClass, solution);
|
2498
2432
|
}));
|
2499
2433
|
}
|
2500
2434
|
else {
|
@@ -2502,12 +2436,12 @@ function computeMroLinearization(classType) {
|
|
2502
2436
|
}
|
2503
2437
|
});
|
2504
2438
|
classListsToMerge.push(filteredBaseClasses.map((baseClass) => {
|
2505
|
-
const
|
2506
|
-
return applySolvedTypeVars(baseClass,
|
2439
|
+
const solution = buildSolutionFromSpecializedClass(classType);
|
2440
|
+
return applySolvedTypeVars(baseClass, solution);
|
2507
2441
|
}));
|
2508
2442
|
// The first class in the MRO is the class itself.
|
2509
|
-
const
|
2510
|
-
let specializedClassType = applySolvedTypeVars(classType,
|
2443
|
+
const solution = buildSolutionFromSpecializedClass(classType);
|
2444
|
+
let specializedClassType = applySolvedTypeVars(classType, solution);
|
2511
2445
|
if (!(0, types_1.isClass)(specializedClassType) && !(0, types_1.isAnyOrUnknown)(specializedClassType)) {
|
2512
2446
|
specializedClassType = types_1.UnknownType.create();
|
2513
2447
|
}
|
@@ -2650,41 +2584,25 @@ function convertTypeToParamSpecValue(type) {
|
|
2650
2584
|
return newFunction;
|
2651
2585
|
}
|
2652
2586
|
if ((0, types_1.isFunction)(type)) {
|
2587
|
+
// If it's already a ParamSpecValue, return it as is.
|
2588
|
+
if (types_1.FunctionType.isParamSpecValue(type)) {
|
2589
|
+
return type;
|
2590
|
+
}
|
2653
2591
|
const newFunction = types_1.FunctionType.createInstance('', '', '', type.shared.flags | 65536 /* FunctionTypeFlags.ParamSpecValue */, type.shared.docString);
|
2654
2592
|
newFunction.shared.deprecatedMessage = type.shared.deprecatedMessage;
|
2655
2593
|
type.shared.parameters.forEach((param, index) => {
|
2656
|
-
types_1.FunctionType.addParam(newFunction, types_1.FunctionParam.create(param.category, types_1.FunctionType.
|
2594
|
+
types_1.FunctionType.addParam(newFunction, types_1.FunctionParam.create(param.category, types_1.FunctionType.getParamType(type, index), param.flags, param.name, types_1.FunctionType.getParamDefaultType(type, index)));
|
2657
2595
|
});
|
2658
|
-
|
2659
|
-
newFunction.priv.higherOrderTypeVarScopeIds = [...type.priv.higherOrderTypeVarScopeIds];
|
2660
|
-
newFunction.shared.typeVarScopeId = newFunction.priv.higherOrderTypeVarScopeIds.pop();
|
2661
|
-
}
|
2596
|
+
newFunction.shared.typeVarScopeId = type.shared.typeVarScopeId;
|
2662
2597
|
newFunction.priv.constructorTypeVarScopeId = type.priv.constructorTypeVarScopeId;
|
2663
2598
|
return newFunction;
|
2664
2599
|
}
|
2665
2600
|
return types_1.ParamSpecType.getUnknown();
|
2666
2601
|
}
|
2667
2602
|
exports.convertTypeToParamSpecValue = convertTypeToParamSpecValue;
|
2668
|
-
// This function calls the setTypeVarType method on the TypeVarContext after
|
2669
|
-
// converting the parameters for use with a ParamSpec.
|
2670
|
-
function setTypeVarType(typeVarContext, typeVar, lowerBound, lowerBoundNoLiterals, upperBound) {
|
2671
|
-
if ((0, types_1.isParamSpec)(typeVar)) {
|
2672
|
-
if (lowerBound) {
|
2673
|
-
lowerBound = convertTypeToParamSpecValue(lowerBound);
|
2674
|
-
}
|
2675
|
-
if (lowerBoundNoLiterals) {
|
2676
|
-
lowerBoundNoLiterals = convertTypeToParamSpecValue(lowerBoundNoLiterals);
|
2677
|
-
}
|
2678
|
-
if (upperBound) {
|
2679
|
-
lowerBound = convertTypeToParamSpecValue(upperBound);
|
2680
|
-
}
|
2681
|
-
}
|
2682
|
-
typeVarContext.setTypeVarType(typeVar, lowerBound, lowerBoundNoLiterals, upperBound);
|
2683
|
-
}
|
2684
|
-
exports.setTypeVarType = setTypeVarType;
|
2685
2603
|
// Converts a FunctionType into a ParamSpec if it consists only of
|
2686
2604
|
// (* args: P.args, ** kwargs: P.kwargs). Otherwise returns the original type.
|
2687
|
-
function
|
2605
|
+
function simplifyFunctionToParamSpec(type) {
|
2688
2606
|
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
|
2689
2607
|
const withoutParamSpec = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(type);
|
2690
2608
|
let hasParams = withoutParamSpec.shared.parameters.length > 0;
|
@@ -2700,31 +2618,19 @@ function convertParamSpecValueToType(type) {
|
|
2700
2618
|
if (!hasParams && paramSpec) {
|
2701
2619
|
return paramSpec;
|
2702
2620
|
}
|
2703
|
-
|
2704
|
-
const functionType = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | withoutParamSpec.shared.flags);
|
2705
|
-
types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.shared.typeVarScopeId);
|
2706
|
-
types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.priv.higherOrderTypeVarScopeIds);
|
2707
|
-
functionType.priv.constructorTypeVarScopeId = withoutParamSpec.priv.constructorTypeVarScopeId;
|
2708
|
-
withoutParamSpec.shared.parameters.forEach((entry, index) => {
|
2709
|
-
types_1.FunctionType.addParam(functionType, types_1.FunctionParam.create(entry.category, types_1.FunctionType.getEffectiveParamType(withoutParamSpec, index), (entry.flags & types_1.FunctionParamFlags.NameSynthesized) | types_1.FunctionParamFlags.TypeDeclared, entry.name, entry.defaultType));
|
2710
|
-
});
|
2711
|
-
if (paramSpec) {
|
2712
|
-
types_1.FunctionType.addParamSpecVariadics(functionType, paramSpec);
|
2713
|
-
}
|
2714
|
-
functionType.shared.docString = withoutParamSpec.shared.docString;
|
2715
|
-
functionType.shared.deprecatedMessage = withoutParamSpec.shared.deprecatedMessage;
|
2716
|
-
functionType.shared.methodClass = withoutParamSpec.shared.methodClass;
|
2717
|
-
return functionType;
|
2621
|
+
return type;
|
2718
2622
|
}
|
2719
|
-
exports.
|
2623
|
+
exports.simplifyFunctionToParamSpec = simplifyFunctionToParamSpec;
|
2720
2624
|
// Recursively walks a type and calls a callback for each TypeVar, allowing
|
2721
2625
|
// it to be replaced with something else.
|
2722
2626
|
class TypeVarTransformer {
|
2723
2627
|
constructor() {
|
2724
|
-
this._isTransformingTypeArg = false;
|
2725
2628
|
this._pendingTypeVarTransformations = new Set();
|
2726
2629
|
this._pendingFunctionTransformations = [];
|
2727
2630
|
}
|
2631
|
+
get pendingTypeVarTransformations() {
|
2632
|
+
return this._pendingTypeVarTransformations;
|
2633
|
+
}
|
2728
2634
|
apply(type, recursionCount) {
|
2729
2635
|
var _a, _b, _c;
|
2730
2636
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
@@ -2765,7 +2671,7 @@ class TypeVarTransformer {
|
|
2765
2671
|
return replacementType;
|
2766
2672
|
});
|
2767
2673
|
if (requiresUpdate) {
|
2768
|
-
return types_1.TypeBase.cloneForTypeAlias(type,
|
2674
|
+
return types_1.TypeBase.cloneForTypeAlias(type, { ...aliasInfo, typeArgs });
|
2769
2675
|
}
|
2770
2676
|
return type;
|
2771
2677
|
}
|
@@ -2774,43 +2680,36 @@ class TypeVarTransformer {
|
|
2774
2680
|
// type variables in the same scope recursively by setting it the scope in the
|
2775
2681
|
// _pendingTypeVarTransformations set.
|
2776
2682
|
if (!this._isTypeVarScopePending(type.priv.scopeId)) {
|
2777
|
-
|
2778
|
-
|
2779
|
-
|
2780
|
-
|
2683
|
+
let paramSpecAccess;
|
2684
|
+
// If this is a ParamSpec with a ".args" or ".kwargs" access, strip
|
2685
|
+
// it off for now. We'll add it back later if appropriate.
|
2686
|
+
if ((0, types_1.isParamSpec)(type) && type.priv.paramSpecAccess) {
|
2687
|
+
paramSpecAccess = type.priv.paramSpecAccess;
|
2688
|
+
type = types_1.TypeVarType.cloneForParamSpecAccess(type, /* access */ undefined);
|
2689
|
+
}
|
2690
|
+
replacementType = (_c = this.transformTypeVar(type, recursionCount)) !== null && _c !== void 0 ? _c : type;
|
2691
|
+
if ((0, types_1.isParamSpec)(type) && replacementType !== type) {
|
2692
|
+
replacementType = simplifyFunctionToParamSpec(convertTypeToParamSpecValue(replacementType));
|
2693
|
+
}
|
2694
|
+
// If the original type was a ParamSpec with a ".args" or ".kwargs" access,
|
2695
|
+
// preserve that information in the transformed type.
|
2696
|
+
if (paramSpecAccess) {
|
2697
|
+
if ((0, types_1.isParamSpec)(replacementType)) {
|
2698
|
+
replacementType = types_1.TypeVarType.cloneForParamSpecAccess(replacementType, paramSpecAccess);
|
2781
2699
|
}
|
2782
|
-
|
2783
|
-
|
2784
|
-
const paramSpecType = convertParamSpecValueToType(paramSpecValue);
|
2785
|
-
if (type.priv.paramSpecAccess) {
|
2786
|
-
if ((0, types_1.isParamSpec)(paramSpecType)) {
|
2787
|
-
replacementType = types_1.TypeVarType.cloneForParamSpecAccess(paramSpecType, type.priv.paramSpecAccess);
|
2788
|
-
}
|
2789
|
-
else {
|
2790
|
-
replacementType = types_1.UnknownType.create();
|
2791
|
-
}
|
2792
|
-
}
|
2793
|
-
else {
|
2794
|
-
replacementType = paramSpecType;
|
2795
|
-
}
|
2700
|
+
else {
|
2701
|
+
replacementType = types_1.UnknownType.create();
|
2796
2702
|
}
|
2797
2703
|
}
|
2798
|
-
|
2799
|
-
|
2800
|
-
|
2801
|
-
|
2802
|
-
|
2803
|
-
|
2804
|
-
|
2805
|
-
|
2806
|
-
|
2807
|
-
}
|
2808
|
-
}
|
2809
|
-
// If we're transforming a variadic type variable that was in a union,
|
2810
|
-
// expand the union types.
|
2811
|
-
if ((0, types_1.isTypeVarTuple)(type) && type.priv.isVariadicInUnion) {
|
2812
|
-
replacementType = _expandVariadicUnpackedUnion(replacementType);
|
2813
|
-
}
|
2704
|
+
// If we're transforming a TypeVarTuple that was in a union,
|
2705
|
+
// expand the union types.
|
2706
|
+
if ((0, types_1.isTypeVarTuple)(type) && type.priv.isInUnion) {
|
2707
|
+
replacementType = _expandUnpackedTypeVarTupleUnion(replacementType);
|
2708
|
+
}
|
2709
|
+
if (type.priv.scopeId) {
|
2710
|
+
this._pendingTypeVarTransformations.add(type.priv.scopeId);
|
2711
|
+
replacementType = this.apply(replacementType, recursionCount);
|
2712
|
+
this._pendingTypeVarTransformations.delete(type.priv.scopeId);
|
2814
2713
|
}
|
2815
2714
|
}
|
2816
2715
|
return replacementType;
|
@@ -2818,12 +2717,12 @@ class TypeVarTransformer {
|
|
2818
2717
|
if ((0, types_1.isUnion)(type)) {
|
2819
2718
|
const newUnionType = mapSubtypes(type, (subtype) => {
|
2820
2719
|
let transformedType = this.apply(subtype, recursionCount);
|
2821
|
-
// If we're transforming a
|
2822
|
-
// combine the individual types within the
|
2720
|
+
// If we're transforming a TypeVarTuple within a union,
|
2721
|
+
// combine the individual types within the TypeVarTuple.
|
2823
2722
|
if ((0, types_1.isTypeVarTuple)(subtype) && !(0, types_1.isTypeVarTuple)(transformedType)) {
|
2824
2723
|
const subtypesToCombine = [];
|
2825
2724
|
doForEachSubtype(transformedType, (transformedSubtype) => {
|
2826
|
-
subtypesToCombine.push(
|
2725
|
+
subtypesToCombine.push(_expandUnpackedTypeVarTupleUnion(transformedSubtype));
|
2827
2726
|
});
|
2828
2727
|
transformedType = (0, types_1.combineTypes)(subtypesToCombine);
|
2829
2728
|
}
|
@@ -2880,13 +2779,10 @@ class TypeVarTransformer {
|
|
2880
2779
|
transformTupleTypeVar(paramSpec, recursionCount) {
|
2881
2780
|
return undefined;
|
2882
2781
|
}
|
2883
|
-
transformParamSpec(paramSpec, recursionCount) {
|
2884
|
-
return undefined;
|
2885
|
-
}
|
2886
2782
|
transformUnionSubtype(preTransform, postTransform, recursionCount) {
|
2887
2783
|
return postTransform;
|
2888
2784
|
}
|
2889
|
-
|
2785
|
+
doForEachConstraintSet(callback) {
|
2890
2786
|
// By default, simply return the result of the callback. Subclasses
|
2891
2787
|
// can override this method as they see fit.
|
2892
2788
|
return callback();
|
@@ -2905,15 +2801,14 @@ class TypeVarTransformer {
|
|
2905
2801
|
}
|
2906
2802
|
return updatedType;
|
2907
2803
|
});
|
2908
|
-
return requiresUpdate
|
2909
|
-
? types_1.TypeBase.cloneForTypeAlias(type, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParams, newTypeArgs)
|
2910
|
-
: type;
|
2804
|
+
return requiresUpdate ? types_1.TypeBase.cloneForTypeAlias(type, { ...aliasInfo, typeArgs: newTypeArgs }) : type;
|
2911
2805
|
}
|
2912
2806
|
transformConditionalType(type, recursionCount) {
|
2913
2807
|
// By default, do not perform any transform.
|
2914
2808
|
return type;
|
2915
2809
|
}
|
2916
2810
|
transformTypeVarsInClassType(classType, recursionCount) {
|
2811
|
+
var _a;
|
2917
2812
|
const typeParams = types_1.ClassType.getTypeParams(classType);
|
2918
2813
|
// Handle the common case where the class has no type parameters.
|
2919
2814
|
if (typeParams.length === 0 &&
|
@@ -2924,18 +2819,6 @@ class TypeVarTransformer {
|
|
2924
2819
|
let newTypeArgs;
|
2925
2820
|
let newTupleTypeArgs;
|
2926
2821
|
let specializationNeeded = false;
|
2927
|
-
const transformParamSpec = (paramSpec) => {
|
2928
|
-
const paramSpecValue = this.transformParamSpec(paramSpec, recursionCount);
|
2929
|
-
if (paramSpecValue) {
|
2930
|
-
specializationNeeded = true;
|
2931
|
-
return convertParamSpecValueToType(paramSpecValue);
|
2932
|
-
}
|
2933
|
-
else {
|
2934
|
-
return paramSpec;
|
2935
|
-
}
|
2936
|
-
};
|
2937
|
-
const wasTransformingTypeArg = this._isTransformingTypeArg;
|
2938
|
-
this._isTransformingTypeArg = true;
|
2939
2822
|
// If type args were previously provided, specialize them.
|
2940
2823
|
// Handle tuples specially.
|
2941
2824
|
if (types_1.ClassType.isTupleClass(classType)) {
|
@@ -2987,52 +2870,20 @@ class TypeVarTransformer {
|
|
2987
2870
|
}
|
2988
2871
|
}
|
2989
2872
|
if (!newTypeArgs) {
|
2990
|
-
|
2991
|
-
|
2992
|
-
|
2993
|
-
|
2994
|
-
|
2995
|
-
|
2996
|
-
|
2997
|
-
|
2998
|
-
|
2999
|
-
// (e.g. Union[Unpack[Vs]]), expand the subtypes into a union here.
|
3000
|
-
if ((0, types_1.isTypeVar)(oldTypeArgType) &&
|
3001
|
-
(0, types_1.isTypeVarTuple)(oldTypeArgType) &&
|
3002
|
-
oldTypeArgType.priv.isVariadicInUnion) {
|
3003
|
-
newTypeArgType = _expandVariadicUnpackedUnion(newTypeArgType);
|
3004
|
-
}
|
3005
|
-
}
|
3006
|
-
return newTypeArgType;
|
3007
|
-
});
|
3008
|
-
}
|
3009
|
-
else {
|
3010
|
-
newTypeArgs = [];
|
3011
|
-
typeParams.forEach((typeParam) => {
|
3012
|
-
let replacementType = typeParam;
|
3013
|
-
if ((0, types_1.isParamSpec)(typeParam)) {
|
3014
|
-
replacementType = transformParamSpec(typeParam);
|
3015
|
-
if (replacementType !== typeParam) {
|
3016
|
-
specializationNeeded = true;
|
3017
|
-
}
|
3018
|
-
}
|
3019
|
-
else {
|
3020
|
-
if (!this._isTypeVarScopePending(typeParam.priv.scopeId)) {
|
3021
|
-
const transformedType = this.transformTypeVar(typeParam, recursionCount);
|
3022
|
-
replacementType = transformedType !== null && transformedType !== void 0 ? transformedType : typeParam;
|
3023
|
-
if (replacementType !== typeParam) {
|
3024
|
-
specializationNeeded = true;
|
3025
|
-
}
|
3026
|
-
else if (transformedType !== undefined && !classType.priv.typeArgs) {
|
3027
|
-
specializationNeeded = true;
|
3028
|
-
}
|
3029
|
-
}
|
2873
|
+
const typeArgs = (_a = classType.priv.typeArgs) !== null && _a !== void 0 ? _a : typeParams;
|
2874
|
+
newTypeArgs = typeArgs.map((oldTypeArgType) => {
|
2875
|
+
let newTypeArgType = this.apply(oldTypeArgType, recursionCount);
|
2876
|
+
if (newTypeArgType !== oldTypeArgType) {
|
2877
|
+
specializationNeeded = true;
|
2878
|
+
// If this was a TypeVarTuple that was part of a union
|
2879
|
+
// (e.g. Union[Unpack[Vs]]), expand the subtypes into a union here.
|
2880
|
+
if ((0, types_1.isTypeVar)(oldTypeArgType) && (0, types_1.isTypeVarTuple)(oldTypeArgType) && oldTypeArgType.priv.isInUnion) {
|
2881
|
+
newTypeArgType = _expandUnpackedTypeVarTupleUnion(newTypeArgType);
|
3030
2882
|
}
|
3031
|
-
|
3032
|
-
|
3033
|
-
}
|
2883
|
+
}
|
2884
|
+
return newTypeArgType;
|
2885
|
+
});
|
3034
2886
|
}
|
3035
|
-
this._isTransformingTypeArg = wasTransformingTypeArg;
|
3036
2887
|
// If specialization wasn't needed, don't allocate a new class.
|
3037
2888
|
if (!specializationNeeded) {
|
3038
2889
|
return classType;
|
@@ -3042,7 +2893,7 @@ class TypeVarTransformer {
|
|
3042
2893
|
/* includeSubclasses */ undefined, newTupleTypeArgs);
|
3043
2894
|
}
|
3044
2895
|
transformTypeVarsInFunctionType(sourceType, recursionCount) {
|
3045
|
-
return this.
|
2896
|
+
return this.doForEachConstraintSet(() => {
|
3046
2897
|
let functionType = sourceType;
|
3047
2898
|
const declaredReturnType = types_1.FunctionType.getEffectiveReturnType(functionType);
|
3048
2899
|
const specializedReturnType = declaredReturnType
|
@@ -3051,32 +2902,31 @@ class TypeVarTransformer {
|
|
3051
2902
|
let typesRequiredSpecialization = declaredReturnType !== specializedReturnType;
|
3052
2903
|
const specializedParams = {
|
3053
2904
|
parameterTypes: [],
|
3054
|
-
|
2905
|
+
parameterDefaultTypes: undefined,
|
3055
2906
|
returnType: specializedReturnType,
|
3056
2907
|
};
|
3057
2908
|
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(functionType);
|
3058
2909
|
if (paramSpec) {
|
3059
|
-
const paramSpecType = this.
|
2910
|
+
const paramSpecType = this.transformTypeVar(paramSpec, recursionCount);
|
3060
2911
|
if (paramSpecType) {
|
3061
|
-
const
|
3062
|
-
|
2912
|
+
const paramSpecValue = convertTypeToParamSpecValue(paramSpecType);
|
2913
|
+
const transformedParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(paramSpecValue);
|
2914
|
+
if (paramSpecValue.shared.parameters.length > 0 ||
|
3063
2915
|
!transformedParamSpec ||
|
3064
2916
|
!(0, types_1.isTypeSame)(paramSpec, transformedParamSpec)) {
|
3065
|
-
functionType = types_1.FunctionType.applyParamSpecValue(functionType,
|
2917
|
+
functionType = types_1.FunctionType.applyParamSpecValue(functionType, paramSpecValue);
|
3066
2918
|
}
|
3067
2919
|
}
|
3068
2920
|
}
|
3069
2921
|
let variadicParamIndex;
|
3070
2922
|
let variadicTypesToUnpack;
|
3071
2923
|
const specializedDefaultArgs = [];
|
3072
|
-
const wasTransformingTypeArg = this._isTransformingTypeArg;
|
3073
|
-
this._isTransformingTypeArg = true;
|
3074
2924
|
for (let i = 0; i < functionType.shared.parameters.length; i++) {
|
3075
|
-
const paramType = types_1.FunctionType.
|
2925
|
+
const paramType = types_1.FunctionType.getParamType(functionType, i);
|
3076
2926
|
const specializedType = this.apply(paramType, recursionCount);
|
3077
2927
|
specializedParams.parameterTypes.push(specializedType);
|
3078
2928
|
// Do we need to specialize the default argument type for this parameter?
|
3079
|
-
let defaultArgType = types_1.FunctionType.
|
2929
|
+
let defaultArgType = types_1.FunctionType.getParamDefaultType(functionType, i);
|
3080
2930
|
if (defaultArgType) {
|
3081
2931
|
const specializedArgType = this.apply(defaultArgType, recursionCount);
|
3082
2932
|
if (specializedArgType !== defaultArgType) {
|
@@ -3121,12 +2971,11 @@ class TypeVarTransformer {
|
|
3121
2971
|
functionType.priv.strippedFirstParamType = newStrippedType;
|
3122
2972
|
}
|
3123
2973
|
}
|
3124
|
-
this._isTransformingTypeArg = wasTransformingTypeArg;
|
3125
2974
|
if (!typesRequiredSpecialization) {
|
3126
2975
|
return functionType;
|
3127
2976
|
}
|
3128
2977
|
if (specializedDefaultArgs.some((t) => t !== undefined)) {
|
3129
|
-
specializedParams.
|
2978
|
+
specializedParams.parameterDefaultTypes = specializedDefaultArgs;
|
3130
2979
|
}
|
3131
2980
|
// If there was no unpacked variadic type variable, we're done.
|
3132
2981
|
if (!variadicTypesToUnpack) {
|
@@ -3158,7 +3007,7 @@ class TypeVarTransformer {
|
|
3158
3007
|
}
|
3159
3008
|
}
|
3160
3009
|
else {
|
3161
|
-
const param =
|
3010
|
+
const param = functionType.shared.parameters[index];
|
3162
3011
|
if ((0, types_1.isKeywordOnlySeparator)(param)) {
|
3163
3012
|
insertKeywordOnlySeparator = false;
|
3164
3013
|
}
|
@@ -3166,17 +3015,15 @@ class TypeVarTransformer {
|
|
3166
3015
|
insertKeywordOnlySeparator = false;
|
3167
3016
|
}
|
3168
3017
|
// Insert a keyword-only separator parameter if we previously
|
3169
|
-
// unpacked a
|
3018
|
+
// unpacked a TypeVarTuple.
|
3170
3019
|
if (param.category === 0 /* ParamCategory.Simple */ && param.name && insertKeywordOnlySeparator) {
|
3171
3020
|
types_1.FunctionType.addKeywordOnlyParamSeparator(newFunctionType);
|
3172
3021
|
insertKeywordOnlySeparator = false;
|
3173
3022
|
}
|
3174
|
-
param.type = paramType;
|
3175
|
-
if (param.name && types_1.FunctionParam.isNameSynthesized(param)) {
|
3176
|
-
param.name = `__p${newFunctionType.shared.parameters.length}`;
|
3177
|
-
}
|
3178
3023
|
if (param.category !== 0 /* ParamCategory.Simple */ || param.name || !swallowPositionOnlySeparator) {
|
3179
|
-
types_1.FunctionType.addParam(newFunctionType, param)
|
3024
|
+
types_1.FunctionType.addParam(newFunctionType, types_1.FunctionParam.create(param.category, paramType, param.flags, param.name && types_1.FunctionParam.isNameSynthesized(param)
|
3025
|
+
? `__p${newFunctionType.shared.parameters.length}`
|
3026
|
+
: param.name, types_1.FunctionType.getParamDefaultType(functionType, index)));
|
3180
3027
|
}
|
3181
3028
|
}
|
3182
3029
|
});
|
@@ -3188,18 +3035,7 @@ class TypeVarTransformer {
|
|
3188
3035
|
return !!typeVarScopeId && this._pendingTypeVarTransformations.has(typeVarScopeId);
|
3189
3036
|
}
|
3190
3037
|
}
|
3191
|
-
|
3192
|
-
class TypeVarAnyReplacer extends TypeVarTransformer {
|
3193
|
-
constructor() {
|
3194
|
-
super();
|
3195
|
-
}
|
3196
|
-
transformTypeVar(typeVar) {
|
3197
|
-
return types_1.AnyType.create();
|
3198
|
-
}
|
3199
|
-
transformParamSpec(paramSpec) {
|
3200
|
-
return types_1.ParamSpecType.getUnknown();
|
3201
|
-
}
|
3202
|
-
}
|
3038
|
+
exports.TypeVarTransformer = TypeVarTransformer;
|
3203
3039
|
// For a TypeVar with a default type, validates whether the default type is using
|
3204
3040
|
// any other TypeVars that are not currently in scope.
|
3205
3041
|
class TypeVarDefaultValidator extends TypeVarTransformer {
|
@@ -3210,18 +3046,11 @@ class TypeVarDefaultValidator extends TypeVarTransformer {
|
|
3210
3046
|
}
|
3211
3047
|
transformTypeVar(typeVar) {
|
3212
3048
|
const replacementType = this._liveTypeParams.find((param) => param.shared.name === typeVar.shared.name);
|
3213
|
-
if (!replacementType || (0, types_1.isParamSpec)(replacementType)) {
|
3049
|
+
if (!replacementType || (0, types_1.isParamSpec)(replacementType) !== (0, types_1.isParamSpec)(typeVar)) {
|
3214
3050
|
this._invalidTypeVars.add(typeVar.shared.name);
|
3215
3051
|
}
|
3216
3052
|
return types_1.UnknownType.create();
|
3217
3053
|
}
|
3218
|
-
transformParamSpec(paramSpec) {
|
3219
|
-
const replacementType = this._liveTypeParams.find((param) => param.shared.name === paramSpec.shared.name);
|
3220
|
-
if (!replacementType || !(0, types_1.isParamSpec)(replacementType)) {
|
3221
|
-
this._invalidTypeVars.add(paramSpec.shared.name);
|
3222
|
-
}
|
3223
|
-
return undefined;
|
3224
|
-
}
|
3225
3054
|
}
|
3226
3055
|
class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
3227
3056
|
constructor(_signatureTracker, _expressionOffset) {
|
@@ -3250,16 +3079,16 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
|
3250
3079
|
offsetIndex = existingSignature.expressionOffsets.length;
|
3251
3080
|
}
|
3252
3081
|
if (offsetIndex > 0) {
|
3253
|
-
const
|
3082
|
+
const solution = new constraintSolution_1.ConstraintSolution();
|
3254
3083
|
// Create new type variables with the same scope but with
|
3255
3084
|
// different (unique) names.
|
3256
3085
|
sourceType.shared.typeParams.forEach((typeParam) => {
|
3257
3086
|
if (typeParam.priv.scopeType === 1 /* TypeVarScopeType.Function */) {
|
3258
3087
|
const replacement = types_1.TypeVarType.cloneForNewName(typeParam, `${typeParam.shared.name}(${offsetIndex})`);
|
3259
|
-
|
3088
|
+
solution.setType(typeParam, replacement);
|
3260
3089
|
}
|
3261
3090
|
});
|
3262
|
-
updatedSourceType = applySolvedTypeVars(sourceType,
|
3091
|
+
updatedSourceType = applySolvedTypeVars(sourceType, solution);
|
3263
3092
|
(0, debug_1.assert)((0, types_1.isFunction)(updatedSourceType) || (0, types_1.isOverloadedFunction)(updatedSourceType));
|
3264
3093
|
}
|
3265
3094
|
}
|
@@ -3267,9 +3096,10 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
|
3267
3096
|
return updatedSourceType;
|
3268
3097
|
}
|
3269
3098
|
}
|
3270
|
-
// Replaces the
|
3271
|
-
//
|
3272
|
-
|
3099
|
+
// Replaces the free type vars within a type with their corresponding bound
|
3100
|
+
// type vars if they are in one of the specified scopes. If undefined is
|
3101
|
+
// passed for the scopeIds list, all free type vars are replaced.
|
3102
|
+
class BoundTypeVarTransform extends TypeVarTransformer {
|
3273
3103
|
constructor(_scopeIds) {
|
3274
3104
|
super();
|
3275
3105
|
this._scopeIds = _scopeIds;
|
@@ -3280,35 +3110,30 @@ class InternalScopeUpdateTransform extends TypeVarTransformer {
|
|
3280
3110
|
}
|
3281
3111
|
return undefined;
|
3282
3112
|
}
|
3283
|
-
transformParamSpec(paramSpec) {
|
3284
|
-
if (this._isTypeVarInScope(paramSpec)) {
|
3285
|
-
return convertTypeToParamSpecValue(this._replaceTypeVar(paramSpec));
|
3286
|
-
}
|
3287
|
-
return undefined;
|
3288
|
-
}
|
3289
3113
|
_isTypeVarInScope(typeVar) {
|
3290
|
-
|
3114
|
+
if (!typeVar.priv.scopeId) {
|
3115
|
+
return false;
|
3116
|
+
}
|
3117
|
+
// If no scopeIds were specified, transform all Type Vars.
|
3118
|
+
if (!this._scopeIds) {
|
3119
|
+
return true;
|
3120
|
+
}
|
3121
|
+
return this._scopeIds.includes(typeVar.priv.scopeId);
|
3291
3122
|
}
|
3292
3123
|
_replaceTypeVar(typeVar) {
|
3293
|
-
return types_1.TypeVarType.
|
3124
|
+
return types_1.TypeVarType.cloneAsBound(typeVar);
|
3294
3125
|
}
|
3295
3126
|
}
|
3296
|
-
// Replaces the
|
3297
|
-
//
|
3298
|
-
class
|
3127
|
+
// Replaces the bound type vars within a type with their corresponding
|
3128
|
+
// free type vars.
|
3129
|
+
class FreeTypeVarTransform extends TypeVarTransformer {
|
3299
3130
|
constructor(_scopeIds) {
|
3300
3131
|
super();
|
3301
3132
|
this._scopeIds = _scopeIds;
|
3302
3133
|
}
|
3303
3134
|
transformTypeVar(typeVar) {
|
3304
|
-
if (typeVar.priv.
|
3305
|
-
return typeVar.priv.
|
3306
|
-
}
|
3307
|
-
return undefined;
|
3308
|
-
}
|
3309
|
-
transformParamSpec(paramSpec) {
|
3310
|
-
if (paramSpec.priv.externalTypeVar && this._isTypeVarInScope(paramSpec.priv.externalTypeVar)) {
|
3311
|
-
return convertTypeToParamSpecValue(paramSpec.priv.externalTypeVar);
|
3135
|
+
if (typeVar.priv.freeTypeVar && this._isTypeVarInScope(typeVar.priv.freeTypeVar)) {
|
3136
|
+
return typeVar.priv.freeTypeVar;
|
3312
3137
|
}
|
3313
3138
|
return undefined;
|
3314
3139
|
}
|
@@ -3322,144 +3147,120 @@ class ExternalScopeUpdateTransform extends TypeVarTransformer {
|
|
3322
3147
|
// Specializes a (potentially generic) type by substituting
|
3323
3148
|
// type variables from a type var map.
|
3324
3149
|
class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
3325
|
-
constructor(
|
3150
|
+
constructor(_solution, _options) {
|
3326
3151
|
super();
|
3327
|
-
this.
|
3152
|
+
this._solution = _solution;
|
3328
3153
|
this._options = _options;
|
3329
3154
|
this._isSolvingDefaultType = false;
|
3330
3155
|
}
|
3331
3156
|
transformTypeVar(typeVar, recursionCount) {
|
3332
|
-
var _a, _b;
|
3333
|
-
const solutionSet = this.
|
3334
|
-
// If
|
3335
|
-
|
3336
|
-
|
3337
|
-
let replacement = solutionSet.getTypeVarType(typeVar, !!this._options.useLowerBoundOnly);
|
3338
|
-
// If there was no lower bound but there is an upper bound that
|
3339
|
-
// contains literals or a TypeVar, we'll use the upper bound even if
|
3340
|
-
// "useLowerBoundOnly" is specified.
|
3341
|
-
if (!replacement && this._options.useLowerBoundOnly) {
|
3342
|
-
const wideType = solutionSet.getTypeVarType(typeVar);
|
3343
|
-
if (wideType) {
|
3344
|
-
if ((0, types_1.isTypeVar)(wideType) || containsLiteralType(wideType, /* includeTypeArgs */ true)) {
|
3345
|
-
replacement = wideType;
|
3346
|
-
}
|
3347
|
-
}
|
3348
|
-
}
|
3157
|
+
var _a, _b, _c;
|
3158
|
+
const solutionSet = this._solution.getSolutionSet((_a = this._activeConstraintSetIndex) !== null && _a !== void 0 ? _a : 0);
|
3159
|
+
// If we're solving a default type, handle type variables with no scope ID.
|
3160
|
+
if (this._isSolvingDefaultType && !typeVar.priv.scopeId) {
|
3161
|
+
const replacement = this._getReplacementForDefaultByName(typeVar, solutionSet);
|
3349
3162
|
if (replacement) {
|
3350
|
-
|
3351
|
-
|
3352
|
-
|
3353
|
-
|
3354
|
-
|
3355
|
-
|
3356
|
-
|
3357
|
-
|
3358
|
-
|
3359
|
-
|
3360
|
-
|
3163
|
+
return replacement;
|
3164
|
+
}
|
3165
|
+
if (typeVar.shared.isDefaultExplicit) {
|
3166
|
+
return this.apply(typeVar.shared.defaultType, recursionCount);
|
3167
|
+
}
|
3168
|
+
return types_1.UnknownType.create();
|
3169
|
+
}
|
3170
|
+
if (!this._shouldReplaceTypeVar(typeVar)) {
|
3171
|
+
return undefined;
|
3172
|
+
}
|
3173
|
+
let replacement = solutionSet.getType(typeVar);
|
3174
|
+
if (replacement) {
|
3175
|
+
// No more processing is needed for ParamSpecs.
|
3176
|
+
if ((0, types_1.isParamSpec)(typeVar)) {
|
3177
|
+
return replacement;
|
3178
|
+
}
|
3179
|
+
if (types_1.TypeBase.isInstantiable(typeVar)) {
|
3180
|
+
if ((0, types_1.isAnyOrUnknown)(replacement) &&
|
3181
|
+
this._options.typeClassType &&
|
3182
|
+
(0, types_1.isInstantiableClass)(this._options.typeClassType)) {
|
3183
|
+
replacement = types_1.ClassType.specialize(types_1.ClassType.cloneAsInstance(this._options.typeClassType), [
|
3184
|
+
replacement,
|
3185
|
+
]);
|
3361
3186
|
}
|
3362
3187
|
else {
|
3363
|
-
|
3364
|
-
|
3365
|
-
|
3366
|
-
|
3367
|
-
|
3368
|
-
|
3369
|
-
|
3370
|
-
|
3371
|
-
|
3372
|
-
|
3373
|
-
|
3374
|
-
|
3375
|
-
|
3376
|
-
|
3377
|
-
|
3378
|
-
|
3379
|
-
|
3188
|
+
replacement = convertToInstantiable(replacement, /* includeSubclasses */ false);
|
3189
|
+
}
|
3190
|
+
}
|
3191
|
+
else {
|
3192
|
+
// If the TypeVar is not instantiable (i.e. not a type[T]), then
|
3193
|
+
// it represents an instance of a type. If the replacement includes
|
3194
|
+
// a generic class that has not been specialized, specialize it
|
3195
|
+
// now with default type arguments.
|
3196
|
+
replacement = mapSubtypes(replacement, (subtype) => {
|
3197
|
+
if ((0, types_1.isClassInstance)(subtype)) {
|
3198
|
+
// If the includeSubclasses wasn't set, force it to be set by
|
3199
|
+
// converting to/from an instantiable.
|
3200
|
+
if (!subtype.priv.includeSubclasses) {
|
3201
|
+
subtype = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneAsInstantiable(subtype));
|
3202
|
+
}
|
3203
|
+
if (subtype.shared.typeParams && !subtype.priv.typeArgs) {
|
3204
|
+
if (this._options.replaceUnsolved) {
|
3205
|
+
return this._options.replaceUnsolved.useUnknown
|
3206
|
+
? specializeWithUnknownTypeArgs(subtype, this._options.replaceUnsolved.tupleClassType)
|
3207
|
+
: specializeWithDefaultTypeArgs(subtype);
|
3380
3208
|
}
|
3381
3209
|
}
|
3382
|
-
|
3383
|
-
|
3384
|
-
}
|
3385
|
-
if ((0, types_1.isTypeVarTuple)(replacement) && (0, types_1.isTypeVarTuple)(typeVar) && typeVar.priv.isVariadicUnpacked) {
|
3386
|
-
return types_1.TypeVarType.cloneForUnpacked(replacement, typeVar.priv.isVariadicInUnion);
|
3387
|
-
}
|
3388
|
-
// If this isn't a variadic typeVar, combine all of the tuple
|
3389
|
-
// type args into a common type.
|
3390
|
-
if (!(0, types_1.isTypeVarTuple)(typeVar) &&
|
3391
|
-
(0, types_1.isClassInstance)(replacement) &&
|
3392
|
-
replacement.priv.tupleTypeArgs &&
|
3393
|
-
replacement.priv.isUnpacked) {
|
3394
|
-
replacement = combineTupleTypeArgs(replacement.priv.tupleTypeArgs);
|
3395
|
-
}
|
3396
|
-
if (!(0, types_1.isTypeVar)(replacement) ||
|
3397
|
-
!replacement.priv.isInScopePlaceholder ||
|
3398
|
-
!this._options.unknownIfNotFound) {
|
3399
|
-
return replacement;
|
3400
|
-
}
|
3210
|
+
}
|
3211
|
+
return subtype;
|
3212
|
+
});
|
3401
3213
|
}
|
3402
|
-
|
3403
|
-
|
3404
|
-
// default or Unknown.
|
3405
|
-
let useDefaultOrUnknown = false;
|
3406
|
-
if (this._options.unknownIfNotFound) {
|
3407
|
-
const exemptTypeVars = (_b = this._options.unknownExemptTypeVars) !== null && _b !== void 0 ? _b : [];
|
3408
|
-
const typeVarInstance = types_1.TypeBase.isInstance(typeVar) ? typeVar : types_1.TypeVarType.cloneAsInstance(typeVar);
|
3409
|
-
if (!exemptTypeVars.some((t) => (0, types_1.isTypeSame)(t, typeVarInstance))) {
|
3410
|
-
useDefaultOrUnknown = true;
|
3411
|
-
}
|
3214
|
+
if ((0, types_1.isTypeVarTuple)(replacement) && (0, types_1.isTypeVarTuple)(typeVar) && typeVar.priv.isUnpacked) {
|
3215
|
+
return types_1.TypeVarType.cloneForUnpacked(replacement, typeVar.priv.isInUnion);
|
3412
3216
|
}
|
3413
|
-
|
3414
|
-
|
3217
|
+
// If this isn't a TypeVarTuple, combine all of the tuple
|
3218
|
+
// type args into a common type.
|
3219
|
+
if (!(0, types_1.isTypeVarTuple)(typeVar) &&
|
3220
|
+
(0, types_1.isClassInstance)(replacement) &&
|
3221
|
+
replacement.priv.tupleTypeArgs &&
|
3222
|
+
replacement.priv.isUnpacked) {
|
3223
|
+
replacement = combineTupleTypeArgs(replacement.priv.tupleTypeArgs);
|
3415
3224
|
}
|
3416
|
-
if (
|
3417
|
-
|
3418
|
-
if (typeVar.shared.isDefaultExplicit && !this._options.useUnknownOverDefault) {
|
3419
|
-
return this._solveDefaultType(typeVar, recursionCount);
|
3420
|
-
}
|
3421
|
-
return getUnknownForTypeVar(typeVar, this._options.tupleClassType);
|
3225
|
+
if (!(0, types_1.isTypeVar)(replacement) || !types_1.TypeVarType.isUnification(replacement) || !this._options.replaceUnsolved) {
|
3226
|
+
return replacement;
|
3422
3227
|
}
|
3423
3228
|
}
|
3424
|
-
|
3425
|
-
|
3426
|
-
const replacementEntry = solutionSet
|
3427
|
-
.getTypeVars()
|
3428
|
-
.find((entry) => entry.typeVar.shared.name === typeVar.shared.name);
|
3429
|
-
if (replacementEntry) {
|
3430
|
-
return solutionSet.getTypeVarType(replacementEntry.typeVar);
|
3431
|
-
}
|
3432
|
-
if (typeVar.shared.isDefaultExplicit) {
|
3433
|
-
return this.apply(typeVar.shared.defaultType, recursionCount);
|
3434
|
-
}
|
3435
|
-
return types_1.UnknownType.create();
|
3229
|
+
if (!this._shouldReplaceUnsolvedTypeVar(typeVar)) {
|
3230
|
+
return undefined;
|
3436
3231
|
}
|
3437
|
-
|
3232
|
+
// Use the default value if there is one.
|
3233
|
+
if (typeVar.shared.isDefaultExplicit && !((_b = this._options.replaceUnsolved) === null || _b === void 0 ? void 0 : _b.useUnknown)) {
|
3234
|
+
return this._solveDefaultType(typeVar, recursionCount);
|
3235
|
+
}
|
3236
|
+
return getUnknownForTypeVar(typeVar, (_c = this._options.replaceUnsolved) === null || _c === void 0 ? void 0 : _c.tupleClassType);
|
3438
3237
|
}
|
3439
3238
|
transformUnionSubtype(preTransform, postTransform) {
|
3440
|
-
var _a;
|
3239
|
+
var _a, _b;
|
3441
3240
|
// If a union contains unsolved TypeVars within scope, eliminate them
|
3442
3241
|
// unless this results in an empty union. This elimination is needed
|
3443
3242
|
// in cases where TypeVars can go unsolved due to unions in parameter
|
3444
3243
|
// annotations, like this:
|
3445
3244
|
// def test(x: Union[str, T]) -> Union[str, T]
|
3446
|
-
if (this._options.eliminateUnsolvedInUnions) {
|
3245
|
+
if ((_a = this._options.replaceUnsolved) === null || _a === void 0 ? void 0 : _a.eliminateUnsolvedInUnions) {
|
3447
3246
|
if ((0, types_1.isTypeVar)(preTransform) &&
|
3448
|
-
preTransform
|
3449
|
-
this.
|
3450
|
-
const solutionSet = this.
|
3451
|
-
const typeVarType = solutionSet.
|
3247
|
+
this._shouldReplaceTypeVar(preTransform) &&
|
3248
|
+
this._shouldReplaceUnsolvedTypeVar(preTransform)) {
|
3249
|
+
const solutionSet = this._solution.getSolutionSet((_b = this._activeConstraintSetIndex) !== null && _b !== void 0 ? _b : 0);
|
3250
|
+
const typeVarType = solutionSet.getType(preTransform);
|
3452
3251
|
// Did the TypeVar remain unsolved?
|
3453
|
-
if (!typeVarType || ((0, types_1.isTypeVar)(typeVarType) &&
|
3252
|
+
if (!typeVarType || ((0, types_1.isTypeVar)(typeVarType) && types_1.TypeVarType.isUnification(typeVarType))) {
|
3454
3253
|
// If the TypeVar was not transformed, then it was unsolved,
|
3455
3254
|
// and we'll eliminate it.
|
3456
3255
|
if (preTransform === postTransform) {
|
3457
3256
|
return undefined;
|
3458
3257
|
}
|
3459
|
-
// If
|
3258
|
+
// If useDefaultForUnsolved or useUnknownForUnsolved is true, the postTransform type will
|
3460
3259
|
// be Unknown, which we want to eliminate.
|
3461
|
-
if (
|
3462
|
-
|
3260
|
+
if (this._options.replaceUnsolved) {
|
3261
|
+
if ((0, types_1.isUnknown)(postTransform)) {
|
3262
|
+
return undefined;
|
3263
|
+
}
|
3463
3264
|
}
|
3464
3265
|
}
|
3465
3266
|
}
|
@@ -3468,84 +3269,41 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3468
3269
|
}
|
3469
3270
|
transformTupleTypeVar(typeVar) {
|
3470
3271
|
var _a;
|
3471
|
-
if (!
|
3272
|
+
if (!this._shouldReplaceTypeVar(typeVar)) {
|
3472
3273
|
const defaultType = typeVar.shared.defaultType;
|
3473
3274
|
if (typeVar.shared.isDefaultExplicit && (0, types_1.isClassInstance)(defaultType) && defaultType.priv.tupleTypeArgs) {
|
3474
3275
|
return defaultType.priv.tupleTypeArgs;
|
3475
3276
|
}
|
3476
3277
|
return undefined;
|
3477
3278
|
}
|
3478
|
-
const solutionSet = this.
|
3479
|
-
const value = solutionSet.
|
3279
|
+
const solutionSet = this._solution.getSolutionSet((_a = this._activeConstraintSetIndex) !== null && _a !== void 0 ? _a : 0);
|
3280
|
+
const value = solutionSet.getType(typeVar);
|
3480
3281
|
if (value && (0, types_1.isClassInstance)(value) && value.priv.tupleTypeArgs && (0, types_1.isUnpackedClass)(value)) {
|
3481
3282
|
return value.priv.tupleTypeArgs;
|
3482
3283
|
}
|
3483
3284
|
return undefined;
|
3484
3285
|
}
|
3485
|
-
transformParamSpec(paramSpec, recursionCount) {
|
3486
|
-
var _a, _b;
|
3487
|
-
const solutionSet = this._typeVarContext.getSolutionSet((_a = this._activeSolutionSetIndex) !== null && _a !== void 0 ? _a : 0);
|
3488
|
-
// If we're solving a default type, handle param specs with no scope ID.
|
3489
|
-
if (this._isSolvingDefaultType && !paramSpec.priv.scopeId) {
|
3490
|
-
const replacementEntry = solutionSet
|
3491
|
-
.getTypeVars()
|
3492
|
-
.find((entry) => entry.typeVar.shared.name === paramSpec.shared.name);
|
3493
|
-
if (replacementEntry && (0, types_1.isParamSpec)(replacementEntry.typeVar)) {
|
3494
|
-
return solutionSet.getTypeVarType(replacementEntry.typeVar);
|
3495
|
-
}
|
3496
|
-
if (paramSpec.shared.isDefaultExplicit) {
|
3497
|
-
return convertTypeToParamSpecValue(this.apply(paramSpec.shared.defaultType, recursionCount));
|
3498
|
-
}
|
3499
|
-
return types_1.ParamSpecType.getUnknown();
|
3500
|
-
}
|
3501
|
-
if (!paramSpec.priv.scopeId || !this._typeVarContext.hasSolveForScope(paramSpec.priv.scopeId)) {
|
3502
|
-
return undefined;
|
3503
|
-
}
|
3504
|
-
const transformedParamSpec = solutionSet.getTypeVarType(paramSpec);
|
3505
|
-
if (transformedParamSpec) {
|
3506
|
-
return transformedParamSpec;
|
3507
|
-
}
|
3508
|
-
let useDefaultOrUnknown = false;
|
3509
|
-
if (this._options.unknownIfNotFound) {
|
3510
|
-
const exemptTypeVars = (_b = this._options.unknownExemptTypeVars) !== null && _b !== void 0 ? _b : [];
|
3511
|
-
if (!exemptTypeVars.some((t) => (0, types_1.isTypeSame)(t, paramSpec, { ignoreTypeFlags: true }))) {
|
3512
|
-
useDefaultOrUnknown = true;
|
3513
|
-
}
|
3514
|
-
}
|
3515
|
-
else if (this._options.applyInScopePlaceholders && paramSpec.priv.isInScopePlaceholder) {
|
3516
|
-
useDefaultOrUnknown = true;
|
3517
|
-
}
|
3518
|
-
if (useDefaultOrUnknown) {
|
3519
|
-
// Use the default value if there is one.
|
3520
|
-
if (paramSpec.shared.isDefaultExplicit && !this._options.useUnknownOverDefault) {
|
3521
|
-
return convertTypeToParamSpecValue(this._solveDefaultType(paramSpec, recursionCount));
|
3522
|
-
}
|
3523
|
-
// Convert to the ParamSpec equivalent of "Unknown".
|
3524
|
-
return types_1.ParamSpecType.getUnknown();
|
3525
|
-
}
|
3526
|
-
return undefined;
|
3527
|
-
}
|
3528
3286
|
transformConditionalType(type, recursionCount) {
|
3529
3287
|
var _a, _b, _c, _d;
|
3530
3288
|
if (!((_a = type.props) === null || _a === void 0 ? void 0 : _a.condition)) {
|
3531
3289
|
return type;
|
3532
3290
|
}
|
3533
|
-
const solutionSet = this.
|
3291
|
+
const solutionSet = this._solution.getSolutionSet((_b = this._activeConstraintSetIndex) !== null && _b !== void 0 ? _b : 0);
|
3534
3292
|
for (const condition of type.props.condition) {
|
3535
3293
|
// This doesn't apply to bound type variables.
|
3536
|
-
if (condition.typeVar
|
3294
|
+
if (!types_1.TypeVarType.hasConstraints(condition.typeVar)) {
|
3537
3295
|
continue;
|
3538
3296
|
}
|
3539
|
-
const conditionTypeVar = (_d = (_c = condition.typeVar.priv) === null || _c === void 0 ? void 0 : _c.
|
3540
|
-
const
|
3541
|
-
if (!
|
3297
|
+
const conditionTypeVar = (_d = (_c = condition.typeVar.priv) === null || _c === void 0 ? void 0 : _c.freeTypeVar) !== null && _d !== void 0 ? _d : condition.typeVar;
|
3298
|
+
const replacement = solutionSet.getType(conditionTypeVar);
|
3299
|
+
if (!replacement || condition.constraintIndex >= conditionTypeVar.shared.constraints.length) {
|
3542
3300
|
continue;
|
3543
3301
|
}
|
3544
|
-
const value = solutionSet.
|
3302
|
+
const value = solutionSet.getType(conditionTypeVar);
|
3545
3303
|
if (!value) {
|
3546
3304
|
continue;
|
3547
3305
|
}
|
3548
|
-
const constraintType =
|
3306
|
+
const constraintType = conditionTypeVar.shared.constraints[condition.constraintIndex];
|
3549
3307
|
// If this violates the constraint, substitute a Never type.
|
3550
3308
|
if (!(0, types_1.isTypeSame)(constraintType, value)) {
|
3551
3309
|
return types_1.NeverType.createNever();
|
@@ -3553,19 +3311,19 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3553
3311
|
}
|
3554
3312
|
return type;
|
3555
3313
|
}
|
3556
|
-
|
3557
|
-
const
|
3314
|
+
doForEachConstraintSet(callback) {
|
3315
|
+
const solutionSets = this._solution.getSolutionSets();
|
3558
3316
|
// Handle the common case where there are not multiple signature contexts.
|
3559
|
-
if (
|
3317
|
+
if (solutionSets.length <= 1) {
|
3560
3318
|
return callback();
|
3561
3319
|
}
|
3562
3320
|
// Loop through all of the signature contexts in the type var context
|
3563
3321
|
// to create an overload type.
|
3564
|
-
const overloadTypes =
|
3565
|
-
this.
|
3322
|
+
const overloadTypes = solutionSets.map((_, index) => {
|
3323
|
+
this._activeConstraintSetIndex = index;
|
3566
3324
|
return callback();
|
3567
3325
|
});
|
3568
|
-
this.
|
3326
|
+
this._activeConstraintSetIndex = undefined;
|
3569
3327
|
const filteredOverloads = [];
|
3570
3328
|
doForEachSubtype((0, types_1.combineTypes)(overloadTypes), (subtype) => {
|
3571
3329
|
(0, debug_1.assert)((0, types_1.isFunction)(subtype));
|
@@ -3577,6 +3335,50 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3577
3335
|
}
|
3578
3336
|
return types_1.OverloadedFunctionType.create(filteredOverloads);
|
3579
3337
|
}
|
3338
|
+
// Handle the case where we need the default replacement value for a typeVar
|
3339
|
+
// that has no scope and therefore doesn't have an assigned scopeID. We'll
|
3340
|
+
// look it up by name in the solution set. This is a bit hacky because there
|
3341
|
+
// could be multiple typeVars with the same name, but we'll assume that this
|
3342
|
+
// won't happen.
|
3343
|
+
_getReplacementForDefaultByName(typeVar, solutionSet) {
|
3344
|
+
let replacementValue;
|
3345
|
+
const partialScopeId = `${typeVar.shared.name}.`;
|
3346
|
+
solutionSet.doForEachTypeVar((value, typeVarId) => {
|
3347
|
+
if (typeVarId.startsWith(partialScopeId)) {
|
3348
|
+
replacementValue = value;
|
3349
|
+
}
|
3350
|
+
});
|
3351
|
+
return replacementValue;
|
3352
|
+
}
|
3353
|
+
_shouldReplaceTypeVar(typeVar) {
|
3354
|
+
if (!typeVar.priv.scopeId || types_1.TypeVarType.isBound(typeVar)) {
|
3355
|
+
return false;
|
3356
|
+
}
|
3357
|
+
return true;
|
3358
|
+
}
|
3359
|
+
_shouldReplaceUnsolvedTypeVar(typeVar) {
|
3360
|
+
var _a;
|
3361
|
+
// Never replace nested TypeVars with unknown.
|
3362
|
+
if (this.pendingTypeVarTransformations.size > 0) {
|
3363
|
+
return false;
|
3364
|
+
}
|
3365
|
+
if (!typeVar.priv.scopeId) {
|
3366
|
+
return false;
|
3367
|
+
}
|
3368
|
+
if (!this._options.replaceUnsolved) {
|
3369
|
+
return false;
|
3370
|
+
}
|
3371
|
+
if (!this._options.replaceUnsolved.scopeIds.includes(typeVar.priv.scopeId)) {
|
3372
|
+
return false;
|
3373
|
+
}
|
3374
|
+
const exemptTypeVars = (_a = this._options.replaceUnsolved) === null || _a === void 0 ? void 0 : _a.unsolvedExemptTypeVars;
|
3375
|
+
if (exemptTypeVars) {
|
3376
|
+
if (exemptTypeVars.some((t) => (0, types_1.isTypeSame)(t, typeVar, { ignoreTypeFlags: true }))) {
|
3377
|
+
return false;
|
3378
|
+
}
|
3379
|
+
}
|
3380
|
+
return true;
|
3381
|
+
}
|
3580
3382
|
_solveDefaultType(typeVar, recursionCount) {
|
3581
3383
|
const defaultType = typeVar.shared.defaultType;
|
3582
3384
|
const wasSolvingDefaultType = this._isSolvingDefaultType;
|
@@ -3594,46 +3396,12 @@ class ExpectedTypeTransformer extends TypeVarTransformer {
|
|
3594
3396
|
}
|
3595
3397
|
transformTypeVar(typeVar) {
|
3596
3398
|
if (!this._isTypeVarLive(typeVar)) {
|
3597
|
-
return types_1.TypeVarType.
|
3598
|
-
}
|
3599
|
-
return undefined;
|
3600
|
-
}
|
3601
|
-
transformParamSpec(paramSpec) {
|
3602
|
-
if (!this._isTypeVarLive(paramSpec)) {
|
3603
|
-
return convertTypeToParamSpecValue(types_1.TypeVarType.cloneAsInScopePlaceholder(paramSpec, this._usageOffset));
|
3399
|
+
return types_1.TypeVarType.cloneAsUnificationVar(typeVar, this._usageOffset);
|
3604
3400
|
}
|
3605
3401
|
return undefined;
|
3606
3402
|
}
|
3607
3403
|
_isTypeVarLive(typeVar) {
|
3608
|
-
return this._liveTypeVarScopes.some((scopeId) => { var _a; return typeVar.priv.scopeId === scopeId || ((_a = typeVar.priv.
|
3609
|
-
}
|
3610
|
-
}
|
3611
|
-
class InScopePlaceholderTransformer extends TypeVarTransformer {
|
3612
|
-
constructor(_solutionSet) {
|
3613
|
-
super();
|
3614
|
-
this._solutionSet = _solutionSet;
|
3404
|
+
return this._liveTypeVarScopes.some((scopeId) => { var _a; return typeVar.priv.scopeId === scopeId || ((_a = typeVar.priv.freeTypeVar) === null || _a === void 0 ? void 0 : _a.priv.scopeId) === scopeId; });
|
3615
3405
|
}
|
3616
|
-
transformTypeVar(typeVar) {
|
3617
|
-
var _a;
|
3618
|
-
if (typeVar.priv.isInScopePlaceholder) {
|
3619
|
-
return (_a = this._solutionSet.getTypeVarType(typeVar)) !== null && _a !== void 0 ? _a : typeVar;
|
3620
|
-
}
|
3621
|
-
return undefined;
|
3622
|
-
}
|
3623
|
-
transformParamSpec(paramSpec) {
|
3624
|
-
if (paramSpec.priv.isInScopePlaceholder) {
|
3625
|
-
return this._solutionSet.getTypeVarType(paramSpec);
|
3626
|
-
}
|
3627
|
-
return undefined;
|
3628
|
-
}
|
3629
|
-
}
|
3630
|
-
function applyInScopePlaceholdersToType(type, solutionSet) {
|
3631
|
-
// Handle the common case where there are no in-scope placeholders.
|
3632
|
-
// No more work is required in this case.
|
3633
|
-
if (!solutionSet.getTypeVars().some((entry) => entry.typeVar.priv.isInScopePlaceholder)) {
|
3634
|
-
return type;
|
3635
|
-
}
|
3636
|
-
const transformer = new InScopePlaceholderTransformer(solutionSet);
|
3637
|
-
return transformer.apply(type, 0);
|
3638
3406
|
}
|
3639
3407
|
//# sourceMappingURL=typeUtils.js.map
|