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

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 (148) hide show
  1. package/dist/analyzer/binder.d.ts +0 -1
  2. package/dist/analyzer/binder.js +32 -95
  3. package/dist/analyzer/binder.js.map +1 -1
  4. package/dist/analyzer/checker.js +48 -31
  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/commentUtils.js +11 -1
  9. package/dist/analyzer/commentUtils.js.map +1 -1
  10. package/dist/analyzer/constructorTransform.d.ts +1 -0
  11. package/dist/analyzer/constructorTransform.js +19 -2
  12. package/dist/analyzer/constructorTransform.js.map +1 -1
  13. package/dist/analyzer/declaration.d.ts +2 -4
  14. package/dist/analyzer/declaration.js +6 -1
  15. package/dist/analyzer/declaration.js.map +1 -1
  16. package/dist/analyzer/declarationUtils.d.ts +1 -5
  17. package/dist/analyzer/declarationUtils.js +2 -47
  18. package/dist/analyzer/declarationUtils.js.map +1 -1
  19. package/dist/analyzer/docStringConversion.js +9 -3
  20. package/dist/analyzer/docStringConversion.js.map +1 -1
  21. package/dist/analyzer/packageTypeVerifier.js +40 -40
  22. package/dist/analyzer/packageTypeVerifier.js.map +1 -1
  23. package/dist/analyzer/parseTreeUtils.d.ts +4 -2
  24. package/dist/analyzer/parseTreeUtils.js +77 -2
  25. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  26. package/dist/analyzer/patternMatching.js +20 -1
  27. package/dist/analyzer/patternMatching.js.map +1 -1
  28. package/dist/analyzer/program.d.ts +1 -0
  29. package/dist/analyzer/program.js +154 -13
  30. package/dist/analyzer/program.js.map +1 -1
  31. package/dist/analyzer/properties.js +3 -2
  32. package/dist/analyzer/properties.js.map +1 -1
  33. package/dist/analyzer/protocols.js +4 -2
  34. package/dist/analyzer/protocols.js.map +1 -1
  35. package/dist/analyzer/pythonPathUtils.js +27 -13
  36. package/dist/analyzer/pythonPathUtils.js.map +1 -1
  37. package/dist/analyzer/service.js +6 -1
  38. package/dist/analyzer/service.js.map +1 -1
  39. package/dist/analyzer/sourceFile.js +12 -1
  40. package/dist/analyzer/sourceFile.js.map +1 -1
  41. package/dist/analyzer/symbol.js +1 -4
  42. package/dist/analyzer/symbol.js.map +1 -1
  43. package/dist/analyzer/symbolUtils.d.ts +0 -3
  44. package/dist/analyzer/symbolUtils.js +1 -14
  45. package/dist/analyzer/symbolUtils.js.map +1 -1
  46. package/dist/analyzer/typeDocStringUtils.js +5 -3
  47. package/dist/analyzer/typeDocStringUtils.js.map +1 -1
  48. package/dist/analyzer/typeEvaluator.js +642 -259
  49. package/dist/analyzer/typeEvaluator.js.map +1 -1
  50. package/dist/analyzer/typeEvaluatorTypes.d.ts +11 -2
  51. package/dist/analyzer/typeGuards.js +2 -2
  52. package/dist/analyzer/typeGuards.js.map +1 -1
  53. package/dist/analyzer/typePrinter.js +63 -55
  54. package/dist/analyzer/typePrinter.js.map +1 -1
  55. package/dist/analyzer/typeUtils.d.ts +2 -0
  56. package/dist/analyzer/typeUtils.js +22 -3
  57. package/dist/analyzer/typeUtils.js.map +1 -1
  58. package/dist/analyzer/typedDicts.d.ts +2 -1
  59. package/dist/analyzer/typedDicts.js +83 -57
  60. package/dist/analyzer/typedDicts.js.map +1 -1
  61. package/dist/analyzer/types.d.ts +3 -1
  62. package/dist/analyzer/types.js +8 -0
  63. package/dist/analyzer/types.js.map +1 -1
  64. package/dist/commands/dumpFileDebugInfoCommand.js +78 -0
  65. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  66. package/dist/common/collectionUtils.d.ts +1 -0
  67. package/dist/common/collectionUtils.js +8 -1
  68. package/dist/common/collectionUtils.js.map +1 -1
  69. package/dist/common/extensibility.js +25 -1
  70. package/dist/common/extensibility.js.map +1 -1
  71. package/dist/common/positionUtils.d.ts +2 -0
  72. package/dist/common/positionUtils.js +15 -1
  73. package/dist/common/positionUtils.js.map +1 -1
  74. package/dist/languageServerBase.js +9 -1
  75. package/dist/languageServerBase.js.map +1 -1
  76. package/dist/languageService/callHierarchyProvider.js +4 -2
  77. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  78. package/dist/languageService/completionProvider.d.ts +4 -2
  79. package/dist/languageService/completionProvider.js +252 -191
  80. package/dist/languageService/completionProvider.js.map +1 -1
  81. package/dist/languageService/completionProviderUtils.d.ts +1 -1
  82. package/dist/languageService/completionProviderUtils.js +3 -3
  83. package/dist/languageService/completionProviderUtils.js.map +1 -1
  84. package/dist/languageService/definitionProvider.js +2 -1
  85. package/dist/languageService/definitionProvider.js.map +1 -1
  86. package/dist/languageService/documentSymbolProvider.js +2 -1
  87. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  88. package/dist/languageService/hoverProvider.js +11 -3
  89. package/dist/languageService/hoverProvider.js.map +1 -1
  90. package/dist/languageService/importAdder.js +4 -1
  91. package/dist/languageService/importAdder.js.map +1 -1
  92. package/dist/languageService/indentationUtils.d.ts +1 -1
  93. package/dist/languageService/indentationUtils.js +22 -12
  94. package/dist/languageService/indentationUtils.js.map +1 -1
  95. package/dist/languageService/renameModuleProvider.d.ts +1 -1
  96. package/dist/languageService/renameModuleProvider.js +28 -8
  97. package/dist/languageService/renameModuleProvider.js.map +1 -1
  98. package/dist/languageService/tooltipUtils.js +2 -1
  99. package/dist/languageService/tooltipUtils.js.map +1 -1
  100. package/dist/localization/localize.d.ts +12 -2
  101. package/dist/localization/localize.js +5 -1
  102. package/dist/localization/localize.js.map +1 -1
  103. package/dist/localization/package.nls.en-us.json +6 -2
  104. package/dist/parser/parser.js +40 -25
  105. package/dist/parser/parser.js.map +1 -1
  106. package/dist/parser/tokenizer.js +1 -1
  107. package/dist/pyright.js +1 -1
  108. package/dist/pyright.js.map +1 -1
  109. package/dist/tests/completions.test.js +445 -0
  110. package/dist/tests/completions.test.js.map +1 -1
  111. package/dist/tests/docStringConversion.test.js +23 -0
  112. package/dist/tests/docStringConversion.test.js.map +1 -1
  113. package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js +13 -3
  114. package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js.map +1 -1
  115. package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js +7 -2
  116. package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js.map +1 -1
  117. package/dist/tests/fourslash/completions.errorNodes.fourslash.d.ts +1 -0
  118. package/dist/tests/fourslash/completions.errorNodes.fourslash.js +24 -0
  119. package/dist/tests/fourslash/completions.errorNodes.fourslash.js.map +1 -0
  120. package/dist/tests/fourslash/hover.slots.fourslash.d.ts +1 -0
  121. package/dist/tests/fourslash/hover.slots.fourslash.js +16 -0
  122. package/dist/tests/fourslash/hover.slots.fourslash.js.map +1 -0
  123. package/dist/tests/hoverProvider.test.js +1 -1
  124. package/dist/tests/hoverProvider.test.js.map +1 -1
  125. package/dist/tests/importAdder.test.js +13 -0
  126. package/dist/tests/importAdder.test.js.map +1 -1
  127. package/dist/tests/indentationUtils.reindent.test.js +21 -0
  128. package/dist/tests/indentationUtils.reindent.test.js.map +1 -1
  129. package/dist/tests/moveSymbol.importAdder.test.js +137 -31
  130. package/dist/tests/moveSymbol.importAdder.test.js.map +1 -1
  131. package/dist/tests/moveSymbol.insertion.test.js +98 -0
  132. package/dist/tests/moveSymbol.insertion.test.js.map +1 -1
  133. package/dist/tests/moveSymbol.misc.test.js +27 -0
  134. package/dist/tests/moveSymbol.misc.test.js.map +1 -1
  135. package/dist/tests/renameModuleTestUtils.d.ts +1 -1
  136. package/dist/tests/renameModuleTestUtils.js +9 -5
  137. package/dist/tests/renameModuleTestUtils.js.map +1 -1
  138. package/dist/tests/typeEvaluator1.test.js +8 -0
  139. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  140. package/dist/tests/typeEvaluator2.test.js +5 -1
  141. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  142. package/dist/tests/typeEvaluator3.test.js +20 -4
  143. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  144. package/dist/tests/typeEvaluator4.test.js +4 -0
  145. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  146. package/dist/tests/typeEvaluator5.test.js +6 -0
  147. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  148. 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) {
@@ -1920,7 +1921,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1920
1921
  loadSymbolsFromPath: false,
1921
1922
  range: (0, textRange_1.getEmptyRange)(),
1922
1923
  usesLocalName: !!importAlias,
1923
- moduleName: importInfo.importName,
1924
+ moduleName: firstNamePartValue,
1924
1925
  firstNamePart: firstNamePartValue,
1925
1926
  isInExceptSuite: this._isInExceptSuite,
1926
1927
  };
