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

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 (80) hide show
  1. package/dist/analyzer/aliasDeclarationUtils.js +2 -2
  2. package/dist/analyzer/analyzerNodeInfo.d.ts +4 -1
  3. package/dist/analyzer/analyzerNodeInfo.js +12 -1
  4. package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
  5. package/dist/analyzer/binder.d.ts +6 -1
  6. package/dist/analyzer/binder.js +133 -30
  7. package/dist/analyzer/binder.js.map +1 -1
  8. package/dist/analyzer/checker.d.ts +4 -1
  9. package/dist/analyzer/checker.js +125 -47
  10. package/dist/analyzer/checker.js.map +1 -1
  11. package/dist/analyzer/constraintSolver.js +6 -3
  12. package/dist/analyzer/constraintSolver.js.map +1 -1
  13. package/dist/analyzer/declaration.d.ts +18 -6
  14. package/dist/analyzer/declaration.js +19 -9
  15. package/dist/analyzer/declaration.js.map +1 -1
  16. package/dist/analyzer/declarationUtils.d.ts +1 -1
  17. package/dist/analyzer/declarationUtils.js +19 -16
  18. package/dist/analyzer/declarationUtils.js.map +1 -1
  19. package/dist/analyzer/packageTypeVerifier.js +6 -6
  20. package/dist/analyzer/parseTreeUtils.d.ts +3 -3
  21. package/dist/analyzer/parseTreeUtils.js +16 -11
  22. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  23. package/dist/analyzer/parseTreeWalker.d.ts +4 -1
  24. package/dist/analyzer/parseTreeWalker.js +19 -1
  25. package/dist/analyzer/parseTreeWalker.js.map +1 -1
  26. package/dist/analyzer/properties.js +2 -0
  27. package/dist/analyzer/properties.js.map +1 -1
  28. package/dist/analyzer/protocols.d.ts +0 -1
  29. package/dist/analyzer/protocols.js +1 -63
  30. package/dist/analyzer/protocols.js.map +1 -1
  31. package/dist/analyzer/tracePrinter.js +8 -4
  32. package/dist/analyzer/tracePrinter.js.map +1 -1
  33. package/dist/analyzer/typeDocStringUtils.js +1 -1
  34. package/dist/analyzer/typeEvaluator.js +524 -176
  35. package/dist/analyzer/typeEvaluator.js.map +1 -1
  36. package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -0
  37. package/dist/analyzer/typeEvaluatorWithTracker.js +2 -0
  38. package/dist/analyzer/typeEvaluatorWithTracker.js.map +1 -1
  39. package/dist/analyzer/typePrinter.js +4 -1
  40. package/dist/analyzer/typePrinter.js.map +1 -1
  41. package/dist/analyzer/typeStubWriter.d.ts +4 -1
  42. package/dist/analyzer/typeStubWriter.js +36 -0
  43. package/dist/analyzer/typeStubWriter.js.map +1 -1
  44. package/dist/analyzer/typeUtils.js +10 -5
  45. package/dist/analyzer/typeUtils.js.map +1 -1
  46. package/dist/analyzer/types.d.ts +11 -4
  47. package/dist/analyzer/types.js +23 -8
  48. package/dist/analyzer/types.js.map +1 -1
  49. package/dist/languageService/autoImporter.js +1 -1
  50. package/dist/languageService/callHierarchyProvider.js +9 -9
  51. package/dist/languageService/completionProvider.js +19 -13
  52. package/dist/languageService/completionProvider.js.map +1 -1
  53. package/dist/languageService/definitionProvider.js +3 -3
  54. package/dist/languageService/documentSymbolCollector.js +1 -1
  55. package/dist/languageService/documentSymbolProvider.js +10 -7
  56. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  57. package/dist/languageService/hoverProvider.js +19 -5
  58. package/dist/languageService/hoverProvider.js.map +1 -1
  59. package/dist/languageService/referencesProvider.js +8 -5
  60. package/dist/languageService/referencesProvider.js.map +1 -1
  61. package/dist/languageService/tooltipUtils.js +1 -1
  62. package/dist/localization/localize.d.ts +27 -0
  63. package/dist/localization/localize.js +16 -0
  64. package/dist/localization/localize.js.map +1 -1
  65. package/dist/localization/package.nls.en-us.json +18 -2
  66. package/dist/parser/parseNodes.d.ts +41 -5
  67. package/dist/parser/parseNodes.js +83 -4
  68. package/dist/parser/parseNodes.js.map +1 -1
  69. package/dist/parser/parser.d.ts +3 -0
  70. package/dist/parser/parser.js +129 -12
  71. package/dist/parser/parser.js.map +1 -1
  72. package/dist/parser/tokenizer.js +4 -3
  73. package/dist/parser/tokenizer.js.map +1 -1
  74. package/dist/parser/tokenizerTypes.d.ts +5 -3
  75. package/dist/parser/tokenizerTypes.js +6 -4
  76. package/dist/parser/tokenizerTypes.js.map +1 -1
  77. package/dist/tests/typeEvaluator5.test.d.ts +1 -0
  78. package/dist/tests/typeEvaluator5.test.js +112 -0
  79. package/dist/tests/typeEvaluator5.test.js.map +1 -0
  80. package/package.json +1 -1
