@zzzen/pyright-internal 1.2.0-dev.20231112 → 1.2.0-dev.20231119

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 (71) hide show
  1. package/dist/analyzer/checker.d.ts +1 -0
  2. package/dist/analyzer/checker.js +31 -19
  3. package/dist/analyzer/checker.js.map +1 -1
  4. package/dist/analyzer/constraintSolver.js +10 -0
  5. package/dist/analyzer/constraintSolver.js.map +1 -1
  6. package/dist/analyzer/constructors.js +10 -6
  7. package/dist/analyzer/constructors.js.map +1 -1
  8. package/dist/analyzer/declarationUtils.js +5 -2
  9. package/dist/analyzer/declarationUtils.js.map +1 -1
  10. package/dist/analyzer/docStringConversion.js +1 -1
  11. package/dist/analyzer/docStringConversion.js.map +1 -1
  12. package/dist/analyzer/docStringUtils.js +1 -1
  13. package/dist/analyzer/importResolver.js +6 -1
  14. package/dist/analyzer/importResolver.js.map +1 -1
  15. package/dist/analyzer/patternMatching.js +19 -14
  16. package/dist/analyzer/patternMatching.js.map +1 -1
  17. package/dist/analyzer/program.js +2 -3
  18. package/dist/analyzer/program.js.map +1 -1
  19. package/dist/analyzer/sourceMapper.js +3 -0
  20. package/dist/analyzer/sourceMapper.js.map +1 -1
  21. package/dist/analyzer/typeEvaluator.js +39 -23
  22. package/dist/analyzer/typeEvaluator.js.map +1 -1
  23. package/dist/analyzer/typeGuards.js +16 -2
  24. package/dist/analyzer/typeGuards.js.map +1 -1
  25. package/dist/analyzer/typeUtils.js +40 -0
  26. package/dist/analyzer/typeUtils.js.map +1 -1
  27. package/dist/analyzer/typeVarContext.d.ts +1 -0
  28. package/dist/analyzer/typeVarContext.js +3 -0
  29. package/dist/analyzer/typeVarContext.js.map +1 -1
  30. package/dist/analyzer/types.d.ts +1 -1
  31. package/dist/analyzer/types.js +12 -4
  32. package/dist/analyzer/types.js.map +1 -1
  33. package/dist/languageServerBase.d.ts +3 -3
  34. package/dist/languageServerBase.js +6 -6
  35. package/dist/languageServerBase.js.map +1 -1
  36. package/dist/languageService/completionProvider.js +5 -11
  37. package/dist/languageService/completionProvider.js.map +1 -1
  38. package/dist/localization/localize.d.ts +3 -3
  39. package/dist/localization/localize.js +3 -1
  40. package/dist/localization/localize.js.map +1 -1
  41. package/dist/localization/package.nls.cs.json +5 -5
  42. package/dist/localization/package.nls.de.json +5 -5
  43. package/dist/localization/package.nls.en-us.json +8 -6
  44. package/dist/localization/package.nls.es.json +5 -5
  45. package/dist/localization/package.nls.fr.json +5 -5
  46. package/dist/localization/package.nls.it.json +5 -5
  47. package/dist/localization/package.nls.ja.json +5 -5
  48. package/dist/localization/package.nls.ko.json +5 -5
  49. package/dist/localization/package.nls.pl.json +5 -5
  50. package/dist/localization/package.nls.pt-br.json +5 -5
  51. package/dist/localization/package.nls.qps-ploc.json +2 -2
  52. package/dist/localization/package.nls.ru.json +5 -5
  53. package/dist/localization/package.nls.tr.json +5 -5
  54. package/dist/localization/package.nls.zh-cn.json +5 -5
  55. package/dist/localization/package.nls.zh-tw.json +5 -5
  56. package/dist/pyright.js +17 -1
  57. package/dist/pyright.js.map +1 -1
  58. package/dist/tests/config.test.js +7 -5
  59. package/dist/tests/config.test.js.map +1 -1
  60. package/dist/tests/docStringConversion.test.js +0 -22
  61. package/dist/tests/docStringConversion.test.js.map +1 -1
  62. package/dist/tests/fourslash/completions.params.fourslash.js +11 -0
  63. package/dist/tests/fourslash/completions.params.fourslash.js.map +1 -1
  64. package/dist/tests/fourslash/hover.docstring.split.fourslash.js +10 -0
  65. package/dist/tests/fourslash/hover.docstring.split.fourslash.js.map +1 -1
  66. package/dist/tests/typeEvaluator1.test.js +4 -0
  67. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  68. package/dist/tests/typeEvaluator2.test.js +8 -0
  69. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  70. package/dist/tests/typeEvaluator4.test.js +1 -1
  71. package/package.json +1 -1
