@zzzen/pyright-internal 1.2.0-dev.20240901 → 1.2.0-dev.20240908

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 (78) hide show
  1. package/dist/analyzer/binder.js +14 -8
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.js +23 -41
  4. package/dist/analyzer/checker.js.map +1 -1
  5. package/dist/analyzer/codeFlowEngine.js +7 -2
  6. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  7. package/dist/analyzer/constraintSolver.js +2 -2
  8. package/dist/analyzer/constraintSolver.js.map +1 -1
  9. package/dist/analyzer/constructors.js +7 -1
  10. package/dist/analyzer/constructors.js.map +1 -1
  11. package/dist/analyzer/dataClasses.js +6 -1
  12. package/dist/analyzer/dataClasses.js.map +1 -1
  13. package/dist/analyzer/namedTuples.js +4 -1
  14. package/dist/analyzer/namedTuples.js.map +1 -1
  15. package/dist/analyzer/operations.js +5 -0
  16. package/dist/analyzer/operations.js.map +1 -1
  17. package/dist/analyzer/parseTreeWalker.js +1 -1
  18. package/dist/analyzer/parseTreeWalker.js.map +1 -1
  19. package/dist/analyzer/protocols.js +5 -8
  20. package/dist/analyzer/protocols.js.map +1 -1
  21. package/dist/analyzer/sourceMapper.js +2 -1
  22. package/dist/analyzer/sourceMapper.js.map +1 -1
  23. package/dist/analyzer/typeEvaluator.js +536 -155
  24. package/dist/analyzer/typeEvaluator.js.map +1 -1
  25. package/dist/analyzer/typeEvaluatorTypes.d.ts +11 -5
  26. package/dist/analyzer/typeEvaluatorTypes.js +4 -1
  27. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  28. package/dist/analyzer/typeGuards.js +11 -8
  29. package/dist/analyzer/typeGuards.js.map +1 -1
  30. package/dist/analyzer/typePrinter.d.ts +2 -1
  31. package/dist/analyzer/typePrinter.js +24 -4
  32. package/dist/analyzer/typePrinter.js.map +1 -1
  33. package/dist/analyzer/typeUtils.d.ts +4 -0
  34. package/dist/analyzer/typeUtils.js +54 -1
  35. package/dist/analyzer/typeUtils.js.map +1 -1
  36. package/dist/analyzer/types.d.ts +8 -4
  37. package/dist/analyzer/types.js +68 -26
  38. package/dist/analyzer/types.js.map +1 -1
  39. package/dist/commands/dumpFileDebugInfoCommand.js +0 -1
  40. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  41. package/dist/languageService/callHierarchyProvider.js +2 -1
  42. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  43. package/dist/languageService/completionProvider.js +12 -12
  44. package/dist/languageService/completionProvider.js.map +1 -1
  45. package/dist/languageService/definitionProvider.js +6 -6
  46. package/dist/languageService/definitionProvider.js.map +1 -1
  47. package/dist/languageService/documentSymbolCollector.js +9 -9
  48. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  49. package/dist/languageService/hoverProvider.d.ts +1 -0
  50. package/dist/languageService/hoverProvider.js +30 -3
  51. package/dist/languageService/hoverProvider.js.map +1 -1
  52. package/dist/languageService/signatureHelpProvider.js +2 -2
  53. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  54. package/dist/languageService/tooltipUtils.js +2 -2
  55. package/dist/languageService/tooltipUtils.js.map +1 -1
  56. package/dist/localization/localize.d.ts +2 -0
  57. package/dist/localization/localize.js +2 -0
  58. package/dist/localization/localize.js.map +1 -1
  59. package/dist/localization/package.nls.en-us.json +2 -0
  60. package/dist/parser/parseNodes.d.ts +2 -3
  61. package/dist/parser/parseNodes.js.map +1 -1
  62. package/dist/parser/parser.js +6 -20
  63. package/dist/parser/parser.js.map +1 -1
  64. package/dist/tests/checker.test.js +5 -1
  65. package/dist/tests/checker.test.js.map +1 -1
  66. package/dist/tests/importStatementUtils.test.js +1 -1
  67. package/dist/tests/importStatementUtils.test.js.map +1 -1
  68. package/dist/tests/typeEvaluator1.test.js +1 -1
  69. package/dist/tests/typeEvaluator2.test.js +13 -1
  70. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  71. package/dist/tests/typeEvaluator3.test.js +1 -1
  72. package/dist/tests/typeEvaluator5.test.js +6 -0
  73. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  74. package/dist/tests/typeEvaluator8.test.js +40 -0
  75. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  76. package/dist/workspaceFactory.js +7 -7
  77. package/dist/workspaceFactory.js.map +1 -1
  78. package/package.json +1 -1