@@ -50,7 +50,6 @@ const importStatementUtils_1 = require("./importStatementUtils");
50
50
  const ParseTreeUtils = __importStar(require("./parseTreeUtils"));
51
51
  const parseTreeWalker_1 = require("./parseTreeWalker");
52
52
  const patternMatching_1 = require("./patternMatching");
53
- const protocols_1 = require("./protocols");
54
53
  const scopeUtils_1 = require("./scopeUtils");
55
54
  const sourceMapper_1 = require("./sourceMapper");
56
55
  const staticExpressions_1 = require("./staticExpressions");
@@ -111,6 +110,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
111
110
  // A list of all nodes that are defined within the module that
112
111
  // have their own scopes.
113
112
  this._scopedNodes = [];
113
+ // A list of all visited type parameter lists.
114
+ this._typeParameterLists = [];
114
115
  this._fileInfo = AnalyzerNodeInfo.getFileInfo(_moduleNode);
115
116
  }
116
117
  check() {
@@ -156,6 +157,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
156
157
  }
157
158
  visitClass(node) {
158
159
  const classTypeResult = this._evaluator.getTypeOfClass(node);
160
+ if (node.typeParameters) {
161
+ this.walk(node.typeParameters);
162
+ }
159
163
  this.walk(node.suite);
160
164
  this.walkMultiple(node.decorators);
161
165
  this.walkMultiple(node.arguments);
@@ -211,6 +215,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
211
215
  }
212
216
  visitFunction(node) {
213
217
  var _a;
218
+ if (node.typeParameters) {
219
+ this.walk(node.typeParameters);
220
+ }
214
221
  const functionTypeResult = this._evaluator.getTypeOfFunction(node);
215
222
  const containingClassNode = ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true);
216
223
  if (functionTypeResult) {
@@ -320,7 +327,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
320
327
  if (annotationNode && index < functionTypeResult.functionType.details.parameters.length) {
321
328
  const paramType = functionTypeResult.functionType.details.parameters[index].type;
322
329
  if ((0, types_1.isTypeVar)(paramType) &&
323
- paramType.details.variance === 1 /* Covariant */ &&
330
+ paramType.details.declaredVariance === 2 /* Covariant */ &&
324
331
  !paramType.details.isSynthesized &&
325
332
  functionTypeResult.functionType.details.name !== '__init__') {
326
333
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramTypeCovariant(), annotationNode);
@@ -854,6 +861,13 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
854
861
  }
855
862
  return false;
856
863
  }