@@ -1942,6 +1943,14 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1942
1943
  isInExceptSuite: this._isInExceptSuite,
1943
1944
  };
1944
1945
  }
1946
+ // See if there is import info for this part of the path. This allows us
1947
+ // to implicitly import all of the modules in a multi-part module name.
1948
+ const implicitImportInfo = AnalyzerNodeInfo.getImportInfo(node.module.nameParts[0]);
1949
+ if (implicitImportInfo && implicitImportInfo.resolvedPaths.length) {
1950
+ newDecl.path = implicitImportInfo.resolvedPaths[0];
1951
+ newDecl.loadSymbolsFromPath = true;
1952
+ this._addImplicitImportsToLoaderActions(implicitImportInfo, newDecl);
1953
+ }
1945
1954
  // Add the implicit imports for this module if it's the last
1946
1955
  // name part we're resolving.
1947
1956
  if (importAlias || node.module.nameParts.length === 1) {
@@ -1964,7 +1973,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1964
1973
  if (!loaderActions) {
1965
1974
  const loaderActionPath = importInfo && i < importInfo.resolvedPaths.length
1966
1975
  ? importInfo.resolvedPaths[i]
1967
- : '*** unresolved ***';
1976
+ : declaration_1.UnresolvedModuleMarker;
1968
1977
  // Allocate a new loader action.
1969
1978
  loaderActions = {
1970
1979
  path: loaderActionPath,
@@ -1977,15 +1986,27 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1977
1986
  }
1978
1987
  curLoaderActions.implicitImports.set(namePartValue, loaderActions);
1979
1988
  }
1980
- // If this is the last name part we're resolving, add in the
1981
- // implicit imports as well.
1982
1989
  if (i === node.module.nameParts.length - 1) {
1990
+ // If this is the last name part we're resolving, add in the
1991
+ // implicit imports as well.
1983
1992
  if (importInfo && i < importInfo.resolvedPaths.length) {
1984
1993
  loaderActions.path = importInfo.resolvedPaths[i];
1985
1994
  loaderActions.loadSymbolsFromPath = true;
1986
1995
  this._addImplicitImportsToLoaderActions(importInfo, loaderActions);
1987
1996
  }
1988
1997
  }
1998
+ else {
1999
+ // If this isn't the last name part we're resolving, see if there
2000
+ // is import info for this part of the path. This allows us to implicitly
2001
+ // import all of the modules in a multi-part module name (e.g. "import a.b.c"
2002
+ // imports "a" and "a.b" and "a.b.c").
2003
+ const implicitImportInfo = AnalyzerNodeInfo.getImportInfo(node.module.nameParts[i]);
2004
+ if (implicitImportInfo && implicitImportInfo.resolvedPaths.length) {
2005
+ loaderActions.path = implicitImportInfo.resolvedPaths[i];
2006
+ loaderActions.loadSymbolsFromPath = true;
2007
+ this._addImplicitImportsToLoaderActions(implicitImportInfo, loaderActions);
2008
+ }
2009
+ }
1989
2010
  curLoaderActions = loaderActions;
1990
2011
  }