@@ -412,7 +412,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
412
412
  }
413
413
  }
414
414
  this._scopedNodes.push(node);
415
- if (functionTypeResult && (0, types_1.isOverloaded)(functionTypeResult.decoratedType)) {
415
+ if (functionTypeResult &&
416
+ (0, types_1.isOverloaded)(functionTypeResult.decoratedType) &&
417
+ functionTypeResult.functionType.priv.overloaded) {
416
418
  // If this is the implementation for the overloaded function, skip
417
419
  // overload consistency checks.
418
420
  if (types_1.OverloadedType.getImplementation(functionTypeResult.decoratedType) !== functionTypeResult.functionType) {
@@ -672,34 +674,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
672
674
  return true;
673
675
  }
674
676
  visitRaise(node) {
675
- this._evaluator.verifyRaiseExceptionType(node);
676
- if (node.d.valueExpression) {
677
- const baseExceptionType = this._evaluator.getBuiltInType(node, 'BaseException');
678
- const exceptionType = this._evaluator.getType(node.d.valueExpression);
679
- // Validate that the argument of "raise" is an exception object or None.
680
- if (exceptionType && baseExceptionType && (0, types_1.isInstantiableClass)(baseExceptionType)) {
681
- const diagAddendum = new diagnostic_1.DiagnosticAddendum();
682
- (0, typeUtils_1.doForEachSubtype)(exceptionType, (subtype) => {
683
- subtype = this._evaluator.makeTopLevelTypeVarsConcrete(subtype);
684
- if (!(0, types_1.isAnyOrUnknown)(subtype) && !(0, typeUtils_1.isNoneInstance)(subtype)) {
685
- if ((0, types_1.isClass)(subtype)) {
686
- if (!(0, typeUtils_1.derivesFromClassRecursive)(subtype, baseExceptionType, /* ignoreUnknown */ false)) {
687
- diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeIncorrect().format({
688
- type: this._evaluator.printType(subtype),
689
- }));
690
- }
691
- }
692
- else {
693
- diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeIncorrect().format({
694
- type: this._evaluator.printType(subtype),
695
- }));
696
- }
697
- }
698
- });
699
- if (!diagAddendum.isEmpty()) {
700
- this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.expectedExceptionObj() + diagAddendum.getString(), node.d.valueExpression);
701
- }
702
- }
677
+ if (node.d.expr) {
678
+ this._evaluator.verifyRaiseExceptionType(node.d.expr);
679
+ }
680
+ if (node.d.fromExpr) {
681
+ this._evaluator.verifyRaiseExceptionType(node.d.fromExpr);
703
682
  }
704
683
  return true;
705
684
  }
@@ -1009,11 +988,11 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1009
988
  return true;
1010
989
  }
1011
990
  visitImportFromAs(node) {
1012
- var _a, _b;
991
+ var _a, _b, _c;
1013
992
  if (this._fileInfo.isStubFile) {
1014
993
  return false;
1015
994
  }
1016
- const decls = this._evaluator.getDeclarationsForNameNode(node.d.name);
995
+ const decls = (_a = this._evaluator.getDeclInfoForNameNode(node.d.name)) === null || _a === void 0 ? void 0 : _a.decls;
1017
996
  if (!decls) {
1018
997
  return false;
1019
998
  }
@@ -1035,14 +1014,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1035
1014
  break;
1036
1015
  }
1037
1016
  let isImportFromTyping = false;
