@zzzen/pyright-internal 1.1.254 → 1.2.0-dev.2022-07-02

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 (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/analyzer/analyzerFileInfo.d.ts +1 -1
  4. package/dist/analyzer/backgroundAnalysisProgram.d.ts +1 -0
  5. package/dist/analyzer/backgroundAnalysisProgram.js +3 -0
  6. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  7. package/dist/analyzer/binder.js +9 -2
  8. package/dist/analyzer/binder.js.map +1 -1
  9. package/dist/analyzer/checker.js +19 -26
  10. package/dist/analyzer/checker.js.map +1 -1
  11. package/dist/analyzer/codeFlowUtils.js +33 -0
  12. package/dist/analyzer/codeFlowUtils.js.map +1 -1
  13. package/dist/analyzer/dataClasses.js +6 -4
  14. package/dist/analyzer/dataClasses.js.map +1 -1
  15. package/dist/analyzer/declaration.js +11 -1
  16. package/dist/analyzer/declaration.js.map +1 -1
  17. package/dist/analyzer/importResult.js +7 -0
  18. package/dist/analyzer/importResult.js.map +1 -1
  19. package/dist/analyzer/importStatementUtils.js +10 -1
  20. package/dist/analyzer/importStatementUtils.js.map +1 -1
  21. package/dist/analyzer/namedTuples.js +1 -1
  22. package/dist/analyzer/namedTuples.js.map +1 -1
  23. package/dist/analyzer/packageTypeReport.js +10 -1
  24. package/dist/analyzer/packageTypeReport.js.map +1 -1
  25. package/dist/analyzer/parseTreeUtils.js +11 -2
  26. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  27. package/dist/analyzer/program.d.ts +2 -1
  28. package/dist/analyzer/program.js +27 -23
  29. package/dist/analyzer/program.js.map +1 -1
  30. package/dist/analyzer/protocols.js +3 -1
  31. package/dist/analyzer/protocols.js.map +1 -1
  32. package/dist/analyzer/scope.js +22 -1
  33. package/dist/analyzer/scope.js.map +1 -1
  34. package/dist/analyzer/service.d.ts +20 -8
  35. package/dist/analyzer/service.js +39 -19
  36. package/dist/analyzer/service.js.map +1 -1
  37. package/dist/analyzer/sourceFile.js +1 -1
  38. package/dist/analyzer/sourceFile.js.map +1 -1
  39. package/dist/analyzer/sourceFileInfoUtils.d.ts +2 -0
  40. package/dist/analyzer/sourceFileInfoUtils.js +15 -0
  41. package/dist/analyzer/sourceFileInfoUtils.js.map +1 -0
  42. package/dist/analyzer/symbol.d.ts +3 -1
  43. package/dist/analyzer/symbol.js +39 -1
  44. package/dist/analyzer/symbol.js.map +1 -1
  45. package/dist/analyzer/typeDocStringUtils.js +10 -2
  46. package/dist/analyzer/typeDocStringUtils.js.map +1 -1
  47. package/dist/analyzer/typeEvaluator.js +86 -32
  48. package/dist/analyzer/typeEvaluator.js.map +1 -1
  49. package/dist/analyzer/typeEvaluatorTypes.d.ts +0 -1
  50. package/dist/analyzer/typeEvaluatorTypes.js +65 -1
  51. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  52. package/dist/analyzer/typeGuards.d.ts +2 -0
  53. package/dist/analyzer/typeGuards.js +113 -69
  54. package/dist/analyzer/typeGuards.js.map +1 -1
  55. package/dist/analyzer/typePrinter.js +23 -1
  56. package/dist/analyzer/typePrinter.js.map +1 -1
  57. package/dist/analyzer/typeUtils.js +119 -28
  58. package/dist/analyzer/typeUtils.js.map +1 -1
  59. package/dist/analyzer/typedDicts.js +2 -1
  60. package/dist/analyzer/typedDicts.js.map +1 -1
  61. package/dist/analyzer/types.d.ts +1 -0
  62. package/dist/analyzer/types.js +195 -1
  63. package/dist/analyzer/types.js.map +1 -1
  64. package/dist/backgroundAnalysisBase.d.ts +1 -1
  65. package/dist/commands/commands.js +9 -0
  66. package/dist/commands/commands.js.map +1 -1
  67. package/dist/common/commandLineOptions.js +8 -1
  68. package/dist/common/commandLineOptions.js.map +1 -1
  69. package/dist/common/core.js +7 -1
  70. package/dist/common/core.js.map +1 -1
  71. package/dist/common/diagnostic.js +9 -1
  72. package/dist/common/diagnostic.js.map +1 -1
  73. package/dist/common/host.js +7 -1
  74. package/dist/common/host.js.map +1 -1
  75. package/dist/common/pathUtils.d.ts +1 -0
  76. package/dist/common/pathUtils.js +34 -1
  77. package/dist/common/pathUtils.js.map +1 -1
  78. package/dist/common/stringUtils.d.ts +1 -0
  79. package/dist/common/stringUtils.js +8 -1
  80. package/dist/common/stringUtils.js.map +1 -1
  81. package/dist/languageServerBase.d.ts +10 -3
  82. package/dist/languageServerBase.js +40 -14
  83. package/dist/languageServerBase.js.map +1 -1
  84. package/dist/languageService/analyzerServiceExecutor.js +3 -0
  85. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  86. package/dist/languageService/autoImporter.js +2 -1
  87. package/dist/languageService/autoImporter.js.map +1 -1
  88. package/dist/languageService/completionProvider.d.ts +2 -2
  89. package/dist/languageService/completionProvider.js +3 -5
  90. package/dist/languageService/completionProvider.js.map +1 -1
  91. package/dist/parser/parseNodes.d.ts +3 -0
  92. package/dist/parser/parseNodes.js +110 -2
  93. package/dist/parser/parseNodes.js.map +1 -1
  94. package/dist/parser/parser.d.ts +0 -1
  95. package/dist/parser/parser.js +26 -12
  96. package/dist/parser/parser.js.map +1 -1
  97. package/dist/parser/stringTokenUtils.js +8 -1
  98. package/dist/parser/stringTokenUtils.js.map +1 -1
  99. package/dist/parser/tokenizerTypes.js +155 -1
  100. package/dist/parser/tokenizerTypes.js.map +1 -1
  101. package/dist/pyright.js +6 -1
  102. package/dist/pyright.js.map +1 -1
  103. package/dist/tests/chainedSourceFiles.test.js +12 -9
  104. package/dist/tests/chainedSourceFiles.test.js.map +1 -1
  105. package/dist/tests/checker.test.js +4 -0
  106. package/dist/tests/checker.test.js.map +1 -1
  107. package/dist/tests/config.test.js +14 -13
  108. package/dist/tests/config.test.js.map +1 -1
  109. package/dist/tests/debug.test.js +6 -0
  110. package/dist/tests/debug.test.js.map +1 -1
  111. package/dist/tests/fourslash/completions.autoimport.lib.alias.fourslash.d.ts +1 -0
  112. package/dist/tests/fourslash/completions.autoimport.lib.alias.fourslash.js +53 -0
  113. package/dist/tests/fourslash/completions.autoimport.lib.alias.fourslash.js.map +1 -0
  114. package/dist/tests/fourslash/fourslash.d.ts +16 -0
  115. package/dist/tests/fourslash/hover.class.docString.fourslash.d.ts +1 -0
  116. package/dist/tests/fourslash/hover.class.docString.fourslash.js +24 -0
  117. package/dist/tests/fourslash/hover.class.docString.fourslash.js.map +1 -0
  118. package/dist/tests/harness/fourslash/fourSlashParser.js +6 -0
  119. package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
  120. package/dist/tests/harness/fourslash/fourSlashTypes.js +19 -1
  121. package/dist/tests/harness/fourslash/fourSlashTypes.js.map +1 -1
  122. package/dist/tests/harness/fourslash/testLanguageService.js +9 -1
  123. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  124. package/dist/tests/harness/fourslash/testState.Consts.d.ts +1 -0
  125. package/dist/tests/harness/fourslash/testState.Consts.js +1 -0
  126. package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -1
  127. package/dist/tests/harness/fourslash/testState.d.ts +4 -3
  128. package/dist/tests/harness/fourslash/testState.js +27 -11
  129. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  130. package/dist/tests/harness/vfs/pathValidation.js +25 -1
  131. package/dist/tests/harness/vfs/pathValidation.js.map +1 -1
  132. package/dist/tests/pathUtils.test.js +17 -0
  133. package/dist/tests/pathUtils.test.js.map +1 -1
  134. package/dist/tests/testUtils.js +1 -1
  135. package/dist/tests/testUtils.js.map +1 -1
  136. package/dist/tests/typeEvaluator1.test.js +9 -1
  137. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  138. package/dist/tests/typeEvaluator2.test.js +9 -1
  139. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  140. package/dist/tests/typeEvaluator3.test.js +4 -0
  141. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  142. package/dist/workspaceMap.d.ts +2 -1
  143. package/dist/workspaceMap.js +25 -3
  144. package/dist/workspaceMap.js.map +1 -1
  145. package/package.json +45 -44
@@ -57,6 +57,7 @@ const staticExpressions_1 = require("./staticExpressions");
57
57
  const SymbolNameUtils = __importStar(require("./symbolNameUtils"));
58
58
  const symbolUtils_1 = require("./symbolUtils");
59
59
  const typeEvaluator_1 = require("./typeEvaluator");
60
+ const typeGuards_1 = require("./typeGuards");
60
61
  const types_1 = require("./types");
61
62
  const typeUtils_1 = require("./typeUtils");
62
63
  const typeVarContext_1 = require("./typeVarContext");
@@ -459,6 +460,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
459
460
  }