864
+ visitTypeParameterList(node) {
865
+ this._typeParameterLists.push(node);
866
+ return true;
867
+ }
868
+ visitTypeParameter(node) {
869
+ return false;
870
+ }
857
871
  visitTypeAnnotation(node) {
858
872
  this._evaluator.getType(node.typeAnnotation);
859
873
  return true;
@@ -1313,7 +1327,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1313
1327
  return undefined;
1314
1328
  }
1315
1329
  for (const decl of decls) {
1316
- if (decl.type === 3 /* Function */) {
1330
+ if (decl.type === 5 /* Function */) {
1317
1331
  const functionType = this._evaluator.getTypeOfFunction(decl.node);
1318
1332
  if ((functionType === null || functionType === void 0 ? void 0 : functionType.functionType) === overloadType) {
1319
1333
  return decl.node;
@@ -1542,12 +1556,26 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1542
1556
  });
1543
1557
  }
1544
1558
  }
1559
+ // Report unaccessed type parameters.
1560
+ const accessedSymbolSet = this._fileInfo.accessedSymbolSet;
1561
+ for (const paramList of this._typeParameterLists) {
1562
+ for (const param of paramList.parameters) {
1563
+ const symbol = AnalyzerNodeInfo.getTypeParameterSymbol(param.name);
1564
+ (0, debug_1.assert)(symbol);
1565
+ if (!accessedSymbolSet.has(symbol.id)) {
1566
+ const decls = symbol.getDeclarations();
1567
+ decls.forEach((decl) => {
1568
+ this._conditionallyReportUnusedDeclaration(decl, /* isPrivate */ false);
1569
+ });
1570
+ }
1571
+ }
1572
+ }
1545
1573
  }