1991
2012
  }
@@ -2764,21 +2785,8 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2764
2785
  const symbolWithScope = this._currentScope.lookUpSymbolRecursive(name.value);
2765
2786
  if (symbolWithScope && symbolWithScope.symbol) {
2766
2787
  const finalInfo = this._isAnnotationFinal(typeAnnotation);
2767
- const isExplicitTypeAlias = this._isAnnotationTypeAlias(typeAnnotation);
2768
2788
  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;
2789
+ if (finalInfo.isFinal) {
2782
2790
  if (!finalInfo.finalTypeNode) {
2783
2791
  typeAnnotationNode = undefined;
2784
2792
  }
@@ -2786,7 +2794,6 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2786
2794
  // Is this annotation indicating that the variable is a "ClassVar"?
2787
2795
  let classVarInfo = this._isAnnotationClassVar(typeAnnotation);
2788
2796
  if (classVarInfo.isClassVar) {
2789
- innerTypeAnnotationNode = classVarInfo.classVarTypeNode;
2790
2797
  if (!classVarInfo.classVarTypeNode) {
2791
2798
  typeAnnotationNode = undefined;
2792
2799
  }
@@ -2811,11 +2818,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2811
2818
  node: target,
2812
2819
  isConstant: (0, symbolNameUtils_1.isConstantName)(name.value),
2813
2820
  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,
2821
+ typeAliasName: target,
2819
2822
  path: this._fileInfo.filePath,
2820
2823
  typeAnnotationNode,
2821
2824
  range: (0, positionUtils_1.convertTextRangeToRange)(name, this._fileInfo.lines),
@@ -2929,72 +2932,12 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2929
2932
  return false;
2930
2933
  }
2931
2934
  _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) {
2935
+ const docNode = ParseTreeUtils.getVariableDocStringNode(node);
2936
+ if (!docNode) {
2994
2937
  return undefined;
2995
2938
  }
2996
2939
  // A docstring can consist of multiple joined strings in a single expression.
2997
- const strings = nextStatement.statements[0].strings;
2940
+ const strings = docNode.strings;
2998
2941
  if (strings.length === 1) {
2999
2942
  // Common case.
3000
2943
  return strings[0].value;
@@ -3081,12 +3024,6 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
3081
3024
  }
3082
3025
  return false;
3083
3026
  }
3084
- _isAnnotationTypeAlias(typeAnnotation) {
3085
- if (!typeAnnotation) {
3086
- return false;
3087
- }
3088
- return this._isTypingAnnotation(typeAnnotation, 'TypeAlias');
3089
- }
3090
3027
  // Determines whether a member access expression is referring to a
3091
3028
  // member of a class (either a class or instance member). This will
3092
3029
  // typically take the form "self.x" or "cls.x".