@zzzen/pyright-internal 1.2.0-dev.20240310 → 1.2.0-dev.20240317

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 (75) hide show
  1. package/dist/analyzer/checker.d.ts +1 -0
  2. package/dist/analyzer/checker.js +38 -45
  3. package/dist/analyzer/checker.js.map +1 -1
  4. package/dist/analyzer/operations.js +8 -8
  5. package/dist/analyzer/operations.js.map +1 -1
  6. package/dist/analyzer/parseTreeUtils.js +1 -1
  7. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  8. package/dist/analyzer/patternMatching.js +16 -12
  9. package/dist/analyzer/patternMatching.js.map +1 -1
  10. package/dist/analyzer/service.js +1 -1
  11. package/dist/analyzer/service.js.map +1 -1
  12. package/dist/analyzer/typeEvaluator.js +188 -73
  13. package/dist/analyzer/typeEvaluator.js.map +1 -1
  14. package/dist/analyzer/typeEvaluatorTypes.d.ts +6 -1
  15. package/dist/analyzer/typeGuards.js +8 -11
  16. package/dist/analyzer/typeGuards.js.map +1 -1
  17. package/dist/analyzer/typeUtils.d.ts +1 -1
  18. package/dist/analyzer/typeUtils.js +13 -14
  19. package/dist/analyzer/typeUtils.js.map +1 -1
  20. package/dist/analyzer/types.d.ts +2 -1
  21. package/dist/analyzer/types.js +1 -0
  22. package/dist/analyzer/types.js.map +1 -1
  23. package/dist/backgroundThreadBase.d.ts +4 -1
  24. package/dist/backgroundThreadBase.js +14 -1
  25. package/dist/backgroundThreadBase.js.map +1 -1
  26. package/dist/commands/dumpFileDebugInfoCommand.js +0 -1
  27. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  28. package/dist/common/configOptions.d.ts +1 -0
  29. package/dist/common/configOptions.js +5 -0
  30. package/dist/common/configOptions.js.map +1 -1
  31. package/dist/common/diagnosticRules.d.ts +1 -0
  32. package/dist/common/diagnosticRules.js +1 -0
  33. package/dist/common/diagnosticRules.js.map +1 -1
  34. package/dist/common/logTracker.d.ts +5 -5
  35. package/dist/common/logTracker.js +7 -6
  36. package/dist/common/logTracker.js.map +1 -1
  37. package/dist/localization/localize.d.ts +4 -0
  38. package/dist/localization/localize.js +1 -8
  39. package/dist/localization/localize.js.map +1 -1
  40. package/dist/localization/package.nls.cs.json +13 -5
  41. package/dist/localization/package.nls.de.json +13 -5
  42. package/dist/localization/package.nls.en-us.json +1 -0
  43. package/dist/localization/package.nls.es.json +13 -5
  44. package/dist/localization/package.nls.fr.json +15 -7
  45. package/dist/localization/package.nls.it.json +11 -3
  46. package/dist/localization/package.nls.ja.json +13 -5
  47. package/dist/localization/package.nls.ko.json +13 -5
  48. package/dist/localization/package.nls.pl.json +13 -5
  49. package/dist/localization/package.nls.pt-br.json +13 -5
  50. package/dist/localization/package.nls.qps-ploc.json +13 -5
  51. package/dist/localization/package.nls.ru.json +12 -4
  52. package/dist/localization/package.nls.tr.json +13 -5
  53. package/dist/localization/package.nls.zh-cn.json +13 -5
  54. package/dist/localization/package.nls.zh-tw.json +13 -5
  55. package/dist/parser/parser.js +1 -1
  56. package/dist/parser/parser.js.map +1 -1
  57. package/dist/parser/stringTokenUtils.js +12 -12
  58. package/dist/parser/stringTokenUtils.js.map +1 -1
  59. package/dist/parser/tokenizer.d.ts +0 -1
  60. package/dist/parser/tokenizer.js +41 -41
  61. package/dist/parser/tokenizer.js.map +1 -1
  62. package/dist/parser/tokenizerTypes.d.ts +1 -2
  63. package/dist/parser/tokenizerTypes.js +0 -1
  64. package/dist/parser/tokenizerTypes.js.map +1 -1
  65. package/dist/tests/fourslash/completions.override2.fourslash.js +1 -1
  66. package/dist/tests/fourslash/completions.override2.fourslash.js.map +1 -1
  67. package/dist/tests/harness/fourslash/testLanguageService.d.ts +2 -1
  68. package/dist/tests/harness/fourslash/testLanguageService.js +2 -2
  69. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  70. package/dist/tests/typeEvaluator2.test.js +1 -1
  71. package/dist/tests/typeEvaluator3.test.js +1 -1
  72. package/dist/tests/typeEvaluator4.test.js +1 -1
  73. package/dist/tests/typeEvaluator5.test.js +9 -7
  74. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  75. package/package.json +1 -1
