@zzzen/pyright-internal 1.2.0-dev.20241027 → 1.2.0-dev.20241110

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 (115) hide show
  1. package/dist/analyzer/binder.d.ts +2 -3
  2. package/dist/analyzer/binder.js +36 -21
  3. package/dist/analyzer/binder.js.map +1 -1
  4. package/dist/analyzer/checker.js +11 -7
  5. package/dist/analyzer/checker.js.map +1 -1
  6. package/dist/analyzer/codeFlowEngine.js +2 -2
  7. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  8. package/dist/analyzer/constructorTransform.js +18 -1
  9. package/dist/analyzer/constructorTransform.js.map +1 -1
  10. package/dist/analyzer/constructors.js +1 -1
  11. package/dist/analyzer/constructors.js.map +1 -1
  12. package/dist/analyzer/dataClasses.js +0 -4
  13. package/dist/analyzer/dataClasses.js.map +1 -1
  14. package/dist/analyzer/declaration.d.ts +1 -1
  15. package/dist/analyzer/declaration.js.map +1 -1
  16. package/dist/analyzer/enums.js +3 -1
  17. package/dist/analyzer/enums.js.map +1 -1
  18. package/dist/analyzer/importResolver.d.ts +1 -1
  19. package/dist/analyzer/importResolver.js +5 -5
  20. package/dist/analyzer/importResolver.js.map +1 -1
  21. package/dist/analyzer/operations.js +6 -0
  22. package/dist/analyzer/operations.js.map +1 -1
  23. package/dist/analyzer/parameterUtils.js +2 -0
  24. package/dist/analyzer/parameterUtils.js.map +1 -1
  25. package/dist/analyzer/patternMatching.js +4 -2
  26. package/dist/analyzer/patternMatching.js.map +1 -1
  27. package/dist/analyzer/protocols.js +1 -1
  28. package/dist/analyzer/protocols.js.map +1 -1
  29. package/dist/analyzer/service.js +1 -1
  30. package/dist/analyzer/service.js.map +1 -1
  31. package/dist/analyzer/serviceUtils.d.ts +0 -2
  32. package/dist/analyzer/serviceUtils.js +3 -5
  33. package/dist/analyzer/serviceUtils.js.map +1 -1
  34. package/dist/analyzer/sourceFile.js +1 -1
  35. package/dist/analyzer/sourceFile.js.map +1 -1
  36. package/dist/analyzer/tuples.d.ts +2 -2
  37. package/dist/analyzer/typeEvaluator.js +153 -43
  38. package/dist/analyzer/typeEvaluator.js.map +1 -1
  39. package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -1
  40. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  41. package/dist/analyzer/typeGuards.js +10 -5
  42. package/dist/analyzer/typeGuards.js.map +1 -1
  43. package/dist/analyzer/typePrinter.js +6 -0
  44. package/dist/analyzer/typePrinter.js.map +1 -1
  45. package/dist/analyzer/typeUtils.d.ts +0 -1
  46. package/dist/analyzer/typeUtils.js +51 -30
  47. package/dist/analyzer/typeUtils.js.map +1 -1
  48. package/dist/analyzer/typedDicts.d.ts +2 -1
  49. package/dist/analyzer/typedDicts.js +21 -1
  50. package/dist/analyzer/typedDicts.js.map +1 -1
  51. package/dist/analyzer/types.js +4 -5
  52. package/dist/analyzer/types.js.map +1 -1
  53. package/dist/common/pathConsts.d.ts +3 -0
  54. package/dist/common/pathConsts.js +4 -1
  55. package/dist/common/pathConsts.js.map +1 -1
  56. package/dist/languageService/autoImporter.d.ts +6 -2
  57. package/dist/languageService/autoImporter.js +15 -15
  58. package/dist/languageService/autoImporter.js.map +1 -1
  59. package/dist/languageService/completionProvider.js +4 -2
  60. package/dist/languageService/completionProvider.js.map +1 -1
  61. package/dist/languageService/fileWatcherDynamicFeature.js +2 -2
  62. package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
  63. package/dist/languageService/hoverProvider.d.ts +2 -1
  64. package/dist/languageService/hoverProvider.js +33 -10
  65. package/dist/languageService/hoverProvider.js.map +1 -1
  66. package/dist/languageService/signatureHelpProvider.js +21 -13
  67. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  68. package/dist/localization/localize.d.ts +5 -4
  69. package/dist/localization/localize.js +5 -2
  70. package/dist/localization/localize.js.map +1 -1
  71. package/dist/localization/package.nls.cs.json +1 -2
  72. package/dist/localization/package.nls.de.json +2 -3
  73. package/dist/localization/package.nls.en-us.json +19 -4
  74. package/dist/localization/package.nls.es.json +2 -3
  75. package/dist/localization/package.nls.fr.json +1 -2
  76. package/dist/localization/package.nls.it.json +2 -3
  77. package/dist/localization/package.nls.ja.json +1 -2
  78. package/dist/localization/package.nls.ko.json +1 -2
  79. package/dist/localization/package.nls.pl.json +1 -2
  80. package/dist/localization/package.nls.pt-br.json +1 -2
  81. package/dist/localization/package.nls.qps-ploc.json +1 -2
  82. package/dist/localization/package.nls.ru.json +1 -2
  83. package/dist/localization/package.nls.tr.json +1 -2
  84. package/dist/localization/package.nls.zh-cn.json +1 -2
  85. package/dist/localization/package.nls.zh-tw.json +1 -2
  86. package/dist/parser/parseNodes.d.ts +3 -2
  87. package/dist/parser/parseNodes.js +2 -1
  88. package/dist/parser/parseNodes.js.map +1 -1
  89. package/dist/parser/parser.d.ts +2 -1
  90. package/dist/parser/parser.js +36 -7
  91. package/dist/parser/parser.js.map +1 -1
  92. package/dist/tests/fourslash/hover.typedDict.get.fourslash.d.ts +1 -0
  93. package/dist/tests/fourslash/hover.typedDict.get.fourslash.js +16 -0
  94. package/dist/tests/fourslash/hover.typedDict.get.fourslash.js.map +1 -0
  95. package/dist/tests/fourslash/signature.dataclassAlias.fourslash.d.ts +1 -0
  96. package/dist/tests/fourslash/signature.dataclassAlias.fourslash.js +73 -0
  97. package/dist/tests/fourslash/signature.dataclassAlias.fourslash.js.map +1 -0
  98. package/dist/tests/harness/fourslash/testState.js +14 -1
  99. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  100. package/dist/tests/harness/fourslash/testStateUtils.js +2 -2
  101. package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
  102. package/dist/tests/typeEvaluator2.test.js +4 -0
  103. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  104. package/dist/tests/typeEvaluator3.test.js +6 -2
  105. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  106. package/dist/tests/typeEvaluator4.test.js +1 -1
  107. package/dist/tests/typeEvaluator5.test.js +7 -1
  108. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  109. package/dist/tests/typeEvaluator6.test.js +17 -1
  110. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  111. package/dist/tests/typeEvaluator7.test.js +13 -3
  112. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  113. package/dist/tests/typeEvaluator8.test.js +4 -0
  114. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  115. package/package.json +1 -1