@@ -115,6 +115,7 @@ export declare class Checker extends ParseTreeWalker {
115
115
  private _validateTypeGuardFunction;
116
116
  private _validateDunderSignatures;
117
117
  private _validateFunctionReturn;
118
+ private _validateReturnTypeIsNotContravariant;
118
119
  private _reportUnknownReturnResult;
119
120
  private _validateFinalMemberOverrides;
120
121
  private _reportDuplicateEnumMembers;
@@ -2461,21 +2461,20 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2461
2461
  return;
2462
2462
  }
2463
2463
  let isValidType = true;
2464
+ const diag = new diagnostic_1.DiagnosticAddendum();
2464
2465
  (0, typeUtils_1.doForEachSubtype)(arg1Type, (arg1Subtype) => {
2465
2466
  if ((0, types_1.isClassInstance)(arg1Subtype) && types_1.ClassType.isTupleClass(arg1Subtype) && arg1Subtype.tupleTypeArguments) {
2466
- if (arg1Subtype.tupleTypeArguments.some((typeArg) => !this._isTypeSupportedTypeForIsInstance(typeArg.type, isInstanceCheck))) {
2467
+ if (arg1Subtype.tupleTypeArguments.some((typeArg) => !this._isTypeSupportedTypeForIsInstance(typeArg.type, isInstanceCheck, diag))) {
2467
2468
  isValidType = false;
2468
2469
  }
2469
2470
  }
2470
2471
  else {
2471
- if (!this._isTypeSupportedTypeForIsInstance(arg1Subtype, isInstanceCheck)) {
2472
+ if (!this._isTypeSupportedTypeForIsInstance(arg1Subtype, isInstanceCheck, diag)) {
2472
2473
  isValidType = false;
2473
2474
  }
2474
2475
  }
2475
2476
  });
2476
2477
  if (!isValidType) {
2477
- const diag = new diagnostic_1.DiagnosticAddendum();
2478
- diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeVarNotAllowed());
2479
2478
  this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, isInstanceCheck
2480
2479
  ? localize_1.Localizer.Diagnostic.isInstanceInvalidType().format({
2481
2480
  type: this._evaluator.printType(arg1Type),
@@ -2556,12 +2555,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2556
2555
  if (!isValidType) {
2557
2556
  return;
2558
2557
  }
2559
- // According to PEP 544, protocol classes cannot be used as the right-hand
2560
- // argument to isinstance or issubclass unless they are annotated as
2561
- // "runtime checkable".
2562
- if (classTypeList.some((type) => types_1.ClassType.isProtocolClass(type) && !types_1.ClassType.isRuntimeCheckable(type))) {
2563
- this._evaluator.addError(localize_1.Localizer.Diagnostic.protocolUsedInCall().format({ name: callName }), node.arguments[1].valueExpression);
2564
- }
2565
2558
  if ((0, typeUtils_1.derivesFromAnyOrUnknown)(arg0Type)) {
2566
2559
  return;
2567
2560
  }
@@ -2652,7 +2645,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2652
2645
  }
2653
2646
  // Determines whether the specified type is allowed as the second argument
2654
2647
  // to an isinstance or issubclass check.
2655
- _isTypeSupportedTypeForIsInstance(type, isInstanceCheck) {
2648
+ _isTypeSupportedTypeForIsInstance(type, isInstanceCheck, diag) {
2656
2649
  let isSupported = true;
2657
2650
  (0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
2658
2651
  subtype = this._evaluator.makeTopLevelTypeVarsConcrete(subtype);
@@ -2664,23 +2657,33 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
2664
2657
  break;
2665
2658
  case 6 /* Class */:
2666
2659
  if ((0, typeUtils_1.isNoneInstance)(subtype)) {
2660
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.noneNotAllowed());
2667
2661
  isSupported = false;
2668
2662
  }
2669
2663
  else if (subtype.isTypeArgumentExplicit && !subtype.includeSubclasses) {
2670
2664
  // If it's a class, make sure that it has not been given explicit
2671
2665
  // type arguments. This will result in a TypeError exception.
2666
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.genericClassNotAllowed());
2667
+ isSupported = false;
2668
+ }
2669
+ else if (types_1.ClassType.isProtocolClass(subtype) &&
2670
+ !types_1.ClassType.isRuntimeCheckable(subtype) &&
2671
+ !subtype.includeSubclasses) {
2672
+ // According to PEP 544, protocol classes cannot be used as the right-hand
2673
+ // argument to isinstance or issubclass unless they are annotated as
2674
+ // "runtime checkable".
2675
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.protocolRequiresRuntimeCheckable());
2672
2676
  isSupported = false;
2673
2677
  }
2674
2678
  break;
2675
2679
  case 4 /* Function */:
2676
2680
  if (!types_1.TypeBase.isInstantiable(subtype) || subtype.isCallableWithTypeArgs) {
2681
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.genericClassNotAllowed());
2677
2682
  isSupported = false;
2678
2683
  }
2679
2684
  break;
2680
- case 8 /* Union */:
2681
- isSupported = this._isTypeSupportedTypeForIsInstance(subtype, isInstanceCheck);
2682
- break;
2683
- default:
2685
+ case 9 /* TypeVar */:
2686
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeVarNotAllowed());
2684
2687
  isSupported = false;
2685
2688
  break;
2686
2689
  }
