@zzzen/pyright-internal 1.2.0-dev.20230226 → 1.2.0-dev.20230305

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 (113) hide show
  1. package/dist/analyzer/binder.d.ts +0 -1
  2. package/dist/analyzer/binder.js +9 -92
  3. package/dist/analyzer/binder.js.map +1 -1
  4. package/dist/analyzer/checker.js +45 -28
  5. package/dist/analyzer/checker.js.map +1 -1
  6. package/dist/analyzer/codeFlowEngine.js +4 -4
  7. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  8. package/dist/analyzer/declaration.d.ts +2 -4
  9. package/dist/analyzer/declaration.js +6 -1
  10. package/dist/analyzer/declaration.js.map +1 -1
  11. package/dist/analyzer/declarationUtils.d.ts +1 -5
  12. package/dist/analyzer/declarationUtils.js +2 -47
  13. package/dist/analyzer/declarationUtils.js.map +1 -1
  14. package/dist/analyzer/docStringConversion.js +9 -3
  15. package/dist/analyzer/docStringConversion.js.map +1 -1
  16. package/dist/analyzer/parseTreeUtils.d.ts +4 -2
  17. package/dist/analyzer/parseTreeUtils.js +77 -2
  18. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  19. package/dist/analyzer/patternMatching.js +18 -1
  20. package/dist/analyzer/patternMatching.js.map +1 -1
  21. package/dist/analyzer/program.d.ts +1 -0
  22. package/dist/analyzer/program.js +151 -11
  23. package/dist/analyzer/program.js.map +1 -1
  24. package/dist/analyzer/properties.js +3 -2
  25. package/dist/analyzer/properties.js.map +1 -1
  26. package/dist/analyzer/protocols.js +4 -2
  27. package/dist/analyzer/protocols.js.map +1 -1
  28. package/dist/analyzer/pythonPathUtils.js +27 -13
  29. package/dist/analyzer/pythonPathUtils.js.map +1 -1
  30. package/dist/analyzer/service.js +6 -1
  31. package/dist/analyzer/service.js.map +1 -1
  32. package/dist/analyzer/symbol.js +1 -4
  33. package/dist/analyzer/symbol.js.map +1 -1
  34. package/dist/analyzer/symbolUtils.d.ts +0 -3
  35. package/dist/analyzer/symbolUtils.js +1 -14
  36. package/dist/analyzer/symbolUtils.js.map +1 -1
  37. package/dist/analyzer/typeDocStringUtils.js +5 -3
  38. package/dist/analyzer/typeDocStringUtils.js.map +1 -1
  39. package/dist/analyzer/typeEvaluator.js +503 -234
  40. package/dist/analyzer/typeEvaluator.js.map +1 -1
  41. package/dist/analyzer/typeEvaluatorTypes.d.ts +10 -2
  42. package/dist/analyzer/typeGuards.js +2 -2
  43. package/dist/analyzer/typeGuards.js.map +1 -1
  44. package/dist/analyzer/typeUtils.d.ts +1 -0
  45. package/dist/analyzer/typeUtils.js +14 -1
  46. package/dist/analyzer/typeUtils.js.map +1 -1
  47. package/dist/analyzer/typedDicts.js +26 -17
  48. package/dist/analyzer/typedDicts.js.map +1 -1
  49. package/dist/analyzer/types.d.ts +2 -1
  50. package/dist/analyzer/types.js.map +1 -1
  51. package/dist/common/collectionUtils.d.ts +1 -0
  52. package/dist/common/collectionUtils.js +8 -1
  53. package/dist/common/collectionUtils.js.map +1 -1
  54. package/dist/common/positionUtils.d.ts +2 -0
  55. package/dist/common/positionUtils.js +15 -1
  56. package/dist/common/positionUtils.js.map +1 -1
  57. package/dist/languageServerBase.js +6 -0
  58. package/dist/languageServerBase.js.map +1 -1
  59. package/dist/languageService/callHierarchyProvider.js +4 -2
  60. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  61. package/dist/languageService/completionProvider.js +46 -40
  62. package/dist/languageService/completionProvider.js.map +1 -1
  63. package/dist/languageService/completionProviderUtils.d.ts +1 -1
  64. package/dist/languageService/completionProviderUtils.js +3 -3
  65. package/dist/languageService/completionProviderUtils.js.map +1 -1
  66. package/dist/languageService/definitionProvider.js +2 -1
  67. package/dist/languageService/definitionProvider.js.map +1 -1
  68. package/dist/languageService/documentSymbolProvider.js +2 -1
  69. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  70. package/dist/languageService/hoverProvider.js +11 -3
  71. package/dist/languageService/hoverProvider.js.map +1 -1
  72. package/dist/languageService/importAdder.js +4 -1
  73. package/dist/languageService/importAdder.js.map +1 -1
  74. package/dist/languageService/indentationUtils.d.ts +1 -1
  75. package/dist/languageService/indentationUtils.js +22 -12
  76. package/dist/languageService/indentationUtils.js.map +1 -1
  77. package/dist/languageService/renameModuleProvider.js +20 -7
  78. package/dist/languageService/renameModuleProvider.js.map +1 -1
  79. package/dist/localization/localize.d.ts +9 -2
  80. package/dist/localization/localize.js +4 -1
  81. package/dist/localization/localize.js.map +1 -1
  82. package/dist/localization/package.nls.en-us.json +5 -2
  83. package/dist/parser/parser.js +18 -18
  84. package/dist/parser/parser.js.map +1 -1
  85. package/dist/pyright.js +1 -1
  86. package/dist/pyright.js.map +1 -1
  87. package/dist/tests/docStringConversion.test.js +23 -0
  88. package/dist/tests/docStringConversion.test.js.map +1 -1
  89. package/dist/tests/fourslash/completions.errorNodes.fourslash.d.ts +1 -0
  90. package/dist/tests/fourslash/completions.errorNodes.fourslash.js +24 -0
  91. package/dist/tests/fourslash/completions.errorNodes.fourslash.js.map +1 -0
  92. package/dist/tests/fourslash/hover.slots.fourslash.d.ts +1 -0
  93. package/dist/tests/fourslash/hover.slots.fourslash.js +16 -0
  94. package/dist/tests/fourslash/hover.slots.fourslash.js.map +1 -0
  95. package/dist/tests/importAdder.test.js +13 -0
  96. package/dist/tests/importAdder.test.js.map +1 -1
  97. package/dist/tests/indentationUtils.reindent.test.js +21 -0
  98. package/dist/tests/indentationUtils.reindent.test.js.map +1 -1
  99. package/dist/tests/moveSymbol.importAdder.test.js +137 -31
  100. package/dist/tests/moveSymbol.importAdder.test.js.map +1 -1
  101. package/dist/tests/moveSymbol.insertion.test.js +98 -0
  102. package/dist/tests/moveSymbol.insertion.test.js.map +1 -1
  103. package/dist/tests/renameModuleTestUtils.d.ts +1 -1
  104. package/dist/tests/renameModuleTestUtils.js +9 -5
  105. package/dist/tests/renameModuleTestUtils.js.map +1 -1
  106. package/dist/tests/typeEvaluator1.test.js +4 -0
  107. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  108. package/dist/tests/typeEvaluator2.test.js +1 -1
  109. package/dist/tests/typeEvaluator3.test.js +20 -4
  110. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  111. package/dist/tests/typeEvaluator5.test.js +6 -0
  112. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  113. package/package.json +1 -1
