@zzzen/pyright-internal 1.2.0-dev.20260920 → 1.2.0-dev.20261004

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 (200) hide show
  1. package/dist/analyzer/analyzerNodeInfo.js +7 -2
  2. package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
  3. package/dist/analyzer/binder.js +17 -6
  4. package/dist/analyzer/binder.js.map +1 -1
  5. package/dist/analyzer/checker.d.ts +2 -2
  6. package/dist/analyzer/checker.js +21 -9
  7. package/dist/analyzer/checker.js.map +1 -1
  8. package/dist/analyzer/codeFlowEngine.d.ts +2 -0
  9. package/dist/analyzer/codeFlowEngine.js +162 -20
  10. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  11. package/dist/analyzer/codeFlowTypes.d.ts +2 -1
  12. package/dist/analyzer/codeFlowTypes.js +1 -0
  13. package/dist/analyzer/codeFlowTypes.js.map +1 -1
  14. package/dist/analyzer/codeFlowUtils.js +4 -1
  15. package/dist/analyzer/codeFlowUtils.js.map +1 -1
  16. package/dist/analyzer/operations.js +1 -1
  17. package/dist/analyzer/operations.js.map +1 -1
  18. package/dist/analyzer/overloadResult.d.ts +15 -0
  19. package/dist/analyzer/overloadResult.js +233 -0
  20. package/dist/analyzer/overloadResult.js.map +1 -0
  21. package/dist/analyzer/overloadResultAdmission.d.ts +20 -0
  22. package/dist/analyzer/overloadResultAdmission.js +448 -0
  23. package/dist/analyzer/overloadResultAdmission.js.map +1 -0
  24. package/dist/analyzer/overloadResultController.d.ts +227 -0
  25. package/dist/analyzer/overloadResultController.js +904 -0
  26. package/dist/analyzer/overloadResultController.js.map +1 -0
  27. package/dist/analyzer/overloadResultSelector.d.ts +24 -0
  28. package/dist/analyzer/overloadResultSelector.js +131 -0
  29. package/dist/analyzer/overloadResultSelector.js.map +1 -0
  30. package/dist/analyzer/parseTreeUtils.d.ts +1 -0
  31. package/dist/analyzer/parseTreeUtils.js +4 -0
  32. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  33. package/dist/analyzer/patternMatching.js +39 -2
  34. package/dist/analyzer/patternMatching.js.map +1 -1
  35. package/dist/analyzer/program.d.ts +13 -2
  36. package/dist/analyzer/program.js +102 -47
  37. package/dist/analyzer/program.js.map +1 -1
  38. package/dist/analyzer/protocols.d.ts +1 -0
  39. package/dist/analyzer/protocols.js +297 -9
  40. package/dist/analyzer/protocols.js.map +1 -1
  41. package/dist/analyzer/sourceFile.d.ts +6 -2
  42. package/dist/analyzer/sourceFile.js +9 -3
  43. package/dist/analyzer/sourceFile.js.map +1 -1
  44. package/dist/analyzer/symbolNameUtils.d.ts +1 -0
  45. package/dist/analyzer/symbolNameUtils.js +5 -0
  46. package/dist/analyzer/symbolNameUtils.js.map +1 -1
  47. package/dist/analyzer/tracePrinter.js +4 -0
  48. package/dist/analyzer/tracePrinter.js.map +1 -1
  49. package/dist/analyzer/typeCacheUtils.d.ts +4 -0
  50. package/dist/analyzer/typeCacheUtils.js +36 -0
  51. package/dist/analyzer/typeCacheUtils.js.map +1 -1
  52. package/dist/analyzer/typeComplexity.js +2 -0
  53. package/dist/analyzer/typeComplexity.js.map +1 -1
  54. package/dist/analyzer/typeEvaluator.d.ts +10 -1
  55. package/dist/analyzer/typeEvaluator.js +477 -19
  56. package/dist/analyzer/typeEvaluator.js.map +1 -1
  57. package/dist/analyzer/typeEvaluatorTypes.d.ts +31 -1
  58. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  59. package/dist/analyzer/typeGuards.d.ts +1 -1
  60. package/dist/analyzer/typePrinter.js +8 -0
  61. package/dist/analyzer/typePrinter.js.map +1 -1
  62. package/dist/analyzer/typeUtils.d.ts +1 -1
  63. package/dist/analyzer/typeUtils.js +38 -27
  64. package/dist/analyzer/typeUtils.js.map +1 -1
  65. package/dist/analyzer/typeWalker.d.ts +2 -1
  66. package/dist/analyzer/typeWalker.js +12 -0
  67. package/dist/analyzer/typeWalker.js.map +1 -1
  68. package/dist/analyzer/typedDicts.js +9 -4
  69. package/dist/analyzer/typedDicts.js.map +1 -1
  70. package/dist/analyzer/types.d.ts +16 -2
  71. package/dist/analyzer/types.js +94 -2
  72. package/dist/analyzer/types.js.map +1 -1
  73. package/dist/common/configOptions.d.ts +1 -0
  74. package/dist/common/configOptions.js +2 -0
  75. package/dist/common/configOptions.js.map +1 -1
  76. package/dist/common/extensibility.d.ts +1 -0
  77. package/dist/common/processUtils.d.ts +9 -1
  78. package/dist/common/processUtils.js +52 -10
  79. package/dist/common/processUtils.js.map +1 -1
  80. package/dist/common/windowsProcessTree.d.ts +4 -0
  81. package/dist/common/windowsProcessTree.js +47 -0
  82. package/dist/common/windowsProcessTree.js.map +1 -0
  83. package/dist/common/windowsProcessTree.json +310 -0
  84. package/dist/languageServerBase.js +2 -2
  85. package/dist/languageServerBase.js.map +1 -1
  86. package/dist/languageService/callHierarchyProvider.js +15 -6
  87. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  88. package/dist/languageService/completionProvider.js +4 -1
  89. package/dist/languageService/completionProvider.js.map +1 -1
  90. package/dist/localization/package.nls.pl.json +2 -2
  91. package/dist/localization/package.nls.pt-br.json +1 -1
  92. package/dist/localization/package.nls.zh-cn.json +2 -2
  93. package/dist/localization/package.nls.zh-tw.json +1 -1
  94. package/dist/tests/config.test.js +48 -0
  95. package/dist/tests/config.test.js.map +1 -1
  96. package/dist/tests/fourslash/findDefinitions.metaclass.fourslash.d.ts +1 -0
  97. package/dist/tests/fourslash/findDefinitions.metaclass.fourslash.js +44 -0
  98. package/dist/tests/fourslash/findDefinitions.metaclass.fourslash.js.map +1 -0
  99. package/dist/tests/fourslash/findDefinitions.metaclassDict.fourslash.d.ts +1 -0
  100. package/dist/tests/fourslash/findDefinitions.metaclassDict.fourslash.js +42 -0
  101. package/dist/tests/fourslash/findDefinitions.metaclassDict.fourslash.js.map +1 -0
  102. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedFunction.fourslash.js +10 -6
  103. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedFunction.fourslash.js.map +1 -1
  104. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.function.fourslash.js +16 -10
  105. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.function.fourslash.js.map +1 -1
  106. package/dist/tests/harness/fourslash/testState.js +10 -9
  107. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  108. package/dist/tests/languageServer.test.js +129 -0
  109. package/dist/tests/languageServer.test.js.map +1 -1
  110. package/dist/tests/mypyPrimerMcp.test.js +2 -1
  111. package/dist/tests/mypyPrimerMcp.test.js.map +1 -1
  112. package/dist/tests/overloadResult.test.d.ts +1 -0
  113. package/dist/tests/overloadResult.test.js +182 -0
  114. package/dist/tests/overloadResult.test.js.map +1 -0
  115. package/dist/tests/overloadResultController.test.d.ts +1 -0
  116. package/dist/tests/overloadResultController.test.js +2146 -0
  117. package/dist/tests/overloadResultController.test.js.map +1 -0
  118. package/dist/tests/protocolRequirement.test.d.ts +1 -0
  119. package/dist/tests/protocolRequirement.test.js +122 -0
  120. package/dist/tests/protocolRequirement.test.js.map +1 -0
  121. package/dist/tests/protocolRequirementAdversarial.test.d.ts +1 -0
  122. package/dist/tests/protocolRequirementAdversarial.test.js +92 -0
  123. package/dist/tests/protocolRequirementAdversarial.test.js.map +1 -0
  124. package/dist/tests/protocolRequirementBoundary.test.d.ts +1 -0
  125. package/dist/tests/protocolRequirementBoundary.test.js +119 -0
  126. package/dist/tests/protocolRequirementBoundary.test.js.map +1 -0
  127. package/dist/tests/protocolRequirementComplexity.test.d.ts +1 -0
  128. package/dist/tests/protocolRequirementComplexity.test.js +159 -0
  129. package/dist/tests/protocolRequirementComplexity.test.js.map +1 -0
  130. package/dist/tests/protocolRequirementCycles.test.d.ts +1 -0
  131. package/dist/tests/protocolRequirementCycles.test.js +160 -0
  132. package/dist/tests/protocolRequirementCycles.test.js.map +1 -0
  133. package/dist/tests/protocolRequirementGeneral.test.d.ts +1 -0
  134. package/dist/tests/protocolRequirementGeneral.test.js +120 -0
  135. package/dist/tests/protocolRequirementGeneral.test.js.map +1 -0
  136. package/dist/tests/protocolRequirementInstances.test.d.ts +1 -0
  137. package/dist/tests/protocolRequirementInstances.test.js +164 -0
  138. package/dist/tests/protocolRequirementInstances.test.js.map +1 -0
  139. package/dist/tests/protocolRequirementListStub.test.d.ts +1 -0
  140. package/dist/tests/protocolRequirementListStub.test.js +244 -0
  141. package/dist/tests/protocolRequirementListStub.test.js.map +1 -0
  142. package/dist/tests/protocolRequirementPopulated.test.d.ts +1 -0
  143. package/dist/tests/protocolRequirementPopulated.test.js +172 -0
  144. package/dist/tests/protocolRequirementPopulated.test.js.map +1 -0
  145. package/dist/tests/protocolRequirementRecursive.test.d.ts +1 -0
  146. package/dist/tests/protocolRequirementRecursive.test.js +118 -0
  147. package/dist/tests/protocolRequirementRecursive.test.js.map +1 -0
  148. package/dist/tests/protocolRequirementSpeculative.test.d.ts +1 -0
  149. package/dist/tests/protocolRequirementSpeculative.test.js +200 -0
  150. package/dist/tests/protocolRequirementSpeculative.test.js.map +1 -0
  151. package/dist/tests/protocolRequirementState.test.d.ts +1 -0
  152. package/dist/tests/protocolRequirementState.test.js +161 -0
  153. package/dist/tests/protocolRequirementState.test.js.map +1 -0
  154. package/dist/tests/service.test.js +36 -0
  155. package/dist/tests/service.test.js.map +1 -1
  156. package/dist/tests/testState.test.js +64 -0
  157. package/dist/tests/testState.test.js.map +1 -1
  158. package/dist/tests/testUtils.d.ts +6 -1
  159. package/dist/tests/testUtils.js +11 -6
  160. package/dist/tests/testUtils.js.map +1 -1
  161. package/dist/tests/typeCacheIsolation.test.d.ts +1 -0
  162. package/dist/tests/typeCacheIsolation.test.js +109 -0
  163. package/dist/tests/typeCacheIsolation.test.js.map +1 -0
  164. package/dist/tests/typeCacheUtils.test.js +59 -0
  165. package/dist/tests/typeCacheUtils.test.js.map +1 -1
  166. package/dist/tests/typeEvaluator1.test.js +32 -2
  167. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  168. package/dist/tests/typeEvaluator4.test.js +6 -2
  169. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  170. package/dist/tests/typeEvaluator5.test.js +25 -0
  171. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  172. package/dist/tests/typeEvaluator6.test.js +19 -23
  173. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  174. package/dist/tests/typeEvaluator7.test.js +237 -2
  175. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  176. package/dist/tests/typeEvaluator8.test.js +28 -0
  177. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  178. package/dist/tests/typeServer/inProcTypeServerTestUtils.d.ts +7 -2
  179. package/dist/tests/typeServer/inProcTypeServerTestUtils.js +14 -7
  180. package/dist/tests/typeServer/inProcTypeServerTestUtils.js.map +1 -1
  181. package/dist/tests/typeServer/stubGenerator.test.js +29 -0
  182. package/dist/tests/typeServer/stubGenerator.test.js.map +1 -1
  183. package/dist/tests/typeServer/typeServer.inProc.test.js +173 -1
  184. package/dist/tests/typeServer/typeServer.inProc.test.js.map +1 -1
  185. package/dist/tests/typeServer/typeServer.virtualFileRedirect.test.js +15 -0
  186. package/dist/tests/typeServer/typeServer.virtualFileRedirect.test.js.map +1 -1
  187. package/dist/tests/typeUtils.test.js +36 -0
  188. package/dist/tests/typeUtils.test.js.map +1 -1
  189. package/dist/trace/nativeAdapter.js +1 -5
  190. package/dist/trace/nativeAdapter.js.map +1 -1
  191. package/dist/typeServer/protocol/typeServerProtocol.d.ts +8 -2
  192. package/dist/typeServer/protocol/typeServerProtocol.js +1 -0
  193. package/dist/typeServer/protocol/typeServerProtocol.js.map +1 -1
  194. package/dist/typeServer/stubGenerator.js +5 -6
  195. package/dist/typeServer/stubGenerator.js.map +1 -1
  196. package/dist/typeServer/typeServerConversionUtils.js +9 -0
  197. package/dist/typeServer/typeServerConversionUtils.js.map +1 -1
  198. package/dist/workspaceFactory.js +5 -0
  199. package/dist/workspaceFactory.js.map +1 -1
  200. package/package.json +3 -3
