@zzzen/pyright-internal 1.2.0-dev.20241006 → 1.2.0-dev.20241020

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 (85) hide show
  1. package/dist/analyzer/binder.js +1 -2
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.js +3 -16
  4. package/dist/analyzer/checker.js.map +1 -1
  5. package/dist/analyzer/constraintSolver.js +11 -6
  6. package/dist/analyzer/constraintSolver.js.map +1 -1
  7. package/dist/analyzer/constraintTracker.d.ts +1 -0
  8. package/dist/analyzer/constraintTracker.js +7 -1
  9. package/dist/analyzer/constraintTracker.js.map +1 -1
  10. package/dist/analyzer/constructorTransform.js +3 -6
  11. package/dist/analyzer/constructorTransform.js.map +1 -1
  12. package/dist/analyzer/constructors.js +10 -8
  13. package/dist/analyzer/constructors.js.map +1 -1
  14. package/dist/analyzer/dataClasses.js +76 -19
  15. package/dist/analyzer/dataClasses.js.map +1 -1
  16. package/dist/analyzer/importResolver.js +2 -10
  17. package/dist/analyzer/importResolver.js.map +1 -1
  18. package/dist/analyzer/parameterUtils.d.ts +2 -1
  19. package/dist/analyzer/parameterUtils.js +2 -1
  20. package/dist/analyzer/parameterUtils.js.map +1 -1
  21. package/dist/analyzer/patternMatching.js +2 -2
  22. package/dist/analyzer/patternMatching.js.map +1 -1
  23. package/dist/analyzer/protocols.js +68 -26
  24. package/dist/analyzer/protocols.js.map +1 -1
  25. package/dist/analyzer/tuples.js +2 -2
  26. package/dist/analyzer/tuples.js.map +1 -1
  27. package/dist/analyzer/typeEvaluator.js +163 -92
  28. package/dist/analyzer/typeEvaluator.js.map +1 -1
  29. package/dist/analyzer/typeEvaluatorTypes.d.ts +5 -3
  30. package/dist/analyzer/typeEvaluatorTypes.js +5 -3
  31. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  32. package/dist/analyzer/typeGuards.js +3 -3
  33. package/dist/analyzer/typeGuards.js.map +1 -1
  34. package/dist/analyzer/typePrinter.js +5 -7
  35. package/dist/analyzer/typePrinter.js.map +1 -1
  36. package/dist/analyzer/typeUtils.d.ts +7 -1
  37. package/dist/analyzer/typeUtils.js +97 -11
  38. package/dist/analyzer/typeUtils.js.map +1 -1
  39. package/dist/analyzer/typedDicts.js +41 -30
  40. package/dist/analyzer/typedDicts.js.map +1 -1
  41. package/dist/analyzer/types.d.ts +12 -5
  42. package/dist/analyzer/types.js +33 -10
  43. package/dist/analyzer/types.js.map +1 -1
  44. package/dist/common/pythonVersion.js +1 -1
  45. package/dist/languageService/completionProvider.d.ts +2 -2
  46. package/dist/languageService/completionProvider.js +14 -7
  47. package/dist/languageService/completionProvider.js.map +1 -1
  48. package/dist/localization/localize.d.ts +4 -0
  49. package/dist/localization/localize.js +2 -0
  50. package/dist/localization/localize.js.map +1 -1
  51. package/dist/localization/package.nls.cs.json +2 -1
  52. package/dist/localization/package.nls.de.json +2 -1
  53. package/dist/localization/package.nls.en-us.json +7 -2
  54. package/dist/localization/package.nls.es.json +2 -1
  55. package/dist/localization/package.nls.fr.json +2 -1
  56. package/dist/localization/package.nls.it.json +2 -1
  57. package/dist/localization/package.nls.ja.json +2 -1
  58. package/dist/localization/package.nls.ko.json +2 -1
  59. package/dist/localization/package.nls.pl.json +2 -1
  60. package/dist/localization/package.nls.pt-br.json +2 -1
  61. package/dist/localization/package.nls.qps-ploc.json +2 -1
  62. package/dist/localization/package.nls.ru.json +2 -1
  63. package/dist/localization/package.nls.tr.json +2 -1
  64. package/dist/localization/package.nls.zh-cn.json +2 -1
  65. package/dist/localization/package.nls.zh-tw.json +2 -1
  66. package/dist/parser/tokenizer.d.ts +1 -0
  67. package/dist/parser/tokenizer.js +8 -0
  68. package/dist/parser/tokenizer.js.map +1 -1
  69. package/dist/tests/fourslash/findDefinitions.dataclasses.converter.fourslash.d.ts +1 -0
  70. package/dist/tests/fourslash/findDefinitions.dataclasses.converter.fourslash.js +40 -0
  71. package/dist/tests/fourslash/findDefinitions.dataclasses.converter.fourslash.js.map +1 -0
  72. package/dist/tests/typeEvaluator1.test.js +1 -0
  73. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  74. package/dist/tests/typeEvaluator3.test.js +1 -1
  75. package/dist/tests/typeEvaluator4.test.js +7 -2
  76. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  77. package/dist/tests/typeEvaluator5.test.js +8 -2
  78. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  79. package/dist/tests/typeEvaluator6.test.js +4 -4
  80. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  81. package/dist/tests/typeEvaluator7.test.js +11 -2
  82. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  83. package/dist/tests/typeEvaluator8.test.js +12 -0
  84. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  85. package/package.json +1 -1
