@zzzen/pyright-internal 1.2.0-dev.20240602 → 1.2.0-dev.20240609
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.js +14 -8
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +47 -30
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +26 -34
- 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 -5
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +1 -1
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/enums.d.ts +1 -1
- package/dist/analyzer/enums.js +19 -16
- package/dist/analyzer/enums.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/patternMatching.js +4 -4
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/properties.js +2 -2
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +2 -2
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/sourceFile.js +3 -3
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +279 -209
- 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 +21 -14
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +3 -4
- package/dist/analyzer/typeUtils.js +89 -124
- 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/types.d.ts +11 -12
- package/dist/analyzer/types.js +137 -169
- 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 +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/configOptions.d.ts +2 -1
- package/dist/common/configOptions.js +12 -3
- package/dist/common/configOptions.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/languageServerBase.js +1 -1
- package/dist/languageServerBase.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 +2 -2
- package/dist/localization/package.nls.de.json +2 -2
- package/dist/localization/package.nls.en-us.json +3 -0
- package/dist/localization/package.nls.es.json +2 -2
- package/dist/localization/package.nls.fr.json +2 -2
- package/dist/localization/package.nls.it.json +2 -2
- package/dist/localization/package.nls.ja.json +2 -2
- package/dist/localization/package.nls.ko.json +3 -3
- package/dist/localization/package.nls.pl.json +2 -2
- package/dist/localization/package.nls.pt-br.json +2 -2
- package/dist/localization/package.nls.qps-ploc.json +2 -2
- package/dist/localization/package.nls.ru.json +2 -2
- package/dist/localization/package.nls.tr.json +2 -2
- package/dist/localization/package.nls.zh-cn.json +2 -2
- package/dist/localization/package.nls.zh-tw.json +2 -2
- package/dist/pyright.js +3 -0
- package/dist/pyright.js.map +1 -1
- package/dist/tests/config.test.js +2 -2
- 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/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/package.json +1 -1
package/dist/analyzer/types.d.ts
CHANGED
@@ -184,7 +184,7 @@ interface ClassDetails {
|
|
184
184
|
flags: ClassTypeFlags;
|
185
185
|
typeSourceId: TypeSourceId;
|
186
186
|
baseClasses: Type[];
|
187
|
-
mro:
|
187
|
+
mro: (ClassType | AnyType | UnknownType)[];
|
188
188
|
declaration?: ClassDeclaration | SpecialBuiltInClassDeclaration | undefined;
|
189
189
|
declaredMetaclass?: ClassType | UnknownType | undefined;
|
190
190
|
effectiveMetaclass?: ClassType | UnknownType | undefined;
|
@@ -257,7 +257,6 @@ export declare namespace ClassType {
|
|
257
257
|
function isUnspecialized(classType: ClassType): boolean;
|
258
258
|
function isSpecialBuiltIn(classType: ClassType, className?: string): boolean;
|
259
259
|
function isBuiltIn(classType: ClassType, className?: string | string[]): boolean;
|
260
|
-
function derivesFromAnyOrUnknown(classType: ClassType): boolean;
|
261
260
|
function supportsAbstractMethods(classType: ClassType): boolean;
|
262
261
|
function isDataClass(classType: ClassType): boolean;
|
263
262
|
function isSkipSynthesizedDataClassInit(classType: ClassType): boolean;
|
@@ -290,13 +289,13 @@ export declare namespace ClassType {
|
|
290
289
|
function isTupleClass(classType: ClassType): boolean;
|
291
290
|
function isReadOnlyInstanceVariables(classType: ClassType): boolean;
|
292
291
|
function getTypeParameters(classType: ClassType): TypeVarType[];
|
293
|
-
function
|
292
|
+
function derivesFromAnyOrUnknown(classType: ClassType): boolean;
|
294
293
|
function getSymbolTable(classType: ClassType): SymbolTable;
|
295
294
|
function getInheritedSlotsNames(classType: ClassType): string[] | undefined;
|
296
295
|
function isHierarchyPartiallyEvaluated(classType: ClassType): boolean;
|
297
296
|
function isSameGenericClass(classType: ClassType, type2: ClassType, recursionCount?: number): boolean;
|
298
297
|
function isDerivedFrom(subclassType: ClassType, parentClassType: ClassType, inheritanceChain?: InheritanceChain): boolean;
|
299
|
-
function getReverseMro(classType: ClassType):
|
298
|
+
function getReverseMro(classType: ClassType): (ClassType | UnknownType | AnyType)[];
|
300
299
|
}
|
301
300
|
export interface FunctionParameter {
|
302
301
|
category: ParameterCategory;
|
@@ -328,7 +327,7 @@ export declare const enum FunctionTypeFlags {
|
|
328
327
|
PyTypedDefinition = 4096,
|
329
328
|
Final = 8192,
|
330
329
|
UnannotatedParams = 16384,
|
331
|
-
|
330
|
+
GradualCallableForm = 32768,
|
332
331
|
ParamSpecValue = 65536,
|
333
332
|
PartiallyEvaluated = 131072,
|
334
333
|
Overridden = 262144,
|
@@ -349,7 +348,6 @@ interface FunctionDetails {
|
|
349
348
|
deprecatedMessage?: string | undefined;
|
350
349
|
methodClass?: ClassType | undefined;
|
351
350
|
decoratorDataClassBehaviors?: DataClassBehaviors | undefined;
|
352
|
-
paramSpec?: TypeVarType | undefined;
|
353
351
|
constructorTypeVarScopeId?: TypeVarScopeId | undefined;
|
354
352
|
higherOrderTypeVarScopeIds?: TypeVarScopeId[];
|
355
353
|
}
|
@@ -388,14 +386,15 @@ export declare namespace FunctionType {
|
|
388
386
|
function cloneAsInstance(type: FunctionType): FunctionType;
|
389
387
|
function cloneAsInstantiable(type: FunctionType): FunctionType;
|
390
388
|
function cloneForSpecialization(type: FunctionType, specializedTypes: SpecializedFunctionTypes, specializedInferredReturnType: Type | undefined): FunctionType;
|
391
|
-
function
|
389
|
+
function applyParamSpecValue(type: FunctionType, paramSpecValue: FunctionType): FunctionType;
|
392
390
|
function cloneWithNewFlags(type: FunctionType, flags: FunctionTypeFlags): FunctionType;
|
393
391
|
function cloneWithNewTypeVarScopeId(type: FunctionType, newScopeId: TypeVarScopeId, typeParameters: TypeVarType[], trackedSignatures?: SignatureWithOffsets[]): FunctionType;
|
394
392
|
function cloneWithDocString(type: FunctionType, docString?: string): FunctionType;
|
395
393
|
function cloneWithDeprecatedMessage(type: FunctionType, deprecatedMessage?: string): FunctionType;
|
396
|
-
function
|
397
|
-
function
|
398
|
-
function
|
394
|
+
function cloneRemoveParamSpecArgsKwargs(type: FunctionType, stripPositionOnlySeparator?: boolean): FunctionType;
|
395
|
+
function getParamSpecFromArgsKwargs(type: FunctionType): TypeVarType | undefined;
|
396
|
+
function addParamSpecVariadics(type: FunctionType, paramSpec: TypeVarType): void;
|
397
|
+
function addDefaultParameters(type: FunctionType, useUnknown?: boolean): void;
|
399
398
|
function addHigherOrderTypeVarScopeIds(functionType: FunctionType, scopeIds: (TypeVarScopeId | undefined)[] | TypeVarScopeId | undefined): void;
|
400
399
|
function getDefaultParameters(useUnknown?: boolean): FunctionParameter[];
|
401
400
|
function hasDefaultParameters(functionType: FunctionType): boolean;
|
@@ -414,7 +413,7 @@ export declare namespace FunctionType {
|
|
414
413
|
function isPyTypedDefinition(type: FunctionType): boolean;
|
415
414
|
function isFinal(type: FunctionType): boolean;
|
416
415
|
function hasUnannotatedParams(type: FunctionType): boolean;
|
417
|
-
function
|
416
|
+
function isGradualCallableForm(type: FunctionType): boolean;
|
418
417
|
function isParamSpecValue(type: FunctionType): boolean;
|
419
418
|
function isPartiallyEvaluated(type: FunctionType): boolean;
|
420
419
|
function isOverridden(type: FunctionType): boolean;
|
@@ -423,7 +422,7 @@ export declare namespace FunctionType {
|
|
423
422
|
function addParameter(type: FunctionType, param: FunctionParameter): void;
|
424
423
|
function addPositionOnlyParameterSeparator(type: FunctionType): void;
|
425
424
|
function addKeywordOnlyParameterSeparator(type: FunctionType): void;
|
426
|
-
function
|
425
|
+
function getEffectiveReturnType(type: FunctionType, includeInferred?: boolean): Type | undefined;
|
427
426
|
}
|
428
427
|
export interface OverloadedFunctionType extends TypeBase {
|
429
428
|
category: TypeCategory.OverloadedFunction;
|
package/dist/analyzer/types.js
CHANGED
@@ -427,11 +427,7 @@ var ClassType;
|
|
427
427
|
if (includeSubclasses) {
|
428
428
|
newClassType.includeSubclasses = true;
|
429
429
|
}
|
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;
|
430
|
+
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
431
|
if (isEmptyContainer !== undefined) {
|
436
432
|
newClassType.isEmptyContainer = isEmptyContainer;
|
437
433
|
}
|
@@ -609,10 +605,6 @@ var ClassType;
|
|
609
605
|
return true;
|
610
606
|
}
|
611
607
|
ClassType.isBuiltIn = isBuiltIn;
|
612
|
-
function derivesFromAnyOrUnknown(classType) {
|
613
|
-
return classType.details.mro.some((mroClass) => !isClass(mroClass));
|
614
|
-
}
|
615
|
-
ClassType.derivesFromAnyOrUnknown = derivesFromAnyOrUnknown;
|
616
608
|
function supportsAbstractMethods(classType) {
|
617
609
|
return !!(classType.details.flags & 2048 /* ClassTypeFlags.SupportsAbstractMethods */);
|
618
610
|
}
|
@@ -743,10 +735,10 @@ var ClassType;
|
|
743
735
|
return classType.details.typeParameters;
|
744
736
|
}
|
745
737
|
ClassType.getTypeParameters = getTypeParameters;
|
746
|
-
function
|
738
|
+
function derivesFromAnyOrUnknown(classType) {
|
747
739
|
return classType.details.mro.some((baseClass) => isAnyOrUnknown(baseClass));
|
748
740
|
}
|
749
|
-
ClassType.
|
741
|
+
ClassType.derivesFromAnyOrUnknown = derivesFromAnyOrUnknown;
|
750
742
|
function getSymbolTable(classType) {
|
751
743
|
var _a, _b;
|
752
744
|
(_b = (_a = classType.details).synthesizeMethodsDeferred) === null || _b === void 0 ? void 0 : _b.call(_a);
|
@@ -933,7 +925,7 @@ var FunctionTypeFlags;
|
|
933
925
|
// The *args and **kwargs parameters do not need to be present for this
|
934
926
|
// function to be compatible. This is used for Callable[..., x] and
|
935
927
|
// ... type arguments to ParamSpec and Concatenate.
|
936
|
-
FunctionTypeFlags[FunctionTypeFlags["
|
928
|
+
FunctionTypeFlags[FunctionTypeFlags["GradualCallableForm"] = 32768] = "GradualCallableForm";
|
937
929
|
// This function represents the value bound to a ParamSpec, so its return
|
938
930
|
// type is not meaningful.
|
939
931
|
FunctionTypeFlags[FunctionTypeFlags["ParamSpecValue"] = 65536] = "ParamSpecValue";
|
@@ -1061,89 +1053,70 @@ var FunctionType;
|
|
1061
1053
|
}
|
1062
1054
|
FunctionType.cloneForSpecialization = cloneForSpecialization;
|
1063
1055
|
// Creates a new function based on the parameters of another function.
|
1064
|
-
function
|
1065
|
-
const
|
1056
|
+
function applyParamSpecValue(type, paramSpecValue) {
|
1057
|
+
const hasPositionalOnly = paramSpecValue.details.parameters.some((param) => isPositionOnlySeparator(param));
|
1058
|
+
const newFunction = FunctionType.cloneRemoveParamSpecArgsKwargs(TypeBase.cloneType(type), hasPositionalOnly);
|
1059
|
+
const paramSpec = FunctionType.getParamSpecFromArgsKwargs(type);
|
1060
|
+
(0, debug_1.assert)(paramSpec !== undefined);
|
1066
1061
|
// 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,
|
1062
|
+
newFunction.details = { ...newFunction.details };
|
1063
|
+
newFunction.details.typeParameters = newFunction.details.typeParameters.filter((t) => !isTypeSame(t, paramSpec));
|
1064
|
+
const prevParams = Array.from(newFunction.details.parameters);
|
1065
|
+
newFunction.details.parameters = [
|
1066
|
+
...prevParams,
|
1067
|
+
...paramSpecValue.details.parameters.map((param) => {
|
1068
|
+
return {
|
1069
|
+
category: param.category,
|
1070
|
+
name: param.name,
|
1071
|
+
hasDefault: param.hasDefault,
|
1072
|
+
defaultValueExpression: param.defaultValueExpression,
|
1073
|
+
isNameSynthesized: param.isNameSynthesized,
|
1074
|
+
hasDeclaredType: true,
|
1075
|
+
type: param.type,
|
1120
1076
|
};
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1077
|
+
}),
|
1078
|
+
];
|
1079
|
+
if (newFunction.details.docString === undefined) {
|
1080
|
+
newFunction.details.docString = paramSpecValue.details.docString;
|
1081
|
+
}
|
1082
|
+
if (newFunction.details.deprecatedMessage === undefined) {
|
1083
|
+
newFunction.details.deprecatedMessage = paramSpecValue.details.deprecatedMessage;
|
1084
|
+
}
|
1085
|
+
const origFlagsMask = 256 /* FunctionTypeFlags.Overloaded */ | 65536 /* FunctionTypeFlags.ParamSpecValue */;
|
1086
|
+
newFunction.details.flags = type.details.flags & origFlagsMask;
|
1087
|
+
const methodFlagsMask = 2 /* FunctionTypeFlags.ClassMethod */ | 4 /* FunctionTypeFlags.StaticMethod */ | 1 /* FunctionTypeFlags.ConstructorMethod */;
|
1088
|
+
// If the original function was a method, use its method type. Otherwise
|
1089
|
+
// use the method type of the param spec.
|
1090
|
+
if (type.details.methodClass) {
|
1091
|
+
newFunction.details.flags |= type.details.flags & methodFlagsMask;
|
1092
|
+
}
|
1093
|
+
else {
|
1094
|
+
newFunction.details.flags |= paramSpecValue.details.flags & methodFlagsMask;
|
1095
|
+
}
|
1096
|
+
// Use the "..." flag from the param spec.
|
1097
|
+
newFunction.details.flags |= paramSpecValue.details.flags & 32768 /* FunctionTypeFlags.GradualCallableForm */;
|
1098
|
+
// Mark the function as synthesized since there is no user-defined declaration for it.
|
1099
|
+
newFunction.details.flags |= 64 /* FunctionTypeFlags.SynthesizedMethod */;
|
1100
|
+
delete newFunction.details.declaration;
|
1101
|
+
// Update the specialized parameter types as well.
|
1102
|
+
const specializedTypes = newFunction.specializedTypes;
|
1103
|
+
if (specializedTypes) {
|
1104
|
+
paramSpecValue.details.parameters.forEach((paramInfo) => {
|
1105
|
+
var _a;
|
1106
|
+
specializedTypes.parameterTypes.push(paramInfo.type);
|
1107
|
+
// Assume that the parameters introduced via paramSpec have no specialized
|
1108
|
+
// default arg types. Fall back on the original default arg type in this case.
|
1109
|
+
(_a = specializedTypes.parameterDefaultArgs) === null || _a === void 0 ? void 0 : _a.push(undefined);
|
1110
|
+
});
|
1111
|
+
}
|
1112
|
+
FunctionType.addHigherOrderTypeVarScopeIds(newFunction, paramSpecValue.details.typeVarScopeId);
|
1113
|
+
FunctionType.addHigherOrderTypeVarScopeIds(newFunction, paramSpecValue.details.higherOrderTypeVarScopeIds);
|
1114
|
+
if (!newFunction.details.methodClass && paramSpecValue.details.methodClass) {
|
1142
1115
|
newFunction.details.methodClass = paramSpecValue.details.methodClass;
|
1143
1116
|
}
|
1144
1117
|
return newFunction;
|
1145
1118
|
}
|
1146
|
-
FunctionType.
|
1119
|
+
FunctionType.applyParamSpecValue = applyParamSpecValue;
|
1147
1120
|
function cloneWithNewFlags(type, flags) {
|
1148
1121
|
const newFunction = TypeBase.cloneType(type);
|
1149
1122
|
// Make a shallow clone of the details.
|
@@ -1179,82 +1152,92 @@ var FunctionType;
|
|
1179
1152
|
return newFunction;
|
1180
1153
|
}
|
1181
1154
|
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
|
-
}
|
1155
|
+
// If the function ends with "*args: P.args, **kwargs: P.kwargs", this function
|
1156
|
+
// returns a new function that is a clone of the input function with the
|
1157
|
+
// *args and **kwargs parameters removed. If stripPositionOnlySeparator is true,
|
1158
|
+
// a trailing positional-only separator will be removed.
|
1159
|
+
function cloneRemoveParamSpecArgsKwargs(type, stripPositionOnlySeparator = false) {
|
1160
|
+
const paramCount = type.details.parameters.length;
|
1161
|
+
if (paramCount < 2) {
|
1162
|
+
return type;
|
1209
1163
|
}
|
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;
|
1164
|
+
const argsParam = type.details.parameters[paramCount - 2];
|
1165
|
+
const kwargsParam = type.details.parameters[paramCount - 1];
|
1166
|
+
if (argsParam.category !== 1 /* ParameterCategory.ArgsList */ ||
|
1167
|
+
kwargsParam.category !== 2 /* ParameterCategory.KwargsDict */) {
|
1168
|
+
return type;
|
1224
1169
|
}
|
1225
|
-
|
1226
|
-
|
1170
|
+
const argsType = FunctionType.getEffectiveParameterType(type, paramCount - 2);
|
1171
|
+
const kwargsType = FunctionType.getEffectiveParameterType(type, paramCount - 1);
|
1172
|
+
if (!isParamSpec(argsType) || !isParamSpec(kwargsType) || !isTypeSame(argsType, kwargsType)) {
|
1173
|
+
return type;
|
1227
1174
|
}
|
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);
|
1175
|
+
const newFunction = TypeBase.cloneType(type);
|
1234
1176
|
// Make a shallow clone of the details.
|
1235
1177
|
newFunction.details = { ...type.details };
|
1236
|
-
|
1237
|
-
|
1178
|
+
const details = newFunction.details;
|
1179
|
+
let paramsToDrop = 2;
|
1180
|
+
// If the last remaining parameter is a position-only separator, remove it as well.
|
1181
|
+
// Always remove it if it's the only remaining parameter.
|
1182
|
+
if (paramCount >= 3 && isPositionOnlySeparator(details.parameters[paramCount - 3])) {
|
1183
|
+
if (paramCount === 3 || stripPositionOnlySeparator) {
|
1184
|
+
paramsToDrop = 3;
|
1185
|
+
}
|
1186
|
+
}
|
1187
|
+
// Remove the last parameters, which are the *args and **kwargs.
|
1188
|
+
details.parameters = details.parameters.slice(0, details.parameters.length - paramsToDrop);
|
1238
1189
|
if (type.specializedTypes) {
|
1239
1190
|
newFunction.specializedTypes = { ...type.specializedTypes };
|
1240
|
-
newFunction.specializedTypes.parameterTypes = newFunction.specializedTypes.parameterTypes.slice(0, newFunction.specializedTypes.parameterTypes.length -
|
1191
|
+
newFunction.specializedTypes.parameterTypes = newFunction.specializedTypes.parameterTypes.slice(0, newFunction.specializedTypes.parameterTypes.length - paramsToDrop);
|
1241
1192
|
if (newFunction.specializedTypes.parameterDefaultArgs) {
|
1242
1193
|
newFunction.specializedTypes.parameterDefaultArgs =
|
1243
|
-
newFunction.specializedTypes.parameterDefaultArgs.slice(0, newFunction.specializedTypes.parameterDefaultArgs.length -
|
1194
|
+
newFunction.specializedTypes.parameterDefaultArgs.slice(0, newFunction.specializedTypes.parameterDefaultArgs.length - paramsToDrop);
|
1244
1195
|
}
|
1245
1196
|
}
|
1246
|
-
if (!newFunction.details.paramSpec) {
|
1247
|
-
newFunction.details.paramSpec = paramSpec;
|
1248
|
-
}
|
1249
1197
|
if (type.inferredReturnType) {
|
1250
1198
|
newFunction.inferredReturnType = type.inferredReturnType;
|
1251
1199
|
}
|
1252
1200
|
return newFunction;
|
1253
1201
|
}
|
1254
|
-
FunctionType.
|
1255
|
-
function
|
1202
|
+
FunctionType.cloneRemoveParamSpecArgsKwargs = cloneRemoveParamSpecArgsKwargs;
|
1203
|
+
// If the function ends with "*args: P.args, **kwargs: P.kwargs", this function
|
1204
|
+
// returns P. Otherwise, it returns undefined.
|
1205
|
+
function getParamSpecFromArgsKwargs(type) {
|
1206
|
+
const params = type.details.parameters;
|
1207
|
+
if (params.length < 2) {
|
1208
|
+
return undefined;
|
1209
|
+
}
|
1210
|
+
const secondLastParam = params[params.length - 2];
|
1211
|
+
const lastParam = params[params.length - 1];
|
1212
|
+
if (secondLastParam.category === 1 /* ParameterCategory.ArgsList */ &&
|
1213
|
+
isTypeVar(secondLastParam.type) &&
|
1214
|
+
secondLastParam.type.paramSpecAccess === 'args' &&
|
1215
|
+
lastParam.category === 2 /* ParameterCategory.KwargsDict */ &&
|
1216
|
+
isTypeVar(lastParam.type) &&
|
1217
|
+
lastParam.type.paramSpecAccess === 'kwargs') {
|
1218
|
+
return TypeVarType.cloneForParamSpecAccess(secondLastParam.type, /* access */ undefined);
|
1219
|
+
}
|
1220
|
+
return undefined;
|
1221
|
+
}
|
1222
|
+
FunctionType.getParamSpecFromArgsKwargs = getParamSpecFromArgsKwargs;
|
1223
|
+
function addParamSpecVariadics(type, paramSpec) {
|
1224
|
+
FunctionType.addParameter(type, {
|
1225
|
+
category: 1 /* ParameterCategory.ArgsList */,
|
1226
|
+
name: 'args',
|
1227
|
+
type: TypeVarType.cloneForParamSpecAccess(paramSpec, 'args'),
|
1228
|
+
hasDeclaredType: true,
|
1229
|
+
});
|
1230
|
+
FunctionType.addParameter(type, {
|
1231
|
+
category: 2 /* ParameterCategory.KwargsDict */,
|
1232
|
+
name: 'kwargs',
|
1233
|
+
type: TypeVarType.cloneForParamSpecAccess(paramSpec, 'kwargs'),
|
1234
|
+
hasDeclaredType: true,
|
1235
|
+
});
|
1236
|
+
}
|
1237
|
+
FunctionType.addParamSpecVariadics = addParamSpecVariadics;
|
1238
|
+
function addDefaultParameters(type, useUnknown = false) {
|
1256
1239
|
getDefaultParameters(useUnknown).forEach((param) => {
|
1257
|
-
FunctionType.addParameter(
|
1240
|
+
FunctionType.addParameter(type, param);
|
1258
1241
|
});
|
1259
1242
|
}
|
1260
1243
|
FunctionType.addDefaultParameters = addDefaultParameters;
|
@@ -1386,10 +1369,10 @@ var FunctionType;
|
|
1386
1369
|
return (type.details.flags & 16384 /* FunctionTypeFlags.UnannotatedParams */) !== 0;
|
1387
1370
|
}
|
1388
1371
|
FunctionType.hasUnannotatedParams = hasUnannotatedParams;
|
1389
|
-
function
|
1390
|
-
return (type.details.flags & 32768 /* FunctionTypeFlags.
|
1372
|
+
function isGradualCallableForm(type) {
|
1373
|
+
return (type.details.flags & 32768 /* FunctionTypeFlags.GradualCallableForm */) !== 0;
|
1391
1374
|
}
|
1392
|
-
FunctionType.
|
1375
|
+
FunctionType.isGradualCallableForm = isGradualCallableForm;
|
1393
1376
|
function isParamSpecValue(type) {
|
1394
1377
|
return (type.details.flags & 65536 /* FunctionTypeFlags.ParamSpecValue */) !== 0;
|
1395
1378
|
}
|
@@ -1443,7 +1426,7 @@ var FunctionType;
|
|
1443
1426
|
});
|
1444
1427
|
}
|
1445
1428
|
FunctionType.addKeywordOnlyParameterSeparator = addKeywordOnlyParameterSeparator;
|
1446
|
-
function
|
1429
|
+
function getEffectiveReturnType(type, includeInferred = true) {
|
1447
1430
|
var _a;
|
1448
1431
|
if ((_a = type.specializedTypes) === null || _a === void 0 ? void 0 : _a.returnType) {
|
1449
1432
|
return type.specializedTypes.returnType;
|
@@ -1456,7 +1439,7 @@ var FunctionType;
|
|
1456
1439
|
}
|
1457
1440
|
return undefined;
|
1458
1441
|
}
|
1459
|
-
FunctionType.
|
1442
|
+
FunctionType.getEffectiveReturnType = getEffectiveReturnType;
|
1460
1443
|
})(FunctionType || (exports.FunctionType = FunctionType = {}));
|
1461
1444
|
var OverloadedFunctionType;
|
1462
1445
|
(function (OverloadedFunctionType) {
|
@@ -2102,8 +2085,7 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2102
2085
|
return false;
|
2103
2086
|
}
|
2104
2087
|
// If one function is ... and the other is not, they are not the same.
|
2105
|
-
if (FunctionType.
|
2106
|
-
FunctionType.shouldSkipArgsKwargsCompatibilityCheck(functionType2)) {
|
2088
|
+
if (FunctionType.isGradualCallableForm(type1) !== FunctionType.isGradualCallableForm(functionType2)) {
|
2107
2089
|
return false;
|
2108
2090
|
}
|
2109
2091
|
const positionOnlyIndex1 = params1.findIndex((param) => isPositionOnlySeparator(param));
|
@@ -2137,20 +2119,6 @@ function isTypeSame(type1, type2, options = {}, recursionCount = 0) {
|
|
2137
2119
|
return false;
|
2138
2120
|
}
|
2139
2121
|
}
|
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
2122
|
// Make sure the return types match.
|
2155
2123
|
let return1Type = type1.details.declaredReturnType;
|
2156
2124
|
if (type1.specializedTypes && type1.specializedTypes.returnType) {
|