@@ -128,7 +128,6 @@ export declare class Binder extends ParseTreeWalker {
128
128
  private _isAnnotationClassVar;
129
129
  private _isRequiredAnnotation;
130
130
  private _isNotRequiredAnnotation;
131
- private _isAnnotationTypeAlias;
132
131
  private _getMemberAccessInfo;
133
132
  private _addImplicitImportsToLoaderActions;
134
133
  private _handleTypingStubAssignmentOrAnnotation;
@@ -46,6 +46,7 @@ const textRange_1 = require("../common/textRange");
46
46
  const localize_1 = require("../localization/localize");
47
47
  const AnalyzerNodeInfo = __importStar(require("./analyzerNodeInfo"));
48
48
  const codeFlowTypes_1 = require("./codeFlowTypes");
49
+ const declaration_1 = require("./declaration");
49
50
  const docStringUtils_1 = require("./docStringUtils");
50
51
  const ParseTreeUtils = __importStar(require("./parseTreeUtils"));
51
52
  const parseTreeWalker_1 = require("./parseTreeWalker");
@@ -1268,7 +1269,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1268
1269
  }
1269
1270
  visitImportFrom(node) {
1270
1271
  var _a;
1271
- const typingSymbolsOfInterest = ['Final', 'TypeAlias', 'ClassVar', 'Required', 'NotRequired', 'Annotated'];
1272
+ const typingSymbolsOfInterest = ['Final', 'ClassVar', 'Annotated'];
1272
1273
  const dataclassesSymbolsOfInterest = ['InitVar'];
1273
1274
  const importInfo = AnalyzerNodeInfo.getImportInfo(node.module);
1274
1275
  let resolvedPath = '';
@@ -1906,7 +1907,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1906
1907
  pathOfLastSubmodule = importInfo.resolvedPaths[importInfo.resolvedPaths.length - 1];
1907
1908
  }