@@ -60,6 +60,10 @@ export interface ApplyTypeVarOptions {
60
60
  eliminateUnsolvedInUnions?: boolean;
61
61
  };
62
62
  }
63
+ export interface AddConditionOptions {
64
+ skipSelfCondition?: boolean;
65
+ skipBoundTypeVars?: boolean;
66
+ }
63
67
  export declare class UniqueSignatureTracker {
64
68
  private _trackedSignatures;
65
69
  constructor();
@@ -95,7 +99,7 @@ export declare function preserveUnknown(type1: Type, type2: Type): AnyType | Unk
95
99
  export declare function isUnionableType(subtypes: Type[]): boolean;
96
100
  export declare function derivesFromAnyOrUnknown(type: Type): boolean;
97
101
  export declare function getFullNameOfType(type: Type): string | undefined;
98
- export declare function addConditionToType<T extends Type>(type: T, condition: TypeCondition[] | undefined, skipSelfCondition?: boolean): T;
102
+ export declare function addConditionToType<T extends Type>(type: T, condition: TypeCondition[] | undefined, options?: AddConditionOptions): T;
99
103
  export declare function getTypeCondition(type: Type): TypeCondition[] | undefined;
100
104
  export declare function isTypeAliasPlaceholder(type: Type): boolean;
101
105
  export declare function isTypeAliasRecursive(typeAliasPlaceholder: TypeVarType, type: Type): boolean | undefined;
@@ -173,6 +177,8 @@ export declare function explodeGenericClass(classType: ClassType): Type;
173
177
  export declare function combineSameSizedTuples(type: Type, tupleType: Type | undefined): Type;
174
178
  export declare function combineTupleTypeArgs(typeArgs: TupleTypeArg[]): Type;
175
179
  export declare function specializeTupleClass(classType: ClassType, typeArgs: TupleTypeArg[], isTypeArgExplicit?: boolean, isUnpacked?: boolean): ClassType;
180
+ export declare function makePacked(type: Type): Type;
181
+ export declare function makeUnpacked(type: Type): Type;
176
182
  export declare function getGeneratorTypeArgs(returnType: Type): Type[] | undefined;
177
183
  export declare function requiresTypeArgs(classType: ClassType): boolean;
178
184
  export declare function requiresSpecialization(type: Type, options?: RequiresSpecializationOptions, recursionCount?: number): boolean;
@@ -102,6 +102,8 @@ exports.explodeGenericClass = explodeGenericClass;
102
102
  exports.combineSameSizedTuples = combineSameSizedTuples;
103
103
  exports.combineTupleTypeArgs = combineTupleTypeArgs;
104
104
  exports.specializeTupleClass = specializeTupleClass;
105
+ exports.makePacked = makePacked;
106
+ exports.makeUnpacked = makeUnpacked;
105
107
  exports.getGeneratorTypeArgs = getGeneratorTypeArgs;
106
108
  exports.requiresTypeArgs = requiresTypeArgs;
107
109
  exports.requiresSpecialization = requiresSpecialization;
@@ -501,6 +503,20 @@ function compareTypes(a, b, recursionCount = 0) {
501
503
  if (!isLiteralType(bClass)) {
502
504
  return -1;
503
505
  }
506
+ else if (types_1.ClassType.isSameGenericClass(a, bClass)) {
507
+ // Sort by literal value.
508
+ const aLiteralValue = a.priv.literalValue;
509
+ const bLiteralValue = bClass.priv.literalValue;
510
+ if ((typeof aLiteralValue === 'string' && typeof bLiteralValue === 'string') ||
511
+ (typeof aLiteralValue === 'number' && typeof bLiteralValue === 'number')) {
512
+ if (aLiteralValue < bLiteralValue) {
513
+ return -1;
514
+ }
515
+ else if (aLiteralValue > bLiteralValue) {
516
+ return 1;
517
+ }
518
+ }
519
+ }
504
520
  }
505
521
  else if (isLiteralType(bClass)) {
506
522
  return 1;
@@ -696,17 +712,23 @@ function getFullNameOfType(type) {
696
712
  }
697
713
  return undefined;
698
714
  }
699
- function addConditionToType(type, condition, skipSelfCondition = false) {
715
+ function addConditionToType(type, condition, options) {
700
716
  var _a, _b;
701
717
  if (!condition) {
702
718
  return type;
703
719
  }
704
- if (skipSelfCondition) {
720
+ if (options === null || options === void 0 ? void 0 : options.skipSelfCondition) {
705
721
  condition = condition.filter((c) => !types_1.TypeVarType.isSelf(c.typeVar));
706
722
  if (condition.length === 0) {
707
723
  return type;
708
724
  }
709
725
  }
726
+ if (options === null || options === void 0 ? void 0 : options.skipBoundTypeVars) {
727
+ condition = condition.filter((c) => c.typeVar.shared.constraints.length > 0);
728
+ if (condition.length === 0) {
729
+ return type;
730
+ }
731
+ }
710
732
  switch (type.category) {
711
733
  case 0 /* TypeCategory.Unbound */:
712
734
  case 1 /* TypeCategory.Unknown */:
@@ -862,6 +884,8 @@ function getUnknownTypeForCallable() {
862
884
  // "self specializes" the class, filling in its own type parameters
863
885
  // as type arguments.
864
886
  function selfSpecializeClass(type, options) {
887
+ // We can't use requiresTypeArgs(type) here because it returns false
888
+ // if the type parameters have default values.
865
889
  if (type.shared.typeParams.length === 0) {
866
890
  return type;
867
891
  }
@@ -1066,7 +1090,7 @@ function isTupleClass(type) {
1066
1090
  // in the tuple is unknown.
1067
1091
  function isUnboundedTupleClass(type) {
1068
1092
  var _a;
1069
- return (_a = type.priv.tupleTypeArgs) === null || _a === void 0 ? void 0 : _a.some((t) => t.isUnbounded || (0, types_1.isUnpackedTypeVarTuple)(t.type));
1093
+ return (_a = type.priv.tupleTypeArgs) === null || _a === void 0 ? void 0 : _a.some((t) => t.isUnbounded || (0, types_1.isUnpackedTypeVarTuple)(t.type) || (0, types_1.isUnpackedTypeVar)(t.type));
1070
1094
  }
1071
1095
  // Indicates whether the specified index is within range and its type is unambiguous
1072
1096
  // in that it doesn't involve any element ranges that are of indeterminate length.
@@ -1074,7 +1098,7 @@ function isTupleIndexUnambiguous(type, index) {
1074
1098
  if (!type.priv.tupleTypeArgs) {
1075
1099
  return false;
1076
1100
  }
1077
- const unboundedIndex = type.priv.tupleTypeArgs.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedTypeVarTuple)(t.type));
1101
+ const unboundedIndex = type.priv.tupleTypeArgs.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedTypeVarTuple)(t.type) || (0, types_1.isUnpackedTypeVar)(t.type));
1078
1102
  if (index < 0) {
1079
1103
  const lowerIndexLimit = unboundedIndex < 0 ? 0 : unboundedIndex;
1080
1104
  index += type.priv.tupleTypeArgs.length;
@@ -1371,7 +1395,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
1371
1395
  }
1372
1396
  // Next look at class members.
1373
1397
  if ((flags & 32 /* MemberAccessFlags.SkipClassMembers */) === 0) {
1374
- const symbol = memberFields.get(memberName);
1398
+ let symbol = memberFields.get(memberName);
1375
1399
  if (symbol && symbol.isClassMember()) {
1376
1400
  const hasDeclaredType = symbol.hasTypedDeclarations();
1377
1401
  if (!declaredTypesOnly || hasDeclaredType) {
@@ -1391,6 +1415,12 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
1391
1415
  isClassMember = isDataclass;
1392
1416
  }
1393
1417
  }
1418
+ // Handle the special case of a __call__ class member in a partial class.
1419
+ if (memberName === '__call__' &&
1420
+ classType.priv.partialCallType &&
1421
+ types_1.ClassType.isSameGenericClass(classType, specializedMroClass)) {
1422
+ symbol = symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, classType.priv.partialCallType);
1423
+ }
1394
1424
  const cm = {
1395
1425
  symbol,
1396
1426
  isInstanceMember,
@@ -2113,13 +2143,27 @@ function combineSameSizedTuples(type, tupleType) {
2113
2143
  })));
2114
2144
  }
2115
2145
  function combineTupleTypeArgs(typeArgs) {
2116
- return (0, types_1.combineTypes)(typeArgs.map((t) => {
2117
- if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedTypeVarTuple)(t.type)) {
2118
- // Treat the unpacked TypeVarTuple as a union.
2119
- return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
2146
+ const typesToCombine = [];
2147
+ typeArgs.forEach((t) => {
2148
+ if ((0, types_1.isTypeVar)(t.type)) {
2149
+ if ((0, types_1.isUnpackedTypeVarTuple)(t.type)) {
2150
+ // Treat the unpacked TypeVarTuple as a union.
2151
+ typesToCombine.push(types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true));
2152
+ return;
2153
+ }
2154
+ if ((0, types_1.isUnpackedTypeVar)(t.type)) {
2155
+ if (t.type.shared.boundType &&
2156
+ (0, types_1.isClassInstance)(t.type.shared.boundType) &&
2157
+ isTupleClass(t.type.shared.boundType) &&
2158
+ t.type.shared.boundType.priv.tupleTypeArgs) {
2159
+ typesToCombine.push(combineTupleTypeArgs(t.type.shared.boundType.priv.tupleTypeArgs));
2160
+ }
2161
+ return;
2162
+ }
2120
2163
  }
2121
- return t.type;
2122
- }));
2164
+ typesToCombine.push(t.type);
2165
+ });
2166
+ return (0, types_1.combineTypes)(typesToCombine);
2123
2167
  }