@@ -93,6 +93,7 @@ export declare class Checker extends ParseTreeWalker {
93
93
  private _isLegalOverloadImplementation;
94
94
  private _walkStatementsAndReportUnreachable;
95
95
  private _validateStubStatement;
96
+ private _validateExceptionTypeRecursive;
96
97
  private _validateExceptionType;
97
98
  private _reportUnusedDunderAllSymbols;
98
99
  private _validateSymbolTables;
@@ -1121,7 +1121,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1121
1121
  }
1122
1122
  let isTypeBool = true;
1123
1123
  const diag = new diagnostic_1.DiagnosticAddendum();
1124
- this._evaluator.mapSubtypesExpandTypeVars(operandType, /* conditionFilter */ undefined, (expandedSubtype) => {
1124
+ this._evaluator.mapSubtypesExpandTypeVars(operandType, /* options */ undefined, (expandedSubtype) => {
1125
1125
  if ((0, types_1.isAnyOrUnknown)(expandedSubtype)) {
1126
1126
  return undefined;
1127
1127
  }
@@ -1556,7 +1556,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1556
1556
  // other types, and ParamSpecs. There are legitimate uses for singleton
1557
1557
  // instances in these particular cases.
1558
1558
  let isExempt = nameType.details.constraints.length > 0 ||
1559
- !!nameType.details.defaultType ||
1559
+ nameType.details.isDefaultExplicit ||
1560
1560
  (exemptBoundTypeVar && subscriptIndex !== undefined) ||
1561
1561
  (0, types_1.isParamSpec)(nameType);
1562
1562
  if (!isExempt && baseExpression && subscriptIndex !== undefined) {
@@ -1604,7 +1604,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1604
1604
  if (constructorClass && nameType.scopeId === constructorClass.details.typeVarScopeId) {
1605
1605
  const existingEntry = classTypeVarUsage.get(nameType.details.name);
1606
1606
  const isParamTypeWithEllipsisUsage = ((_d = curParamNode === null || curParamNode === void 0 ? void 0 : curParamNode.defaultValue) === null || _d === void 0 ? void 0 : _d.nodeType) === 18 /* ParseNodeType.Ellipsis */;
1607
- const isExempt = !!nameType.details.defaultType;
1607
+ const isExempt = !!nameType.details.isDefaultExplicit;
1608
1608
  if (!existingEntry) {
1609
1609
  classTypeVarUsage.set(nameType.details.name, {
1610
1610
  typeVar: nameType,
@@ -1935,57 +1935,48 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1935
1935
  }
1936
1936
  }
1937
1937
  }
1938
- _validateExceptionType(exceptionType, errorNode) {
1939
- var _a, _b;
1940
- const baseExceptionType = this._evaluator.getBuiltInType(errorNode, 'BaseException');
1938
+ _validateExceptionTypeRecursive(exceptionType, diag, baseExceptionType, allowTuple) {
1941
1939
  const derivesFromBaseException = (classType) => {
1942
1940
  if (!baseExceptionType || !(0, types_1.isInstantiableClass)(baseExceptionType)) {
1943
1941
  return true;
1944
1942
  }
1945
1943
  return (0, typeUtils_1.derivesFromClassRecursive)(classType, baseExceptionType, /* ignoreUnknown */ false);
1946
1944
  };
1947
- const diagAddendum = new diagnostic_1.DiagnosticAddendum();
1948
- let resultingExceptionType;
1949
- if ((0, types_1.isAnyOrUnknown)(exceptionType)) {
1950
- resultingExceptionType = exceptionType;
1951
- }
1952
- else {
1953
- if ((0, types_1.isInstantiableClass)(exceptionType)) {
1954
- if (!derivesFromBaseException(exceptionType)) {
1955
- diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeIncorrect().format({
1956
- type: this._evaluator.printType(exceptionType),
1957
- }));
1958
- }
1959
- resultingExceptionType = types_1.ClassType.cloneAsInstance(exceptionType);
1945
+ (0, typeUtils_1.doForEachSubtype)(exceptionType, (exceptionSubtype) => {
1946
+ if ((0, types_1.isAnyOrUnknown)(exceptionSubtype)) {
1947
+ return;
1960
1948
  }
1961
- else if ((0, types_1.isClassInstance)(exceptionType)) {
1962
- const iterableType = (_b = (_a = this._evaluator.getTypeOfIterator({ type: exceptionType }, /* isAsync */ false, errorNode)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
1963
- resultingExceptionType = (0, typeUtils_1.mapSubtypes)(iterableType, (subtype) => {
1964
- subtype = this._evaluator.makeTopLevelTypeVarsConcrete(subtype);
1965
- if ((0, types_1.isAnyOrUnknown)(subtype) || (0, types_1.isNever)(subtype)) {
1966
- return subtype;
1967
- }
1968
- if ((0, types_1.isInstantiableClass)(subtype)) {
1969
- if (!derivesFromBaseException(subtype)) {
1970
- diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeIncorrect().format({
1971
- type: this._evaluator.printType(exceptionType),
1972
- }));
1973
- }
1974
- return types_1.ClassType.cloneAsInstance(subtype);
1949
+ if ((0, types_1.isClass)(exceptionSubtype)) {
1950
+ if (types_1.TypeBase.isInstantiable(exceptionSubtype)) {
1951
+ if (!derivesFromBaseException(exceptionSubtype)) {
1952
+ diag.addMessage(localize_1.LocMessage.exceptionTypeIncorrect().format({
1953
+ type: this._evaluator.printType(exceptionSubtype),
1954
+ }));
1975
1955
  }
1976
- diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeIncorrect().format({
1977
- type: this._evaluator.printType(exceptionType),
1978
- }));
1979
- return types_1.UnknownType.create();
1980
- });
1956
+ return;
1957
+ }
1958
+ if (allowTuple && exceptionSubtype.tupleTypeArguments) {
1959
+ exceptionSubtype.tupleTypeArguments.forEach((typeArg) => {
1960
+ this._validateExceptionTypeRecursive(typeArg.type, diag, baseExceptionType,
1961
+ /* allowTuple */ false);
1962
+ });
1963
+ return;
1964
+ }
1965
+ diag.addMessage(localize_1.LocMessage.exceptionTypeIncorrect().format({
1966
+ type: this._evaluator.printType(exceptionSubtype),
1967
+ }));
1981
1968
  }
1982
- }
1969
+ });
1970
+ }
1971
+ _validateExceptionType(exceptionType, errorNode) {
1972
+ const baseExceptionType = this._evaluator.getBuiltInType(errorNode, 'BaseException');
1973
+ const diagAddendum = new diagnostic_1.DiagnosticAddendum();
1974
+ this._validateExceptionTypeRecursive(exceptionType, diagAddendum, baseExceptionType, /* allowTuple */ true);
1983
1975
  if (!diagAddendum.isEmpty()) {
1984
1976
  this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.exceptionTypeNotClass().format({
1985
1977
  type: this._evaluator.printType(exceptionType),
1986
1978
  }), errorNode);
1987
1979
  }
1988
- return resultingExceptionType || types_1.UnknownType.create();
1989
1980
  }
1990
1981
  _reportUnusedDunderAllSymbols(nodes) {
1991
1982
  // If this rule is disabled, don't bother doing the work.
@@ -4347,9 +4338,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
4347
4338
  return;
4348
4339
  }
4349
4340
  // If the symbol has no declaration, and the type is inferred,
4350
- // skip this check.
4351
- if (!symbol.hasTypedDeclarations() && !this._evaluator.isFinalVariable(symbol)) {
4352
- return;
4341
+ // skip the type validation but still check for other issues like
4342
+ // Final overrides and class/instance variable mismatches.
4343
+ let validateType = true;
4344
+ if (!symbol.hasTypedDeclarations()) {
4345
+ validateType = false;
4353
4346
  }
4354
4347
  // Get the symbol type defined in this class.
4355
4348
  const typeOfSymbol = this._evaluator.getEffectiveTypeOfSymbol(symbol);
@@ -4374,7 +4367,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
4374
4367
  continue;
4375
4368
  }
4376
4369
  firstOverride = firstOverride !== null && firstOverride !== void 0 ? firstOverride : baseClassAndSymbol;
4377
- this._validateBaseClassOverride(baseClassAndSymbol, symbol, typeOfSymbol, classType, name);
4370
+ this._validateBaseClassOverride(baseClassAndSymbol, symbol, validateType ? typeOfSymbol : types_1.AnyType.create(), classType, name);
4378
4371
  }
4379
4372
  if (!firstOverride) {
4380
4373
  // If this is a method decorated with @override, validate that there
@@ -4557,7 +4550,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
4557
4550
  // Handle properties specially.
4558
4551
  if (!(0, typeUtils_1.isProperty)(overrideType)) {
4559
4552
  const decls = overrideSymbol.getDeclarations();
4560
- if (decls.length > 0) {
4553
+ if (decls.length > 0 && overrideSymbol.isClassMember()) {
4561
4554
  const lastDecl = decls[decls.length - 1];
4562
4555
  this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportIncompatibleMethodOverride, localize_1.LocMessage.propertyOverridden().format({
4563
4556
  name: memberName,