1038
- if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 25 /* ParseNodeType.ImportFrom */) {
1017
+ if (((_b = node.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 25 /* ParseNodeType.ImportFrom */) {
1039
1018
  if (node.parent.d.module.d.leadingDots === 0 && node.parent.d.module.d.nameParts.length === 1) {
1040
1019
  if (node.parent.d.module.d.nameParts[0].d.value === 'typing') {
1041
1020
  isImportFromTyping = true;
1042
1021
  }
1043
1022
  }
1044
1023
  }
1045
- const type = this._evaluator.getType((_b = node.d.alias) !== null && _b !== void 0 ? _b : node.d.name);
1024
+ const type = this._evaluator.getType((_c = node.d.alias) !== null && _c !== void 0 ? _c : node.d.name);
1046
1025
  this._reportDeprecatedUseForType(node.d.name, type, isImportFromTyping);
1047
1026
  return false;
1048
1027
  }
@@ -1851,7 +1830,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
1851
1830
  // earlier overload. Typeshed stubs contain type: ignore comments on these
1852
1831
  // lines, so it is important for us to report them in the same manner.
1853
1832
  _findNodeForOverload(functionNode, overloadType) {
1854
- const decls = this._evaluator.getDeclarationsForNameNode(functionNode.d.name);
1833
+ var _a;
1834
+ const decls = (_a = this._evaluator.getDeclInfoForNameNode(functionNode.d.name)) === null || _a === void 0 ? void 0 : _a.decls;
1855
1835
  if (!decls) {
1856
1836
  return undefined;
1857
1837
  }
@@ -3306,7 +3286,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3306
3286
  }
3307
3287
  }
3308
3288
  _conditionallyReportPrivateUsage(node) {
3309
- var _a, _b;
3289
+ var _a, _b, _c;
3310
3290
  if (this._fileInfo.diagnosticRuleSet.reportPrivateUsage === 'none') {
3311
3291
  return;
3312
3292
  }
@@ -3329,8 +3309,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3329
3309
  // Get the declarations for this name node, but filter out
3330
3310
  // any variable declarations that are bound using nonlocal
3331
3311
  // or global explicit bindings.
3332
- const declarations = (_b = this._evaluator
3333
- .getDeclarationsForNameNode(node)) === null || _b === void 0 ? void 0 : _b.filter((decl) => decl.type !== 1 /* DeclarationType.Variable */ || !decl.isExplicitBinding);
3312
+ const declarations = (_c = (_b = this._evaluator
3313
+ .getDeclInfoForNameNode(node)) === null || _b === void 0 ? void 0 : _b.decls) === null || _c === void 0 ? void 0 : _c.filter((decl) => decl.type !== 1 /* DeclarationType.Variable */ || !decl.isExplicitBinding);
3334
3314
  let primaryDeclaration = declarations && declarations.length > 0 ? declarations[declarations.length - 1] : undefined;
3335
3315
  if (!primaryDeclaration || primaryDeclaration.node === node) {
3336
3316
  return;
@@ -3465,7 +3445,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3465
3445
  }
3466
3446
  if (isTypeIs) {
3467
3447
  const scopeIds = (0, typeUtils_1.getTypeVarScopeIds)(functionType);
3468
- const typeGuardType = (0, typeUtils_1.makeTypeVarsBound)(returnType.priv.typeArgs[0], scopeIds);
3448
+ const narrowedType = returnType.priv.typeArgs[0];
3449
+ let typeGuardType = (0, typeUtils_1.makeTypeVarsBound)(narrowedType, scopeIds);
3450
+ typeGuardType = types_1.TypeBase.cloneWithTypeForm(typeGuardType, typeGuardType);
3469
3451
  // Determine the type of the first parameter.
3470
3452
  const paramIndex = isMethod && !types_1.FunctionType.isStaticMethod(functionType) ? 1 : 0;
3471
3453
  if (paramIndex >= functionType.shared.parameters.length) {
@@ -3478,7 +3460,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3478
3460
  if (returnAnnotation) {
3479
3461
  this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeIsReturnType().format({
3480
3462
  type: this._evaluator.printType(paramType),
3481
- returnType: this._evaluator.printType(typeGuardType),
3463
+ returnType: this._evaluator.printType(narrowedType),
3482
3464
  }), returnAnnotation);
3483
3465
  }
3484
3466
  }
@@ -3604,7 +3586,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3604
3586
  className: parentSymbol.classType.shared.name,
3605
3587
  }), decl.node);
3606
3588
  }
3607
- else if (types_1.ClassType.isReadOnlyInstanceVariables(parentSymbol.classType) &&
3589
+ else if (types_1.ClassType.hasNamedTupleEntry(parentSymbol.classType, name) &&
3608
3590
  !SymbolNameUtils.isDunderName(name)) {
3609
3591
  // If the parent class is a named tuple, all instance variables
3610
3592
  // (other than dundered ones) are implicitly final.
@@ -3893,7 +3875,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3893
3875
  // If this is part of a dataclass, a class handled by a dataclass_transform,
3894
3876
  // or a NamedTuple, exempt it because the class variable will be transformed
3895
3877
  // into an instance variable in this case.
3896
- if (types_1.ClassType.isDataClass(classType) || types_1.ClassType.isReadOnlyInstanceVariables(classType)) {
3878
+ if (types_1.ClassType.isDataClass(classType) || types_1.ClassType.hasNamedTupleEntry(classType, name)) {
3897
3879
  return true;
3898
3880
  }
3899
3881
  // If this is part of a TypedDict, exempt it because the class variables