@zzzen/pyright-internal 1.2.0-dev.20231029 → 1.2.0-dev.20231105
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/analyzerFileInfo.d.ts +1 -0
- package/dist/analyzer/analyzerFileInfo.js.map +1 -1
- package/dist/analyzer/checker.js +57 -50
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +4 -4
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowUtils.js +4 -2
- package/dist/analyzer/codeFlowUtils.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +2 -3
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +1 -1
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +41 -36
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +3 -3
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/enums.d.ts +2 -5
- package/dist/analyzer/enums.js +4 -2
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/functionTransform.js +1 -1
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +2 -1
- package/dist/analyzer/importResolver.js +13 -5
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/namedTuples.js +3 -2
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +22 -25
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +19 -21
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/patternMatching.js +5 -5
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +1 -1
- package/dist/analyzer/program.js +17 -12
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +5 -5
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +1 -1
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.js +11 -4
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +1 -0
- package/dist/analyzer/sourceFile.js +3 -0
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +11 -13
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +3 -3
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +748 -805
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +12 -25
- package/dist/analyzer/typeEvaluatorTypes.js +1 -36
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +27 -23
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +19 -18
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +17 -8
- package/dist/analyzer/typeUtils.js +146 -93
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +6 -7
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typeWalker.d.ts +1 -2
- package/dist/analyzer/typeWalker.js +7 -13
- package/dist/analyzer/typeWalker.js.map +1 -1
- package/dist/analyzer/typedDicts.js +10 -10
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +8 -19
- package/dist/analyzer/types.js +44 -76
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +7 -9
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/commandLineOptions.d.ts +2 -1
- package/dist/common/commandLineOptions.js +1 -1
- package/dist/common/commandLineOptions.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -1
- package/dist/common/configOptions.js +22 -24
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/pathUtils.d.ts +1 -1
- package/dist/common/pathUtils.js +11 -10
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.js +4 -6
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/languageServerBase.d.ts +2 -2
- package/dist/languageServerBase.js +14 -14
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.js +1 -1
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +3 -3
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.js +8 -8
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.js +1 -1
- package/dist/languageService/definitionProvider.js +1 -1
- package/dist/languageService/documentSymbolCollector.js +1 -1
- package/dist/languageService/hoverProvider.js +1 -1
- package/dist/languageService/signatureHelpProvider.js +0 -14
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +4 -4
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +12 -0
- package/dist/localization/localize.js +4 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +1 -1
- package/dist/localization/package.nls.de.json +1 -1
- package/dist/localization/package.nls.en-us.json +4 -0
- package/dist/localization/package.nls.es.json +1 -1
- package/dist/localization/package.nls.fr.json +1 -1
- package/dist/localization/package.nls.it.json +1 -1
- package/dist/localization/package.nls.ja.json +1 -1
- package/dist/localization/package.nls.ko.json +1 -1
- package/dist/localization/package.nls.pl.json +1 -1
- package/dist/localization/package.nls.pt-br.json +1 -1
- package/dist/localization/package.nls.ru.json +1 -1
- package/dist/localization/package.nls.tr.json +1 -1
- package/dist/localization/package.nls.zh-cn.json +1 -1
- package/dist/localization/package.nls.zh-tw.json +1 -1
- package/dist/pyright.js +3 -6
- package/dist/pyright.js.map +1 -1
- package/dist/server.d.ts +1 -0
- package/dist/server.js +10 -1
- package/dist/server.js.map +1 -1
- package/dist/tests/fourslash/{completions.importInterimFile.fourslash.js → completions.importInterimFile.fourslash.disabled.js} +2 -2
- package/dist/tests/fourslash/completions.importInterimFile.fourslash.disabled.js.map +1 -0
- package/dist/tests/fourslash/fourslash.d.ts +1 -1
- package/dist/tests/fourslash/signature.complicated.fourslash.js +6 -6
- package/dist/tests/fourslash/signature.complicated.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +1 -1
- package/dist/tests/harness/fourslash/testState.js +1 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.js +1 -1
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/logger.test.js +0 -1
- package/dist/tests/logger.test.js.map +1 -1
- package/dist/tests/pathUtils.test.js +30 -1
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/testUtils.js +2 -1
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +3 -3
- package/dist/tests/typeEvaluator2.test.js +1 -1
- package/dist/tests/typeEvaluator3.test.js +7 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +6 -2
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +12 -16
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/tests/zipfs.test.js +2 -0
- package/dist/tests/zipfs.test.js.map +1 -1
- package/package.json +1 -1
- package/dist/tests/fourslash/completions.importInterimFile.fourslash.js.map +0 -1
- /package/dist/tests/fourslash/{completions.importInterimFile.fourslash.d.ts → completions.importInterimFile.fourslash.disabled.d.ts} +0 -0
@@ -8,8 +8,9 @@
|
|
8
8
|
* Functions that operate on Type objects.
|
9
9
|
*/
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
11
|
-
exports.
|
12
|
-
exports.
|
11
|
+
exports.populateTypeVarContextForSelfType = exports.partiallySpecializeType = exports.isTupleIndexUnambiguous = exports.isUnboundedTupleClass = exports.isTupleClass = exports.isMaybeDescriptorInstance = exports.isDescriptorInstance = exports.isCallableType = exports.isProperty = exports.isEllipsisType = exports.getUnionSubtypeCount = exports.getLiteralTypeClassName = exports.containsLiteralType = exports.isLiteralTypeOrUnion = exports.isLiteralType = exports.getSpecializedTupleType = exports.selfSpecializeClass = exports.getUnknownTypeForParamSpec = exports.getUnknownTypeForTypeVar = exports.specializeWithUnknown = exports.specializeWithDefaultTypeArgs = exports.getTypeVarScopeIds = exports.getTypeVarScopeId = exports.transformPossibleRecursiveTypeAlias = exports.isTypeAliasRecursive = exports.isTypeAliasPlaceholder = exports.getTypeCondition = exports.addConditionToType = exports.getFullNameOfType = exports.derivesFromAnyOrUnknown = exports.isUnionableType = exports.preserveUnknown = exports.areTypesSame = exports.doForEachSignature = exports.doForEachSubtype = exports.sortTypes = exports.cleanIncompleteUnknown = exports.mapSignatures = exports.mapSubtypes = exports.makeInferenceContext = exports.isTypeVarSame = exports.isIncompleteUnknown = exports.removeNoneFromUnion = exports.isNoneTypeClass = exports.isNoneInstance = exports.isOptionalType = exports.UniqueSignatureTracker = exports.AssignTypeFlags = exports.ClassIteratorFlags = exports.MemberAccessFlags = void 0;
|
12
|
+
exports.computeMroLinearization = exports.isVarianceOfTypeArgumentCompatible = exports.combineVariances = exports.requiresSpecialization = exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.removeParamSpecVariadicsFromFunction = exports.removeParamSpecVariadicsFromSignature = exports.specializeTupleClass = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsAnyOrUnknown = exports.containsAnyRecursive = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.isMetaclassInstance = exports.isInstantiableMetaclass = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.derivesFromStdlibClass = exports.specializeForBaseClass = exports.buildTypeVarContext = exports.buildTypeVarContextFromSpecializedClass = exports.setTypeArgumentsRecursive = exports.specializeClassType = exports.isTypeVarLimitedToCallable = exports.getTypeVarArgumentsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = exports.lookUpClassMember = exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbolsRecursive = exports.getProtocolSymbols = exports.transformExpectedType = exports.replaceTypeVarsWithAny = exports.validateTypeVarDefault = exports.applyInScopePlaceholders = exports.applySourceContextTypeVarsToSignature = exports.applySourceContextTypeVars = exports.applySolvedTypeVars = exports.ensureFunctionSignaturesAreUnique = void 0;
|
13
|
+
exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = void 0;
|
13
14
|
const collectionUtils_1 = require("../common/collectionUtils");
|
14
15
|
const debug_1 = require("../common/debug");
|
15
16
|
const symbol_1 = require("./symbol");
|
@@ -17,32 +18,43 @@ const symbolUtils_1 = require("./symbolUtils");
|
|
17
18
|
const types_1 = require("./types");
|
18
19
|
const typeVarContext_1 = require("./typeVarContext");
|
19
20
|
const typeWalker_1 = require("./typeWalker");
|
20
|
-
var
|
21
|
-
(function (
|
22
|
-
|
21
|
+
var MemberAccessFlags;
|
22
|
+
(function (MemberAccessFlags) {
|
23
|
+
MemberAccessFlags[MemberAccessFlags["Default"] = 0] = "Default";
|
23
24
|
// By default, the original (derived) class is searched along
|
24
25
|
// with its base classes. If this flag is set, the original
|
25
26
|
// class is skipped and only the base classes are searched.
|
26
|
-
|
27
|
+
MemberAccessFlags[MemberAccessFlags["SkipOriginalClass"] = 1] = "SkipOriginalClass";
|
27
28
|
// By default, base classes are searched as well as the
|
28
29
|
// original (derived) class. If this flag is set, no recursion
|
29
30
|
// is performed.
|
30
|
-
|
31
|
+
MemberAccessFlags[MemberAccessFlags["SkipBaseClasses"] = 2] = "SkipBaseClasses";
|
31
32
|
// Skip the 'object' base class in particular.
|
32
|
-
|
33
|
+
MemberAccessFlags[MemberAccessFlags["SkipObjectBaseClass"] = 4] = "SkipObjectBaseClass";
|
34
|
+
// Skip the 'type' base class in particular.
|
35
|
+
MemberAccessFlags[MemberAccessFlags["SkipTypeBaseClass"] = 8] = "SkipTypeBaseClass";
|
33
36
|
// By default, both class and instance variables are searched.
|
34
37
|
// If this flag is set, the instance variables are skipped.
|
35
|
-
|
38
|
+
MemberAccessFlags[MemberAccessFlags["SkipInstanceMembers"] = 16] = "SkipInstanceMembers";
|
36
39
|
// By default, both class and instance variables are searched.
|
37
40
|
// If this flag is set, the class variables are skipped.
|
38
|
-
|
41
|
+
MemberAccessFlags[MemberAccessFlags["SkipClassMembers"] = 32] = "SkipClassMembers";
|
39
42
|
// By default, the first symbol is returned even if it has only
|
40
43
|
// an inferred type associated with it. If this flag is set,
|
41
44
|
// the search looks only for symbols with declared types.
|
42
|
-
|
43
|
-
//
|
44
|
-
|
45
|
-
|
45
|
+
MemberAccessFlags[MemberAccessFlags["DeclaredTypesOnly"] = 64] = "DeclaredTypesOnly";
|
46
|
+
// Consider writes to symbols flagged as ClassVars as an error.
|
47
|
+
MemberAccessFlags[MemberAccessFlags["DisallowClassVarWrites"] = 128] = "DisallowClassVarWrites";
|
48
|
+
// Normally __new__ is treated as a static method, but when
|
49
|
+
// it is invoked implicitly through a constructor call, it
|
50
|
+
// acts like a class method instead.
|
51
|
+
MemberAccessFlags[MemberAccessFlags["TreatConstructorAsClassMethod"] = 256] = "TreatConstructorAsClassMethod";
|
52
|
+
// If an attribute cannot be found when looking for instance
|
53
|
+
// members, normally an attribute access override method
|
54
|
+
// (__getattr__, etc.) may provide the missing attribute type.
|
55
|
+
// This disables this check.
|
56
|
+
MemberAccessFlags[MemberAccessFlags["SkipAttributeAccessOverride"] = 512] = "SkipAttributeAccessOverride";
|
57
|
+
})(MemberAccessFlags = exports.MemberAccessFlags || (exports.MemberAccessFlags = {}));
|
46
58
|
var ClassIteratorFlags;
|
47
59
|
(function (ClassIteratorFlags) {
|
48
60
|
ClassIteratorFlags[ClassIteratorFlags["Default"] = 0] = "Default";
|
@@ -156,11 +168,25 @@ class UniqueSignatureTracker {
|
|
156
168
|
exports.UniqueSignatureTracker = UniqueSignatureTracker;
|
157
169
|
function isOptionalType(type) {
|
158
170
|
if ((0, types_1.isUnion)(type)) {
|
159
|
-
return (0, types_1.findSubtype)(type, (subtype) =>
|
171
|
+
return (0, types_1.findSubtype)(type, (subtype) => isNoneInstance(subtype)) !== undefined;
|
160
172
|
}
|
161
173
|
return false;
|
162
174
|
}
|
163
175
|
exports.isOptionalType = isOptionalType;
|
176
|
+
function isNoneInstance(type) {
|
177
|
+
return (0, types_1.isClassInstance)(type) && types_1.ClassType.isBuiltIn(type, 'NoneType');
|
178
|
+
}
|
179
|
+
exports.isNoneInstance = isNoneInstance;
|
180
|
+
function isNoneTypeClass(type) {
|
181
|
+
return (0, types_1.isInstantiableClass)(type) && types_1.ClassType.isBuiltIn(type, 'NoneType');
|
182
|
+
}
|
183
|
+
exports.isNoneTypeClass = isNoneTypeClass;
|
184
|
+
// If the type is a union, remove an "None" type from the union,
|
185
|
+
// returning only the known types.
|
186
|
+
function removeNoneFromUnion(type) {
|
187
|
+
return (0, types_1.removeFromUnion)(type, (t) => isNoneInstance(t));
|
188
|
+
}
|
189
|
+
exports.removeNoneFromUnion = removeNoneFromUnion;
|
164
190
|
function isIncompleteUnknown(type) {
|
165
191
|
return (0, types_1.isUnknown)(type) && type.isIncomplete;
|
166
192
|
}
|
@@ -226,7 +252,7 @@ function mapSubtypes(type, callback, sortSubtypes = false) {
|
|
226
252
|
}
|
227
253
|
const newType = (0, types_1.combineTypes)(typesToCombine);
|
228
254
|
// Do our best to retain type aliases.
|
229
|
-
if (newType.category ===
|
255
|
+
if (newType.category === 8 /* Union */) {
|
230
256
|
types_1.UnionType.addTypeAliasSource(newType, type);
|
231
257
|
}
|
232
258
|
return newType;
|
@@ -241,6 +267,35 @@ function mapSubtypes(type, callback, sortSubtypes = false) {
|
|
241
267
|
return transformedSubtype;
|
242
268
|
}
|
243
269
|
exports.mapSubtypes = mapSubtypes;
|
270
|
+
// Iterates over each signature in a function or overload, allowing the
|
271
|
+
// caller to replace one or more signatures with new ones.
|
272
|
+
function mapSignatures(type, callback) {
|
273
|
+
if ((0, types_1.isFunction)(type)) {
|
274
|
+
return callback(type, 0);
|
275
|
+
}
|
276
|
+
const newSignatures = [];
|
277
|
+
let changeMade = false;
|
278
|
+
types_1.OverloadedFunctionType.getOverloads(type).forEach((overload, index) => {
|
279
|
+
const newOverload = callback(overload, index);
|
280
|
+
if (newOverload !== overload) {
|
281
|
+
changeMade = true;
|
282
|
+
}
|
283
|
+
if (newOverload) {
|
284
|
+
newSignatures.push(newOverload);
|
285
|
+
}
|
286
|
+
});
|
287
|
+
if (!changeMade) {
|
288
|
+
return type;
|
289
|
+
}
|
290
|
+
if (newSignatures.length === 0) {
|
291
|
+
return undefined;
|
292
|
+
}
|
293
|
+
if (newSignatures.length === 1) {
|
294
|
+
return newSignatures[0];
|
295
|
+
}
|
296
|
+
return types_1.OverloadedFunctionType.create(newSignatures);
|
297
|
+
}
|
298
|
+
exports.mapSignatures = mapSignatures;
|
244
299
|
// The code flow engine uses a special form of the UnknownType (with the
|
245
300
|
// isIncomplete flag set) to distinguish between an unknown that was generated
|
246
301
|
// in a loop because it was temporarily incomplete versus an unknown that is
|
@@ -311,12 +366,11 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
311
366
|
case 0 /* Unbound */:
|
312
367
|
case 1 /* Unknown */:
|
313
368
|
case 2 /* Any */:
|
314
|
-
case 3 /*
|
315
|
-
case
|
316
|
-
case 9 /* Union */: {
|
369
|
+
case 3 /* Never */:
|
370
|
+
case 8 /* Union */: {
|
317
371
|
return 0;
|
318
372
|
}
|
319
|
-
case
|
373
|
+
case 4 /* Function */: {
|
320
374
|
const bFunc = b;
|
321
375
|
const aParamCount = a.details.parameters.length;
|
322
376
|
const bParamCount = bFunc.details.parameters.length;
|
@@ -329,12 +383,12 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
329
383
|
if (aParam.category !== bParam.category) {
|
330
384
|
return bParam.category - aParam.category;
|
331
385
|
}
|
332
|
-
const typeComparison = compareTypes(
|
386
|
+
const typeComparison = compareTypes(types_1.FunctionType.getEffectiveParameterType(a, i), types_1.FunctionType.getEffectiveParameterType(bFunc, i));
|
333
387
|
if (typeComparison !== 0) {
|
334
388
|
return typeComparison;
|
335
389
|
}
|
336
390
|
}
|
337
|
-
const returnTypeComparison = compareTypes((_a =
|
391
|
+
const returnTypeComparison = compareTypes((_a = types_1.FunctionType.getSpecializedReturnType(a)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create(), (_b = types_1.FunctionType.getSpecializedReturnType(bFunc)) !== null && _b !== void 0 ? _b : types_1.UnknownType.create());
|
338
392
|
if (returnTypeComparison !== 0) {
|
339
393
|
return returnTypeComparison;
|
340
394
|
}
|
@@ -348,7 +402,7 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
348
402
|
}
|
349
403
|
return 0;
|
350
404
|
}
|
351
|
-
case
|
405
|
+
case 5 /* OverloadedFunction */: {
|
352
406
|
const bOver = b;
|
353
407
|
const aOverloadCount = a.overloads.length;
|
354
408
|
const bOverloadCount = bOver.overloads.length;
|
@@ -363,7 +417,7 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
363
417
|
}
|
364
418
|
return 0;
|
365
419
|
}
|
366
|
-
case
|
420
|
+
case 6 /* Class */: {
|
367
421
|
const bClass = b;
|
368
422
|
// Sort instances before instantiables.
|
369
423
|
if ((0, types_1.isClassInstance)(a) && (0, types_1.isInstantiableClass)(bClass)) {
|
@@ -381,6 +435,13 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
381
435
|
else if (isLiteralType(bClass)) {
|
382
436
|
return 1;
|
383
437
|
}
|
438
|
+
// Always sort NoneType at the end.
|
439
|
+
if (types_1.ClassType.isBuiltIn(a, 'NoneType')) {
|
440
|
+
return 1;
|
441
|
+
}
|
442
|
+
else if (types_1.ClassType.isBuiltIn(bClass, 'NoneType')) {
|
443
|
+
return -1;
|
444
|
+
}
|
384
445
|
// Sort non-generics before generics.
|
385
446
|
if (a.details.typeParameters.length > 0 || isTupleClass(a)) {
|
386
447
|
if (bClass.details.typeParameters.length === 0) {
|
@@ -417,12 +478,12 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
417
478
|
}
|
418
479
|
return 0;
|
419
480
|
}
|
420
|
-
case
|
481
|
+
case 7 /* Module */: {
|
421
482
|
const aName = a.moduleName;
|
422
483
|
const bName = b.moduleName;
|
423
484
|
return aName < bName ? -1 : aName === bName ? 0 : 1;
|
424
485
|
}
|
425
|
-
case
|
486
|
+
case 9 /* TypeVar */: {
|
426
487
|
const aName = a.details.name;
|
427
488
|
const bName = b.details.name;
|
428
489
|
return aName < bName ? -1 : aName === bName ? 0 : 1;
|
@@ -527,15 +588,13 @@ function getFullNameOfType(type) {
|
|
527
588
|
case 2 /* Any */:
|
528
589
|
case 1 /* Unknown */:
|
529
590
|
return 'typing.Any';
|
530
|
-
case
|
531
|
-
return 'builtins.None';
|
532
|
-
case 7 /* Class */:
|
591
|
+
case 6 /* Class */:
|
533
592
|
return type.details.fullName;
|
534
|
-
case
|
593
|
+
case 4 /* Function */:
|
535
594
|
return type.details.fullName;
|
536
|
-
case
|
595
|
+
case 7 /* Module */:
|
537
596
|
return type.moduleName;
|
538
|
-
case
|
597
|
+
case 5 /* OverloadedFunction */:
|
539
598
|
return type.overloads[0].details.fullName;
|
540
599
|
}
|
541
600
|
return undefined;
|
@@ -549,18 +608,17 @@ function addConditionToType(type, condition) {
|
|
549
608
|
case 0 /* Unbound */:
|
550
609
|
case 1 /* Unknown */:
|
551
610
|
case 2 /* Any */:
|
552
|
-
case
|
553
|
-
case
|
554
|
-
case
|
611
|
+
case 3 /* Never */:
|
612
|
+
case 7 /* Module */:
|
613
|
+
case 9 /* TypeVar */:
|
555
614
|
return type;
|
556
|
-
case
|
557
|
-
case 5 /* Function */:
|
615
|
+
case 4 /* Function */:
|
558
616
|
return types_1.TypeBase.cloneForCondition(type, types_1.TypeCondition.combine(type.condition, condition));
|
559
|
-
case
|
617
|
+
case 5 /* OverloadedFunction */:
|
560
618
|
return types_1.OverloadedFunctionType.create(type.overloads.map((t) => addConditionToType(t, condition)));
|
561
|
-
case
|
619
|
+
case 6 /* Class */:
|
562
620
|
return types_1.TypeBase.cloneForCondition(type, types_1.TypeCondition.combine(type.condition, condition));
|
563
|
-
case
|
621
|
+
case 8 /* Union */:
|
564
622
|
return (0, types_1.combineTypes)(type.subtypes.map((t) => addConditionToType(t, condition)));
|
565
623
|
}
|
566
624
|
}
|
@@ -570,15 +628,14 @@ function getTypeCondition(type) {
|
|
570
628
|
case 0 /* Unbound */:
|
571
629
|
case 1 /* Unknown */:
|
572
630
|
case 2 /* Any */:
|
573
|
-
case
|
574
|
-
case
|
575
|
-
case
|
576
|
-
case
|
577
|
-
case
|
631
|
+
case 3 /* Never */:
|
632
|
+
case 7 /* Module */:
|
633
|
+
case 9 /* TypeVar */:
|
634
|
+
case 5 /* OverloadedFunction */:
|
635
|
+
case 8 /* Union */:
|
578
636
|
return undefined;
|
579
|
-
case
|
580
|
-
case
|
581
|
-
case 5 /* Function */:
|
637
|
+
case 6 /* Class */:
|
638
|
+
case 4 /* Function */:
|
582
639
|
return type.condition;
|
583
640
|
}
|
584
641
|
}
|
@@ -593,7 +650,7 @@ exports.isTypeAliasPlaceholder = isTypeAliasPlaceholder;
|
|
593
650
|
// within the specified type. It's OK if it's used indirectly as
|
594
651
|
// a type argument.
|
595
652
|
function isTypeAliasRecursive(typeAliasPlaceholder, type) {
|
596
|
-
if (type.category !==
|
653
|
+
if (type.category !== 8 /* Union */) {
|
597
654
|
if (type === typeAliasPlaceholder) {
|
598
655
|
return true;
|
599
656
|
}
|
@@ -830,7 +887,7 @@ function isCallableType(type) {
|
|
830
887
|
if (types_1.TypeBase.isInstantiable(type)) {
|
831
888
|
return true;
|
832
889
|
}
|
833
|
-
const callMember = lookUpObjectMember(type, '__call__',
|
890
|
+
const callMember = lookUpObjectMember(type, '__call__', 16 /* SkipInstanceMembers */);
|
834
891
|
return !!callMember;
|
835
892
|
}
|
836
893
|
if ((0, types_1.isUnion)(type)) {
|
@@ -898,7 +955,7 @@ exports.isTupleIndexUnambiguous = isTupleIndexUnambiguous;
|
|
898
955
|
function partiallySpecializeType(type, contextClassType, selfClass, typeClassType) {
|
899
956
|
// If the context class is not specialized (or doesn't need specialization),
|
900
957
|
// then there's no need to do any more work.
|
901
|
-
if (types_1.ClassType.isUnspecialized(contextClassType)) {
|
958
|
+
if (types_1.ClassType.isUnspecialized(contextClassType) && !selfClass) {
|
902
959
|
return type;
|
903
960
|
}
|
904
961
|
// Partially specialize the type using the specialized class type vars.
|
@@ -1127,7 +1184,7 @@ exports.lookUpClassMember = lookUpClassMember;
|
|
1127
1184
|
// If skipMroClass is defined, all MRO classes up to and including that class
|
1128
1185
|
// are skipped.
|
1129
1186
|
function* getClassMemberIterator(classType, memberName, flags = 0 /* Default */, skipMroClass) {
|
1130
|
-
const declaredTypesOnly = (flags &
|
1187
|
+
const declaredTypesOnly = (flags & 64 /* DeclaredTypesOnly */) !== 0;
|
1131
1188
|
let skippedUndeclaredType = false;
|
1132
1189
|
if ((0, types_1.isClass)(classType)) {
|
1133
1190
|
let classFlags = 0 /* Default */;
|
@@ -1142,7 +1199,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* Default */,
|
|
1142
1199
|
if (flags & 4 /* SkipObjectBaseClass */) {
|
1143
1200
|
classFlags = classFlags | 2 /* SkipObjectBaseClass */;
|
1144
1201
|
}
|
1145
|
-
if (flags &
|
1202
|
+
if (flags & 8 /* SkipTypeBaseClass */) {
|
1146
1203
|
classFlags = classFlags | 4 /* SkipTypeBaseClass */;
|
1147
1204
|
}
|
1148
1205
|
const classItr = getClassIterator(classType, classFlags, skipMroClass);
|
@@ -1169,7 +1226,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* Default */,
|
|
1169
1226
|
}
|
1170
1227
|
const memberFields = specializedMroClass.details.fields;
|
1171
1228
|
// Look at instance members first if requested.
|
1172
|
-
if ((flags &
|
1229
|
+
if ((flags & 16 /* SkipInstanceMembers */) === 0) {
|
1173
1230
|
const symbol = memberFields.get(memberName);
|
1174
1231
|
if (symbol && symbol.isInstanceMember()) {
|
1175
1232
|
const hasDeclaredType = symbol.hasTypedDeclarations();
|
@@ -1191,7 +1248,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* Default */,
|
|
1191
1248
|
}
|
1192
1249
|
}
|
1193
1250
|
// Next look at class members.
|
1194
|
-
if ((flags &
|
1251
|
+
if ((flags & 32 /* SkipClassMembers */) === 0) {
|
1195
1252
|
const symbol = memberFields.get(memberName);
|
1196
1253
|
if (symbol && symbol.isClassMember()) {
|
1197
1254
|
const hasDeclaredType = symbol.hasTypedDeclarations();
|
@@ -1490,12 +1547,12 @@ function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionC
|
|
1490
1547
|
return;
|
1491
1548
|
}
|
1492
1549
|
switch (destType.category) {
|
1493
|
-
case
|
1550
|
+
case 8 /* Union */:
|
1494
1551
|
doForEachSubtype(destType, (subtype) => {
|
1495
1552
|
setTypeArgumentsRecursive(subtype, srcType, typeVarContext, recursionCount);
|
1496
1553
|
});
|
1497
1554
|
break;
|
1498
|
-
case
|
1555
|
+
case 6 /* Class */:
|
1499
1556
|
if (destType.typeArguments) {
|
1500
1557
|
destType.typeArguments.forEach((typeArg) => {
|
1501
1558
|
setTypeArgumentsRecursive(typeArg, srcType, typeVarContext, recursionCount);
|
@@ -1507,7 +1564,7 @@ function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionC
|
|
1507
1564
|
});
|
1508
1565
|
}
|
1509
1566
|
break;
|
1510
|
-
case
|
1567
|
+
case 4 /* Function */:
|
1511
1568
|
if (destType.specializedTypes) {
|
1512
1569
|
destType.specializedTypes.parameterTypes.forEach((paramType) => {
|
1513
1570
|
setTypeArgumentsRecursive(paramType, srcType, typeVarContext, recursionCount);
|
@@ -1531,12 +1588,12 @@ function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionC
|
|
1531
1588
|
}
|
1532
1589
|
}
|
1533
1590
|
break;
|
1534
|
-
case
|
1591
|
+
case 5 /* OverloadedFunction */:
|
1535
1592
|
destType.overloads.forEach((subtype) => {
|
1536
1593
|
setTypeArgumentsRecursive(subtype, srcType, typeVarContext, recursionCount);
|
1537
1594
|
});
|
1538
1595
|
break;
|
1539
|
-
case
|
1596
|
+
case 9 /* TypeVar */:
|
1540
1597
|
if (!typeVarContext.getPrimarySignature().getTypeVar(destType)) {
|
1541
1598
|
typeVarContext.setTypeVarType(destType, srcType);
|
1542
1599
|
}
|
@@ -1729,7 +1786,7 @@ function convertToInstance(type, includeSubclasses = true) {
|
|
1729
1786
|
}
|
1730
1787
|
let result = mapSubtypes(type, (subtype) => {
|
1731
1788
|
switch (subtype.category) {
|
1732
|
-
case
|
1789
|
+
case 6 /* Class */: {
|
1733
1790
|
// Handle type[x] as a special case.
|
1734
1791
|
if (types_1.ClassType.isBuiltIn(subtype, 'type')) {
|
1735
1792
|
if (types_1.TypeBase.isInstance(subtype)) {
|
@@ -1742,26 +1799,21 @@ function convertToInstance(type, includeSubclasses = true) {
|
|
1742
1799
|
}
|
1743
1800
|
else {
|
1744
1801
|
if (subtype.typeArguments && subtype.typeArguments.length > 0) {
|
1745
|
-
|
1802
|
+
if (!(0, types_1.isAnyOrUnknown)(subtype.typeArguments[0])) {
|
1803
|
+
return convertToInstantiable(subtype.typeArguments[0]);
|
1804
|
+
}
|
1746
1805
|
}
|
1747
1806
|
}
|
1748
1807
|
}
|
1749
|
-
// Handle NoneType as a special case.
|
1750
|
-
if (types_1.TypeBase.isInstantiable(subtype) && types_1.ClassType.isBuiltIn(subtype, 'NoneType')) {
|
1751
|
-
return types_1.NoneType.createInstance();
|
1752
|
-
}
|
1753
1808
|
return types_1.ClassType.cloneAsInstance(subtype, includeSubclasses);
|
1754
1809
|
}
|
1755
|
-
case
|
1756
|
-
return types_1.NoneType.createInstance();
|
1757
|
-
}
|
1758
|
-
case 5 /* Function */: {
|
1810
|
+
case 4 /* Function */: {
|
1759
1811
|
if (types_1.TypeBase.isInstantiable(subtype)) {
|
1760
1812
|
return types_1.FunctionType.cloneAsInstance(subtype);
|
1761
1813
|
}
|
1762
1814
|
break;
|
1763
1815
|
}
|
1764
|
-
case
|
1816
|
+
case 9 /* TypeVar */: {
|
1765
1817
|
if (types_1.TypeBase.isInstantiable(subtype)) {
|
1766
1818
|
return types_1.TypeVarType.cloneAsInstance(subtype);
|
1767
1819
|
}
|
@@ -1795,16 +1847,13 @@ function convertToInstantiable(type, includeSubclasses = true) {
|
|
1795
1847
|
}
|
1796
1848
|
let result = mapSubtypes(type, (subtype) => {
|
1797
1849
|
switch (subtype.category) {
|
1798
|
-
case
|
1850
|
+
case 6 /* Class */: {
|
1799
1851
|
return types_1.ClassType.cloneAsInstantiable(subtype, includeSubclasses);
|
1800
1852
|
}
|
1801
|
-
case
|
1802
|
-
return types_1.NoneType.createType();
|
1803
|
-
}
|
1804
|
-
case 5 /* Function */: {
|
1853
|
+
case 4 /* Function */: {
|
1805
1854
|
return types_1.FunctionType.cloneAsInstantiable(subtype);
|
1806
1855
|
}
|
1807
|
-
case
|
1856
|
+
case 9 /* TypeVar */: {
|
1808
1857
|
return types_1.TypeVarType.cloneAsInstantiable(subtype);
|
1809
1858
|
}
|
1810
1859
|
}
|
@@ -2216,7 +2265,7 @@ exports.requiresSpecialization = requiresSpecialization;
|
|
2216
2265
|
function _requiresSpecialization(type, options, recursionCount = 0) {
|
2217
2266
|
var _a;
|
2218
2267
|
switch (type.category) {
|
2219
|
-
case
|
2268
|
+
case 6 /* Class */: {
|
2220
2269
|
if (types_1.ClassType.isPseudoGenericClass(type) && (options === null || options === void 0 ? void 0 : options.ignorePseudoGeneric)) {
|
2221
2270
|
return false;
|
2222
2271
|
}
|
@@ -2228,7 +2277,7 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
|
|
2228
2277
|
}
|
2229
2278
|
return types_1.ClassType.getTypeParameters(type).length > 0;
|
2230
2279
|
}
|
2231
|
-
case
|
2280
|
+
case 4 /* Function */: {
|
2232
2281
|
if (type.details.paramSpec) {
|
2233
2282
|
return true;
|
2234
2283
|
}
|
@@ -2252,13 +2301,13 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
|
|
2252
2301
|
}
|
2253
2302
|
return false;
|
2254
2303
|
}
|
2255
|
-
case
|
2304
|
+
case 5 /* OverloadedFunction */: {
|
2256
2305
|
return type.overloads.some((overload) => requiresSpecialization(overload, options, recursionCount));
|
2257
2306
|
}
|
2258
|
-
case
|
2307
|
+
case 8 /* Union */: {
|
2259
2308
|
return type.subtypes.some((subtype) => requiresSpecialization(subtype, options, recursionCount));
|
2260
2309
|
}
|
2261
|
-
case
|
2310
|
+
case 9 /* TypeVar */: {
|
2262
2311
|
// Most TypeVar types need to be specialized.
|
2263
2312
|
if (!type.details.recursiveTypeAliasName) {
|
2264
2313
|
if (type.details.isSynthesizedSelf && (options === null || options === void 0 ? void 0 : options.ignoreSelf)) {
|
@@ -2350,9 +2399,9 @@ function computeMroLinearization(classType) {
|
|
2350
2399
|
// Generic has some special-case logic (see description of __mro_entries__
|
2351
2400
|
// in PEP 560) that we need to account for here.
|
2352
2401
|
if (types_1.ClassType.isBuiltIn(baseClass, 'Generic')) {
|
2353
|
-
// If the class is a Protocol, the generic is ignored for
|
2354
|
-
// of computing the MRO.
|
2355
|
-
if (types_1.ClassType.isProtocolClass(classType)) {
|
2402
|
+
// If the class is a Protocol or TypedDict, the generic is ignored for
|
2403
|
+
// the purposes of computing the MRO.
|
2404
|
+
if (types_1.ClassType.isProtocolClass(classType) || types_1.ClassType.isTypedDictClass(classType)) {
|
2356
2405
|
return false;
|
2357
2406
|
}
|
2358
2407
|
// If the class contains any specialized generic classes after
|
@@ -2475,27 +2524,27 @@ function addDeclaringModuleNamesForType(type, moduleList, recursionCount = 0) {
|
|
2475
2524
|
}
|
2476
2525
|
};
|
2477
2526
|
switch (type.category) {
|
2478
|
-
case
|
2527
|
+
case 6 /* Class */: {
|
2479
2528
|
addIfUnique(type.details.moduleName);
|
2480
2529
|
break;
|
2481
2530
|
}
|
2482
|
-
case
|
2531
|
+
case 4 /* Function */: {
|
2483
2532
|
addIfUnique(type.details.moduleName);
|
2484
2533
|
break;
|
2485
2534
|
}
|
2486
|
-
case
|
2535
|
+
case 5 /* OverloadedFunction */: {
|
2487
2536
|
type.overloads.forEach((overload) => {
|
2488
2537
|
addDeclaringModuleNamesForType(overload, moduleList, recursionCount);
|
2489
2538
|
});
|
2490
2539
|
break;
|
2491
2540
|
}
|
2492
|
-
case
|
2541
|
+
case 8 /* Union */: {
|
2493
2542
|
doForEachSubtype(type, (subtype) => {
|
2494
2543
|
addDeclaringModuleNamesForType(subtype, moduleList, recursionCount);
|
2495
2544
|
});
|
2496
2545
|
break;
|
2497
2546
|
}
|
2498
|
-
case
|
2547
|
+
case 7 /* Module */: {
|
2499
2548
|
addIfUnique(type.moduleName);
|
2500
2549
|
break;
|
2501
2550
|
}
|
@@ -2583,7 +2632,7 @@ class TypeVarTransformer {
|
|
2583
2632
|
if ((0, types_1.isAnyOrUnknown)(type)) {
|
2584
2633
|
return type;
|
2585
2634
|
}
|
2586
|
-
if (
|
2635
|
+
if (isNoneInstance(type)) {
|
2587
2636
|
return type;
|
2588
2637
|
}
|
2589
2638
|
if ((0, types_1.isTypeVar)(type)) {
|
@@ -2963,7 +3012,9 @@ class TypeVarTransformer {
|
|
2963
3012
|
return types_1.FunctionType.cloneForSpecialization(functionType, specializedParameters, specializedInferredReturnType);
|
2964
3013
|
}
|
2965
3014
|
// Unpack the tuple and synthesize a new function in the process.
|
2966
|
-
const newFunctionType = types_1.
|
3015
|
+
const newFunctionType = types_1.TypeBase.isInstantiable(functionType)
|
3016
|
+
? types_1.FunctionType.createInstantiable(functionType.details.flags | 64 /* SynthesizedMethod */)
|
3017
|
+
: types_1.FunctionType.createSynthesizedInstance('', functionType.details.flags);
|
2967
3018
|
let insertKeywordOnlySeparator = false;
|
2968
3019
|
let swallowPositionOnlySeparator = false;
|
2969
3020
|
specializedParameters.parameterTypes.forEach((paramType, index) => {
|
@@ -2972,7 +3023,9 @@ class TypeVarTransformer {
|
|
2972
3023
|
// Unpack the tuple into individual parameters.
|
2973
3024
|
variadicTypesToUnpack.forEach((unpackedType) => {
|
2974
3025
|
types_1.FunctionType.addParameter(newFunctionType, {
|
2975
|
-
category: unpackedType.isUnbounded
|
3026
|
+
category: unpackedType.isUnbounded || (0, types_1.isVariadicTypeVar)(unpackedType.type)
|
3027
|
+
? 1 /* ArgsList */
|
3028
|
+
: 0 /* Simple */,
|
2976
3029
|
name: `__p${newFunctionType.details.parameters.length}`,
|
2977
3030
|
isNameSynthesized: true,
|
2978
3031
|
type: unpackedType.type,
|