@@ -893,6 +893,9 @@ function selfSpecializeClass(type, options) {
893
893
  return type;
894
894
  }
895
895
  const typeParams = type.shared.typeParams.map((typeParam) => {
896
+ if ((0, types_1.isTypeVarTuple)(typeParam)) {
897
+ typeParam = types_1.TypeVarType.cloneForUnpacked(typeParam);
898
+ }
896
899
  return (options === null || options === void 0 ? void 0 : options.useBoundTypeVars) ? types_1.TypeVarType.cloneAsBound(typeParam) : typeParam;
897
900
  });
898
901
  return types_1.ClassType.specialize(type, typeParams);
@@ -1331,7 +1334,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
1331
1334
  let classFlags = 0 /* ClassIteratorFlags.Default */;
1332
1335
  if (flags & 1 /* MemberAccessFlags.SkipOriginalClass */) {
1333
1336
  if ((0, types_1.isClass)(classType)) {
1334
- skipMroClass = classType;
1337
+ skipMroClass = (0, types_1.isClassInstance)(classType) ? types_1.ClassType.cloneAsInstantiable(classType) : classType;
1335
1338
  }
1336
1339
  }
1337
1340
  if (flags & 2 /* MemberAccessFlags.SkipBaseClasses */) {
@@ -1418,7 +1421,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
1418
1421
  // Handle the special case of a __call__ class member in a partial class.
1419
1422
  if (memberName === '__call__' &&
1420
1423
  classType.priv.partialCallType &&
1421
- types_1.ClassType.isSameGenericClass(classType, specializedMroClass)) {
1424
+ types_1.ClassType.isSameGenericClass(types_1.TypeBase.isInstance(classType) ? types_1.ClassType.cloneAsInstantiable(classType) : classType, specializedMroClass)) {
1422
1425
  symbol = symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, classType.priv.partialCallType);
1423
1426
  }
