@zzzen/pyright-internal 1.2.0-dev.20240630 → 1.2.0-dev.20240714
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/analyzerNodeInfo.js +74 -46
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/binder.js +507 -513
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +652 -633
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +5 -3
- package/dist/analyzer/codeFlowEngine.js +143 -122
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.js +30 -28
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/constraintSolver.d.ts +1 -1
- package/dist/analyzer/constraintSolver.js +71 -67
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +22 -22
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +85 -77
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +113 -176
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +1 -1
- package/dist/analyzer/declarationUtils.js +14 -15
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +85 -85
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.js +71 -57
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/functionTransform.js +8 -18
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +2 -1
- package/dist/analyzer/importResolver.js +40 -29
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +27 -27
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +33 -59
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.d.ts +4 -4
- package/dist/analyzer/operations.js +70 -70
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +66 -62
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +4 -4
- package/dist/analyzer/parameterUtils.js +28 -46
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +268 -269
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +76 -76
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.js +195 -147
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +1 -1
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +78 -147
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +22 -22
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +3 -2
- package/dist/analyzer/sourceFile.js +8 -8
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +20 -19
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +83 -84
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/testWalker.js +2 -2
- package/dist/analyzer/testWalker.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +20 -20
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +25 -25
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +2330 -2367
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +33 -31
- package/dist/analyzer/typeEvaluatorTypes.js +48 -41
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +221 -217
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +118 -115
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +104 -103
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +26 -9
- package/dist/analyzer/typeUtils.js +460 -404
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +8 -8
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typeWalker.js +13 -10
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.js +96 -198
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +147 -103
- package/dist/analyzer/types.js +668 -493
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +33 -33
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/diagnostic.d.ts +14 -0
- package/dist/common/diagnostic.js +41 -1
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/diagnosticSink.d.ts +4 -0
- package/dist/common/diagnosticSink.js +21 -1
- package/dist/common/diagnosticSink.js.map +1 -1
- package/dist/common/fileSystem.d.ts +1 -0
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/fullAccessHost.js +6 -4
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +1 -0
- package/dist/common/realFileSystem.js +4 -0
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/textEditTracker.js +14 -14
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/languageService/autoImporter.js +10 -10
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +23 -23
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +1 -1
- package/dist/languageService/completionProvider.js +156 -154
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +1 -1
- package/dist/languageService/definitionProvider.js +3 -1
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +19 -19
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/hoverProvider.js +25 -24
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importSorter.js +8 -8
- package/dist/languageService/importSorter.js.map +1 -1
- package/dist/languageService/referencesProvider.js +8 -8
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.d.ts +1 -1
- package/dist/languageService/signatureHelpProvider.js +6 -6
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.js +3 -3
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +13 -13
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +3 -0
- package/dist/localization/localize.js +1 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +2 -1
- package/dist/parser/parseNodes.d.ts +468 -401
- package/dist/parser/parseNodes.js +626 -355
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +1 -0
- package/dist/parser/parser.js +322 -297
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyright.js +265 -5
- package/dist/pyright.js.map +1 -1
- package/dist/tests/classDeclaration.test.js +14 -14
- package/dist/tests/classDeclaration.test.js.map +1 -1
- package/dist/tests/fourslash/hover.init.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.init.fourslash.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +3 -2
- package/dist/tests/harness/vfs/filesystem.js +6 -2
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importResolver.test.js +4 -3
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +5 -5
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/parser.test.js +8 -8
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +7 -7
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +2 -2
- package/dist/tests/typeEvaluator3.test.js +10 -5
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator7.test.js +2 -2
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +14 -39
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/package.json +1 -1
package/dist/analyzer/types.js
CHANGED
@@ -8,7 +8,8 @@
|
|
8
8
|
* Representation of types used during type analysis within Python.
|
9
9
|
*/
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
11
|
-
exports.
|
11
|
+
exports.findSubtype = exports.removeFromUnion = exports.removeUnbound = exports.removeUnknownFromUnion = exports.isTypeSame = exports.getTypeAliasInfo = exports.isOverloadedFunction = exports.isFunction = exports.isParamSpec = exports.isUnpacked = exports.isUnpackedClass = exports.isUnpackedVariadicTypeVar = exports.isVariadicTypeVar = 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.TypeVarScopeType = 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.InScopePlaceholderScopeId = exports.TypeFlags = exports.TypeCategory = void 0;
|
12
|
+
exports.isSameWithoutLiteralValue = exports.combineTypes = void 0;
|
12
13
|
const debug_1 = require("../common/debug");
|
13
14
|
var TypeCategory;
|
14
15
|
(function (TypeCategory) {
|
@@ -46,6 +47,12 @@ var TypeFlags;
|
|
46
47
|
TypeFlags[TypeFlags["Instantiable"] = 1] = "Instantiable";
|
47
48
|
// This type refers to something that has been instantiated.
|
48
49
|
TypeFlags[TypeFlags["Instance"] = 2] = "Instance";
|
50
|
+
// This type is inferred within a py.typed source file and could be
|
51
|
+
// inferred differently by other type checkers.
|
52
|
+
TypeFlags[TypeFlags["Ambiguous"] = 4] = "Ambiguous";
|
53
|
+
// This mask indicates which flags should be considered significant
|
54
|
+
// when comparing two types for equivalence.
|
55
|
+
TypeFlags[TypeFlags["TypeCompatibilityMask"] = 3] = "TypeCompatibilityMask";
|
49
56
|
})(TypeFlags || (exports.TypeFlags = TypeFlags = {}));
|
50
57
|
exports.InScopePlaceholderScopeId = '-';
|
51
58
|
class EnumLiteral {
|
@@ -79,42 +86,69 @@ var TypeBase;
|
|
79
86
|
}
|
80
87
|
TypeBase.isInstance = isInstance;
|
81
88
|
function isAmbiguous(type) {
|
82
|
-
return
|
89
|
+
return (type.flags & 4 /* TypeFlags.Ambiguous */) !== 0;
|
83
90
|
}
|
84
91
|
TypeBase.isAmbiguous = isAmbiguous;
|
92
|
+
function addProps(type) {
|
93
|
+
if (!type.props) {
|
94
|
+
type.props = {
|
95
|
+
instantiableDepth: undefined,
|
96
|
+
specialForm: undefined,
|
97
|
+
typeAliasInfo: undefined,
|
98
|
+
condition: undefined,
|
99
|
+
};
|
100
|
+
}
|
101
|
+
return type.props;
|
102
|
+
}
|
103
|
+
TypeBase.addProps = addProps;
|
104
|
+
function setSpecialForm(type, specialForm) {
|
105
|
+
TypeBase.addProps(type).specialForm = specialForm;
|
106
|
+
}
|
107
|
+
TypeBase.setSpecialForm = setSpecialForm;
|
108
|
+
function setInstantiableDepth(type, depth) {
|
109
|
+
TypeBase.addProps(type).instantiableDepth = depth;
|
110
|
+
}
|
111
|
+
TypeBase.setInstantiableDepth = setInstantiableDepth;
|
112
|
+
function setTypeAliasInfo(type, typeAliasInfo) {
|
113
|
+
TypeBase.addProps(type).typeAliasInfo = typeAliasInfo;
|
114
|
+
}
|
115
|
+
TypeBase.setTypeAliasInfo = setTypeAliasInfo;
|
116
|
+
function setCondition(type, condition) {
|
117
|
+
TypeBase.addProps(type).condition = condition;
|
118
|
+
}
|
119
|
+
TypeBase.setCondition = setCondition;
|
85
120
|
function cloneType(type) {
|
86
121
|
const clone = { ...type };
|
87
|
-
|
122
|
+
if (type.props) {
|
123
|
+
clone.props = { ...type.props };
|
124
|
+
}
|
125
|
+
if (type.priv) {
|
126
|
+
clone.priv = { ...type.priv };
|
127
|
+
}
|
128
|
+
clone.cached = undefined;
|
88
129
|
return clone;
|
89
130
|
}
|
90
131
|
TypeBase.cloneType = cloneType;
|
91
132
|
function cloneAsSpecialForm(type, specialForm) {
|
92
|
-
const clone =
|
93
|
-
|
94
|
-
if (specialForm) {
|
95
|
-
clone.specialForm = specialForm;
|
96
|
-
}
|
97
|
-
else {
|
98
|
-
delete clone.specialForm;
|
99
|
-
}
|
133
|
+
const clone = TypeBase.cloneType(type);
|
134
|
+
TypeBase.setSpecialForm(clone, specialForm);
|
100
135
|
return clone;
|
101
136
|
}
|
102
137
|
TypeBase.cloneAsSpecialForm = cloneAsSpecialForm;
|
103
138
|
function cloneTypeAsInstance(type, cache) {
|
139
|
+
var _a;
|
104
140
|
(0, debug_1.assert)(TypeBase.isInstantiable(type));
|
105
141
|
const newInstance = TypeBase.cloneType(type);
|
106
|
-
|
142
|
+
const depth = (_a = newInstance.props) === null || _a === void 0 ? void 0 : _a.instantiableDepth;
|
143
|
+
if (depth === undefined) {
|
107
144
|
newInstance.flags &= ~1 /* TypeFlags.Instantiable */;
|
108
145
|
newInstance.flags |= 2 /* TypeFlags.Instance */;
|
109
|
-
|
146
|
+
}
|
147
|
+
else if (depth <= 1) {
|
148
|
+
TypeBase.setInstantiableDepth(newInstance, undefined);
|
110
149
|
}
|
111
150
|
else {
|
112
|
-
|
113
|
-
delete newInstance.instantiableNestingLevel;
|
114
|
-
}
|
115
|
-
else {
|
116
|
-
newInstance.instantiableNestingLevel--;
|
117
|
-
}
|
151
|
+
TypeBase.setInstantiableDepth(newInstance, depth - 1);
|
118
152
|
}
|
119
153
|
// Should we cache it for next time?
|
120
154
|
if (cache) {
|
@@ -127,18 +161,21 @@ var TypeBase;
|
|
127
161
|
}
|
128
162
|
TypeBase.cloneTypeAsInstance = cloneTypeAsInstance;
|
129
163
|
function cloneTypeAsInstantiable(type, cache) {
|
164
|
+
var _a, _b;
|
130
165
|
const newInstance = TypeBase.cloneType(type);
|
131
166
|
if (TypeBase.isInstance(type)) {
|
132
167
|
newInstance.flags &= ~2 /* TypeFlags.Instance */;
|
133
168
|
newInstance.flags |= 1 /* TypeFlags.Instantiable */;
|
134
169
|
}
|
135
170
|
else {
|
136
|
-
|
137
|
-
|
171
|
+
const oldDepth = (_a = type.props) === null || _a === void 0 ? void 0 : _a.instantiableDepth;
|
172
|
+
TypeBase.setInstantiableDepth(newInstance, oldDepth === undefined ? 1 : oldDepth + 1);
|
138
173
|
}
|
139
174
|
// Remove type alias information because the type will no longer match
|
140
175
|
// that of the type alias definition.
|
141
|
-
|
176
|
+
if ((_b = newInstance.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo) {
|
177
|
+
TypeBase.setTypeAliasInfo(newInstance, undefined);
|
178
|
+
}
|
142
179
|
// Should we cache it for next time?
|
143
180
|
if (cache) {
|
144
181
|
if (!type.cached) {
|
@@ -151,36 +188,38 @@ var TypeBase;
|
|
151
188
|
TypeBase.cloneTypeAsInstantiable = cloneTypeAsInstantiable;
|
152
189
|
function cloneForTypeAlias(type, name, fullName, moduleName, fileUri, typeVarScopeId, isPep695Syntax, typeParams, typeArgs) {
|
153
190
|
const typeClone = cloneType(type);
|
154
|
-
typeClone
|
191
|
+
TypeBase.setTypeAliasInfo(typeClone, {
|
155
192
|
name,
|
156
193
|
fullName,
|
157
194
|
moduleName,
|
158
195
|
fileUri,
|
159
|
-
typeParameters: typeParams,
|
160
|
-
typeArguments: typeArgs,
|
161
196
|
typeVarScopeId,
|
162
197
|
isPep695Syntax,
|
163
|
-
|
198
|
+
typeParameters: typeParams,
|
199
|
+
usageVariance: undefined,
|
200
|
+
typeArguments: typeArgs,
|
201
|
+
});
|
164
202
|
return typeClone;
|
165
203
|
}
|
166
204
|
TypeBase.cloneForTypeAlias = cloneForTypeAlias;
|
167
205
|
function cloneForCondition(type, condition) {
|
206
|
+
var _a;
|
168
207
|
// Handle the common case where there are no conditions. In this case,
|
169
208
|
// cloning isn't necessary.
|
170
|
-
if (type.condition === undefined && condition === undefined) {
|
209
|
+
if (((_a = type.props) === null || _a === void 0 ? void 0 : _a.condition) === undefined && condition === undefined) {
|
171
210
|
return type;
|
172
211
|
}
|
173
212
|
const typeClone = cloneType(type);
|
174
|
-
typeClone
|
213
|
+
TypeBase.setCondition(typeClone, condition);
|
175
214
|
return typeClone;
|
176
215
|
}
|
177
216
|
TypeBase.cloneForCondition = cloneForCondition;
|
178
217
|
function cloneForAmbiguousType(type) {
|
179
|
-
if (
|
218
|
+
if (TypeBase.isAmbiguous(type)) {
|
180
219
|
return type;
|
181
220
|
}
|
182
221
|
const typeClone = cloneType(type);
|
183
|
-
typeClone.
|
222
|
+
typeClone.flags |= 4 /* TypeFlags.Ambiguous */;
|
184
223
|
return typeClone;
|
185
224
|
}
|
186
225
|
TypeBase.cloneForAmbiguousType = cloneForAmbiguousType;
|
@@ -190,6 +229,10 @@ var UnboundType;
|
|
190
229
|
const _instance = {
|
191
230
|
category: 0 /* TypeCategory.Unbound */,
|
192
231
|
flags: 1 /* TypeFlags.Instantiable */ | 2 /* TypeFlags.Instance */,
|
232
|
+
props: undefined,
|
233
|
+
cached: undefined,
|
234
|
+
shared: undefined,
|
235
|
+
priv: undefined,
|
193
236
|
};
|
194
237
|
function create() {
|
195
238
|
// All Unbound objects are the same, so use a shared instance.
|
@@ -197,8 +240,9 @@ var UnboundType;
|
|
197
240
|
}
|
198
241
|
UnboundType.create = create;
|
199
242
|
function convertToInstance(type) {
|
243
|
+
var _a;
|
200
244
|
// Remove the "special form" if present. Otherwise return the existing type.
|
201
|
-
return type.specialForm ? UnboundType.create() : type;
|
245
|
+
return ((_a = type.props) === null || _a === void 0 ? void 0 : _a.specialForm) ? UnboundType.create() : type;
|
202
246
|
}
|
203
247
|
UnboundType.convertToInstance = convertToInstance;
|
204
248
|
})(UnboundType || (exports.UnboundType = UnboundType = {}));
|
@@ -207,12 +251,24 @@ var UnknownType;
|
|
207
251
|
const _instance = {
|
208
252
|
category: 1 /* TypeCategory.Unknown */,
|
209
253
|
flags: 1 /* TypeFlags.Instantiable */ | 2 /* TypeFlags.Instance */,
|
210
|
-
|
254
|
+
props: undefined,
|
255
|
+
cached: undefined,
|
256
|
+
shared: undefined,
|
257
|
+
priv: {
|
258
|
+
isIncomplete: false,
|
259
|
+
possibleType: undefined,
|
260
|
+
},
|
211
261
|
};
|
212
262
|
const _incompleteInstance = {
|
213
263
|
category: 1 /* TypeCategory.Unknown */,
|
214
264
|
flags: 1 /* TypeFlags.Instantiable */ | 2 /* TypeFlags.Instance */,
|
215
|
-
|
265
|
+
props: undefined,
|
266
|
+
cached: undefined,
|
267
|
+
shared: undefined,
|
268
|
+
priv: {
|
269
|
+
isIncomplete: true,
|
270
|
+
possibleType: undefined,
|
271
|
+
},
|
216
272
|
};
|
217
273
|
function create(isIncomplete = false) {
|
218
274
|
return isIncomplete ? _incompleteInstance : _instance;
|
@@ -222,15 +278,21 @@ var UnknownType;
|
|
222
278
|
const unknownWithPossibleType = {
|
223
279
|
category: 1 /* TypeCategory.Unknown */,
|
224
280
|
flags: 1 /* TypeFlags.Instantiable */ | 2 /* TypeFlags.Instance */,
|
225
|
-
|
226
|
-
|
281
|
+
props: undefined,
|
282
|
+
cached: undefined,
|
283
|
+
shared: undefined,
|
284
|
+
priv: {
|
285
|
+
isIncomplete,
|
286
|
+
possibleType,
|
287
|
+
},
|
227
288
|
};
|
228
289
|
return unknownWithPossibleType;
|
229
290
|
}
|
230
291
|
UnknownType.createPossibleType = createPossibleType;
|
231
292
|
function convertToInstance(type) {
|
293
|
+
var _a;
|
232
294
|
// Remove the "special form" if present. Otherwise return the existing type.
|
233
|
-
return type.specialForm ? UnknownType.create(type.isIncomplete) : type;
|
295
|
+
return ((_a = type.props) === null || _a === void 0 ? void 0 : _a.specialForm) ? UnknownType.create(type.priv.isIncomplete) : type;
|
234
296
|
}
|
235
297
|
UnknownType.convertToInstance = convertToInstance;
|
236
298
|
})(UnknownType || (exports.UnknownType = UnknownType = {}));
|
@@ -239,11 +301,18 @@ var ModuleType;
|
|
239
301
|
function create(moduleName, fileUri, symbolTable) {
|
240
302
|
const newModuleType = {
|
241
303
|
category: 7 /* TypeCategory.Module */,
|
242
|
-
fields: symbolTable || new Map(),
|
243
|
-
loaderFields: new Map(),
|
244
304
|
flags: 1 /* TypeFlags.Instantiable */ | 1 /* TypeFlags.Instantiable */,
|
245
|
-
|
246
|
-
|
305
|
+
props: undefined,
|
306
|
+
cached: undefined,
|
307
|
+
shared: undefined,
|
308
|
+
priv: {
|
309
|
+
fields: symbolTable || new Map(),
|
310
|
+
docString: undefined,
|
311
|
+
notPresentFieldType: undefined,
|
312
|
+
loaderFields: new Map(),
|
313
|
+
moduleName,
|
314
|
+
fileUri,
|
315
|
+
},
|
247
316
|
};
|
248
317
|
return newModuleType;
|
249
318
|
}
|
@@ -252,16 +321,16 @@ var ModuleType;
|
|
252
321
|
// Always look for the symbol in the module's fields before consulting
|
253
322
|
// the loader fields. The loader runs before the module, so its values
|
254
323
|
// will be overwritten by the module.
|
255
|
-
let symbol = moduleType.fields.get(name);
|
256
|
-
if (moduleType.loaderFields) {
|
324
|
+
let symbol = moduleType.priv.fields.get(name);
|
325
|
+
if (moduleType.priv.loaderFields) {
|
257
326
|
if (!symbol) {
|
258
|
-
symbol = moduleType.loaderFields.get(name);
|
327
|
+
symbol = moduleType.priv.loaderFields.get(name);
|
259
328
|
}
|
260
329
|
else if (symbol.getDeclarations().length === 1) {
|
261
330
|
// If the symbol is hidden when accessed via the module but is
|
262
331
|
// also accessible through a loader field, use the latter so it
|
263
332
|
// isn't flagged as an error.
|
264
|
-
const loaderSymbol = moduleType.loaderFields.get(name);
|
333
|
+
const loaderSymbol = moduleType.priv.loaderFields.get(name);
|
265
334
|
if (loaderSymbol && !loaderSymbol.isExternallyHidden()) {
|
266
335
|
symbol = loaderSymbol;
|
267
336
|
}
|
@@ -275,7 +344,7 @@ var ClassTypeFlags;
|
|
275
344
|
(function (ClassTypeFlags) {
|
276
345
|
ClassTypeFlags[ClassTypeFlags["None"] = 0] = "None";
|
277
346
|
// Class is defined in the "builtins" or "typing" file.
|
278
|
-
ClassTypeFlags[ClassTypeFlags["
|
347
|
+
ClassTypeFlags[ClassTypeFlags["BuiltIn"] = 1] = "BuiltIn";
|
279
348
|
// Class requires special-case handling because it
|
280
349
|
// exhibits non-standard behavior or is not defined
|
281
350
|
// formally as a class. Examples include 'Optional'
|
@@ -349,13 +418,19 @@ var ClassTypeFlags;
|
|
349
418
|
// A special form is not compatible with type[T] and cannot
|
350
419
|
// be directly instantiated.
|
351
420
|
ClassTypeFlags[ClassTypeFlags["SpecialFormClass"] = 8388608] = "SpecialFormClass";
|
421
|
+
// This class is rejected when used as the second argument to
|
422
|
+
// an isinstance or issubclass call.
|
423
|
+
ClassTypeFlags[ClassTypeFlags["IllegalIsinstanceClass"] = 16777216] = "IllegalIsinstanceClass";
|
352
424
|
})(ClassTypeFlags || (exports.ClassTypeFlags = ClassTypeFlags = {}));
|
353
425
|
var ClassType;
|
354
426
|
(function (ClassType) {
|
355
427
|
function createInstantiable(name, fullName, moduleName, fileUri, flags, typeSourceId, declaredMetaclass, effectiveMetaclass, docString) {
|
356
428
|
const newClass = {
|
357
429
|
category: 6 /* TypeCategory.Class */,
|
358
|
-
|
430
|
+
flags: 1 /* TypeFlags.Instantiable */,
|
431
|
+
props: undefined,
|
432
|
+
cached: undefined,
|
433
|
+
shared: {
|
359
434
|
name,
|
360
435
|
fullName,
|
361
436
|
moduleName,
|
@@ -370,13 +445,13 @@ var ClassType;
|
|
370
445
|
typeParameters: [],
|
371
446
|
docString,
|
372
447
|
},
|
373
|
-
|
448
|
+
priv: {},
|
374
449
|
};
|
375
450
|
return newClass;
|
376
451
|
}
|
377
452
|
ClassType.createInstantiable = createInstantiable;
|
378
453
|
function cloneAsInstance(type, includeSubclasses = true) {
|
379
|
-
var _a;
|
454
|
+
var _a, _b;
|
380
455
|
if (TypeBase.isInstance(type)) {
|
381
456
|
return type;
|
382
457
|
}
|
@@ -384,9 +459,11 @@ var ClassType;
|
|
384
459
|
return type.cached.typeBaseInstanceType;
|
385
460
|
}
|
386
461
|
const newInstance = TypeBase.cloneTypeAsInstance(type, /* cache */ includeSubclasses);
|
387
|
-
|
462
|
+
if ((_b = newInstance.props) === null || _b === void 0 ? void 0 : _b.specialForm) {
|
463
|
+
TypeBase.setSpecialForm(newInstance, undefined);
|
464
|
+
}
|
388
465
|
if (includeSubclasses) {
|
389
|
-
newInstance.includeSubclasses = true;
|
466
|
+
newInstance.priv.includeSubclasses = true;
|
390
467
|
}
|
391
468
|
return newInstance;
|
392
469
|
}
|
@@ -398,131 +475,136 @@ var ClassType;
|
|
398
475
|
}
|
399
476
|
const newInstance = TypeBase.cloneTypeAsInstantiable(type, includeSubclasses);
|
400
477
|
if (includeSubclasses) {
|
401
|
-
newInstance.includeSubclasses = true;
|
478
|
+
newInstance.priv.includeSubclasses = true;
|
402
479
|
}
|
403
480
|
return newInstance;
|
404
481
|
}
|
405
482
|
ClassType.cloneAsInstantiable = cloneAsInstantiable;
|
406
483
|
function cloneForSpecialization(classType, typeArguments, isTypeArgumentExplicit, includeSubclasses = false, tupleTypeArguments, isEmptyContainer) {
|
407
484
|
const newClassType = TypeBase.cloneType(classType);
|
408
|
-
newClassType.typeArguments = (typeArguments === null || typeArguments === void 0 ? void 0 : typeArguments.length) === 0 ? undefined : typeArguments;
|
409
|
-
newClassType.isTypeArgumentExplicit = isTypeArgumentExplicit;
|
485
|
+
newClassType.priv.typeArguments = (typeArguments === null || typeArguments === void 0 ? void 0 : typeArguments.length) === 0 ? undefined : typeArguments;
|
486
|
+
newClassType.priv.isTypeArgumentExplicit = isTypeArgumentExplicit;
|
410
487
|
if (includeSubclasses) {
|
411
|
-
newClassType.includeSubclasses = true;
|
488
|
+
newClassType.priv.includeSubclasses = true;
|
412
489
|
}
|
413
|
-
newClassType.tupleTypeArguments = tupleTypeArguments ? [...tupleTypeArguments] : undefined;
|
490
|
+
newClassType.priv.tupleTypeArguments = tupleTypeArguments ? [...tupleTypeArguments] : undefined;
|
414
491
|
if (isEmptyContainer !== undefined) {
|
415
|
-
newClassType.isEmptyContainer = isEmptyContainer;
|
492
|
+
newClassType.priv.isEmptyContainer = isEmptyContainer;
|
416
493
|
}
|
417
494
|
return newClassType;
|
418
495
|
}
|
419
496
|
ClassType.cloneForSpecialization = cloneForSpecialization;
|
420
497
|
function cloneIncludeSubclasses(classType, includeSubclasses = true) {
|
421
|
-
if (!!classType.includeSubclasses === includeSubclasses) {
|
498
|
+
if (!!classType.priv.includeSubclasses === includeSubclasses) {
|
422
499
|
return classType;
|
423
500
|
}
|
424
501
|
const newClassType = TypeBase.cloneType(classType);
|
425
|
-
newClassType.includeSubclasses = includeSubclasses;
|
502
|
+
newClassType.priv.includeSubclasses = includeSubclasses;
|
426
503
|
return newClassType;
|
427
504
|
}
|
428
505
|
ClassType.cloneIncludeSubclasses = cloneIncludeSubclasses;
|
429
506
|
function cloneWithLiteral(classType, value) {
|
507
|
+
var _a;
|
430
508
|
const newClassType = TypeBase.cloneType(classType);
|
431
|
-
newClassType.literalValue = value;
|
509
|
+
newClassType.priv.literalValue = value;
|
432
510
|
// Remove type alias information because the type will no longer match
|
433
511
|
// that of the type alias definition if we change the literal type.
|
434
|
-
|
512
|
+
if ((_a = newClassType.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) {
|
513
|
+
TypeBase.setTypeAliasInfo(newClassType, undefined);
|
514
|
+
}
|
435
515
|
return newClassType;
|
436
516
|
}
|
437
517
|
ClassType.cloneWithLiteral = cloneWithLiteral;
|
438
518
|
function cloneForDeprecatedInstance(type, deprecatedMessage) {
|
439
519
|
const newClassType = TypeBase.cloneType(type);
|
440
|
-
newClassType.deprecatedInstanceMessage = deprecatedMessage;
|
520
|
+
newClassType.priv.deprecatedInstanceMessage = deprecatedMessage;
|
441
521
|
return newClassType;
|
442
522
|
}
|
443
523
|
ClassType.cloneForDeprecatedInstance = cloneForDeprecatedInstance;
|
444
524
|
function cloneForTypingAlias(classType, aliasName) {
|
445
525
|
const newClassType = TypeBase.cloneType(classType);
|
446
|
-
newClassType.aliasName = aliasName;
|
526
|
+
newClassType.priv.aliasName = aliasName;
|
447
527
|
return newClassType;
|
448
528
|
}
|
449
529
|
ClassType.cloneForTypingAlias = cloneForTypingAlias;
|
450
530
|
function cloneForNarrowedTypedDictEntries(classType, narrowedEntries) {
|
451
531
|
const newClassType = TypeBase.cloneType(classType);
|
452
|
-
newClassType.typedDictNarrowedEntries = narrowedEntries;
|
532
|
+
newClassType.priv.typedDictNarrowedEntries = narrowedEntries;
|
453
533
|
return newClassType;
|
454
534
|
}
|
455
535
|
ClassType.cloneForNarrowedTypedDictEntries = cloneForNarrowedTypedDictEntries;
|
456
536
|
function cloneForPartialTypedDict(classType) {
|
457
537
|
const newClassType = TypeBase.cloneType(classType);
|
458
|
-
newClassType.isTypedDictPartial = true;
|
538
|
+
newClassType.priv.isTypedDictPartial = true;
|
459
539
|
return newClassType;
|
460
540
|
}
|
461
541
|
ClassType.cloneForPartialTypedDict = cloneForPartialTypedDict;
|
462
542
|
function cloneRemoveTypePromotions(classType) {
|
463
|
-
if (!classType.includePromotions) {
|
543
|
+
if (!classType.priv.includePromotions) {
|
464
544
|
return classType;
|
465
545
|
}
|
466
546
|
const newClassType = TypeBase.cloneType(classType);
|
467
|
-
|
547
|
+
if (newClassType.priv.includePromotions !== undefined) {
|
548
|
+
newClassType.priv.includePromotions = undefined;
|
549
|
+
}
|
468
550
|
return newClassType;
|
469
551
|
}
|
470
552
|
ClassType.cloneRemoveTypePromotions = cloneRemoveTypePromotions;
|
471
553
|
function cloneForTypeGuard(classType, typeGuardType, isStrictTypeGuard) {
|
472
554
|
const newClassType = TypeBase.cloneType(classType);
|
473
|
-
newClassType.typeGuardType = typeGuardType;
|
474
|
-
newClassType.isStrictTypeGuard = isStrictTypeGuard;
|
555
|
+
newClassType.priv.typeGuardType = typeGuardType;
|
556
|
+
newClassType.priv.isStrictTypeGuard = isStrictTypeGuard;
|
475
557
|
return newClassType;
|
476
558
|
}
|
477
559
|
ClassType.cloneForTypeGuard = cloneForTypeGuard;
|
478
560
|
function cloneForSymbolTableUpdate(classType) {
|
479
561
|
const newClassType = TypeBase.cloneType(classType);
|
480
|
-
newClassType.
|
481
|
-
newClassType.
|
482
|
-
newClassType.
|
483
|
-
newClassType.
|
562
|
+
newClassType.shared = { ...newClassType.shared };
|
563
|
+
newClassType.shared.fields = new Map(newClassType.shared.fields);
|
564
|
+
newClassType.shared.mro = Array.from(newClassType.shared.mro);
|
565
|
+
newClassType.shared.mro[0] = cloneAsInstantiable(newClassType);
|
484
566
|
return newClassType;
|
485
567
|
}
|
486
568
|
ClassType.cloneForSymbolTableUpdate = cloneForSymbolTableUpdate;
|
487
569
|
function cloneForUnpacked(classType, isUnpacked = true) {
|
488
570
|
const newClassType = TypeBase.cloneType(classType);
|
489
|
-
newClassType.isUnpacked = isUnpacked;
|
571
|
+
newClassType.priv.isUnpacked = isUnpacked;
|
490
572
|
return newClassType;
|
491
573
|
}
|
492
574
|
ClassType.cloneForUnpacked = cloneForUnpacked;
|
493
575
|
function cloneWithNewFlags(classType, newFlags) {
|
494
576
|
const newClassType = TypeBase.cloneType(classType);
|
495
|
-
newClassType.
|
496
|
-
newClassType.
|
577
|
+
newClassType.shared = { ...newClassType.shared };
|
578
|
+
newClassType.shared.flags = newFlags;
|
497
579
|
return newClassType;
|
498
580
|
}
|
499
581
|
ClassType.cloneWithNewFlags = cloneWithNewFlags;
|
500
582
|
function isLiteralValueSame(type1, type2) {
|
501
|
-
if (type1.literalValue === undefined) {
|
502
|
-
return type2.literalValue === undefined;
|
583
|
+
if (type1.priv.literalValue === undefined) {
|
584
|
+
return type2.priv.literalValue === undefined;
|
503
585
|
}
|
504
|
-
else if (type2.literalValue === undefined) {
|
586
|
+
else if (type2.priv.literalValue === undefined) {
|
505
587
|
return false;
|
506
588
|
}
|
507
|
-
if (type1.literalValue instanceof EnumLiteral) {
|
508
|
-
if (type2.literalValue instanceof EnumLiteral) {
|
509
|
-
return type1.literalValue.itemName === type2.literalValue.itemName;
|
589
|
+
if (type1.priv.literalValue instanceof EnumLiteral) {
|
590
|
+
if (type2.priv.literalValue instanceof EnumLiteral) {
|
591
|
+
return type1.priv.literalValue.itemName === type2.priv.literalValue.itemName;
|
510
592
|
}
|
511
593
|
return false;
|
512
594
|
}
|
513
|
-
return type1.literalValue === type2.literalValue;
|
595
|
+
return type1.priv.literalValue === type2.priv.literalValue;
|
514
596
|
}
|
515
597
|
ClassType.isLiteralValueSame = isLiteralValueSame;
|
516
598
|
// Determines whether two typed dict classes are equivalent given
|
517
599
|
// that one or both have narrowed entries (i.e. entries that are
|
518
600
|
// guaranteed to be present).
|
519
601
|
function isTypedDictNarrowedEntriesSame(type1, type2) {
|
520
|
-
if (type1.typedDictNarrowedEntries) {
|
521
|
-
if (!type2.typedDictNarrowedEntries) {
|
602
|
+
if (type1.priv.typedDictNarrowedEntries) {
|
603
|
+
if (!type2.priv.typedDictNarrowedEntries) {
|
522
604
|
return false;
|
523
605
|
}
|
524
|
-
const tdEntries1 = type1.typedDictNarrowedEntries;
|
525
|
-
const tdEntries2 = type2.typedDictNarrowedEntries;
|
606
|
+
const tdEntries1 = type1.priv.typedDictNarrowedEntries;
|
607
|
+
const tdEntries2 = type2.priv.typedDictNarrowedEntries;
|
526
608
|
if (tdEntries1.size !== tdEntries2.size) {
|
527
609
|
return false;
|
528
610
|
}
|
@@ -538,7 +620,7 @@ var ClassType;
|
|
538
620
|
}
|
539
621
|
}
|
540
622
|
}
|
541
|
-
else if (type2.typedDictNarrowedEntries) {
|
623
|
+
else if (type2.priv.typedDictNarrowedEntries) {
|
542
624
|
return false;
|
543
625
|
}
|
544
626
|
return true;
|
@@ -549,11 +631,11 @@ var ClassType;
|
|
549
631
|
// within type1.
|
550
632
|
function isTypedDictNarrower(type1, type2) {
|
551
633
|
var _a;
|
552
|
-
const tdEntries2 = type2.typedDictNarrowedEntries;
|
634
|
+
const tdEntries2 = type2.priv.typedDictNarrowedEntries;
|
553
635
|
if (!tdEntries2) {
|
554
636
|
return true;
|
555
637
|
}
|
556
|
-
const tdEntries1 = (_a = type1.typedDictNarrowedEntries) !== null && _a !== void 0 ? _a : new Map();
|
638
|
+
const tdEntries1 = (_a = type1.priv.typedDictNarrowedEntries) !== null && _a !== void 0 ? _a : new Map();
|
557
639
|
let key;
|
558
640
|
let entry2;
|
559
641
|
for ([key, entry2] of tdEntries2.entries()) {
|
@@ -569,185 +651,189 @@ var ClassType;
|
|
569
651
|
ClassType.isTypedDictNarrower = isTypedDictNarrower;
|
570
652
|
// Is the class generic but not specialized?
|
571
653
|
function isUnspecialized(classType) {
|
572
|
-
return classType.
|
654
|
+
return classType.shared.typeParameters.length > 0 && classType.priv.typeArguments === undefined;
|
573
655
|
}
|
574
656
|
ClassType.isUnspecialized = isUnspecialized;
|
575
657
|
function isSpecialBuiltIn(classType, className) {
|
576
|
-
if (!(classType.
|
658
|
+
if (!(classType.shared.flags & 2 /* ClassTypeFlags.SpecialBuiltIn */) && !classType.priv.aliasName) {
|
577
659
|
return false;
|
578
660
|
}
|
579
661
|
if (className !== undefined) {
|
580
|
-
return classType.
|
662
|
+
return classType.shared.name === className;
|
581
663
|
}
|
582
664
|
return true;
|
583
665
|
}
|
584
666
|
ClassType.isSpecialBuiltIn = isSpecialBuiltIn;
|
585
667
|
function isBuiltIn(classType, className) {
|
586
|
-
if (!(classType.
|
668
|
+
if (!(classType.shared.flags & 1 /* ClassTypeFlags.BuiltIn */)) {
|
587
669
|
return false;
|
588
670
|
}
|
589
671
|
if (className !== undefined) {
|
590
672
|
const classArray = Array.isArray(className) ? className : [className];
|
591
|
-
return (classArray.some((name) => name === classType.
|
592
|
-
classArray.some((name) => name === classType.aliasName));
|
673
|
+
return (classArray.some((name) => name === classType.shared.name) ||
|
674
|
+
classArray.some((name) => name === classType.priv.aliasName));
|
593
675
|
}
|
594
676
|
return true;
|
595
677
|
}
|
596
678
|
ClassType.isBuiltIn = isBuiltIn;
|
597
679
|
function supportsAbstractMethods(classType) {
|
598
|
-
return !!(classType.
|
680
|
+
return !!(classType.shared.flags & 64 /* ClassTypeFlags.SupportsAbstractMethods */);
|
599
681
|
}
|
600
682
|
ClassType.supportsAbstractMethods = supportsAbstractMethods;
|
601
683
|
function isDataClass(classType) {
|
602
|
-
return !!classType.
|
684
|
+
return !!classType.shared.dataClassBehaviors;
|
603
685
|
}
|
604
686
|
ClassType.isDataClass = isDataClass;
|
605
687
|
function isDataClassSkipGenerateInit(classType) {
|
606
688
|
var _a;
|
607
|
-
return !!((_a = classType.
|
689
|
+
return !!((_a = classType.shared.dataClassBehaviors) === null || _a === void 0 ? void 0 : _a.skipGenerateInit);
|
608
690
|
}
|
609
691
|
ClassType.isDataClassSkipGenerateInit = isDataClassSkipGenerateInit;
|
610
692
|
function isDataClassSkipGenerateEq(classType) {
|
611
693
|
var _a;
|
612
|
-
return !!((_a = classType.
|
694
|
+
return !!((_a = classType.shared.dataClassBehaviors) === null || _a === void 0 ? void 0 : _a.skipGenerateEq);
|
613
695
|
}
|
614
696
|
ClassType.isDataClassSkipGenerateEq = isDataClassSkipGenerateEq;
|
615
697
|
function isDataClassFrozen(classType) {
|
616
698
|
var _a;
|
617
|
-
return !!((_a = classType.
|
699
|
+
return !!((_a = classType.shared.dataClassBehaviors) === null || _a === void 0 ? void 0 : _a.frozen);
|
618
700
|
}
|
619
701
|
ClassType.isDataClassFrozen = isDataClassFrozen;
|
620
702
|
function isDataClassGenerateOrder(classType) {
|
621
703
|
var _a;
|
622
|
-
return !!((_a = classType.
|
704
|
+
return !!((_a = classType.shared.dataClassBehaviors) === null || _a === void 0 ? void 0 : _a.generateOrder);
|
623
705
|
}
|
624
706
|
ClassType.isDataClassGenerateOrder = isDataClassGenerateOrder;
|
625
707
|
function isDataClassKeywordOnly(classType) {
|
626
708
|
var _a;
|
627
|
-
return !!((_a = classType.
|
709
|
+
return !!((_a = classType.shared.dataClassBehaviors) === null || _a === void 0 ? void 0 : _a.keywordOnly);
|
628
710
|
}
|
629
711
|
ClassType.isDataClassKeywordOnly = isDataClassKeywordOnly;
|
630
712
|
function isDataClassGenerateSlots(classType) {
|
631
713
|
var _a;
|
632
|
-
return !!((_a = classType.
|
714
|
+
return !!((_a = classType.shared.dataClassBehaviors) === null || _a === void 0 ? void 0 : _a.generateSlots);
|
633
715
|
}
|
634
716
|
ClassType.isDataClassGenerateSlots = isDataClassGenerateSlots;
|
635
717
|
function isDataClassGenerateHash(classType) {
|
636
718
|
var _a;
|
637
|
-
return !!((_a = classType.
|
719
|
+
return !!((_a = classType.shared.dataClassBehaviors) === null || _a === void 0 ? void 0 : _a.generateHash);
|
638
720
|
}
|
639
721
|
ClassType.isDataClassGenerateHash = isDataClassGenerateHash;
|
640
722
|
function isTypeCheckOnly(classType) {
|
641
|
-
return !!(classType.
|
723
|
+
return !!(classType.shared.flags & 1048576 /* ClassTypeFlags.TypeCheckOnly */);
|
642
724
|
}
|
643
725
|
ClassType.isTypeCheckOnly = isTypeCheckOnly;
|
644
726
|
function isNewTypeClass(classType) {
|
645
|
-
return !!(classType.
|
727
|
+
return !!(classType.shared.flags & 2097152 /* ClassTypeFlags.NewTypeClass */);
|
646
728
|
}
|
647
729
|
ClassType.isNewTypeClass = isNewTypeClass;
|
648
730
|
function isValidTypeAliasClass(classType) {
|
649
|
-
return !!(classType.
|
731
|
+
return !!(classType.shared.flags & 4194304 /* ClassTypeFlags.ValidTypeAliasClass */);
|
650
732
|
}
|
651
733
|
ClassType.isValidTypeAliasClass = isValidTypeAliasClass;
|
652
734
|
function isSpecialFormClass(classType) {
|
653
|
-
return !!(classType.
|
735
|
+
return !!(classType.shared.flags & 8388608 /* ClassTypeFlags.SpecialFormClass */);
|
654
736
|
}
|
655
737
|
ClassType.isSpecialFormClass = isSpecialFormClass;
|
738
|
+
function isIllegalIsinstanceClass(classType) {
|
739
|
+
return !!(classType.shared.flags & 16777216 /* ClassTypeFlags.IllegalIsinstanceClass */);
|
740
|
+
}
|
741
|
+
ClassType.isIllegalIsinstanceClass = isIllegalIsinstanceClass;
|
656
742
|
function isTypedDictClass(classType) {
|
657
|
-
return !!(classType.
|
743
|
+
return !!(classType.shared.flags & 4 /* ClassTypeFlags.TypedDictClass */);
|
658
744
|
}
|
659
745
|
ClassType.isTypedDictClass = isTypedDictClass;
|
660
746
|
function isCanOmitDictValues(classType) {
|
661
|
-
return !!(classType.
|
747
|
+
return !!(classType.shared.flags & 32 /* ClassTypeFlags.CanOmitDictValues */);
|
662
748
|
}
|
663
749
|
ClassType.isCanOmitDictValues = isCanOmitDictValues;
|
664
750
|
function isTypedDictMarkedClosed(classType) {
|
665
|
-
return !!(classType.
|
751
|
+
return !!(classType.shared.flags & 8 /* ClassTypeFlags.TypedDictMarkedClosed */);
|
666
752
|
}
|
667
753
|
ClassType.isTypedDictMarkedClosed = isTypedDictMarkedClosed;
|
668
754
|
function isTypedDictEffectivelyClosed(classType) {
|
669
|
-
return !!(classType.
|
755
|
+
return !!(classType.shared.flags & 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */);
|
670
756
|
}
|
671
757
|
ClassType.isTypedDictEffectivelyClosed = isTypedDictEffectivelyClosed;
|
672
758
|
function isEnumClass(classType) {
|
673
|
-
return !!(classType.
|
759
|
+
return !!(classType.shared.flags & 65536 /* ClassTypeFlags.EnumClass */);
|
674
760
|
}
|
675
761
|
ClassType.isEnumClass = isEnumClass;
|
676
762
|
function isPropertyClass(classType) {
|
677
|
-
return !!(classType.
|
763
|
+
return !!(classType.shared.flags & 128 /* ClassTypeFlags.PropertyClass */);
|
678
764
|
}
|
679
765
|
ClassType.isPropertyClass = isPropertyClass;
|
680
766
|
function isClassProperty(classType) {
|
681
|
-
return !!(classType.
|
767
|
+
return !!(classType.shared.flags & 131072 /* ClassTypeFlags.ClassProperty */);
|
682
768
|
}
|
683
769
|
ClassType.isClassProperty = isClassProperty;
|
684
770
|
function isFinal(classType) {
|
685
|
-
return !!(classType.
|
771
|
+
return !!(classType.shared.flags & 256 /* ClassTypeFlags.Final */);
|
686
772
|
}
|
687
773
|
ClassType.isFinal = isFinal;
|
688
774
|
function isProtocolClass(classType) {
|
689
|
-
return !!(classType.
|
775
|
+
return !!(classType.shared.flags & 512 /* ClassTypeFlags.ProtocolClass */);
|
690
776
|
}
|
691
777
|
ClassType.isProtocolClass = isProtocolClass;
|
692
778
|
function isDefinedInStub(classType) {
|
693
|
-
return !!(classType.
|
779
|
+
return !!(classType.shared.flags & 262144 /* ClassTypeFlags.DefinedInStub */);
|
694
780
|
}
|
695
781
|
ClassType.isDefinedInStub = isDefinedInStub;
|
696
782
|
function isPseudoGenericClass(classType) {
|
697
|
-
return !!(classType.
|
783
|
+
return !!(classType.shared.flags & 1024 /* ClassTypeFlags.PseudoGenericClass */);
|
698
784
|
}
|
699
785
|
ClassType.isPseudoGenericClass = isPseudoGenericClass;
|
700
786
|
function getDataClassEntries(classType) {
|
701
787
|
var _a, _b;
|
702
|
-
(_b = (_a = classType.
|
703
|
-
return classType.
|
788
|
+
(_b = (_a = classType.shared).synthesizeMethodsDeferred) === null || _b === void 0 ? void 0 : _b.call(_a);
|
789
|
+
return classType.shared.dataClassEntries || [];
|
704
790
|
}
|
705
791
|
ClassType.getDataClassEntries = getDataClassEntries;
|
706
792
|
function isRuntimeCheckable(classType) {
|
707
|
-
return !!(classType.
|
793
|
+
return !!(classType.shared.flags & 2048 /* ClassTypeFlags.RuntimeCheckable */);
|
708
794
|
}
|
709
795
|
ClassType.isRuntimeCheckable = isRuntimeCheckable;
|
710
796
|
function isTypingExtensionClass(classType) {
|
711
|
-
return !!(classType.
|
797
|
+
return !!(classType.shared.flags & 4096 /* ClassTypeFlags.TypingExtensionClass */);
|
712
798
|
}
|
713
799
|
ClassType.isTypingExtensionClass = isTypingExtensionClass;
|
714
800
|
function isPartiallyEvaluated(classType) {
|
715
|
-
return !!(classType.
|
801
|
+
return !!(classType.shared.flags & 8192 /* ClassTypeFlags.PartiallyEvaluated */);
|
716
802
|
}
|
717
803
|
ClassType.isPartiallyEvaluated = isPartiallyEvaluated;
|
718
804
|
function hasCustomClassGetItem(classType) {
|
719
|
-
return !!(classType.
|
805
|
+
return !!(classType.shared.flags & 16384 /* ClassTypeFlags.HasCustomClassGetItem */);
|
720
806
|
}
|
721
807
|
ClassType.hasCustomClassGetItem = hasCustomClassGetItem;
|
722
808
|
function isTupleClass(classType) {
|
723
|
-
return !!(classType.
|
809
|
+
return !!(classType.shared.flags & 32768 /* ClassTypeFlags.TupleClass */);
|
724
810
|
}
|
725
811
|
ClassType.isTupleClass = isTupleClass;
|
726
812
|
function isReadOnlyInstanceVariables(classType) {
|
727
|
-
return !!(classType.
|
813
|
+
return !!(classType.shared.flags & 524288 /* ClassTypeFlags.ReadOnlyInstanceVariables */);
|
728
814
|
}
|
729
815
|
ClassType.isReadOnlyInstanceVariables = isReadOnlyInstanceVariables;
|
730
816
|
function getTypeParameters(classType) {
|
731
|
-
return classType.
|
817
|
+
return classType.shared.typeParameters;
|
732
818
|
}
|
733
819
|
ClassType.getTypeParameters = getTypeParameters;
|
734
820
|
function derivesFromAnyOrUnknown(classType) {
|
735
|
-
return classType.
|
821
|
+
return classType.shared.mro.some((baseClass) => isAnyOrUnknown(baseClass));
|
736
822
|
}
|
737
823
|
ClassType.derivesFromAnyOrUnknown = derivesFromAnyOrUnknown;
|
738
824
|
function getSymbolTable(classType) {
|
739
825
|
var _a, _b;
|
740
|
-
(_b = (_a = classType.
|
741
|
-
return classType.
|
826
|
+
(_b = (_a = classType.shared).synthesizeMethodsDeferred) === null || _b === void 0 ? void 0 : _b.call(_a);
|
827
|
+
return classType.shared.fields;
|
742
828
|
}
|
743
829
|
ClassType.getSymbolTable = getSymbolTable;
|
744
830
|
function getInheritedSlotsNames(classType) {
|
745
831
|
var _a, _b, _c, _d;
|
746
832
|
// First synthesize methods if needed. The slots entries
|
747
833
|
// can depend on synthesized methods.
|
748
|
-
(_b = (_a = classType.
|
749
|
-
(_d = (_c = classType.
|
750
|
-
return classType.
|
834
|
+
(_b = (_a = classType.shared).synthesizeMethodsDeferred) === null || _b === void 0 ? void 0 : _b.call(_a);
|
835
|
+
(_d = (_c = classType.shared).calculateInheritedSlotsNamesDeferred) === null || _d === void 0 ? void 0 : _d.call(_c);
|
836
|
+
return classType.shared.inheritedSlotsNamesCached;
|
751
837
|
}
|
752
838
|
ClassType.getInheritedSlotsNames = getInheritedSlotsNames;
|
753
839
|
// Similar to isPartiallyEvaluated except that it also looks at all of the
|
@@ -755,16 +841,16 @@ var ClassType;
|
|
755
841
|
// partially evaluated.
|
756
842
|
function isHierarchyPartiallyEvaluated(classType) {
|
757
843
|
return (ClassType.isPartiallyEvaluated(classType) ||
|
758
|
-
classType.
|
844
|
+
classType.shared.mro.some((mroClass) => isClass(mroClass) && ClassType.isPartiallyEvaluated(mroClass)));
|
759
845
|
}
|
760
846
|
ClassType.isHierarchyPartiallyEvaluated = isHierarchyPartiallyEvaluated;
|
761
847
|
// Same as isTypeSame except that it doesn't compare type arguments.
|
762
848
|
function isSameGenericClass(classType, type2, recursionCount = 0) {
|
763
|
-
if (!classType.isTypedDictPartial !== !type2.isTypedDictPartial) {
|
849
|
+
if (!classType.priv.isTypedDictPartial !== !type2.priv.isTypedDictPartial) {
|
764
850
|
return false;
|
765
851
|
}
|
766
|
-
const class1Details = classType.
|
767
|
-
const class2Details = type2.
|
852
|
+
const class1Details = classType.shared;
|
853
|
+
const class2Details = type2.shared;
|
768
854
|
if (class1Details === class2Details) {
|
769
855
|
return true;
|
770
856
|
}
|
@@ -819,8 +905,8 @@ var ClassType;
|
|
819
905
|
// Is it the exact same class?
|
820
906
|
if (isSameGenericClass(subclassType, parentClassType)) {
|
821
907
|
// Handle literal types.
|
822
|
-
if (parentClassType.literalValue !== undefined) {
|
823
|
-
if (subclassType.literalValue === undefined ||
|
908
|
+
if (parentClassType.priv.literalValue !== undefined) {
|
909
|
+
if (subclassType.priv.literalValue === undefined ||
|
824
910
|
!ClassType.isLiteralValueSame(parentClassType, subclassType)) {
|
825
911
|
return false;
|
826
912
|
}
|
@@ -848,7 +934,7 @@ var ClassType;
|
|
848
934
|
}
|
849
935
|
return true;
|
850
936
|
}
|
851
|
-
for (const baseClass of subclassType.
|
937
|
+
for (const baseClass of subclassType.shared.baseClasses) {
|
852
938
|
if (isInstantiableClass(baseClass)) {
|
853
939
|
if (isDerivedFrom(baseClass, parentClassType, inheritanceChain)) {
|
854
940
|
if (inheritanceChain) {
|
@@ -868,10 +954,39 @@ var ClassType;
|
|
868
954
|
}
|
869
955
|
ClassType.isDerivedFrom = isDerivedFrom;
|
870
956
|
function getReverseMro(classType) {
|
871
|
-
return classType.
|
957
|
+
return classType.shared.mro.slice(0).reverse();
|
872
958
|
}
|
873
959
|
ClassType.getReverseMro = getReverseMro;
|
874
960
|
})(ClassType || (exports.ClassType = ClassType = {}));
|
961
|
+
var FunctionParamFlags;
|
962
|
+
(function (FunctionParamFlags) {
|
963
|
+
FunctionParamFlags[FunctionParamFlags["None"] = 0] = "None";
|
964
|
+
// Is the name of the parameter synthesize internally?
|
965
|
+
FunctionParamFlags[FunctionParamFlags["NameSynthesized"] = 1] = "NameSynthesized";
|
966
|
+
// Does the parameter have an explicitly-declared type?
|
967
|
+
FunctionParamFlags[FunctionParamFlags["TypeDeclared"] = 2] = "TypeDeclared";
|
968
|
+
// Is the type of the parameter inferred?
|
969
|
+
FunctionParamFlags[FunctionParamFlags["TypeInferred"] = 4] = "TypeInferred";
|
970
|
+
})(FunctionParamFlags || (exports.FunctionParamFlags = FunctionParamFlags = {}));
|
971
|
+
var FunctionParam;
|
972
|
+
(function (FunctionParam) {
|
973
|
+
function create(category, type, flags = FunctionParamFlags.None, name, defaultType) {
|
974
|
+
return { category, type, flags, name, defaultType };
|
975
|
+
}
|
976
|
+
FunctionParam.create = create;
|
977
|
+
function isNameSynthesized(param) {
|
978
|
+
return !!(param.flags & FunctionParamFlags.NameSynthesized);
|
979
|
+
}
|
980
|
+
FunctionParam.isNameSynthesized = isNameSynthesized;
|
981
|
+
function isTypeDeclared(param) {
|
982
|
+
return !!(param.flags & FunctionParamFlags.TypeDeclared);
|
983
|
+
}
|
984
|
+
FunctionParam.isTypeDeclared = isTypeDeclared;
|
985
|
+
function isTypeInferred(param) {
|
986
|
+
return !!(param.flags & FunctionParamFlags.TypeInferred);
|
987
|
+
}
|
988
|
+
FunctionParam.isTypeInferred = isTypeInferred;
|
989
|
+
})(FunctionParam || (exports.FunctionParam = FunctionParam = {}));
|
875
990
|
function isPositionOnlySeparator(param) {
|
876
991
|
// A simple parameter with no name is treated as a "/" separator.
|
877
992
|
return param.category === 0 /* ParameterCategory.Simple */ && !param.name;
|
@@ -935,6 +1050,8 @@ var FunctionTypeFlags;
|
|
935
1050
|
FunctionTypeFlags[FunctionTypeFlags["Overridden"] = 262144] = "Overridden";
|
936
1051
|
// Decorated with @no_type_check.
|
937
1052
|
FunctionTypeFlags[FunctionTypeFlags["NoTypeCheck"] = 524288] = "NoTypeCheck";
|
1053
|
+
// Function defined in one of the core stdlib modules.
|
1054
|
+
FunctionTypeFlags[FunctionTypeFlags["BuiltIn"] = 1048576] = "BuiltIn";
|
938
1055
|
})(FunctionTypeFlags || (exports.FunctionTypeFlags = FunctionTypeFlags = {}));
|
939
1056
|
var FunctionType;
|
940
1057
|
(function (FunctionType) {
|
@@ -953,37 +1070,48 @@ var FunctionType;
|
|
953
1070
|
function create(name, fullName, moduleName, functionFlags, typeFlags, docString) {
|
954
1071
|
const newFunctionType = {
|
955
1072
|
category: 4 /* TypeCategory.Function */,
|
956
|
-
|
1073
|
+
flags: typeFlags,
|
1074
|
+
props: undefined,
|
1075
|
+
cached: undefined,
|
1076
|
+
shared: {
|
957
1077
|
name,
|
958
1078
|
fullName,
|
959
1079
|
moduleName,
|
960
1080
|
flags: functionFlags,
|
961
|
-
parameters: [],
|
962
1081
|
typeParameters: [],
|
1082
|
+
parameters: [],
|
1083
|
+
declaredReturnType: undefined,
|
1084
|
+
declaration: undefined,
|
1085
|
+
typeVarScopeId: undefined,
|
963
1086
|
docString,
|
1087
|
+
deprecatedMessage: undefined,
|
1088
|
+
methodClass: undefined,
|
1089
|
+
decoratorDataClassBehaviors: undefined,
|
964
1090
|
},
|
965
|
-
|
1091
|
+
priv: {},
|
966
1092
|
};
|
967
1093
|
return newFunctionType;
|
968
1094
|
}
|
969
1095
|
// Creates a deep copy of the function type, including a fresh
|
970
1096
|
// version of _functionDetails.
|
971
1097
|
function clone(type, stripFirstParam = false, boundToType, boundTypeVarScopeId) {
|
972
|
-
var _a;
|
1098
|
+
var _a, _b;
|
973
1099
|
const newFunction = TypeBase.cloneType(type);
|
974
|
-
newFunction.
|
975
|
-
newFunction.preBoundFlags = newFunction.
|
976
|
-
newFunction.boundToType = boundToType;
|
977
|
-
|
1100
|
+
newFunction.shared = { ...type.shared };
|
1101
|
+
newFunction.priv.preBoundFlags = newFunction.shared.flags;
|
1102
|
+
newFunction.priv.boundToType = boundToType;
|
1103
|
+
if (boundTypeVarScopeId) {
|
1104
|
+
newFunction.priv.constructorTypeVarScopeId = boundTypeVarScopeId;
|
1105
|
+
}
|
978
1106
|
if (stripFirstParam) {
|
979
|
-
if (type.
|
980
|
-
if (type.
|
981
|
-
if (type.
|
1107
|
+
if (type.shared.parameters.length > 0) {
|
1108
|
+
if (type.shared.parameters[0].category === 0 /* ParameterCategory.Simple */) {
|
1109
|
+
if (type.shared.parameters.length > 0 && !FunctionParam.isTypeInferred(type.shared.parameters[0])) {
|
982
1110
|
// Stash away the effective type of the first parameter if it
|
983
1111
|
// wasn't synthesized.
|
984
|
-
newFunction.strippedFirstParamType = getEffectiveParameterType(type, 0);
|
1112
|
+
newFunction.priv.strippedFirstParamType = getEffectiveParameterType(type, 0);
|
985
1113
|
}
|
986
|
-
newFunction.
|
1114
|
+
newFunction.shared.parameters = type.shared.parameters.slice(1);
|
987
1115
|
}
|
988
1116
|
}
|
989
1117
|
else {
|
@@ -991,34 +1119,36 @@ var FunctionType;
|
|
991
1119
|
}
|
992
1120
|
// If we strip off the first parameter, this is no longer an
|
993
1121
|
// instance method or class method.
|
994
|
-
newFunction.
|
995
|
-
newFunction.
|
1122
|
+
newFunction.shared.flags &= ~(1 /* FunctionTypeFlags.ConstructorMethod */ | 2 /* FunctionTypeFlags.ClassMethod */);
|
1123
|
+
newFunction.shared.flags |= 4 /* FunctionTypeFlags.StaticMethod */;
|
996
1124
|
}
|
997
|
-
if (type.
|
998
|
-
newFunction
|
1125
|
+
if ((_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) {
|
1126
|
+
TypeBase.setTypeAliasInfo(newFunction, type.props.typeAliasInfo);
|
999
1127
|
}
|
1000
|
-
if (type.specializedTypes) {
|
1001
|
-
newFunction.specializedTypes = {
|
1128
|
+
if (type.priv.specializedTypes) {
|
1129
|
+
newFunction.priv.specializedTypes = {
|
1002
1130
|
parameterTypes: stripFirstParam
|
1003
|
-
? type.specializedTypes.parameterTypes.slice(1)
|
1004
|
-
: type.specializedTypes.parameterTypes,
|
1131
|
+
? type.priv.specializedTypes.parameterTypes.slice(1)
|
1132
|
+
: type.priv.specializedTypes.parameterTypes,
|
1005
1133
|
parameterDefaultArgs: stripFirstParam
|
1006
|
-
? (
|
1007
|
-
: type.specializedTypes.parameterDefaultArgs,
|
1008
|
-
returnType: type.specializedTypes.returnType,
|
1134
|
+
? (_b = type.priv.specializedTypes.parameterDefaultArgs) === null || _b === void 0 ? void 0 : _b.slice(1)
|
1135
|
+
: type.priv.specializedTypes.parameterDefaultArgs,
|
1136
|
+
returnType: type.priv.specializedTypes.returnType,
|
1009
1137
|
};
|
1010
1138
|
}
|
1011
|
-
newFunction.inferredReturnType = type.inferredReturnType;
|
1139
|
+
newFunction.priv.inferredReturnType = type.priv.inferredReturnType;
|
1012
1140
|
return newFunction;
|
1013
1141
|
}
|
1014
1142
|
FunctionType.clone = clone;
|
1015
1143
|
function cloneAsInstance(type) {
|
1016
|
-
var _a;
|
1144
|
+
var _a, _b;
|
1017
1145
|
if ((_a = type.cached) === null || _a === void 0 ? void 0 : _a.typeBaseInstanceType) {
|
1018
1146
|
return type.cached.typeBaseInstanceType;
|
1019
1147
|
}
|
1020
1148
|
const newInstance = TypeBase.cloneTypeAsInstance(type, /* cache */ true);
|
1021
|
-
|
1149
|
+
if ((_b = newInstance.props) === null || _b === void 0 ? void 0 : _b.specialForm) {
|
1150
|
+
TypeBase.setSpecialForm(newInstance, undefined);
|
1151
|
+
}
|
1022
1152
|
return newInstance;
|
1023
1153
|
}
|
1024
1154
|
FunctionType.cloneAsInstance = cloneAsInstance;
|
@@ -1036,65 +1166,59 @@ var FunctionType;
|
|
1036
1166
|
// with the object being cloned.
|
1037
1167
|
function cloneForSpecialization(type, specializedTypes, specializedInferredReturnType) {
|
1038
1168
|
const newFunction = TypeBase.cloneType(type);
|
1039
|
-
(0, debug_1.assert)(specializedTypes.parameterTypes.length === type.
|
1169
|
+
(0, debug_1.assert)(specializedTypes.parameterTypes.length === type.shared.parameters.length);
|
1040
1170
|
if (specializedTypes.parameterDefaultArgs) {
|
1041
|
-
(0, debug_1.assert)(specializedTypes.parameterDefaultArgs.length === type.
|
1171
|
+
(0, debug_1.assert)(specializedTypes.parameterDefaultArgs.length === type.shared.parameters.length);
|
1042
1172
|
}
|
1043
|
-
newFunction.specializedTypes = specializedTypes;
|
1044
|
-
newFunction.inferredReturnType = specializedInferredReturnType;
|
1173
|
+
newFunction.priv.specializedTypes = specializedTypes;
|
1174
|
+
newFunction.priv.inferredReturnType = specializedInferredReturnType;
|
1045
1175
|
return newFunction;
|
1046
1176
|
}
|
1047
1177
|
FunctionType.cloneForSpecialization = cloneForSpecialization;
|
1048
1178
|
// Creates a new function based on the parameters of another function.
|
1049
1179
|
function applyParamSpecValue(type, paramSpecValue) {
|
1050
|
-
const hasPositionalOnly = paramSpecValue.
|
1180
|
+
const hasPositionalOnly = paramSpecValue.shared.parameters.some((param) => isPositionOnlySeparator(param));
|
1051
1181
|
const newFunction = FunctionType.cloneRemoveParamSpecArgsKwargs(TypeBase.cloneType(type), hasPositionalOnly);
|
1052
1182
|
const paramSpec = FunctionType.getParamSpecFromArgsKwargs(type);
|
1053
1183
|
(0, debug_1.assert)(paramSpec !== undefined);
|
1054
1184
|
// Make a shallow clone of the details.
|
1055
|
-
newFunction.
|
1056
|
-
newFunction.
|
1057
|
-
const prevParams = Array.from(newFunction.
|
1058
|
-
newFunction.
|
1185
|
+
newFunction.shared = { ...newFunction.shared };
|
1186
|
+
newFunction.shared.typeParameters = newFunction.shared.typeParameters.filter((t) => !isTypeSame(t, paramSpec));
|
1187
|
+
const prevParams = Array.from(newFunction.shared.parameters);
|
1188
|
+
newFunction.shared.parameters = [
|
1059
1189
|
...prevParams,
|
1060
|
-
...paramSpecValue.
|
1061
|
-
return
|
1062
|
-
category: param.category,
|
1063
|
-
name: param.name,
|
1064
|
-
hasDefault: param.hasDefault,
|
1065
|
-
defaultValueExpression: param.defaultValueExpression,
|
1066
|
-
isNameSynthesized: param.isNameSynthesized,
|
1067
|
-
hasDeclaredType: true,
|
1068
|
-
type: param.type,
|
1069
|
-
};
|
1190
|
+
...paramSpecValue.shared.parameters.map((param) => {
|
1191
|
+
return FunctionParam.create(param.category, param.type, (param.flags & FunctionParamFlags.NameSynthesized) | FunctionParamFlags.TypeDeclared, param.name, param.defaultType);
|
1070
1192
|
}),
|
1071
1193
|
];
|
1072
|
-
if (newFunction.
|
1073
|
-
newFunction.
|
1194
|
+
if (newFunction.shared.docString === undefined) {
|
1195
|
+
newFunction.shared.docString = paramSpecValue.shared.docString;
|
1074
1196
|
}
|
1075
|
-
if (newFunction.
|
1076
|
-
newFunction.
|
1197
|
+
if (newFunction.shared.deprecatedMessage === undefined) {
|
1198
|
+
newFunction.shared.deprecatedMessage = paramSpecValue.shared.deprecatedMessage;
|
1077
1199
|
}
|
1078
1200
|
const origFlagsMask = 256 /* FunctionTypeFlags.Overloaded */ | 65536 /* FunctionTypeFlags.ParamSpecValue */;
|
1079
|
-
newFunction.
|
1201
|
+
newFunction.shared.flags = type.shared.flags & origFlagsMask;
|
1080
1202
|
const methodFlagsMask = 2 /* FunctionTypeFlags.ClassMethod */ | 4 /* FunctionTypeFlags.StaticMethod */ | 1 /* FunctionTypeFlags.ConstructorMethod */;
|
1081
1203
|
// If the original function was a method, use its method type. Otherwise
|
1082
1204
|
// use the method type of the param spec.
|
1083
|
-
if (type.
|
1084
|
-
newFunction.
|
1205
|
+
if (type.shared.methodClass) {
|
1206
|
+
newFunction.shared.flags |= type.shared.flags & methodFlagsMask;
|
1085
1207
|
}
|
1086
1208
|
else {
|
1087
|
-
newFunction.
|
1209
|
+
newFunction.shared.flags |= paramSpecValue.shared.flags & methodFlagsMask;
|
1088
1210
|
}
|
1089
1211
|
// Use the "..." flag from the param spec.
|
1090
|
-
newFunction.
|
1212
|
+
newFunction.shared.flags |= paramSpecValue.shared.flags & 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
1091
1213
|
// Mark the function as synthesized since there is no user-defined declaration for it.
|
1092
|
-
newFunction.
|
1093
|
-
|
1214
|
+
newFunction.shared.flags |= 64 /* FunctionTypeFlags.SynthesizedMethod */;
|
1215
|
+
if (newFunction.shared.declaration) {
|
1216
|
+
newFunction.shared.declaration = undefined;
|
1217
|
+
}
|
1094
1218
|
// Update the specialized parameter types as well.
|
1095
|
-
const specializedTypes = newFunction.specializedTypes;
|
1219
|
+
const specializedTypes = newFunction.priv.specializedTypes;
|
1096
1220
|
if (specializedTypes) {
|
1097
|
-
paramSpecValue.
|
1221
|
+
paramSpecValue.shared.parameters.forEach((paramInfo) => {
|
1098
1222
|
var _a;
|
1099
1223
|
specializedTypes.parameterTypes.push(paramInfo.type);
|
1100
1224
|
// Assume that the parameters introduced via paramSpec have no specialized
|
@@ -1102,11 +1226,11 @@ var FunctionType;
|
|
1102
1226
|
(_a = specializedTypes.parameterDefaultArgs) === null || _a === void 0 ? void 0 : _a.push(undefined);
|
1103
1227
|
});
|
1104
1228
|
}
|
1105
|
-
FunctionType.addHigherOrderTypeVarScopeIds(newFunction, paramSpecValue.
|
1106
|
-
FunctionType.addHigherOrderTypeVarScopeIds(newFunction, paramSpecValue.
|
1107
|
-
newFunction.
|
1108
|
-
if (!newFunction.
|
1109
|
-
newFunction.
|
1229
|
+
FunctionType.addHigherOrderTypeVarScopeIds(newFunction, paramSpecValue.shared.typeVarScopeId);
|
1230
|
+
FunctionType.addHigherOrderTypeVarScopeIds(newFunction, paramSpecValue.priv.higherOrderTypeVarScopeIds);
|
1231
|
+
newFunction.priv.constructorTypeVarScopeId = paramSpecValue.priv.constructorTypeVarScopeId;
|
1232
|
+
if (!newFunction.shared.methodClass && paramSpecValue.shared.methodClass) {
|
1233
|
+
newFunction.shared.methodClass = paramSpecValue.shared.methodClass;
|
1110
1234
|
}
|
1111
1235
|
return newFunction;
|
1112
1236
|
}
|
@@ -1114,35 +1238,36 @@ var FunctionType;
|
|
1114
1238
|
function cloneWithNewFlags(type, flags) {
|
1115
1239
|
const newFunction = TypeBase.cloneType(type);
|
1116
1240
|
// Make a shallow clone of the details.
|
1117
|
-
newFunction.
|
1118
|
-
newFunction.
|
1241
|
+
newFunction.shared = { ...type.shared };
|
1242
|
+
newFunction.shared.flags = flags;
|
1119
1243
|
return newFunction;
|
1120
1244
|
}
|
1121
1245
|
FunctionType.cloneWithNewFlags = cloneWithNewFlags;
|
1122
|
-
function cloneWithNewTypeVarScopeId(type, newScopeId, typeParameters, trackedSignatures) {
|
1246
|
+
function cloneWithNewTypeVarScopeId(type, newScopeId, newConstructorScopeId, typeParameters, trackedSignatures) {
|
1123
1247
|
const newFunction = TypeBase.cloneType(type);
|
1124
1248
|
// Make a shallow clone of the details.
|
1125
|
-
newFunction.
|
1126
|
-
newFunction.
|
1127
|
-
newFunction.
|
1128
|
-
newFunction.
|
1129
|
-
|
1249
|
+
newFunction.shared = { ...type.shared };
|
1250
|
+
newFunction.shared.typeVarScopeId = newScopeId;
|
1251
|
+
newFunction.priv.constructorTypeVarScopeId = newConstructorScopeId;
|
1252
|
+
newFunction.shared.typeParameters = typeParameters;
|
1253
|
+
newFunction.priv.trackedSignatures = trackedSignatures;
|
1254
|
+
FunctionType.addHigherOrderTypeVarScopeIds(newFunction, typeParameters.map((t) => t.priv.scopeId));
|
1130
1255
|
return newFunction;
|
1131
1256
|
}
|
1132
1257
|
FunctionType.cloneWithNewTypeVarScopeId = cloneWithNewTypeVarScopeId;
|
1133
1258
|
function cloneWithDocString(type, docString) {
|
1134
1259
|
const newFunction = TypeBase.cloneType(type);
|
1135
1260
|
// Make a shallow clone of the details.
|
1136
|
-
newFunction.
|
1137
|
-
newFunction.
|
1261
|
+
newFunction.shared = { ...type.shared };
|
1262
|
+
newFunction.shared.docString = docString;
|
1138
1263
|
return newFunction;
|
1139
1264
|
}
|
1140
1265
|
FunctionType.cloneWithDocString = cloneWithDocString;
|
1141
1266
|
function cloneWithDeprecatedMessage(type, deprecatedMessage) {
|
1142
1267
|
const newFunction = TypeBase.cloneType(type);
|
1143
1268
|
// Make a shallow clone of the details.
|
1144
|
-
newFunction.
|
1145
|
-
newFunction.
|
1269
|
+
newFunction.shared = { ...type.shared };
|
1270
|
+
newFunction.shared.deprecatedMessage = deprecatedMessage;
|
1146
1271
|
return newFunction;
|
1147
1272
|
}
|
1148
1273
|
FunctionType.cloneWithDeprecatedMessage = cloneWithDeprecatedMessage;
|
@@ -1151,12 +1276,12 @@ var FunctionType;
|
|
1151
1276
|
// *args and **kwargs parameters removed. If stripPositionOnlySeparator is true,
|
1152
1277
|
// a trailing positional-only separator will be removed.
|
1153
1278
|
function cloneRemoveParamSpecArgsKwargs(type, stripPositionOnlySeparator = false) {
|
1154
|
-
const paramCount = type.
|
1279
|
+
const paramCount = type.shared.parameters.length;
|
1155
1280
|
if (paramCount < 2) {
|
1156
1281
|
return type;
|
1157
1282
|
}
|
1158
|
-
const argsParam = type.
|
1159
|
-
const kwargsParam = type.
|
1283
|
+
const argsParam = type.shared.parameters[paramCount - 2];
|
1284
|
+
const kwargsParam = type.shared.parameters[paramCount - 1];
|
1160
1285
|
if (argsParam.category !== 1 /* ParameterCategory.ArgsList */ ||
|
1161
1286
|
kwargsParam.category !== 2 /* ParameterCategory.KwargsDict */) {
|
1162
1287
|
return type;
|
@@ -1168,8 +1293,8 @@ var FunctionType;
|
|
1168
1293
|
}
|
1169
1294
|
const newFunction = TypeBase.cloneType(type);
|
1170
1295
|
// Make a shallow clone of the details.
|
1171
|
-
newFunction.
|
1172
|
-
const details = newFunction.
|
1296
|
+
newFunction.shared = { ...type.shared };
|
1297
|
+
const details = newFunction.shared;
|
1173
1298
|
let paramsToDrop = 2;
|
1174
1299
|
// If the last remaining parameter is a position-only separator, remove it as well.
|
1175
1300
|
// Always remove it if it's the only remaining parameter.
|
@@ -1180,16 +1305,16 @@ var FunctionType;
|
|
1180
1305
|
}
|
1181
1306
|
// Remove the last parameters, which are the *args and **kwargs.
|
1182
1307
|
details.parameters = details.parameters.slice(0, details.parameters.length - paramsToDrop);
|
1183
|
-
if (type.specializedTypes) {
|
1184
|
-
newFunction.specializedTypes = { ...type.specializedTypes };
|
1185
|
-
newFunction.specializedTypes.parameterTypes = newFunction.specializedTypes.parameterTypes.slice(0, newFunction.specializedTypes.parameterTypes.length - paramsToDrop);
|
1186
|
-
if (newFunction.specializedTypes.parameterDefaultArgs) {
|
1187
|
-
newFunction.specializedTypes.parameterDefaultArgs =
|
1188
|
-
newFunction.specializedTypes.parameterDefaultArgs.slice(0, newFunction.specializedTypes.parameterDefaultArgs.length - paramsToDrop);
|
1308
|
+
if (type.priv.specializedTypes) {
|
1309
|
+
newFunction.priv.specializedTypes = { ...type.priv.specializedTypes };
|
1310
|
+
newFunction.priv.specializedTypes.parameterTypes = newFunction.priv.specializedTypes.parameterTypes.slice(0, newFunction.priv.specializedTypes.parameterTypes.length - paramsToDrop);
|
1311
|
+
if (newFunction.priv.specializedTypes.parameterDefaultArgs) {
|
1312
|
+
newFunction.priv.specializedTypes.parameterDefaultArgs =
|
1313
|
+
newFunction.priv.specializedTypes.parameterDefaultArgs.slice(0, newFunction.priv.specializedTypes.parameterDefaultArgs.length - paramsToDrop);
|
1189
1314
|
}
|
1190
1315
|
}
|
1191
|
-
if (type.inferredReturnType) {
|
1192
|
-
newFunction.inferredReturnType = type.inferredReturnType;
|
1316
|
+
if (type.priv.inferredReturnType) {
|
1317
|
+
newFunction.priv.inferredReturnType = type.priv.inferredReturnType;
|
1193
1318
|
}
|
1194
1319
|
return newFunction;
|
1195
1320
|
}
|
@@ -1197,7 +1322,7 @@ var FunctionType;
|
|
1197
1322
|
// If the function ends with "*args: P.args, **kwargs: P.kwargs", this function
|
1198
1323
|
// returns P. Otherwise, it returns undefined.
|
1199
1324
|
function getParamSpecFromArgsKwargs(type) {
|
1200
|
-
const params = type.
|
1325
|
+
const params = type.shared.parameters;
|
1201
1326
|
if (params.length < 2) {
|
1202
1327
|
return undefined;
|
1203
1328
|
}
|
@@ -1205,28 +1330,18 @@ var FunctionType;
|
|
1205
1330
|
const lastParam = params[params.length - 1];
|
1206
1331
|
if (secondLastParam.category === 1 /* ParameterCategory.ArgsList */ &&
|
1207
1332
|
isTypeVar(secondLastParam.type) &&
|
1208
|
-
secondLastParam.type.paramSpecAccess === 'args' &&
|
1333
|
+
secondLastParam.type.priv.paramSpecAccess === 'args' &&
|
1209
1334
|
lastParam.category === 2 /* ParameterCategory.KwargsDict */ &&
|
1210
1335
|
isTypeVar(lastParam.type) &&
|
1211
|
-
lastParam.type.paramSpecAccess === 'kwargs') {
|
1336
|
+
lastParam.type.priv.paramSpecAccess === 'kwargs') {
|
1212
1337
|
return TypeVarType.cloneForParamSpecAccess(secondLastParam.type, /* access */ undefined);
|
1213
1338
|
}
|
1214
1339
|
return undefined;
|
1215
1340
|
}
|
1216
1341
|
FunctionType.getParamSpecFromArgsKwargs = getParamSpecFromArgsKwargs;
|
1217
1342
|
function addParamSpecVariadics(type, paramSpec) {
|
1218
|
-
FunctionType.addParameter(type,
|
1219
|
-
|
1220
|
-
name: 'args',
|
1221
|
-
type: TypeVarType.cloneForParamSpecAccess(paramSpec, 'args'),
|
1222
|
-
hasDeclaredType: true,
|
1223
|
-
});
|
1224
|
-
FunctionType.addParameter(type, {
|
1225
|
-
category: 2 /* ParameterCategory.KwargsDict */,
|
1226
|
-
name: 'kwargs',
|
1227
|
-
type: TypeVarType.cloneForParamSpecAccess(paramSpec, 'kwargs'),
|
1228
|
-
hasDeclaredType: true,
|
1229
|
-
});
|
1343
|
+
FunctionType.addParameter(type, FunctionParam.create(1 /* ParameterCategory.ArgsList */, TypeVarType.cloneForParamSpecAccess(paramSpec, 'args'), FunctionParamFlags.TypeDeclared, 'args'));
|
1344
|
+
FunctionType.addParameter(type, FunctionParam.create(2 /* ParameterCategory.KwargsDict */, TypeVarType.cloneForParamSpecAccess(paramSpec, 'kwargs'), FunctionParamFlags.TypeDeclared, 'kwargs'));
|
1230
1345
|
}
|
1231
1346
|
FunctionType.addParamSpecVariadics = addParamSpecVariadics;
|
1232
1347
|
function addDefaultParameters(type, useUnknown = false) {
|
@@ -1242,34 +1357,24 @@ var FunctionType;
|
|
1242
1357
|
if (!Array.isArray(scopeIds)) {
|
1243
1358
|
scopeIds = [scopeIds];
|
1244
1359
|
}
|
1245
|
-
if (!functionType.
|
1246
|
-
functionType.
|
1360
|
+
if (!functionType.priv.higherOrderTypeVarScopeIds) {
|
1361
|
+
functionType.priv.higherOrderTypeVarScopeIds = [];
|
1247
1362
|
}
|
1248
1363
|
// Add the scope IDs to the function if they're unique.
|
1249
1364
|
scopeIds.forEach((scopeId) => {
|
1250
|
-
if (!scopeId || scopeId === functionType.
|
1365
|
+
if (!scopeId || scopeId === functionType.shared.typeVarScopeId) {
|
1251
1366
|
return;
|
1252
1367
|
}
|
1253
|
-
if (!functionType.
|
1254
|
-
functionType.
|
1368
|
+
if (!functionType.priv.higherOrderTypeVarScopeIds.some((id) => id === scopeId)) {
|
1369
|
+
functionType.priv.higherOrderTypeVarScopeIds.push(scopeId);
|
1255
1370
|
}
|
1256
1371
|
});
|
1257
1372
|
}
|
1258
1373
|
FunctionType.addHigherOrderTypeVarScopeIds = addHigherOrderTypeVarScopeIds;
|
1259
1374
|
function getDefaultParameters(useUnknown = false) {
|
1260
1375
|
return [
|
1261
|
-
|
1262
|
-
|
1263
|
-
name: 'args',
|
1264
|
-
type: useUnknown ? UnknownType.create() : AnyType.create(),
|
1265
|
-
hasDeclaredType: !useUnknown,
|
1266
|
-
},
|
1267
|
-
{
|
1268
|
-
category: 2 /* ParameterCategory.KwargsDict */,
|
1269
|
-
name: 'kwargs',
|
1270
|
-
type: useUnknown ? UnknownType.create() : AnyType.create(),
|
1271
|
-
hasDeclaredType: !useUnknown,
|
1272
|
-
},
|
1376
|
+
FunctionParam.create(1 /* ParameterCategory.ArgsList */, useUnknown ? UnknownType.create() : AnyType.create(), useUnknown ? FunctionParamFlags.None : FunctionParamFlags.TypeDeclared, 'args'),
|
1377
|
+
FunctionParam.create(2 /* ParameterCategory.KwargsDict */, useUnknown ? UnknownType.create() : AnyType.create(), useUnknown ? FunctionParamFlags.None : FunctionParamFlags.TypeDeclared, 'kwargs'),
|
1273
1378
|
];
|
1274
1379
|
}
|
1275
1380
|
FunctionType.getDefaultParameters = getDefaultParameters;
|
@@ -1277,8 +1382,8 @@ var FunctionType;
|
|
1277
1382
|
function hasDefaultParameters(functionType) {
|
1278
1383
|
let sawArgs = false;
|
1279
1384
|
let sawKwargs = false;
|
1280
|
-
for (let i = 0; i < functionType.
|
1281
|
-
const param = functionType.
|
1385
|
+
for (let i = 0; i < functionType.shared.parameters.length; i++) {
|
1386
|
+
const param = functionType.shared.parameters[i];
|
1282
1387
|
// Ignore nameless separator parameters.
|
1283
1388
|
if (!param.name) {
|
1284
1389
|
continue;
|
@@ -1300,7 +1405,7 @@ var FunctionType;
|
|
1300
1405
|
}
|
1301
1406
|
FunctionType.hasDefaultParameters = hasDefaultParameters;
|
1302
1407
|
function isInstanceMethod(type) {
|
1303
|
-
return ((type.
|
1408
|
+
return ((type.shared.flags &
|
1304
1409
|
(1 /* FunctionTypeFlags.ConstructorMethod */ |
|
1305
1410
|
4 /* FunctionTypeFlags.StaticMethod */ |
|
1306
1411
|
2 /* FunctionTypeFlags.ClassMethod */)) ===
|
@@ -1308,128 +1413,134 @@ var FunctionType;
|
|
1308
1413
|
}
|
1309
1414
|
FunctionType.isInstanceMethod = isInstanceMethod;
|
1310
1415
|
function isConstructorMethod(type) {
|
1311
|
-
return (type.
|
1416
|
+
return (type.shared.flags & 1 /* FunctionTypeFlags.ConstructorMethod */) !== 0;
|
1312
1417
|
}
|
1313
1418
|
FunctionType.isConstructorMethod = isConstructorMethod;
|
1314
1419
|
function isStaticMethod(type) {
|
1315
|
-
return (type.
|
1420
|
+
return (type.shared.flags & 4 /* FunctionTypeFlags.StaticMethod */) !== 0;
|
1316
1421
|
}
|
1317
1422
|
FunctionType.isStaticMethod = isStaticMethod;
|
1318
1423
|
function isClassMethod(type) {
|
1319
|
-
return (type.
|
1424
|
+
return (type.shared.flags & 2 /* FunctionTypeFlags.ClassMethod */) !== 0;
|
1320
1425
|
}
|
1321
1426
|
FunctionType.isClassMethod = isClassMethod;
|
1322
1427
|
function isAbstractMethod(type) {
|
1323
|
-
return (type.
|
1428
|
+
return (type.shared.flags & 8 /* FunctionTypeFlags.AbstractMethod */) !== 0;
|
1324
1429
|
}
|
1325
1430
|
FunctionType.isAbstractMethod = isAbstractMethod;
|
1326
1431
|
function isGenerator(type) {
|
1327
|
-
return (type.
|
1432
|
+
return (type.shared.flags & 16 /* FunctionTypeFlags.Generator */) !== 0;
|
1328
1433
|
}
|
1329
1434
|
FunctionType.isGenerator = isGenerator;
|
1330
1435
|
function isSynthesizedMethod(type) {
|
1331
|
-
return (type.
|
1436
|
+
return (type.shared.flags & 64 /* FunctionTypeFlags.SynthesizedMethod */) !== 0;
|
1332
1437
|
}
|
1333
1438
|
FunctionType.isSynthesizedMethod = isSynthesizedMethod;
|
1334
1439
|
function isTypeCheckOnly(type) {
|
1335
|
-
return (type.
|
1440
|
+
return (type.shared.flags & 128 /* FunctionTypeFlags.TypeCheckOnly */) !== 0;
|
1336
1441
|
}
|
1337
1442
|
FunctionType.isTypeCheckOnly = isTypeCheckOnly;
|
1338
1443
|
function isOverloaded(type) {
|
1339
|
-
return (type.
|
1444
|
+
return (type.shared.flags & 256 /* FunctionTypeFlags.Overloaded */) !== 0;
|
1340
1445
|
}
|
1341
1446
|
FunctionType.isOverloaded = isOverloaded;
|
1342
1447
|
function isDefaultParameterCheckDisabled(type) {
|
1343
|
-
return (type.
|
1448
|
+
return (type.shared.flags & 32 /* FunctionTypeFlags.DisableDefaultChecks */) !== 0;
|
1344
1449
|
}
|
1345
1450
|
FunctionType.isDefaultParameterCheckDisabled = isDefaultParameterCheckDisabled;
|
1346
1451
|
function isAsync(type) {
|
1347
|
-
return (type.
|
1452
|
+
return (type.shared.flags & 512 /* FunctionTypeFlags.Async */) !== 0;
|
1348
1453
|
}
|
1349
1454
|
FunctionType.isAsync = isAsync;
|
1350
1455
|
function isStubDefinition(type) {
|
1351
|
-
return (type.
|
1456
|
+
return (type.shared.flags & 2048 /* FunctionTypeFlags.StubDefinition */) !== 0;
|
1352
1457
|
}
|
1353
1458
|
FunctionType.isStubDefinition = isStubDefinition;
|
1354
1459
|
function isPyTypedDefinition(type) {
|
1355
|
-
return (type.
|
1460
|
+
return (type.shared.flags & 4096 /* FunctionTypeFlags.PyTypedDefinition */) !== 0;
|
1356
1461
|
}
|
1357
1462
|
FunctionType.isPyTypedDefinition = isPyTypedDefinition;
|
1358
1463
|
function isFinal(type) {
|
1359
|
-
return (type.
|
1464
|
+
return (type.shared.flags & 8192 /* FunctionTypeFlags.Final */) !== 0;
|
1360
1465
|
}
|
1361
1466
|
FunctionType.isFinal = isFinal;
|
1362
1467
|
function hasUnannotatedParams(type) {
|
1363
|
-
return (type.
|
1468
|
+
return (type.shared.flags & 16384 /* FunctionTypeFlags.UnannotatedParams */) !== 0;
|
1364
1469
|
}
|
1365
1470
|
FunctionType.hasUnannotatedParams = hasUnannotatedParams;
|
1366
1471
|
function isGradualCallableForm(type) {
|
1367
|
-
return (type.
|
1472
|
+
return (type.shared.flags & 32768 /* FunctionTypeFlags.GradualCallableForm */) !== 0;
|
1368
1473
|
}
|
1369
1474
|
FunctionType.isGradualCallableForm = isGradualCallableForm;
|
1370
1475
|
function isParamSpecValue(type) {
|
1371
|
-
return (type.
|
1476
|
+
return (type.shared.flags & 65536 /* FunctionTypeFlags.ParamSpecValue */) !== 0;
|
1372
1477
|
}
|
1373
1478
|
FunctionType.isParamSpecValue = isParamSpecValue;
|
1374
1479
|
function isPartiallyEvaluated(type) {
|
1375
|
-
return !!(type.
|
1480
|
+
return !!(type.shared.flags & 131072 /* FunctionTypeFlags.PartiallyEvaluated */);
|
1376
1481
|
}
|
1377
1482
|
FunctionType.isPartiallyEvaluated = isPartiallyEvaluated;
|
1378
1483
|
function isOverridden(type) {
|
1379
|
-
return !!(type.
|
1484
|
+
return !!(type.shared.flags & 262144 /* FunctionTypeFlags.Overridden */);
|
1380
1485
|
}
|
1381
1486
|
FunctionType.isOverridden = isOverridden;
|
1487
|
+
function isBuiltIn(type, name) {
|
1488
|
+
if (!(type.shared.flags & 1048576 /* FunctionTypeFlags.BuiltIn */)) {
|
1489
|
+
return false;
|
1490
|
+
}
|
1491
|
+
if (name !== undefined) {
|
1492
|
+
const functionArray = Array.isArray(name) ? name : [name];
|
1493
|
+
return functionArray.some((name) => name === type.shared.name);
|
1494
|
+
}
|
1495
|
+
return true;
|
1496
|
+
}
|
1497
|
+
FunctionType.isBuiltIn = isBuiltIn;
|
1382
1498
|
function getEffectiveParameterType(type, index) {
|
1383
|
-
(0, debug_1.assert)(index < type.
|
1384
|
-
if (type.specializedTypes && index < type.specializedTypes.parameterTypes.length) {
|
1385
|
-
return type.specializedTypes.parameterTypes[index];
|
1499
|
+
(0, debug_1.assert)(index < type.shared.parameters.length, 'Parameter types array overflow');
|
1500
|
+
if (type.priv.specializedTypes && index < type.priv.specializedTypes.parameterTypes.length) {
|
1501
|
+
return type.priv.specializedTypes.parameterTypes[index];
|
1386
1502
|
}
|
1387
|
-
return type.
|
1503
|
+
return type.shared.parameters[index].type;
|
1388
1504
|
}
|
1389
1505
|
FunctionType.getEffectiveParameterType = getEffectiveParameterType;
|
1390
1506
|
function getEffectiveParameterDefaultArgType(type, index) {
|
1391
1507
|
var _a;
|
1392
|
-
(0, debug_1.assert)(index < type.
|
1393
|
-
if (((_a = type.specializedTypes) === null || _a === void 0 ? void 0 : _a.parameterDefaultArgs) &&
|
1394
|
-
|
1508
|
+
(0, debug_1.assert)(index < type.shared.parameters.length, 'Parameter types array overflow');
|
1509
|
+
if (((_a = type.priv.specializedTypes) === null || _a === void 0 ? void 0 : _a.parameterDefaultArgs) &&
|
1510
|
+
index < type.priv.specializedTypes.parameterDefaultArgs.length) {
|
1511
|
+
const defaultArgType = type.priv.specializedTypes.parameterDefaultArgs[index];
|
1395
1512
|
if (defaultArgType) {
|
1396
1513
|
return defaultArgType;
|
1397
1514
|
}
|
1398
1515
|
}
|
1399
|
-
return type.
|
1516
|
+
return type.shared.parameters[index].defaultType;
|
1400
1517
|
}
|
1401
1518
|
FunctionType.getEffectiveParameterDefaultArgType = getEffectiveParameterDefaultArgType;
|
1402
1519
|
function addParameter(type, param) {
|
1403
|
-
type.
|
1404
|
-
if (type.specializedTypes) {
|
1405
|
-
type.specializedTypes.parameterTypes.push(param.type);
|
1520
|
+
type.shared.parameters.push(param);
|
1521
|
+
if (type.priv.specializedTypes) {
|
1522
|
+
type.priv.specializedTypes.parameterTypes.push(param.type);
|
1406
1523
|
}
|
1407
1524
|
}
|
1408
1525
|
FunctionType.addParameter = addParameter;
|
1409
1526
|
function addPositionOnlyParameterSeparator(type) {
|
1410
|
-
addParameter(type,
|
1411
|
-
category: 0 /* ParameterCategory.Simple */,
|
1412
|
-
type: AnyType.create(),
|
1413
|
-
});
|
1527
|
+
addParameter(type, FunctionParam.create(0 /* ParameterCategory.Simple */, AnyType.create()));
|
1414
1528
|
}
|
1415
1529
|
FunctionType.addPositionOnlyParameterSeparator = addPositionOnlyParameterSeparator;
|
1416
1530
|
function addKeywordOnlyParameterSeparator(type) {
|
1417
|
-
addParameter(type,
|
1418
|
-
category: 1 /* ParameterCategory.ArgsList */,
|
1419
|
-
type: AnyType.create(),
|
1420
|
-
});
|
1531
|
+
addParameter(type, FunctionParam.create(1 /* ParameterCategory.ArgsList */, AnyType.create()));
|
1421
1532
|
}
|
1422
1533
|
FunctionType.addKeywordOnlyParameterSeparator = addKeywordOnlyParameterSeparator;
|
1423
1534
|
function getEffectiveReturnType(type, includeInferred = true) {
|
1424
1535
|
var _a;
|
1425
|
-
if ((_a = type.specializedTypes) === null || _a === void 0 ? void 0 : _a.returnType) {
|
1426
|
-
return type.specializedTypes.returnType;
|
1536
|
+
if ((_a = type.priv.specializedTypes) === null || _a === void 0 ? void 0 : _a.returnType) {
|
1537
|
+
return type.priv.specializedTypes.returnType;
|
1427
1538
|
}
|
1428
|
-
if (type.
|
1429
|
-
return type.
|
1539
|
+
if (type.shared.declaredReturnType) {
|
1540
|
+
return type.shared.declaredReturnType;
|
1430
1541
|
}
|
1431
1542
|
if (includeInferred) {
|
1432
|
-
return type.inferredReturnType;
|
1543
|
+
return type.priv.inferredReturnType;
|
1433
1544
|
}
|
1434
1545
|
return undefined;
|
1435
1546
|
}
|
@@ -1440,8 +1551,13 @@ var OverloadedFunctionType;
|
|
1440
1551
|
function create(overloads) {
|
1441
1552
|
const newType = {
|
1442
1553
|
category: 5 /* TypeCategory.OverloadedFunction */,
|
1443
|
-
overloads: [],
|
1444
1554
|
flags: 2 /* TypeFlags.Instance */,
|
1555
|
+
props: undefined,
|
1556
|
+
cached: undefined,
|
1557
|
+
shared: undefined,
|
1558
|
+
priv: {
|
1559
|
+
overloads: [],
|
1560
|
+
},
|
1445
1561
|
};
|
1446
1562
|
overloads.forEach((overload) => {
|
1447
1563
|
OverloadedFunctionType.addOverload(newType, overload);
|
@@ -1451,16 +1567,16 @@ var OverloadedFunctionType;
|
|
1451
1567
|
OverloadedFunctionType.create = create;
|
1452
1568
|
// Adds a new overload or an implementation.
|
1453
1569
|
function addOverload(type, functionType) {
|
1454
|
-
functionType.overloaded = type;
|
1455
|
-
type.overloads.push(functionType);
|
1570
|
+
functionType.priv.overloaded = type;
|
1571
|
+
type.priv.overloads.push(functionType);
|
1456
1572
|
}
|
1457
1573
|
OverloadedFunctionType.addOverload = addOverload;
|
1458
1574
|
function getOverloads(type) {
|
1459
|
-
return type.overloads.filter((func) => FunctionType.isOverloaded(func));
|
1575
|
+
return type.priv.overloads.filter((func) => FunctionType.isOverloaded(func));
|
1460
1576
|
}
|
1461
1577
|
OverloadedFunctionType.getOverloads = getOverloads;
|
1462
1578
|
function getImplementation(type) {
|
1463
|
-
return type.overloads.find((func) => !FunctionType.isOverloaded(func));
|
1579
|
+
return type.priv.overloads.find((func) => !FunctionType.isOverloaded(func));
|
1464
1580
|
}
|
1465
1581
|
OverloadedFunctionType.getImplementation = getImplementation;
|
1466
1582
|
})(OverloadedFunctionType || (exports.OverloadedFunctionType = OverloadedFunctionType = {}));
|
@@ -1469,12 +1585,18 @@ var NeverType;
|
|
1469
1585
|
const _neverInstance = {
|
1470
1586
|
category: 3 /* TypeCategory.Never */,
|
1471
1587
|
flags: 2 /* TypeFlags.Instance */ | 1 /* TypeFlags.Instantiable */,
|
1472
|
-
|
1588
|
+
props: undefined,
|
1589
|
+
cached: undefined,
|
1590
|
+
shared: undefined,
|
1591
|
+
priv: { isNoReturn: false },
|
1473
1592
|
};
|
1474
1593
|
const _noReturnInstance = {
|
1475
1594
|
category: 3 /* TypeCategory.Never */,
|
1476
1595
|
flags: 2 /* TypeFlags.Instance */ | 1 /* TypeFlags.Instantiable */,
|
1477
|
-
|
1596
|
+
props: undefined,
|
1597
|
+
cached: undefined,
|
1598
|
+
shared: undefined,
|
1599
|
+
priv: { isNoReturn: true },
|
1478
1600
|
};
|
1479
1601
|
function createNever() {
|
1480
1602
|
return _neverInstance;
|
@@ -1485,11 +1607,12 @@ var NeverType;
|
|
1485
1607
|
}
|
1486
1608
|
NeverType.createNoReturn = createNoReturn;
|
1487
1609
|
function convertToInstance(type) {
|
1610
|
+
var _a;
|
1488
1611
|
// Remove the "special form" if present. Otherwise return the existing type.
|
1489
|
-
if (!type.specialForm) {
|
1612
|
+
if (!((_a = type.props) === null || _a === void 0 ? void 0 : _a.specialForm)) {
|
1490
1613
|
return type;
|
1491
1614
|
}
|
1492
|
-
return type.isNoReturn ? NeverType.createNoReturn() : NeverType.createNever();
|
1615
|
+
return type.priv.isNoReturn ? NeverType.createNoReturn() : NeverType.createNever();
|
1493
1616
|
}
|
1494
1617
|
NeverType.convertToInstance = convertToInstance;
|
1495
1618
|
})(NeverType || (exports.NeverType = NeverType = {}));
|
@@ -1497,18 +1620,27 @@ var AnyType;
|
|
1497
1620
|
(function (AnyType) {
|
1498
1621
|
const _anyInstanceSpecialForm = {
|
1499
1622
|
category: 2 /* TypeCategory.Any */,
|
1500
|
-
isEllipsis: false,
|
1501
1623
|
flags: 2 /* TypeFlags.Instance */ | 1 /* TypeFlags.Instantiable */,
|
1624
|
+
props: undefined,
|
1625
|
+
cached: undefined,
|
1626
|
+
shared: undefined,
|
1627
|
+
priv: { isEllipsis: false },
|
1502
1628
|
};
|
1503
1629
|
const _anyInstance = {
|
1504
1630
|
category: 2 /* TypeCategory.Any */,
|
1505
|
-
isEllipsis: false,
|
1506
1631
|
flags: 2 /* TypeFlags.Instance */ | 1 /* TypeFlags.Instantiable */,
|
1632
|
+
props: undefined,
|
1633
|
+
cached: undefined,
|
1634
|
+
shared: undefined,
|
1635
|
+
priv: { isEllipsis: false },
|
1507
1636
|
};
|
1508
1637
|
const _ellipsisInstance = {
|
1509
1638
|
category: 2 /* TypeCategory.Any */,
|
1510
|
-
isEllipsis: true,
|
1511
1639
|
flags: 2 /* TypeFlags.Instance */ | 1 /* TypeFlags.Instantiable */,
|
1640
|
+
props: undefined,
|
1641
|
+
cached: undefined,
|
1642
|
+
shared: undefined,
|
1643
|
+
priv: { isEllipsis: true },
|
1512
1644
|
};
|
1513
1645
|
function create(isEllipsis = false) {
|
1514
1646
|
return isEllipsis ? _ellipsisInstance : _anyInstance;
|
@@ -1521,8 +1653,9 @@ var AnyType;
|
|
1521
1653
|
})(AnyType || (exports.AnyType = AnyType = {}));
|
1522
1654
|
(function (AnyType) {
|
1523
1655
|
function convertToInstance(type) {
|
1656
|
+
var _a;
|
1524
1657
|
// Remove the "special form" if present. Otherwise return the existing type.
|
1525
|
-
return type.specialForm ? AnyType.create() : type;
|
1658
|
+
return ((_a = type.props) === null || _a === void 0 ? void 0 : _a.specialForm) ? AnyType.create() : type;
|
1526
1659
|
}
|
1527
1660
|
AnyType.convertToInstance = convertToInstance;
|
1528
1661
|
})(AnyType || (exports.AnyType = AnyType = {}));
|
@@ -1547,10 +1680,10 @@ var TypeCondition;
|
|
1547
1680
|
}
|
1548
1681
|
TypeCondition.combine = combine;
|
1549
1682
|
function _compare(c1, c2) {
|
1550
|
-
if (c1.typeVar.
|
1683
|
+
if (c1.typeVar.shared.name < c2.typeVar.shared.name) {
|
1551
1684
|
return -1;
|
1552
1685
|
}
|
1553
|
-
else if (c1.typeVar.
|
1686
|
+
else if (c1.typeVar.shared.name > c2.typeVar.shared.name) {
|
1554
1687
|
return 1;
|
1555
1688
|
}
|
1556
1689
|
if (c1.constraintIndex < c2.constraintIndex) {
|
@@ -1568,7 +1701,7 @@ var TypeCondition;
|
|
1568
1701
|
if (!conditions2 || conditions1.length !== conditions2.length) {
|
1569
1702
|
return false;
|
1570
1703
|
}
|
1571
|
-
return (conditions1.find((c1, index) => c1.typeVar.nameWithScope !== conditions2[index].typeVar.nameWithScope ||
|
1704
|
+
return (conditions1.find((c1, index) => c1.typeVar.priv.nameWithScope !== conditions2[index].typeVar.priv.nameWithScope ||
|
1572
1705
|
c1.constraintIndex !== conditions2[index].constraintIndex) === undefined);
|
1573
1706
|
}
|
1574
1707
|
TypeCondition.isSame = isSame;
|
@@ -1583,7 +1716,7 @@ var TypeCondition;
|
|
1583
1716
|
for (const c1 of conditions1) {
|
1584
1717
|
let foundTypeVarMatch = false;
|
1585
1718
|
const exactMatch = conditions2.find((c2) => {
|
1586
|
-
if (c1.typeVar.nameWithScope === c2.typeVar.nameWithScope) {
|
1719
|
+
if (c1.typeVar.priv.nameWithScope === c2.typeVar.priv.nameWithScope) {
|
1587
1720
|
foundTypeVarMatch = true;
|
1588
1721
|
return c1.constraintIndex === c2.constraintIndex;
|
1589
1722
|
}
|
@@ -1602,46 +1735,64 @@ var UnionType;
|
|
1602
1735
|
function create() {
|
1603
1736
|
const newUnionType = {
|
1604
1737
|
category: 8 /* TypeCategory.Union */,
|
1605
|
-
subtypes: [],
|
1606
|
-
literalInstances: {},
|
1607
|
-
literalClasses: {},
|
1608
1738
|
flags: 2 /* TypeFlags.Instance */ | 1 /* TypeFlags.Instantiable */,
|
1739
|
+
props: undefined,
|
1740
|
+
cached: undefined,
|
1741
|
+
shared: undefined,
|
1742
|
+
priv: {
|
1743
|
+
subtypes: [],
|
1744
|
+
literalInstances: {
|
1745
|
+
literalStrMap: undefined,
|
1746
|
+
literalIntMap: undefined,
|
1747
|
+
literalEnumMap: undefined,
|
1748
|
+
},
|
1749
|
+
literalClasses: {
|
1750
|
+
literalStrMap: undefined,
|
1751
|
+
literalIntMap: undefined,
|
1752
|
+
literalEnumMap: undefined,
|
1753
|
+
},
|
1754
|
+
typeAliasSources: undefined,
|
1755
|
+
includesRecursiveTypeAlias: false,
|
1756
|
+
},
|
1609
1757
|
};
|
1610
1758
|
return newUnionType;
|
1611
1759
|
}
|
1612
1760
|
UnionType.create = create;
|
1613
1761
|
function addType(unionType, newType) {
|
1762
|
+
var _a, _b;
|
1614
1763
|
// If we're adding a string, integer or enum literal, add it to the
|
1615
1764
|
// corresponding literal map to speed up some operations. It's not
|
1616
1765
|
// uncommon for unions to contain hundreds of literals.
|
1617
|
-
if (isClass(newType) && newType.literalValue !== undefined && newType.
|
1618
|
-
const literalMaps = isClassInstance(newType)
|
1766
|
+
if (isClass(newType) && newType.priv.literalValue !== undefined && !((_a = newType.props) === null || _a === void 0 ? void 0 : _a.condition)) {
|
1767
|
+
const literalMaps = isClassInstance(newType)
|
1768
|
+
? unionType.priv.literalInstances
|
1769
|
+
: unionType.priv.literalClasses;
|
1619
1770
|
if (ClassType.isBuiltIn(newType, 'str')) {
|
1620
1771
|
if (literalMaps.literalStrMap === undefined) {
|
1621
1772
|
literalMaps.literalStrMap = new Map();
|
1622
1773
|
}
|
1623
|
-
literalMaps.literalStrMap.set(newType.literalValue, newType);
|
1774
|
+
literalMaps.literalStrMap.set(newType.priv.literalValue, newType);
|
1624
1775
|
}
|
1625
1776
|
else if (ClassType.isBuiltIn(newType, 'int')) {
|
1626
1777
|
if (literalMaps.literalIntMap === undefined) {
|
1627
1778
|
literalMaps.literalIntMap = new Map();
|
1628
1779
|
}
|
1629
|
-
literalMaps.literalIntMap.set(newType.literalValue, newType);
|
1780
|
+
literalMaps.literalIntMap.set(newType.priv.literalValue, newType);
|
1630
1781
|
}
|
1631
1782
|
else if (ClassType.isEnumClass(newType)) {
|
1632
1783
|
if (literalMaps.literalEnumMap === undefined) {
|
1633
1784
|
literalMaps.literalEnumMap = new Map();
|
1634
1785
|
}
|
1635
|
-
const enumLiteral = newType.literalValue;
|
1786
|
+
const enumLiteral = newType.priv.literalValue;
|
1636
1787
|
literalMaps.literalEnumMap.set(enumLiteral.getName(), newType);
|
1637
1788
|
}
|
1638
1789
|
}
|
1639
1790
|
unionType.flags &= newType.flags;
|
1640
|
-
unionType.subtypes.push(newType);
|
1641
|
-
if (isTypeVar(newType) && newType.
|
1791
|
+
unionType.priv.subtypes.push(newType);
|
1792
|
+
if (isTypeVar(newType) && ((_b = newType.shared.recursiveAlias) === null || _b === void 0 ? void 0 : _b.name)) {
|
1642
1793
|
// Note that at least one recursive type alias was included in
|
1643
1794
|
// this union. We'll need to expand it before the union is used.
|
1644
|
-
unionType.includesRecursiveTypeAlias = true;
|
1795
|
+
unionType.priv.includesRecursiveTypeAlias = true;
|
1645
1796
|
}
|
1646
1797
|
}
|
1647
1798
|
UnionType.addType = addType;
|
@@ -1649,22 +1800,25 @@ var UnionType;
|
|
1649
1800
|
// the method skips any subtype indexes that are in the set and adds a found index to
|
1650
1801
|
// the exclusion set. This speeds up union type comparisons.
|
1651
1802
|
function containsType(unionType, subtype, exclusionSet, recursionCount = 0) {
|
1803
|
+
var _a;
|
1652
1804
|
// Handle string literals as a special case because unions can sometimes
|
1653
1805
|
// contain hundreds of string literal types.
|
1654
|
-
if (isClass(subtype) && subtype.condition === undefined && subtype.literalValue !== undefined) {
|
1655
|
-
const literalMaps = isClassInstance(subtype)
|
1806
|
+
if (isClass(subtype) && ((_a = subtype.props) === null || _a === void 0 ? void 0 : _a.condition) === undefined && subtype.priv.literalValue !== undefined) {
|
1807
|
+
const literalMaps = isClassInstance(subtype)
|
1808
|
+
? unionType.priv.literalInstances
|
1809
|
+
: unionType.priv.literalClasses;
|
1656
1810
|
if (ClassType.isBuiltIn(subtype, 'str') && literalMaps.literalStrMap !== undefined) {
|
1657
|
-
return literalMaps.literalStrMap.has(subtype.literalValue);
|
1811
|
+
return literalMaps.literalStrMap.has(subtype.priv.literalValue);
|
1658
1812
|
}
|
1659
1813
|
else if (ClassType.isBuiltIn(subtype, 'int') && literalMaps.literalIntMap !== undefined) {
|
1660
|
-
return literalMaps.literalIntMap.has(subtype.literalValue);
|
1814
|
+
return literalMaps.literalIntMap.has(subtype.priv.literalValue);
|
1661
1815
|
}
|
1662
1816
|
else if (ClassType.isEnumClass(subtype) && literalMaps.literalEnumMap !== undefined) {
|
1663
|
-
const enumLiteral = subtype.literalValue;
|
1817
|
+
const enumLiteral = subtype.priv.literalValue;
|
1664
1818
|
return literalMaps.literalEnumMap.has(enumLiteral.getName());
|
1665
1819
|
}
|
1666
1820
|
}
|
1667
|
-
const foundIndex = unionType.subtypes.findIndex((t, i) => {
|
1821
|
+
const foundIndex = unionType.priv.subtypes.findIndex((t, i) => {
|
1668
1822
|
if (exclusionSet === null || exclusionSet === void 0 ? void 0 : exclusionSet.has(i)) {
|
1669
1823
|
return false;
|
1670
1824
|
}
|
@@ -1678,14 +1832,17 @@ var UnionType;
|
|
1678
1832
|
}
|
1679
1833
|
UnionType.containsType = containsType;
|
1680
1834
|
function addTypeAliasSource(unionType, typeAliasSource) {
|
1835
|
+
var _a;
|
1681
1836
|
if (typeAliasSource.category === 8 /* TypeCategory.Union */) {
|
1682
|
-
const sourcesToAdd = typeAliasSource.
|
1837
|
+
const sourcesToAdd = ((_a = typeAliasSource.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo)
|
1838
|
+
? [typeAliasSource]
|
1839
|
+
: typeAliasSource.priv.typeAliasSources;
|
1683
1840
|
if (sourcesToAdd) {
|
1684
|
-
if (!unionType.typeAliasSources) {
|
1685
|
-
unionType.typeAliasSources = new Set();
|
1841
|
+
if (!unionType.priv.typeAliasSources) {
|
1842
|
+
unionType.priv.typeAliasSources = new Set();
|
1686
1843
|
}
|
1687
1844
|
sourcesToAdd.forEach((source) => {
|
1688
|
-
unionType.typeAliasSources.add(source);
|
1845
|
+
unionType.priv.typeAliasSources.add(source);
|
1689
1846
|
});
|
1690
1847
|
}
|
1691
1848
|
}
|
@@ -1717,13 +1874,15 @@ var TypeVarType;
|
|
1717
1874
|
}
|
1718
1875
|
TypeVarType.createInstantiable = createInstantiable;
|
1719
1876
|
function cloneAsInstance(type) {
|
1720
|
-
var _a;
|
1877
|
+
var _a, _b;
|
1721
1878
|
(0, debug_1.assert)(TypeBase.isInstantiable(type));
|
1722
1879
|
if ((_a = type.cached) === null || _a === void 0 ? void 0 : _a.typeBaseInstanceType) {
|
1723
1880
|
return type.cached.typeBaseInstanceType;
|
1724
1881
|
}
|
1725
1882
|
const newInstance = TypeBase.cloneTypeAsInstance(type, /* cache */ true);
|
1726
|
-
|
1883
|
+
if ((_b = newInstance.props) === null || _b === void 0 ? void 0 : _b.specialForm) {
|
1884
|
+
TypeBase.setSpecialForm(newInstance, undefined);
|
1885
|
+
}
|
1727
1886
|
return newInstance;
|
1728
1887
|
}
|
1729
1888
|
TypeVarType.cloneAsInstance = cloneAsInstance;
|
@@ -1738,36 +1897,36 @@ var TypeVarType;
|
|
1738
1897
|
TypeVarType.cloneAsInstantiable = cloneAsInstantiable;
|
1739
1898
|
function cloneForNewName(type, name) {
|
1740
1899
|
const newInstance = TypeBase.cloneType(type);
|
1741
|
-
newInstance.
|
1742
|
-
newInstance.
|
1743
|
-
if (newInstance.scopeId) {
|
1744
|
-
newInstance.nameWithScope = makeNameWithScope(name, newInstance.scopeId);
|
1900
|
+
newInstance.shared = { ...type.shared };
|
1901
|
+
newInstance.shared.name = name;
|
1902
|
+
if (newInstance.priv.scopeId) {
|
1903
|
+
newInstance.priv.nameWithScope = makeNameWithScope(name, newInstance.priv.scopeId);
|
1745
1904
|
}
|
1746
1905
|
return newInstance;
|
1747
1906
|
}
|
1748
1907
|
TypeVarType.cloneForNewName = cloneForNewName;
|
1749
1908
|
function cloneForScopeId(type, scopeId, scopeName, scopeType) {
|
1750
1909
|
const newInstance = TypeBase.cloneType(type);
|
1751
|
-
newInstance.nameWithScope = makeNameWithScope(type.
|
1752
|
-
newInstance.scopeId = scopeId;
|
1753
|
-
newInstance.scopeName = scopeName;
|
1754
|
-
newInstance.scopeType = scopeType;
|
1910
|
+
newInstance.priv.nameWithScope = makeNameWithScope(type.shared.name, scopeId);
|
1911
|
+
newInstance.priv.scopeId = scopeId;
|
1912
|
+
newInstance.priv.scopeName = scopeName;
|
1913
|
+
newInstance.priv.scopeType = scopeType;
|
1755
1914
|
return newInstance;
|
1756
1915
|
}
|
1757
1916
|
TypeVarType.cloneForScopeId = cloneForScopeId;
|
1758
1917
|
function cloneForUnpacked(type, isInUnion = false) {
|
1759
|
-
(0, debug_1.assert)(type.
|
1918
|
+
(0, debug_1.assert)(type.shared.isVariadic);
|
1760
1919
|
const newInstance = TypeBase.cloneType(type);
|
1761
|
-
newInstance.isVariadicUnpacked = true;
|
1762
|
-
newInstance.isVariadicInUnion = isInUnion;
|
1920
|
+
newInstance.priv.isVariadicUnpacked = true;
|
1921
|
+
newInstance.priv.isVariadicInUnion = isInUnion;
|
1763
1922
|
return newInstance;
|
1764
1923
|
}
|
1765
1924
|
TypeVarType.cloneForUnpacked = cloneForUnpacked;
|
1766
1925
|
function cloneForPacked(type) {
|
1767
|
-
(0, debug_1.assert)(type.
|
1926
|
+
(0, debug_1.assert)(type.shared.isVariadic);
|
1768
1927
|
const newInstance = TypeBase.cloneType(type);
|
1769
|
-
newInstance.isVariadicUnpacked = false;
|
1770
|
-
newInstance.isVariadicInUnion = false;
|
1928
|
+
newInstance.priv.isVariadicUnpacked = false;
|
1929
|
+
newInstance.priv.isVariadicInUnion = false;
|
1771
1930
|
return newInstance;
|
1772
1931
|
}
|
1773
1932
|
TypeVarType.cloneForPacked = cloneForPacked;
|
@@ -1775,55 +1934,55 @@ var TypeVarType;
|
|
1775
1934
|
// and no bound or constraints. ParamSpecs and variadics are left
|
1776
1935
|
// unmodified. So are auto-variant type variables.
|
1777
1936
|
function cloneAsInvariant(type) {
|
1778
|
-
if (type.
|
1937
|
+
if (type.shared.isParamSpec || type.shared.isVariadic) {
|
1779
1938
|
return type;
|
1780
1939
|
}
|
1781
|
-
if (type.
|
1940
|
+
if (type.shared.declaredVariance === 0 /* Variance.Auto */) {
|
1782
1941
|
return type;
|
1783
1942
|
}
|
1784
|
-
if (type.
|
1785
|
-
if (type.
|
1943
|
+
if (type.shared.declaredVariance === 2 /* Variance.Invariant */) {
|
1944
|
+
if (type.shared.boundType === undefined && type.shared.constraints.length === 0) {
|
1786
1945
|
return type;
|
1787
1946
|
}
|
1788
1947
|
}
|
1789
1948
|
const newInstance = TypeBase.cloneType(type);
|
1790
|
-
newInstance.
|
1791
|
-
newInstance.
|
1792
|
-
newInstance.
|
1793
|
-
newInstance.
|
1949
|
+
newInstance.shared = { ...newInstance.shared };
|
1950
|
+
newInstance.shared.declaredVariance = 2 /* Variance.Invariant */;
|
1951
|
+
newInstance.shared.boundType = undefined;
|
1952
|
+
newInstance.shared.constraints = [];
|
1794
1953
|
return newInstance;
|
1795
1954
|
}
|
1796
1955
|
TypeVarType.cloneAsInvariant = cloneAsInvariant;
|
1797
1956
|
function cloneForParamSpecAccess(type, access) {
|
1798
1957
|
const newInstance = TypeBase.cloneType(type);
|
1799
|
-
newInstance.paramSpecAccess = access;
|
1958
|
+
newInstance.priv.paramSpecAccess = access;
|
1800
1959
|
return newInstance;
|
1801
1960
|
}
|
1802
1961
|
TypeVarType.cloneForParamSpecAccess = cloneForParamSpecAccess;
|
1803
1962
|
function cloneAsSpecializedSelf(type, specializedBoundType) {
|
1804
|
-
(0, debug_1.assert)(type.
|
1963
|
+
(0, debug_1.assert)(type.shared.isSynthesizedSelf);
|
1805
1964
|
const newInstance = TypeBase.cloneType(type);
|
1806
|
-
newInstance.
|
1807
|
-
newInstance.
|
1965
|
+
newInstance.shared = { ...newInstance.shared };
|
1966
|
+
newInstance.shared.boundType = specializedBoundType;
|
1808
1967
|
return newInstance;
|
1809
1968
|
}
|
1810
1969
|
TypeVarType.cloneAsSpecializedSelf = cloneAsSpecializedSelf;
|
1811
1970
|
function cloneAsInScopePlaceholder(type, usageOffset) {
|
1812
|
-
if (type.isInScopePlaceholder) {
|
1971
|
+
if (type.priv.isInScopePlaceholder) {
|
1813
1972
|
return type;
|
1814
1973
|
}
|
1815
1974
|
// If the caller specified a usage offset, append it to the TypeVar
|
1816
1975
|
// internal name. This allows us to distinguish it from other uses
|
1817
1976
|
// of the same TypeVar. For example nested calls to a generic
|
1818
1977
|
// function like `foo(foo(1))`.
|
1819
|
-
let newNameWithScope = type.nameWithScope;
|
1978
|
+
let newNameWithScope = type.priv.nameWithScope;
|
1820
1979
|
if (usageOffset) {
|
1821
|
-
newNameWithScope = `${type.nameWithScope}-${usageOffset}`;
|
1980
|
+
newNameWithScope = `${type.priv.nameWithScope}-${usageOffset}`;
|
1822
1981
|
}
|
1823
1982
|
const newInstance = TypeBase.cloneType(type);
|
1824
|
-
newInstance.isInScopePlaceholder = true;
|
1825
|
-
newInstance.scopeId = exports.InScopePlaceholderScopeId;
|
1826
|
-
newInstance.nameWithScope = newNameWithScope;
|
1983
|
+
newInstance.priv.isInScopePlaceholder = true;
|
1984
|
+
newInstance.priv.scopeId = exports.InScopePlaceholderScopeId;
|
1985
|
+
newInstance.priv.nameWithScope = newNameWithScope;
|
1827
1986
|
return newInstance;
|
1828
1987
|
}
|
1829
1988
|
TypeVarType.cloneAsInScopePlaceholder = cloneAsInScopePlaceholder;
|
@@ -1834,38 +1993,48 @@ var TypeVarType;
|
|
1834
1993
|
function create(name, isParamSpec, typeFlags) {
|
1835
1994
|
const newTypeVarType = {
|
1836
1995
|
category: 9 /* TypeCategory.TypeVar */,
|
1837
|
-
|
1996
|
+
flags: typeFlags,
|
1997
|
+
props: undefined,
|
1998
|
+
cached: undefined,
|
1999
|
+
shared: {
|
1838
2000
|
name,
|
1839
2001
|
constraints: [],
|
1840
|
-
|
2002
|
+
boundType: undefined,
|
2003
|
+
isDefaultExplicit: false,
|
2004
|
+
defaultType: UnknownType.create(),
|
1841
2005
|
isParamSpec,
|
1842
2006
|
isVariadic: false,
|
2007
|
+
declaredVariance: 2 /* Variance.Invariant */,
|
1843
2008
|
isSynthesized: false,
|
1844
|
-
|
2009
|
+
isSynthesizedSelf: false,
|
2010
|
+
synthesizedIndex: undefined,
|
2011
|
+
isExemptFromBoundCheck: false,
|
2012
|
+
isTypeParamSyntax: false,
|
2013
|
+
recursiveAlias: undefined,
|
1845
2014
|
},
|
1846
|
-
|
2015
|
+
priv: {},
|
1847
2016
|
};
|
1848
2017
|
return newTypeVarType;
|
1849
2018
|
}
|
1850
2019
|
function addConstraint(typeVarType, constraintType) {
|
1851
|
-
typeVarType.
|
2020
|
+
typeVarType.shared.constraints.push(constraintType);
|
1852
2021
|
}
|
1853
2022
|
TypeVarType.addConstraint = addConstraint;
|
1854
2023
|
function getNameWithScope(typeVarType) {
|
1855
2024
|
// If there is no name with scope, fall back on the (unscoped) name.
|
1856
|
-
return typeVarType.nameWithScope || typeVarType.
|
2025
|
+
return typeVarType.priv.nameWithScope || typeVarType.shared.name;
|
1857
2026
|
}
|
1858
2027
|
TypeVarType.getNameWithScope = getNameWithScope;
|
1859
2028
|
function getReadableName(typeVarType) {
|
1860
|
-
if (typeVarType.scopeName) {
|
1861
|
-
return `${typeVarType.
|
2029
|
+
if (typeVarType.priv.scopeName) {
|
2030
|
+
return `${typeVarType.shared.name}@${typeVarType.priv.scopeName}`;
|
1862
2031
|
}
|
1863
|
-
return typeVarType.
|
2032
|
+
return typeVarType.shared.name;
|
1864
2033
|
}
|
1865
2034
|
TypeVarType.getReadableName = getReadableName;
|
1866
2035
|
function getVariance(type) {
|
1867
2036
|
var _a;
|
1868
|
-
const variance = (_a = type.computedVariance) !== null && _a !== void 0 ? _a : type.
|
2037
|
+
const variance = (_a = type.priv.computedVariance) !== null && _a !== void 0 ? _a : type.shared.declaredVariance;
|
1869
2038
|
// By this point, the variance should have been inferred.
|
1870
2039
|
(0, debug_1.assert)(variance !== 0 /* Variance.Auto */, 'Expected variance to be inferred');
|
1871
2040
|
// If we're in the process of computing variance, it will still be
|
@@ -1879,7 +2048,7 @@ var TypeVarType;
|
|
1879
2048
|
// Indicates whether the specified type is a recursive type alias
|
1880
2049
|
// placeholder that has not yet been resolved.
|
1881
2050
|
function isTypeAliasPlaceholder(type) {
|
1882
|
-
return !!type.
|
2051
|
+
return !!type.shared.recursiveAlias && !type.shared.boundType;
|
1883
2052
|
}
|
1884
2053
|
TypeVarType.isTypeAliasPlaceholder = isTypeAliasPlaceholder;
|
1885
2054
|
})(TypeVarType || (exports.TypeVarType = TypeVarType = {}));
|
@@ -1900,7 +2069,7 @@ function isAnyOrUnknown(type) {
|
|
1900
2069
|
return true;
|
1901
2070
|
}
|
1902
2071
|
if (isUnion(type)) {
|
1903
|
-
return type.subtypes.find((subtype) => !isAnyOrUnknown(subtype)) === undefined;
|
2072
|
+
return type.priv.subtypes.find((subtype) => !isAnyOrUnknown(subtype)) === undefined;
|
1904
2073
|
}
|
1905
2074
|
return false;
|
1906
2075
|
}
|
@@ -1918,7 +2087,7 @@ function isPossiblyUnbound(type) {
|
|
1918
2087
|
return true;
|
1919
2088
|
}
|
1920
2089
|
if (isUnion(type)) {
|
1921
|
-
return type.subtypes.find((subtype) => isPossiblyUnbound(subtype)) !== undefined;
|
2090
|
+
return type.priv.subtypes.find((subtype) => isPossiblyUnbound(subtype)) !== undefined;
|
1922
2091
|
}
|
1923
2092
|
return false;
|
1924
2093
|
}
|
@@ -1944,18 +2113,18 @@ function isTypeVar(type) {
|
|
1944
2113
|
}
|
1945
2114
|
exports.isTypeVar = isTypeVar;
|
1946
2115
|
function isVariadicTypeVar(type) {
|
1947
|
-
return type.category === 9 /* TypeCategory.TypeVar */ && type.
|
2116
|
+
return type.category === 9 /* TypeCategory.TypeVar */ && type.shared.isVariadic;
|
1948
2117
|
}
|
1949
2118
|
exports.isVariadicTypeVar = isVariadicTypeVar;
|
1950
2119
|
function isUnpackedVariadicTypeVar(type) {
|
1951
2120
|
return (type.category === 9 /* TypeCategory.TypeVar */ &&
|
1952
|
-
type.
|
1953
|
-
!!type.isVariadicUnpacked &&
|
1954
|
-
!type.isVariadicInUnion);
|
2121
|
+
type.shared.isVariadic &&
|
2122
|
+
!!type.priv.isVariadicUnpacked &&
|
2123
|
+
!type.priv.isVariadicInUnion);
|
1955
2124
|
}
|
1956
2125
|
exports.isUnpackedVariadicTypeVar = isUnpackedVariadicTypeVar;
|
1957
2126
|
function isUnpackedClass(type) {
|
1958
|
-
if (!isClass(type) || !type.isUnpacked) {
|
2127
|
+
if (!isClass(type) || !type.priv.isUnpacked) {
|
1959
2128
|
return false;
|
1960
2129
|
}
|
1961
2130
|
return true;
|
@@ -1966,7 +2135,7 @@ function isUnpacked(type) {
|
|
1966
2135
|
}
|
1967
2136
|
exports.isUnpacked = isUnpacked;
|
1968
2137
|
function isParamSpec(type) {
|
1969
|
-
return type.category === 9 /* TypeCategory.TypeVar */ && type.
|
2138
|
+
return type.category === 9 /* TypeCategory.TypeVar */ && type.shared.isParamSpec;
|
1970
2139
|
}
|
1971
2140
|
exports.isParamSpec = isParamSpec;
|
1972
2141
|
function isFunction(type) {
|
@@ -1978,14 +2147,15 @@ function isOverloadedFunction(type) {
|
|
1978
2147
|
}
|
1979
2148
|
exports.isOverloadedFunction = isOverloadedFunction;
|
1980
2149
|
function getTypeAliasInfo(type) {
|
1981
|
-
|
1982
|
-
|
2150
|
+
var _a, _b;
|
2151
|
+
if ((_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) {
|
2152
|
+
return type.props.typeAliasInfo;
|
1983
2153
|
}
|
1984
2154
|
if (isTypeVar(type) &&
|
1985
|
-
type.
|
1986
|
-
type.
|
1987
|
-
type.
|
1988
|
-
return type.
|
2155
|
+
type.shared.recursiveAlias &&
|
2156
|
+
type.shared.boundType &&
|
2157
|
+
((_b = type.shared.boundType.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo)) {
|
2158
|
+
return type.shared.boundType.props.typeAliasInfo;
|
1989
2159
|
}
|
1990
2160
|
return undefined;
|
1991
2161
|
}
|
@@ -1994,7 +2164,7 @@ exports.getTypeAliasInfo = getTypeAliasInfo;
|
|
1994
2164
|
// type arguments for "pseudo-generic" classes (non-generic classes whose init
|
1995
2165
|
// methods are not annotated and are therefore treated as generic) are ignored.
|
1996
2166
|
function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
1997
|
-
var _a, _b;
|
2167
|
+
var _a, _b, _c, _d, _e, _f;
|
1998
2168
|
if (type1 === type2) {
|
1999
2169
|
return true;
|
2000
2170
|
}
|
@@ -2010,7 +2180,7 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2010
2180
|
return false;
|
2011
2181
|
}
|
2012
2182
|
if (!options.ignoreTypeFlags) {
|
2013
|
-
if (type1.flags !== type2.flags) {
|
2183
|
+
if ((type1.flags & 3 /* TypeFlags.TypeCompatibilityMask */) !== (type2.flags & 3 /* TypeFlags.TypeCompatibilityMask */)) {
|
2014
2184
|
return false;
|
2015
2185
|
}
|
2016
2186
|
}
|
@@ -2025,14 +2195,14 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2025
2195
|
if (!ClassType.isSameGenericClass(type1, classType2, recursionCount)) {
|
2026
2196
|
return false;
|
2027
2197
|
}
|
2028
|
-
if (!options.ignoreConditions && !TypeCondition.isSame(type1.condition, type2.condition)) {
|
2198
|
+
if (!options.ignoreConditions && !TypeCondition.isSame((_a = type1.props) === null || _a === void 0 ? void 0 : _a.condition, (_b = type2.props) === null || _b === void 0 ? void 0 : _b.condition)) {
|
2029
2199
|
return false;
|
2030
2200
|
}
|
2031
2201
|
if (!options.ignorePseudoGeneric || !ClassType.isPseudoGenericClass(type1)) {
|
2032
2202
|
// Make sure the type args match.
|
2033
|
-
if (type1.tupleTypeArguments && classType2.tupleTypeArguments) {
|
2034
|
-
const type1TupleTypeArgs = type1.tupleTypeArguments || [];
|
2035
|
-
const type2TupleTypeArgs = classType2.tupleTypeArguments || [];
|
2203
|
+
if (type1.priv.tupleTypeArguments && classType2.priv.tupleTypeArguments) {
|
2204
|
+
const type1TupleTypeArgs = type1.priv.tupleTypeArguments || [];
|
2205
|
+
const type2TupleTypeArgs = classType2.priv.tupleTypeArguments || [];
|
2036
2206
|
if (type1TupleTypeArgs.length !== type2TupleTypeArgs.length) {
|
2037
2207
|
return false;
|
2038
2208
|
}
|
@@ -2046,8 +2216,8 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2046
2216
|
}
|
2047
2217
|
}
|
2048
2218
|
else {
|
2049
|
-
const type1TypeArgs = type1.typeArguments || [];
|
2050
|
-
const type2TypeArgs = classType2.typeArguments || [];
|
2219
|
+
const type1TypeArgs = type1.priv.typeArguments || [];
|
2220
|
+
const type2TypeArgs = classType2.priv.typeArguments || [];
|
2051
2221
|
const typeArgCount = Math.max(type1TypeArgs.length, type2TypeArgs.length);
|
2052
2222
|
for (let i = 0; i < typeArgCount; i++) {
|
2053
2223
|
// Assume that missing type args are "Unknown".
|
@@ -2062,7 +2232,7 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2062
2232
|
if (!ClassType.isLiteralValueSame(type1, classType2)) {
|
2063
2233
|
return false;
|
2064
2234
|
}
|
2065
|
-
if (!type1.isTypedDictPartial !== !classType2.isTypedDictPartial) {
|
2235
|
+
if (!type1.priv.isTypedDictPartial !== !classType2.priv.isTypedDictPartial) {
|
2066
2236
|
return false;
|
2067
2237
|
}
|
2068
2238
|
if (!options.ignoreTypedDictNarrowEntries && !ClassType.isTypedDictNarrowedEntriesSame(type1, classType2)) {
|
@@ -2073,8 +2243,8 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2073
2243
|
case 4 /* TypeCategory.Function */: {
|
2074
2244
|
// Make sure the parameter counts match.
|
2075
2245
|
const functionType2 = type2;
|
2076
|
-
const params1 = type1.
|
2077
|
-
const params2 = functionType2.
|
2246
|
+
const params1 = type1.shared.parameters;
|
2247
|
+
const params2 = functionType2.shared.parameters;
|
2078
2248
|
if (params1.length !== params2.length) {
|
2079
2249
|
return false;
|
2080
2250
|
}
|
@@ -2114,19 +2284,19 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2114
2284
|
}
|
2115
2285
|
}
|
2116
2286
|
// Make sure the return types match.
|
2117
|
-
let return1Type = type1.
|
2118
|
-
if (type1.specializedTypes && type1.specializedTypes.returnType) {
|
2119
|
-
return1Type = type1.specializedTypes.returnType;
|
2287
|
+
let return1Type = type1.shared.declaredReturnType;
|
2288
|
+
if (type1.priv.specializedTypes && type1.priv.specializedTypes.returnType) {
|
2289
|
+
return1Type = type1.priv.specializedTypes.returnType;
|
2120
2290
|
}
|
2121
|
-
if (!return1Type && type1.inferredReturnType) {
|
2122
|
-
return1Type = type1.inferredReturnType;
|
2291
|
+
if (!return1Type && type1.priv.inferredReturnType) {
|
2292
|
+
return1Type = type1.priv.inferredReturnType;
|
2123
2293
|
}
|
2124
|
-
let return2Type = functionType2.
|
2125
|
-
if (functionType2.specializedTypes && functionType2.specializedTypes.returnType) {
|
2126
|
-
return2Type = functionType2.specializedTypes.returnType;
|
2294
|
+
let return2Type = functionType2.shared.declaredReturnType;
|
2295
|
+
if (functionType2.priv.specializedTypes && functionType2.priv.specializedTypes.returnType) {
|
2296
|
+
return2Type = functionType2.priv.specializedTypes.returnType;
|
2127
2297
|
}
|
2128
|
-
if (!return2Type && functionType2.inferredReturnType) {
|
2129
|
-
return2Type = functionType2.inferredReturnType;
|
2298
|
+
if (!return2Type && functionType2.priv.inferredReturnType) {
|
2299
|
+
return2Type = functionType2.priv.inferredReturnType;
|
2130
2300
|
}
|
2131
2301
|
if (return1Type || return2Type) {
|
2132
2302
|
if (!return1Type ||
|
@@ -2140,13 +2310,13 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2140
2310
|
case 5 /* TypeCategory.OverloadedFunction */: {
|
2141
2311
|
// Make sure the overload counts match.
|
2142
2312
|
const functionType2 = type2;
|
2143
|
-
if (type1.overloads.length !== functionType2.overloads.length) {
|
2313
|
+
if (type1.priv.overloads.length !== functionType2.priv.overloads.length) {
|
2144
2314
|
return false;
|
2145
2315
|
}
|
2146
2316
|
// We assume here that overloaded functions always appear
|
2147
2317
|
// in the same order from one analysis pass to another.
|
2148
|
-
for (let i = 0; i < type1.overloads.length; i++) {
|
2149
|
-
if (!isTypeSame(type1.overloads[i], functionType2.overloads[i], options, recursionCount)) {
|
2318
|
+
for (let i = 0; i < type1.priv.overloads.length; i++) {
|
2319
|
+
if (!isTypeSame(type1.priv.overloads[i], functionType2.priv.overloads[i], options, recursionCount)) {
|
2150
2320
|
return false;
|
2151
2321
|
}
|
2152
2322
|
}
|
@@ -2154,8 +2324,8 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2154
2324
|
}
|
2155
2325
|
case 8 /* TypeCategory.Union */: {
|
2156
2326
|
const unionType2 = type2;
|
2157
|
-
const subtypes1 = type1.subtypes;
|
2158
|
-
const subtypes2 = unionType2.subtypes;
|
2327
|
+
const subtypes1 = type1.priv.subtypes;
|
2328
|
+
const subtypes2 = unionType2.priv.subtypes;
|
2159
2329
|
if (subtypes1.length !== subtypes2.length) {
|
2160
2330
|
return false;
|
2161
2331
|
}
|
@@ -2166,14 +2336,14 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2166
2336
|
}
|
2167
2337
|
case 9 /* TypeCategory.TypeVar */: {
|
2168
2338
|
const type2TypeVar = type2;
|
2169
|
-
if (type1.scopeId !== type2TypeVar.scopeId) {
|
2339
|
+
if (type1.priv.scopeId !== type2TypeVar.priv.scopeId) {
|
2170
2340
|
return false;
|
2171
2341
|
}
|
2172
2342
|
// Handle the case where this is a generic recursive type alias. Make
|
2173
2343
|
// sure that the type argument types match.
|
2174
|
-
if (type1.
|
2175
|
-
const type1TypeArgs = ((
|
2176
|
-
const type2TypeArgs = ((
|
2344
|
+
if (type1.shared.recursiveAlias && type2TypeVar.shared.recursiveAlias) {
|
2345
|
+
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.typeArguments) || [];
|
2346
|
+
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.typeArguments) || [];
|
2177
2347
|
const typeArgCount = Math.max(type1TypeArgs.length, type2TypeArgs.length);
|
2178
2348
|
for (let i = 0; i < typeArgCount; i++) {
|
2179
2349
|
// Assume that missing type args are "Any".
|
@@ -2184,22 +2354,22 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2184
2354
|
}
|
2185
2355
|
}
|
2186
2356
|
}
|
2187
|
-
if (!type1.isVariadicInUnion !== !type2TypeVar.isVariadicInUnion) {
|
2357
|
+
if (!type1.priv.isVariadicInUnion !== !type2TypeVar.priv.isVariadicInUnion) {
|
2188
2358
|
return false;
|
2189
2359
|
}
|
2190
|
-
if (type1.
|
2360
|
+
if (type1.shared === type2TypeVar.shared) {
|
2191
2361
|
return true;
|
2192
2362
|
}
|
2193
|
-
if (type1.
|
2194
|
-
type1.
|
2195
|
-
type1.
|
2196
|
-
type1.
|
2197
|
-
type1.
|
2198
|
-
type1.scopeId !== type2TypeVar.scopeId) {
|
2363
|
+
if (type1.shared.name !== type2TypeVar.shared.name ||
|
2364
|
+
type1.shared.isParamSpec !== type2TypeVar.shared.isParamSpec ||
|
2365
|
+
type1.shared.isVariadic !== type2TypeVar.shared.isVariadic ||
|
2366
|
+
type1.shared.isSynthesized !== type2TypeVar.shared.isSynthesized ||
|
2367
|
+
type1.shared.declaredVariance !== type2TypeVar.shared.declaredVariance ||
|
2368
|
+
type1.priv.scopeId !== type2TypeVar.priv.scopeId) {
|
2199
2369
|
return false;
|
2200
2370
|
}
|
2201
|
-
const boundType1 = type1.
|
2202
|
-
const boundType2 = type2TypeVar.
|
2371
|
+
const boundType1 = type1.shared.boundType;
|
2372
|
+
const boundType2 = type2TypeVar.shared.boundType;
|
2203
2373
|
if (boundType1) {
|
2204
2374
|
if (!boundType2 ||
|
2205
2375
|
!isTypeSame(boundType1, boundType2, { ...options, ignoreTypeFlags: false }, recursionCount)) {
|
@@ -2211,8 +2381,8 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2211
2381
|
return false;
|
2212
2382
|
}
|
2213
2383
|
}
|
2214
|
-
const constraints1 = type1.
|
2215
|
-
const constraints2 = type2TypeVar.
|
2384
|
+
const constraints1 = type1.shared.constraints;
|
2385
|
+
const constraints2 = type2TypeVar.shared.constraints;
|
2216
2386
|
if (constraints1.length !== constraints2.length) {
|
2217
2387
|
return false;
|
2218
2388
|
}
|
@@ -2227,19 +2397,19 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2227
2397
|
const type2Module = type2;
|
2228
2398
|
// Module types are the same if they share the same
|
2229
2399
|
// module symbol table.
|
2230
|
-
if (type1.fields === type2Module.fields) {
|
2400
|
+
if (type1.priv.fields === type2Module.priv.fields) {
|
2231
2401
|
return true;
|
2232
2402
|
}
|
2233
2403
|
// If both symbol tables are empty, we can also assume
|
2234
2404
|
// they're equal.
|
2235
|
-
if (type1.fields.size === 0 && type2Module.fields.size === 0) {
|
2405
|
+
if (type1.priv.fields.size === 0 && type2Module.priv.fields.size === 0) {
|
2236
2406
|
return true;
|
2237
2407
|
}
|
2238
2408
|
return false;
|
2239
2409
|
}
|
2240
2410
|
case 1 /* TypeCategory.Unknown */: {
|
2241
2411
|
const type2Unknown = type2;
|
2242
|
-
return type1.isIncomplete === type2Unknown.isIncomplete;
|
2412
|
+
return type1.priv.isIncomplete === type2Unknown.priv.isIncomplete;
|
2243
2413
|
}
|
2244
2414
|
}
|
2245
2415
|
return true;
|
@@ -2265,8 +2435,8 @@ function removeUnbound(type) {
|
|
2265
2435
|
exports.removeUnbound = removeUnbound;
|
2266
2436
|
function removeFromUnion(type, removeFilter) {
|
2267
2437
|
if (isUnion(type)) {
|
2268
|
-
const remainingTypes = type.subtypes.filter((t) => !removeFilter(t));
|
2269
|
-
if (remainingTypes.length < type.subtypes.length) {
|
2438
|
+
const remainingTypes = type.priv.subtypes.filter((t) => !removeFilter(t));
|
2439
|
+
if (remainingTypes.length < type.priv.subtypes.length) {
|
2270
2440
|
const newType = combineTypes(remainingTypes);
|
2271
2441
|
if (isUnion(newType)) {
|
2272
2442
|
UnionType.addTypeAliasSource(newType, type);
|
@@ -2279,7 +2449,7 @@ function removeFromUnion(type, removeFilter) {
|
|
2279
2449
|
exports.removeFromUnion = removeFromUnion;
|
2280
2450
|
function findSubtype(type, filter) {
|
2281
2451
|
if (isUnion(type)) {
|
2282
|
-
return type.subtypes.find((subtype) => {
|
2452
|
+
return type.priv.subtypes.find((subtype) => {
|
2283
2453
|
return filter(subtype);
|
2284
2454
|
});
|
2285
2455
|
}
|
@@ -2290,12 +2460,13 @@ exports.findSubtype = findSubtype;
|
|
2290
2460
|
// the same, only one is returned. If they differ, they
|
2291
2461
|
// are combined into a UnionType. NeverTypes are filtered out.
|
2292
2462
|
// If no types remain in the end, a NeverType is returned.
|
2293
|
-
function combineTypes(subtypes,
|
2463
|
+
function combineTypes(subtypes, options) {
|
2464
|
+
var _a;
|
2294
2465
|
// Filter out any "Never" and "NoReturn" types.
|
2295
2466
|
let sawNoReturn = false;
|
2296
2467
|
if (subtypes.some((subtype) => subtype.category === 3 /* TypeCategory.Never */))
|
2297
2468
|
subtypes = subtypes.filter((subtype) => {
|
2298
|
-
if (subtype.category === 3 /* TypeCategory.Never */ && subtype.isNoReturn) {
|
2469
|
+
if (subtype.category === 3 /* TypeCategory.Never */ && subtype.priv.isNoReturn) {
|
2299
2470
|
sawNoReturn = true;
|
2300
2471
|
}
|
2301
2472
|
return subtype.category !== 3 /* TypeCategory.Never */;
|
@@ -2326,12 +2497,12 @@ function combineTypes(subtypes, maxSubtypeCount) {
|
|
2326
2497
|
if (!expandedTypes) {
|
2327
2498
|
expandedTypes = subtypes.slice(0, i);
|
2328
2499
|
}
|
2329
|
-
expandedTypes = expandedTypes.concat(subtype.subtypes);
|
2330
|
-
if (subtype.typeAliasInfo) {
|
2500
|
+
expandedTypes = expandedTypes.concat(subtype.priv.subtypes);
|
2501
|
+
if ((_a = subtype.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) {
|
2331
2502
|
typeAliasSources.add(subtype);
|
2332
2503
|
}
|
2333
|
-
else if (subtype.typeAliasSources) {
|
2334
|
-
subtype.typeAliasSources.forEach((subtype) => {
|
2504
|
+
else if (subtype.priv.typeAliasSources) {
|
2505
|
+
subtype.priv.typeAliasSources.forEach((subtype) => {
|
2335
2506
|
typeAliasSources.add(subtype);
|
2336
2507
|
});
|
2337
2508
|
}
|
@@ -2343,16 +2514,16 @@ function combineTypes(subtypes, maxSubtypeCount) {
|
|
2343
2514
|
expandedTypes = expandedTypes !== null && expandedTypes !== void 0 ? expandedTypes : subtypes;
|
2344
2515
|
// Sort all of the literal and empty types to the end.
|
2345
2516
|
expandedTypes = expandedTypes.sort((type1, type2) => {
|
2346
|
-
if (isClass(type1) && type1.literalValue !== undefined) {
|
2517
|
+
if (isClass(type1) && type1.priv.literalValue !== undefined) {
|
2347
2518
|
return 1;
|
2348
2519
|
}
|
2349
|
-
if (isClass(type2) && type2.literalValue !== undefined) {
|
2520
|
+
if (isClass(type2) && type2.priv.literalValue !== undefined) {
|
2350
2521
|
return -1;
|
2351
2522
|
}
|
2352
|
-
if (isClassInstance(type1) && type1.isEmptyContainer) {
|
2523
|
+
if (isClassInstance(type1) && type1.priv.isEmptyContainer) {
|
2353
2524
|
return 1;
|
2354
2525
|
}
|
2355
|
-
else if (isClassInstance(type2) && type2.isEmptyContainer) {
|
2526
|
+
else if (isClassInstance(type2) && type2.priv.isEmptyContainer) {
|
2356
2527
|
return -1;
|
2357
2528
|
}
|
2358
2529
|
return 0;
|
@@ -2364,7 +2535,7 @@ function combineTypes(subtypes, maxSubtypeCount) {
|
|
2364
2535
|
}
|
2365
2536
|
const newUnionType = UnionType.create();
|
2366
2537
|
if (typeAliasSources.size > 0) {
|
2367
|
-
newUnionType.typeAliasSources = typeAliasSources;
|
2538
|
+
newUnionType.priv.typeAliasSources = typeAliasSources;
|
2368
2539
|
}
|
2369
2540
|
let hitMaxSubtypeCount = false;
|
2370
2541
|
expandedTypes.forEach((subtype, index) => {
|
@@ -2372,8 +2543,8 @@ function combineTypes(subtypes, maxSubtypeCount) {
|
|
2372
2543
|
UnionType.addType(newUnionType, subtype);
|
2373
2544
|
}
|
2374
2545
|
else {
|
2375
|
-
if (maxSubtypeCount === undefined || newUnionType.subtypes.length < maxSubtypeCount) {
|
2376
|
-
_addTypeIfUnique(newUnionType, subtype);
|
2546
|
+
if ((options === null || options === void 0 ? void 0 : options.maxSubtypeCount) === undefined || newUnionType.priv.subtypes.length < options.maxSubtypeCount) {
|
2547
|
+
_addTypeIfUnique(newUnionType, subtype, !(options === null || options === void 0 ? void 0 : options.skipElideRedundantLiterals));
|
2377
2548
|
}
|
2378
2549
|
else {
|
2379
2550
|
hitMaxSubtypeCount = true;
|
@@ -2384,8 +2555,8 @@ function combineTypes(subtypes, maxSubtypeCount) {
|
|
2384
2555
|
return AnyType.create();
|
2385
2556
|
}
|
2386
2557
|
// If only one type remains, convert it from a union to a simple type.
|
2387
|
-
if (newUnionType.subtypes.length === 1) {
|
2388
|
-
return newUnionType.subtypes[0];
|
2558
|
+
if (newUnionType.priv.subtypes.length === 1) {
|
2559
|
+
return newUnionType.priv.subtypes[0];
|
2389
2560
|
}
|
2390
2561
|
return newUnionType;
|
2391
2562
|
}
|
@@ -2398,12 +2569,12 @@ function isSameWithoutLiteralValue(destType, srcType) {
|
|
2398
2569
|
if (isTypeSame(destType, srcType)) {
|
2399
2570
|
return true;
|
2400
2571
|
}
|
2401
|
-
if (isInstantiableClass(srcType) && srcType.literalValue !== undefined) {
|
2572
|
+
if (isInstantiableClass(srcType) && srcType.priv.literalValue !== undefined) {
|
2402
2573
|
// Strip the literal.
|
2403
2574
|
srcType = ClassType.cloneWithLiteral(srcType, /* value */ undefined);
|
2404
2575
|
return isTypeSame(destType, srcType);
|
2405
2576
|
}
|
2406
|
-
if (isClassInstance(srcType) && srcType.literalValue !== undefined) {
|
2577
|
+
if (isClassInstance(srcType) && srcType.priv.literalValue !== undefined) {
|
2407
2578
|
// Strip the literal.
|
2408
2579
|
srcType = ClassType.cloneWithLiteral(srcType, /* value */ undefined);
|
2409
2580
|
return isTypeSame(destType, srcType, { ignoreConditions: true });
|
@@ -2411,32 +2582,35 @@ function isSameWithoutLiteralValue(destType, srcType) {
|
|
2411
2582
|
return false;
|
2412
2583
|
}
|
2413
2584
|
exports.isSameWithoutLiteralValue = isSameWithoutLiteralValue;
|
2414
|
-
function _addTypeIfUnique(unionType, typeToAdd) {
|
2585
|
+
function _addTypeIfUnique(unionType, typeToAdd, elideRedundantLiterals) {
|
2586
|
+
var _a, _b, _c;
|
2415
2587
|
// Handle the addition of a string literal in a special manner to
|
2416
2588
|
// avoid n^2 behavior in unions that contain hundreds of string
|
2417
2589
|
// literal types. Skip this for constrained types.
|
2418
|
-
if (isClass(typeToAdd) && typeToAdd.
|
2419
|
-
const literalMaps = isClassInstance(typeToAdd)
|
2590
|
+
if (isClass(typeToAdd) && !((_a = typeToAdd.props) === null || _a === void 0 ? void 0 : _a.condition)) {
|
2591
|
+
const literalMaps = isClassInstance(typeToAdd)
|
2592
|
+
? unionType.priv.literalInstances
|
2593
|
+
: unionType.priv.literalClasses;
|
2420
2594
|
if (ClassType.isBuiltIn(typeToAdd, 'str') &&
|
2421
|
-
typeToAdd.literalValue !== undefined &&
|
2595
|
+
typeToAdd.priv.literalValue !== undefined &&
|
2422
2596
|
literalMaps.literalStrMap !== undefined) {
|
2423
|
-
if (!literalMaps.literalStrMap.has(typeToAdd.literalValue)) {
|
2597
|
+
if (!literalMaps.literalStrMap.has(typeToAdd.priv.literalValue)) {
|
2424
2598
|
UnionType.addType(unionType, typeToAdd);
|
2425
2599
|
}
|
2426
2600
|
return;
|
2427
2601
|
}
|
2428
2602
|
else if (ClassType.isBuiltIn(typeToAdd, 'int') &&
|
2429
|
-
typeToAdd.literalValue !== undefined &&
|
2603
|
+
typeToAdd.priv.literalValue !== undefined &&
|
2430
2604
|
literalMaps.literalIntMap !== undefined) {
|
2431
|
-
if (!literalMaps.literalIntMap.has(typeToAdd.literalValue)) {
|
2605
|
+
if (!literalMaps.literalIntMap.has(typeToAdd.priv.literalValue)) {
|
2432
2606
|
UnionType.addType(unionType, typeToAdd);
|
2433
2607
|
}
|
2434
2608
|
return;
|
2435
2609
|
}
|
2436
2610
|
else if (ClassType.isEnumClass(typeToAdd) &&
|
2437
|
-
typeToAdd.literalValue !== undefined &&
|
2611
|
+
typeToAdd.priv.literalValue !== undefined &&
|
2438
2612
|
literalMaps.literalEnumMap !== undefined) {
|
2439
|
-
const enumLiteral = typeToAdd.literalValue;
|
2613
|
+
const enumLiteral = typeToAdd.priv.literalValue;
|
2440
2614
|
if (!literalMaps.literalEnumMap.has(enumLiteral.getName())) {
|
2441
2615
|
UnionType.addType(unionType, typeToAdd);
|
2442
2616
|
}
|
@@ -2444,8 +2618,8 @@ function _addTypeIfUnique(unionType, typeToAdd) {
|
|
2444
2618
|
}
|
2445
2619
|
}
|
2446
2620
|
const isPseudoGeneric = isClass(typeToAdd) && ClassType.isPseudoGenericClass(typeToAdd);
|
2447
|
-
for (let i = 0; i < unionType.subtypes.length; i++) {
|
2448
|
-
const type = unionType.subtypes[i];
|
2621
|
+
for (let i = 0; i < unionType.priv.subtypes.length; i++) {
|
2622
|
+
const type = unionType.priv.subtypes[i];
|
2449
2623
|
// Does this type already exist in the types array?
|
2450
2624
|
if (isTypeSame(type, typeToAdd)) {
|
2451
2625
|
return;
|
@@ -2458,27 +2632,28 @@ function _addTypeIfUnique(unionType, typeToAdd) {
|
|
2458
2632
|
// parameterized with its own class) ad infinitum.
|
2459
2633
|
if (isPseudoGeneric) {
|
2460
2634
|
if (isTypeSame(type, typeToAdd, { ignorePseudoGeneric: true })) {
|
2461
|
-
unionType.subtypes[i] = ClassType.cloneForSpecialization(typeToAdd, typeToAdd.
|
2635
|
+
unionType.priv.subtypes[i] = ClassType.cloneForSpecialization(typeToAdd, typeToAdd.shared.typeParameters.map(() => UnknownType.create()),
|
2462
2636
|
/* isTypeArgumentExplicit */ true);
|
2463
2637
|
return;
|
2464
2638
|
}
|
2465
2639
|
}
|
2466
|
-
// If the typeToAdd is a literal value and there's already
|
2467
|
-
// a non-literal type that matches, don't add the literal value.
|
2468
2640
|
if (isClassInstance(type) && isClassInstance(typeToAdd)) {
|
2469
|
-
|
2470
|
-
|
2641
|
+
// If the typeToAdd is a literal value and there's already
|
2642
|
+
// a non-literal type that matches, don't add the literal value.
|
2643
|
+
if (elideRedundantLiterals && isSameWithoutLiteralValue(type, typeToAdd)) {
|
2644
|
+
if (type.priv.literalValue === undefined) {
|
2471
2645
|
return;
|
2472
2646
|
}
|
2473
2647
|
}
|
2474
2648
|
// If we're adding Literal[False] or Literal[True] to its
|
2475
2649
|
// opposite, combine them into a non-literal 'bool' type.
|
2476
2650
|
if (ClassType.isBuiltIn(type, 'bool') &&
|
2477
|
-
!type.condition &&
|
2651
|
+
!((_b = type.props) === null || _b === void 0 ? void 0 : _b.condition) &&
|
2478
2652
|
ClassType.isBuiltIn(typeToAdd, 'bool') &&
|
2479
|
-
!typeToAdd.condition) {
|
2480
|
-
if (typeToAdd.literalValue !== undefined &&
|
2481
|
-
|
2653
|
+
!((_c = typeToAdd.props) === null || _c === void 0 ? void 0 : _c.condition)) {
|
2654
|
+
if (typeToAdd.priv.literalValue !== undefined &&
|
2655
|
+
!typeToAdd.priv.literalValue === type.priv.literalValue) {
|
2656
|
+
unionType.priv.subtypes[i] = ClassType.cloneWithLiteral(type, /* value */ undefined);
|
2482
2657
|
return;
|
2483
2658
|
}
|
2484
2659
|
}
|
@@ -2486,12 +2661,12 @@ function _addTypeIfUnique(unionType, typeToAdd) {
|
|
2486
2661
|
// existing type, see if one of them is a proper subset of the other.
|
2487
2662
|
if (ClassType.isTypedDictClass(type) && ClassType.isSameGenericClass(type, typeToAdd)) {
|
2488
2663
|
// Do not proceed if the TypedDicts are generic and have different type arguments.
|
2489
|
-
if (!type.typeArguments && !typeToAdd.typeArguments) {
|
2664
|
+
if (!type.priv.typeArguments && !typeToAdd.priv.typeArguments) {
|
2490
2665
|
if (ClassType.isTypedDictNarrower(typeToAdd, type)) {
|
2491
2666
|
return;
|
2492
2667
|
}
|
2493
2668
|
else if (ClassType.isTypedDictNarrower(type, typeToAdd)) {
|
2494
|
-
unionType.subtypes[i] = typeToAdd;
|
2669
|
+
unionType.priv.subtypes[i] = typeToAdd;
|
2495
2670
|
return;
|
2496
2671
|
}
|
2497
2672
|
}
|
@@ -2499,7 +2674,7 @@ function _addTypeIfUnique(unionType, typeToAdd) {
|
|
2499
2674
|
}
|
2500
2675
|
// If the typeToAdd is an empty container and there's already
|
2501
2676
|
// non-empty container of the same type, don't add the empty container.
|
2502
|
-
if (isClassInstance(typeToAdd) && typeToAdd.isEmptyContainer) {
|
2677
|
+
if (isClassInstance(typeToAdd) && typeToAdd.priv.isEmptyContainer) {
|
2503
2678
|
if (isClassInstance(type) && ClassType.isSameGenericClass(type, typeToAdd)) {
|
2504
2679
|
return;
|
2505
2680
|
}
|