@zzzen/pyright-internal 1.2.0-dev.20240929 → 1.2.0-dev.20241013

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 (77) 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 +7 -7
  4. package/dist/analyzer/checker.js.map +1 -1
  5. package/dist/analyzer/codeFlowEngine.js +1 -1
  6. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  7. package/dist/analyzer/constraintSolver.js +14 -18
  8. package/dist/analyzer/constraintSolver.js.map +1 -1
  9. package/dist/analyzer/constraintTracker.js +1 -1
  10. package/dist/analyzer/constraintTracker.js.map +1 -1
  11. package/dist/analyzer/constructors.js +10 -8
  12. package/dist/analyzer/constructors.js.map +1 -1
  13. package/dist/analyzer/dataClasses.js +72 -22
  14. package/dist/analyzer/dataClasses.js.map +1 -1
  15. package/dist/analyzer/parameterUtils.d.ts +2 -1
  16. package/dist/analyzer/parameterUtils.js +2 -1
  17. package/dist/analyzer/parameterUtils.js.map +1 -1
  18. package/dist/analyzer/patternMatching.js +14 -3
  19. package/dist/analyzer/patternMatching.js.map +1 -1
  20. package/dist/analyzer/protocols.js +63 -32
  21. package/dist/analyzer/protocols.js.map +1 -1
  22. package/dist/analyzer/tuples.d.ts +8 -3
  23. package/dist/analyzer/tuples.js +157 -2
  24. package/dist/analyzer/tuples.js.map +1 -1
  25. package/dist/analyzer/typeEvaluator.js +283 -356
  26. package/dist/analyzer/typeEvaluator.js.map +1 -1
  27. package/dist/analyzer/typeEvaluatorTypes.d.ts +9 -14
  28. package/dist/analyzer/typeEvaluatorTypes.js +7 -1
  29. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  30. package/dist/analyzer/typePrinter.d.ts +2 -1
  31. package/dist/analyzer/typePrinter.js +17 -17
  32. package/dist/analyzer/typePrinter.js.map +1 -1
  33. package/dist/analyzer/typeStubWriter.js +1 -1
  34. package/dist/analyzer/typeStubWriter.js.map +1 -1
  35. package/dist/analyzer/typeUtils.d.ts +12 -3
  36. package/dist/analyzer/typeUtils.js +85 -21
  37. package/dist/analyzer/typeUtils.js.map +1 -1
  38. package/dist/analyzer/types.d.ts +10 -5
  39. package/dist/analyzer/types.js +49 -18
  40. package/dist/analyzer/types.js.map +1 -1
  41. package/dist/common/collectionUtils.d.ts +2 -0
  42. package/dist/common/collectionUtils.js +15 -0
  43. package/dist/common/collectionUtils.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 +11 -6
  47. package/dist/languageService/completionProvider.js.map +1 -1
  48. package/dist/localization/package.nls.cs.json +1 -0
  49. package/dist/localization/package.nls.de.json +1 -0
  50. package/dist/localization/package.nls.es.json +1 -0
  51. package/dist/localization/package.nls.fr.json +1 -0
  52. package/dist/localization/package.nls.it.json +1 -0
  53. package/dist/localization/package.nls.ja.json +1 -0
  54. package/dist/localization/package.nls.ko.json +1 -0
  55. package/dist/localization/package.nls.pl.json +1 -0
  56. package/dist/localization/package.nls.pt-br.json +1 -0
  57. package/dist/localization/package.nls.qps-ploc.json +1 -0
  58. package/dist/localization/package.nls.ru.json +1 -0
  59. package/dist/localization/package.nls.tr.json +1 -0
  60. package/dist/localization/package.nls.zh-cn.json +6 -5
  61. package/dist/localization/package.nls.zh-tw.json +6 -5
  62. package/dist/tests/fourslash/findDefinitions.dataclasses.converter.fourslash.d.ts +1 -0
  63. package/dist/tests/fourslash/findDefinitions.dataclasses.converter.fourslash.js +40 -0
  64. package/dist/tests/fourslash/findDefinitions.dataclasses.converter.fourslash.js.map +1 -0
  65. package/dist/tests/typeEvaluator1.test.js +1 -0
  66. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  67. package/dist/tests/typeEvaluator4.test.js +4 -3
  68. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  69. package/dist/tests/typeEvaluator5.test.js +3 -3
  70. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  71. package/dist/tests/typeEvaluator6.test.js +9 -3
  72. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  73. package/dist/tests/typeEvaluator7.test.js +11 -8
  74. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  75. package/dist/tests/typeEvaluator8.test.js +4 -0
  76. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  77. package/package.json +1 -1
