@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
package/dist/analyzer/types.js
CHANGED
@@ -8,9 +8,10 @@
|
|
8
8
|
* Representation of types used during type analysis within Python.
|
9
9
|
*/
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
11
|
-
exports.
|
12
|
-
exports.isSameWithoutLiteralValue = exports.combineTypes = void 0;
|
11
|
+
exports.removeUnbound = exports.removeUnknownFromUnion = exports.isTypeSame = exports.getTypeAliasInfo = exports.isOverloadedFunction = exports.isFunction = exports.isUnpacked = exports.isUnpackedClass = exports.isUnpackedTypeVarTuple = exports.isTypeVarTuple = exports.isParamSpec = exports.isTypeVar = exports.isModule = exports.isClassInstance = exports.isInstantiableClass = exports.isClass = exports.isPossiblyUnbound = exports.isUnion = exports.isUnbound = exports.isAnyOrUnknown = exports.isUnknown = exports.isAny = exports.isNever = exports.TypeVarType = exports.ParamSpecType = exports.TypeVarScopeType = exports.TypeVarKind = exports.Variance = exports.UnionType = exports.TypeCondition = exports.AnyType = exports.NeverType = exports.OverloadedFunctionType = exports.FunctionType = exports.FunctionTypeFlags = exports.isKeywordOnlySeparator = exports.isPositionOnlySeparator = exports.FunctionParam = exports.FunctionParamFlags = exports.ClassType = exports.ClassTypeFlags = exports.ModuleType = exports.UnknownType = exports.UnboundType = exports.TypeBase = exports.maxTypeRecursionCount = exports.EnumLiteral = exports.UnificationScopeId = exports.TypeFlags = exports.TypeCategory = void 0;
|
12
|
+
exports.isSameWithoutLiteralValue = exports.combineTypes = exports.findSubtype = exports.removeFromUnion = void 0;
|
13
13
|
const debug_1 = require("../common/debug");
|
14
|
+
const typeUtils_1 = require("./typeUtils");
|
14
15
|
var TypeCategory;
|
15
16
|
(function (TypeCategory) {
|
16
17
|
// Name is not bound to a value of any type.
|
@@ -54,7 +55,7 @@ var TypeFlags;
|
|
54
55
|
// when comparing two types for equivalence.
|
55
56
|
TypeFlags[TypeFlags["TypeCompatibilityMask"] = 3] = "TypeCompatibilityMask";
|
56
57
|
})(TypeFlags || (exports.TypeFlags = TypeFlags = {}));
|
57
|
-
exports.
|
58
|
+
exports.UnificationScopeId = '-';
|
58
59
|
class EnumLiteral {
|
59
60
|
constructor(classFullName, className, itemName, itemType) {
|
60
61
|
this.classFullName = classFullName;
|
@@ -186,19 +187,9 @@ var TypeBase;
|
|
186
187
|
return newInstance;
|
187
188
|
}
|
188
189
|
TypeBase.cloneTypeAsInstantiable = cloneTypeAsInstantiable;
|
189
|
-
function cloneForTypeAlias(type,
|
190
|
+
function cloneForTypeAlias(type, aliasInfo) {
|
190
191
|
const typeClone = cloneType(type);
|
191
|
-
TypeBase.setTypeAliasInfo(typeClone,
|
192
|
-
name,
|
193
|
-
fullName,
|
194
|
-
moduleName,
|
195
|
-
fileUri,
|
196
|
-
typeVarScopeId,
|
197
|
-
isPep695Syntax,
|
198
|
-
typeParameters: typeParams,
|
199
|
-
usageVariance: undefined,
|
200
|
-
typeArguments: typeArgs,
|
201
|
-
});
|
192
|
+
TypeBase.setTypeAliasInfo(typeClone, aliasInfo);
|
202
193
|
return typeClone;
|
203
194
|
}
|
204
195
|
TypeBase.cloneForTypeAlias = cloneForTypeAlias;
|
@@ -395,8 +386,7 @@ var ClassTypeFlags;
|
|
395
386
|
// class is generic, and therefore supports standard subscripting
|
396
387
|
// semantics.
|
397
388
|
ClassTypeFlags[ClassTypeFlags["HasCustomClassGetItem"] = 16384] = "HasCustomClassGetItem";
|
398
|
-
// The tuple class
|
399
|
-
// special-case handling of its type arguments.
|
389
|
+
// The tuple class requires special-case handling for its type arguments.
|
400
390
|
ClassTypeFlags[ClassTypeFlags["TupleClass"] = 32768] = "TupleClass";
|
401
391
|
// The class has a metaclass of EnumMeta or derives from
|
402
392
|
// a class that has this metaclass.
|
@@ -442,7 +432,7 @@ var ClassType;
|
|
442
432
|
effectiveMetaclass,
|
443
433
|
mro: [],
|
444
434
|
fields: new Map(),
|
445
|
-
|
435
|
+
typeParams: [],
|
446
436
|
docString,
|
447
437
|
},
|
448
438
|
priv: {},
|
@@ -480,20 +470,25 @@ var ClassType;
|
|
480
470
|
return newInstance;
|
481
471
|
}
|
482
472
|
ClassType.cloneAsInstantiable = cloneAsInstantiable;
|
483
|
-
function
|
473
|
+
function specialize(classType, typeArgs, isTypeArgExplicit, includeSubclasses = false, tupleTypeArgs, isEmptyContainer) {
|
484
474
|
const newClassType = TypeBase.cloneType(classType);
|
485
|
-
newClassType.priv.
|
486
|
-
|
475
|
+
newClassType.priv.typeArgs = (typeArgs === null || typeArgs === void 0 ? void 0 : typeArgs.length) === 0 ? undefined : typeArgs;
|
476
|
+
// If the user passed undefined for this argument, infer it
|
477
|
+
// based on whether typeArgs was provided.
|
478
|
+
if (isTypeArgExplicit === undefined) {
|
479
|
+
isTypeArgExplicit = !!typeArgs;
|
480
|
+
}
|
481
|
+
newClassType.priv.isTypeArgExplicit = isTypeArgExplicit;
|
487
482
|
if (includeSubclasses) {
|
488
483
|
newClassType.priv.includeSubclasses = true;
|
489
484
|
}
|
490
|
-
newClassType.priv.
|
485
|
+
newClassType.priv.tupleTypeArgs = tupleTypeArgs ? [...tupleTypeArgs] : undefined;
|
491
486
|
if (isEmptyContainer !== undefined) {
|
492
487
|
newClassType.priv.isEmptyContainer = isEmptyContainer;
|
493
488
|
}
|
494
489
|
return newClassType;
|
495
490
|
}
|
496
|
-
ClassType.
|
491
|
+
ClassType.specialize = specialize;
|
497
492
|
function cloneIncludeSubclasses(classType, includeSubclasses = true) {
|
498
493
|
if (!!classType.priv.includeSubclasses === includeSubclasses) {
|
499
494
|
return classType;
|
@@ -550,13 +545,6 @@ var ClassType;
|
|
550
545
|
return newClassType;
|
551
546
|
}
|
552
547
|
ClassType.cloneRemoveTypePromotions = cloneRemoveTypePromotions;
|
553
|
-
function cloneForTypeGuard(classType, typeGuardType, isStrictTypeGuard) {
|
554
|
-
const newClassType = TypeBase.cloneType(classType);
|
555
|
-
newClassType.priv.typeGuardType = typeGuardType;
|
556
|
-
newClassType.priv.isStrictTypeGuard = isStrictTypeGuard;
|
557
|
-
return newClassType;
|
558
|
-
}
|
559
|
-
ClassType.cloneForTypeGuard = cloneForTypeGuard;
|
560
548
|
function cloneForSymbolTableUpdate(classType) {
|
561
549
|
const newClassType = TypeBase.cloneType(classType);
|
562
550
|
newClassType.shared = { ...newClassType.shared };
|
@@ -651,7 +639,7 @@ var ClassType;
|
|
651
639
|
ClassType.isTypedDictNarrower = isTypedDictNarrower;
|
652
640
|
// Is the class generic but not specialized?
|
653
641
|
function isUnspecialized(classType) {
|
654
|
-
return classType.shared.
|
642
|
+
return classType.shared.typeParams.length > 0 && classType.priv.typeArgs === undefined;
|
655
643
|
}
|
656
644
|
ClassType.isUnspecialized = isUnspecialized;
|
657
645
|
function isSpecialBuiltIn(classType, className) {
|
@@ -813,10 +801,10 @@ var ClassType;
|
|
813
801
|
return !!(classType.shared.flags & 524288 /* ClassTypeFlags.ReadOnlyInstanceVariables */);
|
814
802
|
}
|
815
803
|
ClassType.isReadOnlyInstanceVariables = isReadOnlyInstanceVariables;
|
816
|
-
function
|
817
|
-
return classType.shared.
|
804
|
+
function getTypeParams(classType) {
|
805
|
+
return classType.shared.typeParams;
|
818
806
|
}
|
819
|
-
ClassType.
|
807
|
+
ClassType.getTypeParams = getTypeParams;
|
820
808
|
function derivesFromAnyOrUnknown(classType) {
|
821
809
|
return classType.shared.mro.some((baseClass) => isAnyOrUnknown(baseClass));
|
822
810
|
}
|
@@ -860,7 +848,7 @@ var ClassType;
|
|
860
848
|
class1Details.flags !== class2Details.flags ||
|
861
849
|
class1Details.typeSourceId !== class2Details.typeSourceId ||
|
862
850
|
class1Details.baseClasses.length !== class2Details.baseClasses.length ||
|
863
|
-
class1Details.
|
851
|
+
class1Details.typeParams.length !== class2Details.typeParams.length) {
|
864
852
|
return false;
|
865
853
|
}
|
866
854
|
if (recursionCount > exports.maxTypeRecursionCount) {
|
@@ -888,8 +876,8 @@ var ClassType;
|
|
888
876
|
return false;
|
889
877
|
}
|
890
878
|
}
|
891
|
-
for (let i = 0; i < class1Details.
|
892
|
-
if (!isTypeSame(class1Details.
|
879
|
+
for (let i = 0; i < class1Details.typeParams.length; i++) {
|
880
|
+
if (!isTypeSame(class1Details.typeParams[i], class2Details.typeParams[i], { ignorePseudoGeneric: true }, recursionCount)) {
|
893
881
|
return false;
|
894
882
|
}
|
895
883
|
}
|
@@ -971,7 +959,7 @@ var FunctionParamFlags;
|
|
971
959
|
var FunctionParam;
|
972
960
|
(function (FunctionParam) {
|
973
961
|
function create(category, type, flags = FunctionParamFlags.None, name, defaultType) {
|
974
|
-
return { category,
|
962
|
+
return { category, flags, name, _type: type, _defaultType: defaultType };
|
975
963
|
}
|
976
964
|
FunctionParam.create = create;
|
977
965
|
function isNameSynthesized(param) {
|
@@ -989,12 +977,12 @@ var FunctionParam;
|
|
989
977
|
})(FunctionParam || (exports.FunctionParam = FunctionParam = {}));
|
990
978
|
function isPositionOnlySeparator(param) {
|
991
979
|
// A simple parameter with no name is treated as a "/" separator.
|
992
|
-
return param.category === 0 /*
|
980
|
+
return param.category === 0 /* ParamCategory.Simple */ && !param.name;
|
993
981
|
}
|
994
982
|
exports.isPositionOnlySeparator = isPositionOnlySeparator;
|
995
983
|
function isKeywordOnlySeparator(param) {
|
996
984
|
// An *args parameter with no name is treated as a "*" separator.
|
997
|
-
return param.category === 1 /*
|
985
|
+
return param.category === 1 /* ParamCategory.ArgsList */ && !param.name;
|
998
986
|
}
|
999
987
|
exports.isKeywordOnlySeparator = isKeywordOnlySeparator;
|
1000
988
|
var FunctionTypeFlags;
|
@@ -1078,7 +1066,7 @@ var FunctionType;
|
|
1078
1066
|
fullName,
|
1079
1067
|
moduleName,
|
1080
1068
|
flags: functionFlags,
|
1081
|
-
|
1069
|
+
typeParams: [],
|
1082
1070
|
parameters: [],
|
1083
1071
|
declaredReturnType: undefined,
|
1084
1072
|
declaration: undefined,
|
@@ -1094,22 +1082,24 @@ var FunctionType;
|
|
1094
1082
|
}
|
1095
1083
|
// Creates a deep copy of the function type, including a fresh
|
1096
1084
|
// version of _functionDetails.
|
1097
|
-
function clone(type, stripFirstParam = false, boundToType
|
1085
|
+
function clone(type, stripFirstParam = false, boundToType) {
|
1098
1086
|
var _a, _b;
|
1099
1087
|
const newFunction = TypeBase.cloneType(type);
|
1100
1088
|
newFunction.shared = { ...type.shared };
|
1101
1089
|
newFunction.priv.preBoundFlags = newFunction.shared.flags;
|
1102
1090
|
newFunction.priv.boundToType = boundToType;
|
1103
|
-
if (
|
1104
|
-
|
1091
|
+
if (boundToType) {
|
1092
|
+
if (type.shared.name === '__new__' || type.shared.name === '__init__') {
|
1093
|
+
newFunction.priv.constructorTypeVarScopeId = (0, typeUtils_1.getTypeVarScopeId)(boundToType);
|
1094
|
+
}
|
1105
1095
|
}
|
1106
1096
|
if (stripFirstParam) {
|
1107
1097
|
if (type.shared.parameters.length > 0) {
|
1108
|
-
if (type.shared.parameters[0].category === 0 /*
|
1098
|
+
if (type.shared.parameters[0].category === 0 /* ParamCategory.Simple */) {
|
1109
1099
|
if (type.shared.parameters.length > 0 && !FunctionParam.isTypeInferred(type.shared.parameters[0])) {
|
1110
1100
|
// Stash away the effective type of the first parameter if it
|
1111
1101
|
// wasn't synthesized.
|
1112
|
-
newFunction.priv.strippedFirstParamType =
|
1102
|
+
newFunction.priv.strippedFirstParamType = getParamType(type, 0);
|
1113
1103
|
}
|
1114
1104
|
newFunction.shared.parameters = type.shared.parameters.slice(1);
|
1115
1105
|
}
|
@@ -1130,9 +1120,9 @@ var FunctionType;
|
|
1130
1120
|
parameterTypes: stripFirstParam
|
1131
1121
|
? type.priv.specializedTypes.parameterTypes.slice(1)
|
1132
1122
|
: type.priv.specializedTypes.parameterTypes,
|
1133
|
-
|
1134
|
-
? (_b = type.priv.specializedTypes.
|
1135
|
-
: type.priv.specializedTypes.
|
1123
|
+
parameterDefaultTypes: stripFirstParam
|
1124
|
+
? (_b = type.priv.specializedTypes.parameterDefaultTypes) === null || _b === void 0 ? void 0 : _b.slice(1)
|
1125
|
+
: type.priv.specializedTypes.parameterDefaultTypes,
|
1136
1126
|
returnType: type.priv.specializedTypes.returnType,
|
1137
1127
|
};
|
1138
1128
|
}
|
@@ -1164,17 +1154,17 @@ var FunctionType;
|
|
1164
1154
|
// Creates a shallow copy of the function type with new
|
1165
1155
|
// specialized types. The clone shares the _functionDetails
|
1166
1156
|
// with the object being cloned.
|
1167
|
-
function
|
1157
|
+
function specialize(type, specializedTypes, specializedInferredReturnType) {
|
1168
1158
|
const newFunction = TypeBase.cloneType(type);
|
1169
1159
|
(0, debug_1.assert)(specializedTypes.parameterTypes.length === type.shared.parameters.length);
|
1170
|
-
if (specializedTypes.
|
1171
|
-
(0, debug_1.assert)(specializedTypes.
|
1160
|
+
if (specializedTypes.parameterDefaultTypes) {
|
1161
|
+
(0, debug_1.assert)(specializedTypes.parameterDefaultTypes.length === type.shared.parameters.length);
|
1172
1162
|
}
|
1173
1163
|
newFunction.priv.specializedTypes = specializedTypes;
|
1174
1164
|
newFunction.priv.inferredReturnType = specializedInferredReturnType;
|
1175
1165
|
return newFunction;
|
1176
1166
|
}
|
1177
|
-
FunctionType.
|
1167
|
+
FunctionType.specialize = specialize;
|
1178
1168
|
// Creates a new function based on the parameters of another function.
|
1179
1169
|
function applyParamSpecValue(type, paramSpecValue) {
|
1180
1170
|
const hasPositionalOnly = paramSpecValue.shared.parameters.some((param) => isPositionOnlySeparator(param));
|
@@ -1183,12 +1173,12 @@ var FunctionType;
|
|
1183
1173
|
(0, debug_1.assert)(paramSpec !== undefined);
|
1184
1174
|
// Make a shallow clone of the details.
|
1185
1175
|
newFunction.shared = { ...newFunction.shared };
|
1186
|
-
newFunction.shared.
|
1176
|
+
newFunction.shared.typeParams = newFunction.shared.typeParams.filter((t) => !isTypeSame(t, paramSpec));
|
1187
1177
|
const prevParams = Array.from(newFunction.shared.parameters);
|
1188
1178
|
newFunction.shared.parameters = [
|
1189
1179
|
...prevParams,
|
1190
|
-
...paramSpecValue.shared.parameters.map((param) => {
|
1191
|
-
return FunctionParam.create(param.category,
|
1180
|
+
...paramSpecValue.shared.parameters.map((param, index) => {
|
1181
|
+
return FunctionParam.create(param.category, FunctionType.getParamType(paramSpecValue, index), (param.flags & FunctionParamFlags.NameSynthesized) | FunctionParamFlags.TypeDeclared, param.name, FunctionType.getParamDefaultType(paramSpecValue, index));
|
1192
1182
|
}),
|
1193
1183
|
];
|
1194
1184
|
if (newFunction.shared.docString === undefined) {
|
@@ -1218,16 +1208,14 @@ var FunctionType;
|
|
1218
1208
|
// Update the specialized parameter types as well.
|
1219
1209
|
const specializedTypes = newFunction.priv.specializedTypes;
|
1220
1210
|
if (specializedTypes) {
|
1221
|
-
paramSpecValue.shared.parameters.forEach((
|
1211
|
+
paramSpecValue.shared.parameters.forEach((_, index) => {
|
1222
1212
|
var _a;
|
1223
|
-
specializedTypes.parameterTypes.push(
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1213
|
+
specializedTypes.parameterTypes.push(FunctionType.getParamType(paramSpecValue, index));
|
1214
|
+
if (specializedTypes.parameterDefaultTypes) {
|
1215
|
+
(_a = specializedTypes.parameterDefaultTypes) === null || _a === void 0 ? void 0 : _a.push(FunctionType.getParamDefaultType(paramSpecValue, index));
|
1216
|
+
}
|
1227
1217
|
});
|
1228
1218
|
}
|
1229
|
-
FunctionType.addHigherOrderTypeVarScopeIds(newFunction, paramSpecValue.shared.typeVarScopeId);
|
1230
|
-
FunctionType.addHigherOrderTypeVarScopeIds(newFunction, paramSpecValue.priv.higherOrderTypeVarScopeIds);
|
1231
1219
|
newFunction.priv.constructorTypeVarScopeId = paramSpecValue.priv.constructorTypeVarScopeId;
|
1232
1220
|
if (!newFunction.shared.methodClass && paramSpecValue.shared.methodClass) {
|
1233
1221
|
newFunction.shared.methodClass = paramSpecValue.shared.methodClass;
|
@@ -1243,14 +1231,13 @@ var FunctionType;
|
|
1243
1231
|
return newFunction;
|
1244
1232
|
}
|
1245
1233
|
FunctionType.cloneWithNewFlags = cloneWithNewFlags;
|
1246
|
-
function cloneWithNewTypeVarScopeId(type, newScopeId, newConstructorScopeId,
|
1234
|
+
function cloneWithNewTypeVarScopeId(type, newScopeId, newConstructorScopeId, typeParams) {
|
1247
1235
|
const newFunction = TypeBase.cloneType(type);
|
1248
1236
|
// Make a shallow clone of the details.
|
1249
1237
|
newFunction.shared = { ...type.shared };
|
1250
1238
|
newFunction.shared.typeVarScopeId = newScopeId;
|
1251
1239
|
newFunction.priv.constructorTypeVarScopeId = newConstructorScopeId;
|
1252
|
-
newFunction.shared.
|
1253
|
-
FunctionType.addHigherOrderTypeVarScopeIds(newFunction, typeParameters.map((t) => { var _a, _b; return (_b = (_a = t.priv.externalTypeVar) === null || _a === void 0 ? void 0 : _a.priv.scopeId) !== null && _b !== void 0 ? _b : t.priv.scopeId; }));
|
1240
|
+
newFunction.shared.typeParams = typeParams;
|
1254
1241
|
return newFunction;
|
1255
1242
|
}
|
1256
1243
|
FunctionType.cloneWithNewTypeVarScopeId = cloneWithNewTypeVarScopeId;
|
@@ -1281,12 +1268,11 @@ var FunctionType;
|
|
1281
1268
|
}
|
1282
1269
|
const argsParam = type.shared.parameters[paramCount - 2];
|
1283
1270
|
const kwargsParam = type.shared.parameters[paramCount - 1];
|
1284
|
-
if (argsParam.category !== 1 /*
|
1285
|
-
kwargsParam.category !== 2 /* ParameterCategory.KwargsDict */) {
|
1271
|
+
if (argsParam.category !== 1 /* ParamCategory.ArgsList */ || kwargsParam.category !== 2 /* ParamCategory.KwargsDict */) {
|
1286
1272
|
return type;
|
1287
1273
|
}
|
1288
|
-
const argsType = FunctionType.
|
1289
|
-
const kwargsType = FunctionType.
|
1274
|
+
const argsType = FunctionType.getParamType(type, paramCount - 2);
|
1275
|
+
const kwargsType = FunctionType.getParamType(type, paramCount - 1);
|
1290
1276
|
if (!isParamSpec(argsType) || !isParamSpec(kwargsType) || !isTypeSame(argsType, kwargsType)) {
|
1291
1277
|
return type;
|
1292
1278
|
}
|
@@ -1307,9 +1293,9 @@ var FunctionType;
|
|
1307
1293
|
if (type.priv.specializedTypes) {
|
1308
1294
|
newFunction.priv.specializedTypes = { ...type.priv.specializedTypes };
|
1309
1295
|
newFunction.priv.specializedTypes.parameterTypes = newFunction.priv.specializedTypes.parameterTypes.slice(0, newFunction.priv.specializedTypes.parameterTypes.length - paramsToDrop);
|
1310
|
-
if (newFunction.priv.specializedTypes.
|
1311
|
-
newFunction.priv.specializedTypes.
|
1312
|
-
newFunction.priv.specializedTypes.
|
1296
|
+
if (newFunction.priv.specializedTypes.parameterDefaultTypes) {
|
1297
|
+
newFunction.priv.specializedTypes.parameterDefaultTypes =
|
1298
|
+
newFunction.priv.specializedTypes.parameterDefaultTypes.slice(0, newFunction.priv.specializedTypes.parameterDefaultTypes.length - paramsToDrop);
|
1313
1299
|
}
|
1314
1300
|
}
|
1315
1301
|
if (type.priv.inferredReturnType) {
|
@@ -1326,59 +1312,40 @@ var FunctionType;
|
|
1326
1312
|
return undefined;
|
1327
1313
|
}
|
1328
1314
|
const secondLastParam = params[params.length - 2];
|
1315
|
+
const secondLastParamType = FunctionType.getParamType(type, params.length - 2);
|
1329
1316
|
const lastParam = params[params.length - 1];
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1317
|
+
const lastParamType = FunctionType.getParamType(type, params.length - 1);
|
1318
|
+
if (secondLastParam.category === 1 /* ParamCategory.ArgsList */ &&
|
1319
|
+
isParamSpec(secondLastParamType) &&
|
1320
|
+
secondLastParamType.priv.paramSpecAccess === 'args' &&
|
1321
|
+
lastParam.category === 2 /* ParamCategory.KwargsDict */ &&
|
1322
|
+
isParamSpec(lastParamType) &&
|
1323
|
+
lastParamType.priv.paramSpecAccess === 'kwargs') {
|
1324
|
+
return TypeVarType.cloneForParamSpecAccess(secondLastParamType, /* access */ undefined);
|
1337
1325
|
}
|
1338
1326
|
return undefined;
|
1339
1327
|
}
|
1340
1328
|
FunctionType.getParamSpecFromArgsKwargs = getParamSpecFromArgsKwargs;
|
1341
1329
|
function addParamSpecVariadics(type, paramSpec) {
|
1342
|
-
FunctionType.
|
1343
|
-
FunctionType.
|
1330
|
+
FunctionType.addParam(type, FunctionParam.create(1 /* ParamCategory.ArgsList */, TypeVarType.cloneForParamSpecAccess(paramSpec, 'args'), FunctionParamFlags.TypeDeclared, 'args'));
|
1331
|
+
FunctionType.addParam(type, FunctionParam.create(2 /* ParamCategory.KwargsDict */, TypeVarType.cloneForParamSpecAccess(paramSpec, 'kwargs'), FunctionParamFlags.TypeDeclared, 'kwargs'));
|
1344
1332
|
}
|
1345
1333
|
FunctionType.addParamSpecVariadics = addParamSpecVariadics;
|
1346
|
-
function
|
1347
|
-
|
1348
|
-
FunctionType.
|
1349
|
-
});
|
1350
|
-
}
|
1351
|
-
FunctionType.addDefaultParameters = addDefaultParameters;
|
1352
|
-
function addHigherOrderTypeVarScopeIds(functionType, scopeIds) {
|
1353
|
-
if (!scopeIds) {
|
1354
|
-
return;
|
1355
|
-
}
|
1356
|
-
if (!Array.isArray(scopeIds)) {
|
1357
|
-
scopeIds = [scopeIds];
|
1358
|
-
}
|
1359
|
-
if (!functionType.priv.higherOrderTypeVarScopeIds) {
|
1360
|
-
functionType.priv.higherOrderTypeVarScopeIds = [];
|
1361
|
-
}
|
1362
|
-
// Add the scope IDs to the function if they're unique.
|
1363
|
-
scopeIds.forEach((scopeId) => {
|
1364
|
-
if (!scopeId || scopeId === functionType.shared.typeVarScopeId) {
|
1365
|
-
return;
|
1366
|
-
}
|
1367
|
-
if (!functionType.priv.higherOrderTypeVarScopeIds.some((id) => id === scopeId)) {
|
1368
|
-
functionType.priv.higherOrderTypeVarScopeIds.push(scopeId);
|
1369
|
-
}
|
1334
|
+
function addDefaultParams(type, useUnknown = false) {
|
1335
|
+
getDefaultParams(useUnknown).forEach((param) => {
|
1336
|
+
FunctionType.addParam(type, param);
|
1370
1337
|
});
|
1371
1338
|
}
|
1372
|
-
FunctionType.
|
1373
|
-
function
|
1339
|
+
FunctionType.addDefaultParams = addDefaultParams;
|
1340
|
+
function getDefaultParams(useUnknown = false) {
|
1374
1341
|
return [
|
1375
|
-
FunctionParam.create(1 /*
|
1376
|
-
FunctionParam.create(2 /*
|
1342
|
+
FunctionParam.create(1 /* ParamCategory.ArgsList */, useUnknown ? UnknownType.create() : AnyType.create(), useUnknown ? FunctionParamFlags.None : FunctionParamFlags.TypeDeclared, 'args'),
|
1343
|
+
FunctionParam.create(2 /* ParamCategory.KwargsDict */, useUnknown ? UnknownType.create() : AnyType.create(), useUnknown ? FunctionParamFlags.None : FunctionParamFlags.TypeDeclared, 'kwargs'),
|
1377
1344
|
];
|
1378
1345
|
}
|
1379
|
-
FunctionType.
|
1346
|
+
FunctionType.getDefaultParams = getDefaultParams;
|
1380
1347
|
// Indicates whether the input signature consists of (*args: Any, **kwargs: Any).
|
1381
|
-
function
|
1348
|
+
function hasDefaultParams(functionType) {
|
1382
1349
|
let sawArgs = false;
|
1383
1350
|
let sawKwargs = false;
|
1384
1351
|
for (let i = 0; i < functionType.shared.parameters.length; i++) {
|
@@ -1387,22 +1354,22 @@ var FunctionType;
|
|
1387
1354
|
if (!param.name) {
|
1388
1355
|
continue;
|
1389
1356
|
}
|
1390
|
-
if (param.category === 0 /*
|
1357
|
+
if (param.category === 0 /* ParamCategory.Simple */) {
|
1391
1358
|
return false;
|
1392
1359
|
}
|
1393
|
-
else if (param.category === 1 /*
|
1360
|
+
else if (param.category === 1 /* ParamCategory.ArgsList */) {
|
1394
1361
|
sawArgs = true;
|
1395
1362
|
}
|
1396
|
-
else if (param.category === 2 /*
|
1363
|
+
else if (param.category === 2 /* ParamCategory.KwargsDict */) {
|
1397
1364
|
sawKwargs = true;
|
1398
1365
|
}
|
1399
|
-
if (!isAnyOrUnknown(FunctionType.
|
1366
|
+
if (!isAnyOrUnknown(FunctionType.getParamType(functionType, i))) {
|
1400
1367
|
return false;
|
1401
1368
|
}
|
1402
1369
|
}
|
1403
1370
|
return sawArgs && sawKwargs;
|
1404
1371
|
}
|
1405
|
-
FunctionType.
|
1372
|
+
FunctionType.hasDefaultParams = hasDefaultParams;
|
1406
1373
|
function isInstanceMethod(type) {
|
1407
1374
|
return ((type.shared.flags &
|
1408
1375
|
(1 /* FunctionTypeFlags.ConstructorMethod */ |
|
@@ -1443,10 +1410,10 @@ var FunctionType;
|
|
1443
1410
|
return (type.shared.flags & 256 /* FunctionTypeFlags.Overloaded */) !== 0;
|
1444
1411
|
}
|
1445
1412
|
FunctionType.isOverloaded = isOverloaded;
|
1446
|
-
function
|
1413
|
+
function isDefaultParamCheckDisabled(type) {
|
1447
1414
|
return (type.shared.flags & 32 /* FunctionTypeFlags.DisableDefaultChecks */) !== 0;
|
1448
1415
|
}
|
1449
|
-
FunctionType.
|
1416
|
+
FunctionType.isDefaultParamCheckDisabled = isDefaultParamCheckDisabled;
|
1450
1417
|
function isAsync(type) {
|
1451
1418
|
return (type.shared.flags & 512 /* FunctionTypeFlags.Async */) !== 0;
|
1452
1419
|
}
|
@@ -1494,42 +1461,46 @@ var FunctionType;
|
|
1494
1461
|
return true;
|
1495
1462
|
}
|
1496
1463
|
FunctionType.isBuiltIn = isBuiltIn;
|
1497
|
-
function
|
1464
|
+
function getDeclaredParamType(type, index) {
|
1465
|
+
return type.shared.parameters[index]._type;
|
1466
|
+
}
|
1467
|
+
FunctionType.getDeclaredParamType = getDeclaredParamType;
|
1468
|
+
function getParamType(type, index) {
|
1498
1469
|
(0, debug_1.assert)(index < type.shared.parameters.length, 'Parameter types array overflow');
|
1499
1470
|
if (type.priv.specializedTypes && index < type.priv.specializedTypes.parameterTypes.length) {
|
1500
1471
|
return type.priv.specializedTypes.parameterTypes[index];
|
1501
1472
|
}
|
1502
|
-
return type.shared.parameters[index].
|
1473
|
+
return type.shared.parameters[index]._type;
|
1503
1474
|
}
|
1504
|
-
FunctionType.
|
1505
|
-
function
|
1475
|
+
FunctionType.getParamType = getParamType;
|
1476
|
+
function getParamDefaultType(type, index) {
|
1506
1477
|
var _a;
|
1507
1478
|
(0, debug_1.assert)(index < type.shared.parameters.length, 'Parameter types array overflow');
|
1508
|
-
if (((_a = type.priv.specializedTypes) === null || _a === void 0 ? void 0 : _a.
|
1509
|
-
index < type.priv.specializedTypes.
|
1510
|
-
const defaultArgType = type.priv.specializedTypes.
|
1479
|
+
if (((_a = type.priv.specializedTypes) === null || _a === void 0 ? void 0 : _a.parameterDefaultTypes) &&
|
1480
|
+
index < type.priv.specializedTypes.parameterDefaultTypes.length) {
|
1481
|
+
const defaultArgType = type.priv.specializedTypes.parameterDefaultTypes[index];
|
1511
1482
|
if (defaultArgType) {
|
1512
1483
|
return defaultArgType;
|
1513
1484
|
}
|
1514
1485
|
}
|
1515
|
-
return type.shared.parameters[index].
|
1486
|
+
return type.shared.parameters[index]._defaultType;
|
1516
1487
|
}
|
1517
|
-
FunctionType.
|
1518
|
-
function
|
1488
|
+
FunctionType.getParamDefaultType = getParamDefaultType;
|
1489
|
+
function addParam(type, param) {
|
1519
1490
|
type.shared.parameters.push(param);
|
1520
1491
|
if (type.priv.specializedTypes) {
|
1521
|
-
type.priv.specializedTypes.parameterTypes.push(param.
|
1492
|
+
type.priv.specializedTypes.parameterTypes.push(param._type);
|
1522
1493
|
}
|
1523
1494
|
}
|
1524
|
-
FunctionType.
|
1525
|
-
function
|
1526
|
-
|
1495
|
+
FunctionType.addParam = addParam;
|
1496
|
+
function addPositionOnlyParamSeparator(type) {
|
1497
|
+
addParam(type, FunctionParam.create(0 /* ParamCategory.Simple */, AnyType.create()));
|
1527
1498
|
}
|
1528
|
-
FunctionType.
|
1529
|
-
function
|
1530
|
-
|
1499
|
+
FunctionType.addPositionOnlyParamSeparator = addPositionOnlyParamSeparator;
|
1500
|
+
function addKeywordOnlyParamSeparator(type) {
|
1501
|
+
addParam(type, FunctionParam.create(1 /* ParamCategory.ArgsList */, AnyType.create()));
|
1531
1502
|
}
|
1532
|
-
FunctionType.
|
1503
|
+
FunctionType.addKeywordOnlyParamSeparator = addKeywordOnlyParamSeparator;
|
1533
1504
|
function getEffectiveReturnType(type, includeInferred = true) {
|
1534
1505
|
var _a;
|
1535
1506
|
if ((_a = type.priv.specializedTypes) === null || _a === void 0 ? void 0 : _a.returnType) {
|
@@ -1856,20 +1827,36 @@ var Variance;
|
|
1856
1827
|
Variance[Variance["Covariant"] = 3] = "Covariant";
|
1857
1828
|
Variance[Variance["Contravariant"] = 4] = "Contravariant";
|
1858
1829
|
})(Variance || (exports.Variance = Variance = {}));
|
1830
|
+
var TypeVarKind;
|
1831
|
+
(function (TypeVarKind) {
|
1832
|
+
TypeVarKind[TypeVarKind["TypeVar"] = 0] = "TypeVar";
|
1833
|
+
TypeVarKind[TypeVarKind["TypeVarTuple"] = 1] = "TypeVarTuple";
|
1834
|
+
TypeVarKind[TypeVarKind["ParamSpec"] = 2] = "ParamSpec";
|
1835
|
+
})(TypeVarKind || (exports.TypeVarKind = TypeVarKind = {}));
|
1859
1836
|
var TypeVarScopeType;
|
1860
1837
|
(function (TypeVarScopeType) {
|
1861
1838
|
TypeVarScopeType[TypeVarScopeType["Class"] = 0] = "Class";
|
1862
1839
|
TypeVarScopeType[TypeVarScopeType["Function"] = 1] = "Function";
|
1863
1840
|
TypeVarScopeType[TypeVarScopeType["TypeAlias"] = 2] = "TypeAlias";
|
1864
1841
|
})(TypeVarScopeType || (exports.TypeVarScopeType = TypeVarScopeType = {}));
|
1842
|
+
var ParamSpecType;
|
1843
|
+
(function (ParamSpecType) {
|
1844
|
+
// Returns the "Unknown" equivalent for a ParamSpec.
|
1845
|
+
function getUnknown() {
|
1846
|
+
const newFunction = FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.GradualCallableForm */);
|
1847
|
+
FunctionType.addDefaultParams(newFunction);
|
1848
|
+
return newFunction;
|
1849
|
+
}
|
1850
|
+
ParamSpecType.getUnknown = getUnknown;
|
1851
|
+
})(ParamSpecType || (exports.ParamSpecType = ParamSpecType = {}));
|
1865
1852
|
var TypeVarType;
|
1866
1853
|
(function (TypeVarType) {
|
1867
|
-
function createInstance(name) {
|
1868
|
-
return create(name,
|
1854
|
+
function createInstance(name, kind = TypeVarKind.TypeVar) {
|
1855
|
+
return create(name, kind, 2 /* TypeFlags.Instance */);
|
1869
1856
|
}
|
1870
1857
|
TypeVarType.createInstance = createInstance;
|
1871
|
-
function createInstantiable(name,
|
1872
|
-
return create(name,
|
1858
|
+
function createInstantiable(name, kind = TypeVarKind.TypeVar) {
|
1859
|
+
return create(name, kind, 1 /* TypeFlags.Instantiable */);
|
1873
1860
|
}
|
1874
1861
|
TypeVarType.createInstantiable = createInstantiable;
|
1875
1862
|
function cloneAsInstance(type) {
|
@@ -1882,8 +1869,8 @@ var TypeVarType;
|
|
1882
1869
|
if ((_b = newInstance.props) === null || _b === void 0 ? void 0 : _b.specialForm) {
|
1883
1870
|
TypeBase.setSpecialForm(newInstance, undefined);
|
1884
1871
|
}
|
1885
|
-
if (newInstance.priv.
|
1886
|
-
newInstance.priv.
|
1872
|
+
if (newInstance.priv.freeTypeVar) {
|
1873
|
+
newInstance.priv.freeTypeVar = TypeVarType.cloneAsInstance(newInstance.priv.freeTypeVar);
|
1887
1874
|
}
|
1888
1875
|
return newInstance;
|
1889
1876
|
}
|
@@ -1894,8 +1881,8 @@ var TypeVarType;
|
|
1894
1881
|
return type.cached.typeBaseInstantiableType;
|
1895
1882
|
}
|
1896
1883
|
const newInstance = TypeBase.cloneTypeAsInstantiable(type, /* cache */ true);
|
1897
|
-
if (newInstance.priv.
|
1898
|
-
newInstance.priv.
|
1884
|
+
if (newInstance.priv.freeTypeVar) {
|
1885
|
+
newInstance.priv.freeTypeVar = TypeVarType.cloneAsInstantiable(newInstance.priv.freeTypeVar);
|
1899
1886
|
}
|
1900
1887
|
return newInstance;
|
1901
1888
|
}
|
@@ -1920,39 +1907,37 @@ var TypeVarType;
|
|
1920
1907
|
}
|
1921
1908
|
TypeVarType.cloneForScopeId = cloneForScopeId;
|
1922
1909
|
function cloneForUnpacked(type, isInUnion = false) {
|
1923
|
-
(0, debug_1.assert)(type.shared.isVariadic);
|
1924
1910
|
const newInstance = TypeBase.cloneType(type);
|
1925
|
-
newInstance.priv.
|
1926
|
-
newInstance.priv.
|
1927
|
-
if (newInstance.priv.
|
1928
|
-
newInstance.priv.
|
1911
|
+
newInstance.priv.isUnpacked = true;
|
1912
|
+
newInstance.priv.isInUnion = isInUnion;
|
1913
|
+
if (newInstance.priv.freeTypeVar) {
|
1914
|
+
newInstance.priv.freeTypeVar = TypeVarType.cloneForUnpacked(newInstance.priv.freeTypeVar, isInUnion);
|
1929
1915
|
}
|
1930
1916
|
return newInstance;
|
1931
1917
|
}
|
1932
1918
|
TypeVarType.cloneForUnpacked = cloneForUnpacked;
|
1933
1919
|
function cloneForPacked(type) {
|
1934
|
-
(0, debug_1.assert)(type.shared.isVariadic);
|
1935
1920
|
const newInstance = TypeBase.cloneType(type);
|
1936
|
-
newInstance.priv.
|
1937
|
-
newInstance.priv.
|
1938
|
-
if (newInstance.priv.
|
1939
|
-
newInstance.priv.
|
1921
|
+
newInstance.priv.isUnpacked = false;
|
1922
|
+
newInstance.priv.isInUnion = false;
|
1923
|
+
if (newInstance.priv.freeTypeVar) {
|
1924
|
+
newInstance.priv.freeTypeVar = TypeVarType.cloneForPacked(newInstance.priv.freeTypeVar);
|
1940
1925
|
}
|
1941
1926
|
return newInstance;
|
1942
1927
|
}
|
1943
1928
|
TypeVarType.cloneForPacked = cloneForPacked;
|
1944
1929
|
// Creates a "simplified" version of the TypeVar with invariance
|
1945
|
-
// and no bound or constraints. ParamSpecs and
|
1930
|
+
// and no bound or constraints. ParamSpecs and TypeVarTuples are left
|
1946
1931
|
// unmodified. So are auto-variant type variables.
|
1947
1932
|
function cloneAsInvariant(type) {
|
1948
|
-
if (type
|
1933
|
+
if (isParamSpec(type) || isTypeVarTuple(type)) {
|
1949
1934
|
return type;
|
1950
1935
|
}
|
1951
1936
|
if (type.shared.declaredVariance === 0 /* Variance.Auto */) {
|
1952
1937
|
return type;
|
1953
1938
|
}
|
1954
1939
|
if (type.shared.declaredVariance === 2 /* Variance.Invariant */) {
|
1955
|
-
if (type
|
1940
|
+
if (!TypeVarType.hasBound(type) && !TypeVarType.hasConstraints(type)) {
|
1956
1941
|
return type;
|
1957
1942
|
}
|
1958
1943
|
}
|
@@ -1971,15 +1956,15 @@ var TypeVarType;
|
|
1971
1956
|
}
|
1972
1957
|
TypeVarType.cloneForParamSpecAccess = cloneForParamSpecAccess;
|
1973
1958
|
function cloneAsSpecializedSelf(type, specializedBoundType) {
|
1974
|
-
(0, debug_1.assert)(type
|
1959
|
+
(0, debug_1.assert)(TypeVarType.isSelf(type));
|
1975
1960
|
const newInstance = TypeBase.cloneType(type);
|
1976
1961
|
newInstance.shared = { ...newInstance.shared };
|
1977
1962
|
newInstance.shared.boundType = specializedBoundType;
|
1978
1963
|
return newInstance;
|
1979
1964
|
}
|
1980
1965
|
TypeVarType.cloneAsSpecializedSelf = cloneAsSpecializedSelf;
|
1981
|
-
function
|
1982
|
-
if (type
|
1966
|
+
function cloneAsUnificationVar(type, usageOffset) {
|
1967
|
+
if (TypeVarType.isUnification(type)) {
|
1983
1968
|
return type;
|
1984
1969
|
}
|
1985
1970
|
// If the caller specified a usage offset, append it to the TypeVar
|
@@ -1991,50 +1976,60 @@ var TypeVarType;
|
|
1991
1976
|
newNameWithScope = `${type.priv.nameWithScope}-${usageOffset}`;
|
1992
1977
|
}
|
1993
1978
|
const newInstance = TypeBase.cloneType(type);
|
1994
|
-
newInstance.priv.
|
1995
|
-
newInstance.priv.scopeId = exports.
|
1979
|
+
newInstance.priv.isUnificationVar = true;
|
1980
|
+
newInstance.priv.scopeId = exports.UnificationScopeId;
|
1996
1981
|
newInstance.priv.nameWithScope = newNameWithScope;
|
1997
1982
|
return newInstance;
|
1998
1983
|
}
|
1999
|
-
TypeVarType.
|
1984
|
+
TypeVarType.cloneAsUnificationVar = cloneAsUnificationVar;
|
2000
1985
|
function makeNameWithScope(name, scopeId) {
|
2001
1986
|
return `${name}.${scopeId}`;
|
2002
1987
|
}
|
2003
1988
|
TypeVarType.makeNameWithScope = makeNameWithScope;
|
2004
|
-
function
|
1989
|
+
function makeBoundScopeId(scopeId) {
|
2005
1990
|
if (!scopeId) {
|
2006
1991
|
return undefined;
|
2007
1992
|
}
|
1993
|
+
// Append an asterisk to denote a bound scope.
|
2008
1994
|
return `${scopeId}*`;
|
2009
1995
|
}
|
2010
|
-
TypeVarType.
|
2011
|
-
function
|
2012
|
-
if (type.priv.scopeId === undefined || type.priv.
|
1996
|
+
TypeVarType.makeBoundScopeId = makeBoundScopeId;
|
1997
|
+
function cloneAsBound(type) {
|
1998
|
+
if (type.priv.scopeId === undefined || type.priv.freeTypeVar) {
|
2013
1999
|
return type;
|
2014
2000
|
}
|
2015
|
-
const clone = TypeVarType.cloneForScopeId(type, TypeVarType.
|
2016
|
-
clone.priv.
|
2001
|
+
const clone = TypeVarType.cloneForScopeId(type, TypeVarType.makeBoundScopeId(type.priv.scopeId), type.priv.scopeName, type.priv.scopeType);
|
2002
|
+
clone.priv.freeTypeVar = type;
|
2017
2003
|
return clone;
|
2018
2004
|
}
|
2019
|
-
TypeVarType.
|
2020
|
-
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
2024
|
-
|
2005
|
+
TypeVarType.cloneAsBound = cloneAsBound;
|
2006
|
+
// Indicates that the type var is a "free" or unbound type var. Free
|
2007
|
+
// type variables can be solved whereas bound type vars are already bound
|
2008
|
+
// to a value.
|
2009
|
+
function isBound(type) {
|
2010
|
+
// If the type var has an associated free type var, then it's
|
2011
|
+
// considered bound. If it has no associated free var, then it's
|
2012
|
+
// considered free.
|
2013
|
+
return !!type.priv.freeTypeVar;
|
2014
|
+
}
|
2015
|
+
TypeVarType.isBound = isBound;
|
2016
|
+
function isUnification(type) {
|
2017
|
+
return type.priv.isUnificationVar;
|
2018
|
+
}
|
2019
|
+
TypeVarType.isUnification = isUnification;
|
2020
|
+
function create(name, kind, typeFlags) {
|
2025
2021
|
const newTypeVarType = {
|
2026
2022
|
category: 9 /* TypeCategory.TypeVar */,
|
2027
2023
|
flags: typeFlags,
|
2028
2024
|
props: undefined,
|
2029
2025
|
cached: undefined,
|
2030
2026
|
shared: {
|
2027
|
+
kind,
|
2031
2028
|
name,
|
2032
2029
|
constraints: [],
|
2033
2030
|
boundType: undefined,
|
2034
2031
|
isDefaultExplicit: false,
|
2035
2032
|
defaultType: UnknownType.create(),
|
2036
|
-
isParamSpec,
|
2037
|
-
isVariadic: false,
|
2038
2033
|
declaredVariance: 2 /* Variance.Invariant */,
|
2039
2034
|
isSynthesized: false,
|
2040
2035
|
isSynthesizedSelf: false,
|
@@ -2082,6 +2077,18 @@ var TypeVarType;
|
|
2082
2077
|
return !!type.shared.recursiveAlias && !type.shared.boundType;
|
2083
2078
|
}
|
2084
2079
|
TypeVarType.isTypeAliasPlaceholder = isTypeAliasPlaceholder;
|
2080
|
+
function isSelf(type) {
|
2081
|
+
return !!type.shared.isSynthesizedSelf;
|
2082
|
+
}
|
2083
|
+
TypeVarType.isSelf = isSelf;
|
2084
|
+
function hasConstraints(type) {
|
2085
|
+
return type.shared.constraints.length > 0;
|
2086
|
+
}
|
2087
|
+
TypeVarType.hasConstraints = hasConstraints;
|
2088
|
+
function hasBound(type) {
|
2089
|
+
return !!type.shared.boundType;
|
2090
|
+
}
|
2091
|
+
TypeVarType.hasBound = hasBound;
|
2085
2092
|
})(TypeVarType || (exports.TypeVarType = TypeVarType = {}));
|
2086
2093
|
function isNever(type) {
|
2087
2094
|
return type.category === 3 /* TypeCategory.Never */;
|
@@ -2143,17 +2150,18 @@ function isTypeVar(type) {
|
|
2143
2150
|
return type.category === 9 /* TypeCategory.TypeVar */;
|
2144
2151
|
}
|
2145
2152
|
exports.isTypeVar = isTypeVar;
|
2146
|
-
function
|
2147
|
-
return type.category === 9 /* TypeCategory.TypeVar */ && type.shared.
|
2153
|
+
function isParamSpec(type) {
|
2154
|
+
return type.category === 9 /* TypeCategory.TypeVar */ && type.shared.kind === TypeVarKind.ParamSpec;
|
2155
|
+
}
|
2156
|
+
exports.isParamSpec = isParamSpec;
|
2157
|
+
function isTypeVarTuple(type) {
|
2158
|
+
return type.category === 9 /* TypeCategory.TypeVar */ && type.shared.kind === TypeVarKind.TypeVarTuple;
|
2148
2159
|
}
|
2149
|
-
exports.
|
2150
|
-
function
|
2151
|
-
return (type
|
2152
|
-
type.shared.isVariadic &&
|
2153
|
-
!!type.priv.isVariadicUnpacked &&
|
2154
|
-
!type.priv.isVariadicInUnion);
|
2160
|
+
exports.isTypeVarTuple = isTypeVarTuple;
|
2161
|
+
function isUnpackedTypeVarTuple(type) {
|
2162
|
+
return isTypeVarTuple(type) && !!type.priv.isUnpacked && !type.priv.isInUnion;
|
2155
2163
|
}
|
2156
|
-
exports.
|
2164
|
+
exports.isUnpackedTypeVarTuple = isUnpackedTypeVarTuple;
|
2157
2165
|
function isUnpackedClass(type) {
|
2158
2166
|
if (!isClass(type) || !type.priv.isUnpacked) {
|
2159
2167
|
return false;
|
@@ -2162,13 +2170,9 @@ function isUnpackedClass(type) {
|
|
2162
2170
|
}
|
2163
2171
|
exports.isUnpackedClass = isUnpackedClass;
|
2164
2172
|
function isUnpacked(type) {
|
2165
|
-
return
|
2173
|
+
return isUnpackedTypeVarTuple(type) || isUnpackedClass(type);
|
2166
2174
|
}
|
2167
2175
|
exports.isUnpacked = isUnpacked;
|
2168
|
-
function isParamSpec(type) {
|
2169
|
-
return type.category === 9 /* TypeCategory.TypeVar */ && type.shared.isParamSpec;
|
2170
|
-
}
|
2171
|
-
exports.isParamSpec = isParamSpec;
|
2172
2176
|
function isFunction(type) {
|
2173
2177
|
return type.category === 4 /* TypeCategory.Function */;
|
2174
2178
|
}
|
@@ -2231,9 +2235,9 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2231
2235
|
}
|
2232
2236
|
if (!options.ignorePseudoGeneric || !ClassType.isPseudoGenericClass(type1)) {
|
2233
2237
|
// Make sure the type args match.
|
2234
|
-
if (type1.priv.
|
2235
|
-
const type1TupleTypeArgs = type1.priv.
|
2236
|
-
const type2TupleTypeArgs = classType2.priv.
|
2238
|
+
if (type1.priv.tupleTypeArgs && classType2.priv.tupleTypeArgs) {
|
2239
|
+
const type1TupleTypeArgs = type1.priv.tupleTypeArgs || [];
|
2240
|
+
const type2TupleTypeArgs = classType2.priv.tupleTypeArgs || [];
|
2237
2241
|
if (type1TupleTypeArgs.length !== type2TupleTypeArgs.length) {
|
2238
2242
|
return false;
|
2239
2243
|
}
|
@@ -2247,8 +2251,8 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2247
2251
|
}
|
2248
2252
|
}
|
2249
2253
|
else {
|
2250
|
-
const type1TypeArgs = type1.priv.
|
2251
|
-
const type2TypeArgs = classType2.priv.
|
2254
|
+
const type1TypeArgs = type1.priv.typeArgs || [];
|
2255
|
+
const type2TypeArgs = classType2.priv.typeArgs || [];
|
2252
2256
|
const typeArgCount = Math.max(type1TypeArgs.length, type2TypeArgs.length);
|
2253
2257
|
for (let i = 0; i < typeArgCount; i++) {
|
2254
2258
|
// Assume that missing type args are "Unknown".
|
@@ -2308,8 +2312,8 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2308
2312
|
else if (isKeywordOnlySeparator(param1) && isKeywordOnlySeparator(param2)) {
|
2309
2313
|
continue;
|
2310
2314
|
}
|
2311
|
-
const param1Type = FunctionType.
|
2312
|
-
const param2Type = FunctionType.
|
2315
|
+
const param1Type = FunctionType.getParamType(type1, i);
|
2316
|
+
const param2Type = FunctionType.getParamType(functionType2, i);
|
2313
2317
|
if (!isTypeSame(param1Type, param2Type, { ...options, ignoreTypeFlags: false }, recursionCount)) {
|
2314
2318
|
return false;
|
2315
2319
|
}
|
@@ -2373,8 +2377,8 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2373
2377
|
// Handle the case where this is a generic recursive type alias. Make
|
2374
2378
|
// sure that the type argument types match.
|
2375
2379
|
if (type1.shared.recursiveAlias && type2TypeVar.shared.recursiveAlias) {
|
2376
|
-
const type1TypeArgs = ((_d = (_c = type1 === null || type1 === void 0 ? void 0 : type1.props) === null || _c === void 0 ? void 0 : _c.typeAliasInfo) === null || _d === void 0 ? void 0 : _d.
|
2377
|
-
const type2TypeArgs = ((_f = (_e = type2 === null || type2 === void 0 ? void 0 : type2.props) === null || _e === void 0 ? void 0 : _e.typeAliasInfo) === null || _f === void 0 ? void 0 : _f.
|
2380
|
+
const type1TypeArgs = ((_d = (_c = type1 === null || type1 === void 0 ? void 0 : type1.props) === null || _c === void 0 ? void 0 : _c.typeAliasInfo) === null || _d === void 0 ? void 0 : _d.typeArgs) || [];
|
2381
|
+
const type2TypeArgs = ((_f = (_e = type2 === null || type2 === void 0 ? void 0 : type2.props) === null || _e === void 0 ? void 0 : _e.typeAliasInfo) === null || _f === void 0 ? void 0 : _f.typeArgs) || [];
|
2378
2382
|
const typeArgCount = Math.max(type1TypeArgs.length, type2TypeArgs.length);
|
2379
2383
|
for (let i = 0; i < typeArgCount; i++) {
|
2380
2384
|
// Assume that missing type args are "Any".
|
@@ -2385,15 +2389,21 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2385
2389
|
}
|
2386
2390
|
}
|
2387
2391
|
}
|
2388
|
-
if (
|
2389
|
-
|
2392
|
+
if (isTypeVarTuple(type1) && isTypeVarTuple(type2TypeVar)) {
|
2393
|
+
if (!type1.priv.isInUnion !== !type2TypeVar.priv.isInUnion) {
|
2394
|
+
return false;
|
2395
|
+
}
|
2390
2396
|
}
|
2391
2397
|
if (type1.shared === type2TypeVar.shared) {
|
2392
2398
|
return true;
|
2393
2399
|
}
|
2400
|
+
if (isParamSpec(type1) !== isParamSpec(type2TypeVar)) {
|
2401
|
+
return false;
|
2402
|
+
}
|
2403
|
+
if (isTypeVarTuple(type1) !== isTypeVarTuple(type2TypeVar)) {
|
2404
|
+
return false;
|
2405
|
+
}
|
2394
2406
|
if (type1.shared.name !== type2TypeVar.shared.name ||
|
2395
|
-
type1.shared.isParamSpec !== type2TypeVar.shared.isParamSpec ||
|
2396
|
-
type1.shared.isVariadic !== type2TypeVar.shared.isVariadic ||
|
2397
2407
|
type1.shared.isSynthesized !== type2TypeVar.shared.isSynthesized ||
|
2398
2408
|
type1.shared.declaredVariance !== type2TypeVar.shared.declaredVariance ||
|
2399
2409
|
type1.priv.scopeId !== type2TypeVar.priv.scopeId) {
|
@@ -2663,8 +2673,7 @@ function _addTypeIfUnique(unionType, typeToAdd, elideRedundantLiterals) {
|
|
2663
2673
|
// parameterized with its own class) ad infinitum.
|
2664
2674
|
if (isPseudoGeneric) {
|
2665
2675
|
if (isTypeSame(type, typeToAdd, { ignorePseudoGeneric: true })) {
|
2666
|
-
unionType.priv.subtypes[i] = ClassType.
|
2667
|
-
/* isTypeArgumentExplicit */ true);
|
2676
|
+
unionType.priv.subtypes[i] = ClassType.specialize(typeToAdd, typeToAdd.shared.typeParams.map(() => UnknownType.create()));
|
2668
2677
|
return;
|
2669
2678
|
}
|
2670
2679
|
}
|
@@ -2692,7 +2701,7 @@ function _addTypeIfUnique(unionType, typeToAdd, elideRedundantLiterals) {
|
|
2692
2701
|
// existing type, see if one of them is a proper subset of the other.
|
2693
2702
|
if (ClassType.isTypedDictClass(type) && ClassType.isSameGenericClass(type, typeToAdd)) {
|
2694
2703
|
// Do not proceed if the TypedDicts are generic and have different type arguments.
|
2695
|
-
if (!type.priv.
|
2704
|
+
if (!type.priv.typeArgs && !typeToAdd.priv.typeArgs) {
|
2696
2705
|
if (ClassType.isTypedDictNarrower(typeToAdd, type)) {
|
2697
2706
|
return;
|
2698
2707
|
}
|