@zzzen/pyright-internal 1.2.0-dev.20230730 → 1.2.0-dev.20230813

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 (159) hide show
  1. package/dist/analyzer/backgroundAnalysisProgram.d.ts +6 -5
  2. package/dist/analyzer/backgroundAnalysisProgram.js +6 -5
  3. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  4. package/dist/analyzer/binder.js +3 -0
  5. package/dist/analyzer/binder.js.map +1 -1
  6. package/dist/analyzer/checker.js +5 -3
  7. package/dist/analyzer/checker.js.map +1 -1
  8. package/dist/analyzer/codeFlowEngine.js +10 -6
  9. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  10. package/dist/analyzer/constraintSolver.d.ts +1 -0
  11. package/dist/analyzer/constraintSolver.js +30 -23
  12. package/dist/analyzer/constraintSolver.js.map +1 -1
  13. package/dist/analyzer/dataClasses.js +2 -2
  14. package/dist/analyzer/dataClasses.js.map +1 -1
  15. package/dist/analyzer/decorators.js +8 -8
  16. package/dist/analyzer/decorators.js.map +1 -1
  17. package/dist/analyzer/docStringConversion.js +9 -5
  18. package/dist/analyzer/docStringConversion.js.map +1 -1
  19. package/dist/analyzer/enums.js +1 -1
  20. package/dist/analyzer/enums.js.map +1 -1
  21. package/dist/analyzer/importResolver.js +15 -14
  22. package/dist/analyzer/importResolver.js.map +1 -1
  23. package/dist/analyzer/packageTypeVerifier.js +4 -1
  24. package/dist/analyzer/packageTypeVerifier.js.map +1 -1
  25. package/dist/analyzer/parameterUtils.js +5 -1
  26. package/dist/analyzer/parameterUtils.js.map +1 -1
  27. package/dist/analyzer/patternMatching.js +3 -3
  28. package/dist/analyzer/patternMatching.js.map +1 -1
  29. package/dist/analyzer/program.d.ts +4 -1
  30. package/dist/analyzer/program.js +8 -10
  31. package/dist/analyzer/program.js.map +1 -1
  32. package/dist/analyzer/protocols.js +28 -20
  33. package/dist/analyzer/protocols.js.map +1 -1
  34. package/dist/analyzer/service.d.ts +3 -0
  35. package/dist/analyzer/service.js +44 -9
  36. package/dist/analyzer/service.js.map +1 -1
  37. package/dist/analyzer/typeEvaluator.js +127 -78
  38. package/dist/analyzer/typeEvaluator.js.map +1 -1
  39. package/dist/analyzer/typeEvaluatorTypes.d.ts +5 -1
  40. package/dist/analyzer/typeEvaluatorTypes.js +8 -0
  41. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  42. package/dist/analyzer/typeGuards.js +6 -6
  43. package/dist/analyzer/typeGuards.js.map +1 -1
  44. package/dist/analyzer/typePrinter.js +1 -1
  45. package/dist/analyzer/typePrinter.js.map +1 -1
  46. package/dist/analyzer/typeUtils.d.ts +4 -6
  47. package/dist/analyzer/typeUtils.js +56 -31
  48. package/dist/analyzer/typeUtils.js.map +1 -1
  49. package/dist/analyzer/types.d.ts +9 -4
  50. package/dist/analyzer/types.js +4 -8
  51. package/dist/analyzer/types.js.map +1 -1
  52. package/dist/backgroundAnalysis.d.ts +2 -1
  53. package/dist/backgroundAnalysis.js +2 -2
  54. package/dist/backgroundAnalysis.js.map +1 -1
  55. package/dist/backgroundAnalysisBase.d.ts +3 -2
  56. package/dist/backgroundAnalysisBase.js +3 -3
  57. package/dist/backgroundAnalysisBase.js.map +1 -1
  58. package/dist/backgroundThreadBase.d.ts +7 -5
  59. package/dist/backgroundThreadBase.js +20 -6
  60. package/dist/backgroundThreadBase.js.map +1 -1
  61. package/dist/commands/dumpFileDebugInfoCommand.js +0 -1
  62. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  63. package/dist/common/chokidarFileWatcherProvider.d.ts +1 -1
  64. package/dist/common/console.js.map +1 -1
  65. package/dist/common/extensibility.d.ts +4 -29
  66. package/dist/common/extensibility.js +5 -1
  67. package/dist/common/extensibility.js.map +1 -1
  68. package/dist/common/fileSystem.d.ts +2 -15
  69. package/dist/common/fileSystem.js +1 -31
  70. package/dist/common/fileSystem.js.map +1 -1
  71. package/dist/common/fileWatcher.d.ts +15 -0
  72. package/dist/common/fileWatcher.js +34 -0
  73. package/dist/common/fileWatcher.js.map +1 -0
  74. package/dist/common/pathUtils.d.ts +1 -0
  75. package/dist/common/pathUtils.js +19 -5
  76. package/dist/common/pathUtils.js.map +1 -1
  77. package/dist/common/realFileSystem.d.ts +2 -1
  78. package/dist/common/realFileSystem.js +13 -9
  79. package/dist/common/realFileSystem.js.map +1 -1
  80. package/dist/common/serviceProvider.d.ts +14 -0
  81. package/dist/common/serviceProvider.js +37 -0
  82. package/dist/common/serviceProvider.js.map +1 -0
  83. package/dist/common/serviceProviderExtensions.d.ts +16 -0
  84. package/dist/common/serviceProviderExtensions.js +27 -0
  85. package/dist/common/serviceProviderExtensions.js.map +1 -0
  86. package/dist/languageServerBase.d.ts +11 -7
  87. package/dist/languageServerBase.js +21 -13
  88. package/dist/languageServerBase.js.map +1 -1
  89. package/dist/languageService/hoverProvider.js +1 -6
  90. package/dist/languageService/hoverProvider.js.map +1 -1
  91. package/dist/languageService/navigationUtils.js +1 -1
  92. package/dist/languageService/navigationUtils.js.map +1 -1
  93. package/dist/languageService/tooltipUtils.js +7 -1
  94. package/dist/languageService/tooltipUtils.js.map +1 -1
  95. package/dist/localization/localize.d.ts +3 -0
  96. package/dist/localization/localize.js +1 -0
  97. package/dist/localization/localize.js.map +1 -1
  98. package/dist/localization/package.nls.cs.json +1 -0
  99. package/dist/localization/package.nls.de.json +1 -0
  100. package/dist/localization/package.nls.en-us.json +3 -2
  101. package/dist/localization/package.nls.es.json +1 -0
  102. package/dist/localization/package.nls.fr.json +1 -0
  103. package/dist/localization/package.nls.it.json +1 -0
  104. package/dist/localization/package.nls.ja.json +1 -0
  105. package/dist/localization/package.nls.ko.json +1 -0
  106. package/dist/localization/package.nls.pl.json +1 -0
  107. package/dist/localization/package.nls.pt-br.json +1 -0
  108. package/dist/localization/package.nls.qps-ploc.json +1 -0
  109. package/dist/localization/package.nls.ru.json +1 -0
  110. package/dist/localization/package.nls.tr.json +1 -0
  111. package/dist/localization/package.nls.zh-cn.json +1 -0
  112. package/dist/localization/package.nls.zh-tw.json +1 -0
  113. package/dist/nodeMain.js +2 -1
  114. package/dist/nodeMain.js.map +1 -1
  115. package/dist/parser/parser.js +2 -2
  116. package/dist/parser/parser.js.map +1 -1
  117. package/dist/pyright.js +2 -0
  118. package/dist/pyright.js.map +1 -1
  119. package/dist/pyrightFileSystem.d.ts +3 -1
  120. package/dist/pyrightFileSystem.js.map +1 -1
  121. package/dist/readonlyAugmentedFileSystem.d.ts +3 -2
  122. package/dist/readonlyAugmentedFileSystem.js +2 -2
  123. package/dist/readonlyAugmentedFileSystem.js.map +1 -1
  124. package/dist/server.js +8 -1
  125. package/dist/server.js.map +1 -1
  126. package/dist/tests/docStringConversion.test.js +94 -0
  127. package/dist/tests/docStringConversion.test.js.map +1 -1
  128. package/dist/tests/fourslash/completions.importPrivateNoPytyped.fourslash.d.ts +0 -0
  129. package/dist/tests/fourslash/completions.importPrivateNoPytyped.fourslash.js +30 -0
  130. package/dist/tests/fourslash/completions.importPrivateNoPytyped.fourslash.js.map +1 -0
  131. package/dist/tests/fourslash/completions.importPytyped.fourslash.d.ts +0 -0
  132. package/dist/tests/fourslash/completions.importPytyped.fourslash.js +29 -0
  133. package/dist/tests/fourslash/completions.importPytyped.fourslash.js.map +1 -0
  134. package/dist/tests/fourslash/completions.importPytypedLocal.fourslash.d.ts +0 -0
  135. package/dist/tests/fourslash/completions.importPytypedLocal.fourslash.js +29 -0
  136. package/dist/tests/fourslash/completions.importPytypedLocal.fourslash.js.map +1 -0
  137. package/dist/tests/fourslash/hover.async.fourslash.d.ts +1 -0
  138. package/dist/tests/fourslash/hover.async.fourslash.js +12 -0
  139. package/dist/tests/fourslash/hover.async.fourslash.js.map +1 -0
  140. package/dist/tests/harness/fourslash/runner.js +1 -1
  141. package/dist/tests/harness/fourslash/runner.js.map +1 -1
  142. package/dist/tests/harness/fourslash/testLanguageService.js +1 -1
  143. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  144. package/dist/tests/harness/fourslash/testState.d.ts +1 -1
  145. package/dist/tests/harness/fourslash/testState.js +7 -2
  146. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  147. package/dist/tests/harness/vfs/filesystem.d.ts +3 -2
  148. package/dist/tests/harness/vfs/filesystem.js +1 -1
  149. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  150. package/dist/tests/service.test.js +65 -0
  151. package/dist/tests/service.test.js.map +1 -1
  152. package/dist/tests/testUtils.js +6 -1
  153. package/dist/tests/testUtils.js.map +1 -1
  154. package/dist/tests/typeEvaluator4.test.js +2 -2
  155. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  156. package/dist/tests/typeEvaluator5.test.js +1 -1
  157. package/dist/tests/zipfs.test.js +8 -5
  158. package/dist/tests/zipfs.test.js.map +1 -1
  159. package/package.json +1 -1