@@ -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;
@@ -110,7 +112,6 @@ exports.combineVariances = combineVariances;
110
112
  exports.isVarianceOfTypeArgCompatible = isVarianceOfTypeArgCompatible;
111
113
  exports.computeMroLinearization = computeMroLinearization;
112
114
  exports.getDeclaringModulesForType = getDeclaringModulesForType;
113
- exports.convertNodeToArg = convertNodeToArg;
114
115
  exports.convertTypeToParamSpecValue = convertTypeToParamSpecValue;
115
116
  exports.simplifyFunctionToParamSpec = simplifyFunctionToParamSpec;
116
117
  const collectionUtils_1 = require("../common/collectionUtils");
@@ -502,6 +503,20 @@ function compareTypes(a, b, recursionCount = 0) {
502
503
  if (!isLiteralType(bClass)) {
503
504
  return -1;
504
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
+ }
505
520
  }
506
521
  else if (isLiteralType(bClass)) {
507
522
  return 1;
@@ -863,7 +878,7 @@ function getUnknownTypeForCallable() {
863
878
  // "self specializes" the class, filling in its own type parameters
864
879
  // as type arguments.
865
880
  function selfSpecializeClass(type, options) {
866
- if (type.shared.typeParams.length === 0) {
881
+ if (!requiresTypeArgs(type)) {
867
882
  return type;
868
883
  }
869
884
  if (type.priv.typeArgs && !(options === null || options === void 0 ? void 0 : options.overrideTypeArgs)) {
@@ -1067,7 +1082,7 @@ function isTupleClass(type) {
1067
1082
  // in the tuple is unknown.
1068
1083
  function isUnboundedTupleClass(type) {
1069
1084
  var _a;
1070
- return (_a = type.priv.tupleTypeArgs) === null || _a === void 0 ? void 0 : _a.some((t) => t.isUnbounded || (0, types_1.isUnpackedTypeVarTuple)(t.type));
1085
+ 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));
1071
1086
  }
1072
1087
  // Indicates whether the specified index is within range and its type is unambiguous
1073
1088
  // in that it doesn't involve any element ranges that are of indeterminate length.
@@ -1075,7 +1090,7 @@ function isTupleIndexUnambiguous(type, index) {
1075
1090
  if (!type.priv.tupleTypeArgs) {
1076
1091
  return false;
1077
1092
  }
1078
- const unboundedIndex = type.priv.tupleTypeArgs.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedTypeVarTuple)(t.type));
1093
+ const unboundedIndex = type.priv.tupleTypeArgs.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedTypeVarTuple)(t.type) || (0, types_1.isUnpackedTypeVar)(t.type));
1079
1094
  if (index < 0) {
1080
1095
  const lowerIndexLimit = unboundedIndex < 0 ? 0 : unboundedIndex;
1081
1096
  index += type.priv.tupleTypeArgs.length;
@@ -1188,10 +1203,10 @@ function validateTypeVarDefault(typeVar, liveTypeParams, invalidTypeVars) {
1188
1203
  // During bidirectional type inference for constructors, an "expected type"
1189
1204
  // is used to prepopulate the type var map. This is problematic when the
1190
1205
  // expected type uses TypeVars that are not part of the context of the
1191
- // class we are constructing. We'll replace these type variables with dummy
1192
- // type variables.
1206
+ // class we are constructing. We'll replace these type variables with
1207
+ // so-called "unification" type variables.
1193
1208
  function transformExpectedType(expectedType, liveTypeVarScopes, usageOffset) {
1194
- const transformer = new ExpectedTypeTransformer(liveTypeVarScopes, usageOffset);
1209
+ const transformer = new UnificationTypeTransformer(liveTypeVarScopes, usageOffset);
1195
1210
  return transformer.apply(expectedType, 0);
1196
1211
  }
1197
1212
  // Given a protocol class (or abstract class), this function returns
@@ -2114,13 +2129,27 @@ function combineSameSizedTuples(type, tupleType) {
2114
2129
  })));
