@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.
Files changed (95) hide show
  1. package/dist/analyzer/binder.js +14 -8
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.js +47 -30
  4. package/dist/analyzer/checker.js.map +1 -1
  5. package/dist/analyzer/constraintSolver.js +26 -34
  6. package/dist/analyzer/constraintSolver.js.map +1 -1
  7. package/dist/analyzer/constructorTransform.js +1 -1
  8. package/dist/analyzer/constructorTransform.js.map +1 -1
  9. package/dist/analyzer/constructors.js +2 -5
  10. package/dist/analyzer/constructors.js.map +1 -1
  11. package/dist/analyzer/dataClasses.js +1 -1
  12. package/dist/analyzer/dataClasses.js.map +1 -1
  13. package/dist/analyzer/enums.d.ts +1 -1
  14. package/dist/analyzer/enums.js +19 -16
  15. package/dist/analyzer/enums.js.map +1 -1
  16. package/dist/analyzer/operations.js +6 -7
  17. package/dist/analyzer/operations.js.map +1 -1
  18. package/dist/analyzer/parameterUtils.js +1 -13
  19. package/dist/analyzer/parameterUtils.js.map +1 -1
  20. package/dist/analyzer/patternMatching.js +4 -4
  21. package/dist/analyzer/patternMatching.js.map +1 -1
  22. package/dist/analyzer/properties.js +2 -2
  23. package/dist/analyzer/properties.js.map +1 -1
  24. package/dist/analyzer/protocols.js +2 -2
  25. package/dist/analyzer/protocols.js.map +1 -1
  26. package/dist/analyzer/sourceFile.js +3 -3
  27. package/dist/analyzer/sourceFile.js.map +1 -1
  28. package/dist/analyzer/typeEvaluator.js +279 -209
  29. package/dist/analyzer/typeEvaluator.js.map +1 -1
  30. package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -3
  31. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  32. package/dist/analyzer/typeGuards.js +3 -2
  33. package/dist/analyzer/typeGuards.js.map +1 -1
  34. package/dist/analyzer/typePrinter.js +21 -14
  35. package/dist/analyzer/typePrinter.js.map +1 -1
  36. package/dist/analyzer/typeUtils.d.ts +3 -4
  37. package/dist/analyzer/typeUtils.js +89 -124
  38. package/dist/analyzer/typeUtils.js.map +1 -1
  39. package/dist/analyzer/typeVarContext.js +4 -0
  40. package/dist/analyzer/typeVarContext.js.map +1 -1
  41. package/dist/analyzer/types.d.ts +11 -12
  42. package/dist/analyzer/types.js +137 -169
  43. package/dist/analyzer/types.js.map +1 -1
  44. package/dist/backgroundAnalysisBase.d.ts +1 -1
  45. package/dist/backgroundAnalysisBase.js +3 -3
  46. package/dist/commands/dumpFileDebugInfoCommand.js +1 -1
  47. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  48. package/dist/common/configOptions.d.ts +2 -1
  49. package/dist/common/configOptions.js +12 -3
  50. package/dist/common/configOptions.js.map +1 -1
  51. package/dist/common/realFileSystem.d.ts +3 -3
  52. package/dist/common/realFileSystem.js +6 -6
  53. package/dist/common/realFileSystem.js.map +1 -1
  54. package/dist/languageServerBase.js +1 -1
  55. package/dist/languageServerBase.js.map +1 -1
  56. package/dist/languageService/workspaceSymbolProvider.js +1 -1
  57. package/dist/localization/localize.d.ts +6 -0
  58. package/dist/localization/localize.js +3 -0
  59. package/dist/localization/localize.js.map +1 -1
  60. package/dist/localization/package.nls.cs.json +2 -2
  61. package/dist/localization/package.nls.de.json +2 -2
  62. package/dist/localization/package.nls.en-us.json +3 -0
  63. package/dist/localization/package.nls.es.json +2 -2
  64. package/dist/localization/package.nls.fr.json +2 -2
  65. package/dist/localization/package.nls.it.json +2 -2
  66. package/dist/localization/package.nls.ja.json +2 -2
  67. package/dist/localization/package.nls.ko.json +3 -3
  68. package/dist/localization/package.nls.pl.json +2 -2
  69. package/dist/localization/package.nls.pt-br.json +2 -2
  70. package/dist/localization/package.nls.qps-ploc.json +2 -2
  71. package/dist/localization/package.nls.ru.json +2 -2
  72. package/dist/localization/package.nls.tr.json +2 -2
  73. package/dist/localization/package.nls.zh-cn.json +2 -2
  74. package/dist/localization/package.nls.zh-tw.json +2 -2
  75. package/dist/pyright.js +3 -0
  76. package/dist/pyright.js.map +1 -1
  77. package/dist/tests/config.test.js +2 -2
  78. package/dist/tests/config.test.js.map +1 -1
  79. package/dist/tests/diagnosticOverrides.test.js +7 -6
  80. package/dist/tests/diagnosticOverrides.test.js.map +1 -1
  81. package/dist/tests/testState.test.js +1 -1
  82. package/dist/tests/testState.test.js.map +1 -1
  83. package/dist/tests/testUtils.js +1 -1
  84. package/dist/tests/testUtils.js.map +1 -1
  85. package/dist/tests/typeEvaluator2.test.js +4 -0
  86. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  87. package/dist/tests/typeEvaluator3.test.js +8 -0
  88. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  89. package/dist/tests/typeEvaluator4.test.js +7 -3
  90. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  91. package/dist/tests/typeEvaluator7.test.js +15 -9
  92. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  93. package/dist/tests/typePrinter.test.js +2 -2
  94. package/dist/tests/typePrinter.test.js.map +1 -1
  95. package/package.json +1 -1