@@ -95,8 +95,10 @@ const typedDicts_1 = require("./typedDicts");
95
95
  const typeEvaluatorTypes_1 = require("./typeEvaluatorTypes");
96
96
  const typeGuards_1 = require("./typeGuards");
97
97
  const TypePrinter = __importStar(require("./typePrinter"));
98
+ const typeWalker_1 = require("./typeWalker");
98
99
  const types_1 = require("./types");
99
100
  const typeUtils_1 = require("./typeUtils");
101
+ const overloadResultSelector_1 = require("./overloadResultSelector");
100
102
  // This table contains the names of several built-in types that
101
103
  // are not subscriptable at runtime on older versions of Python.
102
104
  // It lists the first version of Python where subscripting is
@@ -192,6 +194,8 @@ const printExpressionTypes = false;
192
194
  function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
193
195
  const nodeInfo = AnalyzerNodeInfo.createAnalyzerNodeInfoAccessor(evaluatorOptions.nodeInfoReader);
194
196
  const maxCodeComplexity = evaluatorOptions.maxCodeComplexity;
197
+ const operationController = evaluatorOptions.experimentalOverloadResult ?? evaluatorOptions.testOnlyExpression;
198
+ let operationRouter = evaluatorOptions.experimentalOverloadResult?.isAutomatic ? undefined : operationController;
195
199
  const symbolResolutionStack = [];
