@zzzen/pyright-internal 1.2.0-dev.20240707 → 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/analyzerNodeInfo.js +74 -46
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/binder.js +506 -512
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +672 -655
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +5 -3
- package/dist/analyzer/codeFlowEngine.js +112 -103
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.js +30 -28
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +70 -66
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.d.ts +1 -2
- package/dist/analyzer/constructorTransform.js +26 -27
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +2 -2
- package/dist/analyzer/constructors.js +95 -190
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +110 -179
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +14 -15
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +78 -79
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.js +70 -56
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/functionTransform.js +8 -18
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +2 -1
- package/dist/analyzer/importResolver.js +40 -29
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +27 -27
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +33 -59
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +194 -145
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +66 -62
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +4 -4
- package/dist/analyzer/parameterUtils.js +30 -47
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -0
- package/dist/analyzer/parseTreeUtils.js +294 -272
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +76 -76
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.js +178 -145
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +1 -1
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +82 -147
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +29 -25
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceFile.js +3 -3
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +20 -19
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +83 -84
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/testWalker.js +15 -3
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +20 -20
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +25 -25
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +2443 -2350
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +13 -9
- package/dist/analyzer/typeEvaluatorTypes.js +7 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +212 -215
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +118 -115
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +104 -103
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +30 -15
- package/dist/analyzer/typeUtils.js +534 -436
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +8 -8
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typeWalker.js +13 -10
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.js +97 -199
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +152 -106
- package/dist/analyzer/types.js +695 -496
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +34 -34
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/fileSystem.d.ts +1 -0
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/fullAccessHost.js +6 -4
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +1 -0
- package/dist/common/realFileSystem.js +4 -0
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/textEditTracker.js +14 -14
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/languageService/autoImporter.js +10 -10
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +23 -23
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +153 -151
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +1 -1
- package/dist/languageService/definitionProvider.js +3 -1
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +19 -19
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.js +36 -27
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importSorter.js +8 -8
- package/dist/languageService/importSorter.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +10 -4
- package/dist/languageService/referencesProvider.js +30 -18
- 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/languageService/signatureHelpProvider.d.ts +1 -1
- package/dist/languageService/signatureHelpProvider.js +6 -6
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.js +3 -3
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +13 -13
- package/dist/languageService/tooltipUtils.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 +471 -402
- package/dist/parser/parseNodes.js +629 -356
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +1 -0
- package/dist/parser/parser.js +345 -300
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/classDeclaration.test.js +14 -14
- package/dist/tests/classDeclaration.test.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/harness/vfs/filesystem.d.ts +3 -2
- package/dist/tests/harness/vfs/filesystem.js +6 -2
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importResolver.test.js +4 -3
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +5 -5
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/parser.test.js +8 -8
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +7 -7
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- 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/typeEvaluator3.test.js +8 -3
- package/dist/tests/typeEvaluator3.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/dist/tests/typePrinter.test.js +14 -39
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/package.json +1 -1
@@ -8,9 +8,9 @@
|
|
8
8
|
* Functions that operate on Type objects.
|
9
9
|
*/
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
11
|
-
exports.
|
12
|
-
exports.
|
13
|
-
exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = exports.computeMroLinearization = void 0;
|
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.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
|
@@ -164,8 +160,8 @@ class UniqueSignatureTracker {
|
|
164
160
|
findSignature(signature) {
|
165
161
|
// Use the associated overload type if this is a function associated with an overload.
|
166
162
|
let effectiveSignature = signature;
|
167
|
-
if ((0, types_1.isFunction)(signature) && signature.overloaded) {
|
168
|
-
effectiveSignature = signature.overloaded;
|
163
|
+
if ((0, types_1.isFunction)(signature) && signature.priv.overloaded) {
|
164
|
+
effectiveSignature = signature.priv.overloaded;
|
169
165
|
}
|
170
166
|
return this._trackedSignatures.find((s) => {
|
171
167
|
return (0, types_1.isTypeSame)(effectiveSignature, s.type);
|
@@ -174,7 +170,7 @@ class UniqueSignatureTracker {
|
|
174
170
|
addSignature(signature, offset) {
|
175
171
|
var _a;
|
176
172
|
// If this function is part of a broader overload, use the overload instead.
|
177
|
-
const effectiveSignature = (0, types_1.isFunction)(signature) ? (_a = signature.overloaded) !== null && _a !== void 0 ? _a : signature : signature;
|
173
|
+
const effectiveSignature = (0, types_1.isFunction)(signature) ? (_a = signature.priv.overloaded) !== null && _a !== void 0 ? _a : signature : signature;
|
178
174
|
const existingSignature = this.findSignature(effectiveSignature);
|
179
175
|
if (existingSignature) {
|
180
176
|
if (!existingSignature.expressionOffsets.some((o) => o === offset)) {
|
@@ -209,7 +205,7 @@ function removeNoneFromUnion(type) {
|
|
209
205
|
}
|
210
206
|
exports.removeNoneFromUnion = removeNoneFromUnion;
|
211
207
|
function isIncompleteUnknown(type) {
|
212
|
-
return (0, types_1.isUnknown)(type) && type.isIncomplete;
|
208
|
+
return (0, types_1.isUnknown)(type) && type.priv.isIncomplete;
|
213
209
|
}
|
214
210
|
exports.isIncompleteUnknown = isIncompleteUnknown;
|
215
211
|
// Similar to isTypeSame except that type1 is a TypeVar and type2
|
@@ -220,7 +216,7 @@ function isTypeVarSame(type1, type2) {
|
|
220
216
|
return true;
|
221
217
|
}
|
222
218
|
// If this isn't a bound TypeVar, return false.
|
223
|
-
if (type1.
|
219
|
+
if (type1.shared.isParamSpec || type1.shared.isVariadic || !type1.shared.boundType) {
|
224
220
|
return false;
|
225
221
|
}
|
226
222
|
// If the second type isn't a union, return false.
|
@@ -235,7 +231,7 @@ function isTypeVarSame(type1, type2) {
|
|
235
231
|
if (!(0, types_1.isTypeSame)(type1, subtype)) {
|
236
232
|
const conditions = getTypeCondition(subtype);
|
237
233
|
if (!conditions ||
|
238
|
-
!conditions.some((condition) => condition.typeVar.nameWithScope === type1.nameWithScope)) {
|
234
|
+
!conditions.some((condition) => condition.typeVar.priv.nameWithScope === type1.priv.nameWithScope)) {
|
239
235
|
isCompatible = false;
|
240
236
|
}
|
241
237
|
}
|
@@ -243,19 +239,20 @@ 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
|
-
function mapSubtypes(type, callback,
|
252
|
+
function mapSubtypes(type, callback, options) {
|
253
|
+
var _a;
|
257
254
|
if ((0, types_1.isUnion)(type)) {
|
258
|
-
const subtypes = sortSubtypes ? sortTypes(type.subtypes) : type.subtypes;
|
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++) {
|
260
257
|
const subtype = subtypes[i];
|
261
258
|
const transformedType = callback(subtype);
|
@@ -272,10 +269,19 @@ function mapSubtypes(type, callback, sortSubtypes = false) {
|
|
272
269
|
for (i++; i < subtypes.length; i++) {
|
273
270
|
accumulateSubtype(callback(subtypes[i]));
|
274
271
|
}
|
275
|
-
const newType = (0, types_1.combineTypes)(typesToCombine
|
276
|
-
|
277
|
-
|
278
|
-
|
272
|
+
const newType = (0, types_1.combineTypes)(typesToCombine, {
|
273
|
+
skipElideRedundantLiterals: options === null || options === void 0 ? void 0 : options.skipElideRedundantLiterals,
|
274
|
+
});
|
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
|
+
}
|
279
285
|
}
|
280
286
|
return newType;
|
281
287
|
}
|
@@ -293,12 +299,12 @@ exports.mapSubtypes = mapSubtypes;
|
|
293
299
|
// caller to replace one or more signatures with new ones.
|
294
300
|
function mapSignatures(type, callback) {
|
295
301
|
if ((0, types_1.isFunction)(type)) {
|
296
|
-
return callback(type
|
302
|
+
return callback(type);
|
297
303
|
}
|
298
304
|
const newSignatures = [];
|
299
305
|
let changeMade = false;
|
300
306
|
types_1.OverloadedFunctionType.getOverloads(type).forEach((overload, index) => {
|
301
|
-
const newOverload = callback(overload
|
307
|
+
const newOverload = callback(overload);
|
302
308
|
if (newOverload !== overload) {
|
303
309
|
changeMade = true;
|
304
310
|
}
|
@@ -312,7 +318,11 @@ function mapSignatures(type, callback) {
|
|
312
318
|
// Add the unmodified implementation if it's present.
|
313
319
|
const implementation = types_1.OverloadedFunctionType.getImplementation(type);
|
314
320
|
if (implementation) {
|
315
|
-
|
321
|
+
const newImplementation = callback(implementation);
|
322
|
+
if (newImplementation) {
|
323
|
+
changeMade = true;
|
324
|
+
newSignatures.push(newImplementation);
|
325
|
+
}
|
316
326
|
}
|
317
327
|
if (!changeMade) {
|
318
328
|
return type;
|
@@ -336,13 +346,13 @@ function cleanIncompleteUnknown(type, recursionCount = 0) {
|
|
336
346
|
recursionCount++;
|
337
347
|
const result = mapSubtypes(type, (subtype) => {
|
338
348
|
// If it's an incomplete unknown, eliminate it.
|
339
|
-
if ((0, types_1.isUnknown)(subtype) && subtype.isIncomplete) {
|
349
|
+
if ((0, types_1.isUnknown)(subtype) && subtype.priv.isIncomplete) {
|
340
350
|
return undefined;
|
341
351
|
}
|
342
|
-
if ((0, types_1.isClass)(subtype) && subtype.typeArguments) {
|
352
|
+
if ((0, types_1.isClass)(subtype) && subtype.priv.typeArguments) {
|
343
353
|
let typeChanged = false;
|
344
|
-
if (subtype.tupleTypeArguments) {
|
345
|
-
const updatedTupleTypeArgs = subtype.tupleTypeArguments.map((tupleTypeArg) => {
|
354
|
+
if (subtype.priv.tupleTypeArguments) {
|
355
|
+
const updatedTupleTypeArgs = subtype.priv.tupleTypeArguments.map((tupleTypeArg) => {
|
346
356
|
const newTypeArg = cleanIncompleteUnknown(tupleTypeArg.type, recursionCount);
|
347
357
|
if (newTypeArg !== tupleTypeArg.type) {
|
348
358
|
typeChanged = true;
|
@@ -354,11 +364,11 @@ function cleanIncompleteUnknown(type, recursionCount = 0) {
|
|
354
364
|
};
|
355
365
|
});
|
356
366
|
if (typeChanged) {
|
357
|
-
return specializeTupleClass(subtype, updatedTupleTypeArgs, !!subtype.isTypeArgumentExplicit, !!subtype.isUnpacked);
|
367
|
+
return specializeTupleClass(subtype, updatedTupleTypeArgs, !!subtype.priv.isTypeArgumentExplicit, !!subtype.priv.isUnpacked);
|
358
368
|
}
|
359
369
|
}
|
360
370
|
else {
|
361
|
-
const updatedTypeArgs = subtype.typeArguments.map((typeArg) => {
|
371
|
+
const updatedTypeArgs = subtype.priv.typeArguments.map((typeArg) => {
|
362
372
|
const newTypeArg = cleanIncompleteUnknown(typeArg, recursionCount);
|
363
373
|
if (newTypeArg !== typeArg) {
|
364
374
|
typeChanged = true;
|
@@ -366,7 +376,7 @@ function cleanIncompleteUnknown(type, recursionCount = 0) {
|
|
366
376
|
return newTypeArg;
|
367
377
|
});
|
368
378
|
if (typeChanged) {
|
369
|
-
return types_1.ClassType.cloneForSpecialization(subtype, updatedTypeArgs, !!subtype.isTypeArgumentExplicit);
|
379
|
+
return types_1.ClassType.cloneForSpecialization(subtype, updatedTypeArgs, !!subtype.priv.isTypeArgumentExplicit);
|
370
380
|
}
|
371
381
|
}
|
372
382
|
}
|
@@ -403,14 +413,14 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
403
413
|
}
|
404
414
|
case 4 /* TypeCategory.Function */: {
|
405
415
|
const bFunc = b;
|
406
|
-
const aParamCount = a.
|
407
|
-
const bParamCount = bFunc.
|
416
|
+
const aParamCount = a.shared.parameters.length;
|
417
|
+
const bParamCount = bFunc.shared.parameters.length;
|
408
418
|
if (aParamCount !== bParamCount) {
|
409
419
|
return bParamCount - aParamCount;
|
410
420
|
}
|
411
421
|
for (let i = 0; i < aParamCount; i++) {
|
412
|
-
const aParam = a.
|
413
|
-
const bParam = bFunc.
|
422
|
+
const aParam = a.shared.parameters[i];
|
423
|
+
const bParam = bFunc.shared.parameters[i];
|
414
424
|
if (aParam.category !== bParam.category) {
|
415
425
|
return bParam.category - aParam.category;
|
416
426
|
}
|
@@ -423,8 +433,8 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
423
433
|
if (returnTypeComparison !== 0) {
|
424
434
|
return returnTypeComparison;
|
425
435
|
}
|
426
|
-
const aName = a.
|
427
|
-
const bName = bFunc.
|
436
|
+
const aName = a.shared.name;
|
437
|
+
const bName = bFunc.shared.name;
|
428
438
|
if (aName < bName) {
|
429
439
|
return -1;
|
430
440
|
}
|
@@ -435,13 +445,13 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
435
445
|
}
|
436
446
|
case 5 /* TypeCategory.OverloadedFunction */: {
|
437
447
|
const bOver = b;
|
438
|
-
const aOverloadCount = a.overloads.length;
|
439
|
-
const bOverloadCount = bOver.overloads.length;
|
448
|
+
const aOverloadCount = a.priv.overloads.length;
|
449
|
+
const bOverloadCount = bOver.priv.overloads.length;
|
440
450
|
if (aOverloadCount !== bOverloadCount) {
|
441
451
|
return bOverloadCount - aOverloadCount;
|
442
452
|
}
|
443
453
|
for (let i = 0; i < aOverloadCount; i++) {
|
444
|
-
const typeComparison = compareTypes(a.overloads[i], bOver.overloads[i]);
|
454
|
+
const typeComparison = compareTypes(a.priv.overloads[i], bOver.priv.overloads[i]);
|
445
455
|
if (typeComparison !== 0) {
|
446
456
|
return typeComparison;
|
447
457
|
}
|
@@ -474,17 +484,17 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
474
484
|
return -1;
|
475
485
|
}
|
476
486
|
// Sort non-generics before generics.
|
477
|
-
if (a.
|
478
|
-
if (bClass.
|
487
|
+
if (a.shared.typeParameters.length > 0 || isTupleClass(a)) {
|
488
|
+
if (bClass.shared.typeParameters.length === 0) {
|
479
489
|
return 1;
|
480
490
|
}
|
481
491
|
}
|
482
|
-
else if (bClass.
|
492
|
+
else if (bClass.shared.typeParameters.length > 0 || isTupleClass(bClass)) {
|
483
493
|
return -1;
|
484
494
|
}
|
485
495
|
// Sort by class name.
|
486
|
-
const aName = a.
|
487
|
-
const bName = b.
|
496
|
+
const aName = a.shared.name;
|
497
|
+
const bName = b.shared.name;
|
488
498
|
if (aName < bName) {
|
489
499
|
return -1;
|
490
500
|
}
|
@@ -492,8 +502,8 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
492
502
|
return 1;
|
493
503
|
}
|
494
504
|
// Sort by type argument count.
|
495
|
-
const aTypeArgCount = a.typeArguments ? a.typeArguments.length : 0;
|
496
|
-
const bTypeArgCount = bClass.typeArguments ? bClass.typeArguments.length : 0;
|
505
|
+
const aTypeArgCount = a.priv.typeArguments ? a.priv.typeArguments.length : 0;
|
506
|
+
const bTypeArgCount = bClass.priv.typeArguments ? bClass.priv.typeArguments.length : 0;
|
497
507
|
if (aTypeArgCount < bTypeArgCount) {
|
498
508
|
return -1;
|
499
509
|
}
|
@@ -502,7 +512,7 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
502
512
|
}
|
503
513
|
// Sort by type argument.
|
504
514
|
for (let i = 0; i < aTypeArgCount; i++) {
|
505
|
-
const typeComparison = compareTypes(a.typeArguments[i], bClass.typeArguments[i], recursionCount);
|
515
|
+
const typeComparison = compareTypes(a.priv.typeArguments[i], bClass.priv.typeArguments[i], recursionCount);
|
506
516
|
if (typeComparison !== 0) {
|
507
517
|
return typeComparison;
|
508
518
|
}
|
@@ -510,13 +520,13 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
510
520
|
return 0;
|
511
521
|
}
|
512
522
|
case 7 /* TypeCategory.Module */: {
|
513
|
-
const aName = a.moduleName;
|
514
|
-
const bName = b.moduleName;
|
523
|
+
const aName = a.priv.moduleName;
|
524
|
+
const bName = b.priv.moduleName;
|
515
525
|
return aName < bName ? -1 : aName === bName ? 0 : 1;
|
516
526
|
}
|
517
527
|
case 9 /* TypeCategory.TypeVar */: {
|
518
|
-
const aName = a.
|
519
|
-
const bName = b.
|
528
|
+
const aName = a.shared.name;
|
529
|
+
const bName = b.shared.name;
|
520
530
|
return aName < bName ? -1 : aName === bName ? 0 : 1;
|
521
531
|
}
|
522
532
|
}
|
@@ -524,7 +534,7 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
524
534
|
}
|
525
535
|
function doForEachSubtype(type, callback, sortSubtypes = false) {
|
526
536
|
if ((0, types_1.isUnion)(type)) {
|
527
|
-
const subtypes = sortSubtypes ? sortTypes(type.subtypes) : type.subtypes;
|
537
|
+
const subtypes = sortSubtypes ? sortTypes(type.priv.subtypes) : type.priv.subtypes;
|
528
538
|
subtypes.forEach((subtype, index) => {
|
529
539
|
callback(subtype, index, subtypes);
|
530
540
|
});
|
@@ -536,7 +546,7 @@ function doForEachSubtype(type, callback, sortSubtypes = false) {
|
|
536
546
|
exports.doForEachSubtype = doForEachSubtype;
|
537
547
|
function someSubtypes(type, callback) {
|
538
548
|
if ((0, types_1.isUnion)(type)) {
|
539
|
-
return type.subtypes.some((subtype) => {
|
549
|
+
return type.priv.subtypes.some((subtype) => {
|
540
550
|
return callback(subtype);
|
541
551
|
});
|
542
552
|
}
|
@@ -547,7 +557,7 @@ function someSubtypes(type, callback) {
|
|
547
557
|
exports.someSubtypes = someSubtypes;
|
548
558
|
function allSubtypes(type, callback) {
|
549
559
|
if ((0, types_1.isUnion)(type)) {
|
550
|
-
return type.subtypes.every((subtype) => {
|
560
|
+
return type.priv.subtypes.every((subtype) => {
|
551
561
|
callback(subtype);
|
552
562
|
});
|
553
563
|
}
|
@@ -584,10 +594,10 @@ exports.areTypesSame = areTypesSame;
|
|
584
594
|
// the incomplete flag on the unknown if present. The caller should verify that
|
585
595
|
// one or the other type is Unknown or Any.
|
586
596
|
function preserveUnknown(type1, type2) {
|
587
|
-
if ((0, types_1.isUnknown)(type1) && type1.isIncomplete) {
|
597
|
+
if ((0, types_1.isUnknown)(type1) && type1.priv.isIncomplete) {
|
588
598
|
return type1;
|
589
599
|
}
|
590
|
-
else if ((0, types_1.isUnknown)(type2) && type2.isIncomplete) {
|
600
|
+
else if ((0, types_1.isUnknown)(type2) && type2.priv.isIncomplete) {
|
591
601
|
return type2;
|
592
602
|
}
|
593
603
|
else if ((0, types_1.isUnknown)(type1) || (0, types_1.isUnknown)(type2)) {
|
@@ -633,32 +643,33 @@ function derivesFromAnyOrUnknown(type) {
|
|
633
643
|
}
|
634
644
|
exports.derivesFromAnyOrUnknown = derivesFromAnyOrUnknown;
|
635
645
|
function getFullNameOfType(type) {
|
636
|
-
var _a;
|
637
|
-
if ((_a = type.
|
638
|
-
return type.typeAliasInfo.fullName;
|
646
|
+
var _a, _b;
|
647
|
+
if ((_b = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) === null || _b === void 0 ? void 0 : _b.fullName) {
|
648
|
+
return type.props.typeAliasInfo.fullName;
|
639
649
|
}
|
640
650
|
switch (type.category) {
|
641
651
|
case 2 /* TypeCategory.Any */:
|
642
652
|
case 1 /* TypeCategory.Unknown */:
|
643
653
|
return 'typing.Any';
|
644
654
|
case 6 /* TypeCategory.Class */:
|
645
|
-
return type.
|
655
|
+
return type.shared.fullName;
|
646
656
|
case 4 /* TypeCategory.Function */:
|
647
|
-
return type.
|
657
|
+
return type.shared.fullName;
|
648
658
|
case 7 /* TypeCategory.Module */:
|
649
|
-
return type.moduleName;
|
659
|
+
return type.priv.moduleName;
|
650
660
|
case 5 /* TypeCategory.OverloadedFunction */:
|
651
|
-
return type.overloads[0].
|
661
|
+
return type.priv.overloads[0].shared.fullName;
|
652
662
|
}
|
653
663
|
return undefined;
|
654
664
|
}
|
655
665
|
exports.getFullNameOfType = getFullNameOfType;
|
656
666
|
function addConditionToType(type, condition, skipSelfCondition = false) {
|
667
|
+
var _a, _b;
|
657
668
|
if (!condition) {
|
658
669
|
return type;
|
659
670
|
}
|
660
671
|
if (skipSelfCondition) {
|
661
|
-
condition = condition.filter((c) => !c.typeVar.
|
672
|
+
condition = condition.filter((c) => !c.typeVar.shared.isSynthesizedSelf);
|
662
673
|
if (condition.length === 0) {
|
663
674
|
return type;
|
664
675
|
}
|
@@ -672,17 +683,18 @@ function addConditionToType(type, condition, skipSelfCondition = false) {
|
|
672
683
|
case 9 /* TypeCategory.TypeVar */:
|
673
684
|
return type;
|
674
685
|
case 4 /* TypeCategory.Function */:
|
675
|
-
return types_1.TypeBase.cloneForCondition(type, types_1.TypeCondition.combine(type.condition, condition));
|
686
|
+
return types_1.TypeBase.cloneForCondition(type, types_1.TypeCondition.combine((_a = type.props) === null || _a === void 0 ? void 0 : _a.condition, condition));
|
676
687
|
case 5 /* TypeCategory.OverloadedFunction */:
|
677
|
-
return types_1.OverloadedFunctionType.create(type.overloads.map((t) => addConditionToType(t, condition)));
|
688
|
+
return types_1.OverloadedFunctionType.create(type.priv.overloads.map((t) => addConditionToType(t, condition)));
|
678
689
|
case 6 /* TypeCategory.Class */:
|
679
|
-
return types_1.TypeBase.cloneForCondition(type, types_1.TypeCondition.combine(type.condition, condition));
|
690
|
+
return types_1.TypeBase.cloneForCondition(type, types_1.TypeCondition.combine((_b = type.props) === null || _b === void 0 ? void 0 : _b.condition, condition));
|
680
691
|
case 8 /* TypeCategory.Union */:
|
681
|
-
return (0, types_1.combineTypes)(type.subtypes.map((t) => addConditionToType(t, condition)));
|
692
|
+
return (0, types_1.combineTypes)(type.priv.subtypes.map((t) => addConditionToType(t, condition)));
|
682
693
|
}
|
683
694
|
}
|
684
695
|
exports.addConditionToType = addConditionToType;
|
685
696
|
function getTypeCondition(type) {
|
697
|
+
var _a;
|
686
698
|
switch (type.category) {
|
687
699
|
case 0 /* TypeCategory.Unbound */:
|
688
700
|
case 1 /* TypeCategory.Unknown */:
|
@@ -695,7 +707,7 @@ function getTypeCondition(type) {
|
|
695
707
|
return undefined;
|
696
708
|
case 6 /* TypeCategory.Class */:
|
697
709
|
case 4 /* TypeCategory.Function */:
|
698
|
-
return type.condition;
|
710
|
+
return (_a = type.props) === null || _a === void 0 ? void 0 : _a.condition;
|
699
711
|
}
|
700
712
|
}
|
701
713
|
exports.getTypeCondition = getTypeCondition;
|
@@ -709,6 +721,7 @@ exports.isTypeAliasPlaceholder = isTypeAliasPlaceholder;
|
|
709
721
|
// within the specified type. It's OK if it's used indirectly as
|
710
722
|
// a type argument.
|
711
723
|
function isTypeAliasRecursive(typeAliasPlaceholder, type) {
|
724
|
+
var _a, _b;
|
712
725
|
if (type.category !== 8 /* TypeCategory.Union */) {
|
713
726
|
if (type === typeAliasPlaceholder) {
|
714
727
|
return true;
|
@@ -716,31 +729,32 @@ function isTypeAliasRecursive(typeAliasPlaceholder, type) {
|
|
716
729
|
// Handle the specific case where the type alias directly refers to itself.
|
717
730
|
// In this case, the type will be unbound because it could not be resolved.
|
718
731
|
return ((0, types_1.isUnbound)(type) &&
|
719
|
-
type.typeAliasInfo &&
|
720
|
-
type.typeAliasInfo.name === typeAliasPlaceholder.
|
732
|
+
((_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) &&
|
733
|
+
type.props.typeAliasInfo.name === ((_b = typeAliasPlaceholder.shared.recursiveAlias) === null || _b === void 0 ? void 0 : _b.name));
|
721
734
|
}
|
722
|
-
return ((0, types_1.findSubtype)(type, (subtype) => (0, types_1.isTypeVar)(subtype) && subtype.
|
735
|
+
return ((0, types_1.findSubtype)(type, (subtype) => (0, types_1.isTypeVar)(subtype) && subtype.shared === typeAliasPlaceholder.shared) !==
|
723
736
|
undefined);
|
724
737
|
}
|
725
738
|
exports.isTypeAliasRecursive = isTypeAliasRecursive;
|
726
739
|
function transformPossibleRecursiveTypeAlias(type) {
|
727
|
-
var _a;
|
740
|
+
var _a, _b;
|
728
741
|
if (type) {
|
729
|
-
|
742
|
+
const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
743
|
+
if ((0, types_1.isTypeVar)(type) && ((_b = type.shared.recursiveAlias) === null || _b === void 0 ? void 0 : _b.name) && type.shared.boundType) {
|
730
744
|
const unspecializedType = types_1.TypeBase.isInstance(type)
|
731
|
-
? convertToInstance(type.
|
732
|
-
: type.
|
733
|
-
if (!(
|
745
|
+
? convertToInstance(type.shared.boundType)
|
746
|
+
: type.shared.boundType;
|
747
|
+
if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments) || !type.shared.recursiveAlias.typeParameters) {
|
734
748
|
return unspecializedType;
|
735
749
|
}
|
736
|
-
const typeVarContext = buildTypeVarContext(type.
|
750
|
+
const typeVarContext = buildTypeVarContext(type.shared.recursiveAlias.typeParameters, aliasInfo.typeArguments, getTypeVarScopeId(type));
|
737
751
|
return applySolvedTypeVars(unspecializedType, typeVarContext);
|
738
752
|
}
|
739
|
-
if ((0, types_1.isUnion)(type) && type.includesRecursiveTypeAlias) {
|
753
|
+
if ((0, types_1.isUnion)(type) && type.priv.includesRecursiveTypeAlias) {
|
740
754
|
let newType = mapSubtypes(type, (subtype) => transformPossibleRecursiveTypeAlias(subtype));
|
741
|
-
if (newType !== type &&
|
755
|
+
if (newType !== type && aliasInfo) {
|
742
756
|
// Copy the type alias information if present.
|
743
|
-
newType = types_1.TypeBase.cloneForTypeAlias(newType,
|
757
|
+
newType = types_1.TypeBase.cloneForTypeAlias(newType, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParameters, aliasInfo.typeArguments);
|
744
758
|
}
|
745
759
|
return newType;
|
746
760
|
}
|
@@ -750,13 +764,13 @@ function transformPossibleRecursiveTypeAlias(type) {
|
|
750
764
|
exports.transformPossibleRecursiveTypeAlias = transformPossibleRecursiveTypeAlias;
|
751
765
|
function getTypeVarScopeId(type) {
|
752
766
|
if ((0, types_1.isClass)(type)) {
|
753
|
-
return type.
|
767
|
+
return type.shared.typeVarScopeId;
|
754
768
|
}
|
755
769
|
if ((0, types_1.isFunction)(type)) {
|
756
|
-
return type.
|
770
|
+
return type.shared.typeVarScopeId;
|
757
771
|
}
|
758
772
|
if ((0, types_1.isTypeVar)(type)) {
|
759
|
-
return type.scopeId;
|
773
|
+
return type.priv.scopeId;
|
760
774
|
}
|
761
775
|
return undefined;
|
762
776
|
}
|
@@ -770,14 +784,11 @@ function getTypeVarScopeIds(type) {
|
|
770
784
|
scopeIds.push(scopeId);
|
771
785
|
}
|
772
786
|
if ((0, types_1.isFunction)(type)) {
|
773
|
-
if (type.
|
774
|
-
scopeIds.push(type.
|
775
|
-
}
|
776
|
-
if (type.details.higherOrderTypeVarScopeIds) {
|
777
|
-
scopeIds.push(...type.details.higherOrderTypeVarScopeIds);
|
787
|
+
if (type.priv.constructorTypeVarScopeId) {
|
788
|
+
scopeIds.push(type.priv.constructorTypeVarScopeId);
|
778
789
|
}
|
779
|
-
if (type.
|
780
|
-
scopeIds.push(type.
|
790
|
+
if (type.priv.higherOrderTypeVarScopeIds) {
|
791
|
+
scopeIds.push(...type.priv.higherOrderTypeVarScopeIds);
|
781
792
|
}
|
782
793
|
}
|
783
794
|
return scopeIds;
|
@@ -787,35 +798,35 @@ exports.getTypeVarScopeIds = getTypeVarScopeIds;
|
|
787
798
|
// specified, specialize it with default type arguments (Unknown or the
|
788
799
|
// default type if provided).
|
789
800
|
function specializeWithDefaultTypeArgs(type) {
|
790
|
-
if (type.
|
801
|
+
if (type.shared.typeParameters.length === 0 || type.priv.typeArguments) {
|
791
802
|
return type;
|
792
803
|
}
|
793
|
-
return types_1.ClassType.cloneForSpecialization(type, type.
|
804
|
+
return types_1.ClassType.cloneForSpecialization(type, type.shared.typeParameters.map((param) => param.shared.defaultType),
|
794
805
|
/* isTypeArgumentExplicit */ false,
|
795
|
-
/* includeSubclasses */ type.includeSubclasses);
|
806
|
+
/* includeSubclasses */ type.priv.includeSubclasses);
|
796
807
|
}
|
797
808
|
exports.specializeWithDefaultTypeArgs = specializeWithDefaultTypeArgs;
|
798
809
|
// Specializes the class with "Unknown" type args (or the equivalent for ParamSpecs
|
799
810
|
// or TypeVarTuples).
|
800
811
|
function specializeWithUnknownTypeArgs(type, tupleClassType) {
|
801
|
-
if (type.
|
812
|
+
if (type.shared.typeParameters.length === 0) {
|
802
813
|
return type;
|
803
814
|
}
|
804
815
|
if (isTupleClass(type)) {
|
805
816
|
return types_1.ClassType.cloneIncludeSubclasses(specializeTupleClass(type, [{ type: types_1.UnknownType.create(), isUnbounded: true }],
|
806
|
-
/* isTypeArgumentExplicit */ false), !!type.includeSubclasses);
|
817
|
+
/* isTypeArgumentExplicit */ false), !!type.priv.includeSubclasses);
|
807
818
|
}
|
808
|
-
return types_1.ClassType.cloneForSpecialization(type, type.
|
819
|
+
return types_1.ClassType.cloneForSpecialization(type, type.shared.typeParameters.map((param) => getUnknownTypeForTypeVar(param, tupleClassType)),
|
809
820
|
/* isTypeArgumentExplicit */ false,
|
810
|
-
/* includeSubclasses */ type.includeSubclasses);
|
821
|
+
/* includeSubclasses */ type.priv.includeSubclasses);
|
811
822
|
}
|
812
823
|
exports.specializeWithUnknownTypeArgs = specializeWithUnknownTypeArgs;
|
813
824
|
// Returns "Unknown" for simple TypeVars or the equivalent for a ParamSpec.
|
814
825
|
function getUnknownTypeForTypeVar(typeVar, tupleClassType) {
|
815
|
-
if (typeVar.
|
826
|
+
if (typeVar.shared.isParamSpec) {
|
816
827
|
return getUnknownTypeForParamSpec();
|
817
828
|
}
|
818
|
-
if (typeVar.
|
829
|
+
if (typeVar.shared.isVariadic && tupleClassType) {
|
819
830
|
return getUnknownTypeForVariadicTypeVar(tupleClassType);
|
820
831
|
}
|
821
832
|
return types_1.UnknownType.create();
|
@@ -839,21 +850,24 @@ exports.getUnknownTypeForVariadicTypeVar = getUnknownTypeForVariadicTypeVar;
|
|
839
850
|
function getUnknownTypeForCallable() {
|
840
851
|
const newFunction = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.GradualCallableForm */);
|
841
852
|
types_1.FunctionType.addDefaultParameters(newFunction);
|
842
|
-
newFunction.
|
853
|
+
newFunction.shared.declaredReturnType = types_1.UnknownType.create();
|
843
854
|
return newFunction;
|
844
855
|
}
|
845
856
|
exports.getUnknownTypeForCallable = getUnknownTypeForCallable;
|
846
857
|
// If the class is generic and not already specialized, this function
|
847
858
|
// "self specializes" the class, filling in its own type parameters
|
848
859
|
// as type arguments.
|
849
|
-
function selfSpecializeClass(type,
|
850
|
-
if (type.
|
860
|
+
function selfSpecializeClass(type, options) {
|
861
|
+
if (type.shared.typeParameters.length === 0) {
|
851
862
|
return type;
|
852
863
|
}
|
853
|
-
if (type.typeArguments && !overrideTypeArgs) {
|
864
|
+
if (type.priv.typeArguments && !(options === null || options === void 0 ? void 0 : options.overrideTypeArgs)) {
|
854
865
|
return type;
|
855
866
|
}
|
856
|
-
|
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
|
+
});
|
870
|
+
return types_1.ClassType.cloneForSpecialization(type, typeParams, /* isTypeArgumentExplicit */ true);
|
857
871
|
}
|
858
872
|
exports.selfSpecializeClass = selfSpecializeClass;
|
859
873
|
// Determines whether the type derives from tuple. If so, it returns
|
@@ -871,7 +885,7 @@ function getSpecializedTupleType(type) {
|
|
871
885
|
}
|
872
886
|
// See if this class derives from Tuple or tuple. If it does, we'll assume that it
|
873
887
|
// hasn't been overridden in a way that changes the behavior of the tuple class.
|
874
|
-
const tupleClass = classType.
|
888
|
+
const tupleClass = classType.shared.mro.find((mroClass) => (0, types_1.isInstantiableClass)(mroClass) && isTupleClass(mroClass));
|
875
889
|
if (!tupleClass || !(0, types_1.isInstantiableClass)(tupleClass)) {
|
876
890
|
return undefined;
|
877
891
|
}
|
@@ -883,7 +897,7 @@ function getSpecializedTupleType(type) {
|
|
883
897
|
}
|
884
898
|
exports.getSpecializedTupleType = getSpecializedTupleType;
|
885
899
|
function isLiteralType(type) {
|
886
|
-
return types_1.TypeBase.isInstance(type) && type.literalValue !== undefined;
|
900
|
+
return types_1.TypeBase.isInstance(type) && type.priv.literalValue !== undefined;
|
887
901
|
}
|
888
902
|
exports.isLiteralType = isLiteralType;
|
889
903
|
function isLiteralTypeOrUnion(type, allowNone = false) {
|
@@ -891,7 +905,7 @@ function isLiteralTypeOrUnion(type, allowNone = false) {
|
|
891
905
|
if (allowNone && isNoneInstance(type)) {
|
892
906
|
return true;
|
893
907
|
}
|
894
|
-
return type.literalValue !== undefined;
|
908
|
+
return type.priv.literalValue !== undefined;
|
895
909
|
}
|
896
910
|
if ((0, types_1.isUnion)(type)) {
|
897
911
|
return !(0, types_1.findSubtype)(type, (subtype) => {
|
@@ -901,7 +915,7 @@ function isLiteralTypeOrUnion(type, allowNone = false) {
|
|
901
915
|
if (isNoneInstance(subtype)) {
|
902
916
|
return !allowNone;
|
903
917
|
}
|
904
|
-
return subtype.literalValue === undefined;
|
918
|
+
return subtype.priv.literalValue === undefined;
|
905
919
|
});
|
906
920
|
}
|
907
921
|
return false;
|
@@ -937,8 +951,8 @@ exports.containsLiteralType = containsLiteralType;
|
|
937
951
|
// it returns undefined.
|
938
952
|
function getLiteralTypeClassName(type) {
|
939
953
|
if ((0, types_1.isClassInstance)(type)) {
|
940
|
-
if (type.literalValue !== undefined && types_1.ClassType.isBuiltIn(type)) {
|
941
|
-
return type.
|
954
|
+
if (type.priv.literalValue !== undefined && types_1.ClassType.isBuiltIn(type)) {
|
955
|
+
return type.shared.name;
|
942
956
|
}
|
943
957
|
return undefined;
|
944
958
|
}
|
@@ -961,13 +975,13 @@ function getLiteralTypeClassName(type) {
|
|
961
975
|
exports.getLiteralTypeClassName = getLiteralTypeClassName;
|
962
976
|
function getUnionSubtypeCount(type) {
|
963
977
|
if ((0, types_1.isUnion)(type)) {
|
964
|
-
return type.subtypes.length;
|
978
|
+
return type.priv.subtypes.length;
|
965
979
|
}
|
966
980
|
return 1;
|
967
981
|
}
|
968
982
|
exports.getUnionSubtypeCount = getUnionSubtypeCount;
|
969
983
|
function isEllipsisType(type) {
|
970
|
-
return (0, types_1.isAny)(type) && type.isEllipsis;
|
984
|
+
return (0, types_1.isAny)(type) && type.priv.isEllipsis;
|
971
985
|
}
|
972
986
|
exports.isEllipsisType = isEllipsisType;
|
973
987
|
function isProperty(type) {
|
@@ -989,21 +1003,21 @@ function isCallableType(type) {
|
|
989
1003
|
return !!callMember;
|
990
1004
|
}
|
991
1005
|
if ((0, types_1.isUnion)(type)) {
|
992
|
-
return type.subtypes.every((subtype) => isCallableType(subtype));
|
1006
|
+
return type.priv.subtypes.every((subtype) => isCallableType(subtype));
|
993
1007
|
}
|
994
1008
|
return false;
|
995
1009
|
}
|
996
1010
|
exports.isCallableType = isCallableType;
|
997
1011
|
function isDescriptorInstance(type, requireSetter = false) {
|
998
1012
|
if ((0, types_1.isUnion)(type)) {
|
999
|
-
return type.subtypes.every((subtype) => isMaybeDescriptorInstance(subtype, requireSetter));
|
1013
|
+
return type.priv.subtypes.every((subtype) => isMaybeDescriptorInstance(subtype, requireSetter));
|
1000
1014
|
}
|
1001
1015
|
return isMaybeDescriptorInstance(type, requireSetter);
|
1002
1016
|
}
|
1003
1017
|
exports.isDescriptorInstance = isDescriptorInstance;
|
1004
1018
|
function isMaybeDescriptorInstance(type, requireSetter = false) {
|
1005
1019
|
if ((0, types_1.isUnion)(type)) {
|
1006
|
-
return type.subtypes.some((subtype) => isMaybeDescriptorInstance(subtype, requireSetter));
|
1020
|
+
return type.priv.subtypes.some((subtype) => isMaybeDescriptorInstance(subtype, requireSetter));
|
1007
1021
|
}
|
1008
1022
|
if (!(0, types_1.isClassInstance)(type)) {
|
1009
1023
|
return false;
|
@@ -1017,6 +1031,15 @@ function isMaybeDescriptorInstance(type, requireSetter = false) {
|
|
1017
1031
|
return true;
|
1018
1032
|
}
|
1019
1033
|
exports.isMaybeDescriptorInstance = isMaybeDescriptorInstance;
|
1034
|
+
function isTupleGradualForm(type) {
|
1035
|
+
return ((0, types_1.isClassInstance)(type) &&
|
1036
|
+
isTupleClass(type) &&
|
1037
|
+
type.priv.tupleTypeArguments &&
|
1038
|
+
type.priv.tupleTypeArguments.length === 1 &&
|
1039
|
+
(0, types_1.isAnyOrUnknown)(type.priv.tupleTypeArguments[0].type) &&
|
1040
|
+
type.priv.tupleTypeArguments[0].isUnbounded);
|
1041
|
+
}
|
1042
|
+
exports.isTupleGradualForm = isTupleGradualForm;
|
1020
1043
|
function isTupleClass(type) {
|
1021
1044
|
return types_1.ClassType.isBuiltIn(type, 'tuple');
|
1022
1045
|
}
|
@@ -1025,32 +1048,30 @@ exports.isTupleClass = isTupleClass;
|
|
1025
1048
|
// the form tuple[x, ...] where the number of elements
|
1026
1049
|
// in the tuple is unknown.
|
1027
1050
|
function isUnboundedTupleClass(type) {
|
1028
|
-
return (type.tupleTypeArguments &&
|
1029
|
-
type.tupleTypeArguments.some((t) => t.isUnbounded || (0, types_1.isUnpackedVariadicTypeVar)(t.type)));
|
1051
|
+
return (type.priv.tupleTypeArguments &&
|
1052
|
+
type.priv.tupleTypeArguments.some((t) => t.isUnbounded || (0, types_1.isUnpackedVariadicTypeVar)(t.type)));
|
1030
1053
|
}
|
1031
1054
|
exports.isUnboundedTupleClass = isUnboundedTupleClass;
|
1032
1055
|
// Indicates whether the specified index is within range and its type is unambiguous
|
1033
1056
|
// in that it doesn't involve any element ranges that are of indeterminate length.
|
1034
1057
|
function isTupleIndexUnambiguous(type, index) {
|
1035
|
-
if (!type.tupleTypeArguments) {
|
1058
|
+
if (!type.priv.tupleTypeArguments) {
|
1036
1059
|
return false;
|
1037
1060
|
}
|
1061
|
+
const unboundedIndex = type.priv.tupleTypeArguments.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedVariadicTypeVar)(t.type));
|
1038
1062
|
if (index < 0) {
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
}
|
1043
|
-
let unambiguousIndexLimit = type.tupleTypeArguments.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedVariadicTypeVar)(t.type));
|
1044
|
-
if (unambiguousIndexLimit < 0) {
|
1045
|
-
unambiguousIndexLimit = type.tupleTypeArguments.length;
|
1063
|
+
const lowerIndexLimit = unboundedIndex < 0 ? 0 : unboundedIndex;
|
1064
|
+
index += type.priv.tupleTypeArguments.length;
|
1065
|
+
return index >= lowerIndexLimit;
|
1046
1066
|
}
|
1047
|
-
|
1067
|
+
const upperIndexLimit = unboundedIndex < 0 ? type.priv.tupleTypeArguments.length : unboundedIndex;
|
1068
|
+
return index < upperIndexLimit;
|
1048
1069
|
}
|
1049
1070
|
exports.isTupleIndexUnambiguous = isTupleIndexUnambiguous;
|
1050
1071
|
// Partially specializes a type within the context of a specified
|
1051
1072
|
// (presumably specialized) class. Optionally specializes the `Self`
|
1052
1073
|
// type variables, replacing them with selfClass.
|
1053
|
-
function partiallySpecializeType(type, contextClassType,
|
1074
|
+
function partiallySpecializeType(type, contextClassType, typeClassType, selfClass) {
|
1054
1075
|
// If the context class is not specialized (or doesn't need specialization),
|
1055
1076
|
// then there's no need to do any more work.
|
1056
1077
|
if (types_1.ClassType.isUnspecialized(contextClassType) && !selfClass) {
|
@@ -1065,20 +1086,20 @@ function partiallySpecializeType(type, contextClassType, selfClass, typeClassTyp
|
|
1065
1086
|
// If this is a property, we may need to partially specialize the
|
1066
1087
|
// access methods associated with it.
|
1067
1088
|
if ((0, types_1.isClass)(result)) {
|
1068
|
-
if (result.fgetInfo || result.fsetInfo || result.fdelInfo) {
|
1089
|
+
if (result.priv.fgetInfo || result.priv.fsetInfo || result.priv.fdelInfo) {
|
1069
1090
|
function updatePropertyMethodInfo(methodInfo) {
|
1070
1091
|
if (!methodInfo) {
|
1071
1092
|
return undefined;
|
1072
1093
|
}
|
1073
1094
|
return {
|
1074
|
-
methodType: partiallySpecializeType(methodInfo.methodType, contextClassType,
|
1095
|
+
methodType: partiallySpecializeType(methodInfo.methodType, contextClassType, typeClassType, selfClass),
|
1075
1096
|
classType: methodInfo.classType,
|
1076
1097
|
};
|
1077
1098
|
}
|
1078
1099
|
result = types_1.TypeBase.cloneType(result);
|
1079
|
-
result.fgetInfo = updatePropertyMethodInfo(result.fgetInfo);
|
1080
|
-
result.fsetInfo = updatePropertyMethodInfo(result.fsetInfo);
|
1081
|
-
result.fdelInfo = updatePropertyMethodInfo(result.fdelInfo);
|
1100
|
+
result.priv.fgetInfo = updatePropertyMethodInfo(result.priv.fgetInfo);
|
1101
|
+
result.priv.fsetInfo = updatePropertyMethodInfo(result.priv.fsetInfo);
|
1102
|
+
result.priv.fdelInfo = updatePropertyMethodInfo(result.priv.fdelInfo);
|
1082
1103
|
}
|
1083
1104
|
}
|
1084
1105
|
return result;
|
@@ -1091,7 +1112,7 @@ function populateTypeVarContextForSelfType(typeVarContext, contextClassType, sel
|
|
1091
1112
|
// Instead, we'll do a simplified version of it here.
|
1092
1113
|
const selfWithoutLiteral = mapSubtypes(selfInstance, (subtype) => {
|
1093
1114
|
if ((0, types_1.isClass)(subtype)) {
|
1094
|
-
if (subtype.literalValue !== undefined) {
|
1115
|
+
if (subtype.priv.literalValue !== undefined) {
|
1095
1116
|
return types_1.ClassType.cloneWithLiteral(subtype, /* value */ undefined);
|
1096
1117
|
}
|
1097
1118
|
}
|
@@ -1109,6 +1130,16 @@ function ensureFunctionSignaturesAreUnique(type, signatureTracker, expressionOff
|
|
1109
1130
|
return transformer.apply(type, 0);
|
1110
1131
|
}
|
1111
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;
|
1112
1143
|
// Specializes a (potentially generic) type by substituting
|
1113
1144
|
// type variables from a type var map.
|
1114
1145
|
function applySolvedTypeVars(type, typeVarContext, options = {}) {
|
@@ -1163,7 +1194,7 @@ function applyInScopePlaceholders(typeVarContext) {
|
|
1163
1194
|
typeVarContext.doForEachSignatureContext((signature) => {
|
1164
1195
|
signature.getTypeVars().forEach((entry) => {
|
1165
1196
|
const typeVar = entry.typeVar;
|
1166
|
-
if (!typeVar.isInScopePlaceholder) {
|
1197
|
+
if (!typeVar.priv.isInScopePlaceholder) {
|
1167
1198
|
const newNarrowTypeBound = entry.narrowBound
|
1168
1199
|
? applyInScopePlaceholdersToType(entry.narrowBound, signature)
|
1169
1200
|
: undefined;
|
@@ -1193,9 +1224,9 @@ exports.applyInScopePlaceholders = applyInScopePlaceholders;
|
|
1193
1224
|
function validateTypeVarDefault(typeVar, liveTypeParams, invalidTypeVars) {
|
1194
1225
|
// If there is no default type or the default type is concrete, there's
|
1195
1226
|
// no need to do any more work here.
|
1196
|
-
if (typeVar.
|
1227
|
+
if (typeVar.shared.isDefaultExplicit && requiresSpecialization(typeVar.shared.defaultType)) {
|
1197
1228
|
const validator = new TypeVarDefaultValidator(liveTypeParams, invalidTypeVars);
|
1198
|
-
validator.apply(typeVar.
|
1229
|
+
validator.apply(typeVar.shared.defaultType, 0);
|
1199
1230
|
}
|
1200
1231
|
}
|
1201
1232
|
exports.validateTypeVarDefault = validateTypeVarDefault;
|
@@ -1220,7 +1251,7 @@ exports.transformExpectedType = transformExpectedType;
|
|
1220
1251
|
// appears in a parent and a child, the child overrides the parent.
|
1221
1252
|
function getProtocolSymbols(classType) {
|
1222
1253
|
const symbolMap = new Map();
|
1223
|
-
if ((classType.
|
1254
|
+
if ((classType.shared.flags & 512 /* ClassTypeFlags.ProtocolClass */) !== 0) {
|
1224
1255
|
getProtocolSymbolsRecursive(classType, symbolMap, 512 /* ClassTypeFlags.ProtocolClass */);
|
1225
1256
|
}
|
1226
1257
|
return symbolMap;
|
@@ -1230,8 +1261,8 @@ function getProtocolSymbolsRecursive(classType, symbolMap, classFlags = 512 /* C
|
|
1230
1261
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
1231
1262
|
return;
|
1232
1263
|
}
|
1233
|
-
classType.
|
1234
|
-
if ((0, types_1.isClass)(baseClass) && (baseClass.
|
1264
|
+
classType.shared.baseClasses.forEach((baseClass) => {
|
1265
|
+
if ((0, types_1.isClass)(baseClass) && (baseClass.shared.flags & classFlags) !== 0) {
|
1235
1266
|
getProtocolSymbolsRecursive(baseClass, symbolMap, classFlags, recursionCount + 1);
|
1236
1267
|
}
|
1237
1268
|
});
|
@@ -1262,16 +1293,16 @@ function getContainerDepth(type, recursionCount = 0) {
|
|
1262
1293
|
return 0;
|
1263
1294
|
}
|
1264
1295
|
let maxChildDepth = 0;
|
1265
|
-
if (type.tupleTypeArguments) {
|
1266
|
-
type.tupleTypeArguments.forEach((typeArgInfo) => {
|
1296
|
+
if (type.priv.tupleTypeArguments) {
|
1297
|
+
type.priv.tupleTypeArguments.forEach((typeArgInfo) => {
|
1267
1298
|
doForEachSubtype(typeArgInfo.type, (subtype) => {
|
1268
1299
|
const childDepth = getContainerDepth(subtype, recursionCount);
|
1269
1300
|
maxChildDepth = Math.max(childDepth, maxChildDepth);
|
1270
1301
|
});
|
1271
1302
|
});
|
1272
1303
|
}
|
1273
|
-
else if (type.typeArguments) {
|
1274
|
-
type.typeArguments.forEach((typeArg) => {
|
1304
|
+
else if (type.priv.typeArguments) {
|
1305
|
+
type.priv.typeArguments.forEach((typeArg) => {
|
1275
1306
|
doForEachSubtype(typeArg, (subtype) => {
|
1276
1307
|
const childDepth = getContainerDepth(subtype, recursionCount);
|
1277
1308
|
maxChildDepth = Math.max(childDepth, maxChildDepth);
|
@@ -1296,7 +1327,7 @@ exports.lookUpObjectMember = lookUpObjectMember;
|
|
1296
1327
|
function lookUpClassMember(classType, memberName, flags = 0 /* MemberAccessFlags.Default */, skipMroClass) {
|
1297
1328
|
var _a, _b;
|
1298
1329
|
// Look in the metaclass first.
|
1299
|
-
const metaclass = classType.
|
1330
|
+
const metaclass = classType.shared.effectiveMetaclass;
|
1300
1331
|
// Skip the "type" class as an optimization because it is known to not
|
1301
1332
|
// define any instance variables, and it's by far the most common metaclass.
|
1302
1333
|
if (metaclass && (0, types_1.isClass)(metaclass) && !types_1.ClassType.isBuiltIn(metaclass, 'type')) {
|
@@ -1454,7 +1485,7 @@ exports.getClassMemberIterator = getClassMemberIterator;
|
|
1454
1485
|
function* getClassIterator(classType, flags = 0 /* ClassIteratorFlags.Default */, skipMroClass) {
|
1455
1486
|
if ((0, types_1.isClass)(classType)) {
|
1456
1487
|
let foundSkipMroClass = skipMroClass === undefined;
|
1457
|
-
for (const mroClass of classType.
|
1488
|
+
for (const mroClass of classType.shared.mro) {
|
1458
1489
|
// Are we still searching for the skipMroClass?
|
1459
1490
|
if (!foundSkipMroClass && skipMroClass) {
|
1460
1491
|
if (!(0, types_1.isClass)(mroClass)) {
|
@@ -1470,7 +1501,7 @@ function* getClassIterator(classType, flags = 0 /* ClassIteratorFlags.Default */
|
|
1470
1501
|
}
|
1471
1502
|
// If mroClass is an ancestor of classType, partially specialize
|
1472
1503
|
// it in the context of classType.
|
1473
|
-
const specializedMroClass = partiallySpecializeType(mroClass, classType);
|
1504
|
+
const specializedMroClass = partiallySpecializeType(mroClass, classType, /* typeClassType */ undefined);
|
1474
1505
|
// Should we ignore members on the 'object' base class?
|
1475
1506
|
if (flags & 2 /* ClassIteratorFlags.SkipObjectBaseClass */) {
|
1476
1507
|
if ((0, types_1.isInstantiableClass)(specializedMroClass)) {
|
@@ -1500,7 +1531,7 @@ function getClassFieldsRecursive(classType) {
|
|
1500
1531
|
const memberMap = new Map();
|
1501
1532
|
// Evaluate the types of members from the end of the MRO to the beginning.
|
1502
1533
|
types_1.ClassType.getReverseMro(classType).forEach((mroClass) => {
|
1503
|
-
const specializedMroClass = partiallySpecializeType(mroClass, classType);
|
1534
|
+
const specializedMroClass = partiallySpecializeType(mroClass, classType, /* typeClassType */ undefined);
|
1504
1535
|
if ((0, types_1.isClass)(specializedMroClass)) {
|
1505
1536
|
types_1.ClassType.getSymbolTable(specializedMroClass).forEach((symbol, name) => {
|
1506
1537
|
if (!symbol.isIgnoredForProtocolMatch() && symbol.hasTypedDeclarations()) {
|
@@ -1530,7 +1561,7 @@ exports.getClassFieldsRecursive = getClassFieldsRecursive;
|
|
1530
1561
|
// but removing any duplicates.
|
1531
1562
|
function addTypeVarsToListIfUnique(list1, list2, typeVarScopeId) {
|
1532
1563
|
for (const type2 of list2) {
|
1533
|
-
if (typeVarScopeId && type2.scopeId !== typeVarScopeId) {
|
1564
|
+
if (typeVarScopeId && type2.priv.scopeId !== typeVarScopeId) {
|
1534
1565
|
continue;
|
1535
1566
|
}
|
1536
1567
|
if (!list1.find((type1) => (0, types_1.isTypeSame)(convertToInstance(type1), convertToInstance(type2)))) {
|
@@ -1545,32 +1576,35 @@ exports.addTypeVarsToListIfUnique = addTypeVarsToListIfUnique;
|
|
1545
1576
|
// Union[List[Dict[_T1, _T2]], _T1, _T3], the result would be
|
1546
1577
|
// [_T1, _T2, _T3].
|
1547
1578
|
function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
1548
|
-
var _a
|
1579
|
+
var _a;
|
1549
1580
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
1550
1581
|
return [];
|
1551
1582
|
}
|
1552
1583
|
recursionCount++;
|
1553
|
-
|
1584
|
+
const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
1585
|
+
if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments) {
|
1554
1586
|
const combinedList = [];
|
1555
|
-
|
1587
|
+
aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments.forEach((typeArg) => {
|
1556
1588
|
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(typeArg, recursionCount));
|
1557
1589
|
});
|
1558
1590
|
return combinedList;
|
1559
1591
|
}
|
1560
1592
|
if ((0, types_1.isTypeVar)(type)) {
|
1561
1593
|
// Don't return any recursive type alias placeholders.
|
1562
|
-
if (type.
|
1594
|
+
if (type.shared.recursiveAlias) {
|
1563
1595
|
return [];
|
1564
1596
|
}
|
1565
1597
|
// Don't return any P.args or P.kwargs types.
|
1566
|
-
if ((0, types_1.isParamSpec)(type) && type.paramSpecAccess) {
|
1598
|
+
if ((0, types_1.isParamSpec)(type) && type.priv.paramSpecAccess) {
|
1567
1599
|
return [types_1.TypeVarType.cloneForParamSpecAccess(type, /* access */ undefined)];
|
1568
1600
|
}
|
1569
1601
|
return [types_1.TypeBase.isInstantiable(type) ? types_1.TypeVarType.cloneAsInstance(type) : type];
|
1570
1602
|
}
|
1571
1603
|
if ((0, types_1.isClass)(type)) {
|
1572
1604
|
const combinedList = [];
|
1573
|
-
const typeArgs = type.
|
1605
|
+
const typeArgs = type.priv.tupleTypeArguments
|
1606
|
+
? type.priv.tupleTypeArguments.map((e) => e.type)
|
1607
|
+
: type.priv.typeArguments;
|
1574
1608
|
if (typeArgs) {
|
1575
1609
|
typeArgs.forEach((typeArg) => {
|
1576
1610
|
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(typeArg, recursionCount));
|
@@ -1587,7 +1621,7 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
|
1587
1621
|
}
|
1588
1622
|
if ((0, types_1.isFunction)(type)) {
|
1589
1623
|
const combinedList = [];
|
1590
|
-
for (let i = 0; i < type.
|
1624
|
+
for (let i = 0; i < type.shared.parameters.length; i++) {
|
1591
1625
|
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(types_1.FunctionType.getEffectiveParameterType(type, i), recursionCount));
|
1592
1626
|
}
|
1593
1627
|
const returnType = types_1.FunctionType.getEffectiveReturnType(type);
|
@@ -1605,7 +1639,7 @@ function specializeClassType(type) {
|
|
1605
1639
|
const typeVarContext = new typeVarContext_1.TypeVarContext(getTypeVarScopeId(type));
|
1606
1640
|
const typeParams = types_1.ClassType.getTypeParameters(type);
|
1607
1641
|
typeParams.forEach((typeParam) => {
|
1608
|
-
typeVarContext.setTypeVarType(typeParam, applySolvedTypeVars(typeParam.
|
1642
|
+
typeVarContext.setTypeVarType(typeParam, applySolvedTypeVars(typeParam.shared.defaultType, typeVarContext));
|
1609
1643
|
});
|
1610
1644
|
return applySolvedTypeVars(type, typeVarContext);
|
1611
1645
|
}
|
@@ -1627,37 +1661,37 @@ function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionC
|
|
1627
1661
|
});
|
1628
1662
|
break;
|
1629
1663
|
case 6 /* TypeCategory.Class */:
|
1630
|
-
if (destType.typeArguments) {
|
1631
|
-
destType.typeArguments.forEach((typeArg) => {
|
1664
|
+
if (destType.priv.typeArguments) {
|
1665
|
+
destType.priv.typeArguments.forEach((typeArg) => {
|
1632
1666
|
setTypeArgumentsRecursive(typeArg, srcType, typeVarContext, recursionCount);
|
1633
1667
|
});
|
1634
1668
|
}
|
1635
|
-
if (destType.tupleTypeArguments) {
|
1636
|
-
destType.tupleTypeArguments.forEach((typeArg) => {
|
1669
|
+
if (destType.priv.tupleTypeArguments) {
|
1670
|
+
destType.priv.tupleTypeArguments.forEach((typeArg) => {
|
1637
1671
|
setTypeArgumentsRecursive(typeArg.type, srcType, typeVarContext, recursionCount);
|
1638
1672
|
});
|
1639
1673
|
}
|
1640
1674
|
break;
|
1641
1675
|
case 4 /* TypeCategory.Function */:
|
1642
|
-
if (destType.specializedTypes) {
|
1643
|
-
destType.specializedTypes.parameterTypes.forEach((paramType) => {
|
1676
|
+
if (destType.priv.specializedTypes) {
|
1677
|
+
destType.priv.specializedTypes.parameterTypes.forEach((paramType) => {
|
1644
1678
|
setTypeArgumentsRecursive(paramType, srcType, typeVarContext, recursionCount);
|
1645
1679
|
});
|
1646
|
-
if (destType.specializedTypes.returnType) {
|
1647
|
-
setTypeArgumentsRecursive(destType.specializedTypes.returnType, srcType, typeVarContext, recursionCount);
|
1680
|
+
if (destType.priv.specializedTypes.returnType) {
|
1681
|
+
setTypeArgumentsRecursive(destType.priv.specializedTypes.returnType, srcType, typeVarContext, recursionCount);
|
1648
1682
|
}
|
1649
1683
|
}
|
1650
1684
|
else {
|
1651
|
-
destType.
|
1685
|
+
destType.shared.parameters.forEach((param) => {
|
1652
1686
|
setTypeArgumentsRecursive(param.type, srcType, typeVarContext, recursionCount);
|
1653
1687
|
});
|
1654
|
-
if (destType.
|
1655
|
-
setTypeArgumentsRecursive(destType.
|
1688
|
+
if (destType.shared.declaredReturnType) {
|
1689
|
+
setTypeArgumentsRecursive(destType.shared.declaredReturnType, srcType, typeVarContext, recursionCount);
|
1656
1690
|
}
|
1657
1691
|
}
|
1658
1692
|
break;
|
1659
1693
|
case 5 /* TypeCategory.OverloadedFunction */:
|
1660
|
-
destType.overloads.forEach((subtype) => {
|
1694
|
+
destType.priv.overloads.forEach((subtype) => {
|
1661
1695
|
setTypeArgumentsRecursive(subtype, srcType, typeVarContext, recursionCount);
|
1662
1696
|
});
|
1663
1697
|
break;
|
@@ -1675,9 +1709,9 @@ exports.setTypeArgumentsRecursive = setTypeArgumentsRecursive;
|
|
1675
1709
|
// _T1 with str and _T2 with int.
|
1676
1710
|
function buildTypeVarContextFromSpecializedClass(classType) {
|
1677
1711
|
const typeParameters = types_1.ClassType.getTypeParameters(classType);
|
1678
|
-
const typeVarContext = buildTypeVarContext(typeParameters, classType.typeArguments, getTypeVarScopeId(classType));
|
1679
|
-
if (types_1.ClassType.isTupleClass(classType) && classType.tupleTypeArguments) {
|
1680
|
-
typeVarContext.setTupleTypeVar(typeParameters[0], classType.tupleTypeArguments);
|
1712
|
+
const typeVarContext = buildTypeVarContext(typeParameters, classType.priv.typeArguments, getTypeVarScopeId(classType));
|
1713
|
+
if (types_1.ClassType.isTupleClass(classType) && classType.priv.tupleTypeArguments) {
|
1714
|
+
typeVarContext.setTupleTypeVar(typeParameters[0], classType.priv.tupleTypeArguments);
|
1681
1715
|
}
|
1682
1716
|
return typeVarContext;
|
1683
1717
|
}
|
@@ -1687,21 +1721,14 @@ function buildTypeVarContext(typeParameters, typeArgs, typeVarScopeId) {
|
|
1687
1721
|
typeParameters.forEach((typeParam, index) => {
|
1688
1722
|
let typeArgType;
|
1689
1723
|
if (typeArgs) {
|
1690
|
-
if (typeParam.
|
1724
|
+
if (typeParam.shared.isParamSpec) {
|
1691
1725
|
if (index < typeArgs.length) {
|
1692
1726
|
typeArgType = typeArgs[index];
|
1693
1727
|
if ((0, types_1.isFunction)(typeArgType) && types_1.FunctionType.isParamSpecValue(typeArgType)) {
|
1694
1728
|
const parameters = [];
|
1695
1729
|
const typeArgFunctionType = typeArgType;
|
1696
|
-
typeArgType.
|
1697
|
-
parameters.push(
|
1698
|
-
category: param.category,
|
1699
|
-
name: param.name,
|
1700
|
-
hasDefault: !!param.hasDefault,
|
1701
|
-
defaultValueExpression: param.defaultValueExpression,
|
1702
|
-
isNameSynthesized: param.isNameSynthesized,
|
1703
|
-
type: types_1.FunctionType.getEffectiveParameterType(typeArgFunctionType, paramIndex),
|
1704
|
-
});
|
1730
|
+
typeArgType.shared.parameters.forEach((param, paramIndex) => {
|
1731
|
+
parameters.push(types_1.FunctionParam.create(param.category, types_1.FunctionType.getEffectiveParameterType(typeArgFunctionType, paramIndex), param.flags & types_1.FunctionParamFlags.NameSynthesized, param.name, param.defaultType));
|
1705
1732
|
});
|
1706
1733
|
typeVarContext.setTypeVarType(typeParam, convertTypeToParamSpecValue(typeArgType));
|
1707
1734
|
}
|
@@ -1740,7 +1767,7 @@ function specializeForBaseClass(srcType, baseClass) {
|
|
1740
1767
|
}
|
1741
1768
|
exports.specializeForBaseClass = specializeForBaseClass;
|
1742
1769
|
function derivesFromStdlibClass(classType, className) {
|
1743
|
-
return classType.
|
1770
|
+
return classType.shared.mro.some((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isBuiltIn(mroClass, className));
|
1744
1771
|
}
|
1745
1772
|
exports.derivesFromStdlibClass = derivesFromStdlibClass;
|
1746
1773
|
// If ignoreUnknown is true, an unknown base class is ignored when
|
@@ -1750,7 +1777,7 @@ function derivesFromClassRecursive(classType, baseClassToFind, ignoreUnknown) {
|
|
1750
1777
|
if (types_1.ClassType.isSameGenericClass(classType, baseClassToFind)) {
|
1751
1778
|
return true;
|
1752
1779
|
}
|
1753
|
-
for (const baseClass of classType.
|
1780
|
+
for (const baseClass of classType.shared.baseClasses) {
|
1754
1781
|
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
1755
1782
|
if (derivesFromClassRecursive(baseClass, baseClassToFind, ignoreUnknown)) {
|
1756
1783
|
return true;
|
@@ -1768,14 +1795,15 @@ function synthesizeTypeVarForSelfCls(classType, isClsParam) {
|
|
1768
1795
|
var _a;
|
1769
1796
|
const selfType = types_1.TypeVarType.createInstance(`__type_of_self__`);
|
1770
1797
|
const scopeId = (_a = getTypeVarScopeId(classType)) !== null && _a !== void 0 ? _a : '';
|
1771
|
-
selfType.
|
1772
|
-
selfType.
|
1773
|
-
selfType.nameWithScope = types_1.TypeVarType.makeNameWithScope(selfType.
|
1774
|
-
selfType.scopeId = scopeId;
|
1775
|
-
const boundType = types_1.ClassType.cloneForSpecialization(classType,
|
1798
|
+
selfType.shared.isSynthesized = true;
|
1799
|
+
selfType.shared.isSynthesizedSelf = true;
|
1800
|
+
selfType.priv.nameWithScope = types_1.TypeVarType.makeNameWithScope(selfType.shared.name, scopeId);
|
1801
|
+
selfType.priv.scopeId = scopeId;
|
1802
|
+
const boundType = types_1.ClassType.cloneForSpecialization(classType,
|
1803
|
+
/* typeArguments */ undefined,
|
1776
1804
|
/* isTypeArgumentExplicit */ false,
|
1777
|
-
/* includeSubclasses */ !!classType.includeSubclasses);
|
1778
|
-
selfType.
|
1805
|
+
/* includeSubclasses */ !!classType.priv.includeSubclasses);
|
1806
|
+
selfType.shared.boundType = types_1.ClassType.cloneAsInstance(boundType);
|
1779
1807
|
return isClsParam ? types_1.TypeVarType.cloneAsInstantiable(selfType) : selfType;
|
1780
1808
|
}
|
1781
1809
|
exports.synthesizeTypeVarForSelfCls = synthesizeTypeVarForSelfCls;
|
@@ -1810,8 +1838,8 @@ function getGeneratorYieldType(declaredReturnType, isAsync) {
|
|
1810
1838
|
['', 'AwaitableGenerator'],
|
1811
1839
|
];
|
1812
1840
|
if (expectedClasses.some((classes) => types_1.ClassType.isBuiltIn(subtype, isAsync ? classes[0] : classes[1]))) {
|
1813
|
-
return subtype.typeArguments && subtype.typeArguments.length >= 1
|
1814
|
-
? subtype.typeArguments[0]
|
1841
|
+
return subtype.priv.typeArguments && subtype.priv.typeArguments.length >= 1
|
1842
|
+
? subtype.priv.typeArguments[0]
|
1815
1843
|
: types_1.UnknownType.create();
|
1816
1844
|
}
|
1817
1845
|
}
|
@@ -1823,12 +1851,12 @@ function getGeneratorYieldType(declaredReturnType, isAsync) {
|
|
1823
1851
|
exports.getGeneratorYieldType = getGeneratorYieldType;
|
1824
1852
|
function isInstantiableMetaclass(type) {
|
1825
1853
|
return ((0, types_1.isInstantiableClass)(type) &&
|
1826
|
-
type.
|
1854
|
+
type.shared.mro.some((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isBuiltIn(mroClass, 'type')));
|
1827
1855
|
}
|
1828
1856
|
exports.isInstantiableMetaclass = isInstantiableMetaclass;
|
1829
1857
|
function isMetaclassInstance(type) {
|
1830
1858
|
return ((0, types_1.isClassInstance)(type) &&
|
1831
|
-
type.
|
1859
|
+
type.shared.mro.some((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isBuiltIn(mroClass, 'type')));
|
1832
1860
|
}
|
1833
1861
|
exports.isMetaclassInstance = isMetaclassInstance;
|
1834
1862
|
function isEffectivelyInstantiable(type, options, recursionCount = 0) {
|
@@ -1839,8 +1867,8 @@ function isEffectivelyInstantiable(type, options, recursionCount = 0) {
|
|
1839
1867
|
if (types_1.TypeBase.isInstantiable(type)) {
|
1840
1868
|
return true;
|
1841
1869
|
}
|
1842
|
-
if ((options === null || options === void 0 ? void 0 : options.honorTypeVarBounds) && (0, types_1.isTypeVar)(type) && type.
|
1843
|
-
if (isEffectivelyInstantiable(type.
|
1870
|
+
if ((options === null || options === void 0 ? void 0 : options.honorTypeVarBounds) && (0, types_1.isTypeVar)(type) && type.shared.boundType) {
|
1871
|
+
if (isEffectivelyInstantiable(type.shared.boundType, options, recursionCount)) {
|
1844
1872
|
return true;
|
1845
1873
|
}
|
1846
1874
|
}
|
@@ -1850,13 +1878,13 @@ function isEffectivelyInstantiable(type, options, recursionCount = 0) {
|
|
1850
1878
|
return true;
|
1851
1879
|
}
|
1852
1880
|
if ((0, types_1.isUnion)(type)) {
|
1853
|
-
return type.subtypes.every((subtype) => isEffectivelyInstantiable(subtype, options, recursionCount));
|
1881
|
+
return type.priv.subtypes.every((subtype) => isEffectivelyInstantiable(subtype, options, recursionCount));
|
1854
1882
|
}
|
1855
1883
|
return false;
|
1856
1884
|
}
|
1857
1885
|
exports.isEffectivelyInstantiable = isEffectivelyInstantiable;
|
1858
1886
|
function convertToInstance(type, includeSubclasses = true) {
|
1859
|
-
var _a;
|
1887
|
+
var _a, _b;
|
1860
1888
|
// See if we've already performed this conversion and cached it.
|
1861
1889
|
if (((_a = type.cached) === null || _a === void 0 ? void 0 : _a.instanceType) && includeSubclasses) {
|
1862
1890
|
return type.cached.instanceType;
|
@@ -1867,17 +1895,17 @@ function convertToInstance(type, includeSubclasses = true) {
|
|
1867
1895
|
// Handle type[x] as a special case.
|
1868
1896
|
if (types_1.ClassType.isBuiltIn(subtype, 'type')) {
|
1869
1897
|
if (types_1.TypeBase.isInstance(subtype)) {
|
1870
|
-
if (!subtype.typeArguments || subtype.typeArguments.length < 1) {
|
1898
|
+
if (!subtype.priv.typeArguments || subtype.priv.typeArguments.length < 1) {
|
1871
1899
|
return types_1.UnknownType.create();
|
1872
1900
|
}
|
1873
1901
|
else {
|
1874
|
-
return subtype.typeArguments[0];
|
1902
|
+
return subtype.priv.typeArguments[0];
|
1875
1903
|
}
|
1876
1904
|
}
|
1877
1905
|
else {
|
1878
|
-
if (subtype.typeArguments && subtype.typeArguments.length > 0) {
|
1879
|
-
if (!(0, types_1.isAnyOrUnknown)(subtype.typeArguments[0])) {
|
1880
|
-
return convertToInstantiable(subtype.typeArguments[0]);
|
1906
|
+
if (subtype.priv.typeArguments && subtype.priv.typeArguments.length > 0) {
|
1907
|
+
if (!(0, types_1.isAnyOrUnknown)(subtype.priv.typeArguments[0])) {
|
1908
|
+
return convertToInstantiable(subtype.priv.typeArguments[0]);
|
1881
1909
|
}
|
1882
1910
|
}
|
1883
1911
|
}
|
@@ -1910,10 +1938,13 @@ function convertToInstance(type, includeSubclasses = true) {
|
|
1910
1938
|
}
|
1911
1939
|
}
|
1912
1940
|
return subtype;
|
1941
|
+
}, {
|
1942
|
+
skipElideRedundantLiterals: true,
|
1913
1943
|
});
|
1914
1944
|
// Copy over any type alias information.
|
1915
|
-
|
1916
|
-
|
1945
|
+
const aliasInfo = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo;
|
1946
|
+
if (aliasInfo && type !== result) {
|
1947
|
+
result = types_1.TypeBase.cloneForTypeAlias(result, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParameters, aliasInfo.typeArguments);
|
1917
1948
|
}
|
1918
1949
|
if (type !== result && includeSubclasses) {
|
1919
1950
|
// Cache the converted value for next time.
|
@@ -1956,7 +1987,7 @@ function convertToInstantiable(type, includeSubclasses = true) {
|
|
1956
1987
|
}
|
1957
1988
|
exports.convertToInstantiable = convertToInstantiable;
|
1958
1989
|
function getMembersForClass(classType, symbolTable, includeInstanceVars) {
|
1959
|
-
classType.
|
1990
|
+
classType.shared.mro.forEach((mroClass) => {
|
1960
1991
|
if ((0, types_1.isInstantiableClass)(mroClass)) {
|
1961
1992
|
// Add any new member variables from this class.
|
1962
1993
|
const isClassTypedDict = types_1.ClassType.isTypedDictClass(mroClass);
|
@@ -1981,9 +2012,9 @@ function getMembersForClass(classType, symbolTable, includeInstanceVars) {
|
|
1981
2012
|
});
|
1982
2013
|
// Add members of the metaclass as well.
|
1983
2014
|
if (!includeInstanceVars) {
|
1984
|
-
const metaclass = classType.
|
2015
|
+
const metaclass = classType.shared.effectiveMetaclass;
|
1985
2016
|
if (metaclass && (0, types_1.isInstantiableClass)(metaclass)) {
|
1986
|
-
for (const mroClass of metaclass.
|
2017
|
+
for (const mroClass of metaclass.shared.mro) {
|
1987
2018
|
if ((0, types_1.isInstantiableClass)(mroClass)) {
|
1988
2019
|
types_1.ClassType.getSymbolTable(mroClass).forEach((symbol, name) => {
|
1989
2020
|
const existingSymbol = symbolTable.get(name);
|
@@ -2009,12 +2040,12 @@ function getMembersForModule(moduleType, symbolTable) {
|
|
2009
2040
|
// Start with the loader fields. If there are any symbols of the
|
2010
2041
|
// same name defined within the module, they will overwrite the
|
2011
2042
|
// loader fields.
|
2012
|
-
if (moduleType.loaderFields) {
|
2013
|
-
moduleType.loaderFields.forEach((symbol, name) => {
|
2043
|
+
if (moduleType.priv.loaderFields) {
|
2044
|
+
moduleType.priv.loaderFields.forEach((symbol, name) => {
|
2014
2045
|
symbolTable.set(name, symbol);
|
2015
2046
|
});
|
2016
2047
|
}
|
2017
|
-
moduleType.fields.forEach((symbol, name) => {
|
2048
|
+
moduleType.priv.fields.forEach((symbol, name) => {
|
2018
2049
|
symbolTable.set(name, symbol);
|
2019
2050
|
});
|
2020
2051
|
}
|
@@ -2099,8 +2130,9 @@ function isPartlyUnknown(type, recursionCount = 0) {
|
|
2099
2130
|
}
|
2100
2131
|
// If this is a generic type alias, see if any of its type arguments
|
2101
2132
|
// are either unspecified or are partially known.
|
2102
|
-
|
2103
|
-
|
2133
|
+
const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
2134
|
+
if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments) {
|
2135
|
+
if (aliasInfo.typeArguments.some((typeArg) => isPartlyUnknown(typeArg, recursionCount))) {
|
2104
2136
|
return true;
|
2105
2137
|
}
|
2106
2138
|
}
|
@@ -2113,11 +2145,11 @@ function isPartlyUnknown(type, recursionCount = 0) {
|
|
2113
2145
|
// If this is a reference to the class itself, as opposed to a reference
|
2114
2146
|
// to a type that represents the class and its subclasses, don't flag
|
2115
2147
|
// the type as partially unknown.
|
2116
|
-
if (!type.includeSubclasses) {
|
2148
|
+
if (!type.priv.includeSubclasses) {
|
2117
2149
|
return false;
|
2118
2150
|
}
|
2119
2151
|
if (!types_1.ClassType.isPseudoGenericClass(type)) {
|
2120
|
-
const typeArgs = ((_b = type.tupleTypeArguments) === null || _b === void 0 ? void 0 : _b.map((t) => t.type)) || type.typeArguments;
|
2152
|
+
const typeArgs = ((_b = type.priv.tupleTypeArguments) === null || _b === void 0 ? void 0 : _b.map((t) => t.type)) || type.priv.typeArguments;
|
2121
2153
|
if (typeArgs) {
|
2122
2154
|
for (const argType of typeArgs) {
|
2123
2155
|
if (isPartlyUnknown(argType, recursionCount)) {
|
@@ -2135,18 +2167,18 @@ function isPartlyUnknown(type, recursionCount = 0) {
|
|
2135
2167
|
});
|
2136
2168
|
}
|
2137
2169
|
if ((0, types_1.isFunction)(type)) {
|
2138
|
-
for (let i = 0; i < type.
|
2170
|
+
for (let i = 0; i < type.shared.parameters.length; i++) {
|
2139
2171
|
// Ignore parameters such as "*" that have no name.
|
2140
|
-
if (type.
|
2172
|
+
if (type.shared.parameters[i].name) {
|
2141
2173
|
const paramType = types_1.FunctionType.getEffectiveParameterType(type, i);
|
2142
2174
|
if (isPartlyUnknown(paramType, recursionCount)) {
|
2143
2175
|
return true;
|
2144
2176
|
}
|
2145
2177
|
}
|
2146
2178
|
}
|
2147
|
-
if (type.
|
2179
|
+
if (type.shared.declaredReturnType &&
|
2148
2180
|
!types_1.FunctionType.isParamSpecValue(type) &&
|
2149
|
-
isPartlyUnknown(type.
|
2181
|
+
isPartlyUnknown(type.shared.declaredReturnType, recursionCount)) {
|
2150
2182
|
return true;
|
2151
2183
|
}
|
2152
2184
|
return false;
|
@@ -2158,10 +2190,12 @@ exports.isPartlyUnknown = isPartlyUnknown;
|
|
2158
2190
|
// that is a union, it "explodes" the class into a union of classes with
|
2159
2191
|
// each element of the union - e.g. Foo[A | B] becomes Foo[A] | Foo[B].
|
2160
2192
|
function explodeGenericClass(classType) {
|
2161
|
-
if (!classType.
|
2193
|
+
if (!classType.priv.typeArguments ||
|
2194
|
+
classType.priv.typeArguments.length !== 1 ||
|
2195
|
+
!(0, types_1.isUnion)(classType.priv.typeArguments[0])) {
|
2162
2196
|
return classType;
|
2163
2197
|
}
|
2164
|
-
return (0, types_1.combineTypes)(classType.typeArguments[0].subtypes.map((subtype) => {
|
2198
|
+
return (0, types_1.combineTypes)(classType.priv.typeArguments[0].priv.subtypes.map((subtype) => {
|
2165
2199
|
return types_1.ClassType.cloneForSpecialization(classType, [subtype], /* isTypeArgumentExplicit */ true);
|
2166
2200
|
}));
|
2167
2201
|
}
|
@@ -2183,12 +2217,12 @@ function combineSameSizedTuples(type, tupleType) {
|
|
2183
2217
|
if (!tupleClass) {
|
2184
2218
|
// Look in the mro list to see if this subtype derives from a
|
2185
2219
|
// tuple with a known size. This includes named tuples.
|
2186
|
-
tupleClass = subtype.
|
2220
|
+
tupleClass = subtype.shared.mro.find((mroClass) => (0, types_1.isClass)(mroClass) && isTupleClass(mroClass) && !isUnboundedTupleClass(mroClass));
|
2187
2221
|
}
|
2188
|
-
if (tupleClass && (0, types_1.isClass)(tupleClass) && tupleClass.tupleTypeArguments) {
|
2222
|
+
if (tupleClass && (0, types_1.isClass)(tupleClass) && tupleClass.priv.tupleTypeArguments) {
|
2189
2223
|
if (tupleEntries) {
|
2190
|
-
if (tupleEntries.length === tupleClass.tupleTypeArguments.length) {
|
2191
|
-
tupleClass.tupleTypeArguments.forEach((entry, index) => {
|
2224
|
+
if (tupleEntries.length === tupleClass.priv.tupleTypeArguments.length) {
|
2225
|
+
tupleClass.priv.tupleTypeArguments.forEach((entry, index) => {
|
2192
2226
|
tupleEntries[index].push(entry.type);
|
2193
2227
|
});
|
2194
2228
|
}
|
@@ -2197,7 +2231,7 @@ function combineSameSizedTuples(type, tupleType) {
|
|
2197
2231
|
}
|
2198
2232
|
}
|
2199
2233
|
else {
|
2200
|
-
tupleEntries = tupleClass.tupleTypeArguments.map((entry) => [entry.type]);
|
2234
|
+
tupleEntries = tupleClass.priv.tupleTypeArguments.map((entry) => [entry.type]);
|
2201
2235
|
}
|
2202
2236
|
}
|
2203
2237
|
else {
|
@@ -2230,14 +2264,14 @@ function specializeTupleClass(classType, typeArgs, isTypeArgumentExplicit = true
|
|
2230
2264
|
const clonedClassType = types_1.ClassType.cloneForSpecialization(classType, [combinedTupleType], isTypeArgumentExplicit,
|
2231
2265
|
/* includeSubclasses */ undefined, typeArgs);
|
2232
2266
|
if (isUnpackedTuple) {
|
2233
|
-
clonedClassType.isUnpacked = true;
|
2267
|
+
clonedClassType.priv.isUnpacked = true;
|
2234
2268
|
}
|
2235
2269
|
return clonedClassType;
|
2236
2270
|
}
|
2237
2271
|
exports.specializeTupleClass = specializeTupleClass;
|
2238
2272
|
function _expandVariadicUnpackedUnion(type) {
|
2239
|
-
if ((0, types_1.isClassInstance)(type) && isTupleClass(type) && type.tupleTypeArguments && type.isUnpacked) {
|
2240
|
-
return (0, types_1.combineTypes)(type.tupleTypeArguments.map((t) => t.type));
|
2273
|
+
if ((0, types_1.isClassInstance)(type) && isTupleClass(type) && type.priv.tupleTypeArguments && type.priv.isUnpacked) {
|
2274
|
+
return (0, types_1.combineTypes)(type.priv.tupleTypeArguments.map((t) => t.type));
|
2241
2275
|
}
|
2242
2276
|
return type;
|
2243
2277
|
}
|
@@ -2247,29 +2281,29 @@ function getGeneratorTypeArgs(returnType) {
|
|
2247
2281
|
var _a;
|
2248
2282
|
if ((0, types_1.isClassInstance)(returnType)) {
|
2249
2283
|
if (types_1.ClassType.isBuiltIn(returnType, ['Generator', 'AsyncGenerator'])) {
|
2250
|
-
return returnType.typeArguments;
|
2284
|
+
return returnType.priv.typeArguments;
|
2251
2285
|
}
|
2252
2286
|
else if (types_1.ClassType.isBuiltIn(returnType, 'AwaitableGenerator')) {
|
2253
2287
|
// AwaitableGenerator has four type arguments, and the first 3
|
2254
2288
|
// correspond to the generator.
|
2255
|
-
return (_a = returnType.typeArguments) === null || _a === void 0 ? void 0 : _a.slice(0, 3);
|
2289
|
+
return (_a = returnType.priv.typeArguments) === null || _a === void 0 ? void 0 : _a.slice(0, 3);
|
2256
2290
|
}
|
2257
2291
|
}
|
2258
2292
|
return undefined;
|
2259
2293
|
}
|
2260
2294
|
exports.getGeneratorTypeArgs = getGeneratorTypeArgs;
|
2261
2295
|
function requiresTypeArguments(classType) {
|
2262
|
-
if (classType.
|
2263
|
-
const firstTypeParam = classType.
|
2296
|
+
if (classType.shared.typeParameters.length > 0) {
|
2297
|
+
const firstTypeParam = classType.shared.typeParameters[0];
|
2264
2298
|
// If there are type parameters, type arguments are needed.
|
2265
2299
|
// The exception is if type parameters have been synthesized
|
2266
2300
|
// for classes that have untyped constructors.
|
2267
|
-
if (firstTypeParam.
|
2301
|
+
if (firstTypeParam.shared.isSynthesized) {
|
2268
2302
|
return false;
|
2269
2303
|
}
|
2270
2304
|
// If the first type parameter has a default type, then no
|
2271
2305
|
// type arguments are needed.
|
2272
|
-
if (firstTypeParam.
|
2306
|
+
if (firstTypeParam.shared.isDefaultExplicit) {
|
2273
2307
|
return false;
|
2274
2308
|
}
|
2275
2309
|
return true;
|
@@ -2289,7 +2323,7 @@ function requiresTypeArguments(classType) {
|
|
2289
2323
|
'TypeGuard',
|
2290
2324
|
'TypeIs',
|
2291
2325
|
];
|
2292
|
-
if (specialClasses.some((t) => t === (classType.aliasName || classType.
|
2326
|
+
if (specialClasses.some((t) => t === (classType.priv.aliasName || classType.shared.name))) {
|
2293
2327
|
return true;
|
2294
2328
|
}
|
2295
2329
|
}
|
@@ -2318,9 +2352,9 @@ function requiresSpecialization(type, options, recursionCount = 0) {
|
|
2318
2352
|
}
|
2319
2353
|
exports.requiresSpecialization = requiresSpecialization;
|
2320
2354
|
function _requiresSpecialization(type, options, recursionCount = 0) {
|
2321
|
-
var _a;
|
2355
|
+
var _a, _b;
|
2322
2356
|
// If the type is conditioned on a TypeVar, it may need to be specialized.
|
2323
|
-
if (type.condition) {
|
2357
|
+
if ((_a = type.props) === null || _a === void 0 ? void 0 : _a.condition) {
|
2324
2358
|
return true;
|
2325
2359
|
}
|
2326
2360
|
switch (type.category) {
|
@@ -2328,53 +2362,54 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
|
|
2328
2362
|
if (types_1.ClassType.isPseudoGenericClass(type) && (options === null || options === void 0 ? void 0 : options.ignorePseudoGeneric)) {
|
2329
2363
|
return false;
|
2330
2364
|
}
|
2331
|
-
if (!type.isTypeArgumentExplicit && (options === null || options === void 0 ? void 0 : options.ignoreImplicitTypeArgs)) {
|
2365
|
+
if (!type.priv.isTypeArgumentExplicit && (options === null || options === void 0 ? void 0 : options.ignoreImplicitTypeArgs)) {
|
2332
2366
|
return false;
|
2333
2367
|
}
|
2334
|
-
if (type.typeArguments) {
|
2335
|
-
return type.typeArguments.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
|
2368
|
+
if (type.priv.typeArguments) {
|
2369
|
+
return type.priv.typeArguments.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
|
2336
2370
|
}
|
2337
2371
|
return types_1.ClassType.getTypeParameters(type).length > 0;
|
2338
2372
|
}
|
2339
2373
|
case 4 /* TypeCategory.Function */: {
|
2340
|
-
for (let i = 0; i < type.
|
2374
|
+
for (let i = 0; i < type.shared.parameters.length; i++) {
|
2341
2375
|
if (requiresSpecialization(types_1.FunctionType.getEffectiveParameterType(type, i), options, recursionCount)) {
|
2342
2376
|
return true;
|
2343
2377
|
}
|
2344
2378
|
}
|
2345
|
-
const declaredReturnType = type.specializedTypes && type.specializedTypes.returnType
|
2346
|
-
? type.specializedTypes.returnType
|
2347
|
-
: type.
|
2379
|
+
const declaredReturnType = type.priv.specializedTypes && type.priv.specializedTypes.returnType
|
2380
|
+
? type.priv.specializedTypes.returnType
|
2381
|
+
: type.shared.declaredReturnType;
|
2348
2382
|
if (declaredReturnType) {
|
2349
2383
|
if (requiresSpecialization(declaredReturnType, options, recursionCount)) {
|
2350
2384
|
return true;
|
2351
2385
|
}
|
2352
2386
|
}
|
2353
|
-
else if (type.inferredReturnType) {
|
2354
|
-
if (requiresSpecialization(type.inferredReturnType, options, recursionCount)) {
|
2387
|
+
else if (type.priv.inferredReturnType) {
|
2388
|
+
if (requiresSpecialization(type.priv.inferredReturnType, options, recursionCount)) {
|
2355
2389
|
return true;
|
2356
2390
|
}
|
2357
2391
|
}
|
2358
2392
|
return false;
|
2359
2393
|
}
|
2360
2394
|
case 5 /* TypeCategory.OverloadedFunction */: {
|
2361
|
-
return type.overloads.some((overload) => requiresSpecialization(overload, options, recursionCount));
|
2395
|
+
return type.priv.overloads.some((overload) => requiresSpecialization(overload, options, recursionCount));
|
2362
2396
|
}
|
2363
2397
|
case 8 /* TypeCategory.Union */: {
|
2364
|
-
return type.subtypes.some((subtype) => requiresSpecialization(subtype, options, recursionCount));
|
2398
|
+
return type.priv.subtypes.some((subtype) => requiresSpecialization(subtype, options, recursionCount));
|
2365
2399
|
}
|
2366
2400
|
case 9 /* TypeCategory.TypeVar */: {
|
2367
2401
|
// Most TypeVar types need to be specialized.
|
2368
|
-
if (!type.
|
2369
|
-
if (type.
|
2402
|
+
if (!type.shared.recursiveAlias) {
|
2403
|
+
if (type.shared.isSynthesizedSelf && (options === null || options === void 0 ? void 0 : options.ignoreSelf)) {
|
2370
2404
|
return false;
|
2371
2405
|
}
|
2372
2406
|
return true;
|
2373
2407
|
}
|
2374
2408
|
// If this is a recursive type alias, it may need to be specialized
|
2375
2409
|
// if it has generic type arguments.
|
2376
|
-
|
2377
|
-
|
2410
|
+
const aliasInfo = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo;
|
2411
|
+
if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments) {
|
2412
|
+
return aliasInfo.typeArguments.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
|
2378
2413
|
}
|
2379
2414
|
}
|
2380
2415
|
}
|
@@ -2399,23 +2434,23 @@ function isVarianceOfTypeArgumentCompatible(type, typeParamVariance) {
|
|
2399
2434
|
if (typeParamVariance === 1 /* Variance.Unknown */ || typeParamVariance === 0 /* Variance.Auto */) {
|
2400
2435
|
return true;
|
2401
2436
|
}
|
2402
|
-
if ((0, types_1.isTypeVar)(type) && !type.
|
2403
|
-
const typeArgVariance = type.
|
2437
|
+
if ((0, types_1.isTypeVar)(type) && !type.shared.isParamSpec && !type.shared.isVariadic) {
|
2438
|
+
const typeArgVariance = type.shared.declaredVariance;
|
2404
2439
|
if (typeArgVariance === 4 /* Variance.Contravariant */ || typeArgVariance === 3 /* Variance.Covariant */) {
|
2405
2440
|
return typeArgVariance === typeParamVariance;
|
2406
2441
|
}
|
2407
2442
|
}
|
2408
2443
|
else if ((0, types_1.isClassInstance)(type)) {
|
2409
|
-
if (type.
|
2410
|
-
return type.
|
2444
|
+
if (type.shared.typeParameters && type.shared.typeParameters.length > 0) {
|
2445
|
+
return type.shared.typeParameters.every((typeParam, index) => {
|
2411
2446
|
let typeArgType;
|
2412
|
-
if (typeParam.
|
2447
|
+
if (typeParam.shared.isParamSpec || typeParam.shared.isVariadic) {
|
2413
2448
|
return true;
|
2414
2449
|
}
|
2415
|
-
if (type.typeArguments && index < type.typeArguments.length) {
|
2416
|
-
typeArgType = type.typeArguments[index];
|
2450
|
+
if (type.priv.typeArguments && index < type.priv.typeArguments.length) {
|
2451
|
+
typeArgType = type.priv.typeArguments[index];
|
2417
2452
|
}
|
2418
|
-
const declaredVariance = typeParam.
|
2453
|
+
const declaredVariance = typeParam.shared.declaredVariance;
|
2419
2454
|
if (declaredVariance === 0 /* Variance.Auto */) {
|
2420
2455
|
return true;
|
2421
2456
|
}
|
@@ -2449,8 +2484,8 @@ exports.isVarianceOfTypeArgumentCompatible = isVarianceOfTypeArgumentCompatible;
|
|
2449
2484
|
function computeMroLinearization(classType) {
|
2450
2485
|
let isMroFound = true;
|
2451
2486
|
// Clear out any existing MRO information.
|
2452
|
-
classType.
|
2453
|
-
const filteredBaseClasses = classType.
|
2487
|
+
classType.shared.mro = [];
|
2488
|
+
const filteredBaseClasses = classType.shared.baseClasses.filter((baseClass, index) => {
|
2454
2489
|
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
2455
2490
|
// Generic has some special-case logic (see description of __mro_entries__
|
2456
2491
|
// in PEP 560) that we need to account for here.
|
@@ -2463,11 +2498,11 @@ function computeMroLinearization(classType) {
|
|
2463
2498
|
// If the class contains any specialized generic classes after
|
2464
2499
|
// the Generic base, the Generic base is ignored for purposes
|
2465
2500
|
// of computing the MRO.
|
2466
|
-
if (classType.
|
2501
|
+
if (classType.shared.baseClasses.some((innerBaseClass, innerIndex) => {
|
2467
2502
|
return (innerIndex > index &&
|
2468
2503
|
(0, types_1.isInstantiableClass)(innerBaseClass) &&
|
2469
|
-
innerBaseClass.typeArguments &&
|
2470
|
-
innerBaseClass.isTypeArgumentExplicit);
|
2504
|
+
innerBaseClass.priv.typeArguments &&
|
2505
|
+
innerBaseClass.priv.isTypeArgumentExplicit);
|
2471
2506
|
})) {
|
2472
2507
|
return false;
|
2473
2508
|
}
|
@@ -2480,7 +2515,7 @@ function computeMroLinearization(classType) {
|
|
2480
2515
|
filteredBaseClasses.forEach((baseClass) => {
|
2481
2516
|
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
2482
2517
|
const typeVarContext = buildTypeVarContextFromSpecializedClass(baseClass);
|
2483
|
-
classListsToMerge.push(baseClass.
|
2518
|
+
classListsToMerge.push(baseClass.shared.mro.map((mroClass) => {
|
2484
2519
|
return applySolvedTypeVars(mroClass, typeVarContext);
|
2485
2520
|
}));
|
2486
2521
|
}
|
@@ -2498,7 +2533,7 @@ function computeMroLinearization(classType) {
|
|
2498
2533
|
if (!(0, types_1.isClass)(specializedClassType) && !(0, types_1.isAnyOrUnknown)(specializedClassType)) {
|
2499
2534
|
specializedClassType = types_1.UnknownType.create();
|
2500
2535
|
}
|
2501
|
-
classType.
|
2536
|
+
classType.shared.mro.push(specializedClassType);
|
2502
2537
|
// Helper function that returns true if the specified searchClass
|
2503
2538
|
// is found in the "tail" (i.e. in elements 1 through n) of any
|
2504
2539
|
// of the class lists.
|
@@ -2532,13 +2567,13 @@ function computeMroLinearization(classType) {
|
|
2532
2567
|
if (!(0, types_1.isClass)(head) && !(0, types_1.isAnyOrUnknown)(head)) {
|
2533
2568
|
head = types_1.UnknownType.create();
|
2534
2569
|
}
|
2535
|
-
classType.
|
2570
|
+
classType.shared.mro.push(head);
|
2536
2571
|
classList.shift();
|
2537
2572
|
break;
|
2538
2573
|
}
|
2539
2574
|
if (!isInTail(classList[0], classListsToMerge)) {
|
2540
2575
|
foundValidHead = true;
|
2541
|
-
classType.
|
2576
|
+
classType.shared.mro.push(classList[0]);
|
2542
2577
|
filterClass(classList[0], classListsToMerge);
|
2543
2578
|
break;
|
2544
2579
|
}
|
@@ -2560,11 +2595,11 @@ function computeMroLinearization(classType) {
|
|
2560
2595
|
if (!(0, types_1.isClass)(head) && !(0, types_1.isAnyOrUnknown)(head)) {
|
2561
2596
|
head = types_1.UnknownType.create();
|
2562
2597
|
}
|
2563
|
-
classType.
|
2598
|
+
classType.shared.mro.push(head);
|
2564
2599
|
nonEmptyList.shift();
|
2565
2600
|
}
|
2566
2601
|
else {
|
2567
|
-
classType.
|
2602
|
+
classType.shared.mro.push(nonEmptyList[0]);
|
2568
2603
|
filterClass(nonEmptyList[0], classListsToMerge);
|
2569
2604
|
}
|
2570
2605
|
}
|
@@ -2581,6 +2616,14 @@ function getDeclaringModulesForType(type) {
|
|
2581
2616
|
return moduleList;
|
2582
2617
|
}
|
2583
2618
|
exports.getDeclaringModulesForType = getDeclaringModulesForType;
|
2619
|
+
function convertArgumentNodeToFunctionArgument(node) {
|
2620
|
+
return {
|
2621
|
+
argumentCategory: node.d.argCategory,
|
2622
|
+
name: node.d.name,
|
2623
|
+
valueExpression: node.d.valueExpr,
|
2624
|
+
};
|
2625
|
+
}
|
2626
|
+
exports.convertArgumentNodeToFunctionArgument = convertArgumentNodeToFunctionArgument;
|
2584
2627
|
function addDeclaringModuleNamesForType(type, moduleList, recursionCount = 0) {
|
2585
2628
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
2586
2629
|
return;
|
@@ -2593,15 +2636,15 @@ function addDeclaringModuleNamesForType(type, moduleList, recursionCount = 0) {
|
|
2593
2636
|
};
|
2594
2637
|
switch (type.category) {
|
2595
2638
|
case 6 /* TypeCategory.Class */: {
|
2596
|
-
addIfUnique(type.
|
2639
|
+
addIfUnique(type.shared.moduleName);
|
2597
2640
|
break;
|
2598
2641
|
}
|
2599
2642
|
case 4 /* TypeCategory.Function */: {
|
2600
|
-
addIfUnique(type.
|
2643
|
+
addIfUnique(type.shared.moduleName);
|
2601
2644
|
break;
|
2602
2645
|
}
|
2603
2646
|
case 5 /* TypeCategory.OverloadedFunction */: {
|
2604
|
-
type.overloads.forEach((overload) => {
|
2647
|
+
type.priv.overloads.forEach((overload) => {
|
2605
2648
|
addDeclaringModuleNamesForType(overload, moduleList, recursionCount);
|
2606
2649
|
});
|
2607
2650
|
break;
|
@@ -2613,7 +2656,7 @@ function addDeclaringModuleNamesForType(type, moduleList, recursionCount = 0) {
|
|
2613
2656
|
break;
|
2614
2657
|
}
|
2615
2658
|
case 7 /* TypeCategory.Module */: {
|
2616
|
-
addIfUnique(type.moduleName);
|
2659
|
+
addIfUnique(type.priv.moduleName);
|
2617
2660
|
break;
|
2618
2661
|
}
|
2619
2662
|
}
|
@@ -2625,27 +2668,20 @@ function convertTypeToParamSpecValue(type) {
|
|
2625
2668
|
if ((0, types_1.isParamSpec)(type)) {
|
2626
2669
|
const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
2627
2670
|
types_1.FunctionType.addParamSpecVariadics(newFunction, type);
|
2628
|
-
newFunction.
|
2671
|
+
newFunction.shared.typeVarScopeId = getTypeVarScopeId(type);
|
2629
2672
|
return newFunction;
|
2630
2673
|
}
|
2631
2674
|
if ((0, types_1.isFunction)(type)) {
|
2632
|
-
const newFunction = types_1.FunctionType.createInstance('', '', '', type.
|
2633
|
-
newFunction.
|
2634
|
-
type.
|
2635
|
-
types_1.FunctionType.addParameter(newFunction,
|
2636
|
-
category: param.category,
|
2637
|
-
name: param.name,
|
2638
|
-
hasDefault: param.hasDefault,
|
2639
|
-
defaultValueExpression: param.defaultValueExpression,
|
2640
|
-
isNameSynthesized: param.isNameSynthesized,
|
2641
|
-
type: types_1.FunctionType.getEffectiveParameterType(type, index),
|
2642
|
-
});
|
2675
|
+
const newFunction = types_1.FunctionType.createInstance('', '', '', type.shared.flags | 65536 /* FunctionTypeFlags.ParamSpecValue */, type.shared.docString);
|
2676
|
+
newFunction.shared.deprecatedMessage = type.shared.deprecatedMessage;
|
2677
|
+
type.shared.parameters.forEach((param, index) => {
|
2678
|
+
types_1.FunctionType.addParameter(newFunction, types_1.FunctionParam.create(param.category, types_1.FunctionType.getEffectiveParameterType(type, index), param.flags & types_1.FunctionParamFlags.NameSynthesized, param.name, param.defaultType));
|
2643
2679
|
});
|
2644
|
-
if (type.
|
2645
|
-
newFunction.
|
2646
|
-
newFunction.
|
2680
|
+
if (type.priv.higherOrderTypeVarScopeIds) {
|
2681
|
+
newFunction.priv.higherOrderTypeVarScopeIds = [...type.priv.higherOrderTypeVarScopeIds];
|
2682
|
+
newFunction.shared.typeVarScopeId = newFunction.priv.higherOrderTypeVarScopeIds.pop();
|
2647
2683
|
}
|
2648
|
-
newFunction.
|
2684
|
+
newFunction.priv.constructorTypeVarScopeId = type.priv.constructorTypeVarScopeId;
|
2649
2685
|
return newFunction;
|
2650
2686
|
}
|
2651
2687
|
return getUnknownTypeForParamSpec();
|
@@ -2656,11 +2692,11 @@ exports.convertTypeToParamSpecValue = convertTypeToParamSpecValue;
|
|
2656
2692
|
function convertParamSpecValueToType(type) {
|
2657
2693
|
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
|
2658
2694
|
const withoutParamSpec = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(type);
|
2659
|
-
let hasParameters = withoutParamSpec.
|
2660
|
-
if (withoutParamSpec.
|
2695
|
+
let hasParameters = withoutParamSpec.shared.parameters.length > 0;
|
2696
|
+
if (withoutParamSpec.shared.parameters.length === 1) {
|
2661
2697
|
// If the ParamSpec has a position-only separator as its only parameter,
|
2662
2698
|
// treat it as though there are no parameters.
|
2663
|
-
const onlyParam = withoutParamSpec.
|
2699
|
+
const onlyParam = withoutParamSpec.shared.parameters[0];
|
2664
2700
|
if ((0, types_1.isPositionOnlySeparator)(onlyParam)) {
|
2665
2701
|
hasParameters = false;
|
2666
2702
|
}
|
@@ -2670,27 +2706,19 @@ function convertParamSpecValueToType(type) {
|
|
2670
2706
|
return paramSpec;
|
2671
2707
|
}
|
2672
2708
|
// Create a function type from the param spec entries.
|
2673
|
-
const functionType = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | withoutParamSpec.
|
2674
|
-
types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.
|
2675
|
-
types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.
|
2676
|
-
functionType.
|
2677
|
-
withoutParamSpec.
|
2678
|
-
types_1.FunctionType.addParameter(functionType,
|
2679
|
-
category: entry.category,
|
2680
|
-
name: entry.name,
|
2681
|
-
hasDefault: entry.hasDefault,
|
2682
|
-
defaultValueExpression: entry.defaultValueExpression,
|
2683
|
-
isNameSynthesized: entry.isNameSynthesized,
|
2684
|
-
hasDeclaredType: true,
|
2685
|
-
type: types_1.FunctionType.getEffectiveParameterType(withoutParamSpec, index),
|
2686
|
-
});
|
2709
|
+
const functionType = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | withoutParamSpec.shared.flags);
|
2710
|
+
types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.shared.typeVarScopeId);
|
2711
|
+
types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.priv.higherOrderTypeVarScopeIds);
|
2712
|
+
functionType.priv.constructorTypeVarScopeId = withoutParamSpec.priv.constructorTypeVarScopeId;
|
2713
|
+
withoutParamSpec.shared.parameters.forEach((entry, index) => {
|
2714
|
+
types_1.FunctionType.addParameter(functionType, types_1.FunctionParam.create(entry.category, types_1.FunctionType.getEffectiveParameterType(withoutParamSpec, index), (entry.flags & types_1.FunctionParamFlags.NameSynthesized) | types_1.FunctionParamFlags.TypeDeclared, entry.name, entry.defaultType));
|
2687
2715
|
});
|
2688
2716
|
if (paramSpec) {
|
2689
2717
|
types_1.FunctionType.addParamSpecVariadics(functionType, paramSpec);
|
2690
2718
|
}
|
2691
|
-
functionType.
|
2692
|
-
functionType.
|
2693
|
-
functionType.
|
2719
|
+
functionType.shared.docString = withoutParamSpec.shared.docString;
|
2720
|
+
functionType.shared.deprecatedMessage = withoutParamSpec.shared.deprecatedMessage;
|
2721
|
+
functionType.shared.methodClass = withoutParamSpec.shared.methodClass;
|
2694
2722
|
return functionType;
|
2695
2723
|
}
|
2696
2724
|
exports.convertParamSpecValueToType = convertParamSpecValueToType;
|
@@ -2703,7 +2731,7 @@ class TypeVarTransformer {
|
|
2703
2731
|
this._pendingFunctionTransformations = [];
|
2704
2732
|
}
|
2705
2733
|
apply(type, recursionCount) {
|
2706
|
-
var _a, _b;
|
2734
|
+
var _a, _b, _c;
|
2707
2735
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
2708
2736
|
return type;
|
2709
2737
|
}
|
@@ -2711,7 +2739,7 @@ class TypeVarTransformer {
|
|
2711
2739
|
type = this.transformGenericTypeAlias(type, recursionCount);
|
2712
2740
|
// If the type is conditioned on a type variable, see if the condition
|
2713
2741
|
// still applies.
|
2714
|
-
if (type.condition) {
|
2742
|
+
if ((_a = type.props) === null || _a === void 0 ? void 0 : _a.condition) {
|
2715
2743
|
type = this.transformConditionalType(type, recursionCount);
|
2716
2744
|
}
|
2717
2745
|
// Shortcut the operation if possible.
|
@@ -2728,12 +2756,13 @@ class TypeVarTransformer {
|
|
2728
2756
|
// Handle recursive type aliases specially. In particular,
|
2729
2757
|
// we need to specialize type arguments for generic recursive
|
2730
2758
|
// type aliases.
|
2731
|
-
|
2732
|
-
|
2759
|
+
const aliasInfo = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo;
|
2760
|
+
if (type.shared.recursiveAlias) {
|
2761
|
+
if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments)) {
|
2733
2762
|
return type;
|
2734
2763
|
}
|
2735
2764
|
let requiresUpdate = false;
|
2736
|
-
const typeArgs =
|
2765
|
+
const typeArgs = aliasInfo.typeArguments.map((typeArg) => {
|
2737
2766
|
const replacementType = this.apply(typeArg, recursionCount);
|
2738
2767
|
if (replacementType !== typeArg) {
|
2739
2768
|
requiresUpdate = true;
|
@@ -2741,7 +2770,7 @@ class TypeVarTransformer {
|
|
2741
2770
|
return replacementType;
|
2742
2771
|
});
|
2743
2772
|
if (requiresUpdate) {
|
2744
|
-
return types_1.TypeBase.cloneForTypeAlias(type,
|
2773
|
+
return types_1.TypeBase.cloneForTypeAlias(type, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParameters, typeArgs);
|
2745
2774
|
}
|
2746
2775
|
return type;
|
2747
2776
|
}
|
@@ -2749,18 +2778,18 @@ class TypeVarTransformer {
|
|
2749
2778
|
// Recursively transform the results, but ensure that we don't replace any
|
2750
2779
|
// type variables in the same scope recursively by setting it the scope in the
|
2751
2780
|
// _pendingTypeVarTransformations set.
|
2752
|
-
if (!this._isTypeVarScopePending(type.scopeId)) {
|
2753
|
-
if (type.
|
2781
|
+
if (!this._isTypeVarScopePending(type.priv.scopeId)) {
|
2782
|
+
if (type.shared.isParamSpec) {
|
2754
2783
|
let paramSpecWithoutAccess = type;
|
2755
|
-
if (type.paramSpecAccess) {
|
2784
|
+
if (type.priv.paramSpecAccess) {
|
2756
2785
|
paramSpecWithoutAccess = types_1.TypeVarType.cloneForParamSpecAccess(type, /* access */ undefined);
|
2757
2786
|
}
|
2758
2787
|
const paramSpecValue = this.transformParamSpec(paramSpecWithoutAccess, recursionCount);
|
2759
2788
|
if (paramSpecValue) {
|
2760
2789
|
const paramSpecType = convertParamSpecValueToType(paramSpecValue);
|
2761
|
-
if (type.paramSpecAccess) {
|
2790
|
+
if (type.priv.paramSpecAccess) {
|
2762
2791
|
if ((0, types_1.isParamSpec)(paramSpecType)) {
|
2763
|
-
replacementType = types_1.TypeVarType.cloneForParamSpecAccess(paramSpecType, type.paramSpecAccess);
|
2792
|
+
replacementType = types_1.TypeVarType.cloneForParamSpecAccess(paramSpecType, type.priv.paramSpecAccess);
|
2764
2793
|
}
|
2765
2794
|
else {
|
2766
2795
|
replacementType = types_1.UnknownType.create();
|
@@ -2772,19 +2801,19 @@ class TypeVarTransformer {
|
|
2772
2801
|
}
|
2773
2802
|
}
|
2774
2803
|
else {
|
2775
|
-
replacementType = (
|
2804
|
+
replacementType = (_c = this.transformTypeVar(type, recursionCount)) !== null && _c !== void 0 ? _c : type;
|
2776
2805
|
if (!this._isTransformingTypeArg) {
|
2777
|
-
if (type.scopeId) {
|
2778
|
-
this._pendingTypeVarTransformations.add(type.scopeId);
|
2806
|
+
if (type.priv.scopeId) {
|
2807
|
+
this._pendingTypeVarTransformations.add(type.priv.scopeId);
|
2779
2808
|
}
|
2780
2809
|
replacementType = this.apply(replacementType, recursionCount);
|
2781
|
-
if (type.scopeId) {
|
2782
|
-
this._pendingTypeVarTransformations.delete(type.scopeId);
|
2810
|
+
if (type.priv.scopeId) {
|
2811
|
+
this._pendingTypeVarTransformations.delete(type.priv.scopeId);
|
2783
2812
|
}
|
2784
2813
|
}
|
2785
2814
|
// If we're transforming a variadic type variable that was in a union,
|
2786
2815
|
// expand the union types.
|
2787
|
-
if ((0, types_1.isVariadicTypeVar)(type) && type.isVariadicInUnion) {
|
2816
|
+
if ((0, types_1.isVariadicTypeVar)(type) && type.priv.isVariadicInUnion) {
|
2788
2817
|
replacementType = _expandVariadicUnpackedUnion(replacementType);
|
2789
2818
|
}
|
2790
2819
|
}
|
@@ -2807,7 +2836,7 @@ class TypeVarTransformer {
|
|
2807
2836
|
return this.transformUnionSubtype(subtype, transformedType, recursionCount);
|
2808
2837
|
}
|
2809
2838
|
return transformedType;
|
2810
|
-
});
|
2839
|
+
}, { retainTypeAlias: true });
|
2811
2840
|
return !(0, types_1.isNever)(newUnionType) ? newUnionType : types_1.UnknownType.create();
|
2812
2841
|
}
|
2813
2842
|
if ((0, types_1.isClass)(type)) {
|
@@ -2832,13 +2861,13 @@ class TypeVarTransformer {
|
|
2832
2861
|
let requiresUpdate = false;
|
2833
2862
|
// Specialize each of the functions in the overload.
|
2834
2863
|
const newOverloads = [];
|
2835
|
-
type.overloads.forEach((entry) => {
|
2864
|
+
type.priv.overloads.forEach((entry) => {
|
2836
2865
|
const replacementType = this.transformTypeVarsInFunctionType(entry, recursionCount);
|
2837
2866
|
if ((0, types_1.isFunction)(replacementType)) {
|
2838
2867
|
newOverloads.push(replacementType);
|
2839
2868
|
}
|
2840
2869
|
else {
|
2841
|
-
(0, collectionUtils_1.appendArray)(newOverloads, replacementType.overloads);
|
2870
|
+
(0, collectionUtils_1.appendArray)(newOverloads, replacementType.priv.overloads);
|
2842
2871
|
}
|
2843
2872
|
if (replacementType !== entry) {
|
2844
2873
|
requiresUpdate = true;
|
@@ -2868,11 +2897,13 @@ class TypeVarTransformer {
|
|
2868
2897
|
return callback();
|
2869
2898
|
}
|
2870
2899
|
transformGenericTypeAlias(type, recursionCount) {
|
2871
|
-
|
2900
|
+
var _a;
|
2901
|
+
const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
2902
|
+
if (!aliasInfo || !aliasInfo.typeParameters || !aliasInfo.typeArguments) {
|
2872
2903
|
return type;
|
2873
2904
|
}
|
2874
2905
|
let requiresUpdate = false;
|
2875
|
-
const newTypeArgs =
|
2906
|
+
const newTypeArgs = aliasInfo.typeArguments.map((typeArg) => {
|
2876
2907
|
const updatedType = this.apply(typeArg, recursionCount);
|
2877
2908
|
if (type !== updatedType) {
|
2878
2909
|
requiresUpdate = true;
|
@@ -2880,7 +2911,7 @@ class TypeVarTransformer {
|
|
2880
2911
|
return updatedType;
|
2881
2912
|
});
|
2882
2913
|
return requiresUpdate
|
2883
|
-
? types_1.TypeBase.cloneForTypeAlias(type,
|
2914
|
+
? types_1.TypeBase.cloneForTypeAlias(type, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParameters, newTypeArgs)
|
2884
2915
|
: type;
|
2885
2916
|
}
|
2886
2917
|
transformConditionalType(type, recursionCount) {
|
@@ -2913,9 +2944,9 @@ class TypeVarTransformer {
|
|
2913
2944
|
// If type args were previously provided, specialize them.
|
2914
2945
|
// Handle tuples specially.
|
2915
2946
|
if (types_1.ClassType.isTupleClass(classType)) {
|
2916
|
-
if (classType.tupleTypeArguments) {
|
2947
|
+
if (classType.priv.tupleTypeArguments) {
|
2917
2948
|
newTupleTypeArgs = [];
|
2918
|
-
classType.tupleTypeArguments.forEach((oldTypeArgType) => {
|
2949
|
+
classType.priv.tupleTypeArguments.forEach((oldTypeArgType) => {
|
2919
2950
|
const newTypeArgType = this.apply(oldTypeArgType.type, recursionCount);
|
2920
2951
|
if (newTypeArgType !== oldTypeArgType.type) {
|
2921
2952
|
specializationNeeded = true;
|
@@ -2923,8 +2954,8 @@ class TypeVarTransformer {
|
|
2923
2954
|
if ((0, types_1.isUnpackedVariadicTypeVar)(oldTypeArgType.type) &&
|
2924
2955
|
(0, types_1.isClassInstance)(newTypeArgType) &&
|
2925
2956
|
isTupleClass(newTypeArgType) &&
|
2926
|
-
newTypeArgType.tupleTypeArguments) {
|
2927
|
-
(0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.tupleTypeArguments);
|
2957
|
+
newTypeArgType.priv.tupleTypeArguments) {
|
2958
|
+
(0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.priv.tupleTypeArguments);
|
2928
2959
|
}
|
2929
2960
|
else {
|
2930
2961
|
// Handle the special case where tuple[T, ...] is being specialized
|
@@ -2932,7 +2963,7 @@ class TypeVarTransformer {
|
|
2932
2963
|
const isEmptyTuple = oldTypeArgType.isUnbounded &&
|
2933
2964
|
(0, types_1.isTypeVar)(oldTypeArgType.type) &&
|
2934
2965
|
(0, types_1.isNever)(newTypeArgType) &&
|
2935
|
-
classType.tupleTypeArguments.length === 1;
|
2966
|
+
classType.priv.tupleTypeArguments.length === 1;
|
2936
2967
|
if (!isEmptyTuple) {
|
2937
2968
|
newTupleTypeArgs.push({
|
2938
2969
|
type: newTypeArgType,
|
@@ -2969,9 +3000,9 @@ class TypeVarTransformer {
|
|
2969
3000
|
}
|
2970
3001
|
}
|
2971
3002
|
if (!newTypeArgs) {
|
2972
|
-
if (classType.typeArguments) {
|
2973
|
-
newTypeArgs = classType.typeArguments.map((oldTypeArgType) => {
|
2974
|
-
if ((0, types_1.isTypeVar)(oldTypeArgType) && oldTypeArgType.
|
3003
|
+
if (classType.priv.typeArguments) {
|
3004
|
+
newTypeArgs = classType.priv.typeArguments.map((oldTypeArgType) => {
|
3005
|
+
if ((0, types_1.isTypeVar)(oldTypeArgType) && oldTypeArgType.shared.isParamSpec) {
|
2975
3006
|
return transformParamSpec(oldTypeArgType);
|
2976
3007
|
}
|
2977
3008
|
let newTypeArgType = this.apply(oldTypeArgType, recursionCount);
|
@@ -2981,7 +3012,7 @@ class TypeVarTransformer {
|
|
2981
3012
|
// (e.g. Union[Unpack[Vs]]), expand the subtypes into a union here.
|
2982
3013
|
if ((0, types_1.isTypeVar)(oldTypeArgType) &&
|
2983
3014
|
(0, types_1.isVariadicTypeVar)(oldTypeArgType) &&
|
2984
|
-
oldTypeArgType.isVariadicInUnion) {
|
3015
|
+
oldTypeArgType.priv.isVariadicInUnion) {
|
2985
3016
|
newTypeArgType = _expandVariadicUnpackedUnion(newTypeArgType);
|
2986
3017
|
}
|
2987
3018
|
}
|
@@ -2992,20 +3023,20 @@ class TypeVarTransformer {
|
|
2992
3023
|
newTypeArgs = [];
|
2993
3024
|
typeParams.forEach((typeParam) => {
|
2994
3025
|
let replacementType = typeParam;
|
2995
|
-
if (typeParam.
|
3026
|
+
if (typeParam.shared.isParamSpec) {
|
2996
3027
|
replacementType = transformParamSpec(typeParam);
|
2997
3028
|
if (replacementType !== typeParam) {
|
2998
3029
|
specializationNeeded = true;
|
2999
3030
|
}
|
3000
3031
|
}
|
3001
3032
|
else {
|
3002
|
-
if (!this._isTypeVarScopePending(typeParam.scopeId)) {
|
3033
|
+
if (!this._isTypeVarScopePending(typeParam.priv.scopeId)) {
|
3003
3034
|
const transformedType = this.transformTypeVar(typeParam, recursionCount);
|
3004
3035
|
replacementType = transformedType !== null && transformedType !== void 0 ? transformedType : typeParam;
|
3005
3036
|
if (replacementType !== typeParam) {
|
3006
3037
|
specializationNeeded = true;
|
3007
3038
|
}
|
3008
|
-
else if (transformedType !== undefined && !classType.typeArguments) {
|
3039
|
+
else if (transformedType !== undefined && !classType.priv.typeArguments) {
|
3009
3040
|
specializationNeeded = true;
|
3010
3041
|
}
|
3011
3042
|
}
|
@@ -3033,6 +3064,7 @@ class TypeVarTransformer {
|
|
3033
3064
|
let typesRequiredSpecialization = declaredReturnType !== specializedReturnType;
|
3034
3065
|
const specializedParameters = {
|
3035
3066
|
parameterTypes: [],
|
3067
|
+
parameterDefaultArgs: undefined,
|
3036
3068
|
returnType: specializedReturnType,
|
3037
3069
|
};
|
3038
3070
|
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(functionType);
|
@@ -3040,7 +3072,7 @@ class TypeVarTransformer {
|
|
3040
3072
|
const paramSpecType = this.transformParamSpec(paramSpec, recursionCount);
|
3041
3073
|
if (paramSpecType) {
|
3042
3074
|
const transformedParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(paramSpecType);
|
3043
|
-
if (paramSpecType.
|
3075
|
+
if (paramSpecType.shared.parameters.length > 0 ||
|
3044
3076
|
!transformedParamSpec ||
|
3045
3077
|
!(0, types_1.isTypeSame)(paramSpec, transformedParamSpec)) {
|
3046
3078
|
functionType = types_1.FunctionType.applyParamSpecValue(functionType, paramSpecType);
|
@@ -3052,7 +3084,7 @@ class TypeVarTransformer {
|
|
3052
3084
|
const specializedDefaultArgs = [];
|
3053
3085
|
const wasTransformingTypeArg = this._isTransformingTypeArg;
|
3054
3086
|
this._isTransformingTypeArg = true;
|
3055
|
-
for (let i = 0; i < functionType.
|
3087
|
+
for (let i = 0; i < functionType.shared.parameters.length; i++) {
|
3056
3088
|
const paramType = types_1.FunctionType.getEffectiveParameterType(functionType, i);
|
3057
3089
|
const specializedType = this.apply(paramType, recursionCount);
|
3058
3090
|
specializedParameters.parameterTypes.push(specializedType);
|
@@ -3068,12 +3100,12 @@ class TypeVarTransformer {
|
|
3068
3100
|
specializedDefaultArgs.push(defaultArgType);
|
3069
3101
|
if (variadicParamIndex === undefined &&
|
3070
3102
|
(0, types_1.isVariadicTypeVar)(paramType) &&
|
3071
|
-
functionType.
|
3103
|
+
functionType.shared.parameters[i].category === 1 /* ParameterCategory.ArgsList */) {
|
3072
3104
|
variadicParamIndex = i;
|
3073
3105
|
if ((0, types_1.isClassInstance)(specializedType) &&
|
3074
3106
|
isTupleClass(specializedType) &&
|
3075
|
-
specializedType.isUnpacked) {
|
3076
|
-
variadicTypesToUnpack = specializedType.tupleTypeArguments;
|
3107
|
+
specializedType.priv.isUnpacked) {
|
3108
|
+
variadicTypesToUnpack = specializedType.priv.tupleTypeArguments;
|
3077
3109
|
}
|
3078
3110
|
}
|
3079
3111
|
if (paramType !== specializedType) {
|
@@ -3081,12 +3113,27 @@ class TypeVarTransformer {
|
|
3081
3113
|
}
|
3082
3114
|
}
|
3083
3115
|
let specializedInferredReturnType;
|
3084
|
-
if (functionType.inferredReturnType) {
|
3085
|
-
specializedInferredReturnType = this.apply(functionType.inferredReturnType, recursionCount);
|
3086
|
-
if (specializedInferredReturnType !== functionType.inferredReturnType) {
|
3116
|
+
if (functionType.priv.inferredReturnType) {
|
3117
|
+
specializedInferredReturnType = this.apply(functionType.priv.inferredReturnType, recursionCount);
|
3118
|
+
if (specializedInferredReturnType !== functionType.priv.inferredReturnType) {
|
3087
3119
|
typesRequiredSpecialization = true;
|
3088
3120
|
}
|
3089
3121
|
}
|
3122
|
+
// Do we need to update the boundToType?
|
3123
|
+
if (functionType.priv.boundToType) {
|
3124
|
+
const newBoundToType = this.apply(functionType.priv.boundToType, recursionCount);
|
3125
|
+
if (newBoundToType !== functionType.priv.boundToType && (0, types_1.isClass)(newBoundToType)) {
|
3126
|
+
functionType = types_1.FunctionType.clone(functionType, /* stripFirstParam */ false, newBoundToType);
|
3127
|
+
}
|
3128
|
+
}
|
3129
|
+
// Do we need to update the strippedFirstParamType?
|
3130
|
+
if (functionType.priv.strippedFirstParamType) {
|
3131
|
+
const newStrippedType = this.apply(functionType.priv.strippedFirstParamType, recursionCount);
|
3132
|
+
if (newStrippedType !== functionType.priv.strippedFirstParamType) {
|
3133
|
+
functionType = types_1.TypeBase.cloneType(functionType);
|
3134
|
+
functionType.priv.strippedFirstParamType = newStrippedType;
|
3135
|
+
}
|
3136
|
+
}
|
3090
3137
|
this._isTransformingTypeArg = wasTransformingTypeArg;
|
3091
3138
|
if (!typesRequiredSpecialization) {
|
3092
3139
|
return functionType;
|
@@ -3100,8 +3147,8 @@ class TypeVarTransformer {
|
|
3100
3147
|
}
|
3101
3148
|
// Unpack the tuple and synthesize a new function in the process.
|
3102
3149
|
const newFunctionType = types_1.TypeBase.isInstantiable(functionType)
|
3103
|
-
? types_1.FunctionType.createInstantiable(functionType.
|
3104
|
-
: types_1.FunctionType.createSynthesizedInstance('', functionType.
|
3150
|
+
? types_1.FunctionType.createInstantiable(functionType.shared.flags | 64 /* FunctionTypeFlags.SynthesizedMethod */)
|
3151
|
+
: types_1.FunctionType.createSynthesizedInstance('', functionType.shared.flags);
|
3105
3152
|
let insertKeywordOnlySeparator = false;
|
3106
3153
|
let swallowPositionOnlySeparator = false;
|
3107
3154
|
specializedParameters.parameterTypes.forEach((paramType, index) => {
|
@@ -3109,15 +3156,9 @@ class TypeVarTransformer {
|
|
3109
3156
|
let sawUnboundedEntry = false;
|
3110
3157
|
// Unpack the tuple into individual parameters.
|
3111
3158
|
variadicTypesToUnpack.forEach((unpackedType) => {
|
3112
|
-
types_1.FunctionType.addParameter(newFunctionType,
|
3113
|
-
|
3114
|
-
|
3115
|
-
: 0 /* ParameterCategory.Simple */,
|
3116
|
-
name: `__p${newFunctionType.details.parameters.length}`,
|
3117
|
-
isNameSynthesized: true,
|
3118
|
-
type: unpackedType.type,
|
3119
|
-
hasDeclaredType: true,
|
3120
|
-
});
|
3159
|
+
types_1.FunctionType.addParameter(newFunctionType, types_1.FunctionParam.create(unpackedType.isUnbounded || (0, types_1.isVariadicTypeVar)(unpackedType.type)
|
3160
|
+
? 1 /* ParameterCategory.ArgsList */
|
3161
|
+
: 0 /* ParameterCategory.Simple */, unpackedType.type, types_1.FunctionParamFlags.NameSynthesized | types_1.FunctionParamFlags.TypeDeclared, `__p${newFunctionType.shared.parameters.length}`));
|
3121
3162
|
if (unpackedType.isUnbounded) {
|
3122
3163
|
sawUnboundedEntry = true;
|
3123
3164
|
}
|
@@ -3130,7 +3171,7 @@ class TypeVarTransformer {
|
|
3130
3171
|
}
|
3131
3172
|
}
|
3132
3173
|
else {
|
3133
|
-
const param = { ...functionType.
|
3174
|
+
const param = { ...functionType.shared.parameters[index] };
|
3134
3175
|
if ((0, types_1.isKeywordOnlySeparator)(param)) {
|
3135
3176
|
insertKeywordOnlySeparator = false;
|
3136
3177
|
}
|
@@ -3144,15 +3185,15 @@ class TypeVarTransformer {
|
|
3144
3185
|
insertKeywordOnlySeparator = false;
|
3145
3186
|
}
|
3146
3187
|
param.type = paramType;
|
3147
|
-
if (param.name &&
|
3148
|
-
param.name = `__p${newFunctionType.
|
3188
|
+
if (param.name && types_1.FunctionParam.isNameSynthesized(param)) {
|
3189
|
+
param.name = `__p${newFunctionType.shared.parameters.length}`;
|
3149
3190
|
}
|
3150
3191
|
if (param.category !== 0 /* ParameterCategory.Simple */ || param.name || !swallowPositionOnlySeparator) {
|
3151
3192
|
types_1.FunctionType.addParameter(newFunctionType, param);
|
3152
3193
|
}
|
3153
3194
|
}
|
3154
3195
|
});
|
3155
|
-
newFunctionType.
|
3196
|
+
newFunctionType.shared.declaredReturnType = specializedParameters.returnType;
|
3156
3197
|
return newFunctionType;
|
3157
3198
|
});
|
3158
3199
|
}
|
@@ -3181,16 +3222,16 @@ class TypeVarDefaultValidator extends TypeVarTransformer {
|
|
3181
3222
|
this._invalidTypeVars = _invalidTypeVars;
|
3182
3223
|
}
|
3183
3224
|
transformTypeVar(typeVar) {
|
3184
|
-
const replacementType = this._liveTypeParams.find((param) => param.
|
3225
|
+
const replacementType = this._liveTypeParams.find((param) => param.shared.name === typeVar.shared.name);
|
3185
3226
|
if (!replacementType || (0, types_1.isParamSpec)(replacementType)) {
|
3186
|
-
this._invalidTypeVars.add(typeVar.
|
3227
|
+
this._invalidTypeVars.add(typeVar.shared.name);
|
3187
3228
|
}
|
3188
3229
|
return types_1.UnknownType.create();
|
3189
3230
|
}
|
3190
3231
|
transformParamSpec(paramSpec) {
|
3191
|
-
const replacementType = this._liveTypeParams.find((param) => param.
|
3232
|
+
const replacementType = this._liveTypeParams.find((param) => param.shared.name === paramSpec.shared.name);
|
3192
3233
|
if (!replacementType || !(0, types_1.isParamSpec)(replacementType)) {
|
3193
|
-
this._invalidTypeVars.add(paramSpec.
|
3234
|
+
this._invalidTypeVars.add(paramSpec.shared.name);
|
3194
3235
|
}
|
3195
3236
|
return undefined;
|
3196
3237
|
}
|
@@ -3210,11 +3251,8 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
|
3210
3251
|
return classType;
|
3211
3252
|
}
|
3212
3253
|
transformTypeVarsInFunctionType(sourceType, recursionCount) {
|
3213
|
-
if (sourceType.trackedSignatures) {
|
3214
|
-
this._signatureTracker.addTrackedSignatures(sourceType.trackedSignatures);
|
3215
|
-
}
|
3216
3254
|
// If this function is not generic, there's no need to check for uniqueness.
|
3217
|
-
if (sourceType.
|
3255
|
+
if (sourceType.shared.typeParameters.length === 0) {
|
3218
3256
|
return super.transformTypeVarsInFunctionType(sourceType, recursionCount);
|
3219
3257
|
}
|
3220
3258
|
let updatedSourceType = sourceType;
|
@@ -3228,10 +3266,10 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
|
3228
3266
|
const typeVarContext = new typeVarContext_1.TypeVarContext(getTypeVarScopeIds(sourceType));
|
3229
3267
|
// Create new type variables with the same scope but with
|
3230
3268
|
// different (unique) names.
|
3231
|
-
sourceType.
|
3232
|
-
if (typeParam.scopeType === 1 /* TypeVarScopeType.Function */) {
|
3233
|
-
let replacement = types_1.TypeVarType.cloneForNewName(typeParam, `${typeParam.
|
3234
|
-
if (replacement.
|
3269
|
+
sourceType.shared.typeParameters.forEach((typeParam) => {
|
3270
|
+
if (typeParam.priv.scopeType === 1 /* TypeVarScopeType.Function */) {
|
3271
|
+
let replacement = types_1.TypeVarType.cloneForNewName(typeParam, `${typeParam.shared.name}(${offsetIndex})`);
|
3272
|
+
if (replacement.shared.isParamSpec) {
|
3235
3273
|
replacement = convertTypeToParamSpecValue(replacement);
|
3236
3274
|
}
|
3237
3275
|
typeVarContext.setTypeVarType(typeParam, replacement);
|
@@ -3245,6 +3283,58 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
|
3245
3283
|
return updatedSourceType;
|
3246
3284
|
}
|
3247
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
|
+
}
|
3248
3338
|
// Specializes a (potentially generic) type by substituting
|
3249
3339
|
// type variables from a type var map.
|
3250
3340
|
class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
@@ -3259,7 +3349,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3259
3349
|
const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
|
3260
3350
|
// If the type variable is unrelated to the scopes we're solving,
|
3261
3351
|
// don't transform that type variable.
|
3262
|
-
if (typeVar.scopeId && this._typeVarContext.hasSolveForScope(typeVar.scopeId)) {
|
3352
|
+
if (typeVar.priv.scopeId && this._typeVarContext.hasSolveForScope(typeVar.priv.scopeId)) {
|
3263
3353
|
let replacement = signatureContext.getTypeVarType(typeVar, !!this._options.useNarrowBoundOnly);
|
3264
3354
|
// If there was no narrow bound but there is a wide bound that
|
3265
3355
|
// contains literals or a TypeVar, we'll use the wide bound even if
|
@@ -3293,22 +3383,26 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3293
3383
|
if ((0, types_1.isClassInstance)(subtype)) {
|
3294
3384
|
// If the includeSubclasses wasn't set, force it to be set by
|
3295
3385
|
// converting to/from an instantiable.
|
3296
|
-
if (!subtype.includeSubclasses) {
|
3386
|
+
if (!subtype.priv.includeSubclasses) {
|
3297
3387
|
subtype = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneAsInstantiable(subtype));
|
3298
3388
|
}
|
3299
|
-
if (
|
3300
|
-
|
3301
|
-
|
3302
|
-
|
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
|
+
}
|
3303
3395
|
}
|
3304
3396
|
}
|
3305
3397
|
return subtype;
|
3306
3398
|
});
|
3307
3399
|
}
|
3308
|
-
if ((0, types_1.isTypeVar)(replacement) && typeVar.isVariadicUnpacked && replacement.
|
3309
|
-
return types_1.TypeVarType.cloneForUnpacked(replacement, typeVar.isVariadicInUnion);
|
3400
|
+
if ((0, types_1.isTypeVar)(replacement) && typeVar.priv.isVariadicUnpacked && replacement.shared.isVariadic) {
|
3401
|
+
return types_1.TypeVarType.cloneForUnpacked(replacement, typeVar.priv.isVariadicInUnion);
|
3310
3402
|
}
|
3311
|
-
if (!(0, types_1.isTypeVar)(replacement) ||
|
3403
|
+
if (!(0, types_1.isTypeVar)(replacement) ||
|
3404
|
+
!replacement.priv.isInScopePlaceholder ||
|
3405
|
+
!this._options.unknownIfNotFound) {
|
3312
3406
|
return replacement;
|
3313
3407
|
}
|
3314
3408
|
}
|
@@ -3323,27 +3417,27 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3323
3417
|
useDefaultOrUnknown = true;
|
3324
3418
|
}
|
3325
3419
|
}
|
3326
|
-
else if (this._options.applyInScopePlaceholders && typeVar.isInScopePlaceholder) {
|
3420
|
+
else if (this._options.applyInScopePlaceholders && typeVar.priv.isInScopePlaceholder) {
|
3327
3421
|
useDefaultOrUnknown = true;
|
3328
3422
|
}
|
3329
3423
|
if (useDefaultOrUnknown) {
|
3330
3424
|
// Use the default value if there is one.
|
3331
|
-
if (typeVar.
|
3332
|
-
return this._solveDefaultType(typeVar
|
3425
|
+
if (typeVar.shared.isDefaultExplicit && !this._options.useUnknownOverDefault) {
|
3426
|
+
return this._solveDefaultType(typeVar, recursionCount);
|
3333
3427
|
}
|
3334
3428
|
return getUnknownTypeForTypeVar(typeVar, this._options.tupleClassType);
|
3335
3429
|
}
|
3336
3430
|
}
|
3337
3431
|
// If we're solving a default type, handle type variables with no scope ID.
|
3338
|
-
if (this._isSolvingDefaultType && !typeVar.scopeId) {
|
3432
|
+
if (this._isSolvingDefaultType && !typeVar.priv.scopeId) {
|
3339
3433
|
const replacementEntry = signatureContext
|
3340
3434
|
.getTypeVars()
|
3341
|
-
.find((entry) => entry.typeVar.
|
3435
|
+
.find((entry) => entry.typeVar.shared.name === typeVar.shared.name);
|
3342
3436
|
if (replacementEntry) {
|
3343
3437
|
return signatureContext.getTypeVarType(replacementEntry.typeVar);
|
3344
3438
|
}
|
3345
|
-
if (typeVar.
|
3346
|
-
return this.apply(typeVar.
|
3439
|
+
if (typeVar.shared.isDefaultExplicit) {
|
3440
|
+
return this.apply(typeVar.shared.defaultType, recursionCount);
|
3347
3441
|
}
|
3348
3442
|
return types_1.UnknownType.create();
|
3349
3443
|
}
|
@@ -3358,12 +3452,12 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3358
3452
|
// def test(x: Union[str, T]) -> Union[str, T]
|
3359
3453
|
if (this._options.eliminateUnsolvedInUnions) {
|
3360
3454
|
if ((0, types_1.isTypeVar)(preTransform) &&
|
3361
|
-
preTransform.scopeId !== undefined &&
|
3362
|
-
this._typeVarContext.hasSolveForScope(preTransform.scopeId)) {
|
3455
|
+
preTransform.priv.scopeId !== undefined &&
|
3456
|
+
this._typeVarContext.hasSolveForScope(preTransform.priv.scopeId)) {
|
3363
3457
|
const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
|
3364
3458
|
const typeVarType = signatureContext.getTypeVarType(preTransform);
|
3365
3459
|
// Did the TypeVar remain unsolved?
|
3366
|
-
if (!typeVarType || ((0, types_1.isTypeVar)(typeVarType) && typeVarType.isInScopePlaceholder)) {
|
3460
|
+
if (!typeVarType || ((0, types_1.isTypeVar)(typeVarType) && typeVarType.priv.isInScopePlaceholder)) {
|
3367
3461
|
// If the TypeVar was not transformed, then it was unsolved,
|
3368
3462
|
// and we'll eliminate it.
|
3369
3463
|
if (preTransform === postTransform) {
|
@@ -3381,10 +3475,12 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3381
3475
|
}
|
3382
3476
|
transformTupleTypeVar(typeVar) {
|
3383
3477
|
var _a;
|
3384
|
-
if (!typeVar.scopeId || !this._typeVarContext.hasSolveForScope(typeVar.scopeId)) {
|
3385
|
-
const defaultType = typeVar.
|
3386
|
-
if (typeVar.
|
3387
|
-
|
3478
|
+
if (!typeVar.priv.scopeId || !this._typeVarContext.hasSolveForScope(typeVar.priv.scopeId)) {
|
3479
|
+
const defaultType = typeVar.shared.defaultType;
|
3480
|
+
if (typeVar.shared.isDefaultExplicit &&
|
3481
|
+
(0, types_1.isClassInstance)(defaultType) &&
|
3482
|
+
defaultType.priv.tupleTypeArguments) {
|
3483
|
+
return defaultType.priv.tupleTypeArguments;
|
3388
3484
|
}
|
3389
3485
|
return undefined;
|
3390
3486
|
}
|
@@ -3395,19 +3491,19 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3395
3491
|
var _a, _b;
|
3396
3492
|
const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
|
3397
3493
|
// If we're solving a default type, handle param specs with no scope ID.
|
3398
|
-
if (this._isSolvingDefaultType && !paramSpec.scopeId) {
|
3494
|
+
if (this._isSolvingDefaultType && !paramSpec.priv.scopeId) {
|
3399
3495
|
const replacementEntry = signatureContext
|
3400
3496
|
.getTypeVars()
|
3401
|
-
.find((entry) => entry.typeVar.
|
3497
|
+
.find((entry) => entry.typeVar.shared.name === paramSpec.shared.name);
|
3402
3498
|
if (replacementEntry) {
|
3403
3499
|
return signatureContext.getParamSpecType(replacementEntry.typeVar);
|
3404
3500
|
}
|
3405
|
-
if (paramSpec.
|
3406
|
-
return convertTypeToParamSpecValue(this.apply(paramSpec.
|
3501
|
+
if (paramSpec.shared.isDefaultExplicit) {
|
3502
|
+
return convertTypeToParamSpecValue(this.apply(paramSpec.shared.defaultType, recursionCount));
|
3407
3503
|
}
|
3408
3504
|
return getUnknownTypeForParamSpec();
|
3409
3505
|
}
|
3410
|
-
if (!paramSpec.scopeId || !this._typeVarContext.hasSolveForScope(paramSpec.scopeId)) {
|
3506
|
+
if (!paramSpec.priv.scopeId || !this._typeVarContext.hasSolveForScope(paramSpec.priv.scopeId)) {
|
3411
3507
|
return undefined;
|
3412
3508
|
}
|
3413
3509
|
const transformedParamSpec = signatureContext.getParamSpecType(paramSpec);
|
@@ -3421,13 +3517,13 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3421
3517
|
useDefaultOrUnknown = true;
|
3422
3518
|
}
|
3423
3519
|
}
|
3424
|
-
else if (this._options.applyInScopePlaceholders && paramSpec.isInScopePlaceholder) {
|
3520
|
+
else if (this._options.applyInScopePlaceholders && paramSpec.priv.isInScopePlaceholder) {
|
3425
3521
|
useDefaultOrUnknown = true;
|
3426
3522
|
}
|
3427
3523
|
if (useDefaultOrUnknown) {
|
3428
3524
|
// Use the default value if there is one.
|
3429
|
-
if (paramSpec.
|
3430
|
-
return convertTypeToParamSpecValue(this._solveDefaultType(paramSpec
|
3525
|
+
if (paramSpec.shared.isDefaultExplicit && !this._options.useUnknownOverDefault) {
|
3526
|
+
return convertTypeToParamSpecValue(this._solveDefaultType(paramSpec, recursionCount));
|
3431
3527
|
}
|
3432
3528
|
// Convert to the ParamSpec equivalent of "Unknown".
|
3433
3529
|
return getUnknownTypeForParamSpec();
|
@@ -3435,25 +3531,26 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3435
3531
|
return undefined;
|
3436
3532
|
}
|
3437
3533
|
transformConditionalType(type, recursionCount) {
|
3438
|
-
var _a;
|
3439
|
-
if (!type.condition) {
|
3534
|
+
var _a, _b, _c, _d;
|
3535
|
+
if (!((_a = type.props) === null || _a === void 0 ? void 0 : _a.condition)) {
|
3440
3536
|
return type;
|
3441
3537
|
}
|
3442
|
-
const signatureContext = this._typeVarContext.getSignatureContext((
|
3443
|
-
for (const condition of type.condition) {
|
3538
|
+
const signatureContext = this._typeVarContext.getSignatureContext((_b = this._activeTypeVarSignatureContextIndex) !== null && _b !== void 0 ? _b : 0);
|
3539
|
+
for (const condition of type.props.condition) {
|
3444
3540
|
// This doesn't apply to bound type variables.
|
3445
|
-
if (condition.typeVar.
|
3541
|
+
if (condition.typeVar.shared.constraints.length === 0) {
|
3446
3542
|
continue;
|
3447
3543
|
}
|
3448
|
-
const
|
3449
|
-
|
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);
|
3546
|
+
if (!typeVarEntry || condition.constraintIndex >= typeVarEntry.typeVar.shared.constraints.length) {
|
3450
3547
|
continue;
|
3451
3548
|
}
|
3452
3549
|
const value = signatureContext.getTypeVarType(typeVarEntry.typeVar);
|
3453
3550
|
if (!value) {
|
3454
3551
|
continue;
|
3455
3552
|
}
|
3456
|
-
const constraintType = typeVarEntry.typeVar.
|
3553
|
+
const constraintType = typeVarEntry.typeVar.shared.constraints[condition.constraintIndex];
|
3457
3554
|
// If this violates the constraint, substitute a Never type.
|
3458
3555
|
if (!(0, types_1.isTypeSame)(constraintType, value)) {
|
3459
3556
|
return types_1.NeverType.createNever();
|
@@ -3477,7 +3574,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3477
3574
|
const filteredOverloads = [];
|
3478
3575
|
doForEachSubtype((0, types_1.combineTypes)(overloadTypes), (subtype) => {
|
3479
3576
|
(0, debug_1.assert)((0, types_1.isFunction)(subtype));
|
3480
|
-
subtype = types_1.FunctionType.cloneWithNewFlags(subtype, subtype.
|
3577
|
+
subtype = types_1.FunctionType.cloneWithNewFlags(subtype, subtype.shared.flags | 256 /* FunctionTypeFlags.Overloaded */);
|
3481
3578
|
filteredOverloads.push(subtype);
|
3482
3579
|
});
|
3483
3580
|
if (filteredOverloads.length === 1) {
|
@@ -3485,7 +3582,8 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3485
3582
|
}
|
3486
3583
|
return types_1.OverloadedFunctionType.create(filteredOverloads);
|
3487
3584
|
}
|
3488
|
-
_solveDefaultType(
|
3585
|
+
_solveDefaultType(typeVar, recursionCount) {
|
3586
|
+
const defaultType = typeVar.shared.defaultType;
|
3489
3587
|
const wasSolvingDefaultType = this._isSolvingDefaultType;
|
3490
3588
|
this._isSolvingDefaultType = true;
|
3491
3589
|
const result = this.apply(defaultType, recursionCount);
|
@@ -3503,7 +3601,7 @@ class ExpectedTypeTransformer extends TypeVarTransformer {
|
|
3503
3601
|
if (!this._isTypeVarLive(typeVar)) {
|
3504
3602
|
return types_1.TypeVarType.cloneAsInScopePlaceholder(typeVar, this._usageOffset);
|
3505
3603
|
}
|
3506
|
-
return
|
3604
|
+
return undefined;
|
3507
3605
|
}
|
3508
3606
|
transformParamSpec(paramSpec) {
|
3509
3607
|
if (!this._isTypeVarLive(paramSpec)) {
|
@@ -3512,7 +3610,7 @@ class ExpectedTypeTransformer extends TypeVarTransformer {
|
|
3512
3610
|
return undefined;
|
3513
3611
|
}
|
3514
3612
|
_isTypeVarLive(typeVar) {
|
3515
|
-
return this._liveTypeVarScopes.some((scopeId) => typeVar.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; });
|
3516
3614
|
}
|
3517
3615
|
}
|
3518
3616
|
class InScopePlaceholderTransformer extends TypeVarTransformer {
|
@@ -3522,13 +3620,13 @@ class InScopePlaceholderTransformer extends TypeVarTransformer {
|
|
3522
3620
|
}
|
3523
3621
|
transformTypeVar(typeVar) {
|
3524
3622
|
var _a;
|
3525
|
-
if (typeVar.isInScopePlaceholder) {
|
3623
|
+
if (typeVar.priv.isInScopePlaceholder) {
|
3526
3624
|
return (_a = this._signatureContext.getTypeVarType(typeVar)) !== null && _a !== void 0 ? _a : typeVar;
|
3527
3625
|
}
|
3528
|
-
return
|
3626
|
+
return undefined;
|
3529
3627
|
}
|
3530
3628
|
transformParamSpec(paramSpec) {
|
3531
|
-
if (paramSpec.isInScopePlaceholder) {
|
3629
|
+
if (paramSpec.priv.isInScopePlaceholder) {
|
3532
3630
|
return this._signatureContext.getParamSpecType(paramSpec);
|
3533
3631
|
}
|
3534
3632
|
return undefined;
|
@@ -3537,7 +3635,7 @@ class InScopePlaceholderTransformer extends TypeVarTransformer {
|
|
3537
3635
|
function applyInScopePlaceholdersToType(type, signatureContext) {
|
3538
3636
|
// Handle the common case where there are no in-scope placeholders.
|
3539
3637
|
// No more work is required in this case.
|
3540
|
-
if (!signatureContext.getTypeVars().some((entry) => entry.typeVar.isInScopePlaceholder)) {
|
3638
|
+
if (!signatureContext.getTypeVars().some((entry) => entry.typeVar.priv.isInScopePlaceholder)) {
|
3541
3639
|
return type;
|
3542
3640
|
}
|
3543
3641
|
const transformer = new InScopePlaceholderTransformer(signatureContext);
|