2115
2130
  }
2116
2131
  function combineTupleTypeArgs(typeArgs) {
2117
- return (0, types_1.combineTypes)(typeArgs.map((t) => {
2118
- if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedTypeVarTuple)(t.type)) {
2119
- // Treat the unpacked TypeVarTuple as a union.
2120
- return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
2132
+ const typesToCombine = [];
2133
+ typeArgs.forEach((t) => {
2134
+ if ((0, types_1.isTypeVar)(t.type)) {
2135
+ if ((0, types_1.isUnpackedTypeVarTuple)(t.type)) {
2136
+ // Treat the unpacked TypeVarTuple as a union.
2137
+ typesToCombine.push(types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true));
2138
+ return;
2139
+ }
2140
+ if ((0, types_1.isUnpackedTypeVar)(t.type)) {
2141
+ if (t.type.shared.boundType &&
2142
+ (0, types_1.isClassInstance)(t.type.shared.boundType) &&
2143
+ isTupleClass(t.type.shared.boundType) &&
2144
+ t.type.shared.boundType.priv.tupleTypeArgs) {
2145
+ typesToCombine.push(combineTupleTypeArgs(t.type.shared.boundType.priv.tupleTypeArgs));
2146
+ }
2147
+ return;
2148
+ }
2121
2149
  }
2122
- return t.type;
2123
- }));
2150
+ typesToCombine.push(t.type);
2151
+ });
2152
+ return (0, types_1.combineTypes)(typesToCombine);
2124
2153
  }
2125
2154
  // Tuples require special handling for specialization. This method computes
2126
2155
  // the "effective" type argument, which is a union of the variadic type
@@ -2139,6 +2168,31 @@ function _expandUnpackedTypeVarTupleUnion(type) {
2139
2168
  }
2140
2169
  return type;
2141
2170
  }
2171
+ // If this is an unpacked type, returns the type as no longer unpacked.
2172
+ function makePacked(type) {
2173
+ if ((0, types_1.isUnpackedClass)(type)) {
2174
+ return types_1.ClassType.cloneForPacked(type);
2175
+ }
2176
+ if ((0, types_1.isUnpackedTypeVarTuple)(type) && !type.priv.isInUnion) {
2177
+ return types_1.TypeVarType.cloneForPacked(type);
2178
+ }
2179
+ if ((0, types_1.isUnpackedTypeVar)(type)) {
2180
+ return types_1.TypeVarType.cloneForPacked(type);
2181
+ }
2182
+ return type;
2183
+ }
2184
+ function makeUnpacked(type) {
2185
+ if ((0, types_1.isClass)(type)) {
2186
+ return types_1.ClassType.cloneForUnpacked(type);
2187
+ }
2188
+ if ((0, types_1.isTypeVarTuple)(type) && !type.priv.isInUnion) {
2189
+ return types_1.TypeVarType.cloneForUnpacked(type);
2190
+ }
2191
+ if ((0, types_1.isTypeVar)(type)) {
2192
+ return types_1.TypeVarType.cloneForUnpacked(type);
2193
+ }
2194
+ return type;
2195
+ }
2142
2196
  // If the declared return type for the function is a Generator or AsyncGenerator,
2143
2197
  // returns the type arguments for the type.