2124
2168
  // Tuples require special handling for specialization. This method computes
2125
2169
  // the "effective" type argument, which is a union of the variadic type
@@ -2138,6 +2182,31 @@ function _expandUnpackedTypeVarTupleUnion(type) {
2138
2182
  }
2139
2183
  return type;
2140
2184
  }
2185
+ // If this is an unpacked type, returns the type as no longer unpacked.
2186
+ function makePacked(type) {
2187
+ if ((0, types_1.isUnpackedClass)(type)) {
2188
+ return types_1.ClassType.cloneForPacked(type);
2189
+ }
2190
+ if ((0, types_1.isUnpackedTypeVarTuple)(type) && !type.priv.isInUnion) {
2191
+ return types_1.TypeVarType.cloneForPacked(type);
2192
+ }
2193
+ if ((0, types_1.isUnpackedTypeVar)(type)) {
2194
+ return types_1.TypeVarType.cloneForPacked(type);
2195
+ }
2196
+ return type;
2197
+ }
2198
+ function makeUnpacked(type) {
2199
+ if ((0, types_1.isClass)(type)) {
2200
+ return types_1.ClassType.cloneForUnpacked(type);
2201
+ }
2202
+ if ((0, types_1.isTypeVarTuple)(type) && !type.priv.isInUnion) {
2203
+ return types_1.TypeVarType.cloneForUnpacked(type);
2204
+ }
2205
+ if ((0, types_1.isTypeVar)(type)) {
2206
+ return types_1.TypeVarType.cloneForUnpacked(type);
2207
+ }
2208
+ return type;
2209
+ }
2141
2210
  // If the declared return type for the function is a Generator or AsyncGenerator,