@@ -109,7 +109,17 @@ var AssignTypeFlags;
109
109
  // each other.
110
110
  class UniqueSignatureTracker {
111
111
  constructor() {
112
- this._signaturesSeen = [];
112
+ this._trackedSignatures = [];
113
+ }
114
+ getTrackedSignatures() {
115
+ return this._trackedSignatures;
116
+ }
117
+ addTrackedSignatures(signatures) {
118
+ signatures.forEach((s) => {
119
+ s.expressionOffsets.forEach((offset) => {
120
+ this.addSignature(s.type, offset);
121
+ });
122
+ });
113
123
  }
114
124
  findSignature(signature) {
115
125
  // Use the associated overload type if this is a function associated with an overload.
@@ -117,7 +127,7 @@ class UniqueSignatureTracker {
117
127
  if ((0, types_1.isFunction)(signature) && signature.overloaded) {
118
128
  effectiveSignature = signature.overloaded;
119
129
  }
120
- return this._signaturesSeen.find((s) => {
130
+ return this._trackedSignatures.find((s) => {
121
131
  return (0, types_1.isTypeSame)(effectiveSignature, s.type);
122
132
  });
123
133
  }
@@ -132,7 +142,7 @@ class UniqueSignatureTracker {
132
142
  }
133
143
  }
134
144
  else {
135
- this._signaturesSeen.push({ type: effectiveSignature, expressionOffsets: [offset] });
145
+ this._trackedSignatures.push({ type: effectiveSignature, expressionOffsets: [offset] });
136
146
  }
137
147
  }
138
148
  }
@@ -186,35 +196,35 @@ function makeInferenceContext(expectedType, isTypeIncomplete, signatureTracker)
186
196
  }
