@zzzen/pyright-internal 1.2.0-dev.20240721 → 1.2.0-dev.20240804
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 +2 -2
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/binder.js +15 -12
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/cacheManager.js +3 -0
- package/dist/analyzer/cacheManager.js.map +1 -1
- package/dist/analyzer/checker.d.ts +5 -3
- package/dist/analyzer/checker.js +238 -193
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +2 -2
- package/dist/analyzer/codeFlowEngine.js +53 -46
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.js +1 -1
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/constraintSolution.d.ts +21 -0
- package/dist/analyzer/constraintSolution.js +71 -0
- package/dist/analyzer/constraintSolution.js.map +1 -0
- package/dist/analyzer/constraintSolver.d.ts +10 -6
- package/dist/analyzer/constraintSolver.js +520 -462
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constraintTracker.d.ts +44 -0
- package/dist/analyzer/constraintTracker.js +230 -0
- package/dist/analyzer/constraintTracker.js.map +1 -0
- package/dist/analyzer/constructorTransform.d.ts +2 -2
- package/dist/analyzer/constructorTransform.js +25 -25
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +3 -3
- package/dist/analyzer/constructors.js +80 -64
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.d.ts +2 -2
- package/dist/analyzer/dataClasses.js +87 -61
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +9 -9
- package/dist/analyzer/declaration.js +9 -9
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/declarationUtils.d.ts +1 -1
- package/dist/analyzer/declarationUtils.js +6 -6
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +5 -5
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/docStringConversion.js +2 -2
- package/dist/analyzer/docStringConversion.js.map +1 -1
- package/dist/analyzer/enums.d.ts +2 -2
- package/dist/analyzer/enums.js +6 -6
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/functionTransform.d.ts +2 -2
- package/dist/analyzer/functionTransform.js +5 -5
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.js +5 -3
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/namedTuples.d.ts +3 -3
- package/dist/analyzer/namedTuples.js +21 -22
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.d.ts +1 -2
- package/dist/analyzer/operations.js +105 -82
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +16 -12
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +12 -12
- package/dist/analyzer/parameterUtils.js +67 -69
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +6 -6
- package/dist/analyzer/parseTreeUtils.js +22 -22
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +122 -101
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +11 -4
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.d.ts +3 -2
- package/dist/analyzer/properties.js +27 -27
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.d.ts +3 -3
- package/dist/analyzer/protocols.js +58 -57
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.js +1 -1
- package/dist/analyzer/pythonPathUtils.js.map +1 -1
- package/dist/analyzer/service.d.ts +3 -7
- package/dist/analyzer/service.js +28 -30
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/serviceUtils.d.ts +8 -0
- package/dist/analyzer/serviceUtils.js +31 -0
- package/dist/analyzer/serviceUtils.js.map +1 -0
- package/dist/analyzer/sourceFile.js +5 -19
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.d.ts +1 -1
- package/dist/analyzer/sourceMapper.js +4 -4
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +1 -1
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +4 -4
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/tuples.d.ts +9 -0
- package/dist/analyzer/tuples.js +253 -0
- package/dist/analyzer/tuples.js.map +1 -0
- package/dist/analyzer/typeComplexity.d.ts +2 -0
- package/dist/analyzer/typeComplexity.js +94 -0
- package/dist/analyzer/typeComplexity.js.map +1 -0
- package/dist/analyzer/typeEvaluator.js +1758 -1979
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +69 -45
- package/dist/analyzer/typeEvaluatorTypes.js +7 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +157 -121
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +1 -1
- package/dist/analyzer/typePrinter.js +64 -61
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.d.ts +3 -3
- package/dist/analyzer/typeStubWriter.js +15 -15
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +45 -41
- package/dist/analyzer/typeUtils.js +511 -748
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeWalker.js +4 -4
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +4 -4
- package/dist/analyzer/typedDicts.js +73 -77
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +97 -72
- package/dist/analyzer/types.js +217 -208
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +11 -11
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -0
- package/dist/common/configOptions.js +5 -0
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/diagnosticRules.d.ts +1 -0
- package/dist/common/diagnosticRules.js +1 -0
- package/dist/common/diagnosticRules.js.map +1 -1
- package/dist/common/fileSystem.d.ts +0 -1
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/languageServerInterface.d.ts +13 -0
- package/dist/common/languageServerInterface.js +15 -1
- package/dist/common/languageServerInterface.js.map +1 -1
- package/dist/common/lspUtils.js +2 -2
- package/dist/common/memUtils.d.ts +4 -0
- package/dist/common/memUtils.js +33 -2
- package/dist/common/memUtils.js.map +1 -1
- package/dist/common/serviceKeys.d.ts +3 -0
- package/dist/common/serviceKeys.js +2 -0
- package/dist/common/serviceKeys.js.map +1 -1
- package/dist/common/serviceProviderExtensions.js +7 -0
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/languageServerBase.d.ts +5 -4
- package/dist/languageServerBase.js +19 -12
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +3 -2
- package/dist/languageService/autoImporter.js +5 -1
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +5 -3
- package/dist/languageService/completionProvider.js +39 -38
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.d.ts +1 -1
- package/dist/languageService/completionProviderUtils.js +3 -3
- package/dist/languageService/completionProviderUtils.js.map +1 -1
- package/dist/languageService/fileWatcherDynamicFeature.js +2 -2
- package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
- package/dist/languageService/hoverProvider.js +3 -3
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/referencesProvider.js +2 -2
- package/dist/languageService/signatureHelpProvider.js +1 -1
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +3 -3
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +5 -0
- package/dist/localization/localize.js +6 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +5 -1
- package/dist/localization/package.nls.de.json +5 -1
- package/dist/localization/package.nls.en-us.json +5 -0
- package/dist/localization/package.nls.es.json +5 -1
- package/dist/localization/package.nls.fr.json +5 -1
- package/dist/localization/package.nls.it.json +5 -1
- package/dist/localization/package.nls.ja.json +5 -1
- package/dist/localization/package.nls.ko.json +5 -1
- package/dist/localization/package.nls.pl.json +5 -1
- package/dist/localization/package.nls.pt-br.json +5 -1
- package/dist/localization/package.nls.qps-ploc.json +5 -1
- package/dist/localization/package.nls.ru.json +5 -1
- package/dist/localization/package.nls.tr.json +5 -1
- package/dist/localization/package.nls.zh-cn.json +5 -1
- package/dist/localization/package.nls.zh-tw.json +5 -1
- package/dist/parser/parseNodes.d.ts +9 -9
- package/dist/parser/parseNodes.js +20 -20
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.js +30 -30
- package/dist/parser/parser.js.map +1 -1
- package/dist/tests/checker.test.js +12 -4
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js +4 -21
- package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js.map +1 -1
- package/dist/tests/fourslash/signature.complicated.fourslash.js +1 -1
- package/dist/tests/fourslash/signature.complicated.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/fourSlashParser.js +1 -1
- package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
- package/dist/tests/harness/fourslash/testStateUtils.js +2 -2
- package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +0 -1
- package/dist/tests/harness/vfs/filesystem.js +0 -4
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importResolver.test.js +62 -15
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/lsp/languageServerTestUtils.js +1 -1
- package/dist/tests/lsp/languageServerTestUtils.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +1 -1
- package/dist/tests/typeEvaluator2.test.js +12 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +5 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +10 -2
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +9 -3
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +72 -60
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +6 -2
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +4 -0
- package/dist/tests/typeEvaluator8.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +13 -18
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +3 -2
- package/dist/workspaceFactory.js +15 -2
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
- package/dist/analyzer/typeVarContext.d.ts +0 -60
- package/dist/analyzer/typeVarContext.js +0 -392
- package/dist/analyzer/typeVarContext.js.map +0 -1
@@ -8,15 +8,15 @@
|
|
8
8
|
* Functions that operate on Type objects.
|
9
9
|
*/
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
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.
|
12
|
-
exports.
|
13
|
-
exports.
|
11
|
+
exports.isTupleClass = 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.getUnknownForTypeVarTuple = exports.getUnknownForTypeVar = 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.requiresTypeArgs = exports.getGeneratorTypeArgs = exports.specializeTupleClass = exports.combineTupleTypeArgs = 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.buildSolution = exports.buildSolutionFromSpecializedClass = exports.setTypeArgsRecursive = exports.specializeClassType = exports.getTypeVarArgsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = exports.lookUpClassMember = exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbolsRecursive = exports.getProtocolSymbols = exports.transformExpectedType = exports.validateTypeVarDefault = exports.applySourceContextTypeVarsToSignature = exports.applySourceContextTypeVars = exports.applySolvedTypeVars = exports.makeTypeVarsFree = exports.makeTypeVarsBound = exports.ensureSignaturesAreUnique = exports.addSolutionForSelfType = exports.partiallySpecializeType = exports.isTupleIndexUnambiguous = exports.isUnboundedTupleClass = void 0;
|
13
|
+
exports.TypeVarTransformer = exports.simplifyFunctionToParamSpec = exports.convertTypeToParamSpecValue = exports.convertNodeToArg = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgCompatible = void 0;
|
14
14
|
const collectionUtils_1 = require("../common/collectionUtils");
|
15
15
|
const debug_1 = require("../common/debug");
|
16
|
+
const constraintSolution_1 = require("./constraintSolution");
|
16
17
|
const symbol_1 = require("./symbol");
|
17
18
|
const symbolUtils_1 = require("./symbolUtils");
|
18
19
|
const types_1 = require("./types");
|
19
|
-
const typeVarContext_1 = require("./typeVarContext");
|
20
20
|
const typeWalker_1 = require("./typeWalker");
|
21
21
|
var MemberAccessFlags;
|
22
22
|
(function (MemberAccessFlags) {
|
@@ -88,10 +88,10 @@ var AssignTypeFlags;
|
|
88
88
|
// This has the potential of recursing infinitely. This flag allows us
|
89
89
|
// to detect the recursion after the first level of checking.
|
90
90
|
AssignTypeFlags[AssignTypeFlags["SkipRecursiveTypeCheck"] = 4] = "SkipRecursiveTypeCheck";
|
91
|
-
//
|
92
|
-
//
|
93
|
-
//
|
94
|
-
AssignTypeFlags[AssignTypeFlags["
|
91
|
+
// During TypeVar solving for a function call, this flag is set if
|
92
|
+
// this is the first of multiple passes. It adjusts certain heuristics
|
93
|
+
// for constraint solving.
|
94
|
+
AssignTypeFlags[AssignTypeFlags["ArgAssignmentFirstPass"] = 8] = "ArgAssignmentFirstPass";
|
95
95
|
// If the dest is not Any but the src is Any, treat it
|
96
96
|
// as incompatible. Also, treat all source TypeVars as their
|
97
97
|
// concrete counterparts. This option is used for validating
|
@@ -103,8 +103,6 @@ var AssignTypeFlags;
|
|
103
103
|
AssignTypeFlags[AssignTypeFlags["PartialOverloadOverlap"] = 32] = "PartialOverloadOverlap";
|
104
104
|
// For function types, skip the return type check.
|
105
105
|
AssignTypeFlags[AssignTypeFlags["SkipReturnTypeCheck"] = 64] = "SkipReturnTypeCheck";
|
106
|
-
// Allow bool values to be assigned to TypeGuard[x] types.
|
107
|
-
AssignTypeFlags[AssignTypeFlags["AllowBoolTypeGuard"] = 128] = "AllowBoolTypeGuard";
|
108
106
|
// In most cases, literals are stripped when assigning to a
|
109
107
|
// type variable. This overrides the standard behavior.
|
110
108
|
AssignTypeFlags[AssignTypeFlags["RetainLiteralsForTypeVar"] = 256] = "RetainLiteralsForTypeVar";
|
@@ -113,11 +111,7 @@ var AssignTypeFlags;
|
|
113
111
|
// because overloads can provide explicit type annotations for self
|
114
112
|
// or cls.
|
115
113
|
AssignTypeFlags[AssignTypeFlags["SkipSelfClsTypeCheck"] = 512] = "SkipSelfClsTypeCheck";
|
116
|
-
//
|
117
|
-
// do not generate an error. This is used for populating the
|
118
|
-
// typeVarContext when handling contravariant parameters in a callable.
|
119
|
-
AssignTypeFlags[AssignTypeFlags["IgnoreTypeVarScope"] = 1024] = "IgnoreTypeVarScope";
|
120
|
-
// We're initially populating the typeVarContext with an expected type,
|
114
|
+
// We're initially populating the constraints with an expected type,
|
121
115
|
// so TypeVars should match the specified type exactly rather than
|
122
116
|
// employing narrowing or widening, and don't strip literals.
|
123
117
|
AssignTypeFlags[AssignTypeFlags["PopulatingExpectedType"] = 2048] = "PopulatingExpectedType";
|
@@ -128,7 +122,7 @@ var AssignTypeFlags;
|
|
128
122
|
// hasn't previously been specialized, it will be specialized with
|
129
123
|
// default type arguments (typically "Unknown"). This flag skips
|
130
124
|
// this step.
|
131
|
-
AssignTypeFlags[AssignTypeFlags["
|
125
|
+
AssignTypeFlags[AssignTypeFlags["AllowUnspecifiedTypeArgs"] = 8192] = "AllowUnspecifiedTypeArgs";
|
132
126
|
// Normally all special form classes are incompatible with type[T],
|
133
127
|
// but a few of them are allowed in the context of an isinstance
|
134
128
|
// or issubclass call.
|
@@ -216,7 +210,7 @@ function isTypeVarSame(type1, type2) {
|
|
216
210
|
return true;
|
217
211
|
}
|
218
212
|
// If this isn't a bound TypeVar, return false.
|
219
|
-
if (
|
213
|
+
if ((0, types_1.isParamSpec)(type1) || (0, types_1.isTypeVarTuple)(type1) || !types_1.TypeVarType.hasBound(type1)) {
|
220
214
|
return false;
|
221
215
|
}
|
222
216
|
// If the second type isn't a union, return false.
|
@@ -269,17 +263,17 @@ function mapSubtypes(type, callback, options) {
|
|
269
263
|
for (i++; i < subtypes.length; i++) {
|
270
264
|
accumulateSubtype(callback(subtypes[i]));
|
271
265
|
}
|
272
|
-
|
266
|
+
let newType = (0, types_1.combineTypes)(typesToCombine, {
|
273
267
|
skipElideRedundantLiterals: options === null || options === void 0 ? void 0 : options.skipElideRedundantLiterals,
|
274
268
|
});
|
275
269
|
if (options === null || options === void 0 ? void 0 : options.retainTypeAlias) {
|
276
270
|
if ((_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) {
|
277
|
-
types_1.TypeBase.
|
271
|
+
newType = types_1.TypeBase.cloneForTypeAlias(newType, type.props.typeAliasInfo);
|
278
272
|
}
|
279
273
|
}
|
280
274
|
else {
|
281
275
|
// Do our best to retain type aliases.
|
282
|
-
if (
|
276
|
+
if ((0, types_1.isUnion)(newType)) {
|
283
277
|
types_1.UnionType.addTypeAliasSource(newType, type);
|
284
278
|
}
|
285
279
|
}
|
@@ -349,10 +343,10 @@ function cleanIncompleteUnknown(type, recursionCount = 0) {
|
|
349
343
|
if ((0, types_1.isUnknown)(subtype) && subtype.priv.isIncomplete) {
|
350
344
|
return undefined;
|
351
345
|
}
|
352
|
-
if ((0, types_1.isClass)(subtype) && subtype.priv.
|
346
|
+
if ((0, types_1.isClass)(subtype) && subtype.priv.typeArgs) {
|
353
347
|
let typeChanged = false;
|
354
|
-
if (subtype.priv.
|
355
|
-
const updatedTupleTypeArgs = subtype.priv.
|
348
|
+
if (subtype.priv.tupleTypeArgs) {
|
349
|
+
const updatedTupleTypeArgs = subtype.priv.tupleTypeArgs.map((tupleTypeArg) => {
|
356
350
|
const newTypeArg = cleanIncompleteUnknown(tupleTypeArg.type, recursionCount);
|
357
351
|
if (newTypeArg !== tupleTypeArg.type) {
|
358
352
|
typeChanged = true;
|
@@ -364,11 +358,11 @@ function cleanIncompleteUnknown(type, recursionCount = 0) {
|
|
364
358
|
};
|
365
359
|
});
|
366
360
|
if (typeChanged) {
|
367
|
-
return specializeTupleClass(subtype, updatedTupleTypeArgs, !!subtype.priv.
|
361
|
+
return specializeTupleClass(subtype, updatedTupleTypeArgs, !!subtype.priv.isTypeArgExplicit, !!subtype.priv.isUnpacked);
|
368
362
|
}
|
369
363
|
}
|
370
364
|
else {
|
371
|
-
const updatedTypeArgs = subtype.priv.
|
365
|
+
const updatedTypeArgs = subtype.priv.typeArgs.map((typeArg) => {
|
372
366
|
const newTypeArg = cleanIncompleteUnknown(typeArg, recursionCount);
|
373
367
|
if (newTypeArg !== typeArg) {
|
374
368
|
typeChanged = true;
|
@@ -376,7 +370,7 @@ function cleanIncompleteUnknown(type, recursionCount = 0) {
|
|
376
370
|
return newTypeArg;
|
377
371
|
});
|
378
372
|
if (typeChanged) {
|
379
|
-
return types_1.ClassType.
|
373
|
+
return types_1.ClassType.specialize(subtype, updatedTypeArgs, !!subtype.priv.isTypeArgExplicit);
|
380
374
|
}
|
381
375
|
}
|
382
376
|
}
|
@@ -424,7 +418,7 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
424
418
|
if (aParam.category !== bParam.category) {
|
425
419
|
return bParam.category - aParam.category;
|
426
420
|
}
|
427
|
-
const typeComparison = compareTypes(types_1.FunctionType.
|
421
|
+
const typeComparison = compareTypes(types_1.FunctionType.getParamType(a, i), types_1.FunctionType.getParamType(bFunc, i));
|
428
422
|
if (typeComparison !== 0) {
|
429
423
|
return typeComparison;
|
430
424
|
}
|
@@ -484,12 +478,12 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
484
478
|
return -1;
|
485
479
|
}
|
486
480
|
// Sort non-generics before generics.
|
487
|
-
if (a.shared.
|
488
|
-
if (bClass.shared.
|
481
|
+
if (a.shared.typeParams.length > 0 || isTupleClass(a)) {
|
482
|
+
if (bClass.shared.typeParams.length === 0) {
|
489
483
|
return 1;
|
490
484
|
}
|
491
485
|
}
|
492
|
-
else if (bClass.shared.
|
486
|
+
else if (bClass.shared.typeParams.length > 0 || isTupleClass(bClass)) {
|
493
487
|
return -1;
|
494
488
|
}
|
495
489
|
// Sort by class name.
|
@@ -502,8 +496,8 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
502
496
|
return 1;
|
503
497
|
}
|
504
498
|
// Sort by type argument count.
|
505
|
-
const aTypeArgCount = a.priv.
|
506
|
-
const bTypeArgCount = bClass.priv.
|
499
|
+
const aTypeArgCount = a.priv.typeArgs ? a.priv.typeArgs.length : 0;
|
500
|
+
const bTypeArgCount = bClass.priv.typeArgs ? bClass.priv.typeArgs.length : 0;
|
507
501
|
if (aTypeArgCount < bTypeArgCount) {
|
508
502
|
return -1;
|
509
503
|
}
|
@@ -512,7 +506,7 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
512
506
|
}
|
513
507
|
// Sort by type argument.
|
514
508
|
for (let i = 0; i < aTypeArgCount; i++) {
|
515
|
-
const typeComparison = compareTypes(a.priv.
|
509
|
+
const typeComparison = compareTypes(a.priv.typeArgs[i], bClass.priv.typeArgs[i], recursionCount);
|
516
510
|
if (typeComparison !== 0) {
|
517
511
|
return typeComparison;
|
518
512
|
}
|
@@ -669,7 +663,7 @@ function addConditionToType(type, condition, skipSelfCondition = false) {
|
|
669
663
|
return type;
|
670
664
|
}
|
671
665
|
if (skipSelfCondition) {
|
672
|
-
condition = condition.filter((c) => !c.typeVar
|
666
|
+
condition = condition.filter((c) => !types_1.TypeVarType.isSelf(c.typeVar));
|
673
667
|
if (condition.length === 0) {
|
674
668
|
return type;
|
675
669
|
}
|
@@ -744,17 +738,17 @@ function transformPossibleRecursiveTypeAlias(type) {
|
|
744
738
|
const unspecializedType = types_1.TypeBase.isInstance(type)
|
745
739
|
? convertToInstance(type.shared.boundType)
|
746
740
|
: type.shared.boundType;
|
747
|
-
if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.
|
741
|
+
if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArgs) || !type.shared.recursiveAlias.typeParams) {
|
748
742
|
return unspecializedType;
|
749
743
|
}
|
750
|
-
const
|
751
|
-
return applySolvedTypeVars(unspecializedType,
|
744
|
+
const solution = buildSolution(type.shared.recursiveAlias.typeParams, aliasInfo.typeArgs);
|
745
|
+
return applySolvedTypeVars(unspecializedType, solution);
|
752
746
|
}
|
753
747
|
if ((0, types_1.isUnion)(type) && type.priv.includesRecursiveTypeAlias) {
|
754
748
|
let newType = mapSubtypes(type, (subtype) => transformPossibleRecursiveTypeAlias(subtype));
|
755
749
|
if (newType !== type && aliasInfo) {
|
756
750
|
// Copy the type alias information if present.
|
757
|
-
newType = types_1.TypeBase.cloneForTypeAlias(newType, aliasInfo
|
751
|
+
newType = types_1.TypeBase.cloneForTypeAlias(newType, aliasInfo);
|
758
752
|
}
|
759
753
|
return newType;
|
760
754
|
}
|
@@ -787,9 +781,6 @@ function getTypeVarScopeIds(type) {
|
|
787
781
|
if (type.priv.constructorTypeVarScopeId) {
|
788
782
|
scopeIds.push(type.priv.constructorTypeVarScopeId);
|
789
783
|
}
|
790
|
-
if (type.priv.higherOrderTypeVarScopeIds) {
|
791
|
-
scopeIds.push(...type.priv.higherOrderTypeVarScopeIds);
|
792
|
-
}
|
793
784
|
}
|
794
785
|
return scopeIds;
|
795
786
|
}
|
@@ -798,58 +789,51 @@ exports.getTypeVarScopeIds = getTypeVarScopeIds;
|
|
798
789
|
// specified, specialize it with default type arguments (Unknown or the
|
799
790
|
// default type if provided).
|
800
791
|
function specializeWithDefaultTypeArgs(type) {
|
801
|
-
if (type.shared.
|
792
|
+
if (type.shared.typeParams.length === 0 || type.priv.typeArgs) {
|
802
793
|
return type;
|
803
794
|
}
|
804
|
-
return types_1.ClassType.
|
805
|
-
/*
|
795
|
+
return types_1.ClassType.specialize(type, type.shared.typeParams.map((param) => param.shared.defaultType),
|
796
|
+
/* isTypeArgExplicit */ false,
|
806
797
|
/* includeSubclasses */ type.priv.includeSubclasses);
|
807
798
|
}
|
808
799
|
exports.specializeWithDefaultTypeArgs = specializeWithDefaultTypeArgs;
|
809
800
|
// Specializes the class with "Unknown" type args (or the equivalent for ParamSpecs
|
810
801
|
// or TypeVarTuples).
|
811
802
|
function specializeWithUnknownTypeArgs(type, tupleClassType) {
|
812
|
-
if (type.shared.
|
803
|
+
if (type.shared.typeParams.length === 0) {
|
813
804
|
return type;
|
814
805
|
}
|
815
806
|
if (isTupleClass(type)) {
|
816
807
|
return types_1.ClassType.cloneIncludeSubclasses(specializeTupleClass(type, [{ type: types_1.UnknownType.create(), isUnbounded: true }],
|
817
|
-
/*
|
808
|
+
/* isTypeArgExplicit */ false), !!type.priv.includeSubclasses);
|
818
809
|
}
|
819
|
-
return types_1.ClassType.
|
820
|
-
/*
|
810
|
+
return types_1.ClassType.specialize(type, type.shared.typeParams.map((param) => getUnknownForTypeVar(param, tupleClassType)),
|
811
|
+
/* isTypeArgExplicit */ false,
|
821
812
|
/* includeSubclasses */ type.priv.includeSubclasses);
|
822
813
|
}
|
823
814
|
exports.specializeWithUnknownTypeArgs = specializeWithUnknownTypeArgs;
|
824
815
|
// Returns "Unknown" for simple TypeVars or the equivalent for a ParamSpec.
|
825
|
-
function
|
826
|
-
if (
|
827
|
-
return
|
816
|
+
function getUnknownForTypeVar(typeVar, tupleClassType) {
|
817
|
+
if ((0, types_1.isParamSpec)(typeVar)) {
|
818
|
+
return types_1.ParamSpecType.getUnknown();
|
828
819
|
}
|
829
|
-
if (typeVar
|
830
|
-
return
|
820
|
+
if ((0, types_1.isTypeVarTuple)(typeVar) && tupleClassType) {
|
821
|
+
return getUnknownForTypeVarTuple(tupleClassType);
|
831
822
|
}
|
832
823
|
return types_1.UnknownType.create();
|
833
824
|
}
|
834
|
-
exports.
|
835
|
-
|
836
|
-
function getUnknownTypeForParamSpec() {
|
837
|
-
const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.GradualCallableForm */);
|
838
|
-
types_1.FunctionType.addDefaultParameters(newFunction);
|
839
|
-
return newFunction;
|
840
|
-
}
|
841
|
-
exports.getUnknownTypeForParamSpec = getUnknownTypeForParamSpec;
|
842
|
-
function getUnknownTypeForVariadicTypeVar(tupleClassType) {
|
825
|
+
exports.getUnknownForTypeVar = getUnknownForTypeVar;
|
826
|
+
function getUnknownForTypeVarTuple(tupleClassType) {
|
843
827
|
(0, debug_1.assert)((0, types_1.isInstantiableClass)(tupleClassType) && types_1.ClassType.isBuiltIn(tupleClassType, 'tuple'));
|
844
828
|
return types_1.ClassType.cloneAsInstance(specializeTupleClass(tupleClassType, [{ type: types_1.UnknownType.create(), isUnbounded: true }],
|
845
|
-
/*
|
829
|
+
/* isTypeArgExplicit */ true,
|
846
830
|
/* isUnpackedTuple */ true));
|
847
831
|
}
|
848
|
-
exports.
|
832
|
+
exports.getUnknownForTypeVarTuple = getUnknownForTypeVarTuple;
|
849
833
|
// Returns the equivalent of "Callable[..., Unknown]".
|
850
834
|
function getUnknownTypeForCallable() {
|
851
835
|
const newFunction = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.GradualCallableForm */);
|
852
|
-
types_1.FunctionType.
|
836
|
+
types_1.FunctionType.addDefaultParams(newFunction);
|
853
837
|
newFunction.shared.declaredReturnType = types_1.UnknownType.create();
|
854
838
|
return newFunction;
|
855
839
|
}
|
@@ -858,16 +842,16 @@ exports.getUnknownTypeForCallable = getUnknownTypeForCallable;
|
|
858
842
|
// "self specializes" the class, filling in its own type parameters
|
859
843
|
// as type arguments.
|
860
844
|
function selfSpecializeClass(type, options) {
|
861
|
-
if (type.shared.
|
845
|
+
if (type.shared.typeParams.length === 0) {
|
862
846
|
return type;
|
863
847
|
}
|
864
|
-
if (type.priv.
|
848
|
+
if (type.priv.typeArgs && !(options === null || options === void 0 ? void 0 : options.overrideTypeArgs)) {
|
865
849
|
return type;
|
866
850
|
}
|
867
|
-
const typeParams = type.shared.
|
868
|
-
return (options === null || options === void 0 ? void 0 : options.
|
851
|
+
const typeParams = type.shared.typeParams.map((typeParam) => {
|
852
|
+
return (options === null || options === void 0 ? void 0 : options.useBoundTypeVars) ? types_1.TypeVarType.cloneAsBound(typeParam) : typeParam;
|
869
853
|
});
|
870
|
-
return types_1.ClassType.
|
854
|
+
return types_1.ClassType.specialize(type, typeParams);
|
871
855
|
}
|
872
856
|
exports.selfSpecializeClass = selfSpecializeClass;
|
873
857
|
// Determines whether the type derives from tuple. If so, it returns
|
@@ -892,8 +876,8 @@ function getSpecializedTupleType(type) {
|
|
892
876
|
if (types_1.ClassType.isSameGenericClass(classType, tupleClass)) {
|
893
877
|
return classType;
|
894
878
|
}
|
895
|
-
const
|
896
|
-
return applySolvedTypeVars(tupleClass,
|
879
|
+
const solution = buildSolutionFromSpecializedClass(classType);
|
880
|
+
return applySolvedTypeVars(tupleClass, solution);
|
897
881
|
}
|
898
882
|
exports.getSpecializedTupleType = getSpecializedTupleType;
|
899
883
|
function isLiteralType(type) {
|
@@ -1034,10 +1018,10 @@ exports.isMaybeDescriptorInstance = isMaybeDescriptorInstance;
|
|
1034
1018
|
function isTupleGradualForm(type) {
|
1035
1019
|
return ((0, types_1.isClassInstance)(type) &&
|
1036
1020
|
isTupleClass(type) &&
|
1037
|
-
type.priv.
|
1038
|
-
type.priv.
|
1039
|
-
(0, types_1.isAnyOrUnknown)(type.priv.
|
1040
|
-
type.priv.
|
1021
|
+
type.priv.tupleTypeArgs &&
|
1022
|
+
type.priv.tupleTypeArgs.length === 1 &&
|
1023
|
+
(0, types_1.isAnyOrUnknown)(type.priv.tupleTypeArgs[0].type) &&
|
1024
|
+
type.priv.tupleTypeArgs[0].isUnbounded);
|
1041
1025
|
}
|
1042
1026
|
exports.isTupleGradualForm = isTupleGradualForm;
|
1043
1027
|
function isTupleClass(type) {
|
@@ -1048,23 +1032,23 @@ exports.isTupleClass = isTupleClass;
|
|
1048
1032
|
// the form tuple[x, ...] where the number of elements
|
1049
1033
|
// in the tuple is unknown.
|
1050
1034
|
function isUnboundedTupleClass(type) {
|
1051
|
-
|
1052
|
-
|
1035
|
+
var _a;
|
1036
|
+
return (_a = type.priv.tupleTypeArgs) === null || _a === void 0 ? void 0 : _a.some((t) => t.isUnbounded || (0, types_1.isUnpackedTypeVarTuple)(t.type));
|
1053
1037
|
}
|
1054
1038
|
exports.isUnboundedTupleClass = isUnboundedTupleClass;
|
1055
1039
|
// Indicates whether the specified index is within range and its type is unambiguous
|
1056
1040
|
// in that it doesn't involve any element ranges that are of indeterminate length.
|
1057
1041
|
function isTupleIndexUnambiguous(type, index) {
|
1058
|
-
if (!type.priv.
|
1042
|
+
if (!type.priv.tupleTypeArgs) {
|
1059
1043
|
return false;
|
1060
1044
|
}
|
1061
|
-
const unboundedIndex = type.priv.
|
1045
|
+
const unboundedIndex = type.priv.tupleTypeArgs.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedTypeVarTuple)(t.type));
|
1062
1046
|
if (index < 0) {
|
1063
1047
|
const lowerIndexLimit = unboundedIndex < 0 ? 0 : unboundedIndex;
|
1064
|
-
index += type.priv.
|
1048
|
+
index += type.priv.tupleTypeArgs.length;
|
1065
1049
|
return index >= lowerIndexLimit;
|
1066
1050
|
}
|
1067
|
-
const upperIndexLimit = unboundedIndex < 0 ? type.priv.
|
1051
|
+
const upperIndexLimit = unboundedIndex < 0 ? type.priv.tupleTypeArgs.length : unboundedIndex;
|
1068
1052
|
return index < upperIndexLimit;
|
1069
1053
|
}
|
1070
1054
|
exports.isTupleIndexUnambiguous = isTupleIndexUnambiguous;
|
@@ -1078,11 +1062,11 @@ function partiallySpecializeType(type, contextClassType, typeClassType, selfClas
|
|
1078
1062
|
return type;
|
1079
1063
|
}
|
1080
1064
|
// Partially specialize the type using the specialized class type vars.
|
1081
|
-
const
|
1065
|
+
const solution = buildSolutionFromSpecializedClass(contextClassType);
|
1082
1066
|
if (selfClass) {
|
1083
|
-
|
1067
|
+
addSolutionForSelfType(solution, contextClassType, selfClass);
|
1084
1068
|
}
|
1085
|
-
let result = applySolvedTypeVars(type,
|
1069
|
+
let result = applySolvedTypeVars(type, solution, { typeClassType });
|
1086
1070
|
// If this is a property, we may need to partially specialize the
|
1087
1071
|
// access methods associated with it.
|
1088
1072
|
if ((0, types_1.isClass)(result)) {
|
@@ -1105,7 +1089,7 @@ function partiallySpecializeType(type, contextClassType, typeClassType, selfClas
|
|
1105
1089
|
return result;
|
1106
1090
|
}
|
1107
1091
|
exports.partiallySpecializeType = partiallySpecializeType;
|
1108
|
-
function
|
1092
|
+
function addSolutionForSelfType(solution, contextClassType, selfClass) {
|
1109
1093
|
const synthesizedSelfTypeVar = synthesizeTypeVarForSelfCls(contextClassType, /* isClsParam */ false);
|
1110
1094
|
const selfInstance = convertToInstance(selfClass);
|
1111
1095
|
// We can't call stripLiteralValue here because that method requires the type evaluator.
|
@@ -1118,107 +1102,58 @@ function populateTypeVarContextForSelfType(typeVarContext, contextClassType, sel
|
|
1118
1102
|
}
|
1119
1103
|
return subtype;
|
1120
1104
|
});
|
1121
|
-
|
1122
|
-
typeVarContext.setTypeVarType(synthesizedSelfTypeVar, selfInstance, selfWithoutLiteral);
|
1123
|
-
}
|
1105
|
+
solution.setType(synthesizedSelfTypeVar, selfWithoutLiteral);
|
1124
1106
|
}
|
1125
|
-
exports.
|
1107
|
+
exports.addSolutionForSelfType = addSolutionForSelfType;
|
1126
1108
|
// Looks for duplicate function types within the type and ensures that
|
1127
1109
|
// if they are generic, they have unique type variables.
|
1128
|
-
function
|
1110
|
+
function ensureSignaturesAreUnique(type, signatureTracker, expressionOffset) {
|
1129
1111
|
const transformer = new UniqueFunctionSignatureTransformer(signatureTracker, expressionOffset);
|
1130
1112
|
return transformer.apply(type, 0);
|
1131
1113
|
}
|
1132
|
-
exports.
|
1133
|
-
function
|
1134
|
-
const transformer = new
|
1114
|
+
exports.ensureSignaturesAreUnique = ensureSignaturesAreUnique;
|
1115
|
+
function makeTypeVarsBound(type, scopeIds) {
|
1116
|
+
const transformer = new BoundTypeVarTransform(scopeIds);
|
1135
1117
|
return transformer.apply(type, 0);
|
1136
1118
|
}
|
1137
|
-
exports.
|
1138
|
-
function
|
1139
|
-
const transformer = new
|
1119
|
+
exports.makeTypeVarsBound = makeTypeVarsBound;
|
1120
|
+
function makeTypeVarsFree(type, scopeIds) {
|
1121
|
+
const transformer = new FreeTypeVarTransform(scopeIds);
|
1140
1122
|
return transformer.apply(type, 0);
|
1141
1123
|
}
|
1142
|
-
exports.
|
1124
|
+
exports.makeTypeVarsFree = makeTypeVarsFree;
|
1143
1125
|
// Specializes a (potentially generic) type by substituting
|
1144
1126
|
// type variables from a type var map.
|
1145
|
-
function applySolvedTypeVars(type,
|
1146
|
-
// Use a shortcut if
|
1147
|
-
if (
|
1148
|
-
!options.unknownIfNotFound &&
|
1149
|
-
!options.eliminateUnsolvedInUnions &&
|
1150
|
-
!options.applyInScopePlaceholders) {
|
1127
|
+
function applySolvedTypeVars(type, solution, options = {}) {
|
1128
|
+
// Use a shortcut if constraints is empty and no transform is necessary.
|
1129
|
+
if (solution.isEmpty() && !options.replaceUnsolved) {
|
1151
1130
|
return type;
|
1152
1131
|
}
|
1153
|
-
|
1154
|
-
applyInScopePlaceholders(typeVarContext);
|
1155
|
-
}
|
1156
|
-
const transformer = new ApplySolvedTypeVarsTransformer(typeVarContext, options);
|
1132
|
+
const transformer = new ApplySolvedTypeVarsTransformer(solution, options);
|
1157
1133
|
return transformer.apply(type, 0);
|
1158
1134
|
}
|
1159
1135
|
exports.applySolvedTypeVars = applySolvedTypeVars;
|
1160
1136
|
// Applies solved TypeVars from one context to this context.
|
1161
|
-
function applySourceContextTypeVars(destContext,
|
1162
|
-
if (
|
1137
|
+
function applySourceContextTypeVars(destContext, srcSolution) {
|
1138
|
+
if (srcSolution.isEmpty()) {
|
1163
1139
|
return;
|
1164
1140
|
}
|
1165
|
-
destContext.
|
1166
|
-
applySourceContextTypeVarsToSignature(
|
1141
|
+
destContext.doForEachConstraintSet((set) => {
|
1142
|
+
applySourceContextTypeVarsToSignature(set, srcSolution);
|
1167
1143
|
});
|
1168
1144
|
}
|
1169
1145
|
exports.applySourceContextTypeVars = applySourceContextTypeVars;
|
1170
|
-
function applySourceContextTypeVarsToSignature(
|
1171
|
-
|
1172
|
-
const
|
1173
|
-
const
|
1174
|
-
? applySolvedTypeVars(entry.
|
1146
|
+
function applySourceContextTypeVarsToSignature(set, srcSolution) {
|
1147
|
+
set.getTypeVars().forEach((entry) => {
|
1148
|
+
const newLowerBound = entry.lowerBound ? applySolvedTypeVars(entry.lowerBound, srcSolution) : undefined;
|
1149
|
+
const newLowerBoundNoLiterals = entry.lowerBoundNoLiterals
|
1150
|
+
? applySolvedTypeVars(entry.lowerBoundNoLiterals, srcSolution)
|
1175
1151
|
: undefined;
|
1176
|
-
const
|
1177
|
-
|
1178
|
-
if (entry.tupleTypes) {
|
1179
|
-
destSignature.setTupleTypeVar(entry.typeVar, entry.tupleTypes.map((arg) => {
|
1180
|
-
return {
|
1181
|
-
type: applySolvedTypeVars(arg.type, srcContext),
|
1182
|
-
isUnbounded: arg.isUnbounded,
|
1183
|
-
isOptional: arg.isOptional,
|
1184
|
-
};
|
1185
|
-
}));
|
1186
|
-
}
|
1152
|
+
const newUpperBound = entry.upperBound ? applySolvedTypeVars(entry.upperBound, srcSolution) : undefined;
|
1153
|
+
set.setBounds(entry.typeVar, newLowerBound, newLowerBoundNoLiterals, newUpperBound);
|
1187
1154
|
});
|
1188
1155
|
}
|
1189
1156
|
exports.applySourceContextTypeVarsToSignature = applySourceContextTypeVarsToSignature;
|
1190
|
-
// If the TypeVarContext contains any type variables whose types depend on
|
1191
|
-
// in-scope placeholders used for bidirectional type inference, replace those
|
1192
|
-
// with the solved type associated with those in-scope placeholders.
|
1193
|
-
function applyInScopePlaceholders(typeVarContext) {
|
1194
|
-
typeVarContext.doForEachSignatureContext((signature) => {
|
1195
|
-
signature.getTypeVars().forEach((entry) => {
|
1196
|
-
const typeVar = entry.typeVar;
|
1197
|
-
if (!typeVar.priv.isInScopePlaceholder) {
|
1198
|
-
const newNarrowTypeBound = entry.narrowBound
|
1199
|
-
? applyInScopePlaceholdersToType(entry.narrowBound, signature)
|
1200
|
-
: undefined;
|
1201
|
-
const newNarrowTypeBoundNoLiterals = entry.narrowBoundNoLiterals
|
1202
|
-
? applyInScopePlaceholdersToType(entry.narrowBoundNoLiterals, signature)
|
1203
|
-
: undefined;
|
1204
|
-
const newWideTypeBound = entry.wideBound
|
1205
|
-
? applyInScopePlaceholdersToType(entry.wideBound, signature)
|
1206
|
-
: undefined;
|
1207
|
-
signature.setTypeVarType(entry.typeVar, newNarrowTypeBound, newNarrowTypeBoundNoLiterals, newWideTypeBound);
|
1208
|
-
if (entry.tupleTypes) {
|
1209
|
-
signature.setTupleTypeVar(entry.typeVar, entry.tupleTypes.map((arg) => {
|
1210
|
-
return {
|
1211
|
-
type: applyInScopePlaceholdersToType(arg.type, signature),
|
1212
|
-
isUnbounded: arg.isUnbounded,
|
1213
|
-
isOptional: arg.isOptional,
|
1214
|
-
};
|
1215
|
-
}));
|
1216
|
-
}
|
1217
|
-
}
|
1218
|
-
});
|
1219
|
-
});
|
1220
|
-
}
|
1221
|
-
exports.applyInScopePlaceholders = applyInScopePlaceholders;
|
1222
1157
|
// Validates that a default type associated with a TypeVar does not refer to
|
1223
1158
|
// other TypeVars or ParamSpecs that are out of scope.
|
1224
1159
|
function validateTypeVarDefault(typeVar, liveTypeParams, invalidTypeVars) {
|
@@ -1230,11 +1165,6 @@ function validateTypeVarDefault(typeVar, liveTypeParams, invalidTypeVars) {
|
|
1230
1165
|
}
|
1231
1166
|
}
|
1232
1167
|
exports.validateTypeVarDefault = validateTypeVarDefault;
|
1233
|
-
function replaceTypeVarsWithAny(type) {
|
1234
|
-
const transformer = new TypeVarAnyReplacer();
|
1235
|
-
return transformer.apply(type, 0);
|
1236
|
-
}
|
1237
|
-
exports.replaceTypeVarsWithAny = replaceTypeVarsWithAny;
|
1238
1168
|
// During bidirectional type inference for constructors, an "expected type"
|
1239
1169
|
// is used to prepopulate the type var map. This is problematic when the
|
1240
1170
|
// expected type uses TypeVars that are not part of the context of the
|
@@ -1293,16 +1223,16 @@ function getContainerDepth(type, recursionCount = 0) {
|
|
1293
1223
|
return 0;
|
1294
1224
|
}
|
1295
1225
|
let maxChildDepth = 0;
|
1296
|
-
if (type.priv.
|
1297
|
-
type.priv.
|
1226
|
+
if (type.priv.tupleTypeArgs) {
|
1227
|
+
type.priv.tupleTypeArgs.forEach((typeArgInfo) => {
|
1298
1228
|
doForEachSubtype(typeArgInfo.type, (subtype) => {
|
1299
1229
|
const childDepth = getContainerDepth(subtype, recursionCount);
|
1300
1230
|
maxChildDepth = Math.max(childDepth, maxChildDepth);
|
1301
1231
|
});
|
1302
1232
|
});
|
1303
1233
|
}
|
1304
|
-
else if (type.priv.
|
1305
|
-
type.priv.
|
1234
|
+
else if (type.priv.typeArgs) {
|
1235
|
+
type.priv.typeArgs.forEach((typeArg) => {
|
1306
1236
|
doForEachSubtype(typeArg, (subtype) => {
|
1307
1237
|
const childDepth = getContainerDepth(subtype, recursionCount);
|
1308
1238
|
maxChildDepth = Math.max(childDepth, maxChildDepth);
|
@@ -1575,17 +1505,17 @@ exports.addTypeVarsToListIfUnique = addTypeVarsToListIfUnique;
|
|
1575
1505
|
// of unique type variables. For example, if the type is
|
1576
1506
|
// Union[List[Dict[_T1, _T2]], _T1, _T3], the result would be
|
1577
1507
|
// [_T1, _T2, _T3].
|
1578
|
-
function
|
1508
|
+
function getTypeVarArgsRecursive(type, recursionCount = 0) {
|
1579
1509
|
var _a;
|
1580
1510
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
1581
1511
|
return [];
|
1582
1512
|
}
|
1583
1513
|
recursionCount++;
|
1584
1514
|
const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
1585
|
-
if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.
|
1515
|
+
if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArgs) {
|
1586
1516
|
const combinedList = [];
|
1587
|
-
aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.
|
1588
|
-
addTypeVarsToListIfUnique(combinedList,
|
1517
|
+
aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArgs.forEach((typeArg) => {
|
1518
|
+
addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(typeArg, recursionCount));
|
1589
1519
|
});
|
1590
1520
|
return combinedList;
|
1591
1521
|
}
|
@@ -1602,12 +1532,10 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
|
1602
1532
|
}
|
1603
1533
|
if ((0, types_1.isClass)(type)) {
|
1604
1534
|
const combinedList = [];
|
1605
|
-
const typeArgs = type.priv.
|
1606
|
-
? type.priv.tupleTypeArguments.map((e) => e.type)
|
1607
|
-
: type.priv.typeArguments;
|
1535
|
+
const typeArgs = type.priv.tupleTypeArgs ? type.priv.tupleTypeArgs.map((e) => e.type) : type.priv.typeArgs;
|
1608
1536
|
if (typeArgs) {
|
1609
1537
|
typeArgs.forEach((typeArg) => {
|
1610
|
-
addTypeVarsToListIfUnique(combinedList,
|
1538
|
+
addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(typeArg, recursionCount));
|
1611
1539
|
});
|
1612
1540
|
}
|
1613
1541
|
return combinedList;
|
@@ -1615,153 +1543,136 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
|
1615
1543
|
if ((0, types_1.isUnion)(type)) {
|
1616
1544
|
const combinedList = [];
|
1617
1545
|
doForEachSubtype(type, (subtype) => {
|
1618
|
-
addTypeVarsToListIfUnique(combinedList,
|
1546
|
+
addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(subtype, recursionCount));
|
1619
1547
|
});
|
1620
1548
|
return combinedList;
|
1621
1549
|
}
|
1622
1550
|
if ((0, types_1.isFunction)(type)) {
|
1623
1551
|
const combinedList = [];
|
1624
1552
|
for (let i = 0; i < type.shared.parameters.length; i++) {
|
1625
|
-
addTypeVarsToListIfUnique(combinedList,
|
1553
|
+
addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(types_1.FunctionType.getParamType(type, i), recursionCount));
|
1626
1554
|
}
|
1627
1555
|
const returnType = types_1.FunctionType.getEffectiveReturnType(type);
|
1628
1556
|
if (returnType) {
|
1629
|
-
addTypeVarsToListIfUnique(combinedList,
|
1557
|
+
addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(returnType, recursionCount));
|
1630
1558
|
}
|
1631
1559
|
return combinedList;
|
1632
1560
|
}
|
1633
1561
|
return [];
|
1634
1562
|
}
|
1635
|
-
exports.
|
1563
|
+
exports.getTypeVarArgsRecursive = getTypeVarArgsRecursive;
|
1636
1564
|
// Creates a specialized version of the class, filling in any unspecified
|
1637
1565
|
// type arguments with Unknown.
|
1638
1566
|
function specializeClassType(type) {
|
1639
|
-
const
|
1640
|
-
const typeParams = types_1.ClassType.
|
1567
|
+
const solution = new constraintSolution_1.ConstraintSolution();
|
1568
|
+
const typeParams = types_1.ClassType.getTypeParams(type);
|
1641
1569
|
typeParams.forEach((typeParam) => {
|
1642
|
-
|
1570
|
+
solution.setType(typeParam, applySolvedTypeVars(typeParam.shared.defaultType, solution));
|
1643
1571
|
});
|
1644
|
-
return applySolvedTypeVars(type,
|
1572
|
+
return applySolvedTypeVars(type, solution);
|
1645
1573
|
}
|
1646
1574
|
exports.specializeClassType = specializeClassType;
|
1647
1575
|
// Recursively finds all of the type arguments and sets them
|
1648
1576
|
// to the specified srcType.
|
1649
|
-
function
|
1577
|
+
function setTypeArgsRecursive(destType, srcType, constraints, recursionCount = 0) {
|
1650
1578
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
1651
1579
|
return;
|
1652
1580
|
}
|
1653
1581
|
recursionCount++;
|
1654
|
-
if (
|
1582
|
+
if (constraints.isLocked()) {
|
1655
1583
|
return;
|
1656
1584
|
}
|
1657
1585
|
switch (destType.category) {
|
1658
1586
|
case 8 /* TypeCategory.Union */:
|
1659
1587
|
doForEachSubtype(destType, (subtype) => {
|
1660
|
-
|
1588
|
+
setTypeArgsRecursive(subtype, srcType, constraints, recursionCount);
|
1661
1589
|
});
|
1662
1590
|
break;
|
1663
1591
|
case 6 /* TypeCategory.Class */:
|
1664
|
-
if (destType.priv.
|
1665
|
-
destType.priv.
|
1666
|
-
|
1592
|
+
if (destType.priv.typeArgs) {
|
1593
|
+
destType.priv.typeArgs.forEach((typeArg) => {
|
1594
|
+
setTypeArgsRecursive(typeArg, srcType, constraints, recursionCount);
|
1667
1595
|
});
|
1668
1596
|
}
|
1669
|
-
if (destType.priv.
|
1670
|
-
destType.priv.
|
1671
|
-
|
1597
|
+
if (destType.priv.tupleTypeArgs) {
|
1598
|
+
destType.priv.tupleTypeArgs.forEach((typeArg) => {
|
1599
|
+
setTypeArgsRecursive(typeArg.type, srcType, constraints, recursionCount);
|
1672
1600
|
});
|
1673
1601
|
}
|
1674
1602
|
break;
|
1675
1603
|
case 4 /* TypeCategory.Function */:
|
1676
1604
|
if (destType.priv.specializedTypes) {
|
1677
1605
|
destType.priv.specializedTypes.parameterTypes.forEach((paramType) => {
|
1678
|
-
|
1606
|
+
setTypeArgsRecursive(paramType, srcType, constraints, recursionCount);
|
1679
1607
|
});
|
1680
1608
|
if (destType.priv.specializedTypes.returnType) {
|
1681
|
-
|
1609
|
+
setTypeArgsRecursive(destType.priv.specializedTypes.returnType, srcType, constraints, recursionCount);
|
1682
1610
|
}
|
1683
1611
|
}
|
1684
1612
|
else {
|
1685
|
-
destType.shared.parameters.forEach((
|
1686
|
-
|
1613
|
+
destType.shared.parameters.forEach((_, index) => {
|
1614
|
+
setTypeArgsRecursive(types_1.FunctionType.getParamType(destType, index), srcType, constraints, recursionCount);
|
1687
1615
|
});
|
1688
1616
|
if (destType.shared.declaredReturnType) {
|
1689
|
-
|
1617
|
+
setTypeArgsRecursive(destType.shared.declaredReturnType, srcType, constraints, recursionCount);
|
1690
1618
|
}
|
1691
1619
|
}
|
1692
1620
|
break;
|
1693
1621
|
case 5 /* TypeCategory.OverloadedFunction */:
|
1694
1622
|
destType.priv.overloads.forEach((subtype) => {
|
1695
|
-
|
1623
|
+
setTypeArgsRecursive(subtype, srcType, constraints, recursionCount);
|
1696
1624
|
});
|
1697
1625
|
break;
|
1698
1626
|
case 9 /* TypeCategory.TypeVar */:
|
1699
|
-
if (!
|
1700
|
-
|
1627
|
+
if (!constraints.getMainConstraintSet().getTypeVar(destType)) {
|
1628
|
+
constraints.setBounds(destType, srcType);
|
1701
1629
|
}
|
1702
1630
|
break;
|
1703
1631
|
}
|
1704
1632
|
}
|
1705
|
-
exports.
|
1633
|
+
exports.setTypeArgsRecursive = setTypeArgsRecursive;
|
1706
1634
|
// Builds a mapping between type parameters and their specialized
|
1707
1635
|
// types. For example, if the generic type is Dict[_T1, _T2] and the
|
1708
1636
|
// specialized type is Dict[str, int], it returns a map that associates
|
1709
1637
|
// _T1 with str and _T2 with int.
|
1710
|
-
function
|
1711
|
-
const
|
1712
|
-
|
1713
|
-
if (
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
typeVarContext.setTypeVarType(typeParam, convertTypeToParamSpecValue(typeArgType));
|
1734
|
-
}
|
1735
|
-
else if ((0, types_1.isParamSpec)(typeArgType) || (0, types_1.isAnyOrUnknown)(typeArgType)) {
|
1736
|
-
typeVarContext.setTypeVarType(typeParam, convertTypeToParamSpecValue(typeArgType));
|
1737
|
-
}
|
1738
|
-
}
|
1739
|
-
}
|
1740
|
-
else {
|
1741
|
-
if (index >= typeArgs.length) {
|
1742
|
-
typeArgType = types_1.AnyType.create();
|
1743
|
-
}
|
1744
|
-
else {
|
1745
|
-
typeArgType = typeArgs[index];
|
1746
|
-
}
|
1747
|
-
typeVarContext.setTypeVarType(typeParam, typeArgType,
|
1748
|
-
/* narrowBoundNoLiterals */ undefined, typeArgType);
|
1749
|
-
}
|
1638
|
+
function buildSolutionFromSpecializedClass(classType) {
|
1639
|
+
const typeParams = types_1.ClassType.getTypeParams(classType);
|
1640
|
+
let typeArgs;
|
1641
|
+
if (classType.priv.tupleTypeArgs) {
|
1642
|
+
typeArgs = [
|
1643
|
+
convertToInstance(specializeTupleClass(classType, classType.priv.tupleTypeArgs, classType.priv.isTypeArgExplicit,
|
1644
|
+
/* isUnpackedTuple */ true)),
|
1645
|
+
];
|
1646
|
+
}
|
1647
|
+
else {
|
1648
|
+
typeArgs = classType.priv.typeArgs;
|
1649
|
+
}
|
1650
|
+
return buildSolution(typeParams, typeArgs);
|
1651
|
+
}
|
1652
|
+
exports.buildSolutionFromSpecializedClass = buildSolutionFromSpecializedClass;
|
1653
|
+
function buildSolution(typeParams, typeArgs) {
|
1654
|
+
const solution = new constraintSolution_1.ConstraintSolution();
|
1655
|
+
if (!typeArgs) {
|
1656
|
+
return solution;
|
1657
|
+
}
|
1658
|
+
typeParams.forEach((typeParam, index) => {
|
1659
|
+
if (index < typeArgs.length) {
|
1660
|
+
solution.setType(typeParam, typeArgs[index]);
|
1750
1661
|
}
|
1751
1662
|
});
|
1752
|
-
return
|
1663
|
+
return solution;
|
1753
1664
|
}
|
1754
|
-
exports.
|
1665
|
+
exports.buildSolution = buildSolution;
|
1755
1666
|
// Determines the specialized base class type that srcType derives from.
|
1756
1667
|
function specializeForBaseClass(srcType, baseClass) {
|
1757
|
-
const typeParams = types_1.ClassType.
|
1668
|
+
const typeParams = types_1.ClassType.getTypeParams(baseClass);
|
1758
1669
|
// If there are no type parameters for the specified base class,
|
1759
1670
|
// no specialization is required.
|
1760
1671
|
if (typeParams.length === 0) {
|
1761
1672
|
return baseClass;
|
1762
1673
|
}
|
1763
|
-
const
|
1764
|
-
const specializedType = applySolvedTypeVars(baseClass,
|
1674
|
+
const solution = buildSolutionFromSpecializedClass(srcType);
|
1675
|
+
const specializedType = applySolvedTypeVars(baseClass, solution);
|
1765
1676
|
(0, debug_1.assert)((0, types_1.isInstantiableClass)(specializedType));
|
1766
1677
|
return specializedType;
|
1767
1678
|
}
|
@@ -1799,9 +1710,9 @@ function synthesizeTypeVarForSelfCls(classType, isClsParam) {
|
|
1799
1710
|
selfType.shared.isSynthesizedSelf = true;
|
1800
1711
|
selfType.priv.nameWithScope = types_1.TypeVarType.makeNameWithScope(selfType.shared.name, scopeId);
|
1801
1712
|
selfType.priv.scopeId = scopeId;
|
1802
|
-
const boundType = types_1.ClassType.
|
1803
|
-
/*
|
1804
|
-
/*
|
1713
|
+
const boundType = types_1.ClassType.specialize(classType,
|
1714
|
+
/* typeArgs */ undefined,
|
1715
|
+
/* isTypeArgExplicit */ false,
|
1805
1716
|
/* includeSubclasses */ !!classType.priv.includeSubclasses);
|
1806
1717
|
selfType.shared.boundType = types_1.ClassType.cloneAsInstance(boundType);
|
1807
1718
|
return isClsParam ? types_1.TypeVarType.cloneAsInstantiable(selfType) : selfType;
|
@@ -1838,8 +1749,8 @@ function getGeneratorYieldType(declaredReturnType, isAsync) {
|
|
1838
1749
|
['', 'AwaitableGenerator'],
|
1839
1750
|
];
|
1840
1751
|
if (expectedClasses.some((classes) => types_1.ClassType.isBuiltIn(subtype, isAsync ? classes[0] : classes[1]))) {
|
1841
|
-
return subtype.priv.
|
1842
|
-
? subtype.priv.
|
1752
|
+
return subtype.priv.typeArgs && subtype.priv.typeArgs.length >= 1
|
1753
|
+
? subtype.priv.typeArgs[0]
|
1843
1754
|
: types_1.UnknownType.create();
|
1844
1755
|
}
|
1845
1756
|
}
|
@@ -1895,17 +1806,17 @@ function convertToInstance(type, includeSubclasses = true) {
|
|
1895
1806
|
// Handle type[x] as a special case.
|
1896
1807
|
if (types_1.ClassType.isBuiltIn(subtype, 'type')) {
|
1897
1808
|
if (types_1.TypeBase.isInstance(subtype)) {
|
1898
|
-
if (!subtype.priv.
|
1809
|
+
if (!subtype.priv.typeArgs || subtype.priv.typeArgs.length < 1) {
|
1899
1810
|
return types_1.UnknownType.create();
|
1900
1811
|
}
|
1901
1812
|
else {
|
1902
|
-
return subtype.priv.
|
1813
|
+
return subtype.priv.typeArgs[0];
|
1903
1814
|
}
|
1904
1815
|
}
|
1905
1816
|
else {
|
1906
|
-
if (subtype.priv.
|
1907
|
-
if (!(0, types_1.isAnyOrUnknown)(subtype.priv.
|
1908
|
-
return convertToInstantiable(subtype.priv.
|
1817
|
+
if (subtype.priv.typeArgs && subtype.priv.typeArgs.length > 0) {
|
1818
|
+
if (!(0, types_1.isAnyOrUnknown)(subtype.priv.typeArgs[0])) {
|
1819
|
+
return convertToInstantiable(subtype.priv.typeArgs[0]);
|
1909
1820
|
}
|
1910
1821
|
}
|
1911
1822
|
}
|
@@ -1944,7 +1855,7 @@ function convertToInstance(type, includeSubclasses = true) {
|
|
1944
1855
|
// Copy over any type alias information.
|
1945
1856
|
const aliasInfo = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo;
|
1946
1857
|
if (aliasInfo && type !== result) {
|
1947
|
-
result = types_1.TypeBase.cloneForTypeAlias(result, aliasInfo
|
1858
|
+
result = types_1.TypeBase.cloneForTypeAlias(result, aliasInfo);
|
1948
1859
|
}
|
1949
1860
|
if (type !== result && includeSubclasses) {
|
1950
1861
|
// Cache the converted value for next time.
|
@@ -2131,8 +2042,8 @@ function isPartlyUnknown(type, recursionCount = 0) {
|
|
2131
2042
|
// If this is a generic type alias, see if any of its type arguments
|
2132
2043
|
// are either unspecified or are partially known.
|
2133
2044
|
const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
2134
|
-
if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.
|
2135
|
-
if (aliasInfo.
|
2045
|
+
if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArgs) {
|
2046
|
+
if (aliasInfo.typeArgs.some((typeArg) => isPartlyUnknown(typeArg, recursionCount))) {
|
2136
2047
|
return true;
|
2137
2048
|
}
|
2138
2049
|
}
|
@@ -2149,7 +2060,7 @@ function isPartlyUnknown(type, recursionCount = 0) {
|
|
2149
2060
|
return false;
|
2150
2061
|
}
|
2151
2062
|
if (!types_1.ClassType.isPseudoGenericClass(type)) {
|
2152
|
-
const typeArgs = ((_b = type.priv.
|
2063
|
+
const typeArgs = ((_b = type.priv.tupleTypeArgs) === null || _b === void 0 ? void 0 : _b.map((t) => t.type)) || type.priv.typeArgs;
|
2153
2064
|
if (typeArgs) {
|
2154
2065
|
for (const argType of typeArgs) {
|
2155
2066
|
if (isPartlyUnknown(argType, recursionCount)) {
|
@@ -2170,7 +2081,7 @@ function isPartlyUnknown(type, recursionCount = 0) {
|
|
2170
2081
|
for (let i = 0; i < type.shared.parameters.length; i++) {
|
2171
2082
|
// Ignore parameters such as "*" that have no name.
|
2172
2083
|
if (type.shared.parameters[i].name) {
|
2173
|
-
const paramType = types_1.FunctionType.
|
2084
|
+
const paramType = types_1.FunctionType.getParamType(type, i);
|
2174
2085
|
if (isPartlyUnknown(paramType, recursionCount)) {
|
2175
2086
|
return true;
|
2176
2087
|
}
|
@@ -2190,13 +2101,11 @@ exports.isPartlyUnknown = isPartlyUnknown;
|
|
2190
2101
|
// that is a union, it "explodes" the class into a union of classes with
|
2191
2102
|
// each element of the union - e.g. Foo[A | B] becomes Foo[A] | Foo[B].
|
2192
2103
|
function explodeGenericClass(classType) {
|
2193
|
-
if (!classType.priv.
|
2194
|
-
classType.priv.typeArguments.length !== 1 ||
|
2195
|
-
!(0, types_1.isUnion)(classType.priv.typeArguments[0])) {
|
2104
|
+
if (!classType.priv.typeArgs || classType.priv.typeArgs.length !== 1 || !(0, types_1.isUnion)(classType.priv.typeArgs[0])) {
|
2196
2105
|
return classType;
|
2197
2106
|
}
|
2198
|
-
return (0, types_1.combineTypes)(classType.priv.
|
2199
|
-
return types_1.ClassType.
|
2107
|
+
return (0, types_1.combineTypes)(classType.priv.typeArgs[0].priv.subtypes.map((subtype) => {
|
2108
|
+
return types_1.ClassType.specialize(classType, [subtype]);
|
2200
2109
|
}));
|
2201
2110
|
}
|
2202
2111
|
exports.explodeGenericClass = explodeGenericClass;
|
@@ -2219,10 +2128,10 @@ function combineSameSizedTuples(type, tupleType) {
|
|
2219
2128
|
// tuple with a known size. This includes named tuples.
|
2220
2129
|
tupleClass = subtype.shared.mro.find((mroClass) => (0, types_1.isClass)(mroClass) && isTupleClass(mroClass) && !isUnboundedTupleClass(mroClass));
|
2221
2130
|
}
|
2222
|
-
if (tupleClass && (0, types_1.isClass)(tupleClass) && tupleClass.priv.
|
2131
|
+
if (tupleClass && (0, types_1.isClass)(tupleClass) && tupleClass.priv.tupleTypeArgs) {
|
2223
2132
|
if (tupleEntries) {
|
2224
|
-
if (tupleEntries.length === tupleClass.priv.
|
2225
|
-
tupleClass.priv.
|
2133
|
+
if (tupleEntries.length === tupleClass.priv.tupleTypeArgs.length) {
|
2134
|
+
tupleClass.priv.tupleTypeArgs.forEach((entry, index) => {
|
2226
2135
|
tupleEntries[index].push(entry.type);
|
2227
2136
|
});
|
2228
2137
|
}
|
@@ -2231,7 +2140,7 @@ function combineSameSizedTuples(type, tupleType) {
|
|
2231
2140
|
}
|
2232
2141
|
}
|
2233
2142
|
else {
|
2234
|
-
tupleEntries = tupleClass.priv.
|
2143
|
+
tupleEntries = tupleClass.priv.tupleTypeArgs.map((entry) => [entry.type]);
|
2235
2144
|
}
|
2236
2145
|
}
|
2237
2146
|
else {
|
@@ -2250,18 +2159,21 @@ function combineSameSizedTuples(type, tupleType) {
|
|
2250
2159
|
})));
|
2251
2160
|
}
|
2252
2161
|
exports.combineSameSizedTuples = combineSameSizedTuples;
|
2253
|
-
|
2254
|
-
|
2255
|
-
|
2256
|
-
function specializeTupleClass(classType, typeArgs, isTypeArgumentExplicit = true, isUnpackedTuple = false) {
|
2257
|
-
const combinedTupleType = (0, types_1.combineTypes)(typeArgs.map((t) => {
|
2258
|
-
if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedVariadicTypeVar)(t.type)) {
|
2162
|
+
function combineTupleTypeArgs(typeArgs) {
|
2163
|
+
return (0, types_1.combineTypes)(typeArgs.map((t) => {
|
2164
|
+
if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedTypeVarTuple)(t.type)) {
|
2259
2165
|
// Treat the unpacked TypeVarTuple as a union.
|
2260
2166
|
return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
|
2261
2167
|
}
|
2262
2168
|
return t.type;
|
2263
2169
|
}));
|
2264
|
-
|
2170
|
+
}
|
2171
|
+
exports.combineTupleTypeArgs = combineTupleTypeArgs;
|
2172
|
+
// Tuples require special handling for specialization. This method computes
|
2173
|
+
// the "effective" type argument, which is a union of the variadic type
|
2174
|
+
// arguments.
|
2175
|
+
function specializeTupleClass(classType, typeArgs, isTypeArgExplicit = true, isUnpackedTuple = false) {
|
2176
|
+
const clonedClassType = types_1.ClassType.specialize(classType, [combineTupleTypeArgs(typeArgs)], isTypeArgExplicit,
|
2265
2177
|
/* includeSubclasses */ undefined, typeArgs);
|
2266
2178
|
if (isUnpackedTuple) {
|
2267
2179
|
clonedClassType.priv.isUnpacked = true;
|
@@ -2269,9 +2181,9 @@ function specializeTupleClass(classType, typeArgs, isTypeArgumentExplicit = true
|
|
2269
2181
|
return clonedClassType;
|
2270
2182
|
}
|
2271
2183
|
exports.specializeTupleClass = specializeTupleClass;
|
2272
|
-
function
|
2273
|
-
if ((0, types_1.isClassInstance)(type) && isTupleClass(type) && type.priv.
|
2274
|
-
return (0, types_1.combineTypes)(type.priv.
|
2184
|
+
function _expandUnpackedTypeVarTupleUnion(type) {
|
2185
|
+
if ((0, types_1.isClassInstance)(type) && isTupleClass(type) && type.priv.tupleTypeArgs && type.priv.isUnpacked) {
|
2186
|
+
return (0, types_1.combineTypes)(type.priv.tupleTypeArgs.map((t) => t.type));
|
2275
2187
|
}
|
2276
2188
|
return type;
|
2277
2189
|
}
|
@@ -2281,20 +2193,20 @@ function getGeneratorTypeArgs(returnType) {
|
|
2281
2193
|
var _a;
|
2282
2194
|
if ((0, types_1.isClassInstance)(returnType)) {
|
2283
2195
|
if (types_1.ClassType.isBuiltIn(returnType, ['Generator', 'AsyncGenerator'])) {
|
2284
|
-
return returnType.priv.
|
2196
|
+
return returnType.priv.typeArgs;
|
2285
2197
|
}
|
2286
2198
|
else if (types_1.ClassType.isBuiltIn(returnType, 'AwaitableGenerator')) {
|
2287
2199
|
// AwaitableGenerator has four type arguments, and the first 3
|
2288
2200
|
// correspond to the generator.
|
2289
|
-
return (_a = returnType.priv.
|
2201
|
+
return (_a = returnType.priv.typeArgs) === null || _a === void 0 ? void 0 : _a.slice(0, 3);
|
2290
2202
|
}
|
2291
2203
|
}
|
2292
2204
|
return undefined;
|
2293
2205
|
}
|
2294
2206
|
exports.getGeneratorTypeArgs = getGeneratorTypeArgs;
|
2295
|
-
function
|
2296
|
-
if (classType.shared.
|
2297
|
-
const firstTypeParam = classType.shared.
|
2207
|
+
function requiresTypeArgs(classType) {
|
2208
|
+
if (classType.shared.typeParams.length > 0) {
|
2209
|
+
const firstTypeParam = classType.shared.typeParams[0];
|
2298
2210
|
// If there are type parameters, type arguments are needed.
|
2299
2211
|
// The exception is if type parameters have been synthesized
|
2300
2212
|
// for classes that have untyped constructors.
|
@@ -2309,7 +2221,7 @@ function requiresTypeArguments(classType) {
|
|
2309
2221
|
return true;
|
2310
2222
|
}
|
2311
2223
|
// There are a few built-in special classes that require
|
2312
|
-
// type arguments even though
|
2224
|
+
// type arguments even though typeParams is empty.
|
2313
2225
|
if (types_1.ClassType.isSpecialBuiltIn(classType)) {
|
2314
2226
|
const specialClasses = [
|
2315
2227
|
'Tuple',
|
@@ -2329,7 +2241,7 @@ function requiresTypeArguments(classType) {
|
|
2329
2241
|
}
|
2330
2242
|
return false;
|
2331
2243
|
}
|
2332
|
-
exports.
|
2244
|
+
exports.requiresTypeArgs = requiresTypeArgs;
|
2333
2245
|
function requiresSpecialization(type, options, recursionCount = 0) {
|
2334
2246
|
var _a;
|
2335
2247
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
@@ -2362,17 +2274,17 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
|
|
2362
2274
|
if (types_1.ClassType.isPseudoGenericClass(type) && (options === null || options === void 0 ? void 0 : options.ignorePseudoGeneric)) {
|
2363
2275
|
return false;
|
2364
2276
|
}
|
2365
|
-
if (!type.priv.
|
2277
|
+
if (!type.priv.isTypeArgExplicit && (options === null || options === void 0 ? void 0 : options.ignoreImplicitTypeArgs)) {
|
2366
2278
|
return false;
|
2367
2279
|
}
|
2368
|
-
if (type.priv.
|
2369
|
-
return type.priv.
|
2280
|
+
if (type.priv.typeArgs) {
|
2281
|
+
return type.priv.typeArgs.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
|
2370
2282
|
}
|
2371
|
-
return types_1.ClassType.
|
2283
|
+
return types_1.ClassType.getTypeParams(type).length > 0;
|
2372
2284
|
}
|
2373
2285
|
case 4 /* TypeCategory.Function */: {
|
2374
2286
|
for (let i = 0; i < type.shared.parameters.length; i++) {
|
2375
|
-
if (requiresSpecialization(types_1.FunctionType.
|
2287
|
+
if (requiresSpecialization(types_1.FunctionType.getParamType(type, i), options, recursionCount)) {
|
2376
2288
|
return true;
|
2377
2289
|
}
|
2378
2290
|
}
|
@@ -2400,7 +2312,7 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
|
|
2400
2312
|
case 9 /* TypeCategory.TypeVar */: {
|
2401
2313
|
// Most TypeVar types need to be specialized.
|
2402
2314
|
if (!type.shared.recursiveAlias) {
|
2403
|
-
if (
|
2315
|
+
if (types_1.TypeVarType.isSelf(type) && (options === null || options === void 0 ? void 0 : options.ignoreSelf)) {
|
2404
2316
|
return false;
|
2405
2317
|
}
|
2406
2318
|
return true;
|
@@ -2408,8 +2320,8 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
|
|
2408
2320
|
// If this is a recursive type alias, it may need to be specialized
|
2409
2321
|
// if it has generic type arguments.
|
2410
2322
|
const aliasInfo = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo;
|
2411
|
-
if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.
|
2412
|
-
return aliasInfo.
|
2323
|
+
if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArgs) {
|
2324
|
+
return aliasInfo.typeArgs.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
|
2413
2325
|
}
|
2414
2326
|
}
|
2415
2327
|
}
|
@@ -2430,25 +2342,25 @@ function combineVariances(variance1, variance2) {
|
|
2430
2342
|
exports.combineVariances = combineVariances;
|
2431
2343
|
// Determines if the variance of the type argument for a generic class is compatible
|
2432
2344
|
// With the declared variance of the corresponding type parameter.
|
2433
|
-
function
|
2345
|
+
function isVarianceOfTypeArgCompatible(type, typeParamVariance) {
|
2434
2346
|
if (typeParamVariance === 1 /* Variance.Unknown */ || typeParamVariance === 0 /* Variance.Auto */) {
|
2435
2347
|
return true;
|
2436
2348
|
}
|
2437
|
-
if ((0, types_1.isTypeVar)(type) && !
|
2349
|
+
if ((0, types_1.isTypeVar)(type) && !(0, types_1.isParamSpec)(type) && !(0, types_1.isTypeVarTuple)(type)) {
|
2438
2350
|
const typeArgVariance = type.shared.declaredVariance;
|
2439
2351
|
if (typeArgVariance === 4 /* Variance.Contravariant */ || typeArgVariance === 3 /* Variance.Covariant */) {
|
2440
2352
|
return typeArgVariance === typeParamVariance;
|
2441
2353
|
}
|
2442
2354
|
}
|
2443
2355
|
else if ((0, types_1.isClassInstance)(type)) {
|
2444
|
-
if (type.shared.
|
2445
|
-
return type.shared.
|
2356
|
+
if (type.shared.typeParams && type.shared.typeParams.length > 0) {
|
2357
|
+
return type.shared.typeParams.every((typeParam, index) => {
|
2446
2358
|
let typeArgType;
|
2447
|
-
if (
|
2359
|
+
if ((0, types_1.isParamSpec)(typeParam) || (0, types_1.isTypeVarTuple)(typeParam)) {
|
2448
2360
|
return true;
|
2449
2361
|
}
|
2450
|
-
if (type.priv.
|
2451
|
-
typeArgType = type.priv.
|
2362
|
+
if (type.priv.typeArgs && index < type.priv.typeArgs.length) {
|
2363
|
+
typeArgType = type.priv.typeArgs[index];
|
2452
2364
|
}
|
2453
2365
|
const declaredVariance = typeParam.shared.declaredVariance;
|
2454
2366
|
if (declaredVariance === 0 /* Variance.Auto */) {
|
@@ -2470,13 +2382,13 @@ function isVarianceOfTypeArgumentCompatible(type, typeParamVariance) {
|
|
2470
2382
|
effectiveVariance = 3 /* Variance.Covariant */;
|
2471
2383
|
}
|
2472
2384
|
}
|
2473
|
-
return
|
2385
|
+
return isVarianceOfTypeArgCompatible(typeArgType !== null && typeArgType !== void 0 ? typeArgType : types_1.UnknownType.create(), effectiveVariance);
|
2474
2386
|
});
|
2475
2387
|
}
|
2476
2388
|
}
|
2477
2389
|
return true;
|
2478
2390
|
}
|
2479
|
-
exports.
|
2391
|
+
exports.isVarianceOfTypeArgCompatible = isVarianceOfTypeArgCompatible;
|
2480
2392
|
// Computes the method resolution ordering for a class whose base classes
|
2481
2393
|
// have already been filled in. The algorithm for computing MRO is described
|
2482
2394
|
// here: https://www.python.org/download/releases/2.3/mro/. It returns true
|
@@ -2501,8 +2413,8 @@ function computeMroLinearization(classType) {
|
|
2501
2413
|
if (classType.shared.baseClasses.some((innerBaseClass, innerIndex) => {
|
2502
2414
|
return (innerIndex > index &&
|
2503
2415
|
(0, types_1.isInstantiableClass)(innerBaseClass) &&
|
2504
|
-
innerBaseClass.priv.
|
2505
|
-
innerBaseClass.priv.
|
2416
|
+
innerBaseClass.priv.typeArgs &&
|
2417
|
+
innerBaseClass.priv.isTypeArgExplicit);
|
2506
2418
|
})) {
|
2507
2419
|
return false;
|
2508
2420
|
}
|
@@ -2514,9 +2426,9 @@ function computeMroLinearization(classType) {
|
|
2514
2426
|
const classListsToMerge = [];
|
2515
2427
|
filteredBaseClasses.forEach((baseClass) => {
|
2516
2428
|
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
2517
|
-
const
|
2429
|
+
const solution = buildSolutionFromSpecializedClass(baseClass);
|
2518
2430
|
classListsToMerge.push(baseClass.shared.mro.map((mroClass) => {
|
2519
|
-
return applySolvedTypeVars(mroClass,
|
2431
|
+
return applySolvedTypeVars(mroClass, solution);
|
2520
2432
|
}));
|
2521
2433
|
}
|
2522
2434
|
else {
|
@@ -2524,12 +2436,12 @@ function computeMroLinearization(classType) {
|
|
2524
2436
|
}
|
2525
2437
|
});
|
2526
2438
|
classListsToMerge.push(filteredBaseClasses.map((baseClass) => {
|
2527
|
-
const
|
2528
|
-
return applySolvedTypeVars(baseClass,
|
2439
|
+
const solution = buildSolutionFromSpecializedClass(classType);
|
2440
|
+
return applySolvedTypeVars(baseClass, solution);
|
2529
2441
|
}));
|
2530
2442
|
// The first class in the MRO is the class itself.
|
2531
|
-
const
|
2532
|
-
let specializedClassType = applySolvedTypeVars(classType,
|
2443
|
+
const solution = buildSolutionFromSpecializedClass(classType);
|
2444
|
+
let specializedClassType = applySolvedTypeVars(classType, solution);
|
2533
2445
|
if (!(0, types_1.isClass)(specializedClassType) && !(0, types_1.isAnyOrUnknown)(specializedClassType)) {
|
2534
2446
|
specializedClassType = types_1.UnknownType.create();
|
2535
2447
|
}
|
@@ -2616,14 +2528,14 @@ function getDeclaringModulesForType(type) {
|
|
2616
2528
|
return moduleList;
|
2617
2529
|
}
|
2618
2530
|
exports.getDeclaringModulesForType = getDeclaringModulesForType;
|
2619
|
-
function
|
2531
|
+
function convertNodeToArg(node) {
|
2620
2532
|
return {
|
2621
|
-
|
2533
|
+
argCategory: node.d.argCategory,
|
2622
2534
|
name: node.d.name,
|
2623
2535
|
valueExpression: node.d.valueExpr,
|
2624
2536
|
};
|
2625
2537
|
}
|
2626
|
-
exports.
|
2538
|
+
exports.convertNodeToArg = convertNodeToArg;
|
2627
2539
|
function addDeclaringModuleNamesForType(type, moduleList, recursionCount = 0) {
|
2628
2540
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
2629
2541
|
return;
|
@@ -2672,64 +2584,53 @@ function convertTypeToParamSpecValue(type) {
|
|
2672
2584
|
return newFunction;
|
2673
2585
|
}
|
2674
2586
|
if ((0, types_1.isFunction)(type)) {
|
2587
|
+
// If it's already a ParamSpecValue, return it as is.
|
2588
|
+
if (types_1.FunctionType.isParamSpecValue(type)) {
|
2589
|
+
return type;
|
2590
|
+
}
|
2675
2591
|
const newFunction = types_1.FunctionType.createInstance('', '', '', type.shared.flags | 65536 /* FunctionTypeFlags.ParamSpecValue */, type.shared.docString);
|
2676
2592
|
newFunction.shared.deprecatedMessage = type.shared.deprecatedMessage;
|
2677
2593
|
type.shared.parameters.forEach((param, index) => {
|
2678
|
-
types_1.FunctionType.
|
2594
|
+
types_1.FunctionType.addParam(newFunction, types_1.FunctionParam.create(param.category, types_1.FunctionType.getParamType(type, index), param.flags, param.name, types_1.FunctionType.getParamDefaultType(type, index)));
|
2679
2595
|
});
|
2680
|
-
|
2681
|
-
newFunction.priv.higherOrderTypeVarScopeIds = [...type.priv.higherOrderTypeVarScopeIds];
|
2682
|
-
newFunction.shared.typeVarScopeId = newFunction.priv.higherOrderTypeVarScopeIds.pop();
|
2683
|
-
}
|
2596
|
+
newFunction.shared.typeVarScopeId = type.shared.typeVarScopeId;
|
2684
2597
|
newFunction.priv.constructorTypeVarScopeId = type.priv.constructorTypeVarScopeId;
|
2685
2598
|
return newFunction;
|
2686
2599
|
}
|
2687
|
-
return
|
2600
|
+
return types_1.ParamSpecType.getUnknown();
|
2688
2601
|
}
|
2689
2602
|
exports.convertTypeToParamSpecValue = convertTypeToParamSpecValue;
|
2690
2603
|
// Converts a FunctionType into a ParamSpec if it consists only of
|
2691
2604
|
// (* args: P.args, ** kwargs: P.kwargs). Otherwise returns the original type.
|
2692
|
-
function
|
2605
|
+
function simplifyFunctionToParamSpec(type) {
|
2693
2606
|
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
|
2694
2607
|
const withoutParamSpec = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(type);
|
2695
|
-
let
|
2608
|
+
let hasParams = withoutParamSpec.shared.parameters.length > 0;
|
2696
2609
|
if (withoutParamSpec.shared.parameters.length === 1) {
|
2697
2610
|
// If the ParamSpec has a position-only separator as its only parameter,
|
2698
2611
|
// treat it as though there are no parameters.
|
2699
2612
|
const onlyParam = withoutParamSpec.shared.parameters[0];
|
2700
2613
|
if ((0, types_1.isPositionOnlySeparator)(onlyParam)) {
|
2701
|
-
|
2614
|
+
hasParams = false;
|
2702
2615
|
}
|
2703
2616
|
}
|
2704
2617
|
// Can we simplify it to just a paramSpec?
|
2705
|
-
if (!
|
2618
|
+
if (!hasParams && paramSpec) {
|
2706
2619
|
return paramSpec;
|
2707
2620
|
}
|
2708
|
-
|
2709
|
-
const functionType = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | withoutParamSpec.shared.flags);
|
2710
|
-
types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.shared.typeVarScopeId);
|
2711
|
-
types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.priv.higherOrderTypeVarScopeIds);
|
2712
|
-
functionType.priv.constructorTypeVarScopeId = withoutParamSpec.priv.constructorTypeVarScopeId;
|
2713
|
-
withoutParamSpec.shared.parameters.forEach((entry, index) => {
|
2714
|
-
types_1.FunctionType.addParameter(functionType, types_1.FunctionParam.create(entry.category, types_1.FunctionType.getEffectiveParameterType(withoutParamSpec, index), (entry.flags & types_1.FunctionParamFlags.NameSynthesized) | types_1.FunctionParamFlags.TypeDeclared, entry.name, entry.defaultType));
|
2715
|
-
});
|
2716
|
-
if (paramSpec) {
|
2717
|
-
types_1.FunctionType.addParamSpecVariadics(functionType, paramSpec);
|
2718
|
-
}
|
2719
|
-
functionType.shared.docString = withoutParamSpec.shared.docString;
|
2720
|
-
functionType.shared.deprecatedMessage = withoutParamSpec.shared.deprecatedMessage;
|
2721
|
-
functionType.shared.methodClass = withoutParamSpec.shared.methodClass;
|
2722
|
-
return functionType;
|
2621
|
+
return type;
|
2723
2622
|
}
|
2724
|
-
exports.
|
2623
|
+
exports.simplifyFunctionToParamSpec = simplifyFunctionToParamSpec;
|
2725
2624
|
// Recursively walks a type and calls a callback for each TypeVar, allowing
|
2726
2625
|
// it to be replaced with something else.
|
2727
2626
|
class TypeVarTransformer {
|
2728
2627
|
constructor() {
|
2729
|
-
this._isTransformingTypeArg = false;
|
2730
2628
|
this._pendingTypeVarTransformations = new Set();
|
2731
2629
|
this._pendingFunctionTransformations = [];
|
2732
2630
|
}
|
2631
|
+
get pendingTypeVarTransformations() {
|
2632
|
+
return this._pendingTypeVarTransformations;
|
2633
|
+
}
|
2733
2634
|
apply(type, recursionCount) {
|
2734
2635
|
var _a, _b, _c;
|
2735
2636
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
@@ -2758,11 +2659,11 @@ class TypeVarTransformer {
|
|
2758
2659
|
// type aliases.
|
2759
2660
|
const aliasInfo = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo;
|
2760
2661
|
if (type.shared.recursiveAlias) {
|
2761
|
-
if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.
|
2662
|
+
if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArgs)) {
|
2762
2663
|
return type;
|
2763
2664
|
}
|
2764
2665
|
let requiresUpdate = false;
|
2765
|
-
const typeArgs = aliasInfo.
|
2666
|
+
const typeArgs = aliasInfo.typeArgs.map((typeArg) => {
|
2766
2667
|
const replacementType = this.apply(typeArg, recursionCount);
|
2767
2668
|
if (replacementType !== typeArg) {
|
2768
2669
|
requiresUpdate = true;
|
@@ -2770,7 +2671,7 @@ class TypeVarTransformer {
|
|
2770
2671
|
return replacementType;
|
2771
2672
|
});
|
2772
2673
|
if (requiresUpdate) {
|
2773
|
-
return types_1.TypeBase.cloneForTypeAlias(type,
|
2674
|
+
return types_1.TypeBase.cloneForTypeAlias(type, { ...aliasInfo, typeArgs });
|
2774
2675
|
}
|
2775
2676
|
return type;
|
2776
2677
|
}
|
@@ -2779,43 +2680,36 @@ class TypeVarTransformer {
|
|
2779
2680
|
// type variables in the same scope recursively by setting it the scope in the
|
2780
2681
|
// _pendingTypeVarTransformations set.
|
2781
2682
|
if (!this._isTypeVarScopePending(type.priv.scopeId)) {
|
2782
|
-
|
2783
|
-
|
2784
|
-
|
2785
|
-
|
2683
|
+
let paramSpecAccess;
|
2684
|
+
// If this is a ParamSpec with a ".args" or ".kwargs" access, strip
|
2685
|
+
// it off for now. We'll add it back later if appropriate.
|
2686
|
+
if ((0, types_1.isParamSpec)(type) && type.priv.paramSpecAccess) {
|
2687
|
+
paramSpecAccess = type.priv.paramSpecAccess;
|
2688
|
+
type = types_1.TypeVarType.cloneForParamSpecAccess(type, /* access */ undefined);
|
2689
|
+
}
|
2690
|
+
replacementType = (_c = this.transformTypeVar(type, recursionCount)) !== null && _c !== void 0 ? _c : type;
|
2691
|
+
if ((0, types_1.isParamSpec)(type) && replacementType !== type) {
|
2692
|
+
replacementType = simplifyFunctionToParamSpec(convertTypeToParamSpecValue(replacementType));
|
2693
|
+
}
|
2694
|
+
// If the original type was a ParamSpec with a ".args" or ".kwargs" access,
|
2695
|
+
// preserve that information in the transformed type.
|
2696
|
+
if (paramSpecAccess) {
|
2697
|
+
if ((0, types_1.isParamSpec)(replacementType)) {
|
2698
|
+
replacementType = types_1.TypeVarType.cloneForParamSpecAccess(replacementType, paramSpecAccess);
|
2786
2699
|
}
|
2787
|
-
|
2788
|
-
|
2789
|
-
const paramSpecType = convertParamSpecValueToType(paramSpecValue);
|
2790
|
-
if (type.priv.paramSpecAccess) {
|
2791
|
-
if ((0, types_1.isParamSpec)(paramSpecType)) {
|
2792
|
-
replacementType = types_1.TypeVarType.cloneForParamSpecAccess(paramSpecType, type.priv.paramSpecAccess);
|
2793
|
-
}
|
2794
|
-
else {
|
2795
|
-
replacementType = types_1.UnknownType.create();
|
2796
|
-
}
|
2797
|
-
}
|
2798
|
-
else {
|
2799
|
-
replacementType = paramSpecType;
|
2800
|
-
}
|
2700
|
+
else {
|
2701
|
+
replacementType = types_1.UnknownType.create();
|
2801
2702
|
}
|
2802
2703
|
}
|
2803
|
-
|
2804
|
-
|
2805
|
-
|
2806
|
-
|
2807
|
-
|
2808
|
-
|
2809
|
-
|
2810
|
-
|
2811
|
-
|
2812
|
-
}
|
2813
|
-
}
|
2814
|
-
// If we're transforming a variadic type variable that was in a union,
|
2815
|
-
// expand the union types.
|
2816
|
-
if ((0, types_1.isVariadicTypeVar)(type) && type.priv.isVariadicInUnion) {
|
2817
|
-
replacementType = _expandVariadicUnpackedUnion(replacementType);
|
2818
|
-
}
|
2704
|
+
// If we're transforming a TypeVarTuple that was in a union,
|
2705
|
+
// expand the union types.
|
2706
|
+
if ((0, types_1.isTypeVarTuple)(type) && type.priv.isInUnion) {
|
2707
|
+
replacementType = _expandUnpackedTypeVarTupleUnion(replacementType);
|
2708
|
+
}
|
2709
|
+
if (type.priv.scopeId) {
|
2710
|
+
this._pendingTypeVarTransformations.add(type.priv.scopeId);
|
2711
|
+
replacementType = this.apply(replacementType, recursionCount);
|
2712
|
+
this._pendingTypeVarTransformations.delete(type.priv.scopeId);
|
2819
2713
|
}
|
2820
2714
|
}
|
2821
2715
|
return replacementType;
|
@@ -2823,12 +2717,12 @@ class TypeVarTransformer {
|
|
2823
2717
|
if ((0, types_1.isUnion)(type)) {
|
2824
2718
|
const newUnionType = mapSubtypes(type, (subtype) => {
|
2825
2719
|
let transformedType = this.apply(subtype, recursionCount);
|
2826
|
-
// If we're transforming a
|
2827
|
-
// combine the individual types within the
|
2828
|
-
if ((0, types_1.
|
2720
|
+
// If we're transforming a TypeVarTuple within a union,
|
2721
|
+
// combine the individual types within the TypeVarTuple.
|
2722
|
+
if ((0, types_1.isTypeVarTuple)(subtype) && !(0, types_1.isTypeVarTuple)(transformedType)) {
|
2829
2723
|
const subtypesToCombine = [];
|
2830
2724
|
doForEachSubtype(transformedType, (transformedSubtype) => {
|
2831
|
-
subtypesToCombine.push(
|
2725
|
+
subtypesToCombine.push(_expandUnpackedTypeVarTupleUnion(transformedSubtype));
|
2832
2726
|
});
|
2833
2727
|
transformedType = (0, types_1.combineTypes)(subtypesToCombine);
|
2834
2728
|
}
|
@@ -2885,13 +2779,10 @@ class TypeVarTransformer {
|
|
2885
2779
|
transformTupleTypeVar(paramSpec, recursionCount) {
|
2886
2780
|
return undefined;
|
2887
2781
|
}
|
2888
|
-
transformParamSpec(paramSpec, recursionCount) {
|
2889
|
-
return undefined;
|
2890
|
-
}
|
2891
2782
|
transformUnionSubtype(preTransform, postTransform, recursionCount) {
|
2892
2783
|
return postTransform;
|
2893
2784
|
}
|
2894
|
-
|
2785
|
+
doForEachConstraintSet(callback) {
|
2895
2786
|
// By default, simply return the result of the callback. Subclasses
|
2896
2787
|
// can override this method as they see fit.
|
2897
2788
|
return callback();
|
@@ -2899,27 +2790,26 @@ class TypeVarTransformer {
|
|
2899
2790
|
transformGenericTypeAlias(type, recursionCount) {
|
2900
2791
|
var _a;
|
2901
2792
|
const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
2902
|
-
if (!aliasInfo || !aliasInfo.
|
2793
|
+
if (!aliasInfo || !aliasInfo.typeParams || !aliasInfo.typeArgs) {
|
2903
2794
|
return type;
|
2904
2795
|
}
|
2905
2796
|
let requiresUpdate = false;
|
2906
|
-
const newTypeArgs = aliasInfo.
|
2797
|
+
const newTypeArgs = aliasInfo.typeArgs.map((typeArg) => {
|
2907
2798
|
const updatedType = this.apply(typeArg, recursionCount);
|
2908
2799
|
if (type !== updatedType) {
|
2909
2800
|
requiresUpdate = true;
|
2910
2801
|
}
|
2911
2802
|
return updatedType;
|
2912
2803
|
});
|
2913
|
-
return requiresUpdate
|
2914
|
-
? types_1.TypeBase.cloneForTypeAlias(type, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParameters, newTypeArgs)
|
2915
|
-
: type;
|
2804
|
+
return requiresUpdate ? types_1.TypeBase.cloneForTypeAlias(type, { ...aliasInfo, typeArgs: newTypeArgs }) : type;
|
2916
2805
|
}
|
2917
2806
|
transformConditionalType(type, recursionCount) {
|
2918
2807
|
// By default, do not perform any transform.
|
2919
2808
|
return type;
|
2920
2809
|
}
|
2921
2810
|
transformTypeVarsInClassType(classType, recursionCount) {
|
2922
|
-
|
2811
|
+
var _a;
|
2812
|
+
const typeParams = types_1.ClassType.getTypeParams(classType);
|
2923
2813
|
// Handle the common case where the class has no type parameters.
|
2924
2814
|
if (typeParams.length === 0 &&
|
2925
2815
|
!types_1.ClassType.isSpecialBuiltIn(classType) &&
|
@@ -2929,33 +2819,21 @@ class TypeVarTransformer {
|
|
2929
2819
|
let newTypeArgs;
|
2930
2820
|
let newTupleTypeArgs;
|
2931
2821
|
let specializationNeeded = false;
|
2932
|
-
const transformParamSpec = (paramSpec) => {
|
2933
|
-
const paramSpecValue = this.transformParamSpec(paramSpec, recursionCount);
|
2934
|
-
if (paramSpecValue) {
|
2935
|
-
specializationNeeded = true;
|
2936
|
-
return convertParamSpecValueToType(paramSpecValue);
|
2937
|
-
}
|
2938
|
-
else {
|
2939
|
-
return paramSpec;
|
2940
|
-
}
|
2941
|
-
};
|
2942
|
-
const wasTransformingTypeArg = this._isTransformingTypeArg;
|
2943
|
-
this._isTransformingTypeArg = true;
|
2944
2822
|
// If type args were previously provided, specialize them.
|
2945
2823
|
// Handle tuples specially.
|
2946
2824
|
if (types_1.ClassType.isTupleClass(classType)) {
|
2947
|
-
if (classType.priv.
|
2825
|
+
if (classType.priv.tupleTypeArgs) {
|
2948
2826
|
newTupleTypeArgs = [];
|
2949
|
-
classType.priv.
|
2827
|
+
classType.priv.tupleTypeArgs.forEach((oldTypeArgType) => {
|
2950
2828
|
const newTypeArgType = this.apply(oldTypeArgType.type, recursionCount);
|
2951
2829
|
if (newTypeArgType !== oldTypeArgType.type) {
|
2952
2830
|
specializationNeeded = true;
|
2953
2831
|
}
|
2954
|
-
if ((0, types_1.
|
2832
|
+
if ((0, types_1.isUnpackedTypeVarTuple)(oldTypeArgType.type) &&
|
2955
2833
|
(0, types_1.isClassInstance)(newTypeArgType) &&
|
2956
2834
|
isTupleClass(newTypeArgType) &&
|
2957
|
-
newTypeArgType.priv.
|
2958
|
-
(0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.priv.
|
2835
|
+
newTypeArgType.priv.tupleTypeArgs) {
|
2836
|
+
(0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.priv.tupleTypeArgs);
|
2959
2837
|
}
|
2960
2838
|
else {
|
2961
2839
|
// Handle the special case where tuple[T, ...] is being specialized
|
@@ -2963,7 +2841,7 @@ class TypeVarTransformer {
|
|
2963
2841
|
const isEmptyTuple = oldTypeArgType.isUnbounded &&
|
2964
2842
|
(0, types_1.isTypeVar)(oldTypeArgType.type) &&
|
2965
2843
|
(0, types_1.isNever)(newTypeArgType) &&
|
2966
|
-
classType.priv.
|
2844
|
+
classType.priv.tupleTypeArgs.length === 1;
|
2967
2845
|
if (!isEmptyTuple) {
|
2968
2846
|
newTupleTypeArgs.push({
|
2969
2847
|
type: newTypeArgType,
|
@@ -2988,108 +2866,67 @@ class TypeVarTransformer {
|
|
2988
2866
|
// If this is an empty tuple, don't recompute the non-tuple type argument.
|
2989
2867
|
if (newTupleTypeArgs && newTupleTypeArgs.length > 0) {
|
2990
2868
|
// Combine the tuple type args into a single non-tuple type argument.
|
2991
|
-
newTypeArgs = [
|
2992
|
-
(0, types_1.combineTypes)(newTupleTypeArgs.map((t) => {
|
2993
|
-
if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedVariadicTypeVar)(t.type)) {
|
2994
|
-
// Treat the unpacked TypeVarTuple as a union.
|
2995
|
-
return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
|
2996
|
-
}
|
2997
|
-
return t.type;
|
2998
|
-
})),
|
2999
|
-
];
|
2869
|
+
newTypeArgs = [combineTupleTypeArgs(newTupleTypeArgs)];
|
3000
2870
|
}
|
3001
2871
|
}
|
3002
2872
|
if (!newTypeArgs) {
|
3003
|
-
|
3004
|
-
|
3005
|
-
|
3006
|
-
|
3007
|
-
|
3008
|
-
|
3009
|
-
|
3010
|
-
|
3011
|
-
|
3012
|
-
// (e.g. Union[Unpack[Vs]]), expand the subtypes into a union here.
|
3013
|
-
if ((0, types_1.isTypeVar)(oldTypeArgType) &&
|
3014
|
-
(0, types_1.isVariadicTypeVar)(oldTypeArgType) &&
|
3015
|
-
oldTypeArgType.priv.isVariadicInUnion) {
|
3016
|
-
newTypeArgType = _expandVariadicUnpackedUnion(newTypeArgType);
|
3017
|
-
}
|
3018
|
-
}
|
3019
|
-
return newTypeArgType;
|
3020
|
-
});
|
3021
|
-
}
|
3022
|
-
else {
|
3023
|
-
newTypeArgs = [];
|
3024
|
-
typeParams.forEach((typeParam) => {
|
3025
|
-
let replacementType = typeParam;
|
3026
|
-
if (typeParam.shared.isParamSpec) {
|
3027
|
-
replacementType = transformParamSpec(typeParam);
|
3028
|
-
if (replacementType !== typeParam) {
|
3029
|
-
specializationNeeded = true;
|
3030
|
-
}
|
3031
|
-
}
|
3032
|
-
else {
|
3033
|
-
if (!this._isTypeVarScopePending(typeParam.priv.scopeId)) {
|
3034
|
-
const transformedType = this.transformTypeVar(typeParam, recursionCount);
|
3035
|
-
replacementType = transformedType !== null && transformedType !== void 0 ? transformedType : typeParam;
|
3036
|
-
if (replacementType !== typeParam) {
|
3037
|
-
specializationNeeded = true;
|
3038
|
-
}
|
3039
|
-
else if (transformedType !== undefined && !classType.priv.typeArguments) {
|
3040
|
-
specializationNeeded = true;
|
3041
|
-
}
|
3042
|
-
}
|
2873
|
+
const typeArgs = (_a = classType.priv.typeArgs) !== null && _a !== void 0 ? _a : typeParams;
|
2874
|
+
newTypeArgs = typeArgs.map((oldTypeArgType) => {
|
2875
|
+
let newTypeArgType = this.apply(oldTypeArgType, recursionCount);
|
2876
|
+
if (newTypeArgType !== oldTypeArgType) {
|
2877
|
+
specializationNeeded = true;
|
2878
|
+
// If this was a TypeVarTuple that was part of a union
|
2879
|
+
// (e.g. Union[Unpack[Vs]]), expand the subtypes into a union here.
|
2880
|
+
if ((0, types_1.isTypeVar)(oldTypeArgType) && (0, types_1.isTypeVarTuple)(oldTypeArgType) && oldTypeArgType.priv.isInUnion) {
|
2881
|
+
newTypeArgType = _expandUnpackedTypeVarTupleUnion(newTypeArgType);
|
3043
2882
|
}
|
3044
|
-
|
3045
|
-
|
3046
|
-
}
|
2883
|
+
}
|
2884
|
+
return newTypeArgType;
|
2885
|
+
});
|
3047
2886
|
}
|
3048
|
-
this._isTransformingTypeArg = wasTransformingTypeArg;
|
3049
2887
|
// If specialization wasn't needed, don't allocate a new class.
|
3050
2888
|
if (!specializationNeeded) {
|
3051
2889
|
return classType;
|
3052
2890
|
}
|
3053
|
-
return types_1.ClassType.
|
3054
|
-
/*
|
2891
|
+
return types_1.ClassType.specialize(classType, newTypeArgs,
|
2892
|
+
/* isTypeArgExplicit */ true,
|
3055
2893
|
/* includeSubclasses */ undefined, newTupleTypeArgs);
|
3056
2894
|
}
|
3057
2895
|
transformTypeVarsInFunctionType(sourceType, recursionCount) {
|
3058
|
-
return this.
|
2896
|
+
return this.doForEachConstraintSet(() => {
|
3059
2897
|
let functionType = sourceType;
|
3060
2898
|
const declaredReturnType = types_1.FunctionType.getEffectiveReturnType(functionType);
|
3061
2899
|
const specializedReturnType = declaredReturnType
|
3062
2900
|
? this.apply(declaredReturnType, recursionCount)
|
3063
2901
|
: undefined;
|
3064
2902
|
let typesRequiredSpecialization = declaredReturnType !== specializedReturnType;
|
3065
|
-
const
|
2903
|
+
const specializedParams = {
|
3066
2904
|
parameterTypes: [],
|
3067
|
-
|
2905
|
+
parameterDefaultTypes: undefined,
|
3068
2906
|
returnType: specializedReturnType,
|
3069
2907
|
};
|
3070
2908
|
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(functionType);
|
3071
2909
|
if (paramSpec) {
|
3072
|
-
const paramSpecType = this.
|
2910
|
+
const paramSpecType = this.transformTypeVar(paramSpec, recursionCount);
|
3073
2911
|
if (paramSpecType) {
|
3074
|
-
const
|
3075
|
-
|
2912
|
+
const paramSpecValue = convertTypeToParamSpecValue(paramSpecType);
|
2913
|
+
const transformedParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(paramSpecValue);
|
2914
|
+
if (paramSpecValue.shared.parameters.length > 0 ||
|
3076
2915
|
!transformedParamSpec ||
|
3077
2916
|
!(0, types_1.isTypeSame)(paramSpec, transformedParamSpec)) {
|
3078
|
-
functionType = types_1.FunctionType.applyParamSpecValue(functionType,
|
2917
|
+
functionType = types_1.FunctionType.applyParamSpecValue(functionType, paramSpecValue);
|
3079
2918
|
}
|
3080
2919
|
}
|
3081
2920
|
}
|
3082
2921
|
let variadicParamIndex;
|
3083
2922
|
let variadicTypesToUnpack;
|
3084
2923
|
const specializedDefaultArgs = [];
|
3085
|
-
const wasTransformingTypeArg = this._isTransformingTypeArg;
|
3086
|
-
this._isTransformingTypeArg = true;
|
3087
2924
|
for (let i = 0; i < functionType.shared.parameters.length; i++) {
|
3088
|
-
const paramType = types_1.FunctionType.
|
2925
|
+
const paramType = types_1.FunctionType.getParamType(functionType, i);
|
3089
2926
|
const specializedType = this.apply(paramType, recursionCount);
|
3090
|
-
|
2927
|
+
specializedParams.parameterTypes.push(specializedType);
|
3091
2928
|
// Do we need to specialize the default argument type for this parameter?
|
3092
|
-
let defaultArgType = types_1.FunctionType.
|
2929
|
+
let defaultArgType = types_1.FunctionType.getParamDefaultType(functionType, i);
|
3093
2930
|
if (defaultArgType) {
|
3094
2931
|
const specializedArgType = this.apply(defaultArgType, recursionCount);
|
3095
2932
|
if (specializedArgType !== defaultArgType) {
|
@@ -3099,13 +2936,13 @@ class TypeVarTransformer {
|
|
3099
2936
|
}
|
3100
2937
|
specializedDefaultArgs.push(defaultArgType);
|
3101
2938
|
if (variadicParamIndex === undefined &&
|
3102
|
-
(0, types_1.
|
3103
|
-
functionType.shared.parameters[i].category === 1 /*
|
2939
|
+
(0, types_1.isTypeVarTuple)(paramType) &&
|
2940
|
+
functionType.shared.parameters[i].category === 1 /* ParamCategory.ArgsList */) {
|
3104
2941
|
variadicParamIndex = i;
|
3105
2942
|
if ((0, types_1.isClassInstance)(specializedType) &&
|
3106
2943
|
isTupleClass(specializedType) &&
|
3107
2944
|
specializedType.priv.isUnpacked) {
|
3108
|
-
variadicTypesToUnpack = specializedType.priv.
|
2945
|
+
variadicTypesToUnpack = specializedType.priv.tupleTypeArgs;
|
3109
2946
|
}
|
3110
2947
|
}
|
3111
2948
|
if (paramType !== specializedType) {
|
@@ -3134,16 +2971,15 @@ class TypeVarTransformer {
|
|
3134
2971
|
functionType.priv.strippedFirstParamType = newStrippedType;
|
3135
2972
|
}
|
3136
2973
|
}
|
3137
|
-
this._isTransformingTypeArg = wasTransformingTypeArg;
|
3138
2974
|
if (!typesRequiredSpecialization) {
|
3139
2975
|
return functionType;
|
3140
2976
|
}
|
3141
2977
|
if (specializedDefaultArgs.some((t) => t !== undefined)) {
|
3142
|
-
|
2978
|
+
specializedParams.parameterDefaultTypes = specializedDefaultArgs;
|
3143
2979
|
}
|
3144
2980
|
// If there was no unpacked variadic type variable, we're done.
|
3145
2981
|
if (!variadicTypesToUnpack) {
|
3146
|
-
return types_1.FunctionType.
|
2982
|
+
return types_1.FunctionType.specialize(functionType, specializedParams, specializedInferredReturnType);
|
3147
2983
|
}
|
3148
2984
|
// Unpack the tuple and synthesize a new function in the process.
|
3149
2985
|
const newFunctionType = types_1.TypeBase.isInstantiable(functionType)
|
@@ -3151,14 +2987,14 @@ class TypeVarTransformer {
|
|
3151
2987
|
: types_1.FunctionType.createSynthesizedInstance('', functionType.shared.flags);
|
3152
2988
|
let insertKeywordOnlySeparator = false;
|
3153
2989
|
let swallowPositionOnlySeparator = false;
|
3154
|
-
|
2990
|
+
specializedParams.parameterTypes.forEach((paramType, index) => {
|
3155
2991
|
if (index === variadicParamIndex) {
|
3156
2992
|
let sawUnboundedEntry = false;
|
3157
2993
|
// Unpack the tuple into individual parameters.
|
3158
2994
|
variadicTypesToUnpack.forEach((unpackedType) => {
|
3159
|
-
types_1.FunctionType.
|
3160
|
-
? 1 /*
|
3161
|
-
: 0 /*
|
2995
|
+
types_1.FunctionType.addParam(newFunctionType, types_1.FunctionParam.create(unpackedType.isUnbounded || (0, types_1.isTypeVarTuple)(unpackedType.type)
|
2996
|
+
? 1 /* ParamCategory.ArgsList */
|
2997
|
+
: 0 /* ParamCategory.Simple */, unpackedType.type, types_1.FunctionParamFlags.NameSynthesized | types_1.FunctionParamFlags.TypeDeclared, `__p${newFunctionType.shared.parameters.length}`));
|
3162
2998
|
if (unpackedType.isUnbounded) {
|
3163
2999
|
sawUnboundedEntry = true;
|
3164
3000
|
}
|
@@ -3171,29 +3007,27 @@ class TypeVarTransformer {
|
|
3171
3007
|
}
|
3172
3008
|
}
|
3173
3009
|
else {
|
3174
|
-
const param =
|
3010
|
+
const param = functionType.shared.parameters[index];
|
3175
3011
|
if ((0, types_1.isKeywordOnlySeparator)(param)) {
|
3176
3012
|
insertKeywordOnlySeparator = false;
|
3177
3013
|
}
|
3178
|
-
else if (param.category === 2 /*
|
3014
|
+
else if (param.category === 2 /* ParamCategory.KwargsDict */) {
|
3179
3015
|
insertKeywordOnlySeparator = false;
|
3180
3016
|
}
|
3181
3017
|
// Insert a keyword-only separator parameter if we previously
|
3182
|
-
// unpacked a
|
3183
|
-
if (param.category === 0 /*
|
3184
|
-
types_1.FunctionType.
|
3018
|
+
// unpacked a TypeVarTuple.
|
3019
|
+
if (param.category === 0 /* ParamCategory.Simple */ && param.name && insertKeywordOnlySeparator) {
|
3020
|
+
types_1.FunctionType.addKeywordOnlyParamSeparator(newFunctionType);
|
3185
3021
|
insertKeywordOnlySeparator = false;
|
3186
3022
|
}
|
3187
|
-
param.
|
3188
|
-
|
3189
|
-
|
3190
|
-
|
3191
|
-
if (param.category !== 0 /* ParameterCategory.Simple */ || param.name || !swallowPositionOnlySeparator) {
|
3192
|
-
types_1.FunctionType.addParameter(newFunctionType, param);
|
3023
|
+
if (param.category !== 0 /* ParamCategory.Simple */ || param.name || !swallowPositionOnlySeparator) {
|
3024
|
+
types_1.FunctionType.addParam(newFunctionType, types_1.FunctionParam.create(param.category, paramType, param.flags, param.name && types_1.FunctionParam.isNameSynthesized(param)
|
3025
|
+
? `__p${newFunctionType.shared.parameters.length}`
|
3026
|
+
: param.name, types_1.FunctionType.getParamDefaultType(functionType, index)));
|
3193
3027
|
}
|
3194
3028
|
}
|
3195
3029
|
});
|
3196
|
-
newFunctionType.shared.declaredReturnType =
|
3030
|
+
newFunctionType.shared.declaredReturnType = specializedParams.returnType;
|
3197
3031
|
return newFunctionType;
|
3198
3032
|
});
|
3199
3033
|
}
|
@@ -3201,18 +3035,7 @@ class TypeVarTransformer {
|
|
3201
3035
|
return !!typeVarScopeId && this._pendingTypeVarTransformations.has(typeVarScopeId);
|
3202
3036
|
}
|
3203
3037
|
}
|
3204
|
-
|
3205
|
-
class TypeVarAnyReplacer extends TypeVarTransformer {
|
3206
|
-
constructor() {
|
3207
|
-
super();
|
3208
|
-
}
|
3209
|
-
transformTypeVar(typeVar) {
|
3210
|
-
return types_1.AnyType.create();
|
3211
|
-
}
|
3212
|
-
transformParamSpec(paramSpec) {
|
3213
|
-
return getUnknownTypeForParamSpec();
|
3214
|
-
}
|
3215
|
-
}
|
3038
|
+
exports.TypeVarTransformer = TypeVarTransformer;
|
3216
3039
|
// For a TypeVar with a default type, validates whether the default type is using
|
3217
3040
|
// any other TypeVars that are not currently in scope.
|
3218
3041
|
class TypeVarDefaultValidator extends TypeVarTransformer {
|
@@ -3223,18 +3046,11 @@ class TypeVarDefaultValidator extends TypeVarTransformer {
|
|
3223
3046
|
}
|
3224
3047
|
transformTypeVar(typeVar) {
|
3225
3048
|
const replacementType = this._liveTypeParams.find((param) => param.shared.name === typeVar.shared.name);
|
3226
|
-
if (!replacementType || (0, types_1.isParamSpec)(replacementType)) {
|
3049
|
+
if (!replacementType || (0, types_1.isParamSpec)(replacementType) !== (0, types_1.isParamSpec)(typeVar)) {
|
3227
3050
|
this._invalidTypeVars.add(typeVar.shared.name);
|
3228
3051
|
}
|
3229
3052
|
return types_1.UnknownType.create();
|
3230
3053
|
}
|
3231
|
-
transformParamSpec(paramSpec) {
|
3232
|
-
const replacementType = this._liveTypeParams.find((param) => param.shared.name === paramSpec.shared.name);
|
3233
|
-
if (!replacementType || !(0, types_1.isParamSpec)(replacementType)) {
|
3234
|
-
this._invalidTypeVars.add(paramSpec.shared.name);
|
3235
|
-
}
|
3236
|
-
return undefined;
|
3237
|
-
}
|
3238
3054
|
}
|
3239
3055
|
class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
3240
3056
|
constructor(_signatureTracker, _expressionOffset) {
|
@@ -3252,7 +3068,7 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
|
3252
3068
|
}
|
3253
3069
|
transformTypeVarsInFunctionType(sourceType, recursionCount) {
|
3254
3070
|
// If this function is not generic, there's no need to check for uniqueness.
|
3255
|
-
if (sourceType.shared.
|
3071
|
+
if (sourceType.shared.typeParams.length === 0) {
|
3256
3072
|
return super.transformTypeVarsInFunctionType(sourceType, recursionCount);
|
3257
3073
|
}
|
3258
3074
|
let updatedSourceType = sourceType;
|
@@ -3263,19 +3079,16 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
|
3263
3079
|
offsetIndex = existingSignature.expressionOffsets.length;
|
3264
3080
|
}
|
3265
3081
|
if (offsetIndex > 0) {
|
3266
|
-
const
|
3082
|
+
const solution = new constraintSolution_1.ConstraintSolution();
|
3267
3083
|
// Create new type variables with the same scope but with
|
3268
3084
|
// different (unique) names.
|
3269
|
-
sourceType.shared.
|
3085
|
+
sourceType.shared.typeParams.forEach((typeParam) => {
|
3270
3086
|
if (typeParam.priv.scopeType === 1 /* TypeVarScopeType.Function */) {
|
3271
|
-
|
3272
|
-
|
3273
|
-
replacement = convertTypeToParamSpecValue(replacement);
|
3274
|
-
}
|
3275
|
-
typeVarContext.setTypeVarType(typeParam, replacement);
|
3087
|
+
const replacement = types_1.TypeVarType.cloneForNewName(typeParam, `${typeParam.shared.name}(${offsetIndex})`);
|
3088
|
+
solution.setType(typeParam, replacement);
|
3276
3089
|
}
|
3277
3090
|
});
|
3278
|
-
updatedSourceType = applySolvedTypeVars(sourceType,
|
3091
|
+
updatedSourceType = applySolvedTypeVars(sourceType, solution);
|
3279
3092
|
(0, debug_1.assert)((0, types_1.isFunction)(updatedSourceType) || (0, types_1.isOverloadedFunction)(updatedSourceType));
|
3280
3093
|
}
|
3281
3094
|
}
|
@@ -3283,9 +3096,10 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
|
3283
3096
|
return updatedSourceType;
|
3284
3097
|
}
|
3285
3098
|
}
|
3286
|
-
// Replaces the
|
3287
|
-
//
|
3288
|
-
|
3099
|
+
// Replaces the free type vars within a type with their corresponding bound
|
3100
|
+
// type vars if they are in one of the specified scopes. If undefined is
|
3101
|
+
// passed for the scopeIds list, all free type vars are replaced.
|
3102
|
+
class BoundTypeVarTransform extends TypeVarTransformer {
|
3289
3103
|
constructor(_scopeIds) {
|
3290
3104
|
super();
|
3291
3105
|
this._scopeIds = _scopeIds;
|
@@ -3296,35 +3110,30 @@ class InternalScopeUpdateTransform extends TypeVarTransformer {
|
|
3296
3110
|
}
|
3297
3111
|
return undefined;
|
3298
3112
|
}
|
3299
|
-
transformParamSpec(paramSpec) {
|
3300
|
-
if (this._isTypeVarInScope(paramSpec)) {
|
3301
|
-
return convertTypeToParamSpecValue(this._replaceTypeVar(paramSpec));
|
3302
|
-
}
|
3303
|
-
return undefined;
|
3304
|
-
}
|
3305
3113
|
_isTypeVarInScope(typeVar) {
|
3306
|
-
|
3114
|
+
if (!typeVar.priv.scopeId) {
|
3115
|
+
return false;
|
3116
|
+
}
|
3117
|
+
// If no scopeIds were specified, transform all Type Vars.
|
3118
|
+
if (!this._scopeIds) {
|
3119
|
+
return true;
|
3120
|
+
}
|
3121
|
+
return this._scopeIds.includes(typeVar.priv.scopeId);
|
3307
3122
|
}
|
3308
3123
|
_replaceTypeVar(typeVar) {
|
3309
|
-
return types_1.TypeVarType.
|
3124
|
+
return types_1.TypeVarType.cloneAsBound(typeVar);
|
3310
3125
|
}
|
3311
3126
|
}
|
3312
|
-
// Replaces the
|
3313
|
-
//
|
3314
|
-
class
|
3127
|
+
// Replaces the bound type vars within a type with their corresponding
|
3128
|
+
// free type vars.
|
3129
|
+
class FreeTypeVarTransform extends TypeVarTransformer {
|
3315
3130
|
constructor(_scopeIds) {
|
3316
3131
|
super();
|
3317
3132
|
this._scopeIds = _scopeIds;
|
3318
3133
|
}
|
3319
3134
|
transformTypeVar(typeVar) {
|
3320
|
-
if (typeVar.priv.
|
3321
|
-
return typeVar.priv.
|
3322
|
-
}
|
3323
|
-
return undefined;
|
3324
|
-
}
|
3325
|
-
transformParamSpec(paramSpec) {
|
3326
|
-
if (paramSpec.priv.externalTypeVar && this._isTypeVarInScope(paramSpec.priv.externalTypeVar)) {
|
3327
|
-
return convertTypeToParamSpecValue(paramSpec.priv.externalTypeVar);
|
3135
|
+
if (typeVar.priv.freeTypeVar && this._isTypeVarInScope(typeVar.priv.freeTypeVar)) {
|
3136
|
+
return typeVar.priv.freeTypeVar;
|
3328
3137
|
}
|
3329
3138
|
return undefined;
|
3330
3139
|
}
|
@@ -3338,135 +3147,120 @@ class ExternalScopeUpdateTransform extends TypeVarTransformer {
|
|
3338
3147
|
// Specializes a (potentially generic) type by substituting
|
3339
3148
|
// type variables from a type var map.
|
3340
3149
|
class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
3341
|
-
constructor(
|
3150
|
+
constructor(_solution, _options) {
|
3342
3151
|
super();
|
3343
|
-
this.
|
3152
|
+
this._solution = _solution;
|
3344
3153
|
this._options = _options;
|
3345
3154
|
this._isSolvingDefaultType = false;
|
3346
3155
|
}
|
3347
3156
|
transformTypeVar(typeVar, recursionCount) {
|
3348
|
-
var _a, _b;
|
3349
|
-
const
|
3350
|
-
// If
|
3351
|
-
|
3352
|
-
|
3353
|
-
let replacement = signatureContext.getTypeVarType(typeVar, !!this._options.useNarrowBoundOnly);
|
3354
|
-
// If there was no narrow bound but there is a wide bound that
|
3355
|
-
// contains literals or a TypeVar, we'll use the wide bound even if
|
3356
|
-
// "useNarrowBoundOnly" is specified.
|
3357
|
-
if (!replacement && this._options.useNarrowBoundOnly) {
|
3358
|
-
const wideType = signatureContext.getTypeVarType(typeVar);
|
3359
|
-
if (wideType) {
|
3360
|
-
if ((0, types_1.isTypeVar)(wideType) || containsLiteralType(wideType, /* includeTypeArgs */ true)) {
|
3361
|
-
replacement = wideType;
|
3362
|
-
}
|
3363
|
-
}
|
3364
|
-
}
|
3157
|
+
var _a, _b, _c;
|
3158
|
+
const solutionSet = this._solution.getSolutionSet((_a = this._activeConstraintSetIndex) !== null && _a !== void 0 ? _a : 0);
|
3159
|
+
// If we're solving a default type, handle type variables with no scope ID.
|
3160
|
+
if (this._isSolvingDefaultType && !typeVar.priv.scopeId) {
|
3161
|
+
const replacement = this._getReplacementForDefaultByName(typeVar, solutionSet);
|
3365
3162
|
if (replacement) {
|
3366
|
-
|
3367
|
-
|
3368
|
-
|
3369
|
-
|
3370
|
-
|
3371
|
-
|
3372
|
-
|
3373
|
-
|
3374
|
-
|
3375
|
-
|
3163
|
+
return replacement;
|
3164
|
+
}
|
3165
|
+
if (typeVar.shared.isDefaultExplicit) {
|
3166
|
+
return this.apply(typeVar.shared.defaultType, recursionCount);
|
3167
|
+
}
|
3168
|
+
return types_1.UnknownType.create();
|
3169
|
+
}
|
3170
|
+
if (!this._shouldReplaceTypeVar(typeVar)) {
|
3171
|
+
return undefined;
|
3172
|
+
}
|
3173
|
+
let replacement = solutionSet.getType(typeVar);
|
3174
|
+
if (replacement) {
|
3175
|
+
// No more processing is needed for ParamSpecs.
|
3176
|
+
if ((0, types_1.isParamSpec)(typeVar)) {
|
3177
|
+
return replacement;
|
3178
|
+
}
|
3179
|
+
if (types_1.TypeBase.isInstantiable(typeVar)) {
|
3180
|
+
if ((0, types_1.isAnyOrUnknown)(replacement) &&
|
3181
|
+
this._options.typeClassType &&
|
3182
|
+
(0, types_1.isInstantiableClass)(this._options.typeClassType)) {
|
3183
|
+
replacement = types_1.ClassType.specialize(types_1.ClassType.cloneAsInstance(this._options.typeClassType), [
|
3184
|
+
replacement,
|
3185
|
+
]);
|
3376
3186
|
}
|
3377
3187
|
else {
|
3378
|
-
|
3379
|
-
|
3380
|
-
|
3381
|
-
|
3382
|
-
|
3383
|
-
|
3384
|
-
|
3385
|
-
|
3386
|
-
|
3387
|
-
|
3388
|
-
|
3389
|
-
|
3390
|
-
|
3391
|
-
|
3392
|
-
|
3393
|
-
|
3394
|
-
|
3188
|
+
replacement = convertToInstantiable(replacement, /* includeSubclasses */ false);
|
3189
|
+
}
|
3190
|
+
}
|
3191
|
+
else {
|
3192
|
+
// If the TypeVar is not instantiable (i.e. not a type[T]), then
|
3193
|
+
// it represents an instance of a type. If the replacement includes
|
3194
|
+
// a generic class that has not been specialized, specialize it
|
3195
|
+
// now with default type arguments.
|
3196
|
+
replacement = mapSubtypes(replacement, (subtype) => {
|
3197
|
+
if ((0, types_1.isClassInstance)(subtype)) {
|
3198
|
+
// If the includeSubclasses wasn't set, force it to be set by
|
3199
|
+
// converting to/from an instantiable.
|
3200
|
+
if (!subtype.priv.includeSubclasses) {
|
3201
|
+
subtype = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneAsInstantiable(subtype));
|
3202
|
+
}
|
3203
|
+
if (subtype.shared.typeParams && !subtype.priv.typeArgs) {
|
3204
|
+
if (this._options.replaceUnsolved) {
|
3205
|
+
return this._options.replaceUnsolved.useUnknown
|
3206
|
+
? specializeWithUnknownTypeArgs(subtype, this._options.replaceUnsolved.tupleClassType)
|
3207
|
+
: specializeWithDefaultTypeArgs(subtype);
|
3395
3208
|
}
|
3396
3209
|
}
|
3397
|
-
|
3398
|
-
|
3399
|
-
}
|
3400
|
-
if ((0, types_1.isTypeVar)(replacement) && typeVar.priv.isVariadicUnpacked && replacement.shared.isVariadic) {
|
3401
|
-
return types_1.TypeVarType.cloneForUnpacked(replacement, typeVar.priv.isVariadicInUnion);
|
3402
|
-
}
|
3403
|
-
if (!(0, types_1.isTypeVar)(replacement) ||
|
3404
|
-
!replacement.priv.isInScopePlaceholder ||
|
3405
|
-
!this._options.unknownIfNotFound) {
|
3406
|
-
return replacement;
|
3407
|
-
}
|
3210
|
+
}
|
3211
|
+
return subtype;
|
3212
|
+
});
|
3408
3213
|
}
|
3409
|
-
|
3410
|
-
|
3411
|
-
// default or Unknown.
|
3412
|
-
let useDefaultOrUnknown = false;
|
3413
|
-
if (this._options.unknownIfNotFound) {
|
3414
|
-
const exemptTypeVars = (_b = this._options.unknownExemptTypeVars) !== null && _b !== void 0 ? _b : [];
|
3415
|
-
const typeVarInstance = types_1.TypeBase.isInstance(typeVar) ? typeVar : types_1.TypeVarType.cloneAsInstance(typeVar);
|
3416
|
-
if (!exemptTypeVars.some((t) => (0, types_1.isTypeSame)(t, typeVarInstance))) {
|
3417
|
-
useDefaultOrUnknown = true;
|
3418
|
-
}
|
3214
|
+
if ((0, types_1.isTypeVarTuple)(replacement) && (0, types_1.isTypeVarTuple)(typeVar) && typeVar.priv.isUnpacked) {
|
3215
|
+
return types_1.TypeVarType.cloneForUnpacked(replacement, typeVar.priv.isInUnion);
|
3419
3216
|
}
|
3420
|
-
|
3421
|
-
|
3217
|
+
// If this isn't a TypeVarTuple, combine all of the tuple
|
3218
|
+
// type args into a common type.
|
3219
|
+
if (!(0, types_1.isTypeVarTuple)(typeVar) &&
|
3220
|
+
(0, types_1.isClassInstance)(replacement) &&
|
3221
|
+
replacement.priv.tupleTypeArgs &&
|
3222
|
+
replacement.priv.isUnpacked) {
|
3223
|
+
replacement = combineTupleTypeArgs(replacement.priv.tupleTypeArgs);
|
3422
3224
|
}
|
3423
|
-
if (
|
3424
|
-
|
3425
|
-
if (typeVar.shared.isDefaultExplicit && !this._options.useUnknownOverDefault) {
|
3426
|
-
return this._solveDefaultType(typeVar, recursionCount);
|
3427
|
-
}
|
3428
|
-
return getUnknownTypeForTypeVar(typeVar, this._options.tupleClassType);
|
3225
|
+
if (!(0, types_1.isTypeVar)(replacement) || !types_1.TypeVarType.isUnification(replacement) || !this._options.replaceUnsolved) {
|
3226
|
+
return replacement;
|
3429
3227
|
}
|
3430
3228
|
}
|
3431
|
-
|
3432
|
-
|
3433
|
-
const replacementEntry = signatureContext
|
3434
|
-
.getTypeVars()
|
3435
|
-
.find((entry) => entry.typeVar.shared.name === typeVar.shared.name);
|
3436
|
-
if (replacementEntry) {
|
3437
|
-
return signatureContext.getTypeVarType(replacementEntry.typeVar);
|
3438
|
-
}
|
3439
|
-
if (typeVar.shared.isDefaultExplicit) {
|
3440
|
-
return this.apply(typeVar.shared.defaultType, recursionCount);
|
3441
|
-
}
|
3442
|
-
return types_1.UnknownType.create();
|
3229
|
+
if (!this._shouldReplaceUnsolvedTypeVar(typeVar)) {
|
3230
|
+
return undefined;
|
3443
3231
|
}
|
3444
|
-
|
3232
|
+
// Use the default value if there is one.
|
3233
|
+
if (typeVar.shared.isDefaultExplicit && !((_b = this._options.replaceUnsolved) === null || _b === void 0 ? void 0 : _b.useUnknown)) {
|
3234
|
+
return this._solveDefaultType(typeVar, recursionCount);
|
3235
|
+
}
|
3236
|
+
return getUnknownForTypeVar(typeVar, (_c = this._options.replaceUnsolved) === null || _c === void 0 ? void 0 : _c.tupleClassType);
|
3445
3237
|
}
|
3446
3238
|
transformUnionSubtype(preTransform, postTransform) {
|
3447
|
-
var _a;
|
3239
|
+
var _a, _b;
|
3448
3240
|
// If a union contains unsolved TypeVars within scope, eliminate them
|
3449
3241
|
// unless this results in an empty union. This elimination is needed
|
3450
3242
|
// in cases where TypeVars can go unsolved due to unions in parameter
|
3451
3243
|
// annotations, like this:
|
3452
3244
|
// def test(x: Union[str, T]) -> Union[str, T]
|
3453
|
-
if (this._options.eliminateUnsolvedInUnions) {
|
3245
|
+
if ((_a = this._options.replaceUnsolved) === null || _a === void 0 ? void 0 : _a.eliminateUnsolvedInUnions) {
|
3454
3246
|
if ((0, types_1.isTypeVar)(preTransform) &&
|
3455
|
-
preTransform
|
3456
|
-
this.
|
3457
|
-
const
|
3458
|
-
const typeVarType =
|
3247
|
+
this._shouldReplaceTypeVar(preTransform) &&
|
3248
|
+
this._shouldReplaceUnsolvedTypeVar(preTransform)) {
|
3249
|
+
const solutionSet = this._solution.getSolutionSet((_b = this._activeConstraintSetIndex) !== null && _b !== void 0 ? _b : 0);
|
3250
|
+
const typeVarType = solutionSet.getType(preTransform);
|
3459
3251
|
// Did the TypeVar remain unsolved?
|
3460
|
-
if (!typeVarType || ((0, types_1.isTypeVar)(typeVarType) &&
|
3252
|
+
if (!typeVarType || ((0, types_1.isTypeVar)(typeVarType) && types_1.TypeVarType.isUnification(typeVarType))) {
|
3461
3253
|
// If the TypeVar was not transformed, then it was unsolved,
|
3462
3254
|
// and we'll eliminate it.
|
3463
3255
|
if (preTransform === postTransform) {
|
3464
3256
|
return undefined;
|
3465
3257
|
}
|
3466
|
-
// If
|
3258
|
+
// If useDefaultForUnsolved or useUnknownForUnsolved is true, the postTransform type will
|
3467
3259
|
// be Unknown, which we want to eliminate.
|
3468
|
-
if (
|
3469
|
-
|
3260
|
+
if (this._options.replaceUnsolved) {
|
3261
|
+
if ((0, types_1.isUnknown)(postTransform)) {
|
3262
|
+
return undefined;
|
3263
|
+
}
|
3470
3264
|
}
|
3471
3265
|
}
|
3472
3266
|
}
|
@@ -3475,58 +3269,17 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3475
3269
|
}
|
3476
3270
|
transformTupleTypeVar(typeVar) {
|
3477
3271
|
var _a;
|
3478
|
-
if (!
|
3272
|
+
if (!this._shouldReplaceTypeVar(typeVar)) {
|
3479
3273
|
const defaultType = typeVar.shared.defaultType;
|
3480
|
-
if (typeVar.shared.isDefaultExplicit &&
|
3481
|
-
|
3482
|
-
defaultType.priv.tupleTypeArguments) {
|
3483
|
-
return defaultType.priv.tupleTypeArguments;
|
3274
|
+
if (typeVar.shared.isDefaultExplicit && (0, types_1.isClassInstance)(defaultType) && defaultType.priv.tupleTypeArgs) {
|
3275
|
+
return defaultType.priv.tupleTypeArgs;
|
3484
3276
|
}
|
3485
3277
|
return undefined;
|
3486
3278
|
}
|
3487
|
-
const
|
3488
|
-
|
3489
|
-
|
3490
|
-
|
3491
|
-
var _a, _b;
|
3492
|
-
const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
|
3493
|
-
// If we're solving a default type, handle param specs with no scope ID.
|
3494
|
-
if (this._isSolvingDefaultType && !paramSpec.priv.scopeId) {
|
3495
|
-
const replacementEntry = signatureContext
|
3496
|
-
.getTypeVars()
|
3497
|
-
.find((entry) => entry.typeVar.shared.name === paramSpec.shared.name);
|
3498
|
-
if (replacementEntry) {
|
3499
|
-
return signatureContext.getParamSpecType(replacementEntry.typeVar);
|
3500
|
-
}
|
3501
|
-
if (paramSpec.shared.isDefaultExplicit) {
|
3502
|
-
return convertTypeToParamSpecValue(this.apply(paramSpec.shared.defaultType, recursionCount));
|
3503
|
-
}
|
3504
|
-
return getUnknownTypeForParamSpec();
|
3505
|
-
}
|
3506
|
-
if (!paramSpec.priv.scopeId || !this._typeVarContext.hasSolveForScope(paramSpec.priv.scopeId)) {
|
3507
|
-
return undefined;
|
3508
|
-
}
|
3509
|
-
const transformedParamSpec = signatureContext.getParamSpecType(paramSpec);
|
3510
|
-
if (transformedParamSpec) {
|
3511
|
-
return transformedParamSpec;
|
3512
|
-
}
|
3513
|
-
let useDefaultOrUnknown = false;
|
3514
|
-
if (this._options.unknownIfNotFound) {
|
3515
|
-
const exemptTypeVars = (_b = this._options.unknownExemptTypeVars) !== null && _b !== void 0 ? _b : [];
|
3516
|
-
if (!exemptTypeVars.some((t) => (0, types_1.isTypeSame)(t, paramSpec, { ignoreTypeFlags: true }))) {
|
3517
|
-
useDefaultOrUnknown = true;
|
3518
|
-
}
|
3519
|
-
}
|
3520
|
-
else if (this._options.applyInScopePlaceholders && paramSpec.priv.isInScopePlaceholder) {
|
3521
|
-
useDefaultOrUnknown = true;
|
3522
|
-
}
|
3523
|
-
if (useDefaultOrUnknown) {
|
3524
|
-
// Use the default value if there is one.
|
3525
|
-
if (paramSpec.shared.isDefaultExplicit && !this._options.useUnknownOverDefault) {
|
3526
|
-
return convertTypeToParamSpecValue(this._solveDefaultType(paramSpec, recursionCount));
|
3527
|
-
}
|
3528
|
-
// Convert to the ParamSpec equivalent of "Unknown".
|
3529
|
-
return getUnknownTypeForParamSpec();
|
3279
|
+
const solutionSet = this._solution.getSolutionSet((_a = this._activeConstraintSetIndex) !== null && _a !== void 0 ? _a : 0);
|
3280
|
+
const value = solutionSet.getType(typeVar);
|
3281
|
+
if (value && (0, types_1.isClassInstance)(value) && value.priv.tupleTypeArgs && (0, types_1.isUnpackedClass)(value)) {
|
3282
|
+
return value.priv.tupleTypeArgs;
|
3530
3283
|
}
|
3531
3284
|
return undefined;
|
3532
3285
|
}
|
@@ -3535,22 +3288,22 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3535
3288
|
if (!((_a = type.props) === null || _a === void 0 ? void 0 : _a.condition)) {
|
3536
3289
|
return type;
|
3537
3290
|
}
|
3538
|
-
const
|
3291
|
+
const solutionSet = this._solution.getSolutionSet((_b = this._activeConstraintSetIndex) !== null && _b !== void 0 ? _b : 0);
|
3539
3292
|
for (const condition of type.props.condition) {
|
3540
3293
|
// This doesn't apply to bound type variables.
|
3541
|
-
if (condition.typeVar
|
3294
|
+
if (!types_1.TypeVarType.hasConstraints(condition.typeVar)) {
|
3542
3295
|
continue;
|
3543
3296
|
}
|
3544
|
-
const conditionTypeVar = (_d = (_c = condition.typeVar.priv) === null || _c === void 0 ? void 0 : _c.
|
3545
|
-
const
|
3546
|
-
if (!
|
3297
|
+
const conditionTypeVar = (_d = (_c = condition.typeVar.priv) === null || _c === void 0 ? void 0 : _c.freeTypeVar) !== null && _d !== void 0 ? _d : condition.typeVar;
|
3298
|
+
const replacement = solutionSet.getType(conditionTypeVar);
|
3299
|
+
if (!replacement || condition.constraintIndex >= conditionTypeVar.shared.constraints.length) {
|
3547
3300
|
continue;
|
3548
3301
|
}
|
3549
|
-
const value =
|
3302
|
+
const value = solutionSet.getType(conditionTypeVar);
|
3550
3303
|
if (!value) {
|
3551
3304
|
continue;
|
3552
3305
|
}
|
3553
|
-
const constraintType =
|
3306
|
+
const constraintType = conditionTypeVar.shared.constraints[condition.constraintIndex];
|
3554
3307
|
// If this violates the constraint, substitute a Never type.
|
3555
3308
|
if (!(0, types_1.isTypeSame)(constraintType, value)) {
|
3556
3309
|
return types_1.NeverType.createNever();
|
@@ -3558,19 +3311,19 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3558
3311
|
}
|
3559
3312
|
return type;
|
3560
3313
|
}
|
3561
|
-
|
3562
|
-
const
|
3314
|
+
doForEachConstraintSet(callback) {
|
3315
|
+
const solutionSets = this._solution.getSolutionSets();
|
3563
3316
|
// Handle the common case where there are not multiple signature contexts.
|
3564
|
-
if (
|
3317
|
+
if (solutionSets.length <= 1) {
|
3565
3318
|
return callback();
|
3566
3319
|
}
|
3567
3320
|
// Loop through all of the signature contexts in the type var context
|
3568
3321
|
// to create an overload type.
|
3569
|
-
const overloadTypes =
|
3570
|
-
this.
|
3322
|
+
const overloadTypes = solutionSets.map((_, index) => {
|
3323
|
+
this._activeConstraintSetIndex = index;
|
3571
3324
|
return callback();
|
3572
3325
|
});
|
3573
|
-
this.
|
3326
|
+
this._activeConstraintSetIndex = undefined;
|
3574
3327
|
const filteredOverloads = [];
|
3575
3328
|
doForEachSubtype((0, types_1.combineTypes)(overloadTypes), (subtype) => {
|
3576
3329
|
(0, debug_1.assert)((0, types_1.isFunction)(subtype));
|
@@ -3582,6 +3335,50 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3582
3335
|
}
|
3583
3336
|
return types_1.OverloadedFunctionType.create(filteredOverloads);
|
3584
3337
|
}
|
3338
|
+
// Handle the case where we need the default replacement value for a typeVar
|
3339
|
+
// that has no scope and therefore doesn't have an assigned scopeID. We'll
|
3340
|
+
// look it up by name in the solution set. This is a bit hacky because there
|
3341
|
+
// could be multiple typeVars with the same name, but we'll assume that this
|
3342
|
+
// won't happen.
|
3343
|
+
_getReplacementForDefaultByName(typeVar, solutionSet) {
|
3344
|
+
let replacementValue;
|
3345
|
+
const partialScopeId = `${typeVar.shared.name}.`;
|
3346
|
+
solutionSet.doForEachTypeVar((value, typeVarId) => {
|
3347
|
+
if (typeVarId.startsWith(partialScopeId)) {
|
3348
|
+
replacementValue = value;
|
3349
|
+
}
|
3350
|
+
});
|
3351
|
+
return replacementValue;
|
3352
|
+
}
|
3353
|
+
_shouldReplaceTypeVar(typeVar) {
|
3354
|
+
if (!typeVar.priv.scopeId || types_1.TypeVarType.isBound(typeVar)) {
|
3355
|
+
return false;
|
3356
|
+
}
|
3357
|
+
return true;
|
3358
|
+
}
|
3359
|
+
_shouldReplaceUnsolvedTypeVar(typeVar) {
|
3360
|
+
var _a;
|
3361
|
+
// Never replace nested TypeVars with unknown.
|
3362
|
+
if (this.pendingTypeVarTransformations.size > 0) {
|
3363
|
+
return false;
|
3364
|
+
}
|
3365
|
+
if (!typeVar.priv.scopeId) {
|
3366
|
+
return false;
|
3367
|
+
}
|
3368
|
+
if (!this._options.replaceUnsolved) {
|
3369
|
+
return false;
|
3370
|
+
}
|
3371
|
+
if (!this._options.replaceUnsolved.scopeIds.includes(typeVar.priv.scopeId)) {
|
3372
|
+
return false;
|
3373
|
+
}
|
3374
|
+
const exemptTypeVars = (_a = this._options.replaceUnsolved) === null || _a === void 0 ? void 0 : _a.unsolvedExemptTypeVars;
|
3375
|
+
if (exemptTypeVars) {
|
3376
|
+
if (exemptTypeVars.some((t) => (0, types_1.isTypeSame)(t, typeVar, { ignoreTypeFlags: true }))) {
|
3377
|
+
return false;
|
3378
|
+
}
|
3379
|
+
}
|
3380
|
+
return true;
|
3381
|
+
}
|
3585
3382
|
_solveDefaultType(typeVar, recursionCount) {
|
3586
3383
|
const defaultType = typeVar.shared.defaultType;
|
3587
3384
|
const wasSolvingDefaultType = this._isSolvingDefaultType;
|
@@ -3599,46 +3396,12 @@ class ExpectedTypeTransformer extends TypeVarTransformer {
|
|
3599
3396
|
}
|
3600
3397
|
transformTypeVar(typeVar) {
|
3601
3398
|
if (!this._isTypeVarLive(typeVar)) {
|
3602
|
-
return types_1.TypeVarType.
|
3603
|
-
}
|
3604
|
-
return undefined;
|
3605
|
-
}
|
3606
|
-
transformParamSpec(paramSpec) {
|
3607
|
-
if (!this._isTypeVarLive(paramSpec)) {
|
3608
|
-
return convertTypeToParamSpecValue(types_1.TypeVarType.cloneAsInScopePlaceholder(paramSpec, this._usageOffset));
|
3399
|
+
return types_1.TypeVarType.cloneAsUnificationVar(typeVar, this._usageOffset);
|
3609
3400
|
}
|
3610
3401
|
return undefined;
|
3611
3402
|
}
|
3612
3403
|
_isTypeVarLive(typeVar) {
|
3613
|
-
return this._liveTypeVarScopes.some((scopeId) => { var _a; return typeVar.priv.scopeId === scopeId || ((_a = typeVar.priv.
|
3614
|
-
}
|
3615
|
-
}
|
3616
|
-
class InScopePlaceholderTransformer extends TypeVarTransformer {
|
3617
|
-
constructor(_signatureContext) {
|
3618
|
-
super();
|
3619
|
-
this._signatureContext = _signatureContext;
|
3404
|
+
return this._liveTypeVarScopes.some((scopeId) => { var _a; return typeVar.priv.scopeId === scopeId || ((_a = typeVar.priv.freeTypeVar) === null || _a === void 0 ? void 0 : _a.priv.scopeId) === scopeId; });
|
3620
3405
|
}
|
3621
|
-
transformTypeVar(typeVar) {
|
3622
|
-
var _a;
|
3623
|
-
if (typeVar.priv.isInScopePlaceholder) {
|
3624
|
-
return (_a = this._signatureContext.getTypeVarType(typeVar)) !== null && _a !== void 0 ? _a : typeVar;
|
3625
|
-
}
|
3626
|
-
return undefined;
|
3627
|
-
}
|
3628
|
-
transformParamSpec(paramSpec) {
|
3629
|
-
if (paramSpec.priv.isInScopePlaceholder) {
|
3630
|
-
return this._signatureContext.getParamSpecType(paramSpec);
|
3631
|
-
}
|
3632
|
-
return undefined;
|
3633
|
-
}
|
3634
|
-
}
|
3635
|
-
function applyInScopePlaceholdersToType(type, signatureContext) {
|
3636
|
-
// Handle the common case where there are no in-scope placeholders.
|
3637
|
-
// No more work is required in this case.
|
3638
|
-
if (!signatureContext.getTypeVars().some((entry) => entry.typeVar.priv.isInScopePlaceholder)) {
|
3639
|
-
return type;
|
3640
|
-
}
|
3641
|
-
const transformer = new InScopePlaceholderTransformer(signatureContext);
|
3642
|
-
return transformer.apply(type, 0);
|
3643
3406
|
}
|
3644
3407
|
//# sourceMappingURL=typeUtils.js.map
|