196
200
  const speculativeTypeTracker = new typeCacheUtils_1.SpeculativeTypeTracker();
197
201
  const suppressedNodeStack = [];
@@ -262,6 +266,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
262
266
  // circular references in complex data structures, so it fails
263
267
  // to clean up the objects if we don't help it out.
264
268
  function disposeEvaluator() {
269
+ operationController?.dispose?.();
265
270
  functionRecursionMap = new Map();
266
271
  codeFlowAnalyzerCache = new Map();
267
272
  typeCache = new Map();
@@ -466,10 +471,40 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
466
471
  }
467
472
  return undefined;
468
473
  }
474
+ function finishOverloadActivation() {
475
+ if (!returnTypeInferenceTypeCache && !isSpeculativeModeInUse(undefined)) {
476
+ try {
477
+ evaluatorOptions.experimentalOverloadResult.finishActivation();
478
+ }
479
+ finally {
480
+ // Install routing before an activation restart re-enters evaluation.
481
+ if (evaluatorOptions.experimentalOverloadResult.roots.size) {
482
+ operationRouter = operationController;
483
+ }
484
+ }
485
+ }
486
+ }
487
+ function runWithOverloadActivation(callback) {
488
+ return evaluatorOptions.experimentalOverloadResult.runWithActivation(() => {
489
+ const result = callback();
490
+ if (evaluatorOptions.experimentalOverloadResult.hasPendingActivation) {
491
+ finishOverloadActivation();
492
+ }
493
+ return result;
494
+ });
495
+ }
469
496
  // Determines the type of the specified node by evaluating it in
470
497
  // context, logging any errors in the process. This may require the
471
498
  // type of surrounding statements to be evaluated.
472
499
  function getType(node) {
500
+ if (evaluatorOptions.experimentalOverloadResult?.needsActivationBoundary()) {
501
+ return runWithOverloadActivation(() => getType(node));
502
+ }
503
+ const canonical = operationRouter?.route?.({ kind: 'query', node })?.result ??
504
+ evaluatorOptions.testOnlyExpression?.query?.(node);
505
+ if (canonical) {
506
+ return canonical.type;
507
+ }
473
508
  initializePrefetchedTypes(node);
474
509
  let type = evaluateContextualTypeForSubnode(node, () => {
475
510
  evaluateTypesForExpressionInContext(node);
@@ -508,6 +543,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
508
543
  return type;
509
544
  }
510
545
  function getTypeResult(node) {
546
+ if (evaluatorOptions.experimentalOverloadResult?.needsActivationBoundary()) {
547
+ return runWithOverloadActivation(() => getTypeResult(node));
548
+ }
549
+ const canonical = operationRouter?.route?.({ kind: 'query', node })?.result ??
550
+ evaluatorOptions.testOnlyExpression?.query?.(node);
551
+ if (canonical) {
552
+ return canonical;
553
+ }
511
554
  return evaluateContextualTypeForSubnode(node, () => {
512
555
  evaluateTypesForExpressionInContext(node);
513
556
  });
@@ -643,6 +686,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
643
686
  }
644
687
  }
645
688
  function getTypeOfExpression(node, flags = 0 /* EvalFlags.None */, inferenceContext) {
689
+ if (evaluatorOptions.experimentalOverloadResult?.needsActivationBoundary()) {
690
+ return runWithOverloadActivation(() => getTypeOfExpression(node, flags, inferenceContext));
691
+ }
646
692
  let useTypeFormCache = (flags & 1073741824 /* EvalFlags.TypeFormArg */) !== 0;
647
693
  if (inferenceContext) {
648
694
  inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
@@ -654,6 +700,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
654
700
  if ((flags & 1073741824 /* EvalFlags.TypeFormArg */) !== 0 && (flags & 33554432 /* EvalFlags.NoConvertSpecialForm */) === 0) {
655
701
  flags |= 32 /* EvalFlags.NoParamSpec */ | 64 /* EvalFlags.NoTypeVarTuple */;
656
702
  }
703
+ const testResult = operationRouter?.route?.({
704
+ kind: 'expression',
705
+ node,
706
+ flags,
707
+ context: inferenceContext,
708
+ })?.result ?? operationRouter?.dispatch(node, flags, inferenceContext);
709
+ if (testResult) {
710
+ return testResult;
711
+ }
657
712
  // Is this type already cached?
658
713
  const cacheEntry = useTypeFormCache
659
714
  ? readTypeFormTypeCacheEntry(node, inferenceContext?.expectedType)
@@ -693,6 +748,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
693
748
  // at that point.
694
749
  initializePrefetchedTypes(node);
695
750
  let typeResult = getTypeOfExpressionCore(node, flags, inferenceContext);
751
+ if (evaluatorOptions.experimentalOverloadResult?.hasPendingActivation) {
752
+ finishOverloadActivation();
753
+ }
754
+ if (operationRouter) {
755
+ typeResult = operationRouter.project(node, typeResult);
756
+ }
696
757
  // Should we disable type promotions for bytes?
697
758
  if ((0, types_1.isInstantiableClass)(typeResult.type) &&
698
759
  typeResult.type.priv.includePromotions &&
@@ -1342,6 +1403,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1342
1403
  }
1343
1404
  recursionCount++;
1344
1405
  switch (type.category) {
1406
+ case 10 /* TypeCategory.OverloadResult */:
1407
+ return true;
1345
1408
  case 0 /* TypeCategory.Unbound */:
1346
1409
  case 1 /* TypeCategory.Unknown */:
1347
1410
  case 2 /* TypeCategory.Any */:
@@ -1440,6 +1503,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1440
1503
  }
1441
1504
  recursionCount++;
1442
1505
  switch (type.category) {
1506
+ case 10 /* TypeCategory.OverloadResult */:
1507
+ return true;
1443
1508
  case 1 /* TypeCategory.Unknown */:
1444
1509
  case 4 /* TypeCategory.Function */:
1445
1510
  case 5 /* TypeCategory.Overloaded */:
@@ -1771,11 +1836,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1771
1836
  }
1772
1837
  const argList = [];
1773
1838
  let previousCategory = 0 /* ArgCategory.Simple */;
1839
+ let hasFakeArg = false;
1774
1840
  // Empty arguments do not enter the AST as nodes, but instead are left blank.
1775
1841
  // Instead, we detect when we appear to be between two known arguments or at the
1776
1842
  // end of the argument list and insert a fake argument of an unknown type to have
1777
1843
  // something to match later.
1778
1844
  function addFakeArg() {
1845
+ hasFakeArg = true;
1779
1846
  argList.push({
1780
1847
  argCategory: previousCategory,
1781
1848
  typeResult: { type: types_1.UnknownType.create() },
@@ -1812,7 +1879,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1812
1879
  /* skipUnknownArgCheck */ true,
1813
1880
  /* inferenceContext */ undefined);
1814
1881
  });
1815
- const specializedType = solveAndApplyConstraints(type, constraints);
1882
+ let specializedType = type;
1883
+ if (types_1.FunctionType.getParamSpecFromArgsKwargs(type)) {
1884
+ const solution = (0, constraintSolver_1.solveConstraints)(evaluatorInterface, constraints);
1885
+ // The fake argument is used only to identify the active parameter. Preserve
1886
+ // type variables in that parameter while specializing the forwarded ParamSpec.
1887
+ if (hasFakeArg && callResult?.activeParam) {
1888
+ const activeParamIndex = type.shared.parameters.indexOf(callResult.activeParam);
1889
+ if (activeParamIndex >= 0) {
1890
+ (0, typeUtils_1.getTypeVarArgsRecursive)(types_1.FunctionType.getParamType(type, activeParamIndex)).forEach((typeVar) => {
1891
+ if (!(0, types_1.isParamSpec)(typeVar)) {
1892
+ solution.doForEachSolutionSet((solutionSet) => {
1893
+ const solvedType = solutionSet.getType(typeVar);
1894
+ if (!solvedType || (0, types_1.isUnknown)(solvedType)) {
1895
+ solutionSet.setType(typeVar, typeVar);
1896
+ }
1897
+ });
1898
+ }
1899
+ });
1900
+ }
1901
+ }
1902
+ specializedType = (0, typeUtils_1.applySolvedTypeVars)(type, solution);
1903
+ }
1816
1904
  const finalType = (0, types_1.isFunction)(specializedType) ? specializedType : type;
1817
1905
  const hasActiveArg = argList.some((arg) => arg.active);
1818
1906
  // If the type was specialized (e.g. ParamSpec expansion), the activeParam
@@ -2427,6 +2515,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2427
2515
  }
2428
2516
  return undefined;
2429
2517
  }
2518
+ function getFunctionClassType(type) {
2519
+ const classType = (0, types_1.isMethodType)(type) ? prefetched?.methodClass : prefetched?.functionClass;
2520
+ return classType && (0, types_1.isInstantiableClass)(classType) ? classType : undefined;
2521
+ }
2430
2522
  function getTypingType(node, symbolName) {
2431
2523
  return (getTypeOfModule(node, symbolName, ['typing']) ?? getTypeOfModule(node, symbolName, ['typing_extensions']));
2432
2524
  }
@@ -2571,7 +2663,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2571
2663
  }