187
197
  exports.makeInferenceContext = makeInferenceContext;
188
198
  // Calls a callback for each subtype and combines the results
189
- // into a final type.
199
+ // into a final type. It performs no memory allocations if the
200
+ // transformed type is the same as the original.
190
201
  function mapSubtypes(type, callback) {
191
202
  if ((0, types_1.isUnion)(type)) {
192
- const newSubtypes = [];
193
- let typeChanged = false;
194
- type.subtypes.forEach((subtype) => {
203
+ for (let i = 0; i < type.subtypes.length; i++) {
204
+ const subtype = type.subtypes[i];
195
205
  const transformedType = callback(subtype);
196
- if (transformedType) {
197
- if (transformedType !== subtype) {
198
- newSubtypes.push(addConditionToType(transformedType, getTypeCondition(type)));
199
- typeChanged = true;
206
+ // Avoid doing any memory allocations until a change is detected.
207
+ if (subtype !== transformedType) {
208
+ const typesToCombine = type.subtypes.slice(0, i);
209
+ // Create a helper lambda that accumulates transformed subtypes.
210
+ const accumulateSubtype = (newSubtype) => {
211
+ if (newSubtype) {
212
+ typesToCombine.push(addConditionToType(newSubtype, getTypeCondition(type)));
213
+ }
214
+ };
215
+ accumulateSubtype(transformedType);
216
+ for (i++; i < type.subtypes.length; i++) {
217
+ accumulateSubtype(callback(type.subtypes[i]));
200
218
  }
201
- else {
202
- newSubtypes.push(subtype);
219
+ const newType = (0, types_1.combineTypes)(typesToCombine);
220
+ // Do our best to retain type aliases.
221
+ if (newType.category === 9 /* Union */) {
222
+ types_1.UnionType.addTypeAliasSource(newType, type);
203
223
  }
224
+ return newType;
204
225
  }
205
- else {
206
- typeChanged = true;
207
- }
208
- });
209
- if (!typeChanged) {
210
- return type;
211
- }
212
- const newType = (0, types_1.combineTypes)(newSubtypes);
213
- // Do our best to retain type aliases.
214
- if (newType.category === 9 /* Union */) {
215
- types_1.UnionType.addTypeAliasSource(newType, type);
216
226
  }
217
- return newType;
227
+ return type;
218
228
  }
219
229
  const transformedSubtype = callback(type);
220
230
  if (!transformedSubtype) {
@@ -519,7 +529,7 @@ function transformPossibleRecursiveTypeAlias(type) {
519
529
  let newType = mapSubtypes(type, (subtype) => transformPossibleRecursiveTypeAlias(subtype));
520
530
  if (newType !== type && type.typeAliasInfo) {
521
531
  // Copy the type alias information if present.
522
- newType = types_1.TypeBase.cloneForTypeAlias(newType, type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.typeParameters, type.typeAliasInfo.typeArguments);
532
+ newType = types_1.TypeBase.cloneForTypeAlias(newType, type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.isPep695Syntax, type.typeAliasInfo.typeParameters, type.typeAliasInfo.typeArguments);
523
533
  }
524
534
  return newType;
525
535
  }
@@ -752,7 +762,18 @@ function partiallySpecializeType(type, contextClassType, selfClass, typeClassTyp
752
762
  exports.partiallySpecializeType = partiallySpecializeType;
753
763
  function populateTypeVarContextForSelfType(typeVarContext, contextClassType, selfClass) {
754
764
  const synthesizedSelfTypeVar = synthesizeTypeVarForSelfCls(contextClassType, /* isClsParam */ false);
755
- typeVarContext.setTypeVarType(synthesizedSelfTypeVar, convertToInstance(selfClass));
765
+ const selfInstance = convertToInstance(selfClass);
766
+ // We can't call stripLiteralValue here because that method requires the type evaluator.
767
+ // Instead, we'll do a simplified version of it here.
768
+ const selfWithoutLiteral = mapSubtypes(selfInstance, (subtype) => {
769
+ if ((0, types_1.isClass)(subtype)) {
770
+ if (subtype.literalValue !== undefined) {
771
+ return types_1.ClassType.cloneWithLiteral(subtype, /* value */ undefined);
772
+ }
773
+ }
774
+ return subtype;
775
+ });
776
+ typeVarContext.setTypeVarType(synthesizedSelfTypeVar, selfInstance, selfWithoutLiteral);
756
777
  }
757
778
  exports.populateTypeVarContextForSelfType = populateTypeVarContextForSelfType;
758
779
  // Looks for duplicate function types within the type and ensures that
@@ -1596,7 +1617,7 @@ function convertToInstance(type, includeSubclasses = true) {
1596
1617
  });
1597
1618
  // Copy over any type alias information.
1598
1619
  if (type.typeAliasInfo && type !== result) {
1599
- result = types_1.TypeBase.cloneForTypeAlias(result, type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.typeParameters, type.typeAliasInfo.typeArguments);
1620
+ result = types_1.TypeBase.cloneForTypeAlias(result, type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.isPep695Syntax, type.typeAliasInfo.typeParameters, type.typeAliasInfo.typeArguments);
1600
1621
  }
1601
1622
  if (type !== result && includeSubclasses) {
1602
1623
  // Cache the converted value for next time.
@@ -1633,7 +1654,7 @@ function convertToInstantiable(type, includeSubclasses = true) {
1633
1654
  });
1634
1655
  // Copy over any type alias information.
1635
1656
  if (type.typeAliasInfo && type !== result) {
1636
- result = types_1.TypeBase.cloneForTypeAlias(result, type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.typeParameters, type.typeAliasInfo.typeArguments);
1657
+ result = types_1.TypeBase.cloneForTypeAlias(result, type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.isPep695Syntax, type.typeAliasInfo.typeParameters, type.typeAliasInfo.typeArguments);
1637
1658
  }
1638
1659
  if (type !== result) {
1639
1660
  // Cache the converted value for next time.
@@ -2417,7 +2438,7 @@ class TypeVarTransformer {
2417
2438
  return replacementType;
2418
2439
  });
2419
2440
  if (requiresUpdate) {
2420
- return types_1.TypeBase.cloneForTypeAlias(type, type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.typeParameters, typeArgs);
2441
+ return types_1.TypeBase.cloneForTypeAlias(type, type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.isPep695Syntax, type.typeAliasInfo.typeParameters, typeArgs);
2421
2442
  }
2422
2443
  return type;
2423
2444
  }
@@ -2540,7 +2561,7 @@ class TypeVarTransformer {
2540
2561
  return updatedType;
2541
2562
  });
2542
2563
  return requiresUpdate
2543
- ? types_1.TypeBase.cloneForTypeAlias(type, type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.typeParameters, newTypeArgs)
2564
+ ? types_1.TypeBase.cloneForTypeAlias(type, type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.isPep695Syntax, type.typeAliasInfo.typeParameters, newTypeArgs)
2544
2565
  : type;
2545
2566
  }
2546
2567
  transformTypeVarsInClassType(classType, recursionCount) {
@@ -2857,6 +2878,9 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
2857
2878
  return classType;
2858
2879
  }
2859
2880
  transformTypeVarsInFunctionType(sourceType, recursionCount) {
2881
+ if (sourceType.trackedSignatures) {
2882
+ this._signatureTracker.addTrackedSignatures(sourceType.trackedSignatures);
2883
+ }
2860
2884
  // If this function is not generic, there's no need to check for uniqueness.
2861
2885
  if (sourceType.details.typeParameters.length === 0) {
2862
2886
  return super.transformTypeVarsInFunctionType(sourceType, recursionCount);
@@ -3103,6 +3127,7 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3103
3127
  const filteredOverloads = [];
3104
3128
  doForEachSubtype((0, types_1.combineTypes)(overloadTypes), (subtype) => {
3105
3129
  (0, debug_1.assert)((0, types_1.isFunction)(subtype));
3130
+ subtype = types_1.FunctionType.cloneWithNewFlags(subtype, subtype.details.flags | 256 /* Overloaded */);
3106
3131
  filteredOverloads.push(subtype);
3107
3132
  });
3108
3133
  if (filteredOverloads.length === 1) {