2142
2211
  // returns the type arguments for the type.
2143
2212
  function getGeneratorTypeArgs(returnType) {
@@ -2225,6 +2294,11 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
2225
2294
  if (!type.priv.isTypeArgExplicit && (options === null || options === void 0 ? void 0 : options.ignoreImplicitTypeArgs)) {
2226
2295
  return false;
2227
2296
  }
2297
+ if (type.priv.tupleTypeArgs) {
2298
+ if (type.priv.tupleTypeArgs.some((typeArg) => requiresSpecialization(typeArg.type, options, recursionCount))) {
2299
+ return true;
2300
+ }
2301
+ }
2228
2302
  if (type.priv.typeArgs) {
2229
2303
  return type.priv.typeArgs.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
2230
2304
  }
@@ -2802,6 +2876,9 @@ class TypeVarTransformer {
2802
2876
  newTypeArgType.priv.tupleTypeArgs) {
2803
2877
  (0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.priv.tupleTypeArgs);
2804
2878
  }
2879
+ else if ((0, types_1.isUnpackedClass)(newTypeArgType) && newTypeArgType.priv.tupleTypeArgs) {
2880
+ (0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.priv.tupleTypeArgs);
2881
+ }
2805
2882
  else {
2806
2883
  // Handle the special case where tuple[T, ...] is being specialized
2807
2884
  // to tuple[Never, ...]. This is equivalent to tuple[()].
@@ -3181,6 +3258,12 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3181
3258
  if ((0, types_1.isTypeVarTuple)(replacement) && (0, types_1.isTypeVarTuple)(typeVar) && typeVar.priv.isUnpacked) {
3182
3259
  return types_1.TypeVarType.cloneForUnpacked(replacement, typeVar.priv.isInUnion);
3183
3260
  }
3261
+ if (!(0, types_1.isTypeVarTuple)(replacement) &&
3262
+ (0, types_1.isTypeVar)(replacement) &&
3263
+ (0, types_1.isTypeVar)(typeVar) &&
3264
+ typeVar.priv.isUnpacked) {
3265
+ return types_1.TypeVarType.cloneForUnpacked(replacement);
3266
+ }
3184
3267
  // If this isn't a TypeVarTuple, combine all of the tuple
3185
3268
  // type args into a common type.
3186
3269
  if (!(0, types_1.isTypeVarTuple)(typeVar) &&
@@ -3189,6 +3272,9 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3189
3272
  replacement.priv.isUnpacked) {
3190
3273
  replacement = combineTupleTypeArgs(replacement.priv.tupleTypeArgs);
3191
3274
  }
3275
+ if ((0, types_1.isUnpackedTypeVar)(typeVar) && (0, types_1.isClass)(replacement)) {
3276
+ replacement = types_1.ClassType.cloneForUnpacked(replacement);
3277
+ }
3192
3278
  if (!(0, types_1.isTypeVar)(replacement) || !types_1.TypeVarType.isUnification(replacement) || !this._options.replaceUnsolved) {
3193
3279
  return replacement;
3194
3280
  }