460
461
  visitFor(node) {
461
462
  this._evaluator.evaluateTypesForStatement(node);
463
+ if (node.typeComment) {
464
+ this._evaluator.addDiagnosticForTextRange(this._fileInfo, this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.annotationNotSupported(), node.typeComment);
465
+ }
462
466
  return true;
463
467
  }
464
468
  visitList(node) {
@@ -495,6 +499,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
495
499
  node.withItems.forEach((item) => {
496
500
  this._evaluator.evaluateTypesForStatement(item);
497
501
  });
502
+ if (node.typeComment) {
503
+ this._evaluator.addDiagnosticForTextRange(this._fileInfo, this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.annotationNotSupported(), node.typeComment);
504
+ }
498
505
  return true;
499
506
  }
500
507
  visitReturn(node) {
@@ -1769,14 +1776,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1769
1776
  }
1770
1777
  else if (otherDecl.type === 3 /* Function */) {
1771
1778
  const primaryType = this._evaluator.getTypeForDeclaration(primaryDecl);
1779
+ let duplicateIsOk = false;
1772
1780
  // If the return type has not yet been inferred, do so now.
1773
1781
  if (primaryType && (0, types_1.isFunction)(primaryType)) {
1774
1782
  this._evaluator.getFunctionInferredReturnType(primaryType);
1775
1783
  }
1776
- let duplicateIsOk = false;
1777
1784
  const otherType = this._evaluator.getTypeForDeclaration(otherDecl);
1778
1785
  const suite1 = ParseTreeUtils.getEnclosingSuite(primaryDecl.node);
1779
1786
  const suite2 = ParseTreeUtils.getEnclosingSuite(otherDecl.node);
1787
+ // Allow same-signature overrides in cases where the declarations
1788
+ // are not within the same statement suite (e.g. one in the "if"
1789
+ // and another in the "else").
1780
1790
  const isInSameStatementList = suite1 === suite2;
1781
1791
  // If the return type has not yet been inferred, do so now.
1782
1792
  if (otherType && (0, types_1.isFunction)(otherType)) {
@@ -1784,10 +1794,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1784
1794
  }
1785
1795
  // If both declarations are functions, it's OK if they
1786
1796
  // both have the same signatures.
1787
- if (primaryType && otherType && (0, types_1.isTypeSame)(primaryType, otherType)) {
1797
+ if (!isInSameStatementList && primaryType && otherType && (0, types_1.isTypeSame)(primaryType, otherType)) {
1788
1798
  duplicateIsOk = true;
1789
1799
  }
1790
- if (!duplicateIsOk || isInSameStatementList) {
1800
+ if (!duplicateIsOk) {
1791
1801
  const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, otherDecl.isMethod
1792
1802
  ? localize_1.Localizer.Diagnostic.obscuredMethodDeclaration().format({ name })
1793
1803
  : localize_1.Localizer.Diagnostic.obscuredFunctionDeclaration().format({ name }), otherDecl.node.name);
@@ -1816,18 +1826,12 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1816
1826
  }
1817
1827
  }
1818
1828
  }
