@zzzen/pyright-internal 1.2.0-dev.20240602 → 1.2.0-dev.20240616
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/binder.d.ts +3 -1
- package/dist/analyzer/binder.js +23 -11
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +50 -33
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +27 -38
- 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 +2 -7
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.d.ts +0 -1
- package/dist/analyzer/dataClasses.js +52 -78
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/decorators.d.ts +2 -1
- package/dist/analyzer/decorators.js +34 -39
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/docStringUtils.d.ts +0 -1
- package/dist/analyzer/docStringUtils.js +1 -6
- package/dist/analyzer/docStringUtils.js.map +1 -1
- package/dist/analyzer/enums.d.ts +1 -1
- package/dist/analyzer/enums.js +20 -17
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.js +11 -9
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/namedTuples.js +3 -3
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +6 -7
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +1 -13
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -1
- package/dist/analyzer/patternMatching.js +4 -4
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/properties.js +4 -4
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +16 -5
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.js +27 -48
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +2 -1
- package/dist/analyzer/sourceFile.js +7 -5
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.d.ts +1 -0
- package/dist/analyzer/typeDocStringUtils.js +8 -1
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +746 -667
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -3
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +3 -2
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +25 -16
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +3 -5
- package/dist/analyzer/typeUtils.js +96 -144
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +4 -0
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typedDicts.js +6 -6
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +51 -54
- package/dist/analyzer/types.js +221 -260
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +1 -1
- package/dist/backgroundAnalysisBase.js +3 -3
- package/dist/commands/dumpFileDebugInfoCommand.js +17 -25
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/cancellationUtils.d.ts +1 -0
- package/dist/common/cancellationUtils.js +15 -1
- package/dist/common/cancellationUtils.js.map +1 -1
- package/dist/common/configOptions.d.ts +2 -1
- package/dist/common/configOptions.js +13 -4
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/docStringService.d.ts +15 -0
- package/dist/common/docStringService.js +38 -0
- package/dist/common/docStringService.js.map +1 -0
- package/dist/common/envVarUtils.js +3 -1
- package/dist/common/envVarUtils.js.map +1 -1
- package/dist/common/extensibility.d.ts +1 -7
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/languageServerInterface.d.ts +1 -2
- package/dist/common/languageServerInterface.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +3 -3
- package/dist/common/realFileSystem.js +6 -6
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceKeys.d.ts +2 -0
- package/dist/common/serviceKeys.js +1 -0
- package/dist/common/serviceKeys.js.map +1 -1
- package/dist/common/serviceProvider.js +3 -0
- package/dist/common/serviceProvider.js.map +1 -1
- package/dist/common/serviceProviderExtensions.d.ts +2 -0
- package/dist/common/serviceProviderExtensions.js +8 -0
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/common/stringUtils.d.ts +1 -0
- package/dist/common/stringUtils.js +5 -1
- package/dist/common/stringUtils.js.map +1 -1
- package/dist/common/uri/uriUtils.d.ts +1 -1
- package/dist/common/uri/uriUtils.js +1 -1
- package/dist/common/uri/uriUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +1 -1
- package/dist/languageServerBase.js +3 -3
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +1 -0
- package/dist/languageService/completionProvider.js +16 -7
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.d.ts +2 -1
- package/dist/languageService/completionProviderUtils.js +6 -4
- package/dist/languageService/completionProviderUtils.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +2 -1
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +2 -1
- package/dist/languageService/hoverProvider.js +7 -5
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.d.ts +3 -1
- package/dist/languageService/signatureHelpProvider.js +8 -6
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.js +1 -1
- package/dist/localization/localize.d.ts +6 -0
- package/dist/localization/localize.js +3 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +4 -3
- package/dist/localization/package.nls.de.json +4 -3
- package/dist/localization/package.nls.en-us.json +3 -0
- package/dist/localization/package.nls.es.json +3 -2
- package/dist/localization/package.nls.fr.json +4 -3
- package/dist/localization/package.nls.it.json +4 -3
- package/dist/localization/package.nls.ja.json +4 -3
- package/dist/localization/package.nls.ko.json +5 -4
- package/dist/localization/package.nls.pl.json +4 -3
- package/dist/localization/package.nls.pt-br.json +4 -3
- package/dist/localization/package.nls.qps-ploc.json +4 -3
- package/dist/localization/package.nls.ru.json +4 -3
- package/dist/localization/package.nls.tr.json +4 -3
- package/dist/localization/package.nls.zh-cn.json +4 -3
- package/dist/localization/package.nls.zh-tw.json +4 -3
- package/dist/pyright.js +3 -0
- package/dist/pyright.js.map +1 -1
- package/dist/tests/checker.test.js +8 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/config.test.js +3 -3
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/diagnosticOverrides.test.js +7 -6
- package/dist/tests/diagnosticOverrides.test.js.map +1 -1
- package/dist/tests/docStringConversion.test.d.ts +2 -1
- package/dist/tests/docStringConversion.test.js +300 -293
- package/dist/tests/docStringConversion.test.js.map +1 -1
- package/dist/tests/fourslash/rename.externallyHidden.fourslash.js +2 -2
- package/dist/tests/fourslash/rename.externallyHidden.fourslash.js.map +1 -1
- package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.js +1 -1
- package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +2 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/pathUtils.test.js +6 -0
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/signatureHelp.test.js +2 -1
- package/dist/tests/signatureHelp.test.js.map +1 -1
- package/dist/tests/testState.test.js +1 -1
- package/dist/tests/testState.test.js.map +1 -1
- package/dist/tests/testUtils.js +1 -1
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +8 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +7 -3
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +15 -9
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +2 -2
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/tests/uri.test.js +6 -0
- package/dist/tests/uri.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +1 -1
- package/package.json +1 -1
- package/dist/tests/docStringUtils.test.d.ts +0 -1
- package/dist/tests/docStringUtils.test.js +0 -74
- package/dist/tests/docStringUtils.test.js.map +0 -1
package/dist/analyzer/types.js
CHANGED
@@ -281,91 +281,74 @@ var ClassTypeFlags;
|
|
281
281
|
// formally as a class. Examples include 'Optional'
|
282
282
|
// and 'Union'.
|
283
283
|
ClassTypeFlags[ClassTypeFlags["SpecialBuiltIn"] = 2] = "SpecialBuiltIn";
|
284
|
-
// Introduced in Python 3.7 - class either derives directly
|
285
|
-
// from NamedTuple or has a @dataclass class decorator.
|
286
|
-
ClassTypeFlags[ClassTypeFlags["DataClass"] = 4] = "DataClass";
|
287
|
-
// Indicates that the dataclass is frozen.
|
288
|
-
ClassTypeFlags[ClassTypeFlags["FrozenDataClass"] = 8] = "FrozenDataClass";
|
289
|
-
// Flags that control whether methods should be
|
290
|
-
// synthesized for a dataclass class.
|
291
|
-
ClassTypeFlags[ClassTypeFlags["SkipSynthesizedDataClassInit"] = 16] = "SkipSynthesizedDataClassInit";
|
292
|
-
ClassTypeFlags[ClassTypeFlags["SkipSynthesizedDataClassEq"] = 32] = "SkipSynthesizedDataClassEq";
|
293
|
-
ClassTypeFlags[ClassTypeFlags["SynthesizedDataClassOrder"] = 64] = "SynthesizedDataClassOrder";
|
294
284
|
// Introduced in PEP 589, TypedDict classes provide a way
|
295
285
|
// to specify type hints for dictionaries with different
|
296
286
|
// value types and a limited set of static keys.
|
297
|
-
ClassTypeFlags[ClassTypeFlags["TypedDictClass"] =
|
287
|
+
ClassTypeFlags[ClassTypeFlags["TypedDictClass"] = 4] = "TypedDictClass";
|
298
288
|
// Used in conjunction with TypedDictClass, indicates that
|
299
289
|
// the TypedDict class is marked "closed".
|
300
|
-
ClassTypeFlags[ClassTypeFlags["TypedDictMarkedClosed"] =
|
290
|
+
ClassTypeFlags[ClassTypeFlags["TypedDictMarkedClosed"] = 8] = "TypedDictMarkedClosed";
|
301
291
|
// Used in conjunction with TypedDictClass, indicates that
|
302
292
|
// the TypedDict class is marked "closed" or one or more of
|
303
293
|
// its superclasses is marked "closed".
|
304
|
-
ClassTypeFlags[ClassTypeFlags["TypedDictEffectivelyClosed"] =
|
294
|
+
ClassTypeFlags[ClassTypeFlags["TypedDictEffectivelyClosed"] = 16] = "TypedDictEffectivelyClosed";
|
305
295
|
// Used in conjunction with TypedDictClass, indicates that
|
306
296
|
// the dictionary values can be omitted.
|
307
|
-
ClassTypeFlags[ClassTypeFlags["CanOmitDictValues"] =
|
297
|
+
ClassTypeFlags[ClassTypeFlags["CanOmitDictValues"] = 32] = "CanOmitDictValues";
|
308
298
|
// The class derives from a class that has the ABCMeta
|
309
299
|
// metaclass. Such classes are allowed to contain
|
310
300
|
// @abstractmethod decorators.
|
311
|
-
ClassTypeFlags[ClassTypeFlags["SupportsAbstractMethods"] =
|
301
|
+
ClassTypeFlags[ClassTypeFlags["SupportsAbstractMethods"] = 64] = "SupportsAbstractMethods";
|
312
302
|
// Derives from property class and has the semantics of
|
313
303
|
// a property (with optional setter, deleter).
|
314
|
-
ClassTypeFlags[ClassTypeFlags["PropertyClass"] =
|
304
|
+
ClassTypeFlags[ClassTypeFlags["PropertyClass"] = 128] = "PropertyClass";
|
315
305
|
// The class is decorated with a "@final" decorator
|
316
306
|
// indicating that it cannot be subclassed.
|
317
|
-
ClassTypeFlags[ClassTypeFlags["Final"] =
|
307
|
+
ClassTypeFlags[ClassTypeFlags["Final"] = 256] = "Final";
|
318
308
|
// The class derives directly from "Protocol".
|
319
|
-
ClassTypeFlags[ClassTypeFlags["ProtocolClass"] =
|
309
|
+
ClassTypeFlags[ClassTypeFlags["ProtocolClass"] = 512] = "ProtocolClass";
|
320
310
|
// A class whose constructor (__init__ method) does not have
|
321
311
|
// annotated types and is treated as though each parameter
|
322
312
|
// is a generic type for purposes of type inference.
|
323
|
-
ClassTypeFlags[ClassTypeFlags["PseudoGenericClass"] =
|
313
|
+
ClassTypeFlags[ClassTypeFlags["PseudoGenericClass"] = 1024] = "PseudoGenericClass";
|
324
314
|
// A protocol class that is "runtime checkable" can be used
|
325
315
|
// in an isinstance call.
|
326
|
-
ClassTypeFlags[ClassTypeFlags["RuntimeCheckable"] =
|
316
|
+
ClassTypeFlags[ClassTypeFlags["RuntimeCheckable"] = 2048] = "RuntimeCheckable";
|
327
317
|
// The type is defined in the typing_extensions.pyi file.
|
328
|
-
ClassTypeFlags[ClassTypeFlags["TypingExtensionClass"] =
|
318
|
+
ClassTypeFlags[ClassTypeFlags["TypingExtensionClass"] = 4096] = "TypingExtensionClass";
|
329
319
|
// The class type is in the process of being evaluated and
|
330
320
|
// is not yet complete. This allows us to detect cases where
|
331
321
|
// the class refers to itself (e.g. uses itself as a type
|
332
322
|
// argument to one of its generic base classes).
|
333
|
-
ClassTypeFlags[ClassTypeFlags["PartiallyEvaluated"] =
|
323
|
+
ClassTypeFlags[ClassTypeFlags["PartiallyEvaluated"] = 8192] = "PartiallyEvaluated";
|
334
324
|
// The class or one of its ancestors defines a __class_getitem__
|
335
325
|
// method that is used for subscripting. This is not set if the
|
336
326
|
// class is generic, and therefore supports standard subscripting
|
337
327
|
// semantics.
|
338
|
-
ClassTypeFlags[ClassTypeFlags["HasCustomClassGetItem"] =
|
328
|
+
ClassTypeFlags[ClassTypeFlags["HasCustomClassGetItem"] = 16384] = "HasCustomClassGetItem";
|
339
329
|
// The tuple class uses a variadic type parameter and requires
|
340
330
|
// special-case handling of its type arguments.
|
341
|
-
ClassTypeFlags[ClassTypeFlags["TupleClass"] =
|
331
|
+
ClassTypeFlags[ClassTypeFlags["TupleClass"] = 32768] = "TupleClass";
|
342
332
|
// The class has a metaclass of EnumMeta or derives from
|
343
333
|
// a class that has this metaclass.
|
344
|
-
ClassTypeFlags[ClassTypeFlags["EnumClass"] =
|
345
|
-
// For dataclasses, should __init__ method always be generated
|
346
|
-
// with keyword-only parameters?
|
347
|
-
ClassTypeFlags[ClassTypeFlags["DataClassKeywordOnlyParams"] = 4194304] = "DataClassKeywordOnlyParams";
|
334
|
+
ClassTypeFlags[ClassTypeFlags["EnumClass"] = 65536] = "EnumClass";
|
348
335
|
// Properties that are defined using the @classmethod decorator.
|
349
|
-
ClassTypeFlags[ClassTypeFlags["ClassProperty"] =
|
336
|
+
ClassTypeFlags[ClassTypeFlags["ClassProperty"] = 131072] = "ClassProperty";
|
350
337
|
// Class is declared within a type stub file.
|
351
|
-
ClassTypeFlags[ClassTypeFlags["DefinedInStub"] =
|
338
|
+
ClassTypeFlags[ClassTypeFlags["DefinedInStub"] = 262144] = "DefinedInStub";
|
352
339
|
// Class does not allow writing or deleting its instance variables
|
353
340
|
// through a member access. Used with named tuples.
|
354
|
-
ClassTypeFlags[ClassTypeFlags["ReadOnlyInstanceVariables"] =
|
355
|
-
// For dataclasses, should __slots__ be generated?
|
356
|
-
ClassTypeFlags[ClassTypeFlags["GenerateDataClassSlots"] = 67108864] = "GenerateDataClassSlots";
|
357
|
-
// For dataclasses, should __hash__ be generated?
|
358
|
-
ClassTypeFlags[ClassTypeFlags["SynthesizeDataClassUnsafeHash"] = 134217728] = "SynthesizeDataClassUnsafeHash";
|
341
|
+
ClassTypeFlags[ClassTypeFlags["ReadOnlyInstanceVariables"] = 524288] = "ReadOnlyInstanceVariables";
|
359
342
|
// Decorated with @type_check_only.
|
360
|
-
ClassTypeFlags[ClassTypeFlags["TypeCheckOnly"] =
|
343
|
+
ClassTypeFlags[ClassTypeFlags["TypeCheckOnly"] = 1048576] = "TypeCheckOnly";
|
361
344
|
// Created with the NewType call.
|
362
|
-
ClassTypeFlags[ClassTypeFlags["NewTypeClass"] =
|
345
|
+
ClassTypeFlags[ClassTypeFlags["NewTypeClass"] = 2097152] = "NewTypeClass";
|
363
346
|
// Class is allowed to be used as an implicit type alias even
|
364
347
|
// though it is not defined using a `class` statement.
|
365
|
-
ClassTypeFlags[ClassTypeFlags["ValidTypeAliasClass"] =
|
348
|
+
ClassTypeFlags[ClassTypeFlags["ValidTypeAliasClass"] = 4194304] = "ValidTypeAliasClass";
|
366
349
|
// A special form is not compatible with type[T] and cannot
|
367
350
|
// be directly instantiated.
|
368
|
-
ClassTypeFlags[ClassTypeFlags["SpecialFormClass"] =
|
351
|
+
ClassTypeFlags[ClassTypeFlags["SpecialFormClass"] = 8388608] = "SpecialFormClass";
|
369
352
|
})(ClassTypeFlags || (exports.ClassTypeFlags = ClassTypeFlags = {}));
|
370
353
|
var ClassType;
|
371
354
|
(function (ClassType) {
|
@@ -427,11 +410,7 @@ var ClassType;
|
|
427
410
|
if (includeSubclasses) {
|
428
411
|
newClassType.includeSubclasses = true;
|
429
412
|
}
|
430
|
-
newClassType.tupleTypeArguments = tupleTypeArguments
|
431
|
-
? tupleTypeArguments.map((t) => isNever(t.type)
|
432
|
-
? { type: UnknownType.create(), isUnbounded: t.isUnbounded, isOptional: t.isOptional }
|
433
|
-
: t)
|
434
|
-
: undefined;
|
413
|
+
newClassType.tupleTypeArguments = tupleTypeArguments === null || tupleTypeArguments === void 0 ? void 0 : tupleTypeArguments.map((t) => isNever(t.type) ? { type: UnknownType.create(), isUnbounded: t.isUnbounded, isOptional: t.isOptional } : t);
|
435
414
|
if (isEmptyContainer !== undefined) {
|
436
415
|
newClassType.isEmptyContainer = isEmptyContainer;
|
437
416
|
}
|
@@ -456,6 +435,12 @@ var ClassType;
|
|
456
435
|
return newClassType;
|
457
436
|
}
|
458
437
|
ClassType.cloneWithLiteral = cloneWithLiteral;
|
438
|
+
function cloneForDeprecatedInstance(type, deprecatedMessage) {
|
439
|
+
const newClassType = TypeBase.cloneType(type);
|
440
|
+
newClassType.deprecatedInstanceMessage = deprecatedMessage;
|
441
|
+
return newClassType;
|
442
|
+
}
|
443
|
+
ClassType.cloneForDeprecatedInstance = cloneForDeprecatedInstance;
|
459
444
|
function cloneForTypingAlias(classType, aliasName) {
|
460
445
|
const newClassType = TypeBase.cloneType(classType);
|
461
446
|
newClassType.aliasName = aliasName;
|
@@ -609,104 +594,107 @@ var ClassType;
|
|
609
594
|
return true;
|
610
595
|
}
|
611
596
|
ClassType.isBuiltIn = isBuiltIn;
|
612
|
-
function derivesFromAnyOrUnknown(classType) {
|
613
|
-
return classType.details.mro.some((mroClass) => !isClass(mroClass));
|
614
|
-
}
|
615
|
-
ClassType.derivesFromAnyOrUnknown = derivesFromAnyOrUnknown;
|
616
597
|
function supportsAbstractMethods(classType) {
|
617
|
-
return !!(classType.details.flags &
|
598
|
+
return !!(classType.details.flags & 64 /* ClassTypeFlags.SupportsAbstractMethods */);
|
618
599
|
}
|
619
600
|
ClassType.supportsAbstractMethods = supportsAbstractMethods;
|
620
601
|
function isDataClass(classType) {
|
621
|
-
return !!
|
602
|
+
return !!classType.details.dataClassBehaviors;
|
622
603
|
}
|
623
604
|
ClassType.isDataClass = isDataClass;
|
624
|
-
function
|
625
|
-
|
605
|
+
function isDataClassSkipGenerateInit(classType) {
|
606
|
+
var _a;
|
607
|
+
return !!((_a = classType.details.dataClassBehaviors) === null || _a === void 0 ? void 0 : _a.skipGenerateInit);
|
626
608
|
}
|
627
|
-
ClassType.
|
628
|
-
function
|
629
|
-
|
609
|
+
ClassType.isDataClassSkipGenerateInit = isDataClassSkipGenerateInit;
|
610
|
+
function isDataClassSkipGenerateEq(classType) {
|
611
|
+
var _a;
|
612
|
+
return !!((_a = classType.details.dataClassBehaviors) === null || _a === void 0 ? void 0 : _a.skipGenerateEq);
|
630
613
|
}
|
631
|
-
ClassType.
|
632
|
-
function
|
633
|
-
|
614
|
+
ClassType.isDataClassSkipGenerateEq = isDataClassSkipGenerateEq;
|
615
|
+
function isDataClassFrozen(classType) {
|
616
|
+
var _a;
|
617
|
+
return !!((_a = classType.details.dataClassBehaviors) === null || _a === void 0 ? void 0 : _a.frozen);
|
634
618
|
}
|
635
|
-
ClassType.
|
636
|
-
function
|
637
|
-
|
619
|
+
ClassType.isDataClassFrozen = isDataClassFrozen;
|
620
|
+
function isDataClassGenerateOrder(classType) {
|
621
|
+
var _a;
|
622
|
+
return !!((_a = classType.details.dataClassBehaviors) === null || _a === void 0 ? void 0 : _a.generateOrder);
|
638
623
|
}
|
639
|
-
ClassType.
|
640
|
-
function
|
641
|
-
|
624
|
+
ClassType.isDataClassGenerateOrder = isDataClassGenerateOrder;
|
625
|
+
function isDataClassKeywordOnly(classType) {
|
626
|
+
var _a;
|
627
|
+
return !!((_a = classType.details.dataClassBehaviors) === null || _a === void 0 ? void 0 : _a.keywordOnly);
|
642
628
|
}
|
643
|
-
ClassType.
|
644
|
-
function
|
645
|
-
|
629
|
+
ClassType.isDataClassKeywordOnly = isDataClassKeywordOnly;
|
630
|
+
function isDataClassGenerateSlots(classType) {
|
631
|
+
var _a;
|
632
|
+
return !!((_a = classType.details.dataClassBehaviors) === null || _a === void 0 ? void 0 : _a.generateSlots);
|
646
633
|
}
|
647
|
-
ClassType.
|
648
|
-
function
|
649
|
-
|
634
|
+
ClassType.isDataClassGenerateSlots = isDataClassGenerateSlots;
|
635
|
+
function isDataClassGenerateHash(classType) {
|
636
|
+
var _a;
|
637
|
+
return !!((_a = classType.details.dataClassBehaviors) === null || _a === void 0 ? void 0 : _a.generateHash);
|
650
638
|
}
|
651
|
-
ClassType.
|
639
|
+
ClassType.isDataClassGenerateHash = isDataClassGenerateHash;
|
652
640
|
function isTypeCheckOnly(classType) {
|
653
|
-
return !!(classType.details.flags &
|
641
|
+
return !!(classType.details.flags & 1048576 /* ClassTypeFlags.TypeCheckOnly */);
|
654
642
|
}
|
655
643
|
ClassType.isTypeCheckOnly = isTypeCheckOnly;
|
656
644
|
function isNewTypeClass(classType) {
|
657
|
-
return !!(classType.details.flags &
|
645
|
+
return !!(classType.details.flags & 2097152 /* ClassTypeFlags.NewTypeClass */);
|
658
646
|
}
|
659
647
|
ClassType.isNewTypeClass = isNewTypeClass;
|
660
648
|
function isValidTypeAliasClass(classType) {
|
661
|
-
return !!(classType.details.flags &
|
649
|
+
return !!(classType.details.flags & 4194304 /* ClassTypeFlags.ValidTypeAliasClass */);
|
662
650
|
}
|
663
651
|
ClassType.isValidTypeAliasClass = isValidTypeAliasClass;
|
664
652
|
function isSpecialFormClass(classType) {
|
665
|
-
return !!(classType.details.flags &
|
653
|
+
return !!(classType.details.flags & 8388608 /* ClassTypeFlags.SpecialFormClass */);
|
666
654
|
}
|
667
655
|
ClassType.isSpecialFormClass = isSpecialFormClass;
|
668
656
|
function isTypedDictClass(classType) {
|
669
|
-
return !!(classType.details.flags &
|
657
|
+
return !!(classType.details.flags & 4 /* ClassTypeFlags.TypedDictClass */);
|
670
658
|
}
|
671
659
|
ClassType.isTypedDictClass = isTypedDictClass;
|
672
660
|
function isCanOmitDictValues(classType) {
|
673
|
-
return !!(classType.details.flags &
|
661
|
+
return !!(classType.details.flags & 32 /* ClassTypeFlags.CanOmitDictValues */);
|
674
662
|
}
|
675
663
|
ClassType.isCanOmitDictValues = isCanOmitDictValues;
|
676
664
|
function isTypedDictMarkedClosed(classType) {
|
677
|
-
return !!(classType.details.flags &
|
665
|
+
return !!(classType.details.flags & 8 /* ClassTypeFlags.TypedDictMarkedClosed */);
|
678
666
|
}
|
679
667
|
ClassType.isTypedDictMarkedClosed = isTypedDictMarkedClosed;
|
680
668
|
function isTypedDictEffectivelyClosed(classType) {
|
681
|
-
return !!(classType.details.flags &
|
669
|
+
return !!(classType.details.flags & 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */);
|
682
670
|
}
|
683
671
|
ClassType.isTypedDictEffectivelyClosed = isTypedDictEffectivelyClosed;
|
684
672
|
function isEnumClass(classType) {
|
685
|
-
return !!(classType.details.flags &
|
673
|
+
return !!(classType.details.flags & 65536 /* ClassTypeFlags.EnumClass */);
|
686
674
|
}
|
687
675
|
ClassType.isEnumClass = isEnumClass;
|
688
676
|
function isPropertyClass(classType) {
|
689
|
-
return !!(classType.details.flags &
|
677
|
+
return !!(classType.details.flags & 128 /* ClassTypeFlags.PropertyClass */);
|
690
678
|
}
|
691
679
|
ClassType.isPropertyClass = isPropertyClass;
|
692
680
|
function isClassProperty(classType) {
|
693
|
-
return !!(classType.details.flags &
|
681
|
+
return !!(classType.details.flags & 131072 /* ClassTypeFlags.ClassProperty */);
|
694
682
|
}
|
695
683
|
ClassType.isClassProperty = isClassProperty;
|
696
684
|
function isFinal(classType) {
|
697
|
-
return !!(classType.details.flags &
|
685
|
+
return !!(classType.details.flags & 256 /* ClassTypeFlags.Final */);
|
698
686
|
}
|
699
687
|
ClassType.isFinal = isFinal;
|
700
688
|
function isProtocolClass(classType) {
|
701
|
-
return !!(classType.details.flags &
|
689
|
+
return !!(classType.details.flags & 512 /* ClassTypeFlags.ProtocolClass */);
|
702
690
|
}
|
703
691
|
ClassType.isProtocolClass = isProtocolClass;
|
704
692
|
function isDefinedInStub(classType) {
|
705
|
-
return !!(classType.details.flags &
|
693
|
+
return !!(classType.details.flags & 262144 /* ClassTypeFlags.DefinedInStub */);
|
706
694
|
}
|
707
695
|
ClassType.isDefinedInStub = isDefinedInStub;
|
708
696
|
function isPseudoGenericClass(classType) {
|
709
|
-
return !!(classType.details.flags &
|
697
|
+
return !!(classType.details.flags & 1024 /* ClassTypeFlags.PseudoGenericClass */);
|
710
698
|
}
|
711
699
|
ClassType.isPseudoGenericClass = isPseudoGenericClass;
|
712
700
|
function getDataClassEntries(classType) {
|
@@ -716,37 +704,37 @@ var ClassType;
|
|
716
704
|
}
|
717
705
|
ClassType.getDataClassEntries = getDataClassEntries;
|
718
706
|
function isRuntimeCheckable(classType) {
|
719
|
-
return !!(classType.details.flags &
|
707
|
+
return !!(classType.details.flags & 2048 /* ClassTypeFlags.RuntimeCheckable */);
|
720
708
|
}
|
721
709
|
ClassType.isRuntimeCheckable = isRuntimeCheckable;
|
722
710
|
function isTypingExtensionClass(classType) {
|
723
|
-
return !!(classType.details.flags &
|
711
|
+
return !!(classType.details.flags & 4096 /* ClassTypeFlags.TypingExtensionClass */);
|
724
712
|
}
|
725
713
|
ClassType.isTypingExtensionClass = isTypingExtensionClass;
|
726
714
|
function isPartiallyEvaluated(classType) {
|
727
|
-
return !!(classType.details.flags &
|
715
|
+
return !!(classType.details.flags & 8192 /* ClassTypeFlags.PartiallyEvaluated */);
|
728
716
|
}
|
729
717
|
ClassType.isPartiallyEvaluated = isPartiallyEvaluated;
|
730
718
|
function hasCustomClassGetItem(classType) {
|
731
|
-
return !!(classType.details.flags &
|
719
|
+
return !!(classType.details.flags & 16384 /* ClassTypeFlags.HasCustomClassGetItem */);
|
732
720
|
}
|
733
721
|
ClassType.hasCustomClassGetItem = hasCustomClassGetItem;
|
734
722
|
function isTupleClass(classType) {
|
735
|
-
return !!(classType.details.flags &
|
723
|
+
return !!(classType.details.flags & 32768 /* ClassTypeFlags.TupleClass */);
|
736
724
|
}
|
737
725
|
ClassType.isTupleClass = isTupleClass;
|
738
726
|
function isReadOnlyInstanceVariables(classType) {
|
739
|
-
return !!(classType.details.flags &
|
727
|
+
return !!(classType.details.flags & 524288 /* ClassTypeFlags.ReadOnlyInstanceVariables */);
|
740
728
|
}
|
741
729
|
ClassType.isReadOnlyInstanceVariables = isReadOnlyInstanceVariables;
|
742
730
|
function getTypeParameters(classType) {
|
743
731
|
return classType.details.typeParameters;
|
744
732
|
}
|
745
733
|
ClassType.getTypeParameters = getTypeParameters;
|
746
|
-
function
|
734
|
+
function derivesFromAnyOrUnknown(classType) {
|
747
735
|
return classType.details.mro.some((baseClass) => isAnyOrUnknown(baseClass));
|
748
736
|
}
|
749
|
-
ClassType.
|
737
|
+
ClassType.derivesFromAnyOrUnknown = derivesFromAnyOrUnknown;
|
750
738
|
function getSymbolTable(classType) {
|
751
739
|
var _a, _b;
|
752
740
|
(_b = (_a = classType.details).synthesizeMethodsDeferred) === null || _b === void 0 ? void 0 : _b.call(_a);
|
@@ -933,7 +921,7 @@ var FunctionTypeFlags;
|
|
933
921
|
// The *args and **kwargs parameters do not need to be present for this
|
934
922
|
// function to be compatible. This is used for Callable[..., x] and
|
935
923
|
// ... type arguments to ParamSpec and Concatenate.
|
936
|
-
FunctionTypeFlags[FunctionTypeFlags["
|
924
|
+
FunctionTypeFlags[FunctionTypeFlags["GradualCallableForm"] = 32768] = "GradualCallableForm";
|
937
925
|
// This function represents the value bound to a ParamSpec, so its return
|
938
926
|
// type is not meaningful.
|
939
927
|
FunctionTypeFlags[FunctionTypeFlags["ParamSpecValue"] = 65536] = "ParamSpecValue";
|
@@ -982,10 +970,11 @@ var FunctionType;
|
|
982
970
|
// version of _functionDetails.
|
983
971
|
function clone(type, stripFirstParam = false, boundToType, boundTypeVarScopeId) {
|
984
972
|
var _a;
|
985
|
-
const newFunction =
|
973
|
+
const newFunction = TypeBase.cloneType(type);
|
986
974
|
newFunction.details = { ...type.details };
|
987
|
-
newFunction.boundToType = boundToType !== null && boundToType !== void 0 ? boundToType : type.boundToType;
|
988
975
|
newFunction.preBoundFlags = newFunction.details.flags;
|
976
|
+
newFunction.boundToType = boundToType;
|
977
|
+
newFunction.boundTypeVarScopeId = boundTypeVarScopeId;
|
989
978
|
if (stripFirstParam) {
|
990
979
|
if (type.details.parameters.length > 0) {
|
991
980
|
if (type.details.parameters[0].category === 0 /* ParameterCategory.Simple */) {
|
@@ -1020,7 +1009,6 @@ var FunctionType;
|
|
1020
1009
|
};
|
1021
1010
|
}
|
1022
1011
|
newFunction.inferredReturnType = type.inferredReturnType;
|
1023
|
-
newFunction.boundTypeVarScopeId = boundTypeVarScopeId !== null && boundTypeVarScopeId !== void 0 ? boundTypeVarScopeId : type.boundTypeVarScopeId;
|
1024
1012
|
return newFunction;
|
1025
1013
|
}
|
1026
1014
|
FunctionType.clone = clone;
|
@@ -1047,103 +1035,81 @@ var FunctionType;
|
|
1047
1035
|
// specialized types. The clone shares the _functionDetails
|
1048
1036
|
// with the object being cloned.
|
1049
1037
|
function cloneForSpecialization(type, specializedTypes, specializedInferredReturnType) {
|
1050
|
-
const newFunction =
|
1051
|
-
newFunction.details = type.details;
|
1038
|
+
const newFunction = TypeBase.cloneType(type);
|
1052
1039
|
(0, debug_1.assert)(specializedTypes.parameterTypes.length === type.details.parameters.length);
|
1053
1040
|
if (specializedTypes.parameterDefaultArgs) {
|
1054
1041
|
(0, debug_1.assert)(specializedTypes.parameterDefaultArgs.length === type.details.parameters.length);
|
1055
1042
|
}
|
1056
1043
|
newFunction.specializedTypes = specializedTypes;
|
1057
|
-
|
1058
|
-
newFunction.inferredReturnType = specializedInferredReturnType;
|
1059
|
-
}
|
1044
|
+
newFunction.inferredReturnType = specializedInferredReturnType;
|
1060
1045
|
return newFunction;
|
1061
1046
|
}
|
1062
1047
|
FunctionType.cloneForSpecialization = cloneForSpecialization;
|
1063
1048
|
// Creates a new function based on the parameters of another function.
|
1064
|
-
function
|
1065
|
-
const
|
1049
|
+
function applyParamSpecValue(type, paramSpecValue) {
|
1050
|
+
const hasPositionalOnly = paramSpecValue.details.parameters.some((param) => isPositionOnlySeparator(param));
|
1051
|
+
const newFunction = FunctionType.cloneRemoveParamSpecArgsKwargs(TypeBase.cloneType(type), hasPositionalOnly);
|
1052
|
+
const paramSpec = FunctionType.getParamSpecFromArgsKwargs(type);
|
1053
|
+
(0, debug_1.assert)(paramSpec !== undefined);
|
1066
1054
|
// Make a shallow clone of the details.
|
1067
|
-
newFunction.details = { ...
|
1068
|
-
newFunction.details.typeParameters = newFunction.details.typeParameters.filter((t) => !
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
droppedLastParam = true;
|
1082
|
-
}
|
1083
|
-
}
|
1084
|
-
newFunction.details.parameters = [
|
1085
|
-
...typeParameters,
|
1086
|
-
...paramSpecValue.details.parameters.map((param) => {
|
1087
|
-
return {
|
1088
|
-
category: param.category,
|
1089
|
-
name: param.name,
|
1090
|
-
hasDefault: param.hasDefault,
|
1091
|
-
defaultValueExpression: param.defaultValueExpression,
|
1092
|
-
isNameSynthesized: param.isNameSynthesized,
|
1093
|
-
hasDeclaredType: true,
|
1094
|
-
type: param.type,
|
1095
|
-
};
|
1096
|
-
}),
|
1097
|
-
];
|
1098
|
-
if (newFunction.details.docString === undefined) {
|
1099
|
-
newFunction.details.docString = paramSpecValue.details.docString;
|
1100
|
-
}
|
1101
|
-
if (newFunction.details.deprecatedMessage === undefined) {
|
1102
|
-
newFunction.details.deprecatedMessage = paramSpecValue.details.deprecatedMessage;
|
1103
|
-
}
|
1104
|
-
newFunction.details.flags =
|
1105
|
-
(paramSpecValue.details.flags &
|
1106
|
-
(2 /* FunctionTypeFlags.ClassMethod */ |
|
1107
|
-
4 /* FunctionTypeFlags.StaticMethod */ |
|
1108
|
-
1 /* FunctionTypeFlags.ConstructorMethod */ |
|
1109
|
-
256 /* FunctionTypeFlags.Overloaded */ |
|
1110
|
-
32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */)) |
|
1111
|
-
64 /* FunctionTypeFlags.SynthesizedMethod */;
|
1112
|
-
if (FunctionType.isParamSpecValue(type)) {
|
1113
|
-
newFunction.details.flags |= 65536 /* FunctionTypeFlags.ParamSpecValue */;
|
1114
|
-
}
|
1115
|
-
// Update the specialized parameter types as well.
|
1116
|
-
if (type.specializedTypes) {
|
1117
|
-
newFunction.specializedTypes = {
|
1118
|
-
parameterTypes: Array.from(type.specializedTypes.parameterTypes),
|
1119
|
-
returnType: type.specializedTypes.returnType,
|
1055
|
+
newFunction.details = { ...newFunction.details };
|
1056
|
+
newFunction.details.typeParameters = newFunction.details.typeParameters.filter((t) => !isTypeSame(t, paramSpec));
|
1057
|
+
const prevParams = Array.from(newFunction.details.parameters);
|
1058
|
+
newFunction.details.parameters = [
|
1059
|
+
...prevParams,
|
1060
|
+
...paramSpecValue.details.parameters.map((param) => {
|
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,
|
1120
1069
|
};
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1070
|
+
}),
|
1071
|
+
];
|
1072
|
+
if (newFunction.details.docString === undefined) {
|
1073
|
+
newFunction.details.docString = paramSpecValue.details.docString;
|
1074
|
+
}
|
1075
|
+
if (newFunction.details.deprecatedMessage === undefined) {
|
1076
|
+
newFunction.details.deprecatedMessage = paramSpecValue.details.deprecatedMessage;
|
1077
|
+
}
|
1078
|
+
const origFlagsMask = 256 /* FunctionTypeFlags.Overloaded */ | 65536 /* FunctionTypeFlags.ParamSpecValue */;
|
1079
|
+
newFunction.details.flags = type.details.flags & origFlagsMask;
|
1080
|
+
const methodFlagsMask = 2 /* FunctionTypeFlags.ClassMethod */ | 4 /* FunctionTypeFlags.StaticMethod */ | 1 /* FunctionTypeFlags.ConstructorMethod */;
|
1081
|
+
// If the original function was a method, use its method type. Otherwise
|
1082
|
+
// use the method type of the param spec.
|
1083
|
+
if (type.details.methodClass) {
|
1084
|
+
newFunction.details.flags |= type.details.flags & methodFlagsMask;
|
1085
|
+
}
|
1086
|
+
else {
|
1087
|
+
newFunction.details.flags |= paramSpecValue.details.flags & methodFlagsMask;
|
1088
|
+
}
|
1089
|
+
// Use the "..." flag from the param spec.
|
1090
|
+
newFunction.details.flags |= paramSpecValue.details.flags & 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
1091
|
+
// Mark the function as synthesized since there is no user-defined declaration for it.
|
1092
|
+
newFunction.details.flags |= 64 /* FunctionTypeFlags.SynthesizedMethod */;
|
1093
|
+
delete newFunction.details.declaration;
|
1094
|
+
// Update the specialized parameter types as well.
|
1095
|
+
const specializedTypes = newFunction.specializedTypes;
|
1096
|
+
if (specializedTypes) {
|
1097
|
+
paramSpecValue.details.parameters.forEach((paramInfo) => {
|
1098
|
+
var _a;
|
1099
|
+
specializedTypes.parameterTypes.push(paramInfo.type);
|
1100
|
+
// Assume that the parameters introduced via paramSpec have no specialized
|
1101
|
+
// default arg types. Fall back on the original default arg type in this case.
|
1102
|
+
(_a = specializedTypes.parameterDefaultArgs) === null || _a === void 0 ? void 0 : _a.push(undefined);
|
1103
|
+
});
|
1104
|
+
}
|
1105
|
+
FunctionType.addHigherOrderTypeVarScopeIds(newFunction, paramSpecValue.details.typeVarScopeId);
|
1106
|
+
FunctionType.addHigherOrderTypeVarScopeIds(newFunction, paramSpecValue.details.higherOrderTypeVarScopeIds);
|
1107
|
+
if (!newFunction.details.methodClass && paramSpecValue.details.methodClass) {
|
1142
1108
|
newFunction.details.methodClass = paramSpecValue.details.methodClass;
|
1143
1109
|
}
|
1144
1110
|
return newFunction;
|
1145
1111
|
}
|
1146
|
-
FunctionType.
|
1112
|
+
FunctionType.applyParamSpecValue = applyParamSpecValue;
|
1147
1113
|
function cloneWithNewFlags(type, flags) {
|
1148
1114
|
const newFunction = TypeBase.cloneType(type);
|
1149
1115
|
// Make a shallow clone of the details.
|
@@ -1179,82 +1145,92 @@ var FunctionType;
|
|
1179
1145
|
return newFunction;
|
1180
1146
|
}
|
1181
1147
|
FunctionType.cloneWithDeprecatedMessage = cloneWithDeprecatedMessage;
|
1182
|
-
//
|
1183
|
-
//
|
1184
|
-
//
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
newFunction.details.parameters = newFunction.details.parameters.slice(0, newFunction.details.parameters.length - 2);
|
1191
|
-
if (newFunction.specializedTypes) {
|
1192
|
-
newFunction.specializedTypes.parameterTypes = newFunction.specializedTypes.parameterTypes.slice(0, newFunction.specializedTypes.parameterTypes.length - 2);
|
1193
|
-
}
|
1194
|
-
// Update the flags of the function.
|
1195
|
-
newFunction.details.flags &= ~32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
|
1196
|
-
if (paramSpecValue.details.flags & 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */) {
|
1197
|
-
newFunction.details.flags |= 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
|
1198
|
-
}
|
1199
|
-
// If there is a position-only separator in the captured param spec signature,
|
1200
|
-
// remove the position-only separator in the existing signature. Otherwise,
|
1201
|
-
// we'll end up with redundant position-only separators.
|
1202
|
-
if (paramSpecValue.details.parameters.some((entry) => isPositionOnlySeparator(entry))) {
|
1203
|
-
if (newFunction.details.parameters.length > 0) {
|
1204
|
-
const lastParam = newFunction.details.parameters[newFunction.details.parameters.length - 1];
|
1205
|
-
if (isPositionOnlySeparator(lastParam)) {
|
1206
|
-
newFunction.details.parameters.pop();
|
1207
|
-
}
|
1208
|
-
}
|
1148
|
+
// If the function ends with "*args: P.args, **kwargs: P.kwargs", this function
|
1149
|
+
// returns a new function that is a clone of the input function with the
|
1150
|
+
// *args and **kwargs parameters removed. If stripPositionOnlySeparator is true,
|
1151
|
+
// a trailing positional-only separator will be removed.
|
1152
|
+
function cloneRemoveParamSpecArgsKwargs(type, stripPositionOnlySeparator = false) {
|
1153
|
+
const paramCount = type.details.parameters.length;
|
1154
|
+
if (paramCount < 2) {
|
1155
|
+
return type;
|
1209
1156
|
}
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
defaultValueExpression: param.defaultValueExpression,
|
1216
|
-
isNameSynthesized: param.isNameSynthesized,
|
1217
|
-
hasDeclaredType: true,
|
1218
|
-
type: param.type,
|
1219
|
-
});
|
1220
|
-
});
|
1221
|
-
newFunction.details.paramSpec = paramSpecValue.details.paramSpec;
|
1222
|
-
if (!newFunction.details.docString) {
|
1223
|
-
newFunction.details.docString = paramSpecValue.details.docString;
|
1157
|
+
const argsParam = type.details.parameters[paramCount - 2];
|
1158
|
+
const kwargsParam = type.details.parameters[paramCount - 1];
|
1159
|
+
if (argsParam.category !== 1 /* ParameterCategory.ArgsList */ ||
|
1160
|
+
kwargsParam.category !== 2 /* ParameterCategory.KwargsDict */) {
|
1161
|
+
return type;
|
1224
1162
|
}
|
1225
|
-
|
1226
|
-
|
1163
|
+
const argsType = FunctionType.getEffectiveParameterType(type, paramCount - 2);
|
1164
|
+
const kwargsType = FunctionType.getEffectiveParameterType(type, paramCount - 1);
|
1165
|
+
if (!isParamSpec(argsType) || !isParamSpec(kwargsType) || !isTypeSame(argsType, kwargsType)) {
|
1166
|
+
return type;
|
1227
1167
|
}
|
1228
|
-
|
1229
|
-
return newFunction;
|
1230
|
-
}
|
1231
|
-
FunctionType.cloneForParamSpecApplication = cloneForParamSpecApplication;
|
1232
|
-
function cloneRemoveParamSpecVariadics(type, paramSpec) {
|
1233
|
-
const newFunction = create(type.details.name, type.details.fullName, type.details.moduleName, type.details.flags, type.flags, type.details.docString);
|
1168
|
+
const newFunction = TypeBase.cloneType(type);
|
1234
1169
|
// Make a shallow clone of the details.
|
1235
1170
|
newFunction.details = { ...type.details };
|
1236
|
-
|
1237
|
-
|
1171
|
+
const details = newFunction.details;
|
1172
|
+
let paramsToDrop = 2;
|
1173
|
+
// If the last remaining parameter is a position-only separator, remove it as well.
|
1174
|
+
// Always remove it if it's the only remaining parameter.
|
1175
|
+
if (paramCount >= 3 && isPositionOnlySeparator(details.parameters[paramCount - 3])) {
|
1176
|
+
if (paramCount === 3 || stripPositionOnlySeparator) {
|
1177
|
+
paramsToDrop = 3;
|
1178
|
+
}
|
1179
|
+
}
|
1180
|
+
// Remove the last parameters, which are the *args and **kwargs.
|
1181
|
+
details.parameters = details.parameters.slice(0, details.parameters.length - paramsToDrop);
|
1238
1182
|
if (type.specializedTypes) {
|
1239
1183
|
newFunction.specializedTypes = { ...type.specializedTypes };
|
1240
|
-
newFunction.specializedTypes.parameterTypes = newFunction.specializedTypes.parameterTypes.slice(0, newFunction.specializedTypes.parameterTypes.length -
|
1184
|
+
newFunction.specializedTypes.parameterTypes = newFunction.specializedTypes.parameterTypes.slice(0, newFunction.specializedTypes.parameterTypes.length - paramsToDrop);
|
1241
1185
|
if (newFunction.specializedTypes.parameterDefaultArgs) {
|
1242
1186
|
newFunction.specializedTypes.parameterDefaultArgs =
|
1243
|
-
newFunction.specializedTypes.parameterDefaultArgs.slice(0, newFunction.specializedTypes.parameterDefaultArgs.length -
|
1187
|
+
newFunction.specializedTypes.parameterDefaultArgs.slice(0, newFunction.specializedTypes.parameterDefaultArgs.length - paramsToDrop);
|
1244
1188
|
}
|
1245
1189
|
}
|
1246
|
-
if (!newFunction.details.paramSpec) {
|
1247
|
-
newFunction.details.paramSpec = paramSpec;
|
1248
|
-
}
|
1249
1190
|
if (type.inferredReturnType) {
|
1250
1191
|
newFunction.inferredReturnType = type.inferredReturnType;
|
1251
1192
|
}
|
1252
1193
|
return newFunction;
|
1253
1194
|
}
|
1254
|
-
FunctionType.
|
1255
|
-
function
|
1195
|
+
FunctionType.cloneRemoveParamSpecArgsKwargs = cloneRemoveParamSpecArgsKwargs;
|
1196
|
+
// If the function ends with "*args: P.args, **kwargs: P.kwargs", this function
|
1197
|
+
// returns P. Otherwise, it returns undefined.
|
1198
|
+
function getParamSpecFromArgsKwargs(type) {
|
1199
|
+
const params = type.details.parameters;
|
1200
|
+
if (params.length < 2) {
|
1201
|
+
return undefined;
|
1202
|
+
}
|
1203
|
+
const secondLastParam = params[params.length - 2];
|
1204
|
+
const lastParam = params[params.length - 1];
|
1205
|
+
if (secondLastParam.category === 1 /* ParameterCategory.ArgsList */ &&
|
1206
|
+
isTypeVar(secondLastParam.type) &&
|
1207
|
+
secondLastParam.type.paramSpecAccess === 'args' &&
|
1208
|
+
lastParam.category === 2 /* ParameterCategory.KwargsDict */ &&
|
1209
|
+
isTypeVar(lastParam.type) &&
|
1210
|
+
lastParam.type.paramSpecAccess === 'kwargs') {
|
1211
|
+
return TypeVarType.cloneForParamSpecAccess(secondLastParam.type, /* access */ undefined);
|
1212
|
+
}
|
1213
|
+
return undefined;
|
1214
|
+
}
|
1215
|
+
FunctionType.getParamSpecFromArgsKwargs = getParamSpecFromArgsKwargs;
|
1216
|
+
function addParamSpecVariadics(type, paramSpec) {
|
1217
|
+
FunctionType.addParameter(type, {
|
1218
|
+
category: 1 /* ParameterCategory.ArgsList */,
|
1219
|
+
name: 'args',
|
1220
|
+
type: TypeVarType.cloneForParamSpecAccess(paramSpec, 'args'),
|
1221
|
+
hasDeclaredType: true,
|
1222
|
+
});
|
1223
|
+
FunctionType.addParameter(type, {
|
1224
|
+
category: 2 /* ParameterCategory.KwargsDict */,
|
1225
|
+
name: 'kwargs',
|
1226
|
+
type: TypeVarType.cloneForParamSpecAccess(paramSpec, 'kwargs'),
|
1227
|
+
hasDeclaredType: true,
|
1228
|
+
});
|
1229
|
+
}
|
1230
|
+
FunctionType.addParamSpecVariadics = addParamSpecVariadics;
|
1231
|
+
function addDefaultParameters(type, useUnknown = false) {
|
1256
1232
|
getDefaultParameters(useUnknown).forEach((param) => {
|
1257
|
-
FunctionType.addParameter(
|
1233
|
+
FunctionType.addParameter(type, param);
|
1258
1234
|
});
|
1259
1235
|
}
|
1260
1236
|
FunctionType.addDefaultParameters = addDefaultParameters;
|
@@ -1386,10 +1362,10 @@ var FunctionType;
|
|
1386
1362
|
return (type.details.flags & 16384 /* FunctionTypeFlags.UnannotatedParams */) !== 0;
|
1387
1363
|
}
|
1388
1364
|
FunctionType.hasUnannotatedParams = hasUnannotatedParams;
|
1389
|
-
function
|
1390
|
-
return (type.details.flags & 32768 /* FunctionTypeFlags.
|
1365
|
+
function isGradualCallableForm(type) {
|
1366
|
+
return (type.details.flags & 32768 /* FunctionTypeFlags.GradualCallableForm */) !== 0;
|
1391
1367
|
}
|
1392
|
-
FunctionType.
|
1368
|
+
FunctionType.isGradualCallableForm = isGradualCallableForm;
|
1393
1369
|
function isParamSpecValue(type) {
|
1394
1370
|
return (type.details.flags & 65536 /* FunctionTypeFlags.ParamSpecValue */) !== 0;
|
1395
1371
|
}
|
@@ -1443,7 +1419,7 @@ var FunctionType;
|
|
1443
1419
|
});
|
1444
1420
|
}
|
1445
1421
|
FunctionType.addKeywordOnlyParameterSeparator = addKeywordOnlyParameterSeparator;
|
1446
|
-
function
|
1422
|
+
function getEffectiveReturnType(type, includeInferred = true) {
|
1447
1423
|
var _a;
|
1448
1424
|
if ((_a = type.specializedTypes) === null || _a === void 0 ? void 0 : _a.returnType) {
|
1449
1425
|
return type.specializedTypes.returnType;
|
@@ -1456,7 +1432,7 @@ var FunctionType;
|
|
1456
1432
|
}
|
1457
1433
|
return undefined;
|
1458
1434
|
}
|
1459
|
-
FunctionType.
|
1435
|
+
FunctionType.getEffectiveReturnType = getEffectiveReturnType;
|
1460
1436
|
})(FunctionType || (exports.FunctionType = FunctionType = {}));
|
1461
1437
|
var OverloadedFunctionType;
|
1462
1438
|
(function (OverloadedFunctionType) {
|
@@ -2102,8 +2078,7 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2102
2078
|
return false;
|
2103
2079
|
}
|
2104
2080
|
// If one function is ... and the other is not, they are not the same.
|
2105
|
-
if (FunctionType.
|
2106
|
-
FunctionType.shouldSkipArgsKwargsCompatibilityCheck(functionType2)) {
|
2081
|
+
if (FunctionType.isGradualCallableForm(type1) !== FunctionType.isGradualCallableForm(functionType2)) {
|
2107
2082
|
return false;
|
2108
2083
|
}
|
2109
2084
|
const positionOnlyIndex1 = params1.findIndex((param) => isPositionOnlySeparator(param));
|
@@ -2137,20 +2112,6 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2137
2112
|
return false;
|
2138
2113
|
}
|
2139
2114
|
}
|
2140
|
-
// If the functions have ParamSpecs associated with them, make sure those match.
|
2141
|
-
const paramSpec1 = type1.details.paramSpec;
|
2142
|
-
const paramSpec2 = functionType2.details.paramSpec;
|
2143
|
-
if (paramSpec1) {
|
2144
|
-
if (!paramSpec2) {
|
2145
|
-
return false;
|
2146
|
-
}
|
2147
|
-
if (!isTypeSame(paramSpec1, paramSpec2, options, recursionCount)) {
|
2148
|
-
return false;
|
2149
|
-
}
|
2150
|
-
}
|
2151
|
-
else if (paramSpec2) {
|
2152
|
-
return false;
|
2153
|
-
}
|
2154
2115
|
// Make sure the return types match.
|
2155
2116
|
let return1Type = type1.details.declaredReturnType;
|
2156
2117
|
if (type1.specializedTypes && type1.specializedTypes.returnType) {
|