@zzzen/pyright-internal 1.2.0-dev.20240714 → 1.2.0-dev.20240721
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/checker.js +23 -21
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +26 -3
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +2 -2
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.d.ts +1 -2
- package/dist/analyzer/constructorTransform.js +4 -5
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +2 -2
- package/dist/analyzer/constructors.js +49 -147
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +1 -4
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/decorators.js +1 -2
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/operations.js +135 -86
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +2 -1
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -0
- package/dist/analyzer/parseTreeUtils.js +27 -4
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +2 -2
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/properties.js +4 -0
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +9 -5
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/testWalker.js +13 -1
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +710 -564
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +7 -4
- package/dist/analyzer/typeEvaluatorTypes.js +3 -0
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +3 -6
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +16 -12
- package/dist/analyzer/typeUtils.js +114 -46
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +1 -1
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +11 -7
- package/dist/analyzer/types.js +40 -9
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +1 -1
- package/dist/languageService/hoverProvider.js +11 -3
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +10 -4
- package/dist/languageService/referencesProvider.js +22 -10
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.js +21 -4
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +4 -3
- package/dist/localization/localize.js +2 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +0 -1
- package/dist/localization/package.nls.de.json +0 -1
- package/dist/localization/package.nls.en-us.json +2 -1
- package/dist/localization/package.nls.es.json +0 -1
- package/dist/localization/package.nls.fr.json +0 -1
- package/dist/localization/package.nls.it.json +0 -1
- package/dist/localization/package.nls.ja.json +0 -1
- package/dist/localization/package.nls.ko.json +0 -1
- package/dist/localization/package.nls.pl.json +0 -1
- package/dist/localization/package.nls.pt-br.json +0 -1
- package/dist/localization/package.nls.qps-ploc.json +0 -1
- package/dist/localization/package.nls.ru.json +0 -1
- package/dist/localization/package.nls.tr.json +0 -1
- package/dist/localization/package.nls.zh-cn.json +0 -1
- package/dist/localization/package.nls.zh-tw.json +0 -1
- package/dist/parser/parseNodes.d.ts +3 -1
- package/dist/parser/parseNodes.js +3 -1
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.js +36 -13
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/fourslash/rename.args.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.args.fourslash.js +71 -0
- package/dist/tests/fourslash/rename.args.fourslash.js.map +1 -0
- package/dist/tests/typeEvaluator1.test.js +17 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +10 -6
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +6 -2
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +7 -3
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/package.json +1 -1
@@ -9,8 +9,8 @@
|
|
9
9
|
*/
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
11
11
|
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.getUnknownTypeForVariadicTypeVar = exports.getUnknownTypeForParamSpec = exports.getUnknownTypeForTypeVar = 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.
|
13
|
-
exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.convertArgumentNodeToFunctionArgument = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgumentCompatible = void 0;
|
12
|
+
exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.specializeTupleClass = 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.buildTypeVarContext = exports.buildTypeVarContextFromSpecializedClass = exports.setTypeArgumentsRecursive = exports.specializeClassType = exports.getTypeVarArgumentsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = exports.lookUpClassMember = exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbolsRecursive = exports.getProtocolSymbols = exports.transformExpectedType = exports.replaceTypeVarsWithAny = exports.validateTypeVarDefault = exports.applyInScopePlaceholders = exports.applySourceContextTypeVarsToSignature = exports.applySourceContextTypeVars = exports.applySolvedTypeVars = exports.updateTypeWithExternalTypeVars = exports.updateTypeWithInternalTypeVars = exports.ensureFunctionSignaturesAreUnique = exports.populateTypeVarContextForSelfType = exports.partiallySpecializeType = exports.isTupleIndexUnambiguous = exports.isUnboundedTupleClass = exports.isTupleClass = void 0;
|
13
|
+
exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.convertArgumentNodeToFunctionArgument = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgumentCompatible = exports.combineVariances = exports.requiresSpecialization = void 0;
|
14
14
|
const collectionUtils_1 = require("../common/collectionUtils");
|
15
15
|
const debug_1 = require("../common/debug");
|
16
16
|
const symbol_1 = require("./symbol");
|
@@ -96,13 +96,13 @@ var AssignTypeFlags;
|
|
96
96
|
// as incompatible. Also, treat all source TypeVars as their
|
97
97
|
// concrete counterparts. This option is used for validating
|
98
98
|
// whether overload signatures overlap.
|
99
|
-
AssignTypeFlags[AssignTypeFlags["
|
99
|
+
AssignTypeFlags[AssignTypeFlags["OverloadOverlap"] = 16] = "OverloadOverlap";
|
100
100
|
// When used in conjunction with OverloadOverlapCheck, look
|
101
101
|
// for partial overlaps. For example, `int | list` overlaps
|
102
102
|
// partially with `int | str`.
|
103
|
-
AssignTypeFlags[AssignTypeFlags["
|
103
|
+
AssignTypeFlags[AssignTypeFlags["PartialOverloadOverlap"] = 32] = "PartialOverloadOverlap";
|
104
104
|
// For function types, skip the return type check.
|
105
|
-
AssignTypeFlags[AssignTypeFlags["
|
105
|
+
AssignTypeFlags[AssignTypeFlags["SkipReturnTypeCheck"] = 64] = "SkipReturnTypeCheck";
|
106
106
|
// Allow bool values to be assigned to TypeGuard[x] types.
|
107
107
|
AssignTypeFlags[AssignTypeFlags["AllowBoolTypeGuard"] = 128] = "AllowBoolTypeGuard";
|
108
108
|
// In most cases, literals are stripped when assigning to a
|
@@ -129,17 +129,13 @@ var AssignTypeFlags;
|
|
129
129
|
// default type arguments (typically "Unknown"). This flag skips
|
130
130
|
// this step.
|
131
131
|
AssignTypeFlags[AssignTypeFlags["AllowUnspecifiedTypeArguments"] = 8192] = "AllowUnspecifiedTypeArguments";
|
132
|
-
// PEP 544 says that if the dest type is a type[Proto] class,
|
133
|
-
// the source must be a "concrete" (non-protocol) class. This
|
134
|
-
// flag skips this check.
|
135
|
-
AssignTypeFlags[AssignTypeFlags["IgnoreProtocolAssignmentCheck"] = 16384] = "IgnoreProtocolAssignmentCheck";
|
136
132
|
// Normally all special form classes are incompatible with type[T],
|
137
133
|
// but a few of them are allowed in the context of an isinstance
|
138
134
|
// or issubclass call.
|
139
|
-
AssignTypeFlags[AssignTypeFlags["AllowIsinstanceSpecialForms"] =
|
135
|
+
AssignTypeFlags[AssignTypeFlags["AllowIsinstanceSpecialForms"] = 16384] = "AllowIsinstanceSpecialForms";
|
140
136
|
// When comparing two methods, skip the type check for the "self" or "cls"
|
141
137
|
// parameters. This is used for variance inference and validation.
|
142
|
-
AssignTypeFlags[AssignTypeFlags["
|
138
|
+
AssignTypeFlags[AssignTypeFlags["SkipSelfClsParamCheck"] = 32768] = "SkipSelfClsParamCheck";
|
143
139
|
})(AssignTypeFlags || (exports.AssignTypeFlags = AssignTypeFlags = {}));
|
144
140
|
// Tracks whether a function signature has been seen before within
|
145
141
|
// an expression. For example, in the expression "foo(foo, foo)", the
|
@@ -243,17 +239,18 @@ function isTypeVarSame(type1, type2) {
|
|
243
239
|
return isCompatible;
|
244
240
|
}
|
245
241
|
exports.isTypeVarSame = isTypeVarSame;
|
246
|
-
function makeInferenceContext(expectedType, isTypeIncomplete) {
|
242
|
+
function makeInferenceContext(expectedType, isTypeIncomplete, returnTypeOverride) {
|
247
243
|
if (!expectedType) {
|
248
244
|
return undefined;
|
249
245
|
}
|
250
|
-
return { expectedType, isTypeIncomplete };
|
246
|
+
return { expectedType, isTypeIncomplete, returnTypeOverride };
|
251
247
|
}
|
252
248
|
exports.makeInferenceContext = makeInferenceContext;
|
253
249
|
// Calls a callback for each subtype and combines the results
|
254
250
|
// into a final type. It performs no memory allocations if the
|
255
251
|
// transformed type is the same as the original.
|
256
252
|
function mapSubtypes(type, callback, options) {
|
253
|
+
var _a;
|
257
254
|
if ((0, types_1.isUnion)(type)) {
|
258
255
|
const subtypes = (options === null || options === void 0 ? void 0 : options.sortSubtypes) ? sortTypes(type.priv.subtypes) : type.priv.subtypes;
|
259
256
|
for (let i = 0; i < subtypes.length; i++) {
|
@@ -275,9 +272,16 @@ function mapSubtypes(type, callback, options) {
|
|
275
272
|
const newType = (0, types_1.combineTypes)(typesToCombine, {
|
276
273
|
skipElideRedundantLiterals: options === null || options === void 0 ? void 0 : options.skipElideRedundantLiterals,
|
277
274
|
});
|
278
|
-
|
279
|
-
|
280
|
-
|
275
|
+
if (options === null || options === void 0 ? void 0 : options.retainTypeAlias) {
|
276
|
+
if ((_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) {
|
277
|
+
types_1.TypeBase.setTypeAliasInfo(newType, type.props.typeAliasInfo);
|
278
|
+
}
|
279
|
+
}
|
280
|
+
else {
|
281
|
+
// Do our best to retain type aliases.
|
282
|
+
if (newType.category === 8 /* TypeCategory.Union */) {
|
283
|
+
types_1.UnionType.addTypeAliasSource(newType, type);
|
284
|
+
}
|
281
285
|
}
|
282
286
|
return newType;
|
283
287
|
}
|
@@ -860,7 +864,9 @@ function selfSpecializeClass(type, options) {
|
|
860
864
|
if (type.priv.typeArguments && !(options === null || options === void 0 ? void 0 : options.overrideTypeArgs)) {
|
861
865
|
return type;
|
862
866
|
}
|
863
|
-
const typeParams = type.shared.typeParameters
|
867
|
+
const typeParams = type.shared.typeParameters.map((typeParam) => {
|
868
|
+
return (options === null || options === void 0 ? void 0 : options.useInternalTypeVars) ? types_1.TypeVarType.cloneWithInternalScopeId(typeParam) : typeParam;
|
869
|
+
});
|
864
870
|
return types_1.ClassType.cloneForSpecialization(type, typeParams, /* isTypeArgumentExplicit */ true);
|
865
871
|
}
|
866
872
|
exports.selfSpecializeClass = selfSpecializeClass;
|
@@ -1052,22 +1058,20 @@ function isTupleIndexUnambiguous(type, index) {
|
|
1052
1058
|
if (!type.priv.tupleTypeArguments) {
|
1053
1059
|
return false;
|
1054
1060
|
}
|
1061
|
+
const unboundedIndex = type.priv.tupleTypeArguments.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedVariadicTypeVar)(t.type));
|
1055
1062
|
if (index < 0) {
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
}
|
1060
|
-
let unambiguousIndexLimit = type.priv.tupleTypeArguments.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedVariadicTypeVar)(t.type));
|
1061
|
-
if (unambiguousIndexLimit < 0) {
|
1062
|
-
unambiguousIndexLimit = type.priv.tupleTypeArguments.length;
|
1063
|
+
const lowerIndexLimit = unboundedIndex < 0 ? 0 : unboundedIndex;
|
1064
|
+
index += type.priv.tupleTypeArguments.length;
|
1065
|
+
return index >= lowerIndexLimit;
|
1063
1066
|
}
|
1064
|
-
|
1067
|
+
const upperIndexLimit = unboundedIndex < 0 ? type.priv.tupleTypeArguments.length : unboundedIndex;
|
1068
|
+
return index < upperIndexLimit;
|
1065
1069
|
}
|
1066
1070
|
exports.isTupleIndexUnambiguous = isTupleIndexUnambiguous;
|
1067
1071
|
// Partially specializes a type within the context of a specified
|
1068
1072
|
// (presumably specialized) class. Optionally specializes the `Self`
|
1069
1073
|
// type variables, replacing them with selfClass.
|
1070
|
-
function partiallySpecializeType(type, contextClassType,
|
1074
|
+
function partiallySpecializeType(type, contextClassType, typeClassType, selfClass) {
|
1071
1075
|
// If the context class is not specialized (or doesn't need specialization),
|
1072
1076
|
// then there's no need to do any more work.
|
1073
1077
|
if (types_1.ClassType.isUnspecialized(contextClassType) && !selfClass) {
|
@@ -1088,7 +1092,7 @@ function partiallySpecializeType(type, contextClassType, selfClass, typeClassTyp
|
|
1088
1092
|
return undefined;
|
1089
1093
|
}
|
1090
1094
|
return {
|
1091
|
-
methodType: partiallySpecializeType(methodInfo.methodType, contextClassType,
|
1095
|
+
methodType: partiallySpecializeType(methodInfo.methodType, contextClassType, typeClassType, selfClass),
|
1092
1096
|
classType: methodInfo.classType,
|
1093
1097
|
};
|
1094
1098
|
}
|
@@ -1126,6 +1130,16 @@ function ensureFunctionSignaturesAreUnique(type, signatureTracker, expressionOff
|
|
1126
1130
|
return transformer.apply(type, 0);
|
1127
1131
|
}
|
1128
1132
|
exports.ensureFunctionSignaturesAreUnique = ensureFunctionSignaturesAreUnique;
|
1133
|
+
function updateTypeWithInternalTypeVars(type, scopeIds) {
|
1134
|
+
const transformer = new InternalScopeUpdateTransform(scopeIds);
|
1135
|
+
return transformer.apply(type, 0);
|
1136
|
+
}
|
1137
|
+
exports.updateTypeWithInternalTypeVars = updateTypeWithInternalTypeVars;
|
1138
|
+
function updateTypeWithExternalTypeVars(type, scopeIds) {
|
1139
|
+
const transformer = new ExternalScopeUpdateTransform(scopeIds);
|
1140
|
+
return transformer.apply(type, 0);
|
1141
|
+
}
|
1142
|
+
exports.updateTypeWithExternalTypeVars = updateTypeWithExternalTypeVars;
|
1129
1143
|
// Specializes a (potentially generic) type by substituting
|
1130
1144
|
// type variables from a type var map.
|
1131
1145
|
function applySolvedTypeVars(type, typeVarContext, options = {}) {
|
@@ -1487,7 +1501,7 @@ function* getClassIterator(classType, flags = 0 /* ClassIteratorFlags.Default */
|
|
1487
1501
|
}
|
1488
1502
|
// If mroClass is an ancestor of classType, partially specialize
|
1489
1503
|
// it in the context of classType.
|
1490
|
-
const specializedMroClass = partiallySpecializeType(mroClass, classType);
|
1504
|
+
const specializedMroClass = partiallySpecializeType(mroClass, classType, /* typeClassType */ undefined);
|
1491
1505
|
// Should we ignore members on the 'object' base class?
|
1492
1506
|
if (flags & 2 /* ClassIteratorFlags.SkipObjectBaseClass */) {
|
1493
1507
|
if ((0, types_1.isInstantiableClass)(specializedMroClass)) {
|
@@ -1517,7 +1531,7 @@ function getClassFieldsRecursive(classType) {
|
|
1517
1531
|
const memberMap = new Map();
|
1518
1532
|
// Evaluate the types of members from the end of the MRO to the beginning.
|
1519
1533
|
types_1.ClassType.getReverseMro(classType).forEach((mroClass) => {
|
1520
|
-
const specializedMroClass = partiallySpecializeType(mroClass, classType);
|
1534
|
+
const specializedMroClass = partiallySpecializeType(mroClass, classType, /* typeClassType */ undefined);
|
1521
1535
|
if ((0, types_1.isClass)(specializedMroClass)) {
|
1522
1536
|
types_1.ClassType.getSymbolTable(specializedMroClass).forEach((symbol, name) => {
|
1523
1537
|
if (!symbol.isIgnoredForProtocolMatch() && symbol.hasTypedDeclarations()) {
|
@@ -1785,7 +1799,8 @@ function synthesizeTypeVarForSelfCls(classType, isClsParam) {
|
|
1785
1799
|
selfType.shared.isSynthesizedSelf = true;
|
1786
1800
|
selfType.priv.nameWithScope = types_1.TypeVarType.makeNameWithScope(selfType.shared.name, scopeId);
|
1787
1801
|
selfType.priv.scopeId = scopeId;
|
1788
|
-
const boundType = types_1.ClassType.cloneForSpecialization(classType,
|
1802
|
+
const boundType = types_1.ClassType.cloneForSpecialization(classType,
|
1803
|
+
/* typeArguments */ undefined,
|
1789
1804
|
/* isTypeArgumentExplicit */ false,
|
1790
1805
|
/* includeSubclasses */ !!classType.priv.includeSubclasses);
|
1791
1806
|
selfType.shared.boundType = types_1.ClassType.cloneAsInstance(boundType);
|
@@ -2821,7 +2836,7 @@ class TypeVarTransformer {
|
|
2821
2836
|
return this.transformUnionSubtype(subtype, transformedType, recursionCount);
|
2822
2837
|
}
|
2823
2838
|
return transformedType;
|
2824
|
-
});
|
2839
|
+
}, { retainTypeAlias: true });
|
2825
2840
|
return !(0, types_1.isNever)(newUnionType) ? newUnionType : types_1.UnknownType.create();
|
2826
2841
|
}
|
2827
2842
|
if ((0, types_1.isClass)(type)) {
|
@@ -3236,9 +3251,6 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
|
3236
3251
|
return classType;
|
3237
3252
|
}
|
3238
3253
|
transformTypeVarsInFunctionType(sourceType, recursionCount) {
|
3239
|
-
if (sourceType.priv.trackedSignatures) {
|
3240
|
-
this._signatureTracker.addTrackedSignatures(sourceType.priv.trackedSignatures);
|
3241
|
-
}
|
3242
3254
|
// If this function is not generic, there's no need to check for uniqueness.
|
3243
3255
|
if (sourceType.shared.typeParameters.length === 0) {
|
3244
3256
|
return super.transformTypeVarsInFunctionType(sourceType, recursionCount);
|
@@ -3271,6 +3283,58 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
|
3271
3283
|
return updatedSourceType;
|
3272
3284
|
}
|
3273
3285
|
}
|
3286
|
+
// Replaces the TypeVars within a type with their corresponding "internal"
|
3287
|
+
// types if they are in one of the specified scopes.
|
3288
|
+
class InternalScopeUpdateTransform extends TypeVarTransformer {
|
3289
|
+
constructor(_scopeIds) {
|
3290
|
+
super();
|
3291
|
+
this._scopeIds = _scopeIds;
|
3292
|
+
}
|
3293
|
+
transformTypeVar(typeVar) {
|
3294
|
+
if (this._isTypeVarInScope(typeVar)) {
|
3295
|
+
return this._replaceTypeVar(typeVar);
|
3296
|
+
}
|
3297
|
+
return undefined;
|
3298
|
+
}
|
3299
|
+
transformParamSpec(paramSpec) {
|
3300
|
+
if (this._isTypeVarInScope(paramSpec)) {
|
3301
|
+
return convertTypeToParamSpecValue(this._replaceTypeVar(paramSpec));
|
3302
|
+
}
|
3303
|
+
return undefined;
|
3304
|
+
}
|
3305
|
+
_isTypeVarInScope(typeVar) {
|
3306
|
+
return typeVar.priv.scopeId !== undefined && this._scopeIds.includes(typeVar.priv.scopeId);
|
3307
|
+
}
|
3308
|
+
_replaceTypeVar(typeVar) {
|
3309
|
+
return types_1.TypeVarType.cloneWithInternalScopeId(typeVar);
|
3310
|
+
}
|
3311
|
+
}
|
3312
|
+
// Replaces the internal TypeVars within a type with their corresponding
|
3313
|
+
// "external" types.
|
3314
|
+
class ExternalScopeUpdateTransform extends TypeVarTransformer {
|
3315
|
+
constructor(_scopeIds) {
|
3316
|
+
super();
|
3317
|
+
this._scopeIds = _scopeIds;
|
3318
|
+
}
|
3319
|
+
transformTypeVar(typeVar) {
|
3320
|
+
if (typeVar.priv.externalTypeVar && this._isTypeVarInScope(typeVar.priv.externalTypeVar)) {
|
3321
|
+
return typeVar.priv.externalTypeVar;
|
3322
|
+
}
|
3323
|
+
return undefined;
|
3324
|
+
}
|
3325
|
+
transformParamSpec(paramSpec) {
|
3326
|
+
if (paramSpec.priv.externalTypeVar && this._isTypeVarInScope(paramSpec.priv.externalTypeVar)) {
|
3327
|
+
return convertTypeToParamSpecValue(paramSpec.priv.externalTypeVar);
|
3328
|
+
}
|
3329
|
+
return undefined;
|
3330
|
+
}
|
3331
|
+
_isTypeVarInScope(typeVar) {
|
3332
|
+
if (!typeVar.priv.scopeId) {
|
3333
|
+
return false;
|
3334
|
+
}
|
3335
|
+
return this._scopeIds.includes(typeVar.priv.scopeId);
|
3336
|
+
}
|
3337
|
+
}
|
3274
3338
|
// Specializes a (potentially generic) type by substituting
|
3275
3339
|
// type variables from a type var map.
|
3276
3340
|
class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
@@ -3322,10 +3386,12 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3322
3386
|
if (!subtype.priv.includeSubclasses) {
|
3323
3387
|
subtype = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneAsInstantiable(subtype));
|
3324
3388
|
}
|
3325
|
-
if (
|
3326
|
-
|
3327
|
-
|
3328
|
-
|
3389
|
+
if (subtype.shared.typeParameters && !subtype.priv.typeArguments) {
|
3390
|
+
if (this._options.unknownIfNotFound) {
|
3391
|
+
return this._options.useUnknownOverDefault
|
3392
|
+
? specializeWithUnknownTypeArgs(subtype, this._options.tupleClassType)
|
3393
|
+
: specializeWithDefaultTypeArgs(subtype);
|
3394
|
+
}
|
3329
3395
|
}
|
3330
3396
|
}
|
3331
3397
|
return subtype;
|
@@ -3357,7 +3423,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3357
3423
|
if (useDefaultOrUnknown) {
|
3358
3424
|
// Use the default value if there is one.
|
3359
3425
|
if (typeVar.shared.isDefaultExplicit && !this._options.useUnknownOverDefault) {
|
3360
|
-
return this._solveDefaultType(typeVar
|
3426
|
+
return this._solveDefaultType(typeVar, recursionCount);
|
3361
3427
|
}
|
3362
3428
|
return getUnknownTypeForTypeVar(typeVar, this._options.tupleClassType);
|
3363
3429
|
}
|
@@ -3457,7 +3523,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3457
3523
|
if (useDefaultOrUnknown) {
|
3458
3524
|
// Use the default value if there is one.
|
3459
3525
|
if (paramSpec.shared.isDefaultExplicit && !this._options.useUnknownOverDefault) {
|
3460
|
-
return convertTypeToParamSpecValue(this._solveDefaultType(paramSpec
|
3526
|
+
return convertTypeToParamSpecValue(this._solveDefaultType(paramSpec, recursionCount));
|
3461
3527
|
}
|
3462
3528
|
// Convert to the ParamSpec equivalent of "Unknown".
|
3463
3529
|
return getUnknownTypeForParamSpec();
|
@@ -3465,7 +3531,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3465
3531
|
return undefined;
|
3466
3532
|
}
|
3467
3533
|
transformConditionalType(type, recursionCount) {
|
3468
|
-
var _a, _b;
|
3534
|
+
var _a, _b, _c, _d;
|
3469
3535
|
if (!((_a = type.props) === null || _a === void 0 ? void 0 : _a.condition)) {
|
3470
3536
|
return type;
|
3471
3537
|
}
|
@@ -3475,7 +3541,8 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3475
3541
|
if (condition.typeVar.shared.constraints.length === 0) {
|
3476
3542
|
continue;
|
3477
3543
|
}
|
3478
|
-
const
|
3544
|
+
const conditionTypeVar = (_d = (_c = condition.typeVar.priv) === null || _c === void 0 ? void 0 : _c.externalTypeVar) !== null && _d !== void 0 ? _d : condition.typeVar;
|
3545
|
+
const typeVarEntry = signatureContext.getTypeVar(conditionTypeVar);
|
3479
3546
|
if (!typeVarEntry || condition.constraintIndex >= typeVarEntry.typeVar.shared.constraints.length) {
|
3480
3547
|
continue;
|
3481
3548
|
}
|
@@ -3515,7 +3582,8 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3515
3582
|
}
|
3516
3583
|
return types_1.OverloadedFunctionType.create(filteredOverloads);
|
3517
3584
|
}
|
3518
|
-
_solveDefaultType(
|
3585
|
+
_solveDefaultType(typeVar, recursionCount) {
|
3586
|
+
const defaultType = typeVar.shared.defaultType;
|
3519
3587
|
const wasSolvingDefaultType = this._isSolvingDefaultType;
|
3520
3588
|
this._isSolvingDefaultType = true;
|
3521
3589
|
const result = this.apply(defaultType, recursionCount);
|
@@ -3533,7 +3601,7 @@ class ExpectedTypeTransformer extends TypeVarTransformer {
|
|
3533
3601
|
if (!this._isTypeVarLive(typeVar)) {
|
3534
3602
|
return types_1.TypeVarType.cloneAsInScopePlaceholder(typeVar, this._usageOffset);
|
3535
3603
|
}
|
3536
|
-
return
|
3604
|
+
return undefined;
|
3537
3605
|
}
|
3538
3606
|
transformParamSpec(paramSpec) {
|
3539
3607
|
if (!this._isTypeVarLive(paramSpec)) {
|
@@ -3542,7 +3610,7 @@ class ExpectedTypeTransformer extends TypeVarTransformer {
|
|
3542
3610
|
return undefined;
|
3543
3611
|
}
|
3544
3612
|
_isTypeVarLive(typeVar) {
|
3545
|
-
return this._liveTypeVarScopes.some((scopeId) => typeVar.priv.scopeId === scopeId);
|
3613
|
+
return this._liveTypeVarScopes.some((scopeId) => { var _a; return typeVar.priv.scopeId === scopeId || ((_a = typeVar.priv.externalTypeVar) === null || _a === void 0 ? void 0 : _a.priv.scopeId) === scopeId; });
|
3546
3614
|
}
|
3547
3615
|
}
|
3548
3616
|
class InScopePlaceholderTransformer extends TypeVarTransformer {
|
@@ -3555,7 +3623,7 @@ class InScopePlaceholderTransformer extends TypeVarTransformer {
|
|
3555
3623
|
if (typeVar.priv.isInScopePlaceholder) {
|
3556
3624
|
return (_a = this._signatureContext.getTypeVarType(typeVar)) !== null && _a !== void 0 ? _a : typeVar;
|
3557
3625
|
}
|
3558
|
-
return
|
3626
|
+
return undefined;
|
3559
3627
|
}
|
3560
3628
|
transformParamSpec(paramSpec) {
|
3561
3629
|
if (paramSpec.priv.isInScopePlaceholder) {
|