@zzzen/pyright-internal 1.2.0-dev.20240707 → 1.2.0-dev.20240714
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 +649 -634
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +5 -3
- package/dist/analyzer/codeFlowEngine.js +87 -101
- 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 +68 -64
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +22 -22
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +51 -48
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +109 -175
- 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 +77 -77
- 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 +66 -66
- 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 +28 -46
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +268 -269
- 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 +176 -143
- 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 +78 -147
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +21 -21
- 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 +2 -2
- 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 +1884 -1937
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +6 -5
- package/dist/analyzer/typeEvaluatorTypes.js +4 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +211 -211
- 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 +14 -3
- package/dist/analyzer/typeUtils.js +432 -402
- 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 +96 -198
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +144 -102
- package/dist/analyzer/types.js +662 -494
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +33 -33
- 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 +25 -24
- 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.js +8 -8
- package/dist/languageService/referencesProvider.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/parser/parseNodes.d.ts +468 -401
- package/dist/parser/parseNodes.js +626 -355
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +1 -0
- package/dist/parser/parser.js +316 -294
- 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/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/typeEvaluator3.test.js +8 -3
- package/dist/tests/typeEvaluator3.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.combineVariances = exports.requiresSpecialization = 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.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 = 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");
|
@@ -164,8 +164,8 @@ class UniqueSignatureTracker {
|
|
164
164
|
findSignature(signature) {
|
165
165
|
// Use the associated overload type if this is a function associated with an overload.
|
166
166
|
let effectiveSignature = signature;
|
167
|
-
if ((0, types_1.isFunction)(signature) && signature.overloaded) {
|
168
|
-
effectiveSignature = signature.overloaded;
|
167
|
+
if ((0, types_1.isFunction)(signature) && signature.priv.overloaded) {
|
168
|
+
effectiveSignature = signature.priv.overloaded;
|
169
169
|
}
|
170
170
|
return this._trackedSignatures.find((s) => {
|
171
171
|
return (0, types_1.isTypeSame)(effectiveSignature, s.type);
|
@@ -174,7 +174,7 @@ class UniqueSignatureTracker {
|
|
174
174
|
addSignature(signature, offset) {
|
175
175
|
var _a;
|
176
176
|
// 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;
|
177
|
+
const effectiveSignature = (0, types_1.isFunction)(signature) ? (_a = signature.priv.overloaded) !== null && _a !== void 0 ? _a : signature : signature;
|
178
178
|
const existingSignature = this.findSignature(effectiveSignature);
|
179
179
|
if (existingSignature) {
|
180
180
|
if (!existingSignature.expressionOffsets.some((o) => o === offset)) {
|
@@ -209,7 +209,7 @@ function removeNoneFromUnion(type) {
|
|
209
209
|
}
|
210
210
|
exports.removeNoneFromUnion = removeNoneFromUnion;
|
211
211
|
function isIncompleteUnknown(type) {
|
212
|
-
return (0, types_1.isUnknown)(type) && type.isIncomplete;
|
212
|
+
return (0, types_1.isUnknown)(type) && type.priv.isIncomplete;
|
213
213
|
}
|
214
214
|
exports.isIncompleteUnknown = isIncompleteUnknown;
|
215
215
|
// Similar to isTypeSame except that type1 is a TypeVar and type2
|
@@ -220,7 +220,7 @@ function isTypeVarSame(type1, type2) {
|
|
220
220
|
return true;
|
221
221
|
}
|
222
222
|
// If this isn't a bound TypeVar, return false.
|
223
|
-
if (type1.
|
223
|
+
if (type1.shared.isParamSpec || type1.shared.isVariadic || !type1.shared.boundType) {
|
224
224
|
return false;
|
225
225
|
}
|
226
226
|
// If the second type isn't a union, return false.
|
@@ -235,7 +235,7 @@ function isTypeVarSame(type1, type2) {
|
|
235
235
|
if (!(0, types_1.isTypeSame)(type1, subtype)) {
|
236
236
|
const conditions = getTypeCondition(subtype);
|
237
237
|
if (!conditions ||
|
238
|
-
!conditions.some((condition) => condition.typeVar.nameWithScope === type1.nameWithScope)) {
|
238
|
+
!conditions.some((condition) => condition.typeVar.priv.nameWithScope === type1.priv.nameWithScope)) {
|
239
239
|
isCompatible = false;
|
240
240
|
}
|
241
241
|
}
|
@@ -253,9 +253,9 @@ exports.makeInferenceContext = makeInferenceContext;
|
|
253
253
|
// Calls a callback for each subtype and combines the results
|
254
254
|
// into a final type. It performs no memory allocations if the
|
255
255
|
// transformed type is the same as the original.
|
256
|
-
function mapSubtypes(type, callback,
|
256
|
+
function mapSubtypes(type, callback, options) {
|
257
257
|
if ((0, types_1.isUnion)(type)) {
|
258
|
-
const subtypes = sortSubtypes ? sortTypes(type.subtypes) : type.subtypes;
|
258
|
+
const subtypes = (options === null || options === void 0 ? void 0 : options.sortSubtypes) ? sortTypes(type.priv.subtypes) : type.priv.subtypes;
|
259
259
|
for (let i = 0; i < subtypes.length; i++) {
|
260
260
|
const subtype = subtypes[i];
|
261
261
|
const transformedType = callback(subtype);
|
@@ -272,7 +272,9 @@ function mapSubtypes(type, callback, sortSubtypes = false) {
|
|
272
272
|
for (i++; i < subtypes.length; i++) {
|
273
273
|
accumulateSubtype(callback(subtypes[i]));
|
274
274
|
}
|
275
|
-
const newType = (0, types_1.combineTypes)(typesToCombine
|
275
|
+
const newType = (0, types_1.combineTypes)(typesToCombine, {
|
276
|
+
skipElideRedundantLiterals: options === null || options === void 0 ? void 0 : options.skipElideRedundantLiterals,
|
277
|
+
});
|
276
278
|
// Do our best to retain type aliases.
|
277
279
|
if (newType.category === 8 /* TypeCategory.Union */) {
|
278
280
|
types_1.UnionType.addTypeAliasSource(newType, type);
|
@@ -293,12 +295,12 @@ exports.mapSubtypes = mapSubtypes;
|
|
293
295
|
// caller to replace one or more signatures with new ones.
|
294
296
|
function mapSignatures(type, callback) {
|
295
297
|
if ((0, types_1.isFunction)(type)) {
|
296
|
-
return callback(type
|
298
|
+
return callback(type);
|
297
299
|
}
|
298
300
|
const newSignatures = [];
|
299
301
|
let changeMade = false;
|
300
302
|
types_1.OverloadedFunctionType.getOverloads(type).forEach((overload, index) => {
|
301
|
-
const newOverload = callback(overload
|
303
|
+
const newOverload = callback(overload);
|
302
304
|
if (newOverload !== overload) {
|
303
305
|
changeMade = true;
|
304
306
|
}
|
@@ -312,7 +314,11 @@ function mapSignatures(type, callback) {
|
|
312
314
|
// Add the unmodified implementation if it's present.
|
313
315
|
const implementation = types_1.OverloadedFunctionType.getImplementation(type);
|
314
316
|
if (implementation) {
|
315
|
-
|
317
|
+
const newImplementation = callback(implementation);
|
318
|
+
if (newImplementation) {
|
319
|
+
changeMade = true;
|
320
|
+
newSignatures.push(newImplementation);
|
321
|
+
}
|
316
322
|
}
|
317
323
|
if (!changeMade) {
|
318
324
|
return type;
|
@@ -336,13 +342,13 @@ function cleanIncompleteUnknown(type, recursionCount = 0) {
|
|
336
342
|
recursionCount++;
|
337
343
|
const result = mapSubtypes(type, (subtype) => {
|
338
344
|
// If it's an incomplete unknown, eliminate it.
|
339
|
-
if ((0, types_1.isUnknown)(subtype) && subtype.isIncomplete) {
|
345
|
+
if ((0, types_1.isUnknown)(subtype) && subtype.priv.isIncomplete) {
|
340
346
|
return undefined;
|
341
347
|
}
|
342
|
-
if ((0, types_1.isClass)(subtype) && subtype.typeArguments) {
|
348
|
+
if ((0, types_1.isClass)(subtype) && subtype.priv.typeArguments) {
|
343
349
|
let typeChanged = false;
|
344
|
-
if (subtype.tupleTypeArguments) {
|
345
|
-
const updatedTupleTypeArgs = subtype.tupleTypeArguments.map((tupleTypeArg) => {
|
350
|
+
if (subtype.priv.tupleTypeArguments) {
|
351
|
+
const updatedTupleTypeArgs = subtype.priv.tupleTypeArguments.map((tupleTypeArg) => {
|
346
352
|
const newTypeArg = cleanIncompleteUnknown(tupleTypeArg.type, recursionCount);
|
347
353
|
if (newTypeArg !== tupleTypeArg.type) {
|
348
354
|
typeChanged = true;
|
@@ -354,11 +360,11 @@ function cleanIncompleteUnknown(type, recursionCount = 0) {
|
|
354
360
|
};
|
355
361
|
});
|
356
362
|
if (typeChanged) {
|
357
|
-
return specializeTupleClass(subtype, updatedTupleTypeArgs, !!subtype.isTypeArgumentExplicit, !!subtype.isUnpacked);
|
363
|
+
return specializeTupleClass(subtype, updatedTupleTypeArgs, !!subtype.priv.isTypeArgumentExplicit, !!subtype.priv.isUnpacked);
|
358
364
|
}
|
359
365
|
}
|
360
366
|
else {
|
361
|
-
const updatedTypeArgs = subtype.typeArguments.map((typeArg) => {
|
367
|
+
const updatedTypeArgs = subtype.priv.typeArguments.map((typeArg) => {
|
362
368
|
const newTypeArg = cleanIncompleteUnknown(typeArg, recursionCount);
|
363
369
|
if (newTypeArg !== typeArg) {
|
364
370
|
typeChanged = true;
|
@@ -366,7 +372,7 @@ function cleanIncompleteUnknown(type, recursionCount = 0) {
|
|
366
372
|
return newTypeArg;
|
367
373
|
});
|
368
374
|
if (typeChanged) {
|
369
|
-
return types_1.ClassType.cloneForSpecialization(subtype, updatedTypeArgs, !!subtype.isTypeArgumentExplicit);
|
375
|
+
return types_1.ClassType.cloneForSpecialization(subtype, updatedTypeArgs, !!subtype.priv.isTypeArgumentExplicit);
|
370
376
|
}
|
371
377
|
}
|
372
378
|
}
|
@@ -403,14 +409,14 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
403
409
|
}
|
404
410
|
case 4 /* TypeCategory.Function */: {
|
405
411
|
const bFunc = b;
|
406
|
-
const aParamCount = a.
|
407
|
-
const bParamCount = bFunc.
|
412
|
+
const aParamCount = a.shared.parameters.length;
|
413
|
+
const bParamCount = bFunc.shared.parameters.length;
|
408
414
|
if (aParamCount !== bParamCount) {
|
409
415
|
return bParamCount - aParamCount;
|
410
416
|
}
|
411
417
|
for (let i = 0; i < aParamCount; i++) {
|
412
|
-
const aParam = a.
|
413
|
-
const bParam = bFunc.
|
418
|
+
const aParam = a.shared.parameters[i];
|
419
|
+
const bParam = bFunc.shared.parameters[i];
|
414
420
|
if (aParam.category !== bParam.category) {
|
415
421
|
return bParam.category - aParam.category;
|
416
422
|
}
|
@@ -423,8 +429,8 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
423
429
|
if (returnTypeComparison !== 0) {
|
424
430
|
return returnTypeComparison;
|
425
431
|
}
|
426
|
-
const aName = a.
|
427
|
-
const bName = bFunc.
|
432
|
+
const aName = a.shared.name;
|
433
|
+
const bName = bFunc.shared.name;
|
428
434
|
if (aName < bName) {
|
429
435
|
return -1;
|
430
436
|
}
|
@@ -435,13 +441,13 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
435
441
|
}
|
436
442
|
case 5 /* TypeCategory.OverloadedFunction */: {
|
437
443
|
const bOver = b;
|
438
|
-
const aOverloadCount = a.overloads.length;
|
439
|
-
const bOverloadCount = bOver.overloads.length;
|
444
|
+
const aOverloadCount = a.priv.overloads.length;
|
445
|
+
const bOverloadCount = bOver.priv.overloads.length;
|
440
446
|
if (aOverloadCount !== bOverloadCount) {
|
441
447
|
return bOverloadCount - aOverloadCount;
|
442
448
|
}
|
443
449
|
for (let i = 0; i < aOverloadCount; i++) {
|
444
|
-
const typeComparison = compareTypes(a.overloads[i], bOver.overloads[i]);
|
450
|
+
const typeComparison = compareTypes(a.priv.overloads[i], bOver.priv.overloads[i]);
|
445
451
|
if (typeComparison !== 0) {
|
446
452
|
return typeComparison;
|
447
453
|
}
|
@@ -474,17 +480,17 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
474
480
|
return -1;
|
475
481
|
}
|
476
482
|
// Sort non-generics before generics.
|
477
|
-
if (a.
|
478
|
-
if (bClass.
|
483
|
+
if (a.shared.typeParameters.length > 0 || isTupleClass(a)) {
|
484
|
+
if (bClass.shared.typeParameters.length === 0) {
|
479
485
|
return 1;
|
480
486
|
}
|
481
487
|
}
|
482
|
-
else if (bClass.
|
488
|
+
else if (bClass.shared.typeParameters.length > 0 || isTupleClass(bClass)) {
|
483
489
|
return -1;
|
484
490
|
}
|
485
491
|
// Sort by class name.
|
486
|
-
const aName = a.
|
487
|
-
const bName = b.
|
492
|
+
const aName = a.shared.name;
|
493
|
+
const bName = b.shared.name;
|
488
494
|
if (aName < bName) {
|
489
495
|
return -1;
|
490
496
|
}
|
@@ -492,8 +498,8 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
492
498
|
return 1;
|
493
499
|
}
|
494
500
|
// Sort by type argument count.
|
495
|
-
const aTypeArgCount = a.typeArguments ? a.typeArguments.length : 0;
|
496
|
-
const bTypeArgCount = bClass.typeArguments ? bClass.typeArguments.length : 0;
|
501
|
+
const aTypeArgCount = a.priv.typeArguments ? a.priv.typeArguments.length : 0;
|
502
|
+
const bTypeArgCount = bClass.priv.typeArguments ? bClass.priv.typeArguments.length : 0;
|
497
503
|
if (aTypeArgCount < bTypeArgCount) {
|
498
504
|
return -1;
|
499
505
|
}
|
@@ -502,7 +508,7 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
502
508
|
}
|
503
509
|
// Sort by type argument.
|
504
510
|
for (let i = 0; i < aTypeArgCount; i++) {
|
505
|
-
const typeComparison = compareTypes(a.typeArguments[i], bClass.typeArguments[i], recursionCount);
|
511
|
+
const typeComparison = compareTypes(a.priv.typeArguments[i], bClass.priv.typeArguments[i], recursionCount);
|
506
512
|
if (typeComparison !== 0) {
|
507
513
|
return typeComparison;
|
508
514
|
}
|
@@ -510,13 +516,13 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
510
516
|
return 0;
|
511
517
|
}
|
512
518
|
case 7 /* TypeCategory.Module */: {
|
513
|
-
const aName = a.moduleName;
|
514
|
-
const bName = b.moduleName;
|
519
|
+
const aName = a.priv.moduleName;
|
520
|
+
const bName = b.priv.moduleName;
|
515
521
|
return aName < bName ? -1 : aName === bName ? 0 : 1;
|
516
522
|
}
|
517
523
|
case 9 /* TypeCategory.TypeVar */: {
|
518
|
-
const aName = a.
|
519
|
-
const bName = b.
|
524
|
+
const aName = a.shared.name;
|
525
|
+
const bName = b.shared.name;
|
520
526
|
return aName < bName ? -1 : aName === bName ? 0 : 1;
|
521
527
|
}
|
522
528
|
}
|
@@ -524,7 +530,7 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
524
530
|
}
|
525
531
|
function doForEachSubtype(type, callback, sortSubtypes = false) {
|
526
532
|
if ((0, types_1.isUnion)(type)) {
|
527
|
-
const subtypes = sortSubtypes ? sortTypes(type.subtypes) : type.subtypes;
|
533
|
+
const subtypes = sortSubtypes ? sortTypes(type.priv.subtypes) : type.priv.subtypes;
|
528
534
|
subtypes.forEach((subtype, index) => {
|
529
535
|
callback(subtype, index, subtypes);
|
530
536
|
});
|
@@ -536,7 +542,7 @@ function doForEachSubtype(type, callback, sortSubtypes = false) {
|
|
536
542
|
exports.doForEachSubtype = doForEachSubtype;
|
537
543
|
function someSubtypes(type, callback) {
|
538
544
|
if ((0, types_1.isUnion)(type)) {
|
539
|
-
return type.subtypes.some((subtype) => {
|
545
|
+
return type.priv.subtypes.some((subtype) => {
|
540
546
|
return callback(subtype);
|
541
547
|
});
|
542
548
|
}
|
@@ -547,7 +553,7 @@ function someSubtypes(type, callback) {
|
|
547
553
|
exports.someSubtypes = someSubtypes;
|
548
554
|
function allSubtypes(type, callback) {
|
549
555
|
if ((0, types_1.isUnion)(type)) {
|
550
|
-
return type.subtypes.every((subtype) => {
|
556
|
+
return type.priv.subtypes.every((subtype) => {
|
551
557
|
callback(subtype);
|
552
558
|
});
|
553
559
|
}
|
@@ -584,10 +590,10 @@ exports.areTypesSame = areTypesSame;
|
|
584
590
|
// the incomplete flag on the unknown if present. The caller should verify that
|
585
591
|
// one or the other type is Unknown or Any.
|
586
592
|
function preserveUnknown(type1, type2) {
|
587
|
-
if ((0, types_1.isUnknown)(type1) && type1.isIncomplete) {
|
593
|
+
if ((0, types_1.isUnknown)(type1) && type1.priv.isIncomplete) {
|
588
594
|
return type1;
|
589
595
|
}
|
590
|
-
else if ((0, types_1.isUnknown)(type2) && type2.isIncomplete) {
|
596
|
+
else if ((0, types_1.isUnknown)(type2) && type2.priv.isIncomplete) {
|
591
597
|
return type2;
|
592
598
|
}
|
593
599
|
else if ((0, types_1.isUnknown)(type1) || (0, types_1.isUnknown)(type2)) {
|
@@ -633,32 +639,33 @@ function derivesFromAnyOrUnknown(type) {
|
|
633
639
|
}
|
634
640
|
exports.derivesFromAnyOrUnknown = derivesFromAnyOrUnknown;
|
635
641
|
function getFullNameOfType(type) {
|
636
|
-
var _a;
|
637
|
-
if ((_a = type.
|
638
|
-
return type.typeAliasInfo.fullName;
|
642
|
+
var _a, _b;
|
643
|
+
if ((_b = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) === null || _b === void 0 ? void 0 : _b.fullName) {
|
644
|
+
return type.props.typeAliasInfo.fullName;
|
639
645
|
}
|
640
646
|
switch (type.category) {
|
641
647
|
case 2 /* TypeCategory.Any */:
|
642
648
|
case 1 /* TypeCategory.Unknown */:
|
643
649
|
return 'typing.Any';
|
644
650
|
case 6 /* TypeCategory.Class */:
|
645
|
-
return type.
|
651
|
+
return type.shared.fullName;
|
646
652
|
case 4 /* TypeCategory.Function */:
|
647
|
-
return type.
|
653
|
+
return type.shared.fullName;
|
648
654
|
case 7 /* TypeCategory.Module */:
|
649
|
-
return type.moduleName;
|
655
|
+
return type.priv.moduleName;
|
650
656
|
case 5 /* TypeCategory.OverloadedFunction */:
|
651
|
-
return type.overloads[0].
|
657
|
+
return type.priv.overloads[0].shared.fullName;
|
652
658
|
}
|
653
659
|
return undefined;
|
654
660
|
}
|
655
661
|
exports.getFullNameOfType = getFullNameOfType;
|
656
662
|
function addConditionToType(type, condition, skipSelfCondition = false) {
|
663
|
+
var _a, _b;
|
657
664
|
if (!condition) {
|
658
665
|
return type;
|
659
666
|
}
|
660
667
|
if (skipSelfCondition) {
|
661
|
-
condition = condition.filter((c) => !c.typeVar.
|
668
|
+
condition = condition.filter((c) => !c.typeVar.shared.isSynthesizedSelf);
|
662
669
|
if (condition.length === 0) {
|
663
670
|
return type;
|
664
671
|
}
|
@@ -672,17 +679,18 @@ function addConditionToType(type, condition, skipSelfCondition = false) {
|
|
672
679
|
case 9 /* TypeCategory.TypeVar */:
|
673
680
|
return type;
|
674
681
|
case 4 /* TypeCategory.Function */:
|
675
|
-
return types_1.TypeBase.cloneForCondition(type, types_1.TypeCondition.combine(type.condition, condition));
|
682
|
+
return types_1.TypeBase.cloneForCondition(type, types_1.TypeCondition.combine((_a = type.props) === null || _a === void 0 ? void 0 : _a.condition, condition));
|
676
683
|
case 5 /* TypeCategory.OverloadedFunction */:
|
677
|
-
return types_1.OverloadedFunctionType.create(type.overloads.map((t) => addConditionToType(t, condition)));
|
684
|
+
return types_1.OverloadedFunctionType.create(type.priv.overloads.map((t) => addConditionToType(t, condition)));
|
678
685
|
case 6 /* TypeCategory.Class */:
|
679
|
-
return types_1.TypeBase.cloneForCondition(type, types_1.TypeCondition.combine(type.condition, condition));
|
686
|
+
return types_1.TypeBase.cloneForCondition(type, types_1.TypeCondition.combine((_b = type.props) === null || _b === void 0 ? void 0 : _b.condition, condition));
|
680
687
|
case 8 /* TypeCategory.Union */:
|
681
|
-
return (0, types_1.combineTypes)(type.subtypes.map((t) => addConditionToType(t, condition)));
|
688
|
+
return (0, types_1.combineTypes)(type.priv.subtypes.map((t) => addConditionToType(t, condition)));
|
682
689
|
}
|
683
690
|
}
|
684
691
|
exports.addConditionToType = addConditionToType;
|
685
692
|
function getTypeCondition(type) {
|
693
|
+
var _a;
|
686
694
|
switch (type.category) {
|
687
695
|
case 0 /* TypeCategory.Unbound */:
|
688
696
|
case 1 /* TypeCategory.Unknown */:
|
@@ -695,7 +703,7 @@ function getTypeCondition(type) {
|
|
695
703
|
return undefined;
|
696
704
|
case 6 /* TypeCategory.Class */:
|
697
705
|
case 4 /* TypeCategory.Function */:
|
698
|
-
return type.condition;
|
706
|
+
return (_a = type.props) === null || _a === void 0 ? void 0 : _a.condition;
|
699
707
|
}
|
700
708
|
}
|
701
709
|
exports.getTypeCondition = getTypeCondition;
|
@@ -709,6 +717,7 @@ exports.isTypeAliasPlaceholder = isTypeAliasPlaceholder;
|
|
709
717
|
// within the specified type. It's OK if it's used indirectly as
|
710
718
|
// a type argument.
|
711
719
|
function isTypeAliasRecursive(typeAliasPlaceholder, type) {
|
720
|
+
var _a, _b;
|
712
721
|
if (type.category !== 8 /* TypeCategory.Union */) {
|
713
722
|
if (type === typeAliasPlaceholder) {
|
714
723
|
return true;
|
@@ -716,31 +725,32 @@ function isTypeAliasRecursive(typeAliasPlaceholder, type) {
|
|
716
725
|
// Handle the specific case where the type alias directly refers to itself.
|
717
726
|
// In this case, the type will be unbound because it could not be resolved.
|
718
727
|
return ((0, types_1.isUnbound)(type) &&
|
719
|
-
type.typeAliasInfo &&
|
720
|
-
type.typeAliasInfo.name === typeAliasPlaceholder.
|
728
|
+
((_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) &&
|
729
|
+
type.props.typeAliasInfo.name === ((_b = typeAliasPlaceholder.shared.recursiveAlias) === null || _b === void 0 ? void 0 : _b.name));
|
721
730
|
}
|
722
|
-
return ((0, types_1.findSubtype)(type, (subtype) => (0, types_1.isTypeVar)(subtype) && subtype.
|
731
|
+
return ((0, types_1.findSubtype)(type, (subtype) => (0, types_1.isTypeVar)(subtype) && subtype.shared === typeAliasPlaceholder.shared) !==
|
723
732
|
undefined);
|
724
733
|
}
|
725
734
|
exports.isTypeAliasRecursive = isTypeAliasRecursive;
|
726
735
|
function transformPossibleRecursiveTypeAlias(type) {
|
727
|
-
var _a;
|
736
|
+
var _a, _b;
|
728
737
|
if (type) {
|
729
|
-
|
738
|
+
const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
739
|
+
if ((0, types_1.isTypeVar)(type) && ((_b = type.shared.recursiveAlias) === null || _b === void 0 ? void 0 : _b.name) && type.shared.boundType) {
|
730
740
|
const unspecializedType = types_1.TypeBase.isInstance(type)
|
731
|
-
? convertToInstance(type.
|
732
|
-
: type.
|
733
|
-
if (!(
|
741
|
+
? convertToInstance(type.shared.boundType)
|
742
|
+
: type.shared.boundType;
|
743
|
+
if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments) || !type.shared.recursiveAlias.typeParameters) {
|
734
744
|
return unspecializedType;
|
735
745
|
}
|
736
|
-
const typeVarContext = buildTypeVarContext(type.
|
746
|
+
const typeVarContext = buildTypeVarContext(type.shared.recursiveAlias.typeParameters, aliasInfo.typeArguments, getTypeVarScopeId(type));
|
737
747
|
return applySolvedTypeVars(unspecializedType, typeVarContext);
|
738
748
|
}
|
739
|
-
if ((0, types_1.isUnion)(type) && type.includesRecursiveTypeAlias) {
|
749
|
+
if ((0, types_1.isUnion)(type) && type.priv.includesRecursiveTypeAlias) {
|
740
750
|
let newType = mapSubtypes(type, (subtype) => transformPossibleRecursiveTypeAlias(subtype));
|
741
|
-
if (newType !== type &&
|
751
|
+
if (newType !== type && aliasInfo) {
|
742
752
|
// Copy the type alias information if present.
|
743
|
-
newType = types_1.TypeBase.cloneForTypeAlias(newType,
|
753
|
+
newType = types_1.TypeBase.cloneForTypeAlias(newType, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParameters, aliasInfo.typeArguments);
|
744
754
|
}
|
745
755
|
return newType;
|
746
756
|
}
|
@@ -750,13 +760,13 @@ function transformPossibleRecursiveTypeAlias(type) {
|
|
750
760
|
exports.transformPossibleRecursiveTypeAlias = transformPossibleRecursiveTypeAlias;
|
751
761
|
function getTypeVarScopeId(type) {
|
752
762
|
if ((0, types_1.isClass)(type)) {
|
753
|
-
return type.
|
763
|
+
return type.shared.typeVarScopeId;
|
754
764
|
}
|
755
765
|
if ((0, types_1.isFunction)(type)) {
|
756
|
-
return type.
|
766
|
+
return type.shared.typeVarScopeId;
|
757
767
|
}
|
758
768
|
if ((0, types_1.isTypeVar)(type)) {
|
759
|
-
return type.scopeId;
|
769
|
+
return type.priv.scopeId;
|
760
770
|
}
|
761
771
|
return undefined;
|
762
772
|
}
|
@@ -770,14 +780,11 @@ function getTypeVarScopeIds(type) {
|
|
770
780
|
scopeIds.push(scopeId);
|
771
781
|
}
|
772
782
|
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);
|
783
|
+
if (type.priv.constructorTypeVarScopeId) {
|
784
|
+
scopeIds.push(type.priv.constructorTypeVarScopeId);
|
778
785
|
}
|
779
|
-
if (type.
|
780
|
-
scopeIds.push(type.
|
786
|
+
if (type.priv.higherOrderTypeVarScopeIds) {
|
787
|
+
scopeIds.push(...type.priv.higherOrderTypeVarScopeIds);
|
781
788
|
}
|
782
789
|
}
|
783
790
|
return scopeIds;
|
@@ -787,35 +794,35 @@ exports.getTypeVarScopeIds = getTypeVarScopeIds;
|
|
787
794
|
// specified, specialize it with default type arguments (Unknown or the
|
788
795
|
// default type if provided).
|
789
796
|
function specializeWithDefaultTypeArgs(type) {
|
790
|
-
if (type.
|
797
|
+
if (type.shared.typeParameters.length === 0 || type.priv.typeArguments) {
|
791
798
|
return type;
|
792
799
|
}
|
793
|
-
return types_1.ClassType.cloneForSpecialization(type, type.
|
800
|
+
return types_1.ClassType.cloneForSpecialization(type, type.shared.typeParameters.map((param) => param.shared.defaultType),
|
794
801
|
/* isTypeArgumentExplicit */ false,
|
795
|
-
/* includeSubclasses */ type.includeSubclasses);
|
802
|
+
/* includeSubclasses */ type.priv.includeSubclasses);
|
796
803
|
}
|
797
804
|
exports.specializeWithDefaultTypeArgs = specializeWithDefaultTypeArgs;
|
798
805
|
// Specializes the class with "Unknown" type args (or the equivalent for ParamSpecs
|
799
806
|
// or TypeVarTuples).
|
800
807
|
function specializeWithUnknownTypeArgs(type, tupleClassType) {
|
801
|
-
if (type.
|
808
|
+
if (type.shared.typeParameters.length === 0) {
|
802
809
|
return type;
|
803
810
|
}
|
804
811
|
if (isTupleClass(type)) {
|
805
812
|
return types_1.ClassType.cloneIncludeSubclasses(specializeTupleClass(type, [{ type: types_1.UnknownType.create(), isUnbounded: true }],
|
806
|
-
/* isTypeArgumentExplicit */ false), !!type.includeSubclasses);
|
813
|
+
/* isTypeArgumentExplicit */ false), !!type.priv.includeSubclasses);
|
807
814
|
}
|
808
|
-
return types_1.ClassType.cloneForSpecialization(type, type.
|
815
|
+
return types_1.ClassType.cloneForSpecialization(type, type.shared.typeParameters.map((param) => getUnknownTypeForTypeVar(param, tupleClassType)),
|
809
816
|
/* isTypeArgumentExplicit */ false,
|
810
|
-
/* includeSubclasses */ type.includeSubclasses);
|
817
|
+
/* includeSubclasses */ type.priv.includeSubclasses);
|
811
818
|
}
|
812
819
|
exports.specializeWithUnknownTypeArgs = specializeWithUnknownTypeArgs;
|
813
820
|
// Returns "Unknown" for simple TypeVars or the equivalent for a ParamSpec.
|
814
821
|
function getUnknownTypeForTypeVar(typeVar, tupleClassType) {
|
815
|
-
if (typeVar.
|
822
|
+
if (typeVar.shared.isParamSpec) {
|
816
823
|
return getUnknownTypeForParamSpec();
|
817
824
|
}
|
818
|
-
if (typeVar.
|
825
|
+
if (typeVar.shared.isVariadic && tupleClassType) {
|
819
826
|
return getUnknownTypeForVariadicTypeVar(tupleClassType);
|
820
827
|
}
|
821
828
|
return types_1.UnknownType.create();
|
@@ -839,21 +846,22 @@ exports.getUnknownTypeForVariadicTypeVar = getUnknownTypeForVariadicTypeVar;
|
|
839
846
|
function getUnknownTypeForCallable() {
|
840
847
|
const newFunction = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.GradualCallableForm */);
|
841
848
|
types_1.FunctionType.addDefaultParameters(newFunction);
|
842
|
-
newFunction.
|
849
|
+
newFunction.shared.declaredReturnType = types_1.UnknownType.create();
|
843
850
|
return newFunction;
|
844
851
|
}
|
845
852
|
exports.getUnknownTypeForCallable = getUnknownTypeForCallable;
|
846
853
|
// If the class is generic and not already specialized, this function
|
847
854
|
// "self specializes" the class, filling in its own type parameters
|
848
855
|
// as type arguments.
|
849
|
-
function selfSpecializeClass(type,
|
850
|
-
if (type.
|
856
|
+
function selfSpecializeClass(type, options) {
|
857
|
+
if (type.shared.typeParameters.length === 0) {
|
851
858
|
return type;
|
852
859
|
}
|
853
|
-
if (type.typeArguments && !overrideTypeArgs) {
|
860
|
+
if (type.priv.typeArguments && !(options === null || options === void 0 ? void 0 : options.overrideTypeArgs)) {
|
854
861
|
return type;
|
855
862
|
}
|
856
|
-
|
863
|
+
const typeParams = type.shared.typeParameters;
|
864
|
+
return types_1.ClassType.cloneForSpecialization(type, typeParams, /* isTypeArgumentExplicit */ true);
|
857
865
|
}
|
858
866
|
exports.selfSpecializeClass = selfSpecializeClass;
|
859
867
|
// Determines whether the type derives from tuple. If so, it returns
|
@@ -871,7 +879,7 @@ function getSpecializedTupleType(type) {
|
|
871
879
|
}
|
872
880
|
// See if this class derives from Tuple or tuple. If it does, we'll assume that it
|
873
881
|
// hasn't been overridden in a way that changes the behavior of the tuple class.
|
874
|
-
const tupleClass = classType.
|
882
|
+
const tupleClass = classType.shared.mro.find((mroClass) => (0, types_1.isInstantiableClass)(mroClass) && isTupleClass(mroClass));
|
875
883
|
if (!tupleClass || !(0, types_1.isInstantiableClass)(tupleClass)) {
|
876
884
|
return undefined;
|
877
885
|
}
|
@@ -883,7 +891,7 @@ function getSpecializedTupleType(type) {
|
|
883
891
|
}
|
884
892
|
exports.getSpecializedTupleType = getSpecializedTupleType;
|
885
893
|
function isLiteralType(type) {
|
886
|
-
return types_1.TypeBase.isInstance(type) && type.literalValue !== undefined;
|
894
|
+
return types_1.TypeBase.isInstance(type) && type.priv.literalValue !== undefined;
|
887
895
|
}
|
888
896
|
exports.isLiteralType = isLiteralType;
|
889
897
|
function isLiteralTypeOrUnion(type, allowNone = false) {
|
@@ -891,7 +899,7 @@ function isLiteralTypeOrUnion(type, allowNone = false) {
|
|
891
899
|
if (allowNone && isNoneInstance(type)) {
|
892
900
|
return true;
|
893
901
|
}
|
894
|
-
return type.literalValue !== undefined;
|
902
|
+
return type.priv.literalValue !== undefined;
|
895
903
|
}
|
896
904
|
if ((0, types_1.isUnion)(type)) {
|
897
905
|
return !(0, types_1.findSubtype)(type, (subtype) => {
|
@@ -901,7 +909,7 @@ function isLiteralTypeOrUnion(type, allowNone = false) {
|
|
901
909
|
if (isNoneInstance(subtype)) {
|
902
910
|
return !allowNone;
|
903
911
|
}
|
904
|
-
return subtype.literalValue === undefined;
|
912
|
+
return subtype.priv.literalValue === undefined;
|
905
913
|
});
|
906
914
|
}
|
907
915
|
return false;
|
@@ -937,8 +945,8 @@ exports.containsLiteralType = containsLiteralType;
|
|
937
945
|
// it returns undefined.
|
938
946
|
function getLiteralTypeClassName(type) {
|
939
947
|
if ((0, types_1.isClassInstance)(type)) {
|
940
|
-
if (type.literalValue !== undefined && types_1.ClassType.isBuiltIn(type)) {
|
941
|
-
return type.
|
948
|
+
if (type.priv.literalValue !== undefined && types_1.ClassType.isBuiltIn(type)) {
|
949
|
+
return type.shared.name;
|
942
950
|
}
|
943
951
|
return undefined;
|
944
952
|
}
|
@@ -961,13 +969,13 @@ function getLiteralTypeClassName(type) {
|
|
961
969
|
exports.getLiteralTypeClassName = getLiteralTypeClassName;
|
962
970
|
function getUnionSubtypeCount(type) {
|
963
971
|
if ((0, types_1.isUnion)(type)) {
|
964
|
-
return type.subtypes.length;
|
972
|
+
return type.priv.subtypes.length;
|
965
973
|
}
|
966
974
|
return 1;
|
967
975
|
}
|
968
976
|
exports.getUnionSubtypeCount = getUnionSubtypeCount;
|
969
977
|
function isEllipsisType(type) {
|
970
|
-
return (0, types_1.isAny)(type) && type.isEllipsis;
|
978
|
+
return (0, types_1.isAny)(type) && type.priv.isEllipsis;
|
971
979
|
}
|
972
980
|
exports.isEllipsisType = isEllipsisType;
|
973
981
|
function isProperty(type) {
|
@@ -989,21 +997,21 @@ function isCallableType(type) {
|
|
989
997
|
return !!callMember;
|
990
998
|
}
|
991
999
|
if ((0, types_1.isUnion)(type)) {
|
992
|
-
return type.subtypes.every((subtype) => isCallableType(subtype));
|
1000
|
+
return type.priv.subtypes.every((subtype) => isCallableType(subtype));
|
993
1001
|
}
|
994
1002
|
return false;
|
995
1003
|
}
|
996
1004
|
exports.isCallableType = isCallableType;
|
997
1005
|
function isDescriptorInstance(type, requireSetter = false) {
|
998
1006
|
if ((0, types_1.isUnion)(type)) {
|
999
|
-
return type.subtypes.every((subtype) => isMaybeDescriptorInstance(subtype, requireSetter));
|
1007
|
+
return type.priv.subtypes.every((subtype) => isMaybeDescriptorInstance(subtype, requireSetter));
|
1000
1008
|
}
|
1001
1009
|
return isMaybeDescriptorInstance(type, requireSetter);
|
1002
1010
|
}
|
1003
1011
|
exports.isDescriptorInstance = isDescriptorInstance;
|
1004
1012
|
function isMaybeDescriptorInstance(type, requireSetter = false) {
|
1005
1013
|
if ((0, types_1.isUnion)(type)) {
|
1006
|
-
return type.subtypes.some((subtype) => isMaybeDescriptorInstance(subtype, requireSetter));
|
1014
|
+
return type.priv.subtypes.some((subtype) => isMaybeDescriptorInstance(subtype, requireSetter));
|
1007
1015
|
}
|
1008
1016
|
if (!(0, types_1.isClassInstance)(type)) {
|
1009
1017
|
return false;
|
@@ -1017,6 +1025,15 @@ function isMaybeDescriptorInstance(type, requireSetter = false) {
|
|
1017
1025
|
return true;
|
1018
1026
|
}
|
1019
1027
|
exports.isMaybeDescriptorInstance = isMaybeDescriptorInstance;
|
1028
|
+
function isTupleGradualForm(type) {
|
1029
|
+
return ((0, types_1.isClassInstance)(type) &&
|
1030
|
+
isTupleClass(type) &&
|
1031
|
+
type.priv.tupleTypeArguments &&
|
1032
|
+
type.priv.tupleTypeArguments.length === 1 &&
|
1033
|
+
(0, types_1.isAnyOrUnknown)(type.priv.tupleTypeArguments[0].type) &&
|
1034
|
+
type.priv.tupleTypeArguments[0].isUnbounded);
|
1035
|
+
}
|
1036
|
+
exports.isTupleGradualForm = isTupleGradualForm;
|
1020
1037
|
function isTupleClass(type) {
|
1021
1038
|
return types_1.ClassType.isBuiltIn(type, 'tuple');
|
1022
1039
|
}
|
@@ -1025,24 +1042,24 @@ exports.isTupleClass = isTupleClass;
|
|
1025
1042
|
// the form tuple[x, ...] where the number of elements
|
1026
1043
|
// in the tuple is unknown.
|
1027
1044
|
function isUnboundedTupleClass(type) {
|
1028
|
-
return (type.tupleTypeArguments &&
|
1029
|
-
type.tupleTypeArguments.some((t) => t.isUnbounded || (0, types_1.isUnpackedVariadicTypeVar)(t.type)));
|
1045
|
+
return (type.priv.tupleTypeArguments &&
|
1046
|
+
type.priv.tupleTypeArguments.some((t) => t.isUnbounded || (0, types_1.isUnpackedVariadicTypeVar)(t.type)));
|
1030
1047
|
}
|
1031
1048
|
exports.isUnboundedTupleClass = isUnboundedTupleClass;
|
1032
1049
|
// Indicates whether the specified index is within range and its type is unambiguous
|
1033
1050
|
// in that it doesn't involve any element ranges that are of indeterminate length.
|
1034
1051
|
function isTupleIndexUnambiguous(type, index) {
|
1035
|
-
if (!type.tupleTypeArguments) {
|
1052
|
+
if (!type.priv.tupleTypeArguments) {
|
1036
1053
|
return false;
|
1037
1054
|
}
|
1038
1055
|
if (index < 0) {
|
1039
|
-
if (isUnboundedTupleClass(type) || type.tupleTypeArguments.length + index < 0) {
|
1056
|
+
if (isUnboundedTupleClass(type) || type.priv.tupleTypeArguments.length + index < 0) {
|
1040
1057
|
return false;
|
1041
1058
|
}
|
1042
1059
|
}
|
1043
|
-
let unambiguousIndexLimit = type.tupleTypeArguments.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedVariadicTypeVar)(t.type));
|
1060
|
+
let unambiguousIndexLimit = type.priv.tupleTypeArguments.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedVariadicTypeVar)(t.type));
|
1044
1061
|
if (unambiguousIndexLimit < 0) {
|
1045
|
-
unambiguousIndexLimit = type.tupleTypeArguments.length;
|
1062
|
+
unambiguousIndexLimit = type.priv.tupleTypeArguments.length;
|
1046
1063
|
}
|
1047
1064
|
return index < unambiguousIndexLimit;
|
1048
1065
|
}
|
@@ -1065,7 +1082,7 @@ function partiallySpecializeType(type, contextClassType, selfClass, typeClassTyp
|
|
1065
1082
|
// If this is a property, we may need to partially specialize the
|
1066
1083
|
// access methods associated with it.
|
1067
1084
|
if ((0, types_1.isClass)(result)) {
|
1068
|
-
if (result.fgetInfo || result.fsetInfo || result.fdelInfo) {
|
1085
|
+
if (result.priv.fgetInfo || result.priv.fsetInfo || result.priv.fdelInfo) {
|
1069
1086
|
function updatePropertyMethodInfo(methodInfo) {
|
1070
1087
|
if (!methodInfo) {
|
1071
1088
|
return undefined;
|
@@ -1076,9 +1093,9 @@ function partiallySpecializeType(type, contextClassType, selfClass, typeClassTyp
|
|
1076
1093
|
};
|
1077
1094
|
}
|
1078
1095
|
result = types_1.TypeBase.cloneType(result);
|
1079
|
-
result.fgetInfo = updatePropertyMethodInfo(result.fgetInfo);
|
1080
|
-
result.fsetInfo = updatePropertyMethodInfo(result.fsetInfo);
|
1081
|
-
result.fdelInfo = updatePropertyMethodInfo(result.fdelInfo);
|
1096
|
+
result.priv.fgetInfo = updatePropertyMethodInfo(result.priv.fgetInfo);
|
1097
|
+
result.priv.fsetInfo = updatePropertyMethodInfo(result.priv.fsetInfo);
|
1098
|
+
result.priv.fdelInfo = updatePropertyMethodInfo(result.priv.fdelInfo);
|
1082
1099
|
}
|
1083
1100
|
}
|
1084
1101
|
return result;
|
@@ -1091,7 +1108,7 @@ function populateTypeVarContextForSelfType(typeVarContext, contextClassType, sel
|
|
1091
1108
|
// Instead, we'll do a simplified version of it here.
|
1092
1109
|
const selfWithoutLiteral = mapSubtypes(selfInstance, (subtype) => {
|
1093
1110
|
if ((0, types_1.isClass)(subtype)) {
|
1094
|
-
if (subtype.literalValue !== undefined) {
|
1111
|
+
if (subtype.priv.literalValue !== undefined) {
|
1095
1112
|
return types_1.ClassType.cloneWithLiteral(subtype, /* value */ undefined);
|
1096
1113
|
}
|
1097
1114
|
}
|
@@ -1163,7 +1180,7 @@ function applyInScopePlaceholders(typeVarContext) {
|
|
1163
1180
|
typeVarContext.doForEachSignatureContext((signature) => {
|
1164
1181
|
signature.getTypeVars().forEach((entry) => {
|
1165
1182
|
const typeVar = entry.typeVar;
|
1166
|
-
if (!typeVar.isInScopePlaceholder) {
|
1183
|
+
if (!typeVar.priv.isInScopePlaceholder) {
|
1167
1184
|
const newNarrowTypeBound = entry.narrowBound
|
1168
1185
|
? applyInScopePlaceholdersToType(entry.narrowBound, signature)
|
1169
1186
|
: undefined;
|
@@ -1193,9 +1210,9 @@ exports.applyInScopePlaceholders = applyInScopePlaceholders;
|
|
1193
1210
|
function validateTypeVarDefault(typeVar, liveTypeParams, invalidTypeVars) {
|
1194
1211
|
// If there is no default type or the default type is concrete, there's
|
1195
1212
|
// no need to do any more work here.
|
1196
|
-
if (typeVar.
|
1213
|
+
if (typeVar.shared.isDefaultExplicit && requiresSpecialization(typeVar.shared.defaultType)) {
|
1197
1214
|
const validator = new TypeVarDefaultValidator(liveTypeParams, invalidTypeVars);
|
1198
|
-
validator.apply(typeVar.
|
1215
|
+
validator.apply(typeVar.shared.defaultType, 0);
|
1199
1216
|
}
|
1200
1217
|
}
|
1201
1218
|
exports.validateTypeVarDefault = validateTypeVarDefault;
|
@@ -1220,7 +1237,7 @@ exports.transformExpectedType = transformExpectedType;
|
|
1220
1237
|
// appears in a parent and a child, the child overrides the parent.
|
1221
1238
|
function getProtocolSymbols(classType) {
|
1222
1239
|
const symbolMap = new Map();
|
1223
|
-
if ((classType.
|
1240
|
+
if ((classType.shared.flags & 512 /* ClassTypeFlags.ProtocolClass */) !== 0) {
|
1224
1241
|
getProtocolSymbolsRecursive(classType, symbolMap, 512 /* ClassTypeFlags.ProtocolClass */);
|
1225
1242
|
}
|
1226
1243
|
return symbolMap;
|
@@ -1230,8 +1247,8 @@ function getProtocolSymbolsRecursive(classType, symbolMap, classFlags = 512 /* C
|
|
1230
1247
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
1231
1248
|
return;
|
1232
1249
|
}
|
1233
|
-
classType.
|
1234
|
-
if ((0, types_1.isClass)(baseClass) && (baseClass.
|
1250
|
+
classType.shared.baseClasses.forEach((baseClass) => {
|
1251
|
+
if ((0, types_1.isClass)(baseClass) && (baseClass.shared.flags & classFlags) !== 0) {
|
1235
1252
|
getProtocolSymbolsRecursive(baseClass, symbolMap, classFlags, recursionCount + 1);
|
1236
1253
|
}
|
1237
1254
|
});
|
@@ -1262,16 +1279,16 @@ function getContainerDepth(type, recursionCount = 0) {
|
|
1262
1279
|
return 0;
|
1263
1280
|
}
|
1264
1281
|
let maxChildDepth = 0;
|
1265
|
-
if (type.tupleTypeArguments) {
|
1266
|
-
type.tupleTypeArguments.forEach((typeArgInfo) => {
|
1282
|
+
if (type.priv.tupleTypeArguments) {
|
1283
|
+
type.priv.tupleTypeArguments.forEach((typeArgInfo) => {
|
1267
1284
|
doForEachSubtype(typeArgInfo.type, (subtype) => {
|
1268
1285
|
const childDepth = getContainerDepth(subtype, recursionCount);
|
1269
1286
|
maxChildDepth = Math.max(childDepth, maxChildDepth);
|
1270
1287
|
});
|
1271
1288
|
});
|
1272
1289
|
}
|
1273
|
-
else if (type.typeArguments) {
|
1274
|
-
type.typeArguments.forEach((typeArg) => {
|
1290
|
+
else if (type.priv.typeArguments) {
|
1291
|
+
type.priv.typeArguments.forEach((typeArg) => {
|
1275
1292
|
doForEachSubtype(typeArg, (subtype) => {
|
1276
1293
|
const childDepth = getContainerDepth(subtype, recursionCount);
|
1277
1294
|
maxChildDepth = Math.max(childDepth, maxChildDepth);
|
@@ -1296,7 +1313,7 @@ exports.lookUpObjectMember = lookUpObjectMember;
|
|
1296
1313
|
function lookUpClassMember(classType, memberName, flags = 0 /* MemberAccessFlags.Default */, skipMroClass) {
|
1297
1314
|
var _a, _b;
|
1298
1315
|
// Look in the metaclass first.
|
1299
|
-
const metaclass = classType.
|
1316
|
+
const metaclass = classType.shared.effectiveMetaclass;
|
1300
1317
|
// Skip the "type" class as an optimization because it is known to not
|
1301
1318
|
// define any instance variables, and it's by far the most common metaclass.
|
1302
1319
|
if (metaclass && (0, types_1.isClass)(metaclass) && !types_1.ClassType.isBuiltIn(metaclass, 'type')) {
|
@@ -1454,7 +1471,7 @@ exports.getClassMemberIterator = getClassMemberIterator;
|
|
1454
1471
|
function* getClassIterator(classType, flags = 0 /* ClassIteratorFlags.Default */, skipMroClass) {
|
1455
1472
|
if ((0, types_1.isClass)(classType)) {
|
1456
1473
|
let foundSkipMroClass = skipMroClass === undefined;
|
1457
|
-
for (const mroClass of classType.
|
1474
|
+
for (const mroClass of classType.shared.mro) {
|
1458
1475
|
// Are we still searching for the skipMroClass?
|
1459
1476
|
if (!foundSkipMroClass && skipMroClass) {
|
1460
1477
|
if (!(0, types_1.isClass)(mroClass)) {
|
@@ -1530,7 +1547,7 @@ exports.getClassFieldsRecursive = getClassFieldsRecursive;
|
|
1530
1547
|
// but removing any duplicates.
|
1531
1548
|
function addTypeVarsToListIfUnique(list1, list2, typeVarScopeId) {
|
1532
1549
|
for (const type2 of list2) {
|
1533
|
-
if (typeVarScopeId && type2.scopeId !== typeVarScopeId) {
|
1550
|
+
if (typeVarScopeId && type2.priv.scopeId !== typeVarScopeId) {
|
1534
1551
|
continue;
|
1535
1552
|
}
|
1536
1553
|
if (!list1.find((type1) => (0, types_1.isTypeSame)(convertToInstance(type1), convertToInstance(type2)))) {
|
@@ -1545,32 +1562,35 @@ exports.addTypeVarsToListIfUnique = addTypeVarsToListIfUnique;
|
|
1545
1562
|
// Union[List[Dict[_T1, _T2]], _T1, _T3], the result would be
|
1546
1563
|
// [_T1, _T2, _T3].
|
1547
1564
|
function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
1548
|
-
var _a
|
1565
|
+
var _a;
|
1549
1566
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
1550
1567
|
return [];
|
1551
1568
|
}
|
1552
1569
|
recursionCount++;
|
1553
|
-
|
1570
|
+
const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
1571
|
+
if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments) {
|
1554
1572
|
const combinedList = [];
|
1555
|
-
|
1573
|
+
aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments.forEach((typeArg) => {
|
1556
1574
|
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(typeArg, recursionCount));
|
1557
1575
|
});
|
1558
1576
|
return combinedList;
|
1559
1577
|
}
|
1560
1578
|
if ((0, types_1.isTypeVar)(type)) {
|
1561
1579
|
// Don't return any recursive type alias placeholders.
|
1562
|
-
if (type.
|
1580
|
+
if (type.shared.recursiveAlias) {
|
1563
1581
|
return [];
|
1564
1582
|
}
|
1565
1583
|
// Don't return any P.args or P.kwargs types.
|
1566
|
-
if ((0, types_1.isParamSpec)(type) && type.paramSpecAccess) {
|
1584
|
+
if ((0, types_1.isParamSpec)(type) && type.priv.paramSpecAccess) {
|
1567
1585
|
return [types_1.TypeVarType.cloneForParamSpecAccess(type, /* access */ undefined)];
|
1568
1586
|
}
|
1569
1587
|
return [types_1.TypeBase.isInstantiable(type) ? types_1.TypeVarType.cloneAsInstance(type) : type];
|
1570
1588
|
}
|
1571
1589
|
if ((0, types_1.isClass)(type)) {
|
1572
1590
|
const combinedList = [];
|
1573
|
-
const typeArgs = type.
|
1591
|
+
const typeArgs = type.priv.tupleTypeArguments
|
1592
|
+
? type.priv.tupleTypeArguments.map((e) => e.type)
|
1593
|
+
: type.priv.typeArguments;
|
1574
1594
|
if (typeArgs) {
|
1575
1595
|
typeArgs.forEach((typeArg) => {
|
1576
1596
|
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(typeArg, recursionCount));
|
@@ -1587,7 +1607,7 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
|
1587
1607
|
}
|
1588
1608
|
if ((0, types_1.isFunction)(type)) {
|
1589
1609
|
const combinedList = [];
|
1590
|
-
for (let i = 0; i < type.
|
1610
|
+
for (let i = 0; i < type.shared.parameters.length; i++) {
|
1591
1611
|
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(types_1.FunctionType.getEffectiveParameterType(type, i), recursionCount));
|
1592
1612
|
}
|
1593
1613
|
const returnType = types_1.FunctionType.getEffectiveReturnType(type);
|
@@ -1605,7 +1625,7 @@ function specializeClassType(type) {
|
|
1605
1625
|
const typeVarContext = new typeVarContext_1.TypeVarContext(getTypeVarScopeId(type));
|
1606
1626
|
const typeParams = types_1.ClassType.getTypeParameters(type);
|
1607
1627
|
typeParams.forEach((typeParam) => {
|
1608
|
-
typeVarContext.setTypeVarType(typeParam, applySolvedTypeVars(typeParam.
|
1628
|
+
typeVarContext.setTypeVarType(typeParam, applySolvedTypeVars(typeParam.shared.defaultType, typeVarContext));
|
1609
1629
|
});
|
1610
1630
|
return applySolvedTypeVars(type, typeVarContext);
|
1611
1631
|
}
|
@@ -1627,37 +1647,37 @@ function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionC
|
|
1627
1647
|
});
|
1628
1648
|
break;
|
1629
1649
|
case 6 /* TypeCategory.Class */:
|
1630
|
-
if (destType.typeArguments) {
|
1631
|
-
destType.typeArguments.forEach((typeArg) => {
|
1650
|
+
if (destType.priv.typeArguments) {
|
1651
|
+
destType.priv.typeArguments.forEach((typeArg) => {
|
1632
1652
|
setTypeArgumentsRecursive(typeArg, srcType, typeVarContext, recursionCount);
|
1633
1653
|
});
|
1634
1654
|
}
|
1635
|
-
if (destType.tupleTypeArguments) {
|
1636
|
-
destType.tupleTypeArguments.forEach((typeArg) => {
|
1655
|
+
if (destType.priv.tupleTypeArguments) {
|
1656
|
+
destType.priv.tupleTypeArguments.forEach((typeArg) => {
|
1637
1657
|
setTypeArgumentsRecursive(typeArg.type, srcType, typeVarContext, recursionCount);
|
1638
1658
|
});
|
1639
1659
|
}
|
1640
1660
|
break;
|
1641
1661
|
case 4 /* TypeCategory.Function */:
|
1642
|
-
if (destType.specializedTypes) {
|
1643
|
-
destType.specializedTypes.parameterTypes.forEach((paramType) => {
|
1662
|
+
if (destType.priv.specializedTypes) {
|
1663
|
+
destType.priv.specializedTypes.parameterTypes.forEach((paramType) => {
|
1644
1664
|
setTypeArgumentsRecursive(paramType, srcType, typeVarContext, recursionCount);
|
1645
1665
|
});
|
1646
|
-
if (destType.specializedTypes.returnType) {
|
1647
|
-
setTypeArgumentsRecursive(destType.specializedTypes.returnType, srcType, typeVarContext, recursionCount);
|
1666
|
+
if (destType.priv.specializedTypes.returnType) {
|
1667
|
+
setTypeArgumentsRecursive(destType.priv.specializedTypes.returnType, srcType, typeVarContext, recursionCount);
|
1648
1668
|
}
|
1649
1669
|
}
|
1650
1670
|
else {
|
1651
|
-
destType.
|
1671
|
+
destType.shared.parameters.forEach((param) => {
|
1652
1672
|
setTypeArgumentsRecursive(param.type, srcType, typeVarContext, recursionCount);
|
1653
1673
|
});
|
1654
|
-
if (destType.
|
1655
|
-
setTypeArgumentsRecursive(destType.
|
1674
|
+
if (destType.shared.declaredReturnType) {
|
1675
|
+
setTypeArgumentsRecursive(destType.shared.declaredReturnType, srcType, typeVarContext, recursionCount);
|
1656
1676
|
}
|
1657
1677
|
}
|
1658
1678
|
break;
|
1659
1679
|
case 5 /* TypeCategory.OverloadedFunction */:
|
1660
|
-
destType.overloads.forEach((subtype) => {
|
1680
|
+
destType.priv.overloads.forEach((subtype) => {
|
1661
1681
|
setTypeArgumentsRecursive(subtype, srcType, typeVarContext, recursionCount);
|
1662
1682
|
});
|
1663
1683
|
break;
|
@@ -1675,9 +1695,9 @@ exports.setTypeArgumentsRecursive = setTypeArgumentsRecursive;
|
|
1675
1695
|
// _T1 with str and _T2 with int.
|
1676
1696
|
function buildTypeVarContextFromSpecializedClass(classType) {
|
1677
1697
|
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);
|
1698
|
+
const typeVarContext = buildTypeVarContext(typeParameters, classType.priv.typeArguments, getTypeVarScopeId(classType));
|
1699
|
+
if (types_1.ClassType.isTupleClass(classType) && classType.priv.tupleTypeArguments) {
|
1700
|
+
typeVarContext.setTupleTypeVar(typeParameters[0], classType.priv.tupleTypeArguments);
|
1681
1701
|
}
|
1682
1702
|
return typeVarContext;
|
1683
1703
|
}
|
@@ -1687,21 +1707,14 @@ function buildTypeVarContext(typeParameters, typeArgs, typeVarScopeId) {
|
|
1687
1707
|
typeParameters.forEach((typeParam, index) => {
|
1688
1708
|
let typeArgType;
|
1689
1709
|
if (typeArgs) {
|
1690
|
-
if (typeParam.
|
1710
|
+
if (typeParam.shared.isParamSpec) {
|
1691
1711
|
if (index < typeArgs.length) {
|
1692
1712
|
typeArgType = typeArgs[index];
|
1693
1713
|
if ((0, types_1.isFunction)(typeArgType) && types_1.FunctionType.isParamSpecValue(typeArgType)) {
|
1694
1714
|
const parameters = [];
|
1695
1715
|
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
|
-
});
|
1716
|
+
typeArgType.shared.parameters.forEach((param, paramIndex) => {
|
1717
|
+
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
1718
|
});
|
1706
1719
|
typeVarContext.setTypeVarType(typeParam, convertTypeToParamSpecValue(typeArgType));
|
1707
1720
|
}
|
@@ -1740,7 +1753,7 @@ function specializeForBaseClass(srcType, baseClass) {
|
|
1740
1753
|
}
|
1741
1754
|
exports.specializeForBaseClass = specializeForBaseClass;
|
1742
1755
|
function derivesFromStdlibClass(classType, className) {
|
1743
|
-
return classType.
|
1756
|
+
return classType.shared.mro.some((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isBuiltIn(mroClass, className));
|
1744
1757
|
}
|
1745
1758
|
exports.derivesFromStdlibClass = derivesFromStdlibClass;
|
1746
1759
|
// If ignoreUnknown is true, an unknown base class is ignored when
|
@@ -1750,7 +1763,7 @@ function derivesFromClassRecursive(classType, baseClassToFind, ignoreUnknown) {
|
|
1750
1763
|
if (types_1.ClassType.isSameGenericClass(classType, baseClassToFind)) {
|
1751
1764
|
return true;
|
1752
1765
|
}
|
1753
|
-
for (const baseClass of classType.
|
1766
|
+
for (const baseClass of classType.shared.baseClasses) {
|
1754
1767
|
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
1755
1768
|
if (derivesFromClassRecursive(baseClass, baseClassToFind, ignoreUnknown)) {
|
1756
1769
|
return true;
|
@@ -1768,14 +1781,14 @@ function synthesizeTypeVarForSelfCls(classType, isClsParam) {
|
|
1768
1781
|
var _a;
|
1769
1782
|
const selfType = types_1.TypeVarType.createInstance(`__type_of_self__`);
|
1770
1783
|
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;
|
1784
|
+
selfType.shared.isSynthesized = true;
|
1785
|
+
selfType.shared.isSynthesizedSelf = true;
|
1786
|
+
selfType.priv.nameWithScope = types_1.TypeVarType.makeNameWithScope(selfType.shared.name, scopeId);
|
1787
|
+
selfType.priv.scopeId = scopeId;
|
1775
1788
|
const boundType = types_1.ClassType.cloneForSpecialization(classType, types_1.ClassType.getTypeParameters(classType),
|
1776
1789
|
/* isTypeArgumentExplicit */ false,
|
1777
|
-
/* includeSubclasses */ !!classType.includeSubclasses);
|
1778
|
-
selfType.
|
1790
|
+
/* includeSubclasses */ !!classType.priv.includeSubclasses);
|
1791
|
+
selfType.shared.boundType = types_1.ClassType.cloneAsInstance(boundType);
|
1779
1792
|
return isClsParam ? types_1.TypeVarType.cloneAsInstantiable(selfType) : selfType;
|
1780
1793
|
}
|
1781
1794
|
exports.synthesizeTypeVarForSelfCls = synthesizeTypeVarForSelfCls;
|
@@ -1810,8 +1823,8 @@ function getGeneratorYieldType(declaredReturnType, isAsync) {
|
|
1810
1823
|
['', 'AwaitableGenerator'],
|
1811
1824
|
];
|
1812
1825
|
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]
|
1826
|
+
return subtype.priv.typeArguments && subtype.priv.typeArguments.length >= 1
|
1827
|
+
? subtype.priv.typeArguments[0]
|
1815
1828
|
: types_1.UnknownType.create();
|
1816
1829
|
}
|
1817
1830
|
}
|
@@ -1823,12 +1836,12 @@ function getGeneratorYieldType(declaredReturnType, isAsync) {
|
|
1823
1836
|
exports.getGeneratorYieldType = getGeneratorYieldType;
|
1824
1837
|
function isInstantiableMetaclass(type) {
|
1825
1838
|
return ((0, types_1.isInstantiableClass)(type) &&
|
1826
|
-
type.
|
1839
|
+
type.shared.mro.some((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isBuiltIn(mroClass, 'type')));
|
1827
1840
|
}
|
1828
1841
|
exports.isInstantiableMetaclass = isInstantiableMetaclass;
|
1829
1842
|
function isMetaclassInstance(type) {
|
1830
1843
|
return ((0, types_1.isClassInstance)(type) &&
|
1831
|
-
type.
|
1844
|
+
type.shared.mro.some((mroClass) => (0, types_1.isClass)(mroClass) && types_1.ClassType.isBuiltIn(mroClass, 'type')));
|
1832
1845
|
}
|
1833
1846
|
exports.isMetaclassInstance = isMetaclassInstance;
|
1834
1847
|
function isEffectivelyInstantiable(type, options, recursionCount = 0) {
|
@@ -1839,8 +1852,8 @@ function isEffectivelyInstantiable(type, options, recursionCount = 0) {
|
|
1839
1852
|
if (types_1.TypeBase.isInstantiable(type)) {
|
1840
1853
|
return true;
|
1841
1854
|
}
|
1842
|
-
if ((options === null || options === void 0 ? void 0 : options.honorTypeVarBounds) && (0, types_1.isTypeVar)(type) && type.
|
1843
|
-
if (isEffectivelyInstantiable(type.
|
1855
|
+
if ((options === null || options === void 0 ? void 0 : options.honorTypeVarBounds) && (0, types_1.isTypeVar)(type) && type.shared.boundType) {
|
1856
|
+
if (isEffectivelyInstantiable(type.shared.boundType, options, recursionCount)) {
|
1844
1857
|
return true;
|
1845
1858
|
}
|
1846
1859
|
}
|
@@ -1850,13 +1863,13 @@ function isEffectivelyInstantiable(type, options, recursionCount = 0) {
|
|
1850
1863
|
return true;
|
1851
1864
|
}
|
1852
1865
|
if ((0, types_1.isUnion)(type)) {
|
1853
|
-
return type.subtypes.every((subtype) => isEffectivelyInstantiable(subtype, options, recursionCount));
|
1866
|
+
return type.priv.subtypes.every((subtype) => isEffectivelyInstantiable(subtype, options, recursionCount));
|
1854
1867
|
}
|
1855
1868
|
return false;
|
1856
1869
|
}
|
1857
1870
|
exports.isEffectivelyInstantiable = isEffectivelyInstantiable;
|
1858
1871
|
function convertToInstance(type, includeSubclasses = true) {
|
1859
|
-
var _a;
|
1872
|
+
var _a, _b;
|
1860
1873
|
// See if we've already performed this conversion and cached it.
|
1861
1874
|
if (((_a = type.cached) === null || _a === void 0 ? void 0 : _a.instanceType) && includeSubclasses) {
|
1862
1875
|
return type.cached.instanceType;
|
@@ -1867,17 +1880,17 @@ function convertToInstance(type, includeSubclasses = true) {
|
|
1867
1880
|
// Handle type[x] as a special case.
|
1868
1881
|
if (types_1.ClassType.isBuiltIn(subtype, 'type')) {
|
1869
1882
|
if (types_1.TypeBase.isInstance(subtype)) {
|
1870
|
-
if (!subtype.typeArguments || subtype.typeArguments.length < 1) {
|
1883
|
+
if (!subtype.priv.typeArguments || subtype.priv.typeArguments.length < 1) {
|
1871
1884
|
return types_1.UnknownType.create();
|
1872
1885
|
}
|
1873
1886
|
else {
|
1874
|
-
return subtype.typeArguments[0];
|
1887
|
+
return subtype.priv.typeArguments[0];
|
1875
1888
|
}
|
1876
1889
|
}
|
1877
1890
|
else {
|
1878
|
-
if (subtype.typeArguments && subtype.typeArguments.length > 0) {
|
1879
|
-
if (!(0, types_1.isAnyOrUnknown)(subtype.typeArguments[0])) {
|
1880
|
-
return convertToInstantiable(subtype.typeArguments[0]);
|
1891
|
+
if (subtype.priv.typeArguments && subtype.priv.typeArguments.length > 0) {
|
1892
|
+
if (!(0, types_1.isAnyOrUnknown)(subtype.priv.typeArguments[0])) {
|
1893
|
+
return convertToInstantiable(subtype.priv.typeArguments[0]);
|
1881
1894
|
}
|
1882
1895
|
}
|
1883
1896
|
}
|
@@ -1910,10 +1923,13 @@ function convertToInstance(type, includeSubclasses = true) {
|
|
1910
1923
|
}
|
1911
1924
|
}
|
1912
1925
|
return subtype;
|
1926
|
+
}, {
|
1927
|
+
skipElideRedundantLiterals: true,
|
1913
1928
|
});
|
1914
1929
|
// Copy over any type alias information.
|
1915
|
-
|
1916
|
-
|
1930
|
+
const aliasInfo = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo;
|
1931
|
+
if (aliasInfo && type !== result) {
|
1932
|
+
result = types_1.TypeBase.cloneForTypeAlias(result, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParameters, aliasInfo.typeArguments);
|
1917
1933
|
}
|
1918
1934
|
if (type !== result && includeSubclasses) {
|
1919
1935
|
// Cache the converted value for next time.
|
@@ -1956,7 +1972,7 @@ function convertToInstantiable(type, includeSubclasses = true) {
|
|
1956
1972
|
}
|
1957
1973
|
exports.convertToInstantiable = convertToInstantiable;
|
1958
1974
|
function getMembersForClass(classType, symbolTable, includeInstanceVars) {
|
1959
|
-
classType.
|
1975
|
+
classType.shared.mro.forEach((mroClass) => {
|
1960
1976
|
if ((0, types_1.isInstantiableClass)(mroClass)) {
|
1961
1977
|
// Add any new member variables from this class.
|
1962
1978
|
const isClassTypedDict = types_1.ClassType.isTypedDictClass(mroClass);
|
@@ -1981,9 +1997,9 @@ function getMembersForClass(classType, symbolTable, includeInstanceVars) {
|
|
1981
1997
|
});
|
1982
1998
|
// Add members of the metaclass as well.
|
1983
1999
|
if (!includeInstanceVars) {
|
1984
|
-
const metaclass = classType.
|
2000
|
+
const metaclass = classType.shared.effectiveMetaclass;
|
1985
2001
|
if (metaclass && (0, types_1.isInstantiableClass)(metaclass)) {
|
1986
|
-
for (const mroClass of metaclass.
|
2002
|
+
for (const mroClass of metaclass.shared.mro) {
|
1987
2003
|
if ((0, types_1.isInstantiableClass)(mroClass)) {
|
1988
2004
|
types_1.ClassType.getSymbolTable(mroClass).forEach((symbol, name) => {
|
1989
2005
|
const existingSymbol = symbolTable.get(name);
|
@@ -2009,12 +2025,12 @@ function getMembersForModule(moduleType, symbolTable) {
|
|
2009
2025
|
// Start with the loader fields. If there are any symbols of the
|
2010
2026
|
// same name defined within the module, they will overwrite the
|
2011
2027
|
// loader fields.
|
2012
|
-
if (moduleType.loaderFields) {
|
2013
|
-
moduleType.loaderFields.forEach((symbol, name) => {
|
2028
|
+
if (moduleType.priv.loaderFields) {
|
2029
|
+
moduleType.priv.loaderFields.forEach((symbol, name) => {
|
2014
2030
|
symbolTable.set(name, symbol);
|
2015
2031
|
});
|
2016
2032
|
}
|
2017
|
-
moduleType.fields.forEach((symbol, name) => {
|
2033
|
+
moduleType.priv.fields.forEach((symbol, name) => {
|
2018
2034
|
symbolTable.set(name, symbol);
|
2019
2035
|
});
|
2020
2036
|
}
|
@@ -2099,8 +2115,9 @@ function isPartlyUnknown(type, recursionCount = 0) {
|
|
2099
2115
|
}
|
2100
2116
|
// If this is a generic type alias, see if any of its type arguments
|
2101
2117
|
// are either unspecified or are partially known.
|
2102
|
-
|
2103
|
-
|
2118
|
+
const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
2119
|
+
if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments) {
|
2120
|
+
if (aliasInfo.typeArguments.some((typeArg) => isPartlyUnknown(typeArg, recursionCount))) {
|
2104
2121
|
return true;
|
2105
2122
|
}
|
2106
2123
|
}
|
@@ -2113,11 +2130,11 @@ function isPartlyUnknown(type, recursionCount = 0) {
|
|
2113
2130
|
// If this is a reference to the class itself, as opposed to a reference
|
2114
2131
|
// to a type that represents the class and its subclasses, don't flag
|
2115
2132
|
// the type as partially unknown.
|
2116
|
-
if (!type.includeSubclasses) {
|
2133
|
+
if (!type.priv.includeSubclasses) {
|
2117
2134
|
return false;
|
2118
2135
|
}
|
2119
2136
|
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;
|
2137
|
+
const typeArgs = ((_b = type.priv.tupleTypeArguments) === null || _b === void 0 ? void 0 : _b.map((t) => t.type)) || type.priv.typeArguments;
|
2121
2138
|
if (typeArgs) {
|
2122
2139
|
for (const argType of typeArgs) {
|
2123
2140
|
if (isPartlyUnknown(argType, recursionCount)) {
|
@@ -2135,18 +2152,18 @@ function isPartlyUnknown(type, recursionCount = 0) {
|
|
2135
2152
|
});
|
2136
2153
|
}
|
2137
2154
|
if ((0, types_1.isFunction)(type)) {
|
2138
|
-
for (let i = 0; i < type.
|
2155
|
+
for (let i = 0; i < type.shared.parameters.length; i++) {
|
2139
2156
|
// Ignore parameters such as "*" that have no name.
|
2140
|
-
if (type.
|
2157
|
+
if (type.shared.parameters[i].name) {
|
2141
2158
|
const paramType = types_1.FunctionType.getEffectiveParameterType(type, i);
|
2142
2159
|
if (isPartlyUnknown(paramType, recursionCount)) {
|
2143
2160
|
return true;
|
2144
2161
|
}
|
2145
2162
|
}
|
2146
2163
|
}
|
2147
|
-
if (type.
|
2164
|
+
if (type.shared.declaredReturnType &&
|
2148
2165
|
!types_1.FunctionType.isParamSpecValue(type) &&
|
2149
|
-
isPartlyUnknown(type.
|
2166
|
+
isPartlyUnknown(type.shared.declaredReturnType, recursionCount)) {
|
2150
2167
|
return true;
|
2151
2168
|
}
|
2152
2169
|
return false;
|
@@ -2158,10 +2175,12 @@ exports.isPartlyUnknown = isPartlyUnknown;
|
|
2158
2175
|
// that is a union, it "explodes" the class into a union of classes with
|
2159
2176
|
// each element of the union - e.g. Foo[A | B] becomes Foo[A] | Foo[B].
|
2160
2177
|
function explodeGenericClass(classType) {
|
2161
|
-
if (!classType.
|
2178
|
+
if (!classType.priv.typeArguments ||
|
2179
|
+
classType.priv.typeArguments.length !== 1 ||
|
2180
|
+
!(0, types_1.isUnion)(classType.priv.typeArguments[0])) {
|
2162
2181
|
return classType;
|
2163
2182
|
}
|
2164
|
-
return (0, types_1.combineTypes)(classType.typeArguments[0].subtypes.map((subtype) => {
|
2183
|
+
return (0, types_1.combineTypes)(classType.priv.typeArguments[0].priv.subtypes.map((subtype) => {
|
2165
2184
|
return types_1.ClassType.cloneForSpecialization(classType, [subtype], /* isTypeArgumentExplicit */ true);
|
2166
2185
|
}));
|
2167
2186
|
}
|
@@ -2183,12 +2202,12 @@ function combineSameSizedTuples(type, tupleType) {
|
|
2183
2202
|
if (!tupleClass) {
|
2184
2203
|
// Look in the mro list to see if this subtype derives from a
|
2185
2204
|
// tuple with a known size. This includes named tuples.
|
2186
|
-
tupleClass = subtype.
|
2205
|
+
tupleClass = subtype.shared.mro.find((mroClass) => (0, types_1.isClass)(mroClass) && isTupleClass(mroClass) && !isUnboundedTupleClass(mroClass));
|
2187
2206
|
}
|
2188
|
-
if (tupleClass && (0, types_1.isClass)(tupleClass) && tupleClass.tupleTypeArguments) {
|
2207
|
+
if (tupleClass && (0, types_1.isClass)(tupleClass) && tupleClass.priv.tupleTypeArguments) {
|
2189
2208
|
if (tupleEntries) {
|
2190
|
-
if (tupleEntries.length === tupleClass.tupleTypeArguments.length) {
|
2191
|
-
tupleClass.tupleTypeArguments.forEach((entry, index) => {
|
2209
|
+
if (tupleEntries.length === tupleClass.priv.tupleTypeArguments.length) {
|
2210
|
+
tupleClass.priv.tupleTypeArguments.forEach((entry, index) => {
|
2192
2211
|
tupleEntries[index].push(entry.type);
|
2193
2212
|
});
|
2194
2213
|
}
|
@@ -2197,7 +2216,7 @@ function combineSameSizedTuples(type, tupleType) {
|
|
2197
2216
|
}
|
2198
2217
|
}
|
2199
2218
|
else {
|
2200
|
-
tupleEntries = tupleClass.tupleTypeArguments.map((entry) => [entry.type]);
|
2219
|
+
tupleEntries = tupleClass.priv.tupleTypeArguments.map((entry) => [entry.type]);
|
2201
2220
|
}
|
2202
2221
|
}
|
2203
2222
|
else {
|
@@ -2230,14 +2249,14 @@ function specializeTupleClass(classType, typeArgs, isTypeArgumentExplicit = true
|
|
2230
2249
|
const clonedClassType = types_1.ClassType.cloneForSpecialization(classType, [combinedTupleType], isTypeArgumentExplicit,
|
2231
2250
|
/* includeSubclasses */ undefined, typeArgs);
|
2232
2251
|
if (isUnpackedTuple) {
|
2233
|
-
clonedClassType.isUnpacked = true;
|
2252
|
+
clonedClassType.priv.isUnpacked = true;
|
2234
2253
|
}
|
2235
2254
|
return clonedClassType;
|
2236
2255
|
}
|
2237
2256
|
exports.specializeTupleClass = specializeTupleClass;
|
2238
2257
|
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));
|
2258
|
+
if ((0, types_1.isClassInstance)(type) && isTupleClass(type) && type.priv.tupleTypeArguments && type.priv.isUnpacked) {
|
2259
|
+
return (0, types_1.combineTypes)(type.priv.tupleTypeArguments.map((t) => t.type));
|
2241
2260
|
}
|
2242
2261
|
return type;
|
2243
2262
|
}
|
@@ -2247,29 +2266,29 @@ function getGeneratorTypeArgs(returnType) {
|
|
2247
2266
|
var _a;
|
2248
2267
|
if ((0, types_1.isClassInstance)(returnType)) {
|
2249
2268
|
if (types_1.ClassType.isBuiltIn(returnType, ['Generator', 'AsyncGenerator'])) {
|
2250
|
-
return returnType.typeArguments;
|
2269
|
+
return returnType.priv.typeArguments;
|
2251
2270
|
}
|
2252
2271
|
else if (types_1.ClassType.isBuiltIn(returnType, 'AwaitableGenerator')) {
|
2253
2272
|
// AwaitableGenerator has four type arguments, and the first 3
|
2254
2273
|
// correspond to the generator.
|
2255
|
-
return (_a = returnType.typeArguments) === null || _a === void 0 ? void 0 : _a.slice(0, 3);
|
2274
|
+
return (_a = returnType.priv.typeArguments) === null || _a === void 0 ? void 0 : _a.slice(0, 3);
|
2256
2275
|
}
|
2257
2276
|
}
|
2258
2277
|
return undefined;
|
2259
2278
|
}
|
2260
2279
|
exports.getGeneratorTypeArgs = getGeneratorTypeArgs;
|
2261
2280
|
function requiresTypeArguments(classType) {
|
2262
|
-
if (classType.
|
2263
|
-
const firstTypeParam = classType.
|
2281
|
+
if (classType.shared.typeParameters.length > 0) {
|
2282
|
+
const firstTypeParam = classType.shared.typeParameters[0];
|
2264
2283
|
// If there are type parameters, type arguments are needed.
|
2265
2284
|
// The exception is if type parameters have been synthesized
|
2266
2285
|
// for classes that have untyped constructors.
|
2267
|
-
if (firstTypeParam.
|
2286
|
+
if (firstTypeParam.shared.isSynthesized) {
|
2268
2287
|
return false;
|
2269
2288
|
}
|
2270
2289
|
// If the first type parameter has a default type, then no
|
2271
2290
|
// type arguments are needed.
|
2272
|
-
if (firstTypeParam.
|
2291
|
+
if (firstTypeParam.shared.isDefaultExplicit) {
|
2273
2292
|
return false;
|
2274
2293
|
}
|
2275
2294
|
return true;
|
@@ -2289,7 +2308,7 @@ function requiresTypeArguments(classType) {
|
|
2289
2308
|
'TypeGuard',
|
2290
2309
|
'TypeIs',
|
2291
2310
|
];
|
2292
|
-
if (specialClasses.some((t) => t === (classType.aliasName || classType.
|
2311
|
+
if (specialClasses.some((t) => t === (classType.priv.aliasName || classType.shared.name))) {
|
2293
2312
|
return true;
|
2294
2313
|
}
|
2295
2314
|
}
|
@@ -2318,9 +2337,9 @@ function requiresSpecialization(type, options, recursionCount = 0) {
|
|
2318
2337
|
}
|
2319
2338
|
exports.requiresSpecialization = requiresSpecialization;
|
2320
2339
|
function _requiresSpecialization(type, options, recursionCount = 0) {
|
2321
|
-
var _a;
|
2340
|
+
var _a, _b;
|
2322
2341
|
// If the type is conditioned on a TypeVar, it may need to be specialized.
|
2323
|
-
if (type.condition) {
|
2342
|
+
if ((_a = type.props) === null || _a === void 0 ? void 0 : _a.condition) {
|
2324
2343
|
return true;
|
2325
2344
|
}
|
2326
2345
|
switch (type.category) {
|
@@ -2328,53 +2347,54 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
|
|
2328
2347
|
if (types_1.ClassType.isPseudoGenericClass(type) && (options === null || options === void 0 ? void 0 : options.ignorePseudoGeneric)) {
|
2329
2348
|
return false;
|
2330
2349
|
}
|
2331
|
-
if (!type.isTypeArgumentExplicit && (options === null || options === void 0 ? void 0 : options.ignoreImplicitTypeArgs)) {
|
2350
|
+
if (!type.priv.isTypeArgumentExplicit && (options === null || options === void 0 ? void 0 : options.ignoreImplicitTypeArgs)) {
|
2332
2351
|
return false;
|
2333
2352
|
}
|
2334
|
-
if (type.typeArguments) {
|
2335
|
-
return type.typeArguments.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
|
2353
|
+
if (type.priv.typeArguments) {
|
2354
|
+
return type.priv.typeArguments.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
|
2336
2355
|
}
|
2337
2356
|
return types_1.ClassType.getTypeParameters(type).length > 0;
|
2338
2357
|
}
|
2339
2358
|
case 4 /* TypeCategory.Function */: {
|
2340
|
-
for (let i = 0; i < type.
|
2359
|
+
for (let i = 0; i < type.shared.parameters.length; i++) {
|
2341
2360
|
if (requiresSpecialization(types_1.FunctionType.getEffectiveParameterType(type, i), options, recursionCount)) {
|
2342
2361
|
return true;
|
2343
2362
|
}
|
2344
2363
|
}
|
2345
|
-
const declaredReturnType = type.specializedTypes && type.specializedTypes.returnType
|
2346
|
-
? type.specializedTypes.returnType
|
2347
|
-
: type.
|
2364
|
+
const declaredReturnType = type.priv.specializedTypes && type.priv.specializedTypes.returnType
|
2365
|
+
? type.priv.specializedTypes.returnType
|
2366
|
+
: type.shared.declaredReturnType;
|
2348
2367
|
if (declaredReturnType) {
|
2349
2368
|
if (requiresSpecialization(declaredReturnType, options, recursionCount)) {
|
2350
2369
|
return true;
|
2351
2370
|
}
|
2352
2371
|
}
|
2353
|
-
else if (type.inferredReturnType) {
|
2354
|
-
if (requiresSpecialization(type.inferredReturnType, options, recursionCount)) {
|
2372
|
+
else if (type.priv.inferredReturnType) {
|
2373
|
+
if (requiresSpecialization(type.priv.inferredReturnType, options, recursionCount)) {
|
2355
2374
|
return true;
|
2356
2375
|
}
|
2357
2376
|
}
|
2358
2377
|
return false;
|
2359
2378
|
}
|
2360
2379
|
case 5 /* TypeCategory.OverloadedFunction */: {
|
2361
|
-
return type.overloads.some((overload) => requiresSpecialization(overload, options, recursionCount));
|
2380
|
+
return type.priv.overloads.some((overload) => requiresSpecialization(overload, options, recursionCount));
|
2362
2381
|
}
|
2363
2382
|
case 8 /* TypeCategory.Union */: {
|
2364
|
-
return type.subtypes.some((subtype) => requiresSpecialization(subtype, options, recursionCount));
|
2383
|
+
return type.priv.subtypes.some((subtype) => requiresSpecialization(subtype, options, recursionCount));
|
2365
2384
|
}
|
2366
2385
|
case 9 /* TypeCategory.TypeVar */: {
|
2367
2386
|
// Most TypeVar types need to be specialized.
|
2368
|
-
if (!type.
|
2369
|
-
if (type.
|
2387
|
+
if (!type.shared.recursiveAlias) {
|
2388
|
+
if (type.shared.isSynthesizedSelf && (options === null || options === void 0 ? void 0 : options.ignoreSelf)) {
|
2370
2389
|
return false;
|
2371
2390
|
}
|
2372
2391
|
return true;
|
2373
2392
|
}
|
2374
2393
|
// If this is a recursive type alias, it may need to be specialized
|
2375
2394
|
// if it has generic type arguments.
|
2376
|
-
|
2377
|
-
|
2395
|
+
const aliasInfo = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo;
|
2396
|
+
if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments) {
|
2397
|
+
return aliasInfo.typeArguments.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
|
2378
2398
|
}
|
2379
2399
|
}
|
2380
2400
|
}
|
@@ -2399,23 +2419,23 @@ function isVarianceOfTypeArgumentCompatible(type, typeParamVariance) {
|
|
2399
2419
|
if (typeParamVariance === 1 /* Variance.Unknown */ || typeParamVariance === 0 /* Variance.Auto */) {
|
2400
2420
|
return true;
|
2401
2421
|
}
|
2402
|
-
if ((0, types_1.isTypeVar)(type) && !type.
|
2403
|
-
const typeArgVariance = type.
|
2422
|
+
if ((0, types_1.isTypeVar)(type) && !type.shared.isParamSpec && !type.shared.isVariadic) {
|
2423
|
+
const typeArgVariance = type.shared.declaredVariance;
|
2404
2424
|
if (typeArgVariance === 4 /* Variance.Contravariant */ || typeArgVariance === 3 /* Variance.Covariant */) {
|
2405
2425
|
return typeArgVariance === typeParamVariance;
|
2406
2426
|
}
|
2407
2427
|
}
|
2408
2428
|
else if ((0, types_1.isClassInstance)(type)) {
|
2409
|
-
if (type.
|
2410
|
-
return type.
|
2429
|
+
if (type.shared.typeParameters && type.shared.typeParameters.length > 0) {
|
2430
|
+
return type.shared.typeParameters.every((typeParam, index) => {
|
2411
2431
|
let typeArgType;
|
2412
|
-
if (typeParam.
|
2432
|
+
if (typeParam.shared.isParamSpec || typeParam.shared.isVariadic) {
|
2413
2433
|
return true;
|
2414
2434
|
}
|
2415
|
-
if (type.typeArguments && index < type.typeArguments.length) {
|
2416
|
-
typeArgType = type.typeArguments[index];
|
2435
|
+
if (type.priv.typeArguments && index < type.priv.typeArguments.length) {
|
2436
|
+
typeArgType = type.priv.typeArguments[index];
|
2417
2437
|
}
|
2418
|
-
const declaredVariance = typeParam.
|
2438
|
+
const declaredVariance = typeParam.shared.declaredVariance;
|
2419
2439
|
if (declaredVariance === 0 /* Variance.Auto */) {
|
2420
2440
|
return true;
|
2421
2441
|
}
|
@@ -2449,8 +2469,8 @@ exports.isVarianceOfTypeArgumentCompatible = isVarianceOfTypeArgumentCompatible;
|
|
2449
2469
|
function computeMroLinearization(classType) {
|
2450
2470
|
let isMroFound = true;
|
2451
2471
|
// Clear out any existing MRO information.
|
2452
|
-
classType.
|
2453
|
-
const filteredBaseClasses = classType.
|
2472
|
+
classType.shared.mro = [];
|
2473
|
+
const filteredBaseClasses = classType.shared.baseClasses.filter((baseClass, index) => {
|
2454
2474
|
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
2455
2475
|
// Generic has some special-case logic (see description of __mro_entries__
|
2456
2476
|
// in PEP 560) that we need to account for here.
|
@@ -2463,11 +2483,11 @@ function computeMroLinearization(classType) {
|
|
2463
2483
|
// If the class contains any specialized generic classes after
|
2464
2484
|
// the Generic base, the Generic base is ignored for purposes
|
2465
2485
|
// of computing the MRO.
|
2466
|
-
if (classType.
|
2486
|
+
if (classType.shared.baseClasses.some((innerBaseClass, innerIndex) => {
|
2467
2487
|
return (innerIndex > index &&
|
2468
2488
|
(0, types_1.isInstantiableClass)(innerBaseClass) &&
|
2469
|
-
innerBaseClass.typeArguments &&
|
2470
|
-
innerBaseClass.isTypeArgumentExplicit);
|
2489
|
+
innerBaseClass.priv.typeArguments &&
|
2490
|
+
innerBaseClass.priv.isTypeArgumentExplicit);
|
2471
2491
|
})) {
|
2472
2492
|
return false;
|
2473
2493
|
}
|
@@ -2480,7 +2500,7 @@ function computeMroLinearization(classType) {
|
|
2480
2500
|
filteredBaseClasses.forEach((baseClass) => {
|
2481
2501
|
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
2482
2502
|
const typeVarContext = buildTypeVarContextFromSpecializedClass(baseClass);
|
2483
|
-
classListsToMerge.push(baseClass.
|
2503
|
+
classListsToMerge.push(baseClass.shared.mro.map((mroClass) => {
|
2484
2504
|
return applySolvedTypeVars(mroClass, typeVarContext);
|
2485
2505
|
}));
|
2486
2506
|
}
|
@@ -2498,7 +2518,7 @@ function computeMroLinearization(classType) {
|
|
2498
2518
|
if (!(0, types_1.isClass)(specializedClassType) && !(0, types_1.isAnyOrUnknown)(specializedClassType)) {
|
2499
2519
|
specializedClassType = types_1.UnknownType.create();
|
2500
2520
|
}
|
2501
|
-
classType.
|
2521
|
+
classType.shared.mro.push(specializedClassType);
|
2502
2522
|
// Helper function that returns true if the specified searchClass
|
2503
2523
|
// is found in the "tail" (i.e. in elements 1 through n) of any
|
2504
2524
|
// of the class lists.
|
@@ -2532,13 +2552,13 @@ function computeMroLinearization(classType) {
|
|
2532
2552
|
if (!(0, types_1.isClass)(head) && !(0, types_1.isAnyOrUnknown)(head)) {
|
2533
2553
|
head = types_1.UnknownType.create();
|
2534
2554
|
}
|
2535
|
-
classType.
|
2555
|
+
classType.shared.mro.push(head);
|
2536
2556
|
classList.shift();
|
2537
2557
|
break;
|
2538
2558
|
}
|
2539
2559
|
if (!isInTail(classList[0], classListsToMerge)) {
|
2540
2560
|
foundValidHead = true;
|
2541
|
-
classType.
|
2561
|
+
classType.shared.mro.push(classList[0]);
|
2542
2562
|
filterClass(classList[0], classListsToMerge);
|
2543
2563
|
break;
|
2544
2564
|
}
|
@@ -2560,11 +2580,11 @@ function computeMroLinearization(classType) {
|
|
2560
2580
|
if (!(0, types_1.isClass)(head) && !(0, types_1.isAnyOrUnknown)(head)) {
|
2561
2581
|
head = types_1.UnknownType.create();
|
2562
2582
|
}
|
2563
|
-
classType.
|
2583
|
+
classType.shared.mro.push(head);
|
2564
2584
|
nonEmptyList.shift();
|
2565
2585
|
}
|
2566
2586
|
else {
|
2567
|
-
classType.
|
2587
|
+
classType.shared.mro.push(nonEmptyList[0]);
|
2568
2588
|
filterClass(nonEmptyList[0], classListsToMerge);
|
2569
2589
|
}
|
2570
2590
|
}
|
@@ -2581,6 +2601,14 @@ function getDeclaringModulesForType(type) {
|
|
2581
2601
|
return moduleList;
|
2582
2602
|
}
|
2583
2603
|
exports.getDeclaringModulesForType = getDeclaringModulesForType;
|
2604
|
+
function convertArgumentNodeToFunctionArgument(node) {
|
2605
|
+
return {
|
2606
|
+
argumentCategory: node.d.argCategory,
|
2607
|
+
name: node.d.name,
|
2608
|
+
valueExpression: node.d.valueExpr,
|
2609
|
+
};
|
2610
|
+
}
|
2611
|
+
exports.convertArgumentNodeToFunctionArgument = convertArgumentNodeToFunctionArgument;
|
2584
2612
|
function addDeclaringModuleNamesForType(type, moduleList, recursionCount = 0) {
|
2585
2613
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
2586
2614
|
return;
|
@@ -2593,15 +2621,15 @@ function addDeclaringModuleNamesForType(type, moduleList, recursionCount = 0) {
|
|
2593
2621
|
};
|
2594
2622
|
switch (type.category) {
|
2595
2623
|
case 6 /* TypeCategory.Class */: {
|
2596
|
-
addIfUnique(type.
|
2624
|
+
addIfUnique(type.shared.moduleName);
|
2597
2625
|
break;
|
2598
2626
|
}
|
2599
2627
|
case 4 /* TypeCategory.Function */: {
|
2600
|
-
addIfUnique(type.
|
2628
|
+
addIfUnique(type.shared.moduleName);
|
2601
2629
|
break;
|
2602
2630
|
}
|
2603
2631
|
case 5 /* TypeCategory.OverloadedFunction */: {
|
2604
|
-
type.overloads.forEach((overload) => {
|
2632
|
+
type.priv.overloads.forEach((overload) => {
|
2605
2633
|
addDeclaringModuleNamesForType(overload, moduleList, recursionCount);
|
2606
2634
|
});
|
2607
2635
|
break;
|
@@ -2613,7 +2641,7 @@ function addDeclaringModuleNamesForType(type, moduleList, recursionCount = 0) {
|
|
2613
2641
|
break;
|
2614
2642
|
}
|
2615
2643
|
case 7 /* TypeCategory.Module */: {
|
2616
|
-
addIfUnique(type.moduleName);
|
2644
|
+
addIfUnique(type.priv.moduleName);
|
2617
2645
|
break;
|
2618
2646
|
}
|
2619
2647
|
}
|
@@ -2625,27 +2653,20 @@ function convertTypeToParamSpecValue(type) {
|
|
2625
2653
|
if ((0, types_1.isParamSpec)(type)) {
|
2626
2654
|
const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
2627
2655
|
types_1.FunctionType.addParamSpecVariadics(newFunction, type);
|
2628
|
-
newFunction.
|
2656
|
+
newFunction.shared.typeVarScopeId = getTypeVarScopeId(type);
|
2629
2657
|
return newFunction;
|
2630
2658
|
}
|
2631
2659
|
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
|
-
});
|
2660
|
+
const newFunction = types_1.FunctionType.createInstance('', '', '', type.shared.flags | 65536 /* FunctionTypeFlags.ParamSpecValue */, type.shared.docString);
|
2661
|
+
newFunction.shared.deprecatedMessage = type.shared.deprecatedMessage;
|
2662
|
+
type.shared.parameters.forEach((param, index) => {
|
2663
|
+
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
2664
|
});
|
2644
|
-
if (type.
|
2645
|
-
newFunction.
|
2646
|
-
newFunction.
|
2665
|
+
if (type.priv.higherOrderTypeVarScopeIds) {
|
2666
|
+
newFunction.priv.higherOrderTypeVarScopeIds = [...type.priv.higherOrderTypeVarScopeIds];
|
2667
|
+
newFunction.shared.typeVarScopeId = newFunction.priv.higherOrderTypeVarScopeIds.pop();
|
2647
2668
|
}
|
2648
|
-
newFunction.
|
2669
|
+
newFunction.priv.constructorTypeVarScopeId = type.priv.constructorTypeVarScopeId;
|
2649
2670
|
return newFunction;
|
2650
2671
|
}
|
2651
2672
|
return getUnknownTypeForParamSpec();
|
@@ -2656,11 +2677,11 @@ exports.convertTypeToParamSpecValue = convertTypeToParamSpecValue;
|
|
2656
2677
|
function convertParamSpecValueToType(type) {
|
2657
2678
|
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
|
2658
2679
|
const withoutParamSpec = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(type);
|
2659
|
-
let hasParameters = withoutParamSpec.
|
2660
|
-
if (withoutParamSpec.
|
2680
|
+
let hasParameters = withoutParamSpec.shared.parameters.length > 0;
|
2681
|
+
if (withoutParamSpec.shared.parameters.length === 1) {
|
2661
2682
|
// If the ParamSpec has a position-only separator as its only parameter,
|
2662
2683
|
// treat it as though there are no parameters.
|
2663
|
-
const onlyParam = withoutParamSpec.
|
2684
|
+
const onlyParam = withoutParamSpec.shared.parameters[0];
|
2664
2685
|
if ((0, types_1.isPositionOnlySeparator)(onlyParam)) {
|
2665
2686
|
hasParameters = false;
|
2666
2687
|
}
|
@@ -2670,27 +2691,19 @@ function convertParamSpecValueToType(type) {
|
|
2670
2691
|
return paramSpec;
|
2671
2692
|
}
|
2672
2693
|
// 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
|
-
});
|
2694
|
+
const functionType = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | withoutParamSpec.shared.flags);
|
2695
|
+
types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.shared.typeVarScopeId);
|
2696
|
+
types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.priv.higherOrderTypeVarScopeIds);
|
2697
|
+
functionType.priv.constructorTypeVarScopeId = withoutParamSpec.priv.constructorTypeVarScopeId;
|
2698
|
+
withoutParamSpec.shared.parameters.forEach((entry, index) => {
|
2699
|
+
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
2700
|
});
|
2688
2701
|
if (paramSpec) {
|
2689
2702
|
types_1.FunctionType.addParamSpecVariadics(functionType, paramSpec);
|
2690
2703
|
}
|
2691
|
-
functionType.
|
2692
|
-
functionType.
|
2693
|
-
functionType.
|
2704
|
+
functionType.shared.docString = withoutParamSpec.shared.docString;
|
2705
|
+
functionType.shared.deprecatedMessage = withoutParamSpec.shared.deprecatedMessage;
|
2706
|
+
functionType.shared.methodClass = withoutParamSpec.shared.methodClass;
|
2694
2707
|
return functionType;
|
2695
2708
|
}
|
2696
2709
|
exports.convertParamSpecValueToType = convertParamSpecValueToType;
|
@@ -2703,7 +2716,7 @@ class TypeVarTransformer {
|
|
2703
2716
|
this._pendingFunctionTransformations = [];
|
2704
2717
|
}
|
2705
2718
|
apply(type, recursionCount) {
|
2706
|
-
var _a, _b;
|
2719
|
+
var _a, _b, _c;
|
2707
2720
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
2708
2721
|
return type;
|
2709
2722
|
}
|
@@ -2711,7 +2724,7 @@ class TypeVarTransformer {
|
|
2711
2724
|
type = this.transformGenericTypeAlias(type, recursionCount);
|
2712
2725
|
// If the type is conditioned on a type variable, see if the condition
|
2713
2726
|
// still applies.
|
2714
|
-
if (type.condition) {
|
2727
|
+
if ((_a = type.props) === null || _a === void 0 ? void 0 : _a.condition) {
|
2715
2728
|
type = this.transformConditionalType(type, recursionCount);
|
2716
2729
|
}
|
2717
2730
|
// Shortcut the operation if possible.
|
@@ -2728,12 +2741,13 @@ class TypeVarTransformer {
|
|
2728
2741
|
// Handle recursive type aliases specially. In particular,
|
2729
2742
|
// we need to specialize type arguments for generic recursive
|
2730
2743
|
// type aliases.
|
2731
|
-
|
2732
|
-
|
2744
|
+
const aliasInfo = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo;
|
2745
|
+
if (type.shared.recursiveAlias) {
|
2746
|
+
if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments)) {
|
2733
2747
|
return type;
|
2734
2748
|
}
|
2735
2749
|
let requiresUpdate = false;
|
2736
|
-
const typeArgs =
|
2750
|
+
const typeArgs = aliasInfo.typeArguments.map((typeArg) => {
|
2737
2751
|
const replacementType = this.apply(typeArg, recursionCount);
|
2738
2752
|
if (replacementType !== typeArg) {
|
2739
2753
|
requiresUpdate = true;
|
@@ -2741,7 +2755,7 @@ class TypeVarTransformer {
|
|
2741
2755
|
return replacementType;
|
2742
2756
|
});
|
2743
2757
|
if (requiresUpdate) {
|
2744
|
-
return types_1.TypeBase.cloneForTypeAlias(type,
|
2758
|
+
return types_1.TypeBase.cloneForTypeAlias(type, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParameters, typeArgs);
|
2745
2759
|
}
|
2746
2760
|
return type;
|
2747
2761
|
}
|
@@ -2749,18 +2763,18 @@ class TypeVarTransformer {
|
|
2749
2763
|
// Recursively transform the results, but ensure that we don't replace any
|
2750
2764
|
// type variables in the same scope recursively by setting it the scope in the
|
2751
2765
|
// _pendingTypeVarTransformations set.
|
2752
|
-
if (!this._isTypeVarScopePending(type.scopeId)) {
|
2753
|
-
if (type.
|
2766
|
+
if (!this._isTypeVarScopePending(type.priv.scopeId)) {
|
2767
|
+
if (type.shared.isParamSpec) {
|
2754
2768
|
let paramSpecWithoutAccess = type;
|
2755
|
-
if (type.paramSpecAccess) {
|
2769
|
+
if (type.priv.paramSpecAccess) {
|
2756
2770
|
paramSpecWithoutAccess = types_1.TypeVarType.cloneForParamSpecAccess(type, /* access */ undefined);
|
2757
2771
|
}
|
2758
2772
|
const paramSpecValue = this.transformParamSpec(paramSpecWithoutAccess, recursionCount);
|
2759
2773
|
if (paramSpecValue) {
|
2760
2774
|
const paramSpecType = convertParamSpecValueToType(paramSpecValue);
|
2761
|
-
if (type.paramSpecAccess) {
|
2775
|
+
if (type.priv.paramSpecAccess) {
|
2762
2776
|
if ((0, types_1.isParamSpec)(paramSpecType)) {
|
2763
|
-
replacementType = types_1.TypeVarType.cloneForParamSpecAccess(paramSpecType, type.paramSpecAccess);
|
2777
|
+
replacementType = types_1.TypeVarType.cloneForParamSpecAccess(paramSpecType, type.priv.paramSpecAccess);
|
2764
2778
|
}
|
2765
2779
|
else {
|
2766
2780
|
replacementType = types_1.UnknownType.create();
|
@@ -2772,19 +2786,19 @@ class TypeVarTransformer {
|
|
2772
2786
|
}
|
2773
2787
|
}
|
2774
2788
|
else {
|
2775
|
-
replacementType = (
|
2789
|
+
replacementType = (_c = this.transformTypeVar(type, recursionCount)) !== null && _c !== void 0 ? _c : type;
|
2776
2790
|
if (!this._isTransformingTypeArg) {
|
2777
|
-
if (type.scopeId) {
|
2778
|
-
this._pendingTypeVarTransformations.add(type.scopeId);
|
2791
|
+
if (type.priv.scopeId) {
|
2792
|
+
this._pendingTypeVarTransformations.add(type.priv.scopeId);
|
2779
2793
|
}
|
2780
2794
|
replacementType = this.apply(replacementType, recursionCount);
|
2781
|
-
if (type.scopeId) {
|
2782
|
-
this._pendingTypeVarTransformations.delete(type.scopeId);
|
2795
|
+
if (type.priv.scopeId) {
|
2796
|
+
this._pendingTypeVarTransformations.delete(type.priv.scopeId);
|
2783
2797
|
}
|
2784
2798
|
}
|
2785
2799
|
// If we're transforming a variadic type variable that was in a union,
|
2786
2800
|
// expand the union types.
|
2787
|
-
if ((0, types_1.isVariadicTypeVar)(type) && type.isVariadicInUnion) {
|
2801
|
+
if ((0, types_1.isVariadicTypeVar)(type) && type.priv.isVariadicInUnion) {
|
2788
2802
|
replacementType = _expandVariadicUnpackedUnion(replacementType);
|
2789
2803
|
}
|
2790
2804
|
}
|
@@ -2832,13 +2846,13 @@ class TypeVarTransformer {
|
|
2832
2846
|
let requiresUpdate = false;
|
2833
2847
|
// Specialize each of the functions in the overload.
|
2834
2848
|
const newOverloads = [];
|
2835
|
-
type.overloads.forEach((entry) => {
|
2849
|
+
type.priv.overloads.forEach((entry) => {
|
2836
2850
|
const replacementType = this.transformTypeVarsInFunctionType(entry, recursionCount);
|
2837
2851
|
if ((0, types_1.isFunction)(replacementType)) {
|
2838
2852
|
newOverloads.push(replacementType);
|
2839
2853
|
}
|
2840
2854
|
else {
|
2841
|
-
(0, collectionUtils_1.appendArray)(newOverloads, replacementType.overloads);
|
2855
|
+
(0, collectionUtils_1.appendArray)(newOverloads, replacementType.priv.overloads);
|
2842
2856
|
}
|
2843
2857
|
if (replacementType !== entry) {
|
2844
2858
|
requiresUpdate = true;
|
@@ -2868,11 +2882,13 @@ class TypeVarTransformer {
|
|
2868
2882
|
return callback();
|
2869
2883
|
}
|
2870
2884
|
transformGenericTypeAlias(type, recursionCount) {
|
2871
|
-
|
2885
|
+
var _a;
|
2886
|
+
const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
2887
|
+
if (!aliasInfo || !aliasInfo.typeParameters || !aliasInfo.typeArguments) {
|
2872
2888
|
return type;
|
2873
2889
|
}
|
2874
2890
|
let requiresUpdate = false;
|
2875
|
-
const newTypeArgs =
|
2891
|
+
const newTypeArgs = aliasInfo.typeArguments.map((typeArg) => {
|
2876
2892
|
const updatedType = this.apply(typeArg, recursionCount);
|
2877
2893
|
if (type !== updatedType) {
|
2878
2894
|
requiresUpdate = true;
|
@@ -2880,7 +2896,7 @@ class TypeVarTransformer {
|
|
2880
2896
|
return updatedType;
|
2881
2897
|
});
|
2882
2898
|
return requiresUpdate
|
2883
|
-
? types_1.TypeBase.cloneForTypeAlias(type,
|
2899
|
+
? types_1.TypeBase.cloneForTypeAlias(type, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParameters, newTypeArgs)
|
2884
2900
|
: type;
|
2885
2901
|
}
|
2886
2902
|
transformConditionalType(type, recursionCount) {
|
@@ -2913,9 +2929,9 @@ class TypeVarTransformer {
|
|
2913
2929
|
// If type args were previously provided, specialize them.
|
2914
2930
|
// Handle tuples specially.
|
2915
2931
|
if (types_1.ClassType.isTupleClass(classType)) {
|
2916
|
-
if (classType.tupleTypeArguments) {
|
2932
|
+
if (classType.priv.tupleTypeArguments) {
|
2917
2933
|
newTupleTypeArgs = [];
|
2918
|
-
classType.tupleTypeArguments.forEach((oldTypeArgType) => {
|
2934
|
+
classType.priv.tupleTypeArguments.forEach((oldTypeArgType) => {
|
2919
2935
|
const newTypeArgType = this.apply(oldTypeArgType.type, recursionCount);
|
2920
2936
|
if (newTypeArgType !== oldTypeArgType.type) {
|
2921
2937
|
specializationNeeded = true;
|
@@ -2923,8 +2939,8 @@ class TypeVarTransformer {
|
|
2923
2939
|
if ((0, types_1.isUnpackedVariadicTypeVar)(oldTypeArgType.type) &&
|
2924
2940
|
(0, types_1.isClassInstance)(newTypeArgType) &&
|
2925
2941
|
isTupleClass(newTypeArgType) &&
|
2926
|
-
newTypeArgType.tupleTypeArguments) {
|
2927
|
-
(0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.tupleTypeArguments);
|
2942
|
+
newTypeArgType.priv.tupleTypeArguments) {
|
2943
|
+
(0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.priv.tupleTypeArguments);
|
2928
2944
|
}
|
2929
2945
|
else {
|
2930
2946
|
// Handle the special case where tuple[T, ...] is being specialized
|
@@ -2932,7 +2948,7 @@ class TypeVarTransformer {
|
|
2932
2948
|
const isEmptyTuple = oldTypeArgType.isUnbounded &&
|
2933
2949
|
(0, types_1.isTypeVar)(oldTypeArgType.type) &&
|
2934
2950
|
(0, types_1.isNever)(newTypeArgType) &&
|
2935
|
-
classType.tupleTypeArguments.length === 1;
|
2951
|
+
classType.priv.tupleTypeArguments.length === 1;
|
2936
2952
|
if (!isEmptyTuple) {
|
2937
2953
|
newTupleTypeArgs.push({
|
2938
2954
|
type: newTypeArgType,
|
@@ -2969,9 +2985,9 @@ class TypeVarTransformer {
|
|
2969
2985
|
}
|
2970
2986
|
}
|
2971
2987
|
if (!newTypeArgs) {
|
2972
|
-
if (classType.typeArguments) {
|
2973
|
-
newTypeArgs = classType.typeArguments.map((oldTypeArgType) => {
|
2974
|
-
if ((0, types_1.isTypeVar)(oldTypeArgType) && oldTypeArgType.
|
2988
|
+
if (classType.priv.typeArguments) {
|
2989
|
+
newTypeArgs = classType.priv.typeArguments.map((oldTypeArgType) => {
|
2990
|
+
if ((0, types_1.isTypeVar)(oldTypeArgType) && oldTypeArgType.shared.isParamSpec) {
|
2975
2991
|
return transformParamSpec(oldTypeArgType);
|
2976
2992
|
}
|
2977
2993
|
let newTypeArgType = this.apply(oldTypeArgType, recursionCount);
|
@@ -2981,7 +2997,7 @@ class TypeVarTransformer {
|
|
2981
2997
|
// (e.g. Union[Unpack[Vs]]), expand the subtypes into a union here.
|
2982
2998
|
if ((0, types_1.isTypeVar)(oldTypeArgType) &&
|
2983
2999
|
(0, types_1.isVariadicTypeVar)(oldTypeArgType) &&
|
2984
|
-
oldTypeArgType.isVariadicInUnion) {
|
3000
|
+
oldTypeArgType.priv.isVariadicInUnion) {
|
2985
3001
|
newTypeArgType = _expandVariadicUnpackedUnion(newTypeArgType);
|
2986
3002
|
}
|
2987
3003
|
}
|
@@ -2992,20 +3008,20 @@ class TypeVarTransformer {
|
|
2992
3008
|
newTypeArgs = [];
|
2993
3009
|
typeParams.forEach((typeParam) => {
|
2994
3010
|
let replacementType = typeParam;
|
2995
|
-
if (typeParam.
|
3011
|
+
if (typeParam.shared.isParamSpec) {
|
2996
3012
|
replacementType = transformParamSpec(typeParam);
|
2997
3013
|
if (replacementType !== typeParam) {
|
2998
3014
|
specializationNeeded = true;
|
2999
3015
|
}
|
3000
3016
|
}
|
3001
3017
|
else {
|
3002
|
-
if (!this._isTypeVarScopePending(typeParam.scopeId)) {
|
3018
|
+
if (!this._isTypeVarScopePending(typeParam.priv.scopeId)) {
|
3003
3019
|
const transformedType = this.transformTypeVar(typeParam, recursionCount);
|
3004
3020
|
replacementType = transformedType !== null && transformedType !== void 0 ? transformedType : typeParam;
|
3005
3021
|
if (replacementType !== typeParam) {
|
3006
3022
|
specializationNeeded = true;
|
3007
3023
|
}
|
3008
|
-
else if (transformedType !== undefined && !classType.typeArguments) {
|
3024
|
+
else if (transformedType !== undefined && !classType.priv.typeArguments) {
|
3009
3025
|
specializationNeeded = true;
|
3010
3026
|
}
|
3011
3027
|
}
|
@@ -3033,6 +3049,7 @@ class TypeVarTransformer {
|
|
3033
3049
|
let typesRequiredSpecialization = declaredReturnType !== specializedReturnType;
|
3034
3050
|
const specializedParameters = {
|
3035
3051
|
parameterTypes: [],
|
3052
|
+
parameterDefaultArgs: undefined,
|
3036
3053
|
returnType: specializedReturnType,
|
3037
3054
|
};
|
3038
3055
|
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(functionType);
|
@@ -3040,7 +3057,7 @@ class TypeVarTransformer {
|
|
3040
3057
|
const paramSpecType = this.transformParamSpec(paramSpec, recursionCount);
|
3041
3058
|
if (paramSpecType) {
|
3042
3059
|
const transformedParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(paramSpecType);
|
3043
|
-
if (paramSpecType.
|
3060
|
+
if (paramSpecType.shared.parameters.length > 0 ||
|
3044
3061
|
!transformedParamSpec ||
|
3045
3062
|
!(0, types_1.isTypeSame)(paramSpec, transformedParamSpec)) {
|
3046
3063
|
functionType = types_1.FunctionType.applyParamSpecValue(functionType, paramSpecType);
|
@@ -3052,7 +3069,7 @@ class TypeVarTransformer {
|
|
3052
3069
|
const specializedDefaultArgs = [];
|
3053
3070
|
const wasTransformingTypeArg = this._isTransformingTypeArg;
|
3054
3071
|
this._isTransformingTypeArg = true;
|
3055
|
-
for (let i = 0; i < functionType.
|
3072
|
+
for (let i = 0; i < functionType.shared.parameters.length; i++) {
|
3056
3073
|
const paramType = types_1.FunctionType.getEffectiveParameterType(functionType, i);
|
3057
3074
|
const specializedType = this.apply(paramType, recursionCount);
|
3058
3075
|
specializedParameters.parameterTypes.push(specializedType);
|
@@ -3068,12 +3085,12 @@ class TypeVarTransformer {
|
|
3068
3085
|
specializedDefaultArgs.push(defaultArgType);
|
3069
3086
|
if (variadicParamIndex === undefined &&
|
3070
3087
|
(0, types_1.isVariadicTypeVar)(paramType) &&
|
3071
|
-
functionType.
|
3088
|
+
functionType.shared.parameters[i].category === 1 /* ParameterCategory.ArgsList */) {
|
3072
3089
|
variadicParamIndex = i;
|
3073
3090
|
if ((0, types_1.isClassInstance)(specializedType) &&
|
3074
3091
|
isTupleClass(specializedType) &&
|
3075
|
-
specializedType.isUnpacked) {
|
3076
|
-
variadicTypesToUnpack = specializedType.tupleTypeArguments;
|
3092
|
+
specializedType.priv.isUnpacked) {
|
3093
|
+
variadicTypesToUnpack = specializedType.priv.tupleTypeArguments;
|
3077
3094
|
}
|
3078
3095
|
}
|
3079
3096
|
if (paramType !== specializedType) {
|
@@ -3081,12 +3098,27 @@ class TypeVarTransformer {
|
|
3081
3098
|
}
|
3082
3099
|
}
|
3083
3100
|
let specializedInferredReturnType;
|
3084
|
-
if (functionType.inferredReturnType) {
|
3085
|
-
specializedInferredReturnType = this.apply(functionType.inferredReturnType, recursionCount);
|
3086
|
-
if (specializedInferredReturnType !== functionType.inferredReturnType) {
|
3101
|
+
if (functionType.priv.inferredReturnType) {
|
3102
|
+
specializedInferredReturnType = this.apply(functionType.priv.inferredReturnType, recursionCount);
|
3103
|
+
if (specializedInferredReturnType !== functionType.priv.inferredReturnType) {
|
3087
3104
|
typesRequiredSpecialization = true;
|
3088
3105
|
}
|
3089
3106
|
}
|
3107
|
+
// Do we need to update the boundToType?
|
3108
|
+
if (functionType.priv.boundToType) {
|
3109
|
+
const newBoundToType = this.apply(functionType.priv.boundToType, recursionCount);
|
3110
|
+
if (newBoundToType !== functionType.priv.boundToType && (0, types_1.isClass)(newBoundToType)) {
|
3111
|
+
functionType = types_1.FunctionType.clone(functionType, /* stripFirstParam */ false, newBoundToType);
|
3112
|
+
}
|
3113
|
+
}
|
3114
|
+
// Do we need to update the strippedFirstParamType?
|
3115
|
+
if (functionType.priv.strippedFirstParamType) {
|
3116
|
+
const newStrippedType = this.apply(functionType.priv.strippedFirstParamType, recursionCount);
|
3117
|
+
if (newStrippedType !== functionType.priv.strippedFirstParamType) {
|
3118
|
+
functionType = types_1.TypeBase.cloneType(functionType);
|
3119
|
+
functionType.priv.strippedFirstParamType = newStrippedType;
|
3120
|
+
}
|
3121
|
+
}
|
3090
3122
|
this._isTransformingTypeArg = wasTransformingTypeArg;
|
3091
3123
|
if (!typesRequiredSpecialization) {
|
3092
3124
|
return functionType;
|
@@ -3100,8 +3132,8 @@ class TypeVarTransformer {
|
|
3100
3132
|
}
|
3101
3133
|
// Unpack the tuple and synthesize a new function in the process.
|
3102
3134
|
const newFunctionType = types_1.TypeBase.isInstantiable(functionType)
|
3103
|
-
? types_1.FunctionType.createInstantiable(functionType.
|
3104
|
-
: types_1.FunctionType.createSynthesizedInstance('', functionType.
|
3135
|
+
? types_1.FunctionType.createInstantiable(functionType.shared.flags | 64 /* FunctionTypeFlags.SynthesizedMethod */)
|
3136
|
+
: types_1.FunctionType.createSynthesizedInstance('', functionType.shared.flags);
|
3105
3137
|
let insertKeywordOnlySeparator = false;
|
3106
3138
|
let swallowPositionOnlySeparator = false;
|
3107
3139
|
specializedParameters.parameterTypes.forEach((paramType, index) => {
|
@@ -3109,15 +3141,9 @@ class TypeVarTransformer {
|
|
3109
3141
|
let sawUnboundedEntry = false;
|
3110
3142
|
// Unpack the tuple into individual parameters.
|
3111
3143
|
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
|
-
});
|
3144
|
+
types_1.FunctionType.addParameter(newFunctionType, types_1.FunctionParam.create(unpackedType.isUnbounded || (0, types_1.isVariadicTypeVar)(unpackedType.type)
|
3145
|
+
? 1 /* ParameterCategory.ArgsList */
|
3146
|
+
: 0 /* ParameterCategory.Simple */, unpackedType.type, types_1.FunctionParamFlags.NameSynthesized | types_1.FunctionParamFlags.TypeDeclared, `__p${newFunctionType.shared.parameters.length}`));
|
3121
3147
|
if (unpackedType.isUnbounded) {
|
3122
3148
|
sawUnboundedEntry = true;
|
3123
3149
|
}
|
@@ -3130,7 +3156,7 @@ class TypeVarTransformer {
|
|
3130
3156
|
}
|
3131
3157
|
}
|
3132
3158
|
else {
|
3133
|
-
const param = { ...functionType.
|
3159
|
+
const param = { ...functionType.shared.parameters[index] };
|
3134
3160
|
if ((0, types_1.isKeywordOnlySeparator)(param)) {
|
3135
3161
|
insertKeywordOnlySeparator = false;
|
3136
3162
|
}
|
@@ -3144,15 +3170,15 @@ class TypeVarTransformer {
|
|
3144
3170
|
insertKeywordOnlySeparator = false;
|
3145
3171
|
}
|
3146
3172
|
param.type = paramType;
|
3147
|
-
if (param.name &&
|
3148
|
-
param.name = `__p${newFunctionType.
|
3173
|
+
if (param.name && types_1.FunctionParam.isNameSynthesized(param)) {
|
3174
|
+
param.name = `__p${newFunctionType.shared.parameters.length}`;
|
3149
3175
|
}
|
3150
3176
|
if (param.category !== 0 /* ParameterCategory.Simple */ || param.name || !swallowPositionOnlySeparator) {
|
3151
3177
|
types_1.FunctionType.addParameter(newFunctionType, param);
|
3152
3178
|
}
|
3153
3179
|
}
|
3154
3180
|
});
|
3155
|
-
newFunctionType.
|
3181
|
+
newFunctionType.shared.declaredReturnType = specializedParameters.returnType;
|
3156
3182
|
return newFunctionType;
|
3157
3183
|
});
|
3158
3184
|
}
|
@@ -3181,16 +3207,16 @@ class TypeVarDefaultValidator extends TypeVarTransformer {
|
|
3181
3207
|
this._invalidTypeVars = _invalidTypeVars;
|
3182
3208
|
}
|
3183
3209
|
transformTypeVar(typeVar) {
|
3184
|
-
const replacementType = this._liveTypeParams.find((param) => param.
|
3210
|
+
const replacementType = this._liveTypeParams.find((param) => param.shared.name === typeVar.shared.name);
|
3185
3211
|
if (!replacementType || (0, types_1.isParamSpec)(replacementType)) {
|
3186
|
-
this._invalidTypeVars.add(typeVar.
|
3212
|
+
this._invalidTypeVars.add(typeVar.shared.name);
|
3187
3213
|
}
|
3188
3214
|
return types_1.UnknownType.create();
|
3189
3215
|
}
|
3190
3216
|
transformParamSpec(paramSpec) {
|
3191
|
-
const replacementType = this._liveTypeParams.find((param) => param.
|
3217
|
+
const replacementType = this._liveTypeParams.find((param) => param.shared.name === paramSpec.shared.name);
|
3192
3218
|
if (!replacementType || !(0, types_1.isParamSpec)(replacementType)) {
|
3193
|
-
this._invalidTypeVars.add(paramSpec.
|
3219
|
+
this._invalidTypeVars.add(paramSpec.shared.name);
|
3194
3220
|
}
|
3195
3221
|
return undefined;
|
3196
3222
|
}
|
@@ -3210,11 +3236,11 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
|
3210
3236
|
return classType;
|
3211
3237
|
}
|
3212
3238
|
transformTypeVarsInFunctionType(sourceType, recursionCount) {
|
3213
|
-
if (sourceType.trackedSignatures) {
|
3214
|
-
this._signatureTracker.addTrackedSignatures(sourceType.trackedSignatures);
|
3239
|
+
if (sourceType.priv.trackedSignatures) {
|
3240
|
+
this._signatureTracker.addTrackedSignatures(sourceType.priv.trackedSignatures);
|
3215
3241
|
}
|
3216
3242
|
// If this function is not generic, there's no need to check for uniqueness.
|
3217
|
-
if (sourceType.
|
3243
|
+
if (sourceType.shared.typeParameters.length === 0) {
|
3218
3244
|
return super.transformTypeVarsInFunctionType(sourceType, recursionCount);
|
3219
3245
|
}
|
3220
3246
|
let updatedSourceType = sourceType;
|
@@ -3228,10 +3254,10 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
|
3228
3254
|
const typeVarContext = new typeVarContext_1.TypeVarContext(getTypeVarScopeIds(sourceType));
|
3229
3255
|
// Create new type variables with the same scope but with
|
3230
3256
|
// different (unique) names.
|
3231
|
-
sourceType.
|
3232
|
-
if (typeParam.scopeType === 1 /* TypeVarScopeType.Function */) {
|
3233
|
-
let replacement = types_1.TypeVarType.cloneForNewName(typeParam, `${typeParam.
|
3234
|
-
if (replacement.
|
3257
|
+
sourceType.shared.typeParameters.forEach((typeParam) => {
|
3258
|
+
if (typeParam.priv.scopeType === 1 /* TypeVarScopeType.Function */) {
|
3259
|
+
let replacement = types_1.TypeVarType.cloneForNewName(typeParam, `${typeParam.shared.name}(${offsetIndex})`);
|
3260
|
+
if (replacement.shared.isParamSpec) {
|
3235
3261
|
replacement = convertTypeToParamSpecValue(replacement);
|
3236
3262
|
}
|
3237
3263
|
typeVarContext.setTypeVarType(typeParam, replacement);
|
@@ -3259,7 +3285,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3259
3285
|
const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
|
3260
3286
|
// If the type variable is unrelated to the scopes we're solving,
|
3261
3287
|
// don't transform that type variable.
|
3262
|
-
if (typeVar.scopeId && this._typeVarContext.hasSolveForScope(typeVar.scopeId)) {
|
3288
|
+
if (typeVar.priv.scopeId && this._typeVarContext.hasSolveForScope(typeVar.priv.scopeId)) {
|
3263
3289
|
let replacement = signatureContext.getTypeVarType(typeVar, !!this._options.useNarrowBoundOnly);
|
3264
3290
|
// If there was no narrow bound but there is a wide bound that
|
3265
3291
|
// contains literals or a TypeVar, we'll use the wide bound even if
|
@@ -3293,7 +3319,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3293
3319
|
if ((0, types_1.isClassInstance)(subtype)) {
|
3294
3320
|
// If the includeSubclasses wasn't set, force it to be set by
|
3295
3321
|
// converting to/from an instantiable.
|
3296
|
-
if (!subtype.includeSubclasses) {
|
3322
|
+
if (!subtype.priv.includeSubclasses) {
|
3297
3323
|
subtype = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneAsInstantiable(subtype));
|
3298
3324
|
}
|
3299
3325
|
if (this._options.unknownIfNotFound) {
|
@@ -3305,10 +3331,12 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3305
3331
|
return subtype;
|
3306
3332
|
});
|
3307
3333
|
}
|
3308
|
-
if ((0, types_1.isTypeVar)(replacement) && typeVar.isVariadicUnpacked && replacement.
|
3309
|
-
return types_1.TypeVarType.cloneForUnpacked(replacement, typeVar.isVariadicInUnion);
|
3334
|
+
if ((0, types_1.isTypeVar)(replacement) && typeVar.priv.isVariadicUnpacked && replacement.shared.isVariadic) {
|
3335
|
+
return types_1.TypeVarType.cloneForUnpacked(replacement, typeVar.priv.isVariadicInUnion);
|
3310
3336
|
}
|
3311
|
-
if (!(0, types_1.isTypeVar)(replacement) ||
|
3337
|
+
if (!(0, types_1.isTypeVar)(replacement) ||
|
3338
|
+
!replacement.priv.isInScopePlaceholder ||
|
3339
|
+
!this._options.unknownIfNotFound) {
|
3312
3340
|
return replacement;
|
3313
3341
|
}
|
3314
3342
|
}
|
@@ -3323,27 +3351,27 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3323
3351
|
useDefaultOrUnknown = true;
|
3324
3352
|
}
|
3325
3353
|
}
|
3326
|
-
else if (this._options.applyInScopePlaceholders && typeVar.isInScopePlaceholder) {
|
3354
|
+
else if (this._options.applyInScopePlaceholders && typeVar.priv.isInScopePlaceholder) {
|
3327
3355
|
useDefaultOrUnknown = true;
|
3328
3356
|
}
|
3329
3357
|
if (useDefaultOrUnknown) {
|
3330
3358
|
// Use the default value if there is one.
|
3331
|
-
if (typeVar.
|
3332
|
-
return this._solveDefaultType(typeVar.
|
3359
|
+
if (typeVar.shared.isDefaultExplicit && !this._options.useUnknownOverDefault) {
|
3360
|
+
return this._solveDefaultType(typeVar.shared.defaultType, recursionCount);
|
3333
3361
|
}
|
3334
3362
|
return getUnknownTypeForTypeVar(typeVar, this._options.tupleClassType);
|
3335
3363
|
}
|
3336
3364
|
}
|
3337
3365
|
// If we're solving a default type, handle type variables with no scope ID.
|
3338
|
-
if (this._isSolvingDefaultType && !typeVar.scopeId) {
|
3366
|
+
if (this._isSolvingDefaultType && !typeVar.priv.scopeId) {
|
3339
3367
|
const replacementEntry = signatureContext
|
3340
3368
|
.getTypeVars()
|
3341
|
-
.find((entry) => entry.typeVar.
|
3369
|
+
.find((entry) => entry.typeVar.shared.name === typeVar.shared.name);
|
3342
3370
|
if (replacementEntry) {
|
3343
3371
|
return signatureContext.getTypeVarType(replacementEntry.typeVar);
|
3344
3372
|
}
|
3345
|
-
if (typeVar.
|
3346
|
-
return this.apply(typeVar.
|
3373
|
+
if (typeVar.shared.isDefaultExplicit) {
|
3374
|
+
return this.apply(typeVar.shared.defaultType, recursionCount);
|
3347
3375
|
}
|
3348
3376
|
return types_1.UnknownType.create();
|
3349
3377
|
}
|
@@ -3358,12 +3386,12 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3358
3386
|
// def test(x: Union[str, T]) -> Union[str, T]
|
3359
3387
|
if (this._options.eliminateUnsolvedInUnions) {
|
3360
3388
|
if ((0, types_1.isTypeVar)(preTransform) &&
|
3361
|
-
preTransform.scopeId !== undefined &&
|
3362
|
-
this._typeVarContext.hasSolveForScope(preTransform.scopeId)) {
|
3389
|
+
preTransform.priv.scopeId !== undefined &&
|
3390
|
+
this._typeVarContext.hasSolveForScope(preTransform.priv.scopeId)) {
|
3363
3391
|
const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
|
3364
3392
|
const typeVarType = signatureContext.getTypeVarType(preTransform);
|
3365
3393
|
// Did the TypeVar remain unsolved?
|
3366
|
-
if (!typeVarType || ((0, types_1.isTypeVar)(typeVarType) && typeVarType.isInScopePlaceholder)) {
|
3394
|
+
if (!typeVarType || ((0, types_1.isTypeVar)(typeVarType) && typeVarType.priv.isInScopePlaceholder)) {
|
3367
3395
|
// If the TypeVar was not transformed, then it was unsolved,
|
3368
3396
|
// and we'll eliminate it.
|
3369
3397
|
if (preTransform === postTransform) {
|
@@ -3381,10 +3409,12 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3381
3409
|
}
|
3382
3410
|
transformTupleTypeVar(typeVar) {
|
3383
3411
|
var _a;
|
3384
|
-
if (!typeVar.scopeId || !this._typeVarContext.hasSolveForScope(typeVar.scopeId)) {
|
3385
|
-
const defaultType = typeVar.
|
3386
|
-
if (typeVar.
|
3387
|
-
|
3412
|
+
if (!typeVar.priv.scopeId || !this._typeVarContext.hasSolveForScope(typeVar.priv.scopeId)) {
|
3413
|
+
const defaultType = typeVar.shared.defaultType;
|
3414
|
+
if (typeVar.shared.isDefaultExplicit &&
|
3415
|
+
(0, types_1.isClassInstance)(defaultType) &&
|
3416
|
+
defaultType.priv.tupleTypeArguments) {
|
3417
|
+
return defaultType.priv.tupleTypeArguments;
|
3388
3418
|
}
|
3389
3419
|
return undefined;
|
3390
3420
|
}
|
@@ -3395,19 +3425,19 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3395
3425
|
var _a, _b;
|
3396
3426
|
const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
|
3397
3427
|
// If we're solving a default type, handle param specs with no scope ID.
|
3398
|
-
if (this._isSolvingDefaultType && !paramSpec.scopeId) {
|
3428
|
+
if (this._isSolvingDefaultType && !paramSpec.priv.scopeId) {
|
3399
3429
|
const replacementEntry = signatureContext
|
3400
3430
|
.getTypeVars()
|
3401
|
-
.find((entry) => entry.typeVar.
|
3431
|
+
.find((entry) => entry.typeVar.shared.name === paramSpec.shared.name);
|
3402
3432
|
if (replacementEntry) {
|
3403
3433
|
return signatureContext.getParamSpecType(replacementEntry.typeVar);
|
3404
3434
|
}
|
3405
|
-
if (paramSpec.
|
3406
|
-
return convertTypeToParamSpecValue(this.apply(paramSpec.
|
3435
|
+
if (paramSpec.shared.isDefaultExplicit) {
|
3436
|
+
return convertTypeToParamSpecValue(this.apply(paramSpec.shared.defaultType, recursionCount));
|
3407
3437
|
}
|
3408
3438
|
return getUnknownTypeForParamSpec();
|
3409
3439
|
}
|
3410
|
-
if (!paramSpec.scopeId || !this._typeVarContext.hasSolveForScope(paramSpec.scopeId)) {
|
3440
|
+
if (!paramSpec.priv.scopeId || !this._typeVarContext.hasSolveForScope(paramSpec.priv.scopeId)) {
|
3411
3441
|
return undefined;
|
3412
3442
|
}
|
3413
3443
|
const transformedParamSpec = signatureContext.getParamSpecType(paramSpec);
|
@@ -3421,13 +3451,13 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3421
3451
|
useDefaultOrUnknown = true;
|
3422
3452
|
}
|
3423
3453
|
}
|
3424
|
-
else if (this._options.applyInScopePlaceholders && paramSpec.isInScopePlaceholder) {
|
3454
|
+
else if (this._options.applyInScopePlaceholders && paramSpec.priv.isInScopePlaceholder) {
|
3425
3455
|
useDefaultOrUnknown = true;
|
3426
3456
|
}
|
3427
3457
|
if (useDefaultOrUnknown) {
|
3428
3458
|
// Use the default value if there is one.
|
3429
|
-
if (paramSpec.
|
3430
|
-
return convertTypeToParamSpecValue(this._solveDefaultType(paramSpec.
|
3459
|
+
if (paramSpec.shared.isDefaultExplicit && !this._options.useUnknownOverDefault) {
|
3460
|
+
return convertTypeToParamSpecValue(this._solveDefaultType(paramSpec.shared.defaultType, recursionCount));
|
3431
3461
|
}
|
3432
3462
|
// Convert to the ParamSpec equivalent of "Unknown".
|
3433
3463
|
return getUnknownTypeForParamSpec();
|
@@ -3435,25 +3465,25 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3435
3465
|
return undefined;
|
3436
3466
|
}
|
3437
3467
|
transformConditionalType(type, recursionCount) {
|
3438
|
-
var _a;
|
3439
|
-
if (!type.condition) {
|
3468
|
+
var _a, _b;
|
3469
|
+
if (!((_a = type.props) === null || _a === void 0 ? void 0 : _a.condition)) {
|
3440
3470
|
return type;
|
3441
3471
|
}
|
3442
|
-
const signatureContext = this._typeVarContext.getSignatureContext((
|
3443
|
-
for (const condition of type.condition) {
|
3472
|
+
const signatureContext = this._typeVarContext.getSignatureContext((_b = this._activeTypeVarSignatureContextIndex) !== null && _b !== void 0 ? _b : 0);
|
3473
|
+
for (const condition of type.props.condition) {
|
3444
3474
|
// This doesn't apply to bound type variables.
|
3445
|
-
if (condition.typeVar.
|
3475
|
+
if (condition.typeVar.shared.constraints.length === 0) {
|
3446
3476
|
continue;
|
3447
3477
|
}
|
3448
3478
|
const typeVarEntry = signatureContext.getTypeVar(condition.typeVar);
|
3449
|
-
if (!typeVarEntry || condition.constraintIndex >= typeVarEntry.typeVar.
|
3479
|
+
if (!typeVarEntry || condition.constraintIndex >= typeVarEntry.typeVar.shared.constraints.length) {
|
3450
3480
|
continue;
|
3451
3481
|
}
|
3452
3482
|
const value = signatureContext.getTypeVarType(typeVarEntry.typeVar);
|
3453
3483
|
if (!value) {
|
3454
3484
|
continue;
|
3455
3485
|
}
|
3456
|
-
const constraintType = typeVarEntry.typeVar.
|
3486
|
+
const constraintType = typeVarEntry.typeVar.shared.constraints[condition.constraintIndex];
|
3457
3487
|
// If this violates the constraint, substitute a Never type.
|
3458
3488
|
if (!(0, types_1.isTypeSame)(constraintType, value)) {
|
3459
3489
|
return types_1.NeverType.createNever();
|
@@ -3477,7 +3507,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3477
3507
|
const filteredOverloads = [];
|
3478
3508
|
doForEachSubtype((0, types_1.combineTypes)(overloadTypes), (subtype) => {
|
3479
3509
|
(0, debug_1.assert)((0, types_1.isFunction)(subtype));
|
3480
|
-
subtype = types_1.FunctionType.cloneWithNewFlags(subtype, subtype.
|
3510
|
+
subtype = types_1.FunctionType.cloneWithNewFlags(subtype, subtype.shared.flags | 256 /* FunctionTypeFlags.Overloaded */);
|
3481
3511
|
filteredOverloads.push(subtype);
|
3482
3512
|
});
|
3483
3513
|
if (filteredOverloads.length === 1) {
|
@@ -3512,7 +3542,7 @@ class ExpectedTypeTransformer extends TypeVarTransformer {
|
|
3512
3542
|
return undefined;
|
3513
3543
|
}
|
3514
3544
|
_isTypeVarLive(typeVar) {
|
3515
|
-
return this._liveTypeVarScopes.some((scopeId) => typeVar.scopeId === scopeId);
|
3545
|
+
return this._liveTypeVarScopes.some((scopeId) => typeVar.priv.scopeId === scopeId);
|
3516
3546
|
}
|
3517
3547
|
}
|
3518
3548
|
class InScopePlaceholderTransformer extends TypeVarTransformer {
|
@@ -3522,13 +3552,13 @@ class InScopePlaceholderTransformer extends TypeVarTransformer {
|
|
3522
3552
|
}
|
3523
3553
|
transformTypeVar(typeVar) {
|
3524
3554
|
var _a;
|
3525
|
-
if (typeVar.isInScopePlaceholder) {
|
3555
|
+
if (typeVar.priv.isInScopePlaceholder) {
|
3526
3556
|
return (_a = this._signatureContext.getTypeVarType(typeVar)) !== null && _a !== void 0 ? _a : typeVar;
|
3527
3557
|
}
|
3528
3558
|
return typeVar;
|
3529
3559
|
}
|
3530
3560
|
transformParamSpec(paramSpec) {
|
3531
|
-
if (paramSpec.isInScopePlaceholder) {
|
3561
|
+
if (paramSpec.priv.isInScopePlaceholder) {
|
3532
3562
|
return this._signatureContext.getParamSpecType(paramSpec);
|
3533
3563
|
}
|
3534
3564
|
return undefined;
|
@@ -3537,7 +3567,7 @@ class InScopePlaceholderTransformer extends TypeVarTransformer {
|
|
3537
3567
|
function applyInScopePlaceholdersToType(type, signatureContext) {
|
3538
3568
|
// Handle the common case where there are no in-scope placeholders.
|
3539
3569
|
// No more work is required in this case.
|
3540
|
-
if (!signatureContext.getTypeVars().some((entry) => entry.typeVar.isInScopePlaceholder)) {
|
3570
|
+
if (!signatureContext.getTypeVars().some((entry) => entry.typeVar.priv.isInScopePlaceholder)) {
|
3541
3571
|
return type;
|
3542
3572
|
}
|
3543
3573
|
const transformer = new InScopePlaceholderTransformer(signatureContext);
|