1546
1574
  _reportInvalidOverload(name, symbol) {
1547
1575
  const typedDecls = symbol.getTypedDeclarations();
1548
1576
  if (typedDecls.length >= 1) {
1549
1577
  const primaryDecl = typedDecls[0];
1550
- if (primaryDecl.type === 3 /* Function */) {
1578
+ if (primaryDecl.type === 5 /* Function */) {
1551
1579
  const type = this._evaluator.getEffectiveTypeOfSymbol(symbol);
1552
1580
  const functions = (0, types_1.isOverloadedFunction)(type) ? type.overloads : (0, types_1.isFunction)(type) ? [type] : [];
1553
1581
  const overloadedFunctions = functions.filter((func) => types_1.FunctionType.isOverloaded(func));
@@ -1697,10 +1725,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1697
1725
  let otherDecls = symbol.getDeclarations().filter((decl) => decl !== primaryDecl);
1698
1726
  // If it's a function, we can skip any other declarations
1699
1727
  // that are overloads or property setters/deleters.
1700
- if (primaryDecl.type === 3 /* Function */) {
1728
+ if (primaryDecl.type === 5 /* Function */) {
1701
1729
  const primaryDeclTypeInfo = this._evaluator.getTypeOfFunction(primaryDecl.node);
1702
1730
  otherDecls = otherDecls.filter((decl) => {
1703
- if (decl.type !== 3 /* Function */) {
1731
+ if (decl.type !== 5 /* Function */) {
1704
1732
  return true;
1705
1733
  }
1706
1734
  const funcTypeInfo = this._evaluator.getTypeOfFunction(decl.node);
@@ -1728,7 +1756,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1728
1756
  return;
1729
1757
  }
1730
1758
  let primaryDeclInfo;
1731
- if (primaryDecl.type === 3 /* Function */) {
1759
+ if (primaryDecl.type === 5 /* Function */) {
1732
1760
  if (primaryDecl.isMethod) {
1733
1761
  primaryDeclInfo = localize_1.Localizer.DiagnosticAddendum.seeMethodDeclaration();
1734
1762
  }
@@ -1736,7 +1764,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1736
1764
  primaryDeclInfo = localize_1.Localizer.DiagnosticAddendum.seeFunctionDeclaration();
1737
1765
  }
1738
1766
  }
1739
- else if (primaryDecl.type === 4 /* Class */) {
1767
+ else if (primaryDecl.type === 6 /* Class */) {
1740
1768
  primaryDeclInfo = localize_1.Localizer.DiagnosticAddendum.seeClassDeclaration();
1741
1769
  }
1742
1770
  else if (primaryDecl.type === 2 /* Parameter */) {
@@ -1745,13 +1773,16 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1745
1773
  else if (primaryDecl.type === 1 /* Variable */) {
1746
1774
  primaryDeclInfo = localize_1.Localizer.DiagnosticAddendum.seeVariableDeclaration();
1747
1775
  }
1776
+ else if (primaryDecl.type === 4 /* TypeAlias */) {
1777
+ primaryDeclInfo = localize_1.Localizer.DiagnosticAddendum.seeTypeAliasDeclaration();
1778
+ }
1748
1779
  else {
1749
1780
  primaryDeclInfo = localize_1.Localizer.DiagnosticAddendum.seeDeclaration();
1750
1781
  }
1751
1782
  const addPrimaryDeclInfo = (diag) => {
1752
1783
  if (diag) {
1753
1784
  let primaryDeclNode;
1754
- if (primaryDecl.type === 3 /* Function */ || primaryDecl.type === 4 /* Class */) {
1785
+ if (primaryDecl.type === 5 /* Function */ || primaryDecl.type === 6 /* Class */) {
1755
1786
  primaryDeclNode = primaryDecl.node.name;
1756
1787
  }
1757
1788
  else if (primaryDecl.type === 1 /* Variable */) {
@@ -1759,7 +1790,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1759
1790
  primaryDeclNode = primaryDecl.node;
1760
1791
  }
1761
1792
  }
1762
- else if (primaryDecl.type === 2 /* Parameter */) {
1793
+ else if (primaryDecl.type === 2 /* Parameter */ ||
1794
+ primaryDecl.type === 3 /* TypeParameter */) {
1763
1795
  if (primaryDecl.node.name) {
1764
1796
  primaryDeclNode = primaryDecl.node.name;
1765
1797
  }
@@ -1770,11 +1802,19 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1770
1802
  }
1771
1803
  };
1772
1804
  for (const otherDecl of otherDecls) {
1773
- if (otherDecl.type === 4 /* Class */) {
1774
- const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.obscuredClassDeclaration().format({ name }), otherDecl.node.name);
1775
- addPrimaryDeclInfo(diag);
1805
+ if (otherDecl.type === 6 /* Class */) {
1806
+ let duplicateIsOk = false;
1807
+ if (primaryDecl.type === 3 /* TypeParameter */) {
1808
+ // The error will be reported elsewhere if a type parameter is
1809
+ // involved, so don't report it here.
1810
+ duplicateIsOk = true;
1811
+ }
1812
+ if (!duplicateIsOk) {
1813
+ const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.obscuredClassDeclaration().format({ name }), otherDecl.node.name);
1814
+ addPrimaryDeclInfo(diag);
1815
+ }
1776
1816
  }
1777
- else if (otherDecl.type === 3 /* Function */) {
1817
+ else if (otherDecl.type === 5 /* Function */) {
1778
1818
  const primaryType = this._evaluator.getTypeForDeclaration(primaryDecl);
1779
1819
  let duplicateIsOk = false;
1780
1820
  // If the return type has not yet been inferred, do so now.
@@ -1797,6 +1837,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1797
1837
  if (!isInSameStatementList && primaryType && otherType && (0, types_1.isTypeSame)(primaryType, otherType)) {
1798
1838
  duplicateIsOk = true;
1799
1839
  }
1840
+ if (primaryDecl.type === 3 /* TypeParameter */) {
1841
+ // The error will be reported elsewhere if a type parameter is
1842
+ // involved, so don't report it here.
1843
+ duplicateIsOk = true;
1844
+ }
1800
1845
  if (!duplicateIsOk) {
1801
1846
  const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, otherDecl.isMethod
1802
1847
  ? localize_1.Localizer.Diagnostic.obscuredMethodDeclaration().format({ name })
@@ -1806,8 +1851,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1806
1851
  }
1807
1852
  else if (otherDecl.type === 2 /* Parameter */) {
1808
1853
  if (otherDecl.node.name) {
1809
- const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.obscuredParameterDeclaration().format({ name }), otherDecl.node.name);
1810
- addPrimaryDeclInfo(diag);
1854
+ let duplicateIsOk = false;
1855
+ if (primaryDecl.type === 3 /* TypeParameter */) {
1856
+ // The error will be reported elsewhere if a type parameter is
1857
+ // involved, so don't report it here.
1858
+ duplicateIsOk = true;
1859
+ }
1860
+ if (!duplicateIsOk) {
1861
+ const message = localize_1.Localizer.Diagnostic.obscuredParameterDeclaration();
1862
+ const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message.format({ name }), otherDecl.node.name);
1863
+ addPrimaryDeclInfo(diag);
1864
+ }
1811
1865
  }
1812
1866
  }
1813
1867
  else if (otherDecl.type === 1 /* Variable */) {
@@ -1820,6 +1874,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1820
1874
  if (primaryType && otherType && (0, types_1.isTypeSame)(primaryType, otherType)) {
1821
1875
  duplicateIsOk = true;
1822
1876
  }
1877
+ if (primaryDecl.type === 3 /* TypeParameter */) {
1878
+ // The error will be reported elsewhere if a type parameter is
1879
+ // involved, so don't report it here.
1880
+ duplicateIsOk = true;
1881
+ }
1823
1882
  if (!duplicateIsOk) {
1824
1883
  const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.obscuredVariableDeclaration().format({ name }), otherDecl.node);
1825
1884
  addPrimaryDeclInfo(diag);
@@ -1827,6 +1886,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1827
1886
  }
1828
1887
  }
1829
1888
  }
1889
+ else if (otherDecl.type === 4 /* TypeAlias */) {
1890
+ const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.obscuredTypeAliasDeclaration().format({ name }), otherDecl.node.name);
1891
+ addPrimaryDeclInfo(diag);
1892
+ }
1830
1893
  }
1831
1894
  }
1832
1895
  _conditionallyReportUnusedSymbol(name, symbol, scopeType) {
@@ -1853,7 +1916,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1853
1916
  let message;
1854
1917
  let rule;
1855
1918
  switch (decl.type) {
1856
- case 6 /* Alias */:
1919
+ case 8 /* Alias */:
1857
1920
  diagnosticLevel = this._fileInfo.diagnosticRuleSet.reportUnusedImport;
1858
1921
  rule = diagnosticRules_1.DiagnosticRule.reportUnusedImport;
1859
1922
  if (decl.node.nodeType === 21 /* ImportAs */) {
@@ -1892,6 +1955,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1892
1955
  message = localize_1.Localizer.Diagnostic.unaccessedImport().format({ name: nameNode.value });
1893
1956
  }
1894
1957
  break;
1958
+ case 4 /* TypeAlias */:
1895
1959
  case 1 /* Variable */:
1896
1960
  case 2 /* Parameter */:
1897
1961
  if (!isPrivate) {
@@ -1913,7 +1977,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1913
1977
  }
1914
1978
  else if (decl.node.nodeType === 41 /* Parameter */) {
1915
1979
  nameNode = decl.node.name;
1916
- // Don't emit a diagnostic for unused parameters.
1980
+ // Don't emit a diagnostic for unused parameters or type parameters.
1917
1981
  diagnosticLevel = 'none';
1918
1982
  }
1919
1983
  if (nameNode) {
@@ -1921,7 +1985,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1921
1985
  message = localize_1.Localizer.Diagnostic.unaccessedVariable().format({ name: nameNode.value });
1922
1986
  }
1923
1987
  break;
1924
- case 4 /* Class */:
1988
+ case 6 /* Class */:
1925
1989
  if (!isPrivate) {
1926
1990
  return;
1927
1991
  }
@@ -1935,7 +1999,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1935
1999
  rule = diagnosticRules_1.DiagnosticRule.reportUnusedClass;
1936
2000
  message = localize_1.Localizer.Diagnostic.unaccessedClass().format({ name: nameNode.value });
1937
2001
  break;
1938
- case 3 /* Function */:
2002
+ case 5 /* Function */:
1939
2003
  if (!isPrivate) {
1940
2004
  return;
1941
2005
  }
@@ -1949,13 +2013,23 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1949
2013
  rule = diagnosticRules_1.DiagnosticRule.reportUnusedFunction;
1950
2014
  message = localize_1.Localizer.Diagnostic.unaccessedFunction().format({ name: nameNode.value });
1951
2015
  break;
1952
- default:
2016
+ case 3 /* TypeParameter */:
2017
+ // Never report a diagnostic for an unused TypeParameter.
2018
+ diagnosticLevel = 'none';
2019
+ nameNode = decl.node.name;
2020
+ break;
2021
+ case 0 /* Intrinsic */:
2022
+ case 7 /* SpecialBuiltInClass */:
1953
2023
  return;
2024
+ default:
2025
+ (0, debug_1.assertNever)(decl);
1954
2026
  }
1955
- if (nameNode && rule !== undefined && message) {
1956
- const action = rule === diagnosticRules_1.DiagnosticRule.reportUnusedImport ? { action: "pyright.unusedImport" /* unusedImport */ } : undefined;
2027
+ const action = rule === diagnosticRules_1.DiagnosticRule.reportUnusedImport ? { action: "pyright.unusedImport" /* unusedImport */ } : undefined;
2028
+ if (nameNode) {
1957
2029
  this._fileInfo.diagnosticSink.addUnusedCodeWithTextRange(localize_1.Localizer.Diagnostic.unaccessedSymbol().format({ name: nameNode.value }), nameNode, action);
1958
- this._evaluator.addDiagnostic(diagnosticLevel, rule, message, nameNode);
2030
+ if (rule !== undefined && message) {
2031
+ this._evaluator.addDiagnostic(diagnosticLevel, rule, message, nameNode);
2032
+ }
1959
2033
  }
1960
2034
  }
1961
2035
  // Validates that a call to isinstance or issubclass are necessary. This is a
@@ -2288,7 +2362,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2288
2362
  if (!primaryDeclaration || primaryDeclaration.node === node) {
2289
2363
  return;
2290
2364
  }
2291
- if (primaryDeclaration.type === 6 /* Alias */) {
2365
+ if (primaryDeclaration.type === 8 /* Alias */) {
2292
2366
  // If this symbol is an import alias (i.e. it's a local name rather than the
2293
2367
  // original imported name), skip the private check.
2294
2368
  if (primaryDeclaration.usesLocalName) {
@@ -2474,7 +2548,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2474
2548
  }), returnAnnotation);
2475
2549
  }
2476
2550
  const diag = new diagnostic_1.DiagnosticAddendum();
2477
- if ((0, types_1.isTypeVar)(declaredReturnType) && declaredReturnType.details.variance === 2 /* Contravariant */) {
2551
+ if ((0, types_1.isTypeVar)(declaredReturnType) &&
2552
+ declaredReturnType.details.declaredVariance === 3 /* Contravariant */) {
2478
2553
  diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeVarIsContravariant().format({
2479
2554
  name: types_1.TypeVarType.getReadableName(declaredReturnType),
2480
2555
  }));
@@ -2604,7 +2679,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2604
2679
  }
2605
2680
  }
2606
2681
  }
2607
- else if (decls[0].type === 3 /* Function */) {
2682
+ else if (decls[0].type === 5 /* Function */) {
2608
2683
  if (ParseTreeUtils.isSuiteEmpty(decls[0].node.suite) && decls[0]) {
2609
2684
  if ((0, pathUtils_1.getFileExtension)(decls[0].path).toLowerCase() !== '.pyi') {
2610
2685
  if (!isSymbolImplemented(name)) {
@@ -2793,9 +2868,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2793
2868
  // the proper variance (invariant, covariant, contravariant). See PEP 544
2794
2869
  // for an explanation for why this is important to enforce.
2795
2870
  _validateProtocolTypeParamVariance(errorNode, classType) {
2796
- const origTypeParams = classType.details.typeParameters.filter((typeParam) => !(0, types_1.isParamSpec)(typeParam));
2797
- // If this isn't a generic protocol, there's nothing to do here.
2798
- if (origTypeParams.length === 0) {
2871
+ // If this protocol has no TypeVars with specified variance, there's nothing to do here.
2872
+ if (classType.details.typeParameters.length === 0) {
2799
2873
  return;
2800
2874
  }
2801
2875
  const objectType = this._evaluator.getBuiltInType(errorNode, 'object');
@@ -2803,13 +2877,17 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2803
2877
  return;
2804
2878
  }
2805
2879
  // Replace all of the type parameters with invariant TypeVars.
2806
- const updatedTypeParams = origTypeParams.map((typeParam) => (0, types_1.isVariadicTypeVar)(typeParam) ? typeParam : types_1.TypeVarType.cloneAsInvariant(typeParam));
2880
+ const updatedTypeParams = classType.details.typeParameters.map((typeParam) => types_1.TypeVarType.cloneAsInvariant(typeParam));
2807
2881
  const updatedClassType = types_1.ClassType.cloneWithNewTypeParameters(classType, updatedTypeParams);
2808
2882
  const objectObject = types_1.ClassType.cloneAsInstance(objectType);
2809
- const dummyTypeObject = types_1.ClassType.createInstantiable('__protocolVarianceDummy', '', '', '', 0, 0, undefined, undefined);
2883
+ const dummyTypeObject = types_1.ClassType.createInstantiable('__varianceDummy', '', '', '', 0, 0, undefined, undefined);
2810
2884
  updatedTypeParams.forEach((param, paramIndex) => {
2811
- // Skip variadics.
2812
- if (param.details.isVariadic) {
2885
+ // Skip variadics and ParamSpecs.
2886
+ if (param.details.isVariadic || param.details.isParamSpec) {
2887
+ return;
2888
+ }
2889
+ // Skip type variables with auto-variance.
2890
+ if (param.details.declaredVariance === 0 /* Auto */) {
2813
2891
  return;
2814
2892
  }
2815
2893
  // Replace all type arguments with a dummy type except for the
@@ -2829,29 +2907,29 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2829
2907
  /* isTypeArgumentExplicit */ true);
2830
2908
  const destType = types_1.ClassType.cloneForSpecialization(updatedClassType, destTypeArgs,
2831
2909
  /* isTypeArgumentExplicit */ true);
2832
- const isDestSubtypeOfSrc = (0, protocols_1.assignProtocolClassToSelf)(this._evaluator, srcType, destType);
2910
+ const isDestSubtypeOfSrc = this._evaluator.assignClassToSelf(srcType, destType);
2833
2911
  let expectedVariance;
2834
2912
  if (isDestSubtypeOfSrc) {
2835
- expectedVariance = 1 /* Covariant */;
2913
+ expectedVariance = 2 /* Covariant */;
2836
2914
  }
2837
2915
  else {
2838
- const isSrcSubtypeOfDest = (0, protocols_1.assignProtocolClassToSelf)(this._evaluator, destType, srcType);
2916
+ const isSrcSubtypeOfDest = this._evaluator.assignClassToSelf(destType, srcType);
2839
2917
  if (isSrcSubtypeOfDest) {
2840
- expectedVariance = 2 /* Contravariant */;
2918
+ expectedVariance = 3 /* Contravariant */;
2841
2919
  }
2842
2920
  else {
2843
- expectedVariance = 0 /* Invariant */;
2921
+ expectedVariance = 1 /* Invariant */;
2844
2922
  }
2845
2923
  }
2846
- if (expectedVariance !== origTypeParams[paramIndex].details.variance) {
2924
+ if (expectedVariance !== classType.details.typeParameters[paramIndex].details.declaredVariance) {
2847
2925
  let message;
2848
- if (expectedVariance === 1 /* Covariant */) {
2926
+ if (expectedVariance === 2 /* Covariant */) {
2849
2927
  message = localize_1.Localizer.Diagnostic.protocolVarianceCovariant().format({
2850
2928
  variable: param.details.name,
2851
2929
  class: classType.details.name,
2852
2930
  });
2853
2931
  }
2854
- else if (expectedVariance === 2 /* Contravariant */) {
2932
+ else if (expectedVariance === 3 /* Contravariant */) {
2855
2933
  message = localize_1.Localizer.Diagnostic.protocolVarianceContravariant().format({
2856
2934
  variable: param.details.name,
2857
2935
  class: classType.details.name,
@@ -3094,7 +3172,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3094
3172
  if (!this._evaluator.validateOverrideMethod(baseType, overrideFunction, diagAddendum,
3095
3173
  /* enforceParamNameMatch */ true)) {
3096
3174
  const decl = overrideFunction.details.declaration;
3097
- if (decl && decl.type === 3 /* Function */) {
3175
+ if (decl && decl.type === 5 /* Function */) {
3098
3176
  diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportIncompatibleMethodOverride, diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.Localizer.Diagnostic.baseClassMethodTypeIncompatible().format({
3099
3177
  classType: childClassType.details.name,
3100
3178
  name: memberName,
@@ -3223,7 +3301,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3223
3301
  const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportIncompatibleMethodOverride, diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.Localizer.Diagnostic.incompatibleMethodOverride().format({
3224
3302
  name: memberName,
3225
3303
  className: baseClassAndSymbol.classType.details.name,
3226
- }) + diagAddendum.getString(), decl.type === 3 /* Function */ ? decl.node.name : decl.node);
3304
+ }) + diagAddendum.getString(), decl.type === 5 /* Function */ ? decl.node.name : decl.node);
3227
3305
  const origDecl = (0, symbolUtils_1.getLastTypedDeclaredForSymbol)(baseClassAndSymbol.symbol);
3228
3306
  if (diag && origDecl) {
3229
3307
  diag.addRelatedInfo(localize_1.Localizer.DiagnosticAddendum.overriddenMethod(), origDecl.path, origDecl.range);
@@ -3235,7 +3313,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3235
3313
  // Private names (starting with double underscore) are exempt from this check.
3236
3314
  if (!SymbolNameUtils.isPrivateName(memberName) && types_1.FunctionType.isFinal(baseType)) {
3237
3315
  const decl = (0, symbolUtils_1.getLastTypedDeclaredForSymbol)(overrideSymbol);
3238
- if (decl && decl.type === 3 /* Function */) {
3316
+ if (decl && decl.type === 5 /* Function */) {
3239
3317
  const diag = this._evaluator.addError(localize_1.Localizer.Diagnostic.finalMethodOverride().format({
3240
3318
  name: memberName,
3241
3319
  className: baseClassAndSymbol.classType.details.name,
@@ -3317,7 +3395,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3317
3395
  name: methodName,
3318
3396
  }));
3319
3397
  const decl = subclassMethodType.details.declaration;
3320
- if (decl && decl.type === 3 /* Function */) {
3398
+ if (decl && decl.type === 5 /* Function */) {
3321
3399
  const diag = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportIncompatibleMethodOverride, diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.Localizer.Diagnostic.propertyOverridden().format({
3322
3400
  name: memberName,
3323
3401
  className: baseClassType.details.name,
@@ -3368,7 +3446,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3368
3446
  }
3369
3447
  // If the subclass is declaring an inner class, we'll consider that
3370
3448
  // to be a ClassVar.
3371
- if (overrideSymbol.getTypedDeclarations().every((decl) => decl.type === 4 /* Class */)) {
3449
+ if (overrideSymbol.getTypedDeclarations().every((decl) => decl.type === 6 /* Class */)) {
3372
3450
  isClassVar = true;
3373
3451
  }
3374
3452
  }