1424
1427
  const cm = {
@@ -1592,6 +1595,10 @@ function getTypeVarArgsRecursive(type, recursionCount = 0) {
1592
1595
  if (type.shared.recursiveAlias) {
1593
1596
  return [];
1594
1597
  }
1598
+ // Don't return any bound type variables.
1599
+ if (types_1.TypeVarType.isBound(type)) {
1600
+ return [];
1601
+ }
1595
1602
  // Don't return any P.args or P.kwargs types.
1596
1603
  if ((0, types_1.isParamSpec)(type) && type.priv.paramSpecAccess) {
1597
1604
  return [types_1.TypeVarType.cloneForParamSpecAccess(type, /* access */ undefined)];
@@ -1631,15 +1638,13 @@ function getTypeVarArgsRecursive(type, recursionCount = 0) {
1631
1638
  // Creates a specialized version of the class, filling in any unspecified
1632
1639
  // type arguments with Unknown or default value.
1633
1640
  function specializeWithDefaultTypeArgs(type) {
1634
- if (type.shared.typeParams.length === 0 || type.priv.typeArgs) {
1641
+ if (type.shared.typeParams.length === 0 || type.priv.typeArgs || !type.shared.typeVarScopeId) {
1635
1642
  return type;
1636
1643
  }
1637
1644
  const solution = new constraintSolution_1.ConstraintSolution();
1638
- const typeParams = types_1.ClassType.getTypeParams(type);
1639
- typeParams.forEach((typeParam) => {
1640
- solution.setType(typeParam, applySolvedTypeVars(typeParam.shared.defaultType, solution));
1645
+ return applySolvedTypeVars(type, solution, {
1646
+ replaceUnsolved: { scopeIds: [type.shared.typeVarScopeId], tupleClassType: undefined },
1641
1647
  });
1642
- return applySolvedTypeVars(type, solution);
1643
1648
  }
1644
1649
  // Builds a mapping between type parameters and their specialized
1645
1650
  // types. For example, if the generic type is Dict[_T1, _T2] and the
@@ -2871,6 +2876,7 @@ class TypeVarTransformer {
2871
2876
  let newTypeArgs;
2872
2877
  let newTupleTypeArgs;
2873
2878
  let specializationNeeded = false;
2879
+ let isTypeArgExplicit = true;
2874
2880
  // If type args were previously provided, specialize them.
2875
2881
  // Handle tuples specially.
2876
2882
  if (types_1.ClassType.isTupleClass(classType)) {
@@ -2916,6 +2922,7 @@ class TypeVarTransformer {
2916
2922
  const newTypeArgType = this.apply(typeParams[0], recursionCount);
2917
2923
  newTupleTypeArgs = [{ type: newTypeArgType, isUnbounded: true }];
2918
2924
  specializationNeeded = true;
2925
+ isTypeArgExplicit = false;
2919
2926
  }
2920
2927
  }
2921
2928
  // If this is an empty tuple, don't recompute the non-tuple type argument.
@@ -2926,6 +2933,9 @@ class TypeVarTransformer {
2926
2933
  }
2927
2934
  if (!newTypeArgs) {
2928
2935
  const typeArgs = (_a = classType.priv.typeArgs) !== null && _a !== void 0 ? _a : typeParams;
2936
+ if (!classType.priv.typeArgs) {
2937
+ isTypeArgExplicit = false;
2938
+ }
2929
2939
  newTypeArgs = typeArgs.map((oldTypeArgType) => {
2930
2940
  let newTypeArgType = this.apply(oldTypeArgType, recursionCount);
2931
2941
  if (newTypeArgType !== oldTypeArgType) {
@@ -2943,8 +2953,7 @@ class TypeVarTransformer {
2943
2953
  if (!specializationNeeded) {
2944
2954
  return classType;
2945
2955
  }
2946
- return types_1.ClassType.specialize(classType, newTypeArgs,
2947
- /* isTypeArgExplicit */ true,
2956
+ return types_1.ClassType.specialize(classType, newTypeArgs, isTypeArgExplicit,
2948
2957
  /* includeSubclasses */ undefined, newTupleTypeArgs);
2949
2958
  }
2950
2959
  transformTypeVarsInFunctionType(sourceType, recursionCount) {
@@ -3300,32 +3309,44 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3300
3309
  return getUnknownForTypeVar(typeVar, (_c = this._options.replaceUnsolved) === null || _c === void 0 ? void 0 : _c.tupleClassType);
3301
3310
  }
3302
3311
  transformUnionSubtype(preTransform, postTransform) {
3303
- var _a, _b;
3312
+ var _a, _b, _c;
3304
3313
  // If a union contains unsolved TypeVars within scope, eliminate them
3305
3314
  // unless this results in an empty union. This elimination is needed
3306
3315
  // in cases where TypeVars can go unsolved due to unions in parameter
3307
3316
  // annotations, like this:
3308
3317
  // def test(x: Union[str, T]) -> Union[str, T]
3309
- if ((_a = this._options.replaceUnsolved) === null || _a === void 0 ? void 0 : _a.eliminateUnsolvedInUnions) {
3310
- if ((0, types_1.isTypeVar)(preTransform) &&
3311
- this._shouldReplaceTypeVar(preTransform) &&
3312
- this._shouldReplaceUnsolvedTypeVar(preTransform)) {
3313
- const solutionSet = this._solution.getSolutionSet((_b = this._activeConstraintSetIndex) !== null && _b !== void 0 ? _b : 0);
3314
- const typeVarType = solutionSet.getType(preTransform);
3315
- // Did the TypeVar remain unsolved?
3316
- if (!typeVarType || ((0, types_1.isTypeVar)(typeVarType) && types_1.TypeVarType.isUnification(typeVarType))) {
3317
- // If the TypeVar was not transformed, then it was unsolved,
3318
- // and we'll eliminate it.
3319
- if (preTransform === postTransform) {
3320
- return undefined;
3321
- }
3322
- // If useDefaultForUnsolved or useUnknownForUnsolved is true, the postTransform type will
3323
- // be Unknown, which we want to eliminate.
3324
- if (this._options.replaceUnsolved) {
3325
- if ((0, types_1.isUnknown)(postTransform)) {
3326
- return undefined;
3327
- }
3328
- }
3318
+ if (!((_a = this._options.replaceUnsolved) === null || _a === void 0 ? void 0 : _a.eliminateUnsolvedInUnions)) {
3319
+ return postTransform;
3320
+ }
3321
+ const solutionSet = this._solution.getSolutionSet((_b = this._activeConstraintSetIndex) !== null && _b !== void 0 ? _b : 0);
3322
+ if ((0, types_1.isTypeVar)(preTransform)) {
3323
+ if (!this._shouldReplaceTypeVar(preTransform) || !this._shouldReplaceUnsolvedTypeVar(preTransform)) {
3324
+ return postTransform;
3325
+ }
3326
+ const typeVarType = solutionSet.getType(preTransform);
3327
+ // Did the TypeVar remain unsolved?
3328
+ if (typeVarType) {
3329
+ if (!(0, types_1.isTypeVar)(typeVarType) || !types_1.TypeVarType.isUnification(typeVarType)) {
3330
+ return postTransform;
3331
+ }
3332
+ }
3333
+ // If the TypeVar was not transformed, then it was unsolved,
3334
+ // and we'll eliminate it.
3335
+ if (preTransform === postTransform) {
3336
+ return undefined;
3337
+ }
3338
+ // If useDefaultForUnsolved or useUnknownForUnsolved is true, the postTransform type will
3339
+ // be Unknown, which we want to eliminate.
3340
+ if (this._options.replaceUnsolved && (0, types_1.isUnknown)(postTransform)) {
3341
+ return undefined;
3342
+ }
3343
+ }
3344
+ else if ((_c = preTransform.props) === null || _c === void 0 ? void 0 : _c.condition) {
3345
+ // If this is a type that is conditioned on a unification TypeVar,
3346
+ // see if TypeVar was solved. If not, eliminate the type.
3347
+ for (const condition of preTransform.props.condition) {
3348
+ if (types_1.TypeVarType.isUnification(condition.typeVar) && !solutionSet.getType(condition.typeVar)) {
3349
+ return undefined;
3329
3350
  }
3330
3351
  }
3331
3352
  }