@zzzen/pyright-internal 1.2.0-dev.20221225 → 1.2.0-dev.20230108
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 +5 -3
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +17 -11
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +16 -1
- package/dist/analyzer/codeFlowEngine.js +36 -13
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +30 -31
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +2 -1
- package/dist/analyzer/importResolver.js +18 -3
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/patternMatching.js +5 -4
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +1 -0
- package/dist/analyzer/program.js +52 -25
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/regions.js +14 -5
- package/dist/analyzer/regions.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +1 -1
- package/dist/analyzer/sourceFile.js +1 -0
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.d.ts +2 -2
- package/dist/analyzer/sourceMapper.js +14 -5
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/typeCacheUtils.d.ts +26 -0
- package/dist/analyzer/{typeCache.js → typeCacheUtils.js} +9 -19
- package/dist/analyzer/typeCacheUtils.js.map +1 -0
- package/dist/analyzer/typeDocStringUtils.d.ts +2 -1
- package/dist/analyzer/typeDocStringUtils.js +18 -7
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +551 -379
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -1
- package/dist/analyzer/typeGuards.d.ts +5 -1
- package/dist/analyzer/typeGuards.js +181 -45
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +13 -3
- package/dist/analyzer/typeUtils.js +288 -135
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +2 -10
- package/dist/analyzer/typeVarContext.js +12 -31
- 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/commands/quickActionCommand.js +1 -1
- package/dist/commands/quickActionCommand.js.map +1 -1
- package/dist/common/collectionUtils.d.ts +1 -0
- package/dist/common/collectionUtils.js +9 -1
- package/dist/common/collectionUtils.js.map +1 -1
- package/dist/common/textEditUtils.d.ts +3 -2
- package/dist/common/textEditUtils.js +11 -10
- package/dist/common/textEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +1 -1
- package/dist/languageService/completionProvider.d.ts +3 -0
- package/dist/languageService/completionProvider.js +212 -159
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +0 -1
- package/dist/languageService/hoverProvider.js +7 -20
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/indentationUtils.js +1 -1
- package/dist/languageService/indentationUtils.js.map +1 -1
- package/dist/languageService/tooltipUtils.d.ts +5 -1
- package/dist/languageService/tooltipUtils.js +28 -4
- package/dist/languageService/tooltipUtils.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 +7 -1
- package/dist/parser/parser.js +3 -1
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/completions.test.d.ts +1 -0
- package/dist/tests/completions.test.js +331 -0
- package/dist/tests/completions.test.js.map +1 -0
- package/dist/tests/filesystem.test.js +11 -0
- package/dist/tests/filesystem.test.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +1 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +2 -2
- package/dist/tests/harness/vfs/filesystem.js +5 -1
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/hoverProvider.test.d.ts +1 -0
- package/dist/tests/hoverProvider.test.js +247 -0
- package/dist/tests/hoverProvider.test.js.map +1 -0
- package/dist/tests/indentationUtils.ptvs.test.js +1 -1
- package/dist/tests/indentationUtils.test.js +4 -4
- package/dist/tests/typeEvaluator1.test.js +16 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +6 -2
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +9 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +8 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +54 -6
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/workspaceMap.js +1 -3
- package/dist/workspaceMap.js.map +1 -1
- package/package.json +6 -6
- 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");
|
@@ -822,10 +822,7 @@ function partiallySpecializeType(type, contextClassType, selfClass, typeClassTyp
|
|
822
822
|
if (selfClass) {
|
823
823
|
populateTypeVarContextForSelfType(typeVarContext, contextClassType, selfClass);
|
824
824
|
}
|
825
|
-
return applySolvedTypeVars(type, typeVarContext,
|
826
|
-
/* unknownIfNotFound */ undefined,
|
827
|
-
/* useNarrowBoundOnly */ undefined,
|
828
|
-
/* eliminateUnsolvedInUnions */ undefined, typeClassType);
|
825
|
+
return applySolvedTypeVars(type, typeVarContext, { typeClassType });
|
829
826
|
}
|
830
827
|
exports.partiallySpecializeType = partiallySpecializeType;
|
831
828
|
function populateTypeVarContextForSelfType(typeVarContext, contextClassType, selfClass) {
|
@@ -835,15 +832,26 @@ function populateTypeVarContextForSelfType(typeVarContext, contextClassType, sel
|
|
835
832
|
exports.populateTypeVarContextForSelfType = populateTypeVarContextForSelfType;
|
836
833
|
// Specializes a (potentially generic) type by substituting
|
837
834
|
// type variables from a type var map.
|
838
|
-
function applySolvedTypeVars(type, typeVarContext,
|
835
|
+
function applySolvedTypeVars(type, typeVarContext, options = {}) {
|
839
836
|
// Use a shortcut if the typeVarContext is empty and no transform is necessary.
|
840
|
-
if (typeVarContext.isEmpty() && !unknownIfNotFound && !eliminateUnsolvedInUnions) {
|
837
|
+
if (typeVarContext.isEmpty() && !options.unknownIfNotFound && !options.eliminateUnsolvedInUnions) {
|
841
838
|
return type;
|
842
839
|
}
|
843
|
-
const transformer = new ApplySolvedTypeVarsTransformer(typeVarContext,
|
844
|
-
return transformer.apply(type);
|
840
|
+
const transformer = new ApplySolvedTypeVarsTransformer(typeVarContext, options);
|
841
|
+
return transformer.apply(type, 0);
|
845
842
|
}
|
846
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;
|
847
855
|
// During bidirectional type inference for constructors, an "executed type"
|
848
856
|
// is used to prepopulate the type var map. This is problematic when the
|
849
857
|
// expected type uses TypeVars that are not part of the context of the
|
@@ -861,7 +869,7 @@ function transformExpectedTypeForConstructor(expectedType, liveTypeVarScopes) {
|
|
861
869
|
return undefined;
|
862
870
|
}
|
863
871
|
const transformer = new ExpectedConstructorTypeTransformer(liveTypeVarScopes);
|
864
|
-
return transformer.apply(expectedType);
|
872
|
+
return transformer.apply(expectedType, 0);
|
865
873
|
}
|
866
874
|
exports.transformExpectedTypeForConstructor = transformExpectedTypeForConstructor;
|
867
875
|
// Given a protocol class, this function returns a set of all the
|
@@ -1125,15 +1133,6 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
|
1125
1133
|
return [];
|
1126
1134
|
}
|
1127
1135
|
recursionCount++;
|
1128
|
-
const getTypeVarsFromClass = (classType) => {
|
1129
|
-
const combinedList = [];
|
1130
|
-
if (classType.typeArguments) {
|
1131
|
-
classType.typeArguments.forEach((typeArg) => {
|
1132
|
-
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(typeArg, recursionCount));
|
1133
|
-
});
|
1134
|
-
}
|
1135
|
-
return combinedList;
|
1136
|
-
};
|
1137
1136
|
if ((_a = type.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.typeArguments) {
|
1138
1137
|
const combinedList = [];
|
1139
1138
|
(_b = type.typeAliasInfo) === null || _b === void 0 ? void 0 : _b.typeArguments.forEach((typeArg) => {
|
@@ -1153,7 +1152,14 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
|
1153
1152
|
return [types_1.TypeBase.isInstantiable(type) ? types_1.TypeVarType.cloneAsInstance(type) : type];
|
1154
1153
|
}
|
1155
1154
|
if ((0, types_1.isClass)(type)) {
|
1156
|
-
|
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;
|
1157
1163
|
}
|
1158
1164
|
if ((0, types_1.isUnion)(type)) {
|
1159
1165
|
const combinedList = [];
|
@@ -1179,6 +1185,79 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
|
1179
1185
|
return [];
|
1180
1186
|
}
|
1181
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
|
+
}
|
1182
1261
|
// Creates a specialized version of the class, filling in any unspecified
|
1183
1262
|
// type arguments with Unknown.
|
1184
1263
|
function specializeClassType(type) {
|
@@ -1237,13 +1316,9 @@ function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionC
|
|
1237
1316
|
if (destType.details.paramSpec) {
|
1238
1317
|
// Fill in an empty signature for a ParamSpec if the source is Any or Unknown.
|
1239
1318
|
if (!typeVarContext.hasTypeVar(destType.details.paramSpec) && (0, types_1.isAnyOrUnknown)(srcType)) {
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
typeVarScopeId: undefined,
|
1244
|
-
docString: undefined,
|
1245
|
-
paramSpec: undefined,
|
1246
|
-
});
|
1319
|
+
const newFunction = types_1.FunctionType.createInstance('', '', '', 32768 /* SkipArgsKwargsCompatibilityCheck */ | 65536 /* ParamSpecValue */);
|
1320
|
+
types_1.FunctionType.addDefaultParameters(newFunction);
|
1321
|
+
typeVarContext.setTypeVarType(destType.details.paramSpec, newFunction);
|
1247
1322
|
}
|
1248
1323
|
}
|
1249
1324
|
}
|
@@ -1290,10 +1365,10 @@ function buildTypeVarContext(typeParameters, typeArgs, typeVarScopeId) {
|
|
1290
1365
|
if (index < typeArgs.length) {
|
1291
1366
|
typeArgType = typeArgs[index];
|
1292
1367
|
if ((0, types_1.isFunction)(typeArgType) && types_1.FunctionType.isParamSpecValue(typeArgType)) {
|
1293
|
-
const
|
1368
|
+
const parameters = [];
|
1294
1369
|
const typeArgFunctionType = typeArgType;
|
1295
1370
|
typeArgType.details.parameters.forEach((param, paramIndex) => {
|
1296
|
-
|
1371
|
+
parameters.push({
|
1297
1372
|
category: param.category,
|
1298
1373
|
name: param.name,
|
1299
1374
|
hasDefault: !!param.hasDefault,
|
@@ -1302,32 +1377,10 @@ function buildTypeVarContext(typeParameters, typeArgs, typeVarScopeId) {
|
|
1302
1377
|
type: types_1.FunctionType.getEffectiveParameterType(typeArgFunctionType, paramIndex),
|
1303
1378
|
});
|
1304
1379
|
});
|
1305
|
-
typeVarContext.
|
1306
|
-
parameters: paramSpecEntries,
|
1307
|
-
typeVarScopeId: typeArgType.details.typeVarScopeId,
|
1308
|
-
flags: typeArgType.details.flags,
|
1309
|
-
docString: typeArgType.details.docString,
|
1310
|
-
paramSpec: typeArgType.details.paramSpec,
|
1311
|
-
});
|
1380
|
+
typeVarContext.setTypeVarType(typeParam, convertTypeToParamSpecValue(typeArgType));
|
1312
1381
|
}
|
1313
|
-
else if ((0, types_1.isParamSpec)(typeArgType)) {
|
1314
|
-
typeVarContext.
|
1315
|
-
flags: 0 /* None */,
|
1316
|
-
parameters: [],
|
1317
|
-
typeVarScopeId: undefined,
|
1318
|
-
docString: undefined,
|
1319
|
-
paramSpec: typeArgType,
|
1320
|
-
});
|
1321
|
-
}
|
1322
|
-
else if ((0, types_1.isAnyOrUnknown)(typeArgType)) {
|
1323
|
-
// Fill in an empty signature if the arg type is Any or Unknown.
|
1324
|
-
typeVarContext.setParamSpec(typeParam, {
|
1325
|
-
flags: 32768 /* SkipArgsKwargsCompatibilityCheck */,
|
1326
|
-
parameters: types_1.FunctionType.getDefaultParameters(),
|
1327
|
-
typeVarScopeId: undefined,
|
1328
|
-
docString: undefined,
|
1329
|
-
paramSpec: undefined,
|
1330
|
-
});
|
1382
|
+
else if ((0, types_1.isParamSpec)(typeArgType) || (0, types_1.isAnyOrUnknown)(typeArgType)) {
|
1383
|
+
typeVarContext.setTypeVarType(typeParam, convertTypeToParamSpecValue(typeArgType));
|
1331
1384
|
}
|
1332
1385
|
}
|
1333
1386
|
}
|
@@ -1465,6 +1518,10 @@ function convertToInstance(type, includeSubclasses = true) {
|
|
1465
1518
|
return convertToInstantiable(subtype.typeArguments[0]);
|
1466
1519
|
}
|
1467
1520
|
}
|
1521
|
+
// Handle NoneType as a special case.
|
1522
|
+
if (types_1.TypeBase.isInstantiable(subtype) && types_1.ClassType.isBuiltIn(subtype, 'NoneType')) {
|
1523
|
+
return types_1.NoneType.createInstance();
|
1524
|
+
}
|
1468
1525
|
return types_1.ClassType.cloneAsInstance(subtype, includeSubclasses);
|
1469
1526
|
}
|
1470
1527
|
case 3 /* None */: {
|
@@ -2093,20 +2150,48 @@ function addDeclaringModuleNamesForType(type, moduleList, recursionCount = 0) {
|
|
2093
2150
|
}
|
2094
2151
|
}
|
2095
2152
|
}
|
2096
|
-
function
|
2097
|
-
|
2098
|
-
|
2153
|
+
function convertTypeToParamSpecValue(type) {
|
2154
|
+
if ((0, types_1.isParamSpec)(type)) {
|
2155
|
+
const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* ParamSpecValue */);
|
2156
|
+
newFunction.details.paramSpec = type;
|
2157
|
+
newFunction.details.typeVarScopeId = getTypeVarScopeId(type);
|
2158
|
+
return newFunction;
|
2159
|
+
}
|
2160
|
+
if ((0, types_1.isFunction)(type)) {
|
2161
|
+
const newFunction = types_1.FunctionType.createInstance('', '', '', type.details.flags | 65536 /* ParamSpecValue */, type.details.docString);
|
2162
|
+
type.details.parameters.forEach((param, index) => {
|
2163
|
+
types_1.FunctionType.addParameter(newFunction, {
|
2164
|
+
category: param.category,
|
2165
|
+
name: param.name,
|
2166
|
+
hasDefault: param.hasDefault,
|
2167
|
+
defaultValueExpression: param.defaultValueExpression,
|
2168
|
+
isNameSynthesized: param.isNameSynthesized,
|
2169
|
+
type: types_1.FunctionType.getEffectiveParameterType(type, index),
|
2170
|
+
});
|
2171
|
+
});
|
2172
|
+
newFunction.details.typeVarScopeId = getTypeVarScopeId(type);
|
2173
|
+
newFunction.details.paramSpec = type.details.paramSpec;
|
2174
|
+
return newFunction;
|
2175
|
+
}
|
2176
|
+
const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* ParamSpecValue */ | 32768 /* SkipArgsKwargsCompatibilityCheck */);
|
2177
|
+
types_1.FunctionType.addDefaultParameters(newFunction);
|
2178
|
+
return newFunction;
|
2179
|
+
}
|
2180
|
+
exports.convertTypeToParamSpecValue = convertTypeToParamSpecValue;
|
2181
|
+
function convertParamSpecValueToType(paramSpecValue, omitParamSpec = false) {
|
2182
|
+
let hasParameters = paramSpecValue.details.parameters.length > 0;
|
2183
|
+
if (paramSpecValue.details.parameters.length === 1) {
|
2099
2184
|
// If the ParamSpec has a position-only separator as its only parameter,
|
2100
2185
|
// treat it as though there are no parameters.
|
2101
|
-
const onlyParam =
|
2186
|
+
const onlyParam = paramSpecValue.details.parameters[0];
|
2102
2187
|
if (onlyParam.category === 0 /* Simple */ && !onlyParam.name) {
|
2103
2188
|
hasParameters = false;
|
2104
2189
|
}
|
2105
2190
|
}
|
2106
|
-
if (hasParameters || !
|
2191
|
+
if (hasParameters || !paramSpecValue.details.paramSpec || omitParamSpec) {
|
2107
2192
|
// Create a function type from the param spec entries.
|
2108
|
-
const functionType = types_1.FunctionType.createInstance('', '', '', 65536 /* ParamSpecValue */ |
|
2109
|
-
|
2193
|
+
const functionType = types_1.FunctionType.createInstance('', '', '', 65536 /* ParamSpecValue */ | paramSpecValue.details.flags);
|
2194
|
+
paramSpecValue.details.parameters.forEach((entry) => {
|
2110
2195
|
types_1.FunctionType.addParameter(functionType, {
|
2111
2196
|
category: entry.category,
|
2112
2197
|
name: entry.name,
|
@@ -2118,12 +2203,12 @@ function convertParamSpecValueToType(paramSpecEntry, omitParamSpec = false) {
|
|
2118
2203
|
});
|
2119
2204
|
});
|
2120
2205
|
if (!omitParamSpec) {
|
2121
|
-
functionType.details.paramSpec =
|
2206
|
+
functionType.details.paramSpec = paramSpecValue.details.paramSpec;
|
2122
2207
|
}
|
2123
|
-
functionType.details.docString =
|
2208
|
+
functionType.details.docString = paramSpecValue.details.docString;
|
2124
2209
|
return functionType;
|
2125
2210
|
}
|
2126
|
-
return
|
2211
|
+
return paramSpecValue.details.paramSpec;
|
2127
2212
|
}
|
2128
2213
|
exports.convertParamSpecValueToType = convertParamSpecValueToType;
|
2129
2214
|
// Recursively walks a type and calls a callback for each TypeVar, allowing
|
@@ -2133,7 +2218,7 @@ class TypeVarTransformer {
|
|
2133
2218
|
this._isTransformingTypeArg = false;
|
2134
2219
|
this._pendingTypeVarTransformations = new Set();
|
2135
2220
|
}
|
2136
|
-
apply(type, recursionCount
|
2221
|
+
apply(type, recursionCount) {
|
2137
2222
|
var _a, _b;
|
2138
2223
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
2139
2224
|
return type;
|
@@ -2177,16 +2262,26 @@ class TypeVarTransformer {
|
|
2177
2262
|
// _pendingTypeVarTransformations set.
|
2178
2263
|
const typeVarName = types_1.TypeVarType.getNameWithScope(type);
|
2179
2264
|
if (!this._pendingTypeVarTransformations.has(typeVarName)) {
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
|
2184
|
-
|
2265
|
+
if (type.details.isParamSpec) {
|
2266
|
+
if (!type.paramSpecAccess) {
|
2267
|
+
const paramSpecValue = this.transformParamSpec(type, recursionCount);
|
2268
|
+
if (paramSpecValue) {
|
2269
|
+
replacementType = convertParamSpecValueToType(paramSpecValue);
|
2270
|
+
}
|
2271
|
+
}
|
2185
2272
|
}
|
2186
|
-
|
2187
|
-
|
2188
|
-
|
2189
|
-
|
2273
|
+
else {
|
2274
|
+
replacementType = (_b = this.transformTypeVar(type, recursionCount)) !== null && _b !== void 0 ? _b : type;
|
2275
|
+
if (!this._isTransformingTypeArg) {
|
2276
|
+
this._pendingTypeVarTransformations.add(typeVarName);
|
2277
|
+
replacementType = this.apply(replacementType, recursionCount);
|
2278
|
+
this._pendingTypeVarTransformations.delete(typeVarName);
|
2279
|
+
}
|
2280
|
+
// If we're transforming a variadic type variable that was in a union,
|
2281
|
+
// expand the union types.
|
2282
|
+
if ((0, types_1.isVariadicTypeVar)(type) && type.isVariadicInUnion) {
|
2283
|
+
replacementType = _expandVariadicUnpackedUnion(replacementType);
|
2284
|
+
}
|
2190
2285
|
}
|
2191
2286
|
}
|
2192
2287
|
return replacementType;
|
@@ -2204,7 +2299,7 @@ class TypeVarTransformer {
|
|
2204
2299
|
transformedType = (0, types_1.combineTypes)(subtypesToCombine);
|
2205
2300
|
}
|
2206
2301
|
if (this.transformUnionSubtype) {
|
2207
|
-
return this.transformUnionSubtype(subtype, transformedType);
|
2302
|
+
return this.transformUnionSubtype(subtype, transformedType, recursionCount);
|
2208
2303
|
}
|
2209
2304
|
return transformedType;
|
2210
2305
|
});
|
@@ -2232,16 +2327,16 @@ class TypeVarTransformer {
|
|
2232
2327
|
}
|
2233
2328
|
return type;
|
2234
2329
|
}
|
2235
|
-
transformTypeVar(typeVar) {
|
2330
|
+
transformTypeVar(typeVar, recursionCount) {
|
2236
2331
|
return typeVar;
|
2237
2332
|
}
|
2238
|
-
|
2333
|
+
transformTupleTypeVar(paramSpec, recursionCount) {
|
2239
2334
|
return undefined;
|
2240
2335
|
}
|
2241
|
-
transformParamSpec(paramSpec) {
|
2336
|
+
transformParamSpec(paramSpec, recursionCount) {
|
2242
2337
|
return undefined;
|
2243
2338
|
}
|
2244
|
-
transformUnionSubtype(preTransform, postTransform) {
|
2339
|
+
transformUnionSubtype(preTransform, postTransform, recursionCount) {
|
2245
2340
|
return postTransform;
|
2246
2341
|
}
|
2247
2342
|
_transformGenericTypeAlias(type, recursionCount) {
|
@@ -2266,11 +2361,11 @@ class TypeVarTransformer {
|
|
2266
2361
|
return classType;
|
2267
2362
|
}
|
2268
2363
|
let newTypeArgs = [];
|
2269
|
-
let
|
2364
|
+
let newTupleTypeArgs;
|
2270
2365
|
let specializationNeeded = false;
|
2271
2366
|
const typeParams = types_1.ClassType.getTypeParameters(classType);
|
2272
2367
|
const transformParamSpec = (paramSpec) => {
|
2273
|
-
const paramSpecValue = this.transformParamSpec(paramSpec);
|
2368
|
+
const paramSpecValue = this.transformParamSpec(paramSpec, recursionCount);
|
2274
2369
|
if (paramSpecValue) {
|
2275
2370
|
specializationNeeded = true;
|
2276
2371
|
return convertParamSpecValueToType(paramSpecValue);
|
@@ -2313,7 +2408,7 @@ class TypeVarTransformer {
|
|
2313
2408
|
else {
|
2314
2409
|
const typeParamName = types_1.TypeVarType.getNameWithScope(typeParam);
|
2315
2410
|
if (!this._pendingTypeVarTransformations.has(typeParamName)) {
|
2316
|
-
const transformedType = this.transformTypeVar(typeParam);
|
2411
|
+
const transformedType = this.transformTypeVar(typeParam, recursionCount);
|
2317
2412
|
replacementType = transformedType !== null && transformedType !== void 0 ? transformedType : typeParam;
|
2318
2413
|
if (replacementType !== typeParam) {
|
2319
2414
|
specializationNeeded = true;
|
@@ -2328,7 +2423,7 @@ class TypeVarTransformer {
|
|
2328
2423
|
}
|
2329
2424
|
if (types_1.ClassType.isTupleClass(classType)) {
|
2330
2425
|
if (classType.tupleTypeArguments) {
|
2331
|
-
|
2426
|
+
newTupleTypeArgs = [];
|
2332
2427
|
classType.tupleTypeArguments.forEach((oldTypeArgType) => {
|
2333
2428
|
const newTypeArgType = this.apply(oldTypeArgType.type, recursionCount);
|
2334
2429
|
if (newTypeArgType !== oldTypeArgType.type) {
|
@@ -2338,16 +2433,16 @@ class TypeVarTransformer {
|
|
2338
2433
|
(0, types_1.isClassInstance)(newTypeArgType) &&
|
2339
2434
|
isTupleClass(newTypeArgType) &&
|
2340
2435
|
newTypeArgType.tupleTypeArguments) {
|
2341
|
-
(0, collectionUtils_1.appendArray)(
|
2436
|
+
(0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.tupleTypeArguments);
|
2342
2437
|
}
|
2343
2438
|
else {
|
2344
|
-
|
2439
|
+
newTupleTypeArgs.push({ type: newTypeArgType, isUnbounded: oldTypeArgType.isUnbounded });
|
2345
2440
|
}
|
2346
2441
|
});
|
2347
2442
|
}
|
2348
2443
|
else if (typeParams.length > 0) {
|
2349
|
-
|
2350
|
-
if (
|
2444
|
+
newTupleTypeArgs = this.transformTupleTypeVar(typeParams[0], recursionCount);
|
2445
|
+
if (newTupleTypeArgs) {
|
2351
2446
|
specializationNeeded = true;
|
2352
2447
|
}
|
2353
2448
|
}
|
@@ -2359,13 +2454,13 @@ class TypeVarTransformer {
|
|
2359
2454
|
}
|
2360
2455
|
return types_1.ClassType.cloneForSpecialization(classType, newTypeArgs,
|
2361
2456
|
/* isTypeArgumentExplicit */ true,
|
2362
|
-
/* includeSubclasses */ undefined,
|
2457
|
+
/* includeSubclasses */ undefined, newTupleTypeArgs);
|
2363
2458
|
}
|
2364
2459
|
_transformTypeVarsInFunctionType(sourceType, recursionCount) {
|
2365
2460
|
let functionType = sourceType;
|
2366
2461
|
// Handle functions with a parameter specification in a special manner.
|
2367
2462
|
if (functionType.details.paramSpec) {
|
2368
|
-
const paramSpec = this.transformParamSpec(functionType.details.paramSpec);
|
2463
|
+
const paramSpec = this.transformParamSpec(functionType.details.paramSpec, recursionCount);
|
2369
2464
|
if (paramSpec) {
|
2370
2465
|
functionType = types_1.FunctionType.cloneForParamSpec(functionType, paramSpec);
|
2371
2466
|
}
|
@@ -2390,11 +2485,11 @@ class TypeVarTransformer {
|
|
2390
2485
|
(0, types_1.isParamSpec)(argsParamType) &&
|
2391
2486
|
(0, types_1.isParamSpec)(kwargsParamType) &&
|
2392
2487
|
(0, types_1.isTypeSame)(argsParamType, kwargsParamType)) {
|
2393
|
-
const paramSpecType = this.transformParamSpec(argsParamType);
|
2488
|
+
const paramSpecType = this.transformParamSpec(argsParamType, recursionCount);
|
2394
2489
|
if (paramSpecType) {
|
2395
|
-
if (paramSpecType.parameters.length > 0 ||
|
2396
|
-
paramSpecType.paramSpec === undefined ||
|
2397
|
-
!(0, types_1.isTypeSame)(argsParamType, paramSpecType.paramSpec)) {
|
2490
|
+
if (paramSpecType.details.parameters.length > 0 ||
|
2491
|
+
paramSpecType.details.paramSpec === undefined ||
|
2492
|
+
!(0, types_1.isTypeSame)(argsParamType, paramSpecType.details.paramSpec)) {
|
2398
2493
|
functionType = types_1.FunctionType.cloneForParamSpecApplication(functionType, paramSpecType);
|
2399
2494
|
}
|
2400
2495
|
}
|
@@ -2506,26 +2601,47 @@ class TypeVarTransformer {
|
|
2506
2601
|
return newFunctionType;
|
2507
2602
|
}
|
2508
2603
|
}
|
2604
|
+
// For a TypeVar with a default type, validates whether the default type is using
|
2605
|
+
// any other TypeVars that are not currently in scope.
|
2606
|
+
class TypeVarDefaultValidator extends TypeVarTransformer {
|
2607
|
+
constructor(_liveTypeParams, _invalidTypeVars) {
|
2608
|
+
super();
|
2609
|
+
this._liveTypeParams = _liveTypeParams;
|
2610
|
+
this._invalidTypeVars = _invalidTypeVars;
|
2611
|
+
}
|
2612
|
+
transformTypeVar(typeVar) {
|
2613
|
+
const replacementType = this._liveTypeParams.find((param) => param.details.name === typeVar.details.name);
|
2614
|
+
if (!replacementType || (0, types_1.isParamSpec)(replacementType)) {
|
2615
|
+
this._invalidTypeVars.add(typeVar.details.name);
|
2616
|
+
}
|
2617
|
+
return types_1.UnknownType.create();
|
2618
|
+
}
|
2619
|
+
transformParamSpec(paramSpec) {
|
2620
|
+
const replacementType = this._liveTypeParams.find((param) => param.details.name === paramSpec.details.name);
|
2621
|
+
if (!replacementType || !(0, types_1.isParamSpec)(replacementType)) {
|
2622
|
+
this._invalidTypeVars.add(paramSpec.details.name);
|
2623
|
+
}
|
2624
|
+
return undefined;
|
2625
|
+
}
|
2626
|
+
}
|
2509
2627
|
// Specializes a (potentially generic) type by substituting
|
2510
2628
|
// type variables from a type var map.
|
2511
2629
|
class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
2512
|
-
constructor(_typeVarContext,
|
2630
|
+
constructor(_typeVarContext, _options) {
|
2513
2631
|
super();
|
2514
2632
|
this._typeVarContext = _typeVarContext;
|
2515
|
-
this.
|
2516
|
-
this.
|
2517
|
-
this._eliminateUnsolvedInUnions = _eliminateUnsolvedInUnions;
|
2518
|
-
this._typeClassType = _typeClassType;
|
2633
|
+
this._options = _options;
|
2634
|
+
this._isSolvingDefaultType = false;
|
2519
2635
|
}
|
2520
|
-
transformTypeVar(typeVar) {
|
2636
|
+
transformTypeVar(typeVar, recursionCount) {
|
2521
2637
|
// If the type variable is unrelated to the scopes we're solving,
|
2522
2638
|
// don't transform that type variable.
|
2523
2639
|
if (typeVar.scopeId && this._typeVarContext.hasSolveForScope(typeVar.scopeId)) {
|
2524
|
-
let replacement = this._typeVarContext.getTypeVarType(typeVar, this.
|
2640
|
+
let replacement = this._typeVarContext.getTypeVarType(typeVar, !!this._options.useNarrowBoundOnly);
|
2525
2641
|
// If there was no narrow bound but there is a wide bound that
|
2526
2642
|
// contains literals, we'll use the wide bound even if "useNarrowBoundOnly"
|
2527
2643
|
// is specified.
|
2528
|
-
if (!replacement && this.
|
2644
|
+
if (!replacement && !!this._options.useNarrowBoundOnly) {
|
2529
2645
|
const wideType = this._typeVarContext.getTypeVarType(typeVar);
|
2530
2646
|
if (wideType) {
|
2531
2647
|
if (containsLiteralType(wideType, /* includeTypeArgs */ true)) {
|
@@ -2536,9 +2652,9 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2536
2652
|
if (replacement) {
|
2537
2653
|
if (types_1.TypeBase.isInstantiable(typeVar)) {
|
2538
2654
|
if ((0, types_1.isAnyOrUnknown)(replacement) &&
|
2539
|
-
this.
|
2540
|
-
(0, types_1.isInstantiableClass)(this.
|
2541
|
-
replacement = types_1.ClassType.cloneForSpecialization(types_1.ClassType.cloneAsInstance(this.
|
2655
|
+
this._options.typeClassType &&
|
2656
|
+
(0, types_1.isInstantiableClass)(this._options.typeClassType)) {
|
2657
|
+
replacement = types_1.ClassType.cloneForSpecialization(types_1.ClassType.cloneAsInstance(this._options.typeClassType), [replacement],
|
2542
2658
|
/* isTypeArgumentExplicit */ true);
|
2543
2659
|
}
|
2544
2660
|
else {
|
@@ -2550,13 +2666,40 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2550
2666
|
// If this typeVar is in scope for what we're solving but the type
|
2551
2667
|
// var map doesn't contain any entry for it, replace with the
|
2552
2668
|
// default or Unknown.
|
2553
|
-
if (this.
|
2554
|
-
if
|
2555
|
-
|
2669
|
+
if (this._options.unknownIfNotFound && !this._typeVarContext.hasSolveForScope(types_1.WildcardTypeVarScopeId)) {
|
2670
|
+
// Use the default value if there is one.
|
2671
|
+
if (typeVar.details.defaultType && !this._options.useUnknownOverDefault) {
|
2672
|
+
return this._solveDefaultType(typeVar.details.defaultType, recursionCount);
|
2556
2673
|
}
|
2557
2674
|
return types_1.UnknownType.create();
|
2558
2675
|
}
|
2559
2676
|
}
|
2677
|
+
// If we're solving a default type, handle type variables with no scope ID.
|
2678
|
+
if (this._isSolvingDefaultType && !typeVar.scopeId) {
|
2679
|
+
const replacementEntry = this._typeVarContext
|
2680
|
+
.getTypeVars()
|
2681
|
+
.find((entry) => entry.typeVar.details.name === typeVar.details.name);
|
2682
|
+
if (replacementEntry) {
|
2683
|
+
return this._typeVarContext.getTypeVarType(replacementEntry.typeVar);
|
2684
|
+
}
|
2685
|
+
if (typeVar.details.defaultType) {
|
2686
|
+
return this.apply(typeVar.details.defaultType, recursionCount);
|
2687
|
+
}
|
2688
|
+
return types_1.UnknownType.create();
|
2689
|
+
}
|
2690
|
+
// If we're solving a default type, handle type variables with no scope ID.
|
2691
|
+
if (this._isSolvingDefaultType && !typeVar.scopeId) {
|
2692
|
+
const replacementEntry = this._typeVarContext
|
2693
|
+
.getTypeVars()
|
2694
|
+
.find((entry) => entry.typeVar.details.name === typeVar.details.name);
|
2695
|
+
if (replacementEntry) {
|
2696
|
+
return this._typeVarContext.getTypeVarType(replacementEntry.typeVar);
|
2697
|
+
}
|
2698
|
+
if (typeVar.details.defaultType) {
|
2699
|
+
return this.apply(typeVar.details.defaultType, recursionCount);
|
2700
|
+
}
|
2701
|
+
return types_1.UnknownType.create();
|
2702
|
+
}
|
2560
2703
|
return undefined;
|
2561
2704
|
}
|
2562
2705
|
transformUnionSubtype(preTransform, postTransform) {
|
@@ -2565,7 +2708,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2565
2708
|
// in cases where TypeVars can go unsolved due to unions in parameter
|
2566
2709
|
// annotations, like this:
|
2567
2710
|
// def test(x: Union[str, T]) -> Union[str, T]
|
2568
|
-
if (this.
|
2711
|
+
if (this._options.eliminateUnsolvedInUnions) {
|
2569
2712
|
if ((0, types_1.isTypeVar)(preTransform) &&
|
2570
2713
|
preTransform.scopeId !== undefined &&
|
2571
2714
|
this._typeVarContext.hasSolveForScope(preTransform.scopeId)) {
|
@@ -2576,56 +2719,66 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
2576
2719
|
}
|
2577
2720
|
// If _unknownIfNotFound is true, the postTransform type will
|
2578
2721
|
// be Unknown, which we want to eliminate.
|
2579
|
-
if ((0, types_1.isUnknown)(postTransform) && this.
|
2722
|
+
if ((0, types_1.isUnknown)(postTransform) && this._options.unknownIfNotFound) {
|
2580
2723
|
return undefined;
|
2581
2724
|
}
|
2582
2725
|
}
|
2583
2726
|
}
|
2584
2727
|
return postTransform;
|
2585
2728
|
}
|
2586
|
-
|
2729
|
+
transformTupleTypeVar(typeVar) {
|
2587
2730
|
if (!typeVar.scopeId || !this._typeVarContext.hasSolveForScope(typeVar.scopeId)) {
|
2588
|
-
|
2589
|
-
|
2590
|
-
|
2591
|
-
return typeVar.details.defaultType.tupleTypeArguments;
|
2731
|
+
const defaultType = typeVar.details.defaultType;
|
2732
|
+
if (defaultType && (0, types_1.isClassInstance)(defaultType) && defaultType.tupleTypeArguments) {
|
2733
|
+
return defaultType.tupleTypeArguments;
|
2592
2734
|
}
|
2593
2735
|
return undefined;
|
2594
2736
|
}
|
2595
2737
|
return this._typeVarContext.getTupleTypeVar(typeVar);
|
2596
2738
|
}
|
2597
|
-
transformParamSpec(paramSpec) {
|
2739
|
+
transformParamSpec(paramSpec, recursionCount) {
|
2740
|
+
// If we're solving a default type, handle param specs with no scope ID.
|
2741
|
+
if (this._isSolvingDefaultType && !paramSpec.scopeId) {
|
2742
|
+
const replacementEntry = this._typeVarContext
|
2743
|
+
.getTypeVars()
|
2744
|
+
.find((entry) => entry.typeVar.details.name === paramSpec.details.name);
|
2745
|
+
if (replacementEntry) {
|
2746
|
+
return this._typeVarContext.getParamSpecType(replacementEntry.typeVar);
|
2747
|
+
}
|
2748
|
+
if (paramSpec.details.defaultType) {
|
2749
|
+
return convertTypeToParamSpecValue(this.apply(paramSpec.details.defaultType, recursionCount));
|
2750
|
+
}
|
2751
|
+
return this._getUnknownParamSpec();
|
2752
|
+
}
|
2598
2753
|
if (!paramSpec.scopeId || !this._typeVarContext.hasSolveForScope(paramSpec.scopeId)) {
|
2599
2754
|
return undefined;
|
2600
2755
|
}
|
2601
|
-
const transformedParamSpec = this._typeVarContext.
|
2756
|
+
const transformedParamSpec = this._typeVarContext.getParamSpecType(paramSpec);
|
2602
2757
|
if (transformedParamSpec) {
|
2603
2758
|
return transformedParamSpec;
|
2604
2759
|
}
|
2605
|
-
if (this.
|
2760
|
+
if (this._options.unknownIfNotFound && !this._typeVarContext.hasSolveForScope(types_1.WildcardTypeVarScopeId)) {
|
2606
2761
|
// Use the default value if there is one.
|
2607
|
-
if (paramSpec.details.defaultType
|
2608
|
-
|
2609
|
-
return {
|
2610
|
-
flags: funcType.details.flags,
|
2611
|
-
parameters: funcType.details.parameters,
|
2612
|
-
typeVarScopeId: funcType.details.typeVarScopeId,
|
2613
|
-
docString: funcType.details.docString,
|
2614
|
-
paramSpec: funcType.details.paramSpec,
|
2615
|
-
};
|
2762
|
+
if (paramSpec.details.defaultType) {
|
2763
|
+
return convertTypeToParamSpecValue(this._solveDefaultType(paramSpec.details.defaultType, recursionCount));
|
2616
2764
|
}
|
2617
2765
|
// Convert to the ParamSpec equivalent of "Unknown".
|
2618
|
-
|
2619
|
-
flags: 32768 /* SkipArgsKwargsCompatibilityCheck */,
|
2620
|
-
parameters: types_1.FunctionType.getDefaultParameters(/* useUnknown */ true),
|
2621
|
-
typeVarScopeId: undefined,
|
2622
|
-
docString: undefined,
|
2623
|
-
paramSpec: undefined,
|
2624
|
-
};
|
2625
|
-
return paramSpecValue;
|
2766
|
+
return this._getUnknownParamSpec();
|
2626
2767
|
}
|
2627
2768
|
return undefined;
|
2628
2769
|
}
|
2770
|
+
_solveDefaultType(defaultType, recursionCount) {
|
2771
|
+
const wasSolvingDefaultType = this._isSolvingDefaultType;
|
2772
|
+
this._isSolvingDefaultType = true;
|
2773
|
+
const result = this.apply(defaultType, recursionCount);
|
2774
|
+
this._isSolvingDefaultType = wasSolvingDefaultType;
|
2775
|
+
return result;
|
2776
|
+
}
|
2777
|
+
_getUnknownParamSpec() {
|
2778
|
+
const paramSpecValue = types_1.FunctionType.createInstance('', '', '', 65536 /* ParamSpecValue */ | 32768 /* SkipArgsKwargsCompatibilityCheck */);
|
2779
|
+
types_1.FunctionType.addDefaultParameters(paramSpecValue);
|
2780
|
+
return paramSpecValue;
|
2781
|
+
}
|
2629
2782
|
}
|
2630
2783
|
class ExpectedConstructorTypeTransformer extends TypeVarTransformer {
|
2631
2784
|
constructor(_liveTypeVarScopes) {
|