@@ -3157,10 +3160,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3157
3160
  let declaredReturnType = functionType.details.declaredReturnType;
3158
3161
  if (declaredReturnType) {
3159
3162
  this._reportUnknownReturnResult(node, declaredReturnType);
3160
- if ((0, types_1.isTypeVar)(declaredReturnType) &&
3161
- declaredReturnType.details.declaredVariance === 4 /* Contravariant */) {
3162
- this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.returnTypeContravariant(), returnAnnotation);
3163
- }
3163
+ this._validateReturnTypeIsNotContravariant(declaredReturnType, returnAnnotation);
3164
3164
  }
3165
3165
  // Wrap the declared type in a generator type if the function is a generator.
3166
3166
  if (types_1.FunctionType.isGenerator(functionType)) {
@@ -3201,6 +3201,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3201
3201
  else {
3202
3202
  const inferredReturnType = this._evaluator.getFunctionInferredReturnType(functionType);
3203
3203
  this._reportUnknownReturnResult(node, inferredReturnType);
3204
+ this._validateReturnTypeIsNotContravariant(inferredReturnType, node.name);
3205
+ }
3206
+ }
3207
+ _validateReturnTypeIsNotContravariant(returnType, errorNode) {
3208
+ let isContraTypeVar = false;
3209
+ (0, typeUtils_1.doForEachSubtype)(returnType, (subtype) => {
3210
+ if ((0, types_1.isTypeVar)(subtype) && subtype.details.declaredVariance === 4 /* Contravariant */) {
3211
+ isContraTypeVar = true;
3212
+ }
3213
+ });
3214
+ if (isContraTypeVar) {
3215
+ this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.returnTypeContravariant(), errorNode);
3204
3216
  }
3205
3217
  }
3206
3218
  _reportUnknownReturnResult(node, returnType) {