1908
1909
  else {
1909
- pathOfLastSubmodule = '*** unresolved ***';
1910
+ pathOfLastSubmodule = declaration_1.UnresolvedModuleMarker;
1910
1911
  }
1911
1912
  const isResolved = importInfo && importInfo.isImportFound && !importInfo.isNativeLib && importInfo.resolvedPaths.length > 0;
1912
1913
  if (existingDecl) {
@@ -1964,7 +1965,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1964
1965
  if (!loaderActions) {
1965
1966
  const loaderActionPath = importInfo && i < importInfo.resolvedPaths.length
1966
1967
  ? importInfo.resolvedPaths[i]
1967
- : '*** unresolved ***';
1968
+ : declaration_1.UnresolvedModuleMarker;
1968
1969
  // Allocate a new loader action.
1969
1970
  loaderActions = {
1970
1971
  path: loaderActionPath,
@@ -2764,21 +2765,8 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2764
2765
  const symbolWithScope = this._currentScope.lookUpSymbolRecursive(name.value);
2765
2766
  if (symbolWithScope && symbolWithScope.symbol) {
2766
2767
  const finalInfo = this._isAnnotationFinal(typeAnnotation);
2767
- const isExplicitTypeAlias = this._isAnnotationTypeAlias(typeAnnotation);
2768
2768
  let typeAnnotationNode = typeAnnotation;
2769
- let innerTypeAnnotationNode = typeAnnotation;
2770
- if (isExplicitTypeAlias) {
2771
- typeAnnotationNode = undefined;
2772
- innerTypeAnnotationNode = undefined;
2773
- // Type aliases are allowed only in the global or class scope.
2774
- if (this._currentScope.type !== 2 /* Class */ &&
2775
- this._currentScope.type !== 3 /* Module */ &&
2776
- this._currentScope.type !== 4 /* Builtin */) {
2777
- this._addError(localize_1.Localizer.Diagnostic.typeAliasNotInModuleOrClass(), typeAnnotation);
2778
- }
2779
- }
2780
- else if (finalInfo.isFinal) {
2781
- innerTypeAnnotationNode = finalInfo.finalTypeNode;
2769
+ if (finalInfo.isFinal) {
2782
2770
  if (!finalInfo.finalTypeNode) {
2783
2771
  typeAnnotationNode = undefined;
2784
2772
  }
@@ -2786,7 +2774,6 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2786
2774
  // Is this annotation indicating that the variable is a "ClassVar"?
2787
2775
  let classVarInfo = this._isAnnotationClassVar(typeAnnotation);
2788
2776
  if (classVarInfo.isClassVar) {
2789
- innerTypeAnnotationNode = classVarInfo.classVarTypeNode;
2790
2777
  if (!classVarInfo.classVarTypeNode) {
2791
2778
  typeAnnotationNode = undefined;
2792
2779
  }
@@ -2811,11 +2798,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2811
2798
  node: target,
2812
2799
  isConstant: (0, symbolNameUtils_1.isConstantName)(name.value),
2813
2800
  isFinal: finalInfo.isFinal,
2814
- isClassVar: classVarInfo.isClassVar,
2815
- isRequired: this._isRequiredAnnotation(innerTypeAnnotationNode),
2816
- isNotRequired: this._isNotRequiredAnnotation(innerTypeAnnotationNode),
2817
- typeAliasAnnotation: isExplicitTypeAlias ? typeAnnotation : undefined,
2818
- typeAliasName: isExplicitTypeAlias ? target : undefined,
2801
+ typeAliasName: target,
2819
2802
  path: this._fileInfo.filePath,
2820
2803
  typeAnnotationNode,
2821
2804
  range: (0, positionUtils_1.convertTextRangeToRange)(name, this._fileInfo.lines),
@@ -2929,72 +2912,12 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2929
2912
  return false;
2930
2913
  }
2931
2914
  _getVariableDocString(node) {
2932
- var _a, _b, _c, _d;
2933
- // Walk up the parse tree to find an assignment expression.
2934
- let curNode = node;
2935
- let annotationNode;
2936
- while (curNode) {
2937
- if (curNode.nodeType === 3 /* Assignment */) {
2938
- break;
2939
- }
2940
- if (curNode.nodeType === 54 /* TypeAnnotation */ && !annotationNode) {
2941
- annotationNode = curNode;
2942
- }
2943
- curNode = curNode.parent;
2944
- }
2945
- if ((curNode === null || curNode === void 0 ? void 0 : curNode.nodeType) !== 3 /* Assignment */) {
2946
- // Allow a simple annotation statement to have a docstring even
2947
- // though PEP 258 doesn't mention this case. This PEP pre-dated
2948
- // PEP 526, so it didn't contemplate this situation.
2949
- if (annotationNode) {
2950
- curNode = annotationNode;
2951
- }
2952
- else {
2953
- return undefined;
2954
- }
2955
- }
2956
- const parentNode = curNode.parent;
2957
- if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.nodeType) !== 47 /* StatementList */) {
2958
- return undefined;
2959
- }
2960
- const suiteOrModule = parentNode.parent;
2961
- if (!suiteOrModule ||
2962
- (suiteOrModule.nodeType !== 36 /* Module */ && suiteOrModule.nodeType !== 50 /* Suite */)) {
2963
- return undefined;
2964
- }
2965
- const assignmentIndex = suiteOrModule.statements.findIndex((node) => node === parentNode);
2966
- if (assignmentIndex < 0 || assignmentIndex === suiteOrModule.statements.length - 1) {
2967
- return undefined;
2968
- }
2969
- const nextStatement = suiteOrModule.statements[assignmentIndex + 1];
2970
- if (nextStatement.nodeType !== 47 /* StatementList */ || !ParseTreeUtils.isDocString(nextStatement)) {
2971
- return undefined;
2972
- }
2973
- // See if the assignment is within one of the contexts specified in PEP 258.
2974
- let isValidContext = false;
2975
- if (((_a = parentNode === null || parentNode === void 0 ? void 0 : parentNode.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 36 /* Module */) {
2976
- // If we're at the top level of a module, the attribute docstring is valid.
2977
- isValidContext = true;
2978
- }
2979
- else if (((_b = parentNode === null || parentNode === void 0 ? void 0 : parentNode.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 50 /* Suite */ &&
2980
- ((_d = (_c = parentNode === null || parentNode === void 0 ? void 0 : parentNode.parent) === null || _c === void 0 ? void 0 : _c.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 10 /* Class */) {
2981
- // If we're at the top level of a class, the attribute docstring is valid.
2982
- isValidContext = true;
2983
- }
2984
- else {
2985
- const func = ParseTreeUtils.getEnclosingFunction(parentNode);
2986
- // If we're within an __init__ method, the attribute docstring is valid.
2987
- if (func &&
2988
- func.name.value === '__init__' &&
2989
- ParseTreeUtils.getEnclosingClass(func, /* stopAtFunction */ true)) {
2990
- isValidContext = true;
2991
- }
2992
- }
2993
- if (!isValidContext) {
2915
+ const docNode = ParseTreeUtils.getVariableDocStringNode(node);
2916
+ if (!docNode) {
2994
2917
  return undefined;
2995
2918
  }
2996
2919
  // A docstring can consist of multiple joined strings in a single expression.
2997
- const strings = nextStatement.statements[0].strings;
2920
+ const strings = docNode.strings;
2998
2921
  if (strings.length === 1) {
2999
2922
  // Common case.
3000
2923
  return strings[0].value;
@@ -3081,12 +3004,6 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
3081
3004
  }
3082
3005
  return false;
3083
3006
  }
3084
- _isAnnotationTypeAlias(typeAnnotation) {
3085
- if (!typeAnnotation) {
3086
- return false;
3087
- }
3088
- return this._isTypingAnnotation(typeAnnotation, 'TypeAlias');
3089
- }
3090
3007
  // Determines whether a member access expression is referring to a
3091
3008
  // member of a class (either a class or instance member). This will
3092
3009
  // typically take the form "self.x" or "cls.x".