@@ -184,7 +184,7 @@ interface ClassDetails {
184
184
  flags: ClassTypeFlags;
185
185
  typeSourceId: TypeSourceId;
186
186
  baseClasses: Type[];
187
- mro: Type[];
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 hasUnknownBaseClass(classType: ClassType): boolean;
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): Type[];
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
- SkipArgsKwargsCompatibilityCheck = 32768,
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 cloneForParamSpec(type: FunctionType, paramSpecValue: FunctionType | undefined): FunctionType;
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 cloneForParamSpecApplication(type: FunctionType, paramSpecValue: FunctionType): FunctionType;
397
- function cloneRemoveParamSpecVariadics(type: FunctionType, paramSpec: TypeVarType): FunctionType;
398
- function addDefaultParameters(functionType: FunctionType, useUnknown?: boolean): void;
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 shouldSkipArgsKwargsCompatibilityCheck(type: FunctionType): boolean;
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 getSpecializedReturnType(type: FunctionType, includeInferred?: boolean): Type | undefined;
425
+ function getEffectiveReturnType(type: FunctionType, includeInferred?: boolean): Type | undefined;
427
426
  }
428
427
  export interface OverloadedFunctionType extends TypeBase {
429
428
  category: TypeCategory.OverloadedFunction;
@@ -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 hasUnknownBaseClass(classType) {
738
+ function derivesFromAnyOrUnknown(classType) {
747
739
  return classType.details.mro.some((baseClass) => isAnyOrUnknown(baseClass));
748
740
  }
749
- ClassType.hasUnknownBaseClass = hasUnknownBaseClass;
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["SkipArgsKwargsCompatibilityCheck"] = 32768] = "SkipArgsKwargsCompatibilityCheck";
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 cloneForParamSpec(type, paramSpecValue) {
1065
- const newFunction = create(type.details.name, type.details.fullName, type.details.moduleName, type.details.flags, type.flags, type.details.docString);
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 = { ...type.details };
1068
- newFunction.details.typeParameters = newFunction.details.typeParameters.filter((t) => !newFunction.details.paramSpec || !isTypeSame(t, newFunction.details.paramSpec));
1069
- // The clone should no longer have a parameter specification
1070
- // since we're replacing it.
1071
- delete newFunction.details.paramSpec;
1072
- if (paramSpecValue) {
1073
- const typeParameters = Array.from(type.details.parameters);
1074
- let droppedLastParam = false;
1075
- // If the paramSpec includes a position-only separator
1076
- // and the existing function ends on a position-only separator,
1077
- // we need to remove the latter in favor of the former.
1078
- if (paramSpecValue.details.parameters.some((param) => isPositionOnlySeparator(param))) {
1079
- if (typeParameters.length > 0 && isPositionOnlySeparator(typeParameters[typeParameters.length - 1])) {
1080
- typeParameters.pop();
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
- if (droppedLastParam) {
1122
- newFunction.specializedTypes.parameterTypes.pop();
1123
- }
1124
- if (type.specializedTypes.parameterDefaultArgs) {
1125
- newFunction.specializedTypes.parameterDefaultArgs = Array.from(type.specializedTypes.parameterDefaultArgs);
1126
- if (droppedLastParam) {
1127
- newFunction.specializedTypes.parameterDefaultArgs.pop();
1128
- }
1129
- }
1130
- paramSpecValue.details.parameters.forEach((paramInfo) => {
1131
- newFunction.specializedTypes.parameterTypes.push(paramInfo.type);
1132
- if (newFunction.specializedTypes.parameterDefaultArgs) {
1133
- // Assume that the parameters introduced via paramSpec have no specialized
1134
- // default arg types. Fall back on the original default arg type in this case.
1135
- newFunction.specializedTypes.parameterDefaultArgs.push(undefined);
1136
- }
1137
- });
1138
- }
1139
- FunctionType.addHigherOrderTypeVarScopeIds(newFunction, paramSpecValue.details.typeVarScopeId);
1140
- FunctionType.addHigherOrderTypeVarScopeIds(newFunction, paramSpecValue.details.higherOrderTypeVarScopeIds);
1141
- newFunction.details.paramSpec = paramSpecValue.details.paramSpec;
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.cloneForParamSpec = cloneForParamSpec;
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
- // Creates a new function based on a solved ParamSpec. The input type is assumed to
1183
- // have a signature that ends in "*args: P.args, **kwargs: P.kwargs". These will be
1184
- // replaced by the parameters in the ParamSpec.
1185
- function cloneForParamSpecApplication(type, paramSpecValue) {
1186
- const newFunction = TypeBase.cloneType(type);
1187
- // Make a shallow clone of the details.
1188
- newFunction.details = { ...type.details };
1189
- // Remove the last two parameters, which are the *args and **kwargs.
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
- paramSpecValue.details.parameters.forEach((param) => {
1211
- newFunction.details.parameters.push({
1212
- category: param.category,
1213
- name: param.name,
1214
- hasDefault: param.hasDefault,
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
- if (!newFunction.details.deprecatedMessage) {
1226
- newFunction.details.deprecatedMessage = paramSpecValue.details.deprecatedMessage;
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
- FunctionType.addHigherOrderTypeVarScopeIds(newFunction, paramSpecValue.details.typeVarScopeId);
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
- // Remove the last two parameters, which are the *args and **kwargs.
1237
- newFunction.details.parameters = newFunction.details.parameters.slice(0, newFunction.details.parameters.length - 2);
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 - 2);
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 - 2);
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.cloneRemoveParamSpecVariadics = cloneRemoveParamSpecVariadics;
1255
- function addDefaultParameters(functionType, useUnknown = false) {
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(functionType, param);
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 shouldSkipArgsKwargsCompatibilityCheck(type) {
1390
- return (type.details.flags & 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */) !== 0;
1372
+ function isGradualCallableForm(type) {
1373
+ return (type.details.flags & 32768 /* FunctionTypeFlags.GradualCallableForm */) !== 0;
1391
1374
  }
1392
- FunctionType.shouldSkipArgsKwargsCompatibilityCheck = shouldSkipArgsKwargsCompatibilityCheck;
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 getSpecializedReturnType(type, includeInferred = true) {
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.getSpecializedReturnType = getSpecializedReturnType;
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.shouldSkipArgsKwargsCompatibilityCheck(type1) !==
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) {