@zzzen/pyright-internal 1.2.0-dev.20221218 → 1.2.0-dev.20230101
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 +8 -3
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +16 -1
- package/dist/analyzer/codeFlowEngine.js +41 -20
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +133 -53
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/patternMatching.js +3 -2
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +11 -5
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +9 -0
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +1 -1
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceFile.js +2 -1
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/testWalker.js +5 -0
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/typeCacheUtils.d.ts +28 -0
- package/dist/analyzer/{typeCache.js → typeCacheUtils.js} +8 -14
- package/dist/analyzer/typeCacheUtils.js.map +1 -0
- package/dist/analyzer/typeEvaluator.js +495 -359
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeGuards.js +1 -2
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +14 -6
- package/dist/analyzer/typeUtils.js +291 -144
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +10 -17
- package/dist/analyzer/typeVarContext.js +58 -39
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/types.d.ts +4 -12
- package/dist/analyzer/types.js +22 -22
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +2 -2
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/localization/localize.d.ts +18 -3
- package/dist/localization/localize.js +7 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +8 -2
- package/dist/parser/parseNodes.d.ts +1 -0
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.js +38 -16
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +4 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +10 -2
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +21 -3
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +4 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +49 -7
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/package.json +2 -2
- package/dist/analyzer/typeCache.d.ts +0 -40
- package/dist/analyzer/typeCache.js.map +0 -1
@@ -8,8 +8,8 @@
|
|
8
8
|
* Collection of functions that operate on Type objects.
|
9
9
|
*/
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
11
|
-
exports.
|
12
|
-
exports.convertParamSpecValueToType = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgumentCompatible = exports.requiresSpecialization = exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.removeParamSpecVariadicsFromFunction = exports.removeParamSpecVariadicsFromSignature = exports.specializeTupleClass = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsUnknown = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.specializeForBaseClass = void 0;
|
11
|
+
exports.setTypeArgumentsRecursive = exports.specializeClassType = exports.isTypeVarLimitedToCallable = exports.getTypeVarArgumentsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = exports.lookUpClassMember = exports.lookUpObjectMember = exports.getProtocolSymbols = exports.transformExpectedTypeForConstructor = exports.validateTypeVarDefault = exports.applySolvedTypeVars = exports.populateTypeVarContextForSelfType = exports.partiallySpecializeType = exports.isUnboundedTupleClass = exports.isTupleClass = exports.isMaybeDescriptorInstance = exports.isDescriptorInstance = exports.isProperty = exports.isEllipsisType = exports.getUnionSubtypeCount = exports.getLiteralTypeClassName = exports.containsLiteralType = exports.containsType = exports.isLiteralTypeOrUnion = exports.isLiteralType = exports.getSpecializedTupleType = exports.getTypeVarScopeId = exports.transformPossibleRecursiveTypeAlias = exports.isTypeAliasRecursive = exports.isTypeAliasPlaceholder = exports.getTypeCondition = exports.addConditionToType = exports.getFullNameOfType = exports.derivesFromAnyOrUnknown = exports.isUnionableType = exports.preserveUnknown = exports.areTypesSame = exports.doForEachSubtype = exports.sortTypes = exports.mapSubtypes = exports.isIncompleteUnknown = exports.isOptionalType = exports.getParameterListDetails = exports.ParameterSource = exports.AssignTypeFlags = exports.ClassIteratorFlags = exports.ClassMemberLookupFlags = void 0;
|
12
|
+
exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgumentCompatible = exports.requiresSpecialization = exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.removeParamSpecVariadicsFromFunction = exports.removeParamSpecVariadicsFromSignature = exports.specializeTupleClass = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsUnknown = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.specializeForBaseClass = exports.buildTypeVarContext = exports.buildTypeVarContextFromSpecializedClass = void 0;
|
13
13
|
const collectionUtils_1 = require("../common/collectionUtils");
|
14
14
|
const debug_1 = require("../common/debug");
|
15
15
|
const symbol_1 = require("./symbol");
|
@@ -66,9 +66,10 @@ var AssignTypeFlags;
|
|
66
66
|
// the types are contravariant. Perform type var matching
|
67
67
|
// on dest type vars rather than source type var.
|
68
68
|
AssignTypeFlags[AssignTypeFlags["ReverseTypeVarMatching"] = 2] = "ReverseTypeVarMatching";
|
69
|
-
//
|
70
|
-
//
|
71
|
-
|
69
|
+
// We're comparing type compatibility of two distinct recursive types.
|
70
|
+
// This has the potential of recursing infinitely. This flag allows us
|
71
|
+
// to detect the recursion after the first level of checking.
|
72
|
+
AssignTypeFlags[AssignTypeFlags["SkipRecursiveTypeCheck"] = 4] = "SkipRecursiveTypeCheck";
|
72
73
|
// Normally type vars are treated as variables that need to
|
73
74
|
// be "solved". If this flag is set, they are treated as types
|
74
75
|
// that must match. It is used for overload consistency checking.
|
@@ -98,10 +99,6 @@ var AssignTypeFlags;
|
|
98
99
|
// so TypeVars should match the specified type exactly rather than
|
99
100
|
// employing narrowing or widening, and don't strip literals.
|
100
101
|
AssignTypeFlags[AssignTypeFlags["PopulatingExpectedType"] = 1024] = "PopulatingExpectedType";
|
101
|
-
// We're comparing type compatibility of two distinct recursive types.
|
102
|
-
// This has the potential of recursing infinitely. This flag allows us
|
103
|
-
// to detect the recursion after the first level of checking.
|
104
|
-
AssignTypeFlags[AssignTypeFlags["SkipRecursiveTypeCheck"] = 2048] = "SkipRecursiveTypeCheck";
|
105
102
|
})(AssignTypeFlags = exports.AssignTypeFlags || (exports.AssignTypeFlags = {}));
|
106
103
|
var ParameterSource;
|
107
104
|
(function (ParameterSource) {
|
@@ -825,10 +822,7 @@ function partiallySpecializeType(type, contextClassType, selfClass, typeClassTyp
|
|
825
822
|
if (selfClass) {
|
826
823
|
populateTypeVarContextForSelfType(typeVarContext, contextClassType, selfClass);
|
827
824
|
}
|
828
|
-
return applySolvedTypeVars(type, typeVarContext,
|
829
|
-
/* unknownIfNotFound */ undefined,
|
830
|
-
/* useNarrowBoundOnly */ undefined,
|
831
|
-
/* eliminateUnsolvedInUnions */ undefined, typeClassType);
|
825
|
+
return applySolvedTypeVars(type, typeVarContext, { typeClassType });
|
832
826
|
}
|
833
827
|
exports.partiallySpecializeType = partiallySpecializeType;
|
834
828
|
function populateTypeVarContextForSelfType(typeVarContext, contextClassType, selfClass) {
|
@@ -838,15 +832,26 @@ function populateTypeVarContextForSelfType(typeVarContext, contextClassType, sel
|
|
838
832
|
exports.populateTypeVarContextForSelfType = populateTypeVarContextForSelfType;
|
839
833
|
// Specializes a (potentially generic) type by substituting
|
840
834
|
// type variables from a type var map.
|
841
|
-
function applySolvedTypeVars(type, typeVarContext,
|
835
|
+
function applySolvedTypeVars(type, typeVarContext, options = {}) {
|
842
836
|
// Use a shortcut if the typeVarContext is empty and no transform is necessary.
|
843
|
-
if (typeVarContext.isEmpty() && !unknownIfNotFound && !eliminateUnsolvedInUnions) {
|
837
|
+
if (typeVarContext.isEmpty() && !options.unknownIfNotFound && !options.eliminateUnsolvedInUnions) {
|
844
838
|
return type;
|
845
839
|
}
|
846
|
-
const transformer = new ApplySolvedTypeVarsTransformer(typeVarContext,
|
847
|
-
return transformer.apply(type);
|
840
|
+
const transformer = new ApplySolvedTypeVarsTransformer(typeVarContext, options);
|
841
|
+
return transformer.apply(type, 0);
|
848
842
|
}
|
849
843
|
exports.applySolvedTypeVars = applySolvedTypeVars;
|
844
|
+
// Validates that a default type associated with a TypeVar does not refer to
|
845
|
+
// other TypeVars or ParamSpecs that are out of scope.
|
846
|
+
function validateTypeVarDefault(typeVar, liveTypeParams, invalidTypeVars) {
|
847
|
+
// If there is no default type or the default type is concrete, there's
|
848
|
+
// no need to do any more work here.
|
849
|
+
if (typeVar.details.defaultType && requiresSpecialization(typeVar.details.defaultType)) {
|
850
|
+
const validator = new TypeVarDefaultValidator(liveTypeParams, invalidTypeVars);
|
851
|
+
validator.apply(typeVar.details.defaultType, 0);
|
852
|
+
}
|
853
|
+
}
|
854
|
+
exports.validateTypeVarDefault = validateTypeVarDefault;
|
850
855
|
// During bidirectional type inference for constructors, an "executed type"
|
851
856
|
// is used to prepopulate the type var map. This is problematic when the
|
852
857
|
// expected type uses TypeVars that are not part of the context of the
|
@@ -864,7 +869,7 @@ function transformExpectedTypeForConstructor(expectedType, liveTypeVarScopes) {
|
|
864
869
|
return undefined;
|
865
870
|
}
|
866
871
|
const transformer = new ExpectedConstructorTypeTransformer(liveTypeVarScopes);
|
867
|
-
return transformer.apply(expectedType);
|
872
|
+
return transformer.apply(expectedType, 0);
|
868
873
|
}
|
869
874
|
exports.transformExpectedTypeForConstructor = transformExpectedTypeForConstructor;
|
870
875
|
// Given a protocol class, this function returns a set of all the
|
@@ -1128,15 +1133,6 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
|
1128
1133
|
return [];
|
1129
1134
|
}
|
1130
1135
|
recursionCount++;
|
1131
|
-
const getTypeVarsFromClass = (classType) => {
|
1132
|
-
const combinedList = [];
|
1133
|
-
if (classType.typeArguments) {
|
1134
|
-
classType.typeArguments.forEach((typeArg) => {
|
1135
|
-
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(typeArg, recursionCount));
|
1136
|
-
});
|
1137
|
-
}
|
1138
|
-
return combinedList;
|
1139
|
-
};
|
1140
1136
|
if ((_a = type.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.typeArguments) {
|
1141
1137
|
const combinedList = [];
|
1142
1138
|
(_b = type.typeAliasInfo) === null || _b === void 0 ? void 0 : _b.typeArguments.forEach((typeArg) => {
|
@@ -1156,7 +1152,14 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
|
1156
1152
|
return [types_1.TypeBase.isInstantiable(type) ? types_1.TypeVarType.cloneAsInstance(type) : type];
|
1157
1153
|
}
|
1158
1154
|
if ((0, types_1.isClass)(type)) {
|
1159
|
-
|
1155
|
+
const combinedList = [];
|
1156
|
+
const typeArgs = type.tupleTypeArguments ? type.tupleTypeArguments.map((e) => e.type) : type.typeArguments;
|
1157
|
+
if (typeArgs) {
|
1158
|
+
typeArgs.forEach((typeArg) => {
|
1159
|
+
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(typeArg, recursionCount));
|
1160
|
+
});
|
1161
|
+
}
|
1162
|
+
return combinedList;
|
1160
1163
|
}
|
1161
1164
|
if ((0, types_1.isUnion)(type)) {
|
1162
1165
|
const combinedList = [];
|
@@ -1182,6 +1185,79 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
|
1182
1185
|
return [];
|
1183
1186
|
}
|
1184
1187
|
exports.getTypeVarArgumentsRecursive = getTypeVarArgumentsRecursive;
|
1188
|
+
// Determines if the type variable appears within the type and only within
|
1189
|
+
// a particular Callable within that type.
|
1190
|
+
function isTypeVarLimitedToCallable(type, typeVar) {
|
1191
|
+
const info = getTypeVarWithinTypeInfoRecursive(type, typeVar);
|
1192
|
+
return info.isTypeVarUsed && info.isUsedInCallable;
|
1193
|
+
}
|
1194
|
+
exports.isTypeVarLimitedToCallable = isTypeVarLimitedToCallable;
|
1195
|
+
function getTypeVarWithinTypeInfoRecursive(type, typeVar, recursionCount = 0) {
|
1196
|
+
if (recursionCount > types_1.maxTypeRecursionCount) {
|
1197
|
+
return { isTypeVarUsed: false, isUsedInCallable: false };
|
1198
|
+
}
|
1199
|
+
recursionCount++;
|
1200
|
+
let typeVarUsedCount = 0;
|
1201
|
+
let usedInCallableCount = 0;
|
1202
|
+
if ((0, types_1.isTypeVar)(type)) {
|
1203
|
+
// Ignore P.args or P.kwargs types.
|
1204
|
+
if (!(0, types_1.isParamSpec)(type) || !type.paramSpecAccess) {
|
1205
|
+
if ((0, types_1.isTypeSame)(typeVar, convertToInstance(type))) {
|
1206
|
+
typeVarUsedCount++;
|
1207
|
+
}
|
1208
|
+
}
|
1209
|
+
}
|
1210
|
+
else if ((0, types_1.isClass)(type)) {
|
1211
|
+
if (type.typeArguments) {
|
1212
|
+
type.typeArguments.forEach((typeArg) => {
|
1213
|
+
const subResult = getTypeVarWithinTypeInfoRecursive(typeArg, typeVar, recursionCount);
|
1214
|
+
if (subResult.isTypeVarUsed) {
|
1215
|
+
typeVarUsedCount++;
|
1216
|
+
}
|
1217
|
+
if (subResult.isUsedInCallable) {
|
1218
|
+
usedInCallableCount++;
|
1219
|
+
}
|
1220
|
+
});
|
1221
|
+
}
|
1222
|
+
}
|
1223
|
+
else if ((0, types_1.isUnion)(type)) {
|
1224
|
+
doForEachSubtype(type, (subtype) => {
|
1225
|
+
const subResult = getTypeVarWithinTypeInfoRecursive(subtype, typeVar, recursionCount);
|
1226
|
+
if (subResult.isTypeVarUsed) {
|
1227
|
+
typeVarUsedCount++;
|
1228
|
+
}
|
1229
|
+
if (subResult.isUsedInCallable) {
|
1230
|
+
usedInCallableCount++;
|
1231
|
+
}
|
1232
|
+
});
|
1233
|
+
}
|
1234
|
+
else if ((0, types_1.isFunction)(type)) {
|
1235
|
+
for (let i = 0; i < type.details.parameters.length; i++) {
|
1236
|
+
if (getTypeVarWithinTypeInfoRecursive(types_1.FunctionType.getEffectiveParameterType(type, i), typeVar, recursionCount).isTypeVarUsed) {
|
1237
|
+
typeVarUsedCount++;
|
1238
|
+
}
|
1239
|
+
}
|
1240
|
+
if (type.details.paramSpec) {
|
1241
|
+
if ((0, types_1.isTypeSame)(typeVar, convertToInstance(type.details.paramSpec))) {
|
1242
|
+
typeVarUsedCount++;
|
1243
|
+
}
|
1244
|
+
}
|
1245
|
+
const returnType = types_1.FunctionType.getSpecializedReturnType(type);
|
1246
|
+
if (returnType) {
|
1247
|
+
if (getTypeVarWithinTypeInfoRecursive(returnType, typeVar, recursionCount).isTypeVarUsed) {
|
1248
|
+
typeVarUsedCount++;
|
1249
|
+
}
|
1250
|
+
}
|
1251
|
+
if (typeVarUsedCount > 0) {
|
1252
|
+
typeVarUsedCount = 1;
|
1253
|
+
usedInCallableCount = 1;
|
1254
|
+
}
|
1255
|
+
}
|
1256
|
+
return {
|
1257
|
+
isTypeVarUsed: typeVarUsedCount > 0,
|
1258
|
+
isUsedInCallable: usedInCallableCount === 1 && typeVarUsedCount === 1,
|
1259
|
+
};
|
1260
|
+
}
|
1185
1261
|
// Creates a specialized version of the class, filling in any unspecified
|
1186
1262
|
// type arguments with Unknown.
|
1187
1263
|
function specializeClassType(type) {
|
@@ -1240,13 +1316,9 @@ function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionC
|
|
1240
1316
|
if (destType.details.paramSpec) {
|
1241
1317
|
// Fill in an empty signature for a ParamSpec if the source is Any or Unknown.
|
1242
1318
|
if (!typeVarContext.hasTypeVar(destType.details.paramSpec) && (0, types_1.isAnyOrUnknown)(srcType)) {
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
typeVarScopeId: undefined,
|
1247
|
-
docString: undefined,
|
1248
|
-
paramSpec: undefined,
|
1249
|
-
});
|
1319
|
+
const newFunction = types_1.FunctionType.createInstance('', '', '', 32768 /* SkipArgsKwargsCompatibilityCheck */ | 65536 /* ParamSpecValue */);
|
1320
|
+
types_1.FunctionType.addDefaultParameters(newFunction);
|
1321
|
+
typeVarContext.setTypeVarType(destType.details.paramSpec, newFunction);
|
1250
1322
|
}
|
1251
1323
|
}
|
1252
1324
|
}
|
@@ -1279,7 +1351,7 @@ function buildTypeVarContextFromSpecializedClass(classType, makeConcrete = true)
|
|
1279
1351
|
}
|
1280
1352
|
const typeVarContext = buildTypeVarContext(typeParameters, typeArguments, getTypeVarScopeId(classType));
|
1281
1353
|
if (types_1.ClassType.isTupleClass(classType) && classType.tupleTypeArguments && typeParameters.length >= 1) {
|
1282
|
-
typeVarContext.
|
1354
|
+
typeVarContext.setTupleTypeVar(typeParameters[0], classType.tupleTypeArguments);
|
1283
1355
|
}
|
1284
1356
|
return typeVarContext;
|
1285
1357
|
}
|
@@ -1293,10 +1365,10 @@ function buildTypeVarContext(typeParameters, typeArgs, typeVarScopeId) {
|
|
1293
1365
|
if (index < typeArgs.length) {
|
1294
1366
|
typeArgType = typeArgs[index];
|
1295
1367
|
if ((0, types_1.isFunction)(typeArgType) && types_1.FunctionType.isParamSpecValue(typeArgType)) {
|
1296
|
-
const
|
1368
|
+
const parameters = [];
|
1297
1369
|
const typeArgFunctionType = typeArgType;
|
1298
1370
|
typeArgType.details.parameters.forEach((param, paramIndex) => {
|
1299
|
-
|
1371
|
+
parameters.push({
|
1300
1372
|
category: param.category,
|
1301
1373
|
name: param.name,
|
1302
1374
|
hasDefault: !!param.hasDefault,
|
@@ -1305,32 +1377,10 @@ function buildTypeVarContext(typeParameters, typeArgs, typeVarScopeId) {
|
|
1305
1377
|
type: types_1.FunctionType.getEffectiveParameterType(typeArgFunctionType, paramIndex),
|
1306
1378
|
});
|
1307
1379
|
});
|
1308
|
-
typeVarContext.
|
1309
|
-
parameters: paramSpecEntries,
|
1310
|
-
typeVarScopeId: typeArgType.details.typeVarScopeId,
|
1311
|
-
flags: typeArgType.details.flags,
|
1312
|
-
docString: typeArgType.details.docString,
|
1313
|
-
paramSpec: typeArgType.details.paramSpec,
|
1314
|
-
});
|
1315
|
-
}
|
1316
|
-
else if ((0, types_1.isParamSpec)(typeArgType)) {
|
1317
|
-
typeVarContext.setParamSpec(typeParam, {
|
1318
|
-
flags: 0 /* None */,
|
1319
|
-
parameters: [],
|
1320
|
-
typeVarScopeId: undefined,
|
1321
|
-
docString: undefined,
|
1322
|
-
paramSpec: typeArgType,
|
1323
|
-
});
|
1380
|
+
typeVarContext.setTypeVarType(typeParam, convertTypeToParamSpecValue(typeArgType));
|
1324
1381
|
}
|
1325
|
-
else if ((0, types_1.isAnyOrUnknown)(typeArgType)) {
|
1326
|
-
|
1327
|
-
typeVarContext.setParamSpec(typeParam, {
|
1328
|
-
flags: 32768 /* SkipArgsKwargsCompatibilityCheck */,
|
1329
|
-
parameters: types_1.FunctionType.getDefaultParameters(),
|
1330
|
-
typeVarScopeId: undefined,
|
1331
|
-
docString: undefined,
|
1332
|
-
paramSpec: undefined,
|
1333
|
-
});
|
1382
|
+
else if ((0, types_1.isParamSpec)(typeArgType) || (0, types_1.isAnyOrUnknown)(typeArgType)) {
|
1383
|
+
typeVarContext.setTypeVarType(typeParam, convertTypeToParamSpecValue(typeArgType));
|
1334
1384
|
}
|
1335
1385
|
}
|
1336
1386
|
}
|
@@ -1341,7 +1391,8 @@ function buildTypeVarContext(typeParameters, typeArgs, typeVarScopeId) {
|
|
1341
1391
|
else {
|
1342
1392
|
typeArgType = typeArgs[index];
|
1343
1393
|
}
|
1344
|
-
typeVarContext.setTypeVarType(typeParam, typeArgType,
|
1394
|
+
typeVarContext.setTypeVarType(typeParam, typeArgType,
|
1395
|
+
/* narrowBoundNoLiterals */ undefined, typeArgType);
|
1345
1396
|
}
|
1346
1397
|
}
|
1347
1398
|
});
|
@@ -2095,20 +2146,48 @@ function addDeclaringModuleNamesForType(type, moduleList, recursionCount = 0) {
|
|
2095
2146
|
}
|
2096
2147
|
}
|
2097
2148
|
}
|
2098
|
-
function
|
2099
|
-
|
2100
|
-
|
2149
|
+
function convertTypeToParamSpecValue(type) {
|
2150
|
+
if ((0, types_1.isParamSpec)(type)) {
|
2151
|
+
const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* ParamSpecValue */);
|
2152
|
+
newFunction.details.paramSpec = type;
|
2153
|
+
newFunction.details.typeVarScopeId = getTypeVarScopeId(type);
|
2154
|
+
return newFunction;
|
2155
|
+
}
|
2156
|
+
if ((0, types_1.isFunction)(type)) {
|
2157
|
+
const newFunction = types_1.FunctionType.createInstance('', '', '', type.details.flags | 65536 /* ParamSpecValue */, type.details.docString);
|
2158
|
+
type.details.parameters.forEach((param, index) => {
|
2159
|
+
types_1.FunctionType.addParameter(newFunction, {
|
2160
|
+
category: param.category,
|
2161
|
+
name: param.name,
|
2162
|
+
hasDefault: param.hasDefault,
|
2163
|
+
defaultValueExpression: param.defaultValueExpression,
|
2164
|
+
isNameSynthesized: param.isNameSynthesized,
|
2165
|
+
type: types_1.FunctionType.getEffectiveParameterType(type, index),
|
2166
|
+
});
|
2167
|
+
});
|
2168
|
+
newFunction.details.typeVarScopeId = getTypeVarScopeId(type);
|
2169
|
+
newFunction.details.paramSpec = type.details.paramSpec;
|
2170
|
+
return newFunction;
|
2171
|
+
}
|
2172
|
+
const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* ParamSpecValue */ | 32768 /* SkipArgsKwargsCompatibilityCheck */);
|
2173
|
+
types_1.FunctionType.addDefaultParameters(newFunction);
|
2174
|
+
return newFunction;
|
2175
|
+
}
|
2176
|
+
exports.convertTypeToParamSpecValue = convertTypeToParamSpecValue;
|
2177
|
+
function convertParamSpecValueToType(paramSpecValue, omitParamSpec = false) {
|
2178
|
+
let hasParameters = paramSpecValue.details.parameters.length > 0;
|
2179
|
+
if (paramSpecValue.details.parameters.length === 1) {
|
2101
2180
|
// If the ParamSpec has a position-only separator as its only parameter,
|
2102
2181
|
// treat it as though there are no parameters.
|
2103
|
-
const onlyParam =
|
2182
|
+
const onlyParam = paramSpecValue.details.parameters[0];
|
2104
2183
|
if (onlyParam.category === 0 /* Simple */ && !onlyParam.name) {
|
2105
2184
|
hasParameters = false;
|
2106
2185
|
}
|
2107
2186
|
}
|
2108
|
-
if (hasParameters || !
|
2187
|
+
if (hasParameters || !paramSpecValue.details.paramSpec || omitParamSpec) {
|
2109
2188
|
// Create a function type from the param spec entries.
|
2110
|
-
const functionType = types_1.FunctionType.createInstance('', '', '', 65536 /* ParamSpecValue */ |
|
2111
|
-
|
2189
|
+
const functionType = types_1.FunctionType.createInstance('', '', '', 65536 /* ParamSpecValue */ | paramSpecValue.details.flags);
|
2190
|
+
paramSpecValue.details.parameters.forEach((entry) => {
|
2112
2191
|
types_1.FunctionType.addParameter(functionType, {
|
2113
2192
|
category: entry.category,
|
2114
2193
|
name: entry.name,
|
@@ -2120,12 +2199,12 @@ function convertParamSpecValueToType(paramSpecEntry, omitParamSpec = false) {
|
|
2120
2199
|
});
|
2121
2200
|
});
|
2122
2201
|
if (!omitParamSpec) {
|
2123
|
-
functionType.details.paramSpec =
|
2202
|
+
functionType.details.paramSpec = paramSpecValue.details.paramSpec;
|
2124
2203
|
}
|
2125
|
-
functionType.details.docString =
|
2204
|
+
functionType.details.docString = paramSpecValue.details.docString;
|
2126
2205
|
return functionType;
|
2127
2206
|
}
|
2128
|
-
return
|
2207
|
+
return paramSpecValue.details.paramSpec;
|
2129
2208
|
}
|
2130
2209
|
exports.convertParamSpecValueToType = convertParamSpecValueToType;
|
2131
2210
|
// Recursively walks a type and calls a callback for each TypeVar, allowing
|
@@ -2135,7 +2214,7 @@ class TypeVarTransformer {
|
|
2135
2214
|
this._isTransformingTypeArg = false;
|
2136
2215
|
this._pendingTypeVarTransformations = new Set();
|
2137
2216
|
}
|
2138
|
-
apply(type, recursionCount
|
2217
|
+
apply(type, recursionCount) {
|
2139
2218
|
var _a, _b;
|
2140
2219
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
2141
2220
|
return type;
|
@@ -2179,16 +2258,26 @@ class TypeVarTransformer {
|
|
2179
2258
|
// _pendingTypeVarTransformations set.
|
2180
2259
|
const typeVarName = types_1.TypeVarType.getNameWithScope(type);
|
2181
2260
|
if (!this._pendingTypeVarTransformations.has(typeVarName)) {
|
2182
|
-
|
2183
|
-
|
2184
|
-
|
2185
|
-
|
2186
|
-
|
2261
|
+
if (type.details.isParamSpec) {
|
2262
|
+
if (!type.paramSpecAccess) {
|
2263
|
+
const paramSpecValue = this.transformParamSpec(type, recursionCount);
|
2264
|
+
if (paramSpecValue) {
|
2265
|
+
replacementType = convertParamSpecValueToType(paramSpecValue);
|
2266
|
+
}
|
2267
|
+
}
|
2187
2268
|
}
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2191
|
-
|
2269
|
+
else {
|
2270
|
+
replacementType = (_b = this.transformTypeVar(type, recursionCount)) !== null && _b !== void 0 ? _b : type;
|
2271
|
+
if (!this._isTransformingTypeArg) {
|
2272
|
+
this._pendingTypeVarTransformations.add(typeVarName);
|
2273
|
+
replacementType = this.apply(replacementType, recursionCount);
|
2274
|
+
this._pendingTypeVarTransformations.delete(typeVarName);
|
2275
|
+
}
|
2276
|
+
// If we're transforming a variadic type variable that was in a union,
|
2277
|
+
// expand the union types.
|
2278
|
+
if ((0, types_1.isVariadicTypeVar)(type) && type.isVariadicInUnion) {
|
2279
|
+
replacementType = _expandVariadicUnpackedUnion(replacementType);
|
2280
|
+
}
|
2192
2281
|
}
|
2193
2282
|
}
|
2194
2283
|
return replacementType;
|
@@ -2206,7 +2295,7 @@ class TypeVarTransformer {
|
|
2206
2295
|
transformedType = (0, types_1.combineTypes)(subtypesToCombine);
|
2207
2296
|
}
|
2208
2297
|
if (this.transformUnionSubtype) {
|
2209
|
-
return this.transformUnionSubtype(subtype, transformedType);
|
2298
|
+
return this.transformUnionSubtype(subtype, transformedType, recursionCount);
|
2210
2299
|
}
|
2211
2300
|
return transformedType;
|
2212
2301
|
});
|
@@ -2234,16 +2323,16 @@ class TypeVarTransformer {
|
|
2234
2323
|
}
|
2235
2324
|
return type;
|
2236
2325
|
}
|
2237
|
-
transformTypeVar(typeVar) {
|
2326
|
+
transformTypeVar(typeVar, recursionCount) {
|
2238
2327
|
return typeVar;
|
2239
2328
|
}
|
2240
|
-
|
2329
|
+
transformTupleTypeVar(paramSpec, recursionCount) {
|
2241
2330
|
return undefined;
|
2242
2331
|
}
|
2243
|
-
transformParamSpec(paramSpec) {
|
2332
|
+
transformParamSpec(paramSpec, recursionCount) {
|
2244
2333
|
return undefined;
|
2245
2334
|
}
|
2246
|
-
transformUnionSubtype(preTransform, postTransform) {
|
2335
|
+
transformUnionSubtype(preTransform, postTransform, recursionCount) {
|
2247
2336
|
return postTransform;
|
2248
2337
|
}
|
2249
2338
|
_transformGenericTypeAlias(type, recursionCount) {
|
@@ -2268,11 +2357,11 @@ class TypeVarTransformer {
|
|
2268
2357
|
return classType;
|
2269
2358
|
}
|
2270
2359
|
let newTypeArgs = [];
|
2271
|
-
let
|
2360
|
+
let newTupleTypeArgs;
|
2272
2361
|
let specializationNeeded = false;
|
2273
2362
|
const typeParams = types_1.ClassType.getTypeParameters(classType);
|
2274
2363
|
const transformParamSpec = (paramSpec) => {
|
2275
|
-
const paramSpecValue = this.transformParamSpec(paramSpec);
|
2364
|
+
const paramSpecValue = this.transformParamSpec(paramSpec, recursionCount);
|
2276
2365
|
if (paramSpecValue) {
|
2277
2366
|
specializationNeeded = true;
|
2278
2367
|
return convertParamSpecValueToType(paramSpecValue);
|
@@ -2315,7 +2404,7 @@ class TypeVarTransformer {
|
|
2315
2404
|
else {
|
2316
2405
|
const typeParamName = types_1.TypeVarType.getNameWithScope(typeParam);
|
2317
2406
|
if (!this._pendingTypeVarTransformations.has(typeParamName)) {
|
2318
|
-
const transformedType = this.transformTypeVar(typeParam);
|
2407
|
+
const transformedType = this.transformTypeVar(typeParam, recursionCount);
|
2319
2408
|
replacementType = transformedType !== null && transformedType !== void 0 ? transformedType : typeParam;
|
2320
2409
|
if (replacementType !== typeParam) {
|
2321
2410
|
specializationNeeded = true;
|
@@ -2330,7 +2419,7 @@ class TypeVarTransformer {
|
|
2330
2419
|
}
|
2331
2420
|
if (types_1.ClassType.isTupleClass(classType)) {
|
2332
2421
|
if (classType.tupleTypeArguments) {
|
2333
|
-
|
2422
|
+
newTupleTypeArgs = [];
|
2334
2423
|
classType.tupleTypeArguments.forEach((oldTypeArgType) => {
|
2335
2424
|
const newTypeArgType = this.apply(oldTypeArgType.type, recursionCount);
|
2336
2425
|
if (newTypeArgType !== oldTypeArgType.type) {
|
@@ -2340,16 +2429,16 @@ class TypeVarTransformer {
|
|
2340
2429
|
(0, types_1.isClassInstance)(newTypeArgType) &&
|
2341
2430
|
isTupleClass(newTypeArgType) &&
|
2342
2431
|
newTypeArgType.tupleTypeArguments) {
|
2343
|
-
(0, collectionUtils_1.appendArray)(
|
2432
|
+
(0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.tupleTypeArguments);
|
2344
2433
|
}
|
2345
2434
|
else {
|
2346
|
-
|
2435
|
+
newTupleTypeArgs.push({ type: newTypeArgType, isUnbounded: oldTypeArgType.isUnbounded });
|
2347
2436
|
}
|
2348
2437
|
});
|
2349
2438
|
}
|
2350
2439
|
else if (typeParams.length > 0) {
|
2351
|
-
|
2352
|
-
if (
|
2440
|
+
newTupleTypeArgs = this.transformTupleTypeVar(typeParams[0], recursionCount);
|
2441
|
+
if (newTupleTypeArgs) {
|
2353
2442
|
specializationNeeded = true;
|
2354
2443
|
}
|
2355
2444
|
}
|
@@ -2361,13 +2450,13 @@ class TypeVarTransformer {
|
|
2361
2450
|
}
|
2362
2451
|
return types_1.ClassType.cloneForSpecialization(classType, newTypeArgs,
|
2363
2452
|
/* isTypeArgumentExplicit */ true,
|
2364
|
-
/* includeSubclasses */ undefined,
|
2453
|
+
/* includeSubclasses */ undefined, newTupleTypeArgs);
|
2365
2454
|
}
|
2366
2455
|
_transformTypeVarsInFunctionType(sourceType, recursionCount) {
|
2367
2456
|
let functionType = sourceType;
|
2368
2457
|
// Handle functions with a parameter specification in a special manner.
|
2369
2458
|
if (functionType.details.paramSpec) {
|
2370
|
-
const paramSpec = this.transformParamSpec(functionType.details.paramSpec);
|
2459
|
+
const paramSpec = this.transformParamSpec(functionType.details.paramSpec, recursionCount);
|
2371
2460
|
if (paramSpec) {
|
2372
2461
|
functionType = types_1.FunctionType.cloneForParamSpec(functionType, paramSpec);
|
2373
2462
|
}
|
@@ -2392,11 +2481,11 @@ class TypeVarTransformer {
|
|
2392
2481
|
(0, types_1.isParamSpec)(argsParamType) &&
|
2393
2482
|
(0, types_1.isParamSpec)(kwargsParamType) &&
|
2394
2483
|
(0, types_1.isTypeSame)(argsParamType, kwargsParamType)) {
|
2395
|
-
const paramSpecType = this.transformParamSpec(argsParamType);
|
2484
|
+
const paramSpecType = this.transformParamSpec(argsParamType, recursionCount);
|
2396
2485
|
if (paramSpecType) {
|
2397
|
-
if (paramSpecType.parameters.length > 0 ||
|
2398
|
-
paramSpecType.paramSpec === undefined ||
|
2399
|
-
!(0, types_1.isTypeSame)(argsParamType, paramSpecType.paramSpec)) {
|
2486
|
+
if (paramSpecType.details.parameters.length > 0 ||
|
2487
|
+
paramSpecType.details.paramSpec === undefined ||
|
2488
|
+
!(0, types_1.isTypeSame)(argsParamType, paramSpecType.details.paramSpec)) {
|
2400
2489
|
functionType = types_1.FunctionType.cloneForParamSpecApplication(functionType, paramSpecType);
|
2401
2490
|
}
|
2402
2491
|
}
|
@@ -2508,26 +2597,47 @@ class TypeVarTransformer {
|
|
2508
2597
|
return newFunctionType;
|
2509
2598
|
}
|
2510
2599
|
}
|
2600
|
+
// For a TypeVar with a default type, validates whether the default type is using
|
2601
|
+
// any other TypeVars that are not currently in scope.
|
2602
|
+
class TypeVarDefaultValidator extends TypeVarTransformer {
|
2603
|
+
constructor(_liveTypeParams, _invalidTypeVars) {
|
2604
|
+
super();
|
2605
|
+
this._liveTypeParams = _liveTypeParams;
|
2606
|
+
this._invalidTypeVars = _invalidTypeVars;
|
2607
|
+
}
|
2608
|
+
transformTypeVar(typeVar) {
|
2609
|
+
const replacementType = this._liveTypeParams.find((param) => param.details.name === typeVar.details.name);
|
2610
|
+
if (!replacementType || (0, types_1.isParamSpec)(replacementType)) {
|
2611
|
+
this._invalidTypeVars.add(typeVar.details.name);
|
2612
|
+
}
|
2613
|
+
return types_1.UnknownType.create();
|
2614
|
+
}
|
2615
|
+
transformParamSpec(paramSpec) {
|
2616
|
+
const replacementType = this._liveTypeParams.find((param) => param.details.name === paramSpec.details.name);
|
2617
|
+
if (!replacementType || !(0, types_1.isParamSpec)(replacementType)) {
|
2618
|
+
this._invalidTypeVars.add(paramSpec.details.name);
|
2619
|
+
}
|
2620
|
+
return undefined;
|
2621
|
+
}
|
2622
|
+
}
|
2511
2623
|
// Specializes a (potentially generic) type by substituting
|
2512
2624
|
// type variables from a type var map.
|
2513
2625
|
class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
2514
|
-
constructor(_typeVarContext,
|
2626
|
+
constructor(_typeVarContext, _options) {
|
2515
2627
|
super();
|
2516
2628
|
this._typeVarContext = _typeVarContext;
|
2517
|
-
this.
|
2518
|
-
this.
|
2519
|
-
this._eliminateUnsolvedInUnions = _eliminateUnsolvedInUnions;
|
2520
|
-
this._typeClassType = _typeClassType;
|
2629
|
+
this._options = _options;
|
2630
|
+
this._isSolvingDefaultType = false;
|
2521
2631
|
}
|
2522
|
-
transformTypeVar(typeVar) {
|
2632
|
+
transformTypeVar(typeVar, recursionCount) {
|
2523
2633
|
// If the type variable is unrelated to the scopes we're solving,
|
2524
2634
|
// don't transform that type variable.
|
2525
2635
|
if (typeVar.scopeId && this._typeVarContext.hasSolveForScope(typeVar.scopeId)) {
|
2526
|
-
let replacement = this._typeVarContext.getTypeVarType(typeVar, this.
|
2636
|
+
let replacement = this._typeVarContext.getTypeVarType(typeVar, !!this._options.useNarrowBoundOnly);
|
2527
2637
|
// If there was no narrow bound but there is a wide bound that
|
2528
2638
|
// contains literals, we'll use the wide bound even if "useNarrowBoundOnly"
|
2529
2639
|
// is specified.
|
2530
|
-
if (!replacement && this.
|
2640
|
+
if (!replacement && !!this._options.useNarrowBoundOnly) {
|
2531
2641
|
const wideType = this._typeVarContext.getTypeVarType(typeVar);
|
2532
2642
|
if (wideType) {
|
2533
2643
|
if (containsLiteralType(wideType, /* includeTypeArgs */ true)) {
|
@@ -2538,9 +2648,9 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2538
2648
|
if (replacement) {
|
2539
2649
|
if (types_1.TypeBase.isInstantiable(typeVar)) {
|
2540
2650
|
if ((0, types_1.isAnyOrUnknown)(replacement) &&
|
2541
|
-
this.
|
2542
|
-
(0, types_1.isInstantiableClass)(this.
|
2543
|
-
replacement = types_1.ClassType.cloneForSpecialization(types_1.ClassType.cloneAsInstance(this.
|
2651
|
+
this._options.typeClassType &&
|
2652
|
+
(0, types_1.isInstantiableClass)(this._options.typeClassType)) {
|
2653
|
+
replacement = types_1.ClassType.cloneForSpecialization(types_1.ClassType.cloneAsInstance(this._options.typeClassType), [replacement],
|
2544
2654
|
/* isTypeArgumentExplicit */ true);
|
2545
2655
|
}
|
2546
2656
|
else {
|
@@ -2552,13 +2662,40 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2552
2662
|
// If this typeVar is in scope for what we're solving but the type
|
2553
2663
|
// var map doesn't contain any entry for it, replace with the
|
2554
2664
|
// default or Unknown.
|
2555
|
-
if (this.
|
2665
|
+
if (this._options.unknownIfNotFound && !this._typeVarContext.hasSolveForScope(types_1.WildcardTypeVarScopeId)) {
|
2666
|
+
// Use the default value if there is one.
|
2556
2667
|
if (typeVar.details.defaultType) {
|
2557
|
-
return typeVar.details.defaultType;
|
2668
|
+
return this._solveDefaultType(typeVar.details.defaultType, recursionCount);
|
2558
2669
|
}
|
2559
2670
|
return types_1.UnknownType.create();
|
2560
2671
|
}
|
2561
2672
|
}
|
2673
|
+
// If we're solving a default type, handle type variables with no scope ID.
|
2674
|
+
if (this._isSolvingDefaultType && !typeVar.scopeId) {
|
2675
|
+
const replacementEntry = this._typeVarContext
|
2676
|
+
.getTypeVars()
|
2677
|
+
.find((entry) => entry.typeVar.details.name === typeVar.details.name);
|
2678
|
+
if (replacementEntry) {
|
2679
|
+
return this._typeVarContext.getTypeVarType(replacementEntry.typeVar);
|
2680
|
+
}
|
2681
|
+
if (typeVar.details.defaultType) {
|
2682
|
+
return this.apply(typeVar.details.defaultType, recursionCount);
|
2683
|
+
}
|
2684
|
+
return types_1.UnknownType.create();
|
2685
|
+
}
|
2686
|
+
// If we're solving a default type, handle type variables with no scope ID.
|
2687
|
+
if (this._isSolvingDefaultType && !typeVar.scopeId) {
|
2688
|
+
const replacementEntry = this._typeVarContext
|
2689
|
+
.getTypeVars()
|
2690
|
+
.find((entry) => entry.typeVar.details.name === typeVar.details.name);
|
2691
|
+
if (replacementEntry) {
|
2692
|
+
return this._typeVarContext.getTypeVarType(replacementEntry.typeVar);
|
2693
|
+
}
|
2694
|
+
if (typeVar.details.defaultType) {
|
2695
|
+
return this.apply(typeVar.details.defaultType, recursionCount);
|
2696
|
+
}
|
2697
|
+
return types_1.UnknownType.create();
|
2698
|
+
}
|
2562
2699
|
return undefined;
|
2563
2700
|
}
|
2564
2701
|
transformUnionSubtype(preTransform, postTransform) {
|
@@ -2567,7 +2704,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2567
2704
|
// in cases where TypeVars can go unsolved due to unions in parameter
|
2568
2705
|
// annotations, like this:
|
2569
2706
|
// def test(x: Union[str, T]) -> Union[str, T]
|
2570
|
-
if (this.
|
2707
|
+
if (this._options.eliminateUnsolvedInUnions) {
|
2571
2708
|
if ((0, types_1.isTypeVar)(preTransform) &&
|
2572
2709
|
preTransform.scopeId !== undefined &&
|
2573
2710
|
this._typeVarContext.hasSolveForScope(preTransform.scopeId)) {
|
@@ -2578,56 +2715,66 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2578
2715
|
}
|
2579
2716
|
// If _unknownIfNotFound is true, the postTransform type will
|
2580
2717
|
// be Unknown, which we want to eliminate.
|
2581
|
-
if ((0, types_1.isUnknown)(postTransform) && this.
|
2718
|
+
if ((0, types_1.isUnknown)(postTransform) && this._options.unknownIfNotFound) {
|
2582
2719
|
return undefined;
|
2583
2720
|
}
|
2584
2721
|
}
|
2585
2722
|
}
|
2586
2723
|
return postTransform;
|
2587
2724
|
}
|
2588
|
-
|
2725
|
+
transformTupleTypeVar(typeVar) {
|
2589
2726
|
if (!typeVar.scopeId || !this._typeVarContext.hasSolveForScope(typeVar.scopeId)) {
|
2590
|
-
|
2591
|
-
|
2592
|
-
|
2593
|
-
return typeVar.details.defaultType.tupleTypeArguments;
|
2727
|
+
const defaultType = typeVar.details.defaultType;
|
2728
|
+
if (defaultType && (0, types_1.isClassInstance)(defaultType) && defaultType.tupleTypeArguments) {
|
2729
|
+
return defaultType.tupleTypeArguments;
|
2594
2730
|
}
|
2595
2731
|
return undefined;
|
2596
2732
|
}
|
2597
|
-
return this._typeVarContext.
|
2733
|
+
return this._typeVarContext.getTupleTypeVar(typeVar);
|
2598
2734
|
}
|
2599
|
-
transformParamSpec(paramSpec) {
|
2735
|
+
transformParamSpec(paramSpec, recursionCount) {
|
2736
|
+
// If we're solving a default type, handle param specs with no scope ID.
|
2737
|
+
if (this._isSolvingDefaultType && !paramSpec.scopeId) {
|
2738
|
+
const replacementEntry = this._typeVarContext
|
2739
|
+
.getTypeVars()
|
2740
|
+
.find((entry) => entry.typeVar.details.name === paramSpec.details.name);
|
2741
|
+
if (replacementEntry) {
|
2742
|
+
return this._typeVarContext.getParamSpecType(replacementEntry.typeVar);
|
2743
|
+
}
|
2744
|
+
if (paramSpec.details.defaultType) {
|
2745
|
+
return convertTypeToParamSpecValue(this.apply(paramSpec.details.defaultType, recursionCount));
|
2746
|
+
}
|
2747
|
+
return this._getUnknownParamSpec();
|
2748
|
+
}
|
2600
2749
|
if (!paramSpec.scopeId || !this._typeVarContext.hasSolveForScope(paramSpec.scopeId)) {
|
2601
2750
|
return undefined;
|
2602
2751
|
}
|
2603
|
-
const transformedParamSpec = this._typeVarContext.
|
2752
|
+
const transformedParamSpec = this._typeVarContext.getParamSpecType(paramSpec);
|
2604
2753
|
if (transformedParamSpec) {
|
2605
2754
|
return transformedParamSpec;
|
2606
2755
|
}
|
2607
|
-
if (this.
|
2756
|
+
if (this._options.unknownIfNotFound && !this._typeVarContext.hasSolveForScope(types_1.WildcardTypeVarScopeId)) {
|
2608
2757
|
// Use the default value if there is one.
|
2609
|
-
if (paramSpec.details.defaultType
|
2610
|
-
|
2611
|
-
return {
|
2612
|
-
flags: funcType.details.flags,
|
2613
|
-
parameters: funcType.details.parameters,
|
2614
|
-
typeVarScopeId: funcType.details.typeVarScopeId,
|
2615
|
-
docString: funcType.details.docString,
|
2616
|
-
paramSpec: funcType.details.paramSpec,
|
2617
|
-
};
|
2758
|
+
if (paramSpec.details.defaultType) {
|
2759
|
+
return convertTypeToParamSpecValue(this._solveDefaultType(paramSpec.details.defaultType, recursionCount));
|
2618
2760
|
}
|
2619
2761
|
// Convert to the ParamSpec equivalent of "Unknown".
|
2620
|
-
|
2621
|
-
flags: 32768 /* SkipArgsKwargsCompatibilityCheck */,
|
2622
|
-
parameters: types_1.FunctionType.getDefaultParameters(/* useUnknown */ true),
|
2623
|
-
typeVarScopeId: undefined,
|
2624
|
-
docString: undefined,
|
2625
|
-
paramSpec: undefined,
|
2626
|
-
};
|
2627
|
-
return paramSpecValue;
|
2762
|
+
return this._getUnknownParamSpec();
|
2628
2763
|
}
|
2629
2764
|
return undefined;
|
2630
2765
|
}
|
2766
|
+
_solveDefaultType(defaultType, recursionCount) {
|
2767
|
+
const wasSolvingDefaultType = this._isSolvingDefaultType;
|
2768
|
+
this._isSolvingDefaultType = true;
|
2769
|
+
const result = this.apply(defaultType, recursionCount);
|
2770
|
+
this._isSolvingDefaultType = wasSolvingDefaultType;
|
2771
|
+
return result;
|
2772
|
+
}
|
2773
|
+
_getUnknownParamSpec() {
|
2774
|
+
const paramSpecValue = types_1.FunctionType.createInstance('', '', '', 65536 /* ParamSpecValue */ | 32768 /* SkipArgsKwargsCompatibilityCheck */);
|
2775
|
+
types_1.FunctionType.addDefaultParameters(paramSpecValue);
|
2776
|
+
return paramSpecValue;
|
2777
|
+
}
|
2631
2778
|
}
|
2632
2779
|
class ExpectedConstructorTypeTransformer extends TypeVarTransformer {
|
2633
2780
|
constructor(_liveTypeVarScopes) {
|