2572
2664
  if (isNodeReachable(node)) {
2573
2665
  const fileInfo = nodeInfo.getFileInfo(node);
2574
- return fileInfo.diagnosticSink.addDiagnosticWithTextRange(diagLevel, message, range ?? node);
2666
+ const sink = evaluatorOptions.experimentalOverloadResult?.getDiagnosticSink(node) ?? fileInfo.diagnosticSink;
2667
+ return sink.addDiagnosticWithTextRange(diagLevel, message, range ?? node);
2575
2668
  }
2576
2669
  return undefined;
2577
2670
  }
@@ -2656,6 +2749,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2656
2749
  const memberInfo = (0, typeUtils_1.lookUpClassMember)(classType.classType, nameNode.d.value, 1 /* MemberAccessFlags.SkipOriginalClass */);
2657
2750
  if (memberInfo?.isTypeDeclared) {
2658
2751
  declaredType = getTypeOfMember(memberInfo);
2752
+ if ((0, symbolNameUtils_1.isMethodExemptFromLsp)(nameValue) &&
2753
+ memberInfo.symbol
2754
+ .getTypedDeclarations()
2755
+ .some((decl) => decl.type === 5 /* DeclarationType.Function */) &&
2756
+ (0, types_1.isFunctionOrOverloaded)(typeResult.type) &&
2757
+ (0, types_1.isFunctionOrOverloaded)(declaredType) &&
2758
+ !isFinalVariable(memberInfo.symbol)) {
2759
+ const baseMethods = (0, types_1.isFunction)(declaredType)
2760
+ ? [declaredType]
2761
+ : [
2762
+ ...types_1.OverloadedType.getOverloads(declaredType),
2763
+ types_1.OverloadedType.getImplementation(declaredType),
2764
+ ];
2765
+ if (!baseMethods.some((method) => method && (0, types_1.isFunction)(method) && types_1.FunctionType.isFinal(method))) {
2766
+ // Apply the same override exemptions to aliases and method definitions.
2767
+ declaredType = undefined;
2768
+ }
2769
+ }
2659
2770
  }
2660
2771
  }
2661
2772
  }
@@ -3528,7 +3639,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3528
3639
  }
3529
3640
  else {
3530
3641
  // Handle the special case of "reveal_type" and "reveal_locals".
3531
- if (name === 'reveal_type' || name === 'reveal_locals') {
3642
+ if (ParseTreeUtils.isImplicitRevealTypeName(node) || name === 'reveal_locals') {
3532
3643
  type = types_1.AnyType.create();
3533
3644
  }
3534
3645
  else {
@@ -4432,6 +4543,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4432
4543
  }
4433
4544
  break;
4434
4545
  }
4546
+ case 10 /* TypeCategory.OverloadResult */:
4547
+ throw new Error('Overload-result member dispatch is not enabled');
4435
4548
  default:
4436
4549
  (0, debug_1.assertNever)(baseType);
4437
4550
  }
@@ -4499,6 +4612,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4499
4612
  const isAccessedThroughObject = types_1.TypeBase.isInstance(classType);
4500
4613
  // Always look for a member with a declared type first.
4501
4614
  let memberInfo = (0, typeUtils_1.lookUpClassMember)(classType, memberName, flags | 64 /* MemberAccessFlags.DeclaredTypesOnly */);
4615
+ // A class-level method alias retains its inferred signature, unlike an annotated variable.
4616
+ if (usage.method === 'get' &&
4617
+ memberInfo?.skippedUndeclaredType &&
4618
+ memberInfo.symbol.getTypedDeclarations().some((decl) => decl.type === 5 /* DeclarationType.Function */)) {
4619
+ const inferredMember = (0, typeUtils_1.lookUpClassMember)(classType, memberName, flags);
4620
+ if (inferredMember?.isClassMember &&
4621
+ !inferredMember.isInstanceMember &&
4622
+ (0, types_1.isFunctionOrOverloaded)(getTypeOfMember(inferredMember))) {
4623
+ memberInfo = inferredMember;
4624
+ }
4625
+ }
4502
4626
  // If we couldn't find a symbol with a declared type, use
4503
4627
  // a symbol with an inferred type.