2144
2198
  function getGeneratorTypeArgs(returnType) {
@@ -2226,6 +2280,11 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
2226
2280
  if (!type.priv.isTypeArgExplicit && (options === null || options === void 0 ? void 0 : options.ignoreImplicitTypeArgs)) {
2227
2281
  return false;
2228
2282
  }
2283
+ if (type.priv.tupleTypeArgs) {
2284
+ if (type.priv.tupleTypeArgs.some((typeArg) => requiresSpecialization(typeArg.type, options, recursionCount))) {
2285
+ return true;
2286
+ }
2287
+ }
2229
2288
  if (type.priv.typeArgs) {
2230
2289
  return type.priv.typeArgs.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
2231
2290
  }
@@ -2492,13 +2551,6 @@ function getDeclaringModulesForType(type) {
2492
2551
  addDeclaringModuleNamesForType(type, moduleList);
2493
2552
  return moduleList;
2494
2553
  }
2495
- function convertNodeToArg(node) {
2496
- return {
2497
- argCategory: node.d.argCategory,
2498
- name: node.d.name,
2499
- valueExpression: node.d.valueExpr,
2500
- };
2501
- }
2502
2554
  function addDeclaringModuleNamesForType(type, moduleList, recursionCount = 0) {
2503
2555
  if (recursionCount > types_1.maxTypeRecursionCount) {
2504
2556
  return;
@@ -2810,6 +2862,9 @@ class TypeVarTransformer {
2810
2862
  newTypeArgType.priv.tupleTypeArgs) {
2811
2863
  (0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.priv.tupleTypeArgs);
2812
2864
  }
2865
+ else if ((0, types_1.isUnpackedClass)(newTypeArgType) && newTypeArgType.priv.tupleTypeArgs) {
2866
+ (0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.priv.tupleTypeArgs);
2867
+ }
2813
2868
  else {
2814
2869
  // Handle the special case where tuple[T, ...] is being specialized
2815
2870
  // to tuple[Never, ...]. This is equivalent to tuple[()].
@@ -3189,6 +3244,12 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3189
3244
  if ((0, types_1.isTypeVarTuple)(replacement) && (0, types_1.isTypeVarTuple)(typeVar) && typeVar.priv.isUnpacked) {
3190
3245
  return types_1.TypeVarType.cloneForUnpacked(replacement, typeVar.priv.isInUnion);
3191
3246
  }
3247
+ if (!(0, types_1.isTypeVarTuple)(replacement) &&
3248
+ (0, types_1.isTypeVar)(replacement) &&
3249
+ (0, types_1.isTypeVar)(typeVar) &&
3250
+ typeVar.priv.isUnpacked) {
3251
+ return types_1.TypeVarType.cloneForUnpacked(replacement);
3252
+ }
3192
3253
  // If this isn't a TypeVarTuple, combine all of the tuple
3193
3254
  // type args into a common type.
3194
3255
  if (!(0, types_1.isTypeVarTuple)(typeVar) &&
@@ -3197,6 +3258,9 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3197
3258
  replacement.priv.isUnpacked) {
3198
3259
  replacement = combineTupleTypeArgs(replacement.priv.tupleTypeArgs);
3199
3260
  }
3261
+ if ((0, types_1.isUnpackedTypeVar)(typeVar) && (0, types_1.isClass)(replacement)) {
3262
+ replacement = types_1.ClassType.cloneForUnpacked(replacement);
3263
+ }
3200
3264
  if (!(0, types_1.isTypeVar)(replacement) || !types_1.TypeVarType.isUnification(replacement) || !this._options.replaceUnsolved) {
3201
3265
  return replacement;
3202
3266
  }
@@ -3368,7 +3432,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3368
3432
  return result;
3369
3433
  }
3370
3434
  }
3371
- class ExpectedTypeTransformer extends TypeVarTransformer {
3435
+ class UnificationTypeTransformer extends TypeVarTransformer {
3372
3436
  constructor(_liveTypeVarScopes, _usageOffset) {
3373
3437
  super();
3374
3438
  this._liveTypeVarScopes = _liveTypeVarScopes;