1819
- else if (primaryType && !(0, typeUtils_1.isProperty)(primaryType)) {
1820
- if (primaryDecl.type === 3 /* Function */ || primaryDecl.type === 4 /* Class */) {
1821
- const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.obscuredVariableDeclaration().format({ name }), otherDecl.node);
1822
- addPrimaryDeclInfo(diag);
1823
- }
1824
- }
1825
1829
  }
1826
1830
  }
1827
1831
  }
1828
1832
  _conditionallyReportUnusedSymbol(name, symbol, scopeType) {
1829
- const accessedSymbolMap = this._fileInfo.accessedSymbolMap;
1830
- if (symbol.isIgnoredForProtocolMatch() || accessedSymbolMap.has(symbol.id)) {
1833
+ const accessedSymbolSet = this._fileInfo.accessedSymbolSet;
1834
+ if (symbol.isIgnoredForProtocolMatch() || accessedSymbolSet.has(symbol.id)) {
1831
1835
  return;
1832
1836
  }
1833
1837
  // A name of "_" means "I know this symbol isn't used", so
@@ -2087,18 +2091,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2087
2091
  const filterType = (varType) => {
2088
2092
  const filteredTypes = [];
2089
2093
  for (const filterType of classTypeList) {
2090
- // Handle the special case where the variable type is a TypedDict and
2091
- // we're filtering against 'dict'. TypedDict isn't derived from dict,
2092
- // but at runtime, isinstance returns True.
2093
- const filterIsSuperclass = types_1.ClassType.isDerivedFrom(varType, filterType) ||
2094
- (isInstanceCheck &&
2095
- types_1.ClassType.isProtocolClass(filterType) &&
2096
- this._evaluator.assignType(filterType, varType)) ||
2097
- (types_1.ClassType.isBuiltIn(filterType, 'dict') && types_1.ClassType.isTypedDictClass(varType));
2098
- const filterIsSubclass = types_1.ClassType.isDerivedFrom(filterType, varType) ||
2099
- (isInstanceCheck &&
2100
- types_1.ClassType.isProtocolClass(varType) &&
2101
- this._evaluator.assignType(varType, filterType));
2094
+ const filterIsSuperclass = (0, typeGuards_1.isIsinstanceFilterSuperclass)(this._evaluator, varType, filterType, filterType, isInstanceCheck);
2095
+ const filterIsSubclass = (0, typeGuards_1.isIsinstanceFilterSubclass)(this._evaluator, varType, filterType, filterType, isInstanceCheck);
2102
2096
  // Normally, a class should never be both a subclass and a
2103
2097
  // superclass. However, this can happen if one of the classes
2104
2098
  // derives from an unknown type. In this case, we'll add an
@@ -2645,8 +2639,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2645
2639
  }
2646
2640
  // Collect the list of init-only variables in the order they were declared.
2647
2641
  const initOnlySymbolMap = new Map();
2648
- for (let i = classType.details.mro.length - 1; i >= 0; i--) {
2649
- const mroClass = classType.details.mro[i];
2642
+ types_1.ClassType.getReverseMro(classType).forEach((mroClass) => {
2650
2643
  if ((0, types_1.isClass)(mroClass) && types_1.ClassType.isDataClass(mroClass)) {
2651
2644
  mroClass.details.fields.forEach((symbol, name) => {
2652
2645
  if (symbol.isInitVar()) {
@@ -2654,7 +2647,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2654
2647
  }
2655
2648
  });
2656
2649
  }
2657
- }
2650
+ });
2658
2651
  const postInitType = this._evaluator.getTypeOfMember(postInitMember);
2659
2652
  if (!(0, types_1.isFunction)(postInitType) ||
2660
2653
  !types_1.FunctionType.isInstanceMethod(postInitType) ||