4504
4628
  if (!memberInfo) {
@@ -4747,7 +4871,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4747
4871
  const subDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
4748
4872
  const methodTypeResult = getTypeOfBoundMember(errorNode, concreteMemberType, accessMethodName,
4749
4873
  /* usage */ undefined, subDiag, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */);
4750
- if (!methodTypeResult || methodTypeResult.typeErrors) {
4874
+ const deferredMethodType = usage.method === 'get'
4875
+ ? getDescriptorGetMethodWithDeferredSelfSpecialization(concreteMemberType, subDiag)
4876
+ : undefined;
4877
+ if ((!methodTypeResult || methodTypeResult.typeErrors) && !deferredMethodType) {
4751
4878
  // Provide special error messages for properties.
4752
4879
  if (types_1.ClassType.isPropertyClass(concreteMemberType) && usage.method !== 'get') {
4753
4880
  const message = usage.method === 'set' ? localize_1.LocAddendum.propertyMissingSetter() : localize_1.LocAddendum.propertyMissingDeleter();
@@ -4759,9 +4886,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4759
4886
  }
4760
4887
  return { type: memberType };
4761
4888
  }
4762
- const methodClassType = methodTypeResult.classType;
4763
- let methodType = methodTypeResult.type;
4764
- if (methodTypeResult.typeErrors || !methodClassType) {
4889
+ const methodClassType = methodTypeResult?.classType ?? concreteMemberType;
4890
+ let methodType = deferredMethodType ?? methodTypeResult.type;
4891
+ if (!methodClassType) {
4765
4892
  if (diag && subDiag) {
4766
4893
  diag.addAddendum(subDiag);
4767
4894
  }
@@ -4922,6 +5049,65 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4922
5049
  memberAccessDeprecationInfo: deprecationInfo,
4923
5050
  };
4924
5051
  }
5052
+ function getDescriptorGetMethodWithDeferredSelfSpecialization(concreteMemberType, diag) {
5053
+ const member = (0, typeUtils_1.lookUpClassMember)(concreteMemberType, '__get__');
5054
+ if (!member || !(0, types_1.isInstantiableClass)(member.unspecializedClassType)) {
5055
+ return undefined;
5056
+ }
5057
+ const unspecializedClassType = member.unspecializedClassType;
5058
+ const declaringClassType = member.classType;
5059
+ if (!(0, types_1.isInstantiableClass)(declaringClassType)) {
5060
+ return undefined;
5061
+ }
5062
+ const declaringObjectType = types_1.ClassType.cloneAsInstance(declaringClassType);
5063
+ const unspecializedMethodType = getEffectiveTypeOfSymbol(member.symbol);
5064
+ if (!(0, types_1.isFunctionOrOverloaded)(unspecializedMethodType)) {
5065
+ return undefined;
5066
+ }
5067
+ // A class ParamSpec used in Concatenate within the self annotation needs to be
5068
+ // solved from the concrete descriptor, rather than specialized before self is bound.
5069
+ const classParamSpecs = types_1.ClassType.getTypeParams(unspecializedClassType).filter(types_1.isParamSpec);
5070
+ if (classParamSpecs.length === 0) {
5071
+ return undefined;
5072
+ }
5073
+ const signatures = (0, types_1.isFunction)(unspecializedMethodType)
5074
+ ? [unspecializedMethodType]
5075
+ : types_1.OverloadedType.getOverloads(unspecializedMethodType);
5076
+ const shouldDefer = signatures.some((signature) => {
5077
+ if (signature.shared.parameters.length === 0) {
5078
+ return false;
5079
+ }
5080
+ const selfParamType = types_1.FunctionType.getParamType(signature, 0);
5081
+ if (!(0, types_1.isClassInstance)(selfParamType) || !types_1.ClassType.isSameGenericClass(selfParamType, declaringObjectType)) {
5082
+ return false;
5083
+ }
5084
+ class ConcatenateParamSpecWalker extends typeWalker_1.TypeWalker {
5085
+ constructor() {
5086
+ super(...arguments);
5087
+ this.found = false;
5088
+ }
5089
+ visitFunction(type) {
5090
+ const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
5091
+ if (paramSpec &&
5092
+ types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(type).shared.parameters.length > 0 &&
5093
+ classParamSpecs.some((classParamSpec) => (0, types_1.isTypeSame)(paramSpec, classParamSpec))) {
5094
+ this.found = true;
5095
+ this.cancelWalk();
5096
+ return;
5097
+ }
5098
+ super.visitFunction(type);
5099
+ }
5100
+ }
5101
+ const walker = new ConcatenateParamSpecWalker();
5102
+ selfParamType.priv.typeArgs?.forEach((typeArg) => walker.walk(typeArg));
5103
+ return walker.found;
5104
+ });
5105
+ if (!shouldDefer) {
5106
+ return undefined;
5107
+ }
5108
+ return bindFunctionToClassOrObject(declaringObjectType, unspecializedMethodType, declaringClassType,
5109
+ /* treatConstructorAsClassMethod */ false, concreteMemberType, diag);
5110
+ }
4925
5111
  function bindMethodForMemberAccess(type, concreteType, memberInfo, classType, selfType, flags, memberName, usage, diag, recursionCount = 0) {
4926
5112
  // Check for an attempt to overwrite a final method.
4927
5113
  if (usage.method === 'set') {
@@ -6279,6 +6465,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6279
6465
  else {
6280
6466
  baseTypeResult = getTypeOfExpression(node.d.leftExpr, 2 /* EvalFlags.CallBaseDefaults */ | (flags & 4 /* EvalFlags.ForwardRefs */));
6281
6467
  }
6468
+ operationRouter?.beforeCall(node);
6282
6469
  const argList = ParseTreeUtils.getArgsByRuntimeOrder(node).map((arg) => {
6283
6470
  const functionArg = {
6284
6471
  valueExpression: arg.d.valueExpr,
@@ -6296,8 +6483,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6296
6483
  typeResult = getTypeOfSuperCall(node);
6297
6484
  }
6298
6485
  else if ((0, types_1.isAnyOrUnknown)(baseTypeResult.type) &&
6299
- node.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
6300
- node.d.leftExpr.d.value === 'reveal_type') {
6486
+ ParseTreeUtils.isImplicitRevealTypeName(node.d.leftExpr)) {
6301
6487
  // Handle the implicit "reveal_type" call.
6302
6488
  typeResult = getTypeOfRevealType(node, inferenceContext);
6303
6489
  }
@@ -7058,6 +7244,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7058
7244
  isTypeIncomplete = true;
7059
7245
  }
7060
7246
  if (!callResult.argumentErrors && callResult.returnType) {
7247
+ if (evaluatorOptions.experimentalOverloadResult &&
7248
+ !callResult.isTypeIncomplete &&
7249
+ !overload.priv.boundToType &&
7250
+ !overload.shared.methodClass &&
7251
+ !overload.shared.declaration?.isMethod &&
7252
+ errorNode.nodeType === 9 /* ParseNodeType.Call */ &&
7253
+ errorNode.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
7254
+ errorNode.parent?.nodeType === 3 /* ParseNodeType.Assignment */ &&
7255
+ errorNode.parent.d.rightExpr === errorNode &&
7256
+ expandedArgTypes.length === 1 &&
7257
+ !hasArgTypeOverride &&
7258
+ callResult.argResults) {
7259
+ evaluatorOptions.experimentalOverloadResult.considerActivation(errorNode, callResult.argResults);
7260
+ }
7061
7261
  overloadsUsedForCall.push(overload);
7062
7262
  matchedOverload = overload;
7063
7263
  const matchedOverloadInfo = {
@@ -7276,6 +7476,115 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7276
7476
  });
7277
7477
  return winningOverloadIndex === undefined ? undefined : matches[winningOverloadIndex].overload;
7278
7478
  }
7479
+ function selectAutomaticOverloadResult(node, limit, proofUnits) {
7480
+ const budget = new overloadResultSelector_1.OverloadSelectionBudget(proofUnits);
7481
+ const coverage = [];
7482
+ const matches = [];
7483
+ const decline = (reason) => ({
7484
+ candidates: [],
7485
+ reason: budget.exceeded ? 'proof-limit' : reason,
7486
+ coverage,
7487
+ matches,
7488
+ units: budget.used,
7489
+ });
7490
+ return useSpeculativeMode(node, () => {
7491
+ const callee = getTypeOfExpression(node.d.leftExpr, 2 /* EvalFlags.NoSpecialize */);
7492
+ if (callee.isIncomplete || callee.typeErrors || !(0, types_1.isOverloaded)(callee.type)) {
7493
+ return decline('not-complete-overloaded-function');
7494
+ }
7495
+ const overloads = types_1.OverloadedType.getOverloads(callee.type);
7496
+ if (overloads.length > limit) {
7497
+ return decline('candidate-limit');
7498
+ }
7499
+ const args = node.d.args.map((arg) => ({
7500
+ argCategory: arg.d.argCategory,
7501
+ valueExpression: arg.d.valueExpr,
7502
+ node: arg,
7503
+ name: arg.d.name,
7504
+ }));
7505
+ const sources = node.d.args.map((arg) => getTypeOfExpression(arg.d.valueExpr));
7506
+ if (sources.some((s) => s.isIncomplete || s.typeErrors || (0, types_1.isAny)(s.type) || !(0, overloadResultSelector_1.isFixedOverloadArgumentShape)(s.type, budget))) {
7507
+ return decline('unsupported-argument-shape');
7508
+ }
7509
+ if (!sources.some((s) => (0, overloadResultSelector_1.hasNestedOverloadAny)(s.type))) {
7510
+ return decline('no-invariant-any');
7511
+ }
7512
+ const returns = [];
7513
+ for (let index = 0; index < overloads.length; index++) {
7514
+ checkForCancellation();
7515
+ const overload = overloads[index];
7516
+ const declaration = overload.shared.declaration;
7517
+ const declaredReturnType = overload.shared.declaredReturnType;
7518
+ const returnType = types_1.FunctionType.getEffectiveReturnType(overload);
7519
+ if (!declaration ||
7520
+ declaration.isMethod ||
7521
+ overload.shared.methodClass ||
7522
+ overload.priv.boundToType ||
7523
+ overload.shared.typeParams.length ||
7524
+ !declaredReturnType ||
7525
+ !returnType ||
7526
+ declaration.node.d.decorators.length !== 1 ||
7527
+ overload.shared.parameters.some((p, i) => p.category !== 0 /* ParamCategory.Simple */ ||
7528
+ !p.name ||
7529
+ p.defaultExpr ||
7530
+ types_1.FunctionType.getParamDefaultType(overload, i))) {
7531
+ return decline('unsupported-signature');
7532
+ }
7533
+ if (!(0, overloadResultSelector_1.isFixedOverloadReturnShape)(declaredReturnType, budget) ||
7534
+ (returnType !== declaredReturnType && !(0, overloadResultSelector_1.isFixedOverloadReturnShape)(returnType, budget))) {
7535
+ return decline('unsupported-return-shape');
7536
+ }
7537
+ const mapping = matchArgsToParams(node, args, { type: overload, isIncomplete: false }, index);
7538
+ if (mapping.isTypeIncomplete) {
7539
+ return decline('incomplete-mapping');
7540
+ }
7541
+ if (mapping.argumentErrors) {
7542
+ continue;
7543
+ }
7544
+ if (mapping.argParams.length !== args.length ||
7545
+ mapping.argParams.some((p, i) => p.argument !== args[i] ||
7546
+ p.isDefaultArg ||
7547
+ p.requiresTypeVarMatching ||
7548
+ !(0, overloadResultSelector_1.isFixedOverloadArgumentShape)(p.paramType, budget))) {
7549
+ return decline('unsupported-mapping');
7550
+ }
7551
+ // This is the ordinary matcher and solver, not a parallel
7552
+ // assignability algorithm. Only complete successful matches count.
7553
+ const matched = useSpeculativeMode(node, () => validateArgTypesWithContext(node, mapping, new constraintTracker_1.ConstraintTracker(), true, undefined));
7554
+ if (matched.isTypeIncomplete || !matched.returnType) {
7555
+ return decline('incomplete-solution');
7556
+ }
7557
+ if (!(0, overloadResultSelector_1.isFixedOverloadReturnShape)(matched.returnType, budget)) {
7558
+ return decline('unsupported-solved-return-shape');
7559
+ }
7560
+ if (matched.argumentErrors) {
7561
+ continue;
7562
+ }
7563
+ const proof = mapping.argParams.map((p, i) => (0, overloadResultSelector_1.getFixedOverloadCoverage)(sources[i].type, p.paramType, budget));
7564
+ const covered = proof.includes('unsupported')
7565
+ ? 'unsupported'
7566
+ : proof.includes('not-covered')
7567
+ ? 'not-covered'
7568
+ : 'covered';
7569
+ coverage.push(covered);
7570
+ matches.push(index);
7571
+ if (covered === 'unsupported') {
7572
+ return decline('unsupported-coverage');
7573
+ }
7574
+ if (!returns.some((type) => (0, types_1.isTypeSame)(type, matched.returnType))) {
7575
+ returns.push(matched.returnType);
7576
+ }
7577
+ // A covering overload ends the retained prefix; earlier
7578
+ // non-covering matches remain live alternatives.
7579
+ if (covered === 'covered') {
7580
+ break;
7581
+ }
7582
+ }
7583
+ return returns.length > 1
7584
+ ? { candidates: returns, reason: 'selected', coverage, matches, units: budget.used }
7585
+ : decline('equivalent-or-single-return');
7586
+ });
7587
+ }
7279
7588
  function validateOverloadedArgTypes(errorNode, argList, typeResult, constraints, skipUnknownArgCheck, inferenceContext) {
7280
7589
  const filteredMatchResults = [];
7281
7590
  let contextFreeArgTypes;
@@ -12151,8 +12460,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12151
12460
  }
12152
12461
  // Validate that we received at least two type arguments. One type argument
12153
12462
  // is allowed if it's an unpacked TypeVarTuple or tuple. None is also allowed
12154
- // since it is used to define NoReturn in typeshed stubs).
12155
- if (types.length === 1 && !allowSingleTypeArg && !(0, typeUtils_1.isNoneInstance)(types[0])) {
12463
+ // since it is used to define NoReturn in typeshed stubs). No type arguments,
12464
+ // as in "Union[()]", is a runtime error.
12465
+ if (types.length === 0 || (types.length === 1 && !allowSingleTypeArg && !(0, typeUtils_1.isNoneInstance)(types[0]))) {
12156
12466
  if ((flags & (256 /* EvalFlags.TypeExpression */ | 1073741824 /* EvalFlags.TypeFormArg */)) !== 0) {
12157
12467
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.unionTypeArgCount(), errorNode);
12158
12468
  }
@@ -12505,6 +12815,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12505
12815
  }
12506
12816
  }
12507
12817
  function evaluateTypesForAssignmentStatement(node) {
12818
+ if (operationRouter?.route?.({
12819
+ kind: 'statement',
12820
+ node,
12821
+ evaluate: () => evaluateTypesForAssignmentStatement(node),
12822
+ })) {
12823
+ return;
12824
+ }
12508
12825
  const fileInfo = nodeInfo.getFileInfo(node);
12509
12826
  // If the entire statement has already been evaluated, don't
12510
12827
  // re-evaluate it.
@@ -13240,6 +13557,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13240
13557
  // Determine the effective metaclass.
13241
13558
  if (metaclassNode) {
13242
13559
  let metaclassType = getTypeOfExpression(metaclassNode, exprFlags).type;
13560
+ if ((0, types_1.isAny)(metaclassType)) {
13561
+ metaclassType = types_1.UnknownType.create();
13562
+ }
13243
13563
  if ((0, types_1.isInstantiableClass)(metaclassType) || (0, types_1.isUnknown)(metaclassType)) {
13244
13564
  if ((0, typeUtils_1.requiresSpecialization)(metaclassType, { ignorePseudoGeneric: true })) {
13245
13565
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.metaclassIsGeneric(), metaclassNode);
@@ -14643,7 +14963,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14643
14963
  return exceptionType;
14644
14964
  }
14645
14965
  if ((0, types_1.isInstantiableClass)(exceptionType)) {
14646
- if (types_1.ClassType.isBuiltIn(exceptionType, 'BaseException')) {
14966
+ if ((0, typeUtils_1.derivesFromStdlibClass)(exceptionType, 'BaseException') &&
14967
+ !(0, typeUtils_1.derivesFromStdlibClass)(exceptionType, 'Exception')) {
14647
14968
  includesBaseException = true;
14648
14969
  }
14649
14970
  return types_1.ClassType.cloneAsInstance(exceptionType);
@@ -15365,6 +15686,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15365
15686
  // be evaluated to provide sufficient context for the type. Evaluated types
15366
15687
  // are written back to the type cache for later retrieval.
15367
15688
  function evaluateTypesForStatement(node) {
15689
+ if (evaluatorOptions.experimentalOverloadResult?.needsActivationBoundary()) {
15690
+ return runWithOverloadActivation(() => evaluateTypesForStatement(node));
15691
+ }
15368
15692
  initializePrefetchedTypes(node);
15369
15693
  let curNode = node;
15370
15694
  while (curNode) {
@@ -16179,8 +16503,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16179
16503
  }
16180
16504
  // PEP 563 indicates that if a forward reference can be resolved in the module
16181
16505
  // scope (or, by implication, in the builtins scope), it should prefer that
16182
- // resolution over local resolutions.
16183
- if (symbolWithScope && preferGlobalScope) {
16506
+ // resolution over local resolutions. This doesn't apply to a PEP 695 "type"
16507
+ // statement's target, which binds synchronously in the scope where it appears
16508
+ // (including a class scope) rather than being deferred like other annotations.
16509
+ const isTypeAliasStatementTarget = symbolWithScope?.symbol
16510
+ .getDeclarations()
16511
+ .some((decl) => decl.type === 4 /* DeclarationType.TypeAlias */);
16512
+ if (symbolWithScope && preferGlobalScope && !isTypeAliasStatementTarget) {
16184
16513
  let curSymbolWithScope = symbolWithScope;
16185
16514
  while (curSymbolWithScope.scope.type !== 4 /* ScopeType.Module */ &&
16186
16515
  curSymbolWithScope.scope.type !== 5 /* ScopeType.Builtin */ &&
@@ -19317,6 +19646,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19317
19646
  /* diag */ undefined,
19318
19647
  /* constraints */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount));
19319
19648
  }
19649
+ // Types like "bytes", "bytearray" and "memoryview" support cross-type
19650
+ // content comparisons via "==" and "!=", even though they're otherwise
19651
+ // unrelated (non-overlapping) types. Use derivesFromStdlibClass to check
19652
+ // membership in this group across the MRO.
19653
+ function isBytesLikeType(type) {
19654
+ return ((0, typeUtils_1.derivesFromStdlibClass)(type, 'bytes') ||
19655
+ (0, typeUtils_1.derivesFromStdlibClass)(type, 'bytearray') ||
19656
+ (0, typeUtils_1.derivesFromStdlibClass)(type, 'memoryview'));
19657
+ }
19658
+ // Determines whether the two types are both members of the "bytes-like"
19659
+ // group of types ("bytes", "bytearray" and "memoryview"). Pyright models
19660
+ // this relationship as a "type promotion" (used elsewhere for
19661
+ // assignability), but that grouping is also useful for determining
19662
+ // whether two otherwise-disjoint built-in types can be compared with
19663
+ // "==" or "!=", since these types share compatible "__eq__" semantics
19664
+ // regardless of whether the "disableBytesTypePromotions" setting allows
19665
+ // the assignment.
19666
+ function isTypePromotionRelated(leftType, rightType) {
19667
+ return isBytesLikeType(leftType) && isBytesLikeType(rightType);
19668
+ }
19320
19669
  // Determines whether the two types are potentially comparable -- i.e.
19321
19670
  // their types overlap in such a way that it makes sense for them to
19322
19671
  // be compared with an == or != operator. The functional also supports
@@ -19407,6 +19756,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19407
19756
  }
19408
19757
  return boolVal === (intVal === 1);
19409
19758
  }
19759
+ // Distinct bytes-like classes support cross-type equality regardless
19760
+ // of disableBytesTypePromotions. Don't apply this to the same class:
19761
+ // different bytes literals must remain disjoint.
19762
+ if (!assumeIsOperator &&
19763
+ !types_1.ClassType.isSameGenericClass(leftType, rightType) &&
19764
+ isTypePromotionRelated(leftType, rightType)) {
19765
+ return true;
19766
+ }
19410
19767
  return false;
19411
19768
  }
19412
19769
  }
@@ -19897,8 +20254,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19897
20254
  destParamDetails.firstPositionOrKeywordIndex < srcParamDetails.positionOnlyParamCount &&
19898
20255
  !targetIncludesParamSpec) {
19899
20256
  diag?.createAddendum().addMessage(localize_1.LocAddendum.argsPositionOnly().format({
19900
- expected: srcParamDetails.positionOnlyParamCount,
19901
- received: destParamDetails.firstPositionOrKeywordIndex,
20257
+ expected: destParamDetails.firstPositionOrKeywordIndex,
20258
+ received: srcParamDetails.positionOnlyParamCount,
19902
20259
  }));
19903
20260
  canAssign = false;
19904
20261
  }
@@ -20959,7 +21316,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
20959
21316
  if (functionType.priv.strippedFirstParamType) {
20960
21317
  return functionType;
20961
21318
  }
20962
- if (types_1.FunctionType.isInstanceMethod(functionType)) {
21319
+ if (types_1.FunctionType.isInstanceMethod(functionType) && !treatConstructorAsClassMethod) {
20963
21320
  // If the baseType is a metaclass, don't specialize the function.
20964
21321
  if ((0, typeUtils_1.isInstantiableMetaclass)(baseType)) {
20965
21322
  return functionType;
@@ -20976,8 +21333,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
20976
21333
  }
20977
21334
  return partiallySpecializeBoundMethod(baseType, functionType, diag, recursionCount, selfType ?? baseObj, stripFirstParam);
20978
21335
  }
20979
- if (types_1.FunctionType.isClassMethod(functionType) ||
20980
- (treatConstructorAsClassMethod && types_1.FunctionType.isConstructorMethod(functionType))) {
21336
+ if (types_1.FunctionType.isClassMethod(functionType) || treatConstructorAsClassMethod) {
20981
21337
  const baseClass = (0, types_1.isInstantiableClass)(baseType) ? baseType : types_1.ClassType.cloneAsInstantiable(baseType);
20982
21338
  const clsType = selfType ? (0, typeUtils_1.convertToInstantiable)(selfType) : undefined;
20983
21339
  return partiallySpecializeBoundMethod(baseClass, functionType, diag, recursionCount, clsType ?? baseClass,
@@ -21341,6 +21697,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
21341
21697
  validateInitSubclassArgs,
21342
21698
  isNodeReachable,
21343
21699
  isAfterNodeReachable,
21700
+ isKeyPresentInTypedDict: (node) => codeFlowEngine.isKeyPresentInTypedDict(node),
21344
21701
  getNodeReachability,
21345
21702
  getAfterNodeReachability,
21346
21703
  isAsymmetricAccessorAssignment,
@@ -21396,6 +21753,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
21396
21753
  getNoneType,
21397
21754
  getUnionClassType,
21398
21755
  getTypeClassType,
21756
+ getFunctionClassType,
21399
21757
  getBuiltInObject,
21400
21758
  getTypingType,
21401
21759
  getTypeCheckerInternalsType,
@@ -21424,6 +21782,106 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
21424
21782
  printControlFlowGraph,
21425
21783
  };
21426
21784
  const codeFlowEngine = (0, codeFlowEngine_1.getCodeFlowEngine)(evaluatorInterface, speculativeTypeTracker, nodeInfo);
21785
+ if (evaluatorOptions.testOnlyMemberAccess) {
21786
+ const { nodes, install } = evaluatorOptions.testOnlyMemberAccess;
21787
+ install((node, baseTypeResult) => {
21788
+ (0, debug_1.assert)(nodes.has(node));
21789
+ return getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'get' }, 2 /* EvalFlags.NoSpecialize */);
21790
+ });
21791
+ }
21792
+ evaluatorOptions.experimentalOverloadResult?.installSelector(selectAutomaticOverloadResult);
21793
+ evaluatorOptions.experimentalOverloadResult?.installActivationBoundary(() => !returnTypeInferenceTypeCache && !isSpeculativeModeInUse(undefined), finishOverloadActivation);
21794
+ evaluatorOptions.experimentalOverloadResult?.installCheckerHandoff((root, expression, result, callback) => {
21795
+ const ids = evaluatorOptions.experimentalOverloadResult.roots.get(root);
21796
+ const isComplete = (value) => !value.isIncomplete &&
21797
+ !value.typeErrors &&
21798
+ !((0, types_1.isFunction)(value.type) && types_1.FunctionType.isPartiallyEvaluated(value.type)) &&
21799
+ !((0, types_1.isClass)(value.type) && types_1.ClassType.isPartiallyEvaluated(value.type));
21800
+ if (!ids ||
21801
+ returnTypeInferenceTypeCache ||
21802
+ isSpeculativeModeInUse(undefined) ||
21803
+ typeCache.get(expression.id)?.typeResult !== result ||
21804
+ typeCache.get(expression.id)?.flags !== 0 /* EvalFlags.None */ ||
21805
+ !isComplete(result)) {
21806
+ return false;
21807
+ }
21808
+ for (const id of ids) {
21809
+ const entry = typeCache.get(id);
21810
+ if ((entry && !isComplete(entry.typeResult)) || typeFormTypeCache.has(id)) {
21811
+ return false;
21812
+ }
21813
+ }
21814
+ // Continue synchronously before this candidate's isolation unwinds. No
21815
+ // saved cache set or result is restored, and the checker reads live entries.
21816
+ checkForCancellation();
21817
+ callback();
21818
+ return true;
21819
+ });
21820
+ evaluatorOptions.experimentalOverloadResult?.installQueryCache((root, node) => {
21821
+ const roots = evaluatorOptions.experimentalOverloadResult.roots;
21822
+ const ids = roots.get(root);
21823
+ const isOrdinaryContext = () => !returnTypeInferenceTypeCache && !isSpeculativeModeInUse(undefined);
21824
+ if (!ids || !isOrdinaryContext()) {
21825
+ return undefined;
21826
+ }
21827
+ const isComplete = (result) => !result.isIncomplete &&
21828
+ !((0, types_1.isFunction)(result.type) && types_1.FunctionType.isPartiallyEvaluated(result.type)) &&
21829
+ !((0, types_1.isClass)(result.type) && types_1.ClassType.isPartiallyEvaluated(result.type));
21830
+ const queryEntry = readContextualTypeCacheEntryForNode(node);
21831
+ if (!queryEntry || !isComplete(queryEntry.typeResult)) {
21832
+ return undefined;
21833
+ }
21834
+ const entries = [...ids].map((id) => ({
21835
+ id,
21836
+ runtime: typeCache.get(id),
21837
+ expected: expectedTypeCache.get(id),
21838
+ typeForm: typeFormTypeCache.get(id),
21839
+ }));
21840
+ const areComplete = () => entries.every((entry) => (!entry.runtime || isComplete(entry.runtime.typeResult)) &&
21841
+ (!entry.typeForm || entry.typeForm.every((e) => isComplete(e.typeResult))));
21842
+ if (!areComplete()) {
21843
+ return undefined;
21844
+ }
21845
+ // This is a validity guard, not a saved public answer. Reuse only while
21846
+ // the complete, privately restored cache set is still installed.
21847
+ return () => {
21848
+ const valid = isOrdinaryContext() &&
21849
+ roots.get(root) === ids &&
21850
+ readContextualTypeCacheEntryForNode(node) === queryEntry &&
21851
+ areComplete() &&
21852
+ entries.every((entry) => typeCache.get(entry.id) === entry.runtime &&
21853
+ expectedTypeCache.get(entry.id) === entry.expected &&
21854
+ typeFormTypeCache.get(entry.id) === entry.typeForm);
21855
+ if (valid) {
21856
+ checkForCancellation();
21857
+ }
21858
+ return valid;
21859
+ };
21860
+ });
21861
+ if (operationController) {
21862
+ const { roots } = operationController;
21863
+ operationController.installCacheIsolation({
21864
+ evict(root) {
21865
+ const ids = roots.get(root);
21866
+ (0, debug_1.assert)(ids && ids.size <= 256);
21867
+ (0, debug_1.assert)(!returnTypeInferenceTypeCache && !isSpeculativeModeInUse(undefined));
21868
+ ids.forEach((id) => {
21869
+ typeCache.delete(id);
21870
+ expectedTypeCache.delete(id);
21871
+ typeFormTypeCache.delete(id);
21872
+ });
21873
+ speculativeTypeTracker.evictCacheEntries(ids);
21874
+ },
21875
+ isolate(root, callback, retain = false) {
21876
+ const ids = roots.get(root);
21877
+ (0, debug_1.assert)(ids && ids.size <= 256);
21878
+ // Native argument speculation can query earlier, disjoint operations
21879
+ // through code flow. Never isolate a root that overlaps that context.
21880
+ (0, debug_1.assert)(!returnTypeInferenceTypeCache && speculativeTypeTracker.canUseNodeCacheIsolation(root));
21881
+ return (0, typeCacheUtils_1.useNodeCacheIsolation)(typeCache, ids, () => (0, typeCacheUtils_1.useNodeCacheIsolation)(expectedTypeCache, ids, () => (0, typeCacheUtils_1.useNodeCacheIsolation)(typeFormTypeCache, ids, () => speculativeTypeTracker.useNodeCacheIsolation(ids, callback, root), retain), retain), retain);
21882
+ },
21883
+ });
21884
+ }
21427
21885
  return evaluatorInterface;
21428
21886
  }
21429
21887
  //# sourceMappingURL=typeEvaluator.js.map