@zzzen/pyright-internal 1.2.0-dev.20240512 → 1.2.0-dev.20240526

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 (156) hide show
  1. package/dist/analyzer/analysis.d.ts +5 -1
  2. package/dist/analyzer/analysis.js +3 -3
  3. package/dist/analyzer/analysis.js.map +1 -1
  4. package/dist/analyzer/backgroundAnalysisProgram.js +1 -1
  5. package/dist/analyzer/binder.js +6 -0
  6. package/dist/analyzer/binder.js.map +1 -1
  7. package/dist/analyzer/checker.js +14 -6
  8. package/dist/analyzer/checker.js.map +1 -1
  9. package/dist/analyzer/codeFlowEngine.js +28 -3
  10. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  11. package/dist/analyzer/constraintSolver.js +9 -17
  12. package/dist/analyzer/constraintSolver.js.map +1 -1
  13. package/dist/analyzer/constructorTransform.d.ts +2 -1
  14. package/dist/analyzer/constructorTransform.js +7 -6
  15. package/dist/analyzer/constructorTransform.js.map +1 -1
  16. package/dist/analyzer/constructors.d.ts +2 -2
  17. package/dist/analyzer/constructors.js +25 -22
  18. package/dist/analyzer/constructors.js.map +1 -1
  19. package/dist/analyzer/dataClasses.js +29 -24
  20. package/dist/analyzer/dataClasses.js.map +1 -1
  21. package/dist/analyzer/decorators.js +3 -1
  22. package/dist/analyzer/decorators.js.map +1 -1
  23. package/dist/analyzer/deprecatedSymbols.js +1 -0
  24. package/dist/analyzer/deprecatedSymbols.js.map +1 -1
  25. package/dist/analyzer/enums.d.ts +2 -5
  26. package/dist/analyzer/enums.js +98 -40
  27. package/dist/analyzer/enums.js.map +1 -1
  28. package/dist/analyzer/importResolver.js +11 -4
  29. package/dist/analyzer/importResolver.js.map +1 -1
  30. package/dist/analyzer/operations.js +11 -1
  31. package/dist/analyzer/operations.js.map +1 -1
  32. package/dist/analyzer/parameterUtils.d.ts +5 -5
  33. package/dist/analyzer/parameterUtils.js +16 -16
  34. package/dist/analyzer/parameterUtils.js.map +1 -1
  35. package/dist/analyzer/parentDirectoryCache.js +1 -2
  36. package/dist/analyzer/parentDirectoryCache.js.map +1 -1
  37. package/dist/analyzer/program.d.ts +2 -1
  38. package/dist/analyzer/program.js +13 -6
  39. package/dist/analyzer/program.js.map +1 -1
  40. package/dist/analyzer/properties.js +3 -3
  41. package/dist/analyzer/properties.js.map +1 -1
  42. package/dist/analyzer/service.d.ts +4 -2
  43. package/dist/analyzer/service.js +67 -33
  44. package/dist/analyzer/service.js.map +1 -1
  45. package/dist/analyzer/sourceFile.d.ts +1 -1
  46. package/dist/analyzer/sourceFile.js +20 -6
  47. package/dist/analyzer/sourceFile.js.map +1 -1
  48. package/dist/analyzer/typeDocStringUtils.js +6 -3
  49. package/dist/analyzer/typeDocStringUtils.js.map +1 -1
  50. package/dist/analyzer/typeEvaluator.js +442 -408
  51. package/dist/analyzer/typeEvaluator.js.map +1 -1
  52. package/dist/analyzer/typeEvaluatorTypes.d.ts +5 -4
  53. package/dist/analyzer/typeEvaluatorTypes.js +3 -0
  54. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  55. package/dist/analyzer/typeGuards.d.ts +1 -1
  56. package/dist/analyzer/typeGuards.js +28 -17
  57. package/dist/analyzer/typeGuards.js.map +1 -1
  58. package/dist/analyzer/typePrinter.js +7 -1
  59. package/dist/analyzer/typePrinter.js.map +1 -1
  60. package/dist/analyzer/typeUtils.d.ts +4 -5
  61. package/dist/analyzer/typeUtils.js +18 -85
  62. package/dist/analyzer/typeUtils.js.map +1 -1
  63. package/dist/analyzer/types.d.ts +0 -1
  64. package/dist/analyzer/types.js.map +1 -1
  65. package/dist/backgroundAnalysisBase.js +4 -4
  66. package/dist/backgroundAnalysisBase.js.map +1 -1
  67. package/dist/backgroundThreadBase.d.ts +2 -0
  68. package/dist/backgroundThreadBase.js +7 -3
  69. package/dist/backgroundThreadBase.js.map +1 -1
  70. package/dist/commands/createTypeStub.d.ts +7 -1
  71. package/dist/commands/createTypeStub.js +45 -32
  72. package/dist/commands/createTypeStub.js.map +1 -1
  73. package/dist/common/configOptions.d.ts +4 -3
  74. package/dist/common/configOptions.js +36 -31
  75. package/dist/common/configOptions.js.map +1 -1
  76. package/dist/common/console.d.ts +3 -0
  77. package/dist/common/console.js +4 -0
  78. package/dist/common/console.js.map +1 -1
  79. package/dist/common/languageServerInterface.d.ts +46 -0
  80. package/dist/common/languageServerInterface.js.map +1 -1
  81. package/dist/common/uri/uri.js +2 -0
  82. package/dist/common/uri/uri.js.map +1 -1
  83. package/dist/common/uri/uriUtils.d.ts +1 -1
  84. package/dist/common/uri/uriUtils.js +3 -3
  85. package/dist/common/uri/uriUtils.js.map +1 -1
  86. package/dist/common/workspaceEditUtils.js +8 -6
  87. package/dist/common/workspaceEditUtils.js.map +1 -1
  88. package/dist/languageServerBase.d.ts +4 -45
  89. package/dist/languageServerBase.js +36 -28
  90. package/dist/languageServerBase.js.map +1 -1
  91. package/dist/languageService/analyzerServiceExecutor.d.ts +2 -2
  92. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  93. package/dist/languageService/callHierarchyProvider.js +5 -5
  94. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  95. package/dist/languageService/completionProvider.js +1 -1
  96. package/dist/languageService/completionProvider.js.map +1 -1
  97. package/dist/languageService/documentSymbolProvider.js +1 -1
  98. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  99. package/dist/languageService/fileWatcherDynamicFeature.d.ts +2 -2
  100. package/dist/languageService/fileWatcherDynamicFeature.js +2 -2
  101. package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
  102. package/dist/languageService/navigationUtils.js +1 -1
  103. package/dist/languageService/navigationUtils.js.map +1 -1
  104. package/dist/languageService/workspaceSymbolProvider.js +1 -1
  105. package/dist/languageService/workspaceSymbolProvider.js.map +1 -1
  106. package/dist/localization/localize.d.ts +6 -6
  107. package/dist/localization/localize.js +2 -2
  108. package/dist/localization/localize.js.map +1 -1
  109. package/dist/localization/package.nls.cs.json +1 -3
  110. package/dist/localization/package.nls.de.json +2 -4
  111. package/dist/localization/package.nls.en-us.json +4 -4
  112. package/dist/localization/package.nls.es.json +2 -4
  113. package/dist/localization/package.nls.fr.json +2 -4
  114. package/dist/localization/package.nls.it.json +1 -3
  115. package/dist/localization/package.nls.ja.json +2 -4
  116. package/dist/localization/package.nls.ko.json +1 -3
  117. package/dist/localization/package.nls.pl.json +1 -3
  118. package/dist/localization/package.nls.pt-br.json +1 -3
  119. package/dist/localization/package.nls.qps-ploc.json +2 -4
  120. package/dist/localization/package.nls.ru.json +2 -4
  121. package/dist/localization/package.nls.tr.json +1 -3
  122. package/dist/localization/package.nls.zh-cn.json +2 -4
  123. package/dist/localization/package.nls.zh-tw.json +1 -3
  124. package/dist/parser/parser.js +4 -3
  125. package/dist/parser/parser.js.map +1 -1
  126. package/dist/parser/tokenizer.js +2 -2
  127. package/dist/parser/tokenizer.js.map +1 -1
  128. package/dist/parser/tokenizerTypes.d.ts +1 -0
  129. package/dist/parser/tokenizerTypes.js +4 -0
  130. package/dist/parser/tokenizerTypes.js.map +1 -1
  131. package/dist/pyright.js +1 -1
  132. package/dist/pyright.js.map +1 -1
  133. package/dist/tests/completions.test.js +2 -2
  134. package/dist/tests/completions.test.js.map +1 -1
  135. package/dist/tests/config.test.js +15 -3
  136. package/dist/tests/config.test.js.map +1 -1
  137. package/dist/tests/harness/fourslash/testState.js +2 -1
  138. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  139. package/dist/tests/harness/fourslash/testStateUtils.js +1 -1
  140. package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
  141. package/dist/tests/hoverProvider.test.js +17 -0
  142. package/dist/tests/hoverProvider.test.js.map +1 -1
  143. package/dist/tests/typeEvaluator1.test.js +8 -0
  144. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  145. package/dist/tests/typeEvaluator2.test.js +7 -3
  146. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  147. package/dist/tests/typeEvaluator3.test.js +4 -0
  148. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  149. package/dist/tests/typeEvaluator4.test.js +11 -3
  150. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  151. package/dist/tests/typeEvaluator6.test.js +1 -1
  152. package/dist/tests/typeEvaluator7.test.js +6 -6
  153. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  154. package/dist/tests/typeEvaluator8.test.js +4 -0
  155. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  156. package/package.json +1 -1
@@ -509,7 +509,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
509
509
  }
510
510
  }
511
511
  }
512
- function getTypeOfExpression(node, flags = 0 /* EvaluatorFlags.None */, inferenceContext) {
512
+ function getTypeOfExpression(node, flags = 0 /* EvaluatorFlags.None */, inferenceContext, signatureTracker) {
513
513
  // Is this type already cached?
514
514
  const cacheEntry = readTypeCacheEntry(node);
515
515
  if (cacheEntry &&
@@ -547,9 +547,55 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
547
547
  // needed in assignType, but we don't have access to the parse tree
548
548
  // at that point.
549
549
  initializedBasicTypes(node);
550
+ let typeResult = getTypeOfExpressionCore(node, flags, inferenceContext, signatureTracker);
551
+ // Should we disable type promotions for bytes?
552
+ if ((0, types_1.isInstantiableClass)(typeResult.type) &&
553
+ typeResult.type.includePromotions &&
554
+ !typeResult.type.includeSubclasses &&
555
+ types_1.ClassType.isBuiltIn(typeResult.type, 'bytes')) {
556
+ if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.disableBytesTypePromotions) {
557
+ typeResult = {
558
+ ...typeResult,
559
+ type: types_1.ClassType.cloneRemoveTypePromotions(typeResult.type),
560
+ };
561
+ }
562
+ }
563
+ // Don't allow speculative caching for assignment expressions because
564
+ // the target name node won't have a corresponding type cached speculatively.
565
+ const allowSpeculativeCaching = node.nodeType !== 4 /* ParseNodeType.AssignmentExpression */;
566
+ writeTypeCache(node, typeResult, flags, inferenceContext, allowSpeculativeCaching);
567
+ // If there was an expected type, make sure that the result type is compatible.
568
+ if (inferenceContext &&
569
+ !(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) &&
570
+ !(0, types_1.isNever)(inferenceContext.expectedType)) {
571
+ expectedTypeCache.set(node.id, inferenceContext.expectedType);
572
+ // If this is a generic function and there is a signature tracker,
573
+ // make sure the signature is unique.
574
+ if (signatureTracker && (0, types_1.isFunction)(typeResult.type)) {
575
+ typeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(typeResult.type, signatureTracker, node.start);
576
+ }
577
+ if (!typeResult.isIncomplete && !typeResult.expectedTypeDiagAddendum) {
578
+ const diag = new diagnostic_1.DiagnosticAddendum();
579
+ // Make sure the resulting type is assignable to the expected type.
580
+ if (!assignType(inferenceContext.expectedType, typeResult.type, diag,
581
+ /* destTypeVarContext */ undefined,
582
+ /* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */)) {
583
+ typeResult.typeErrors = true;
584
+ typeResult.expectedTypeDiagAddendum = diag;
585
+ diag.addTextRange(node);
586
+ }
587
+ }
588
+ }
589
+ if (printExpressionTypes) {
590
+ printExpressionSpaceCount--;
591
+ console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Post ${printType(typeResult.type)}${typeResult.isIncomplete ? ' Incomplete' : ''}`);
592
+ }
593
+ return typeResult;
594
+ }
595
+ // This is a helper function that implements the core of getTypeOfExpression.
596
+ function getTypeOfExpressionCore(node, flags = 0 /* EvaluatorFlags.None */, inferenceContext, signatureTracker) {
550
597
  let typeResult;
551
598
  let expectingInstantiable = (flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) !== 0;
552
- let allowSpeculativeCaching = true;
553
599
  switch (node.nodeType) {
554
600
  case 38 /* ParseNodeType.Name */: {
555
601
  typeResult = getTypeOfName(node, flags);
@@ -564,11 +610,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
564
610
  break;
565
611
  }
566
612
  case 9 /* ParseNodeType.Call */: {
567
- typeResult = getTypeOfCall(node, flags, inferenceContext);
613
+ typeResult = getTypeOfCall(node, flags, inferenceContext, signatureTracker);
568
614
  break;
569
615
  }
570
616
  case 52 /* ParseNodeType.Tuple */: {
571
- typeResult = getTypeOfTuple(node, flags, inferenceContext);
617
+ typeResult = getTypeOfTuple(node, flags, inferenceContext, signatureTracker);
572
618
  break;
573
619
  }
574
620
  case 11 /* ParseNodeType.Constant */: {
@@ -629,7 +675,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
629
675
  break;
630
676
  }
631
677
  case 32 /* ParseNodeType.ListComprehension */: {
632
- typeResult = getTypeOfListComprehension(node, inferenceContext);
678
+ typeResult = getTypeOfListComprehension(node, flags, inferenceContext);
633
679
  break;
634
680
  }
635
681
  case 15 /* ParseNodeType.Dictionary */: {
@@ -641,7 +687,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
641
687
  break;
642
688
  }
643
689
  case 3 /* ParseNodeType.Assignment */: {
644
- typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext);
690
+ typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext, signatureTracker);
645
691
  assignTypeToExpression(node.leftExpression, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
646
692
  /* ignoreEmptyContainers */ true,
647
693
  /* allowAssignmentToFinalVar */ true);
@@ -651,12 +697,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
651
697
  if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
652
698
  addError(localize_1.LocMessage.walrusNotAllowed(), node);
653
699
  }
654
- typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext);
700
+ typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext, signatureTracker);
655
701
  assignTypeToExpression(node.name, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
656
702
  /* ignoreEmptyContainers */ true);
657
- // Don't allow speculative caching for assignment expressions because
658
- // the target name node won't have a corresponding type cached speculatively.
659
- allowSpeculativeCaching = false;
660
703
  break;
661
704
  }
662
705
  case 60 /* ParseNodeType.Yield */: {
@@ -707,45 +750,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
707
750
  if (expectingInstantiable) {
708
751
  validateTypeIsInstantiable(typeResult, flags, node);
709
752
  }
710
- // Should we disable type promotions for bytes?
711
- if ((0, types_1.isInstantiableClass)(typeResult.type) &&
712
- typeResult.type.includePromotions &&
713
- !typeResult.type.includeSubclasses &&
714
- types_1.ClassType.isBuiltIn(typeResult.type, 'bytes')) {
715
- if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.disableBytesTypePromotions) {
716
- typeResult = {
717
- ...typeResult,
718
- type: types_1.ClassType.cloneRemoveTypePromotions(typeResult.type),
719
- };
720
- }
721
- }
722
- writeTypeCache(node, typeResult, flags, inferenceContext, allowSpeculativeCaching);
723
- // If there was an expected type, make sure that the result type is compatible.
724
- if (inferenceContext &&
725
- !(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) &&
726
- !(0, types_1.isNever)(inferenceContext.expectedType)) {
727
- expectedTypeCache.set(node.id, inferenceContext.expectedType);
728
- // If this is a generic function and there is a signature tracker,
729
- // make sure the signature is unique.
730
- if (inferenceContext.signatureTracker && (0, types_1.isFunction)(typeResult.type)) {
731
- typeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(typeResult.type, inferenceContext.signatureTracker, node.start);
732
- }
733
- if (!typeResult.isIncomplete && !typeResult.expectedTypeDiagAddendum) {
734
- const diag = new diagnostic_1.DiagnosticAddendum();
735
- // Make sure the resulting type is assignable to the expected type.
736
- if (!assignType(inferenceContext.expectedType, typeResult.type, diag,
737
- /* destTypeVarContext */ undefined,
738
- /* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */)) {
739
- typeResult.typeErrors = true;
740
- typeResult.expectedTypeDiagAddendum = diag;
741
- diag.addTextRange(node);
742
- }
743
- }
744
- }
745
- if (printExpressionTypes) {
746
- printExpressionSpaceCount--;
747
- console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Post ${printType(typeResult.type)}${typeResult.isIncomplete ? ' Incomplete' : ''}`);
748
- }
749
753
  return typeResult;
750
754
  }
751
755
  // Reports the case where a function or class has been decorated with
@@ -1536,7 +1540,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1536
1540
  let callResult;
1537
1541
  useSpeculativeMode(callNode, () => {
1538
1542
  callResult = validateFunctionArguments(exprNode, argList, { type }, new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type)),
1539
- /* skipUnknownArgCheck */ true);
1543
+ /* skipUnknownArgCheck */ true,
1544
+ /* inferenceContext */ undefined,
1545
+ /* signatureTracker */ undefined);
1540
1546
  });
1541
1547
  signatures.push({
1542
1548
  type: expandTypedKwargs(type),
@@ -2856,7 +2862,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2856
2862
  suppressDiagnostics(node.typeExpression, () => {
2857
2863
  callResult = (0, constructors_1.validateConstructorArguments)(evaluatorInterface, node.typeExpression, [], concreteSubtype,
2858
2864
  /* skipUnknownArgCheck */ false,
2859
- /* inferenceContext */ undefined);
2865
+ /* inferenceContext */ undefined,
2866
+ /* signatureTracker */ undefined);
2860
2867
  });
2861
2868
  if (callResult && callResult.argumentErrors) {
2862
2869
  diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeNotInstantiable().format({
@@ -3230,14 +3237,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3230
3237
  if (memberName === 'args' || memberName === 'kwargs') {
3231
3238
  const outerFunctionScope = ParseTreeUtils.getEnclosingClassOrFunction(enclosingScope);
3232
3239
  if ((outerFunctionScope === null || outerFunctionScope === void 0 ? void 0 : outerFunctionScope.nodeType) === 28 /* ParseNodeType.Function */) {
3233
- if (scopedTypeVarInfo.isRescoped) {
3234
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramSpecScopedToReturnType().format({
3235
- name: type.details.name,
3236
- }), node);
3237
- }
3238
- else {
3239
- enclosingScope = outerFunctionScope;
3240
- }
3240
+ enclosingScope = outerFunctionScope;
3241
3241
  }
3242
3242
  else if (!scopedTypeVarInfo.type.scopeId) {
3243
3243
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.paramSpecNotUsedByOuterScope().format({
@@ -3272,17 +3272,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3272
3272
  else if ((flags & 4096 /* EvaluatorFlags.AllowTypeVarsWithoutScopeId */) === 0) {
3273
3273
  if ((type.scopeId === undefined || scopedTypeVarInfo.foundInterveningClass) &&
3274
3274
  !type.details.isSynthesized) {
3275
- let message;
3276
- if (scopedTypeVarInfo.isRescoped) {
3277
- message = (0, types_1.isParamSpec)(type)
3278
- ? localize_1.LocMessage.paramSpecScopedToReturnType()
3279
- : localize_1.LocMessage.typeVarScopedToReturnType();
3280
- }
3281
- else {
3282
- message = (0, types_1.isParamSpec)(type)
3283
- ? localize_1.LocMessage.paramSpecNotUsedByOuterScope()
3284
- : localize_1.LocMessage.typeVarNotUsedByOuterScope();
3285
- }
3275
+ const message = (0, types_1.isParamSpec)(type)
3276
+ ? localize_1.LocMessage.paramSpecNotUsedByOuterScope()
3277
+ : localize_1.LocMessage.typeVarNotUsedByOuterScope();
3286
3278
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message.format({ name: type.details.name }), node);
3287
3279
  }
3288
3280
  }
@@ -3357,7 +3349,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3357
3349
  // Walks up the parse tree to find a function, class, or type alias
3358
3350
  // declaration that provides the context for a type variable.
3359
3351
  function findScopedTypeVar(node, type) {
3360
- var _a;
3361
3352
  let curNode = node;
3362
3353
  let nestedClassCount = 0;
3363
3354
  (0, debug_1.assert)(types_1.TypeBase.isInstantiable(type));
@@ -3381,12 +3372,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3381
3372
  if (functionType) {
3382
3373
  const functionDetails = functionType.details;
3383
3374
  typeParametersForScope = functionDetails.typeParameters;
3384
- // Was this type parameter "rescoped" to a callable found within the
3385
- // return type annotation? If so, it is not available for use within
3386
- // the function body.
3387
- if ((_a = functionDetails.rescopedTypeParameters) === null || _a === void 0 ? void 0 : _a.some((tp) => tp.details.name === type.details.name)) {
3388
- return { type, isRescoped: true, foundInterveningClass: false };
3389
- }
3390
3375
  }
3391
3376
  scopeUsesTypeParameterSyntax = !!curNode.typeParameters;
3392
3377
  }
@@ -3400,7 +3385,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3400
3385
  type = types_1.TypeVarType.cloneForScopeId(type, match.scopeId, match.scopeName, match.scopeType);
3401
3386
  return {
3402
3387
  type,
3403
- isRescoped: false,
3404
3388
  foundInterveningClass: nestedClassCount > 1 && !scopeUsesTypeParameterSyntax,
3405
3389
  };
3406
3390
  }
@@ -3441,13 +3425,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3441
3425
  if (allowedTypeParams) {
3442
3426
  if (!allowedTypeParams.some((param) => param.details.name === type.details.name)) {
3443
3427
  // Return the original type.
3444
- return { type, isRescoped: false, foundInterveningClass: false };
3428
+ return { type, foundInterveningClass: false };
3445
3429
  }
3446
3430
  }
3447
3431
  }
3448
3432
  return {
3449
3433
  type: types_1.TypeVarType.cloneForScopeId(type, leftType.details.recursiveTypeAliasScopeId, leftType.details.recursiveTypeAliasName, 2 /* TypeVarScopeType.TypeAlias */),
3450
- isRescoped: false,
3451
3434
  foundInterveningClass: false,
3452
3435
  };
3453
3436
  }
@@ -3455,7 +3438,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3455
3438
  curNode = curNode.parent;
3456
3439
  }
3457
3440
  // Return the original type.
3458
- return { type, isRescoped: false, foundInterveningClass: false };
3441
+ return { type, foundInterveningClass: false };
3459
3442
  }
3460
3443
  function getTypeOfMemberAccess(node, flags) {
3461
3444
  var _a;
@@ -3547,7 +3530,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3547
3530
  return typeResult;
3548
3531
  }
3549
3532
  function getTypeOfMemberAccessWithBaseType(node, baseTypeResult, usage, flags) {
3550
- var _a;
3533
+ var _a, _b;
3551
3534
  let baseType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(baseTypeResult.type);
3552
3535
  const memberName = node.memberName.value;
3553
3536
  let diag = new diagnostic_1.DiagnosticAddendum();
@@ -3632,8 +3615,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3632
3615
  }
3633
3616
  case 6 /* TypeCategory.Class */: {
3634
3617
  let typeResult;
3635
- if (usage.method === 'get') {
3636
- typeResult = (0, enums_1.getTypeOfEnumMember)(evaluatorInterface, node, baseType, memberName, isIncomplete);
3618
+ const enumMemberResult = (0, enums_1.getTypeOfEnumMember)(evaluatorInterface, node, baseType, memberName, isIncomplete);
3619
+ if (enumMemberResult) {
3620
+ if (usage.method === 'get') {
3621
+ typeResult = enumMemberResult;
3622
+ }
3623
+ else {
3624
+ // Is this an attempt to delete or overwrite an enum member?
3625
+ if ((0, types_1.isClassInstance)(enumMemberResult.type) &&
3626
+ types_1.ClassType.isSameGenericClass(enumMemberResult.type, baseType) &&
3627
+ enumMemberResult.type.literalValue !== undefined) {
3628
+ const diagMessage = usage.method === 'set' ? localize_1.LocMessage.enumMemberSet() : localize_1.LocMessage.enumMemberDelete();
3629
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue, diagMessage.format({ name: memberName }) + diag.getString(), node.memberName, (_a = diag.getEffectiveTextRange()) !== null && _a !== void 0 ? _a : node.memberName);
3630
+ }
3631
+ }
3637
3632
  }
3638
3633
  if (!typeResult) {
3639
3634
  typeResult = getTypeOfBoundMember(node.memberName, baseType, memberName, usage, diag,
@@ -3819,7 +3814,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3819
3814
  const rule = isFunctionRule
3820
3815
  ? diagnosticRules_1.DiagnosticRule.reportFunctionMemberAccess
3821
3816
  : diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue;
3822
- addDiagnostic(rule, diagMessage.format({ name: memberName, type: printType(baseType) }) + diag.getString(), node.memberName, (_a = diag.getEffectiveTextRange()) !== null && _a !== void 0 ? _a : node.memberName);
3817
+ addDiagnostic(rule, diagMessage.format({ name: memberName, type: printType(baseType) }) + diag.getString(), node.memberName, (_b = diag.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : node.memberName);
3823
3818
  }
3824
3819
  // If this is member access on a function, use "Any" so if the
3825
3820
  // reportFunctionMemberAccess rule is disabled, we don't trigger
@@ -4222,7 +4217,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4222
4217
  const callResult = suppressDiagnostics(errorNode, () => {
4223
4218
  return validateCallArguments(errorNode, argList, { type: methodType },
4224
4219
  /* typeVarContext */ undefined,
4225
- /* skipUnknownArgCheck */ true);
4220
+ /* skipUnknownArgCheck */ true,
4221
+ /* inferenceContext */ undefined,
4222
+ /* signatureTracker */ undefined);
4226
4223
  });
4227
4224
  // Collect deprecation information associated with the member access method.
4228
4225
  let deprecationInfo;
@@ -4419,7 +4416,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4419
4416
  }
4420
4417
  const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(accessMemberType));
4421
4418
  const callResult = validateCallArguments(errorNode, argList, { type: accessMemberType }, typeVarContext,
4422
- /* skipUnknownArgCheck */ true);
4419
+ /* skipUnknownArgCheck */ true,
4420
+ /* inferenceContext */ undefined,
4421
+ /* signatureTracker */ undefined);
4423
4422
  let isAsymmetricAccessor = false;
4424
4423
  if (usage.method === 'set') {
4425
4424
  isAsymmetricAccessor = isClassWithAsymmetricAttributeAccessor(classType);
@@ -5221,7 +5220,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5221
5220
  useSpeculativeMode(node, () => {
5222
5221
  callResult = validateCallArguments(node, argList, { type: itemMethodType },
5223
5222
  /* typeVarContext */ undefined,
5224
- /* skipUnknownArgCheck */ true);
5223
+ /* skipUnknownArgCheck */ true,
5224
+ /* inferenceContext */ undefined,
5225
+ /* signatureTracker */ undefined);
5225
5226
  if (callResult.argumentErrors) {
5226
5227
  // If the object supports "__index__" magic method, convert
5227
5228
  // the index to an int and try again.
@@ -5235,7 +5236,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5235
5236
  altArgList[0].typeResult = { type: intType };
5236
5237
  }
5237
5238
  }
5238
- callResult = validateCallArguments(node, altArgList, { type: itemMethodType });
5239
+ callResult = validateCallArguments(node, altArgList, { type: itemMethodType },
5240
+ /* typeVarContext */ undefined,
5241
+ /* skipUnknownArgCheck */ true,
5242
+ /* inferenceContext */ undefined,
5243
+ /* signatureTracker */ undefined);
5239
5244
  // We were successful, so replace the arg list.
5240
5245
  if (!callResult.argumentErrors) {
5241
5246
  argList = altArgList;
@@ -5246,7 +5251,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5246
5251
  }
5247
5252
  callResult = validateCallArguments(node, argList, { type: itemMethodType },
5248
5253
  /* typeVarContext */ undefined,
5249
- /* skipUnknownArgCheck */ true);
5254
+ /* skipUnknownArgCheck */ true,
5255
+ /* inferenceContext */ undefined,
5256
+ /* signatureTracker */ undefined);
5250
5257
  return {
5251
5258
  type: (_d = callResult.returnType) !== null && _d !== void 0 ? _d : types_1.UnknownType.create(),
5252
5259
  isIncomplete: !!callResult.isTypeIncomplete,
@@ -5279,19 +5286,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5279
5286
  const unboundedIndex = tupleTypeArgs.findIndex((typeArg) => typeArg.isUnbounded || (0, types_1.isVariadicTypeVar)(typeArg.type));
5280
5287
  if (value < 0) {
5281
5288
  value = tupleTypeArgs.length + value;
5282
- if (value < 0) {
5289
+ if (unboundedIndex >= 0 && value <= unboundedIndex) {
5283
5290
  return undefined;
5284
5291
  }
5285
- else if (unboundedIndex >= 0 && value <= unboundedIndex) {
5286
- return undefined;
5292
+ else if (value < 0) {
5293
+ return 0;
5287
5294
  }
5288
5295
  }
5289
5296
  else {
5290
- if (value > tupleTypeArgs.length) {
5297
+ if (unboundedIndex >= 0 && value > unboundedIndex) {
5291
5298
  return undefined;
5292
5299
  }
5293
- else if (unboundedIndex >= 0 && value > unboundedIndex) {
5294
- return undefined;
5300
+ else if (value > tupleTypeArgs.length) {
5301
+ return tupleTypeArgs.length;
5295
5302
  }
5296
5303
  }
5297
5304
  }
@@ -5300,9 +5307,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5300
5307
  function getTypeArgs(node, flags, options) {
5301
5308
  const typeArgs = [];
5302
5309
  let adjFlags = flags;
5303
- if ((options === null || options === void 0 ? void 0 : options.isFinalAnnotation) || (options === null || options === void 0 ? void 0 : options.isClassVarAnnotation)) {
5310
+ if (options === null || options === void 0 ? void 0 : options.isFinalAnnotation) {
5304
5311
  adjFlags |= 131072 /* EvaluatorFlags.DisallowClassVar */ | 16 /* EvaluatorFlags.DisallowFinal */;
5305
5312
  }
5313
+ else if (options === null || options === void 0 ? void 0 : options.isClassVarAnnotation) {
5314
+ adjFlags |= 131072 /* EvaluatorFlags.DisallowClassVar */;
5315
+ // If the annotation is a variable within the body of a dataclass, a
5316
+ // Final is allowed within the ClassVar annotation. In all other cases,
5317
+ // it's disallowed.
5318
+ let disallowFinal = true;
5319
+ const enclosingClassNode = ParseTreeUtils.getEnclosingClass(node, /* stopeAtFunction */ true);
5320
+ if (enclosingClassNode) {
5321
+ const classTypeInfo = getTypeOfClass(enclosingClassNode);
5322
+ if (classTypeInfo && types_1.ClassType.isDataClass(classTypeInfo.classType)) {
5323
+ disallowFinal = false;
5324
+ }
5325
+ }
5326
+ if (disallowFinal) {
5327
+ adjFlags |= 16 /* EvaluatorFlags.DisallowFinal */;
5328
+ }
5329
+ }
5306
5330
  else {
5307
5331
  adjFlags &= ~(2 /* EvaluatorFlags.DoNotSpecialize */ |
5308
5332
  32 /* EvaluatorFlags.DisallowParamSpec */ |
@@ -5437,7 +5461,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5437
5461
  }
5438
5462
  return typeResult;
5439
5463
  }
5440
- function getTypeOfTuple(node, flags, inferenceContext) {
5464
+ function getTypeOfTuple(node, flags, inferenceContext, signatureTracker) {
5441
5465
  var _a;
5442
5466
  if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0 &&
5443
5467
  ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
@@ -5454,6 +5478,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5454
5478
  !inferenceContext) {
5455
5479
  return { type: makeTupleObject([]), isEmptyTupleShorthand: true };
5456
5480
  }
5481
+ flags &= ~(256 /* EvaluatorFlags.ExpectingTypeAnnotation */ |
5482
+ 8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
5483
+ 128 /* EvaluatorFlags.ExpectingInstantiableType */);
5457
5484
  // If the expected type is a union, recursively call for each of the subtypes
5458
5485
  // to find one that matches.
5459
5486
  let effectiveExpectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
@@ -5466,7 +5493,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5466
5493
  }
5467
5494
  if (!matchingSubtype) {
5468
5495
  const subtypeResult = useSpeculativeMode(node, () => {
5469
- return getTypeOfTupleWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype));
5496
+ return getTypeOfTupleWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(subtype),
5497
+ /* signatureTracker */ undefined);
5470
5498
  });
5471
5499
  if (subtypeResult && assignType(subtype, subtypeResult.type)) {
5472
5500
  matchingSubtype = subtype;
@@ -5478,14 +5506,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5478
5506
  }
5479
5507
  let expectedTypeDiagAddendum;
5480
5508
  if (effectiveExpectedType) {
5481
- const result = getTypeOfTupleWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType,
5482
- /* isTypeIncomplete */ false, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.signatureTracker));
5509
+ const result = getTypeOfTupleWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType), signatureTracker);
5483
5510
  if (result && !result.typeErrors) {
5484
5511
  return result;
5485
5512
  }
5486
5513
  expectedTypeDiagAddendum = result === null || result === void 0 ? void 0 : result.expectedTypeDiagAddendum;
5487
5514
  }
5488
- const typeResult = getTypeOfTupleInferred(node);
5515
+ const typeResult = getTypeOfTupleInferred(node, flags);
5489
5516
  // If there was an expected type of Any, replace the resulting type
5490
5517
  // with Any rather than return a type with unknowns.
5491
5518
  if (expectedTypeContainsAny) {
@@ -5493,7 +5520,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5493
5520
  }
5494
5521
  return { ...typeResult, expectedTypeDiagAddendum };
5495
5522
  }
5496
- function getTypeOfTupleWithContext(node, inferenceContext) {
5523
+ function getTypeOfTupleWithContext(node, flags, inferenceContext, signatureTracker) {
5497
5524
  inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
5498
5525
  if (!(0, types_1.isClassInstance)(inferenceContext.expectedType)) {
5499
5526
  return undefined;
@@ -5531,10 +5558,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5531
5558
  expectedTypes.push(homogenousType);
5532
5559
  }
5533
5560
  }
5534
- const entryTypeResults = node.expressions.map((expr, index) => getTypeOfExpression(expr,
5535
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(index < expectedTypes.length ? expectedTypes[index] : undefined, inferenceContext.isTypeIncomplete, inferenceContext.signatureTracker)));
5561
+ const entryTypeResults = node.expressions.map((expr, index) => getTypeOfExpression(expr, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(index < expectedTypes.length ? expectedTypes[index] : undefined, inferenceContext.isTypeIncomplete), signatureTracker));
5536
5562
  const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
5537
- const type = makeTupleObject(buildTupleTypesList(entryTypeResults));
5563
+ const type = makeTupleObject(buildTupleTypesList(entryTypeResults, /* stripLiterals */ false));
5538
5564
  // Copy any expected type diag addenda for precision error reporting.
5539
5565
  let expectedTypeDiagAddendum;
5540
5566
  if (entryTypeResults.some((result) => result.expectedTypeDiagAddendum)) {
@@ -5547,10 +5573,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5547
5573
  }
5548
5574
  return { type, expectedTypeDiagAddendum, isIncomplete };
5549
5575
  }
5550
- function getTypeOfTupleInferred(node) {
5551
- const entryTypeResults = node.expressions.map((expr) => getTypeOfExpression(expr));
5576
+ function getTypeOfTupleInferred(node, flags) {
5577
+ const entryTypeResults = node.expressions.map((expr) => getTypeOfExpression(expr, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */));
5552
5578
  const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
5553
- const type = makeTupleObject(buildTupleTypesList(entryTypeResults));
5579
+ const type = makeTupleObject(buildTupleTypesList(entryTypeResults, (flags & 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */) !== 0));
5554
5580
  if (isIncomplete) {
5555
5581
  if ((0, typeUtils_1.getContainerDepth)(type) > maxInferredContainerDepth) {
5556
5582
  return { type: types_1.UnknownType.create() };
@@ -5558,7 +5584,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5558
5584
  }
5559
5585
  return { type, isIncomplete };
5560
5586
  }
5561
- function buildTupleTypesList(entryTypeResults) {
5587
+ function buildTupleTypesList(entryTypeResults, stripLiterals) {
5562
5588
  const entryTypes = [];
5563
5589
  for (const typeResult of entryTypeResults) {
5564
5590
  let possibleUnpackedTuple;
@@ -5587,7 +5613,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5587
5613
  entryTypes.push({ type: types_1.UnknownType.create(/* isIncomplete */ true), isUnbounded: false });
5588
5614
  }
5589
5615
  else {
5590
- entryTypes.push({ type: typeResult.type, isUnbounded: !!typeResult.unpackedType });
5616
+ const entryType = stripLiterals ? stripLiteralValue(typeResult.type) : typeResult.type;
5617
+ entryTypes.push({ type: entryType, isUnbounded: !!typeResult.unpackedType });
5591
5618
  }
5592
5619
  }
5593
5620
  // If there are multiple unbounded entries, combine all of them into a single
@@ -5600,7 +5627,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5600
5627
  }
5601
5628
  return entryTypes;
5602
5629
  }
5603
- function getTypeOfCall(node, flags, inferenceContext) {
5630
+ function getTypeOfCall(node, flags, inferenceContext, signatureTracker) {
5604
5631
  var _a;
5605
5632
  let baseTypeResult;
5606
5633
  // Check for the use of `type(x)` within a type annotation. This isn't
@@ -5633,8 +5660,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5633
5660
  // If the inference context has an associated signature tracker, make sure
5634
5661
  // the base type of this call is not the same as one of the tracked signatures.
5635
5662
  // This is important for nested generic calls (e.g. "foo(foo(x))").
5636
- if (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.signatureTracker) {
5637
- baseTypeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(baseTypeResult.type, inferenceContext.signatureTracker, node.leftExpression.start);
5663
+ if (signatureTracker) {
5664
+ baseTypeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(baseTypeResult.type, signatureTracker, node.leftExpression.start);
5638
5665
  }
5639
5666
  if (!(0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
5640
5667
  if (node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ && node.leftExpression.value === 'super') {
@@ -5645,15 +5672,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5645
5672
  node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
5646
5673
  node.leftExpression.value === 'reveal_type') {
5647
5674
  // Handle the implicit "reveal_type" call.
5648
- typeResult = getTypeOfRevealType(node, inferenceContext);
5675
+ typeResult = getTypeOfRevealType(node, inferenceContext, signatureTracker);
5649
5676
  }
5650
5677
  else if ((0, types_1.isFunction)(baseTypeResult.type) && baseTypeResult.type.details.builtInName === 'reveal_type') {
5651
5678
  // Handle the "typing.reveal_type" call.
5652
- typeResult = getTypeOfRevealType(node, inferenceContext);
5679
+ typeResult = getTypeOfRevealType(node, inferenceContext, signatureTracker);
5653
5680
  }
5654
5681
  else if ((0, types_1.isFunction)(baseTypeResult.type) && baseTypeResult.type.details.builtInName === 'assert_type') {
5655
5682
  // Handle the "typing.assert_type" call.
5656
- typeResult = getTypeOfAssertType(node, inferenceContext);
5683
+ typeResult = getTypeOfAssertType(node, inferenceContext, signatureTracker);
5657
5684
  }
5658
5685
  else if ((0, types_1.isAnyOrUnknown)(baseTypeResult.type) &&
5659
5686
  node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
@@ -5669,7 +5696,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5669
5696
  else {
5670
5697
  const callResult = validateCallArguments(node, argList, baseTypeResult,
5671
5698
  /* typeVarContext */ undefined,
5672
- /* skipUnknownArgCheck */ false, inferenceContext);
5699
+ /* skipUnknownArgCheck */ false, inferenceContext, signatureTracker);
5673
5700
  typeResult.type = (_a = callResult.returnType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
5674
5701
  if (callResult.argumentErrors) {
5675
5702
  typeResult.typeErrors = true;
@@ -5763,7 +5790,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5763
5790
  }
5764
5791
  return typeResult;
5765
5792
  }
5766
- function getTypeOfAssertType(node, inferenceContext) {
5793
+ function getTypeOfAssertType(node, inferenceContext, signatureTracker) {
5767
5794
  if (node.arguments.length !== 2 ||
5768
5795
  node.arguments[0].argumentCategory !== 0 /* ArgumentCategory.Simple */ ||
5769
5796
  node.arguments[0].name !== undefined ||
@@ -5773,7 +5800,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5773
5800
  return { type: types_1.UnknownType.create() };
5774
5801
  }
5775
5802
  const arg0TypeResult = getTypeOfExpression(node.arguments[0].valueExpression,
5776
- /* flags */ undefined, inferenceContext);
5803
+ /* flags */ undefined, inferenceContext, signatureTracker);
5777
5804
  if (arg0TypeResult.isIncomplete) {
5778
5805
  return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
5779
5806
  }
@@ -5787,7 +5814,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5787
5814
  }
5788
5815
  return { type: arg0TypeResult.type };
5789
5816
  }
5790
- function getTypeOfRevealType(node, inferenceContext) {
5817
+ function getTypeOfRevealType(node, inferenceContext, signatureTracker) {
5791
5818
  let arg0Value;
5792
5819
  let expectedRevealTypeNode;
5793
5820
  let expectedRevealType;
@@ -5824,7 +5851,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5824
5851
  addError(localize_1.LocMessage.revealTypeArgs(), node);
5825
5852
  return { type: types_1.UnknownType.create() };
5826
5853
  }
5827
- const typeResult = getTypeOfExpression(arg0Value, /* flags */ undefined, inferenceContext);
5854
+ const typeResult = getTypeOfExpression(arg0Value, /* flags */ undefined, inferenceContext, signatureTracker);
5828
5855
  const type = typeResult.type;
5829
5856
  const exprString = ParseTreeUtils.printExpression(arg0Value);
5830
5857
  const typeString = printType(type, { expandTypeAlias: true });
@@ -5894,7 +5921,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5894
5921
  if (node.arguments.length > 0) {
5895
5922
  targetClassType = getTypeOfExpression(node.arguments[0].valueExpression).type;
5896
5923
  const concreteTargetClassType = makeTopLevelTypeVarsConcrete(targetClassType);
5897
- if (!(0, types_1.isAnyOrUnknown)(concreteTargetClassType) && !(0, types_1.isInstantiableClass)(concreteTargetClassType)) {
5924
+ if (!(0, types_1.isAnyOrUnknown)(concreteTargetClassType) &&
5925
+ !(0, types_1.isInstantiableClass)(concreteTargetClassType) &&
5926
+ !(0, typeUtils_1.isMetaclassInstance)(concreteTargetClassType)) {
5898
5927
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportArgumentType, localize_1.LocMessage.superCallFirstArg().format({ type: printType(targetClassType) }), node.arguments[0].valueExpression);
5899
5928
  }
5900
5929
  }
@@ -6105,7 +6134,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6105
6134
  // there will be only one argument list in expandedArgTypes, and all entries
6106
6135
  // (one for each argument) will be undefined. On subsequent calls, this
6107
6136
  // list will grow to include union expansions.
6108
- function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, inferenceContext) {
6137
+ function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker) {
6109
6138
  var _a, _b;
6110
6139
  const returnTypes = [];
6111
6140
  const matchedOverloads = [];
@@ -6141,7 +6170,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6141
6170
  // record any final types in the type cache.
6142
6171
  const callResult = useSpeculativeMode(errorNode, () => {
6143
6172
  return validateFunctionArgumentTypesWithContext(errorNode, matchResults, effectiveTypeVarContext,
6144
- /* skipUnknownArgCheck */ true, inferenceContext);
6173
+ /* skipUnknownArgCheck */ true, inferenceContext, signatureTracker);
6145
6174
  });
6146
6175
  if (callResult.isTypeIncomplete) {
6147
6176
  isTypeIncomplete = true;
@@ -6250,7 +6279,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6250
6279
  const finalTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : matchedOverloads[0].typeVarContext;
6251
6280
  finalTypeVarContext.unlock();
6252
6281
  finalTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(matchedOverloads[0].overload));
6253
- const finalCallResult = validateFunctionArgumentTypesWithContext(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck, inferenceContext);
6282
+ const finalCallResult = validateFunctionArgumentTypesWithContext(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6254
6283
  if (finalCallResult.isTypeIncomplete) {
6255
6284
  isTypeIncomplete = true;
6256
6285
  }
@@ -6316,7 +6345,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6316
6345
  // Create a list of potential overload matches based on arguments.
6317
6346
  types_1.OverloadedFunctionType.getOverloads(typeResult.type).forEach((overload) => {
6318
6347
  useSpeculativeMode(errorNode, () => {
6319
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
6348
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex,
6349
+ /* signatureTracker */ undefined);
6320
6350
  if (!matchResults.argumentErrors) {
6321
6351
  matches.push(matchResults);
6322
6352
  }
@@ -6347,7 +6377,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6347
6377
  return a.overloadIndex - b.overloadIndex;
6348
6378
  });
6349
6379
  }
6350
- function validateOverloadedFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck, inferenceContext) {
6380
+ function validateOverloadedFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker) {
6351
6381
  let filteredMatchResults = [];
6352
6382
  let contextFreeArgTypes;
6353
6383
  let isTypeIncomplete = !!typeResult.isIncomplete;
@@ -6362,7 +6392,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6362
6392
  // Consider only the functions that have the @overload decorator,
6363
6393
  // not the final function that omits the overload. This is the
6364
6394
  // intended behavior according to PEP 484.
6365
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
6395
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex, signatureTracker);
6366
6396
  if (!matchResults.argumentErrors) {
6367
6397
  filteredMatchResults.push(matchResults);
6368
6398
  }
@@ -6379,7 +6409,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6379
6409
  const functionName = typeResult.type.overloads[0].details.name || '<anonymous function>';
6380
6410
  const diagAddendum = new diagnostic_1.DiagnosticAddendum();
6381
6411
  const argTypes = argList.map((t) => {
6382
- const typeString = printType(getTypeOfArgument(t).type);
6412
+ const typeString = printType(getTypeOfArgument(t, /* inferenceContext */ undefined, signatureTracker).type);
6383
6413
  if (t.argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
6384
6414
  return `*${typeString}`;
6385
6415
  }
@@ -6418,7 +6448,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6418
6448
  const effectiveTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : new typeVarContext_1.TypeVarContext();
6419
6449
  effectiveTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeIds)(bestMatch.overload));
6420
6450
  effectiveTypeVarContext.unlock();
6421
- return validateFunctionArgumentTypesWithContext(errorNode, bestMatch, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
6451
+ return validateFunctionArgumentTypesWithContext(errorNode, bestMatch, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6422
6452
  }
6423
6453
  // If there is only one possible arg/param match among the overloads,
6424
6454
  // use the normal type matching mechanism because it is faster and
@@ -6430,7 +6460,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6430
6460
  }
6431
6461
  let expandedArgTypes = [argList.map((arg) => undefined)];
6432
6462
  while (true) {
6433
- const callResult = validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, filteredMatchResults, typeVarContext, skipUnknownArgCheck, inferenceContext);
6463
+ const callResult = validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, filteredMatchResults, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6434
6464
  if (callResult.isTypeIncomplete) {
6435
6465
  isTypeIncomplete = true;
6436
6466
  }
@@ -6528,7 +6558,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6528
6558
  // list, specializes the call based on arg types, and returns the
6529
6559
  // specialized type of the return value. If it detects an error along
6530
6560
  // the way, it emits a diagnostic and sets argumentErrors to true.
6531
- function validateCallArguments(errorNode, argList, callTypeResult, typeVarContext, skipUnknownArgCheck = false, inferenceContext, recursionCount = 0) {
6561
+ function validateCallArguments(errorNode, argList, callTypeResult, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount = 0) {
6532
6562
  let argumentErrors = false;
6533
6563
  let isTypeIncomplete = false;
6534
6564
  let specializedInitSelfType;
@@ -6547,7 +6577,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6547
6577
  }
6548
6578
  let returnType = mapSubtypesExpandTypeVars(callTypeResult.type, { sortSubtypes: true }, (expandedSubtype, unexpandedSubtype, isLastIteration) => {
6549
6579
  return useSpeculativeMode(isLastIteration ? undefined : errorNode, () => {
6550
- const callResult = validateCallArgumentsForSubtype(errorNode, argList, expandedSubtype, unexpandedSubtype, !!callTypeResult.isIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
6580
+ const callResult = validateCallArgumentsForSubtype(errorNode, argList, expandedSubtype, unexpandedSubtype, !!callTypeResult.isIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount);
6551
6581
  if (callResult.argumentErrors) {
6552
6582
  argumentErrors = true;
6553
6583
  }
@@ -6577,7 +6607,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6577
6607
  overloadsUsedForCall,
6578
6608
  };
6579
6609
  }
6580
- function validateCallArgumentsForSubtype(errorNode, argList, expandedCallType, unexpandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount) {
6610
+ function validateCallArgumentsForSubtype(errorNode, argList, expandedCallType, unexpandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount) {
6581
6611
  switch (expandedCallType.category) {
6582
6612
  case 3 /* TypeCategory.Never */:
6583
6613
  case 1 /* TypeCategory.Unknown */:
@@ -6588,17 +6618,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6588
6618
  if (!isCallTypeIncomplete) {
6589
6619
  argList.forEach((arg) => {
6590
6620
  if (arg.valueExpression && !isSpeculativeModeInUse(arg.valueExpression)) {
6591
- getTypeOfArgument(arg);
6621
+ getTypeOfArgument(arg, /* inferenceContext */ undefined, signatureTracker);
6592
6622
  }
6593
6623
  });
6594
6624
  }
6595
6625
  return { returnType: expandedCallType };
6596
6626
  }
6597
6627
  case 4 /* TypeCategory.Function */: {
6598
- return validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext);
6628
+ return validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6599
6629
  }
6600
6630
  case 5 /* TypeCategory.OverloadedFunction */: {
6601
- return validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext);
6631
+ return validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6602
6632
  }
6603
6633
  case 6 /* TypeCategory.Class */: {
6604
6634
  if ((0, typeUtils_1.isNoneInstance)(expandedCallType)) {
@@ -6606,16 +6636,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6606
6636
  return { argumentErrors: true };
6607
6637
  }
6608
6638
  if (types_1.TypeBase.isInstantiable(expandedCallType)) {
6609
- return validateCallForInstantiableClass(errorNode, argList, expandedCallType, unexpandedCallType, skipUnknownArgCheck, inferenceContext);
6639
+ return validateCallForInstantiableClass(errorNode, argList, expandedCallType, unexpandedCallType, skipUnknownArgCheck, inferenceContext, signatureTracker);
6610
6640
  }
6611
- return validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
6641
+ return validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount);
6612
6642
  }
6613
6643
  // TypeVars should have been expanded in most cases,
6614
6644
  // but we still need to handle the case of Type[T] where
6615
6645
  // T is a constrained type that contains a union. We also
6616
6646
  // need to handle recursive type aliases.
6617
6647
  case 9 /* TypeCategory.TypeVar */: {
6618
- return validateCallArguments(errorNode, argList, { type: (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expandedCallType), isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
6648
+ return validateCallArguments(errorNode, argList, { type: (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expandedCallType), isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount);
6619
6649
  }
6620
6650
  case 7 /* TypeCategory.Module */: {
6621
6651
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.moduleNotCallable(), errorNode);
@@ -6624,7 +6654,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6624
6654
  }
6625
6655
  return { argumentErrors: true };
6626
6656
  }
6627
- function validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext) {
6657
+ function validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker) {
6628
6658
  var _a;
6629
6659
  if (types_1.TypeBase.isInstantiable(expandedCallType)) {
6630
6660
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.callableNotInstantiable().format({
@@ -6644,14 +6674,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6644
6674
  const result = {
6645
6675
  returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList, /* includesTypes */ false),
6646
6676
  };
6647
- validateFunctionArguments(errorNode, argList, { type: expandedCallType }, effectiveTypeVarContext, skipUnknownArgCheck);
6677
+ validateFunctionArguments(errorNode, argList, { type: expandedCallType }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6648
6678
  return result;
6649
6679
  }
6650
6680
  // Handle the NewType specially, replacing the normal return type.
6651
6681
  if (expandedCallType.details.builtInName === 'NewType') {
6652
6682
  return { returnType: createNewType(errorNode, argList) };
6653
6683
  }
6654
- const functionResult = validateFunctionArguments(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
6684
+ const functionResult = validateFunctionArguments(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6655
6685
  let isTypeIncomplete = !!functionResult.isTypeIncomplete;
6656
6686
  let returnType = functionResult.returnType;
6657
6687
  let argumentErrors = !!functionResult.argumentErrors;
@@ -6758,13 +6788,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6758
6788
  }
6759
6789
  return { symbol, symbolName, classType, hasImplementation };
6760
6790
  }
6761
- function validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext) {
6791
+ function validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker) {
6762
6792
  var _a, _b;
6763
6793
  // Handle the 'cast' call as a special case.
6764
6794
  if (expandedCallType.overloads[0].details.builtInName === 'cast' && argList.length === 2) {
6765
6795
  return { returnType: evaluateCastCall(argList, errorNode) };
6766
6796
  }
6767
- const callResult = validateOverloadedFunctionArguments(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext);
6797
+ const callResult = validateOverloadedFunctionArguments(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6768
6798
  let returnType = (_a = callResult.returnType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
6769
6799
  let isTypeIncomplete = !!callResult.isTypeIncomplete;
6770
6800
  let argumentErrors = !!callResult.argumentErrors;
@@ -6791,7 +6821,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6791
6821
  specializedInitSelfType: callResult.specializedInitSelfType,
6792
6822
  };
6793
6823
  }
6794
- function validateCallForInstantiableClass(errorNode, argList, expandedCallType, unexpandedCallType, skipUnknownArgCheck, inferenceContext) {
6824
+ function validateCallForInstantiableClass(errorNode, argList, expandedCallType, unexpandedCallType, skipUnknownArgCheck, inferenceContext, signatureTracker) {
6795
6825
  var _a, _b;
6796
6826
  if (expandedCallType.literalValue !== undefined) {
6797
6827
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.literalNotCallable(), errorNode);
@@ -6808,25 +6838,29 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6808
6838
  return { returnType: types_1.UnknownType.create(), argumentErrors: true };
6809
6839
  }
6810
6840
  // Validate the constructor arguments.
6811
- (0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedCallType, skipUnknownArgCheck, inferenceContext);
6841
+ (0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedCallType, skipUnknownArgCheck, inferenceContext, signatureTracker);
6812
6842
  // The one-parameter form of "type" returns the class
6813
6843
  // for the specified object.
6814
6844
  if (expandedCallType.details.name === 'type' && argList.length === 1) {
6815
- const argType = getTypeOfArgument(argList[0]).type;
6845
+ const argType = getTypeOfArgument(argList[0],
6846
+ /* inferenceContext */ undefined, signatureTracker).type;
6816
6847
  const returnType = (0, typeUtils_1.mapSubtypes)(argType, (subtype) => {
6817
- var _a;
6818
- if ((0, types_1.isInstantiableClass)(subtype)) {
6819
- return (_a = subtype.details.effectiveMetaclass) !== null && _a !== void 0 ? _a : types_1.AnyType.create();
6848
+ if ((0, types_1.isInstantiableClass)(subtype) && subtype.details.effectiveMetaclass) {
6849
+ return subtype.details.effectiveMetaclass;
6820
6850
  }
6821
- if ((0, types_1.isClassInstance)(subtype) ||
6822
- ((0, types_1.isTypeVar)(subtype) && types_1.TypeBase.isInstance(subtype)) ||
6823
- (0, typeUtils_1.isNoneInstance)(subtype)) {
6824
- return (0, typeUtils_1.convertToInstantiable)(stripLiteralValue(subtype));
6851
+ if ((0, types_1.isNever)(subtype)) {
6852
+ return subtype;
6825
6853
  }
6826
- if ((0, types_1.isFunction)(subtype) && types_1.TypeBase.isInstance(subtype)) {
6827
- return types_1.FunctionType.cloneAsInstantiable(subtype);
6854
+ if (types_1.TypeBase.isInstance(subtype)) {
6855
+ if ((0, types_1.isClass)(subtype) || (0, types_1.isTypeVar)(subtype)) {
6856
+ return (0, typeUtils_1.convertToInstantiable)(stripLiteralValue(subtype));
6857
+ }
6858
+ if ((0, types_1.isFunction)(subtype)) {
6859
+ return types_1.FunctionType.cloneAsInstantiable(subtype);
6860
+ }
6828
6861
  }
6829
- return types_1.AnyType.create();
6862
+ return types_1.ClassType.cloneForSpecialization(types_1.ClassType.cloneAsInstance(expandedCallType), [types_1.UnknownType.create()],
6863
+ /* isTypeArgumentExplicit */ true);
6830
6864
  });
6831
6865
  return { returnType };
6832
6866
  }
@@ -6871,7 +6905,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6871
6905
  if (initTypeResult && (0, types_1.isOverloadedFunction)(initTypeResult.type)) {
6872
6906
  validateOverloadedFunctionArguments(errorNode, argList, { type: initTypeResult.type },
6873
6907
  /* typeVarContext */ undefined, skipUnknownArgCheck,
6874
- /* inferenceContext */ undefined);
6908
+ /* inferenceContext */ undefined, signatureTracker);
6875
6909
  }
6876
6910
  return result;
6877
6911
  }
@@ -6933,7 +6967,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6933
6967
  }), errorNode);
6934
6968
  }
6935
6969
  // Assume this is a call to the constructor.
6936
- const constructorResult = (0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedCallType, skipUnknownArgCheck, inferenceContext);
6970
+ const constructorResult = (0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedCallType, skipUnknownArgCheck, inferenceContext, signatureTracker);
6937
6971
  const overloadsUsedForCall = constructorResult.overloadsUsedForCall;
6938
6972
  const argumentErrors = constructorResult.argumentErrors;
6939
6973
  const isTypeIncomplete = constructorResult.isTypeIncomplete;
@@ -6952,7 +6986,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6952
6986
  returnType.details.mro.some((baseClass) => (0, types_1.isInstantiableClass)(baseClass) && types_1.ClassType.isBuiltIn(baseClass, 'type'))) {
6953
6987
  let newClassName = '__class_' + returnType.details.name;
6954
6988
  if (argList.length === 3) {
6955
- const firstArgType = getTypeOfArgument(argList[0]).type;
6989
+ const firstArgType = getTypeOfArgument(argList[0],
6990
+ /* inferenceContext */ undefined, signatureTracker).type;
6956
6991
  if ((0, types_1.isClassInstance)(firstArgType) &&
6957
6992
  types_1.ClassType.isBuiltIn(firstArgType, 'str') &&
6958
6993
  typeof firstArgType.literalValue === 'string') {
@@ -6968,7 +7003,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6968
7003
  }
6969
7004
  return { returnType, overloadsUsedForCall, argumentErrors, isTypeIncomplete };
6970
7005
  }
6971
- function validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount) {
7006
+ function validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount) {
6972
7007
  var _a;
6973
7008
  const callDiag = new diagnostic_1.DiagnosticAddendum();
6974
7009
  const callMethodResult = getTypeOfBoundMember(errorNode, expandedCallType, '__call__',
@@ -6981,7 +7016,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6981
7016
  }) + callDiag.getString(), errorNode);
6982
7017
  return { returnType: types_1.UnknownType.create(), argumentErrors: true };
6983
7018
  }
6984
- const callResult = validateCallArguments(errorNode, argList, { type: callMethodType }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
7019
+ const callResult = validateCallArguments(errorNode, argList, { type: callMethodType }, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount);
6985
7020
  let returnType = (_a = callResult.returnType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
6986
7021
  if ((0, types_1.isTypeVar)(unexpandedCallType) &&
6987
7022
  types_1.TypeBase.isInstantiable(unexpandedCallType) &&
@@ -7001,7 +7036,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7001
7036
  function evaluateCastCall(argList, errorNode) {
7002
7037
  // Verify that the cast is necessary.
7003
7038
  const castToType = getTypeOfArgumentExpectingType(argList[0], { enforceTypeAnnotationRules: true }).type;
7004
- let castFromType = getTypeOfArgument(argList[1]).type;
7039
+ let castFromType = getTypeOfArgument(argList[1],
7040
+ /* inferenceContext */ undefined,
7041
+ /* signatureTracker */ undefined).type;
7005
7042
  if (castFromType.specialForm) {
7006
7043
  castFromType = castFromType.specialForm;
7007
7044
  }
@@ -7017,12 +7054,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7017
7054
  return (0, typeUtils_1.convertToInstance)(castToType);
7018
7055
  }
7019
7056
  // Expands any unpacked tuples within an argument list.
7020
- function expandArgList(argList) {
7057
+ function expandArgList(argList, signatureTracker) {
7021
7058
  var _a;
7022
7059
  const expandedArgList = [];
7023
7060
  for (const arg of argList) {
7024
7061
  if (arg.argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
7025
- const argType = getTypeOfArgument(arg).type;
7062
+ const argType = getTypeOfArgument(arg, /* inferenceContext */ undefined, signatureTracker).type;
7026
7063
  // If this is a tuple with specified element types, use those
7027
7064
  // specified types rather than using the more generic iterator
7028
7065
  // type which will be a union of all element types.
@@ -7064,7 +7101,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7064
7101
  // function. This matching is done based on positions and keywords. Type evaluation and
7065
7102
  // validation is left to the caller.
7066
7103
  // This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
7067
- function matchFunctionArgumentsToParameters(errorNode, argList, typeResult, overloadIndex) {
7104
+ function matchFunctionArgumentsToParameters(errorNode, argList, typeResult, overloadIndex, signatureTracker) {
7068
7105
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
7069
7106
  const paramDetails = (0, parameterUtils_1.getParameterListDetails)(typeResult.type);
7070
7107
  let argIndex = 0;
@@ -7073,7 +7110,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7073
7110
  let isTypeIncomplete = !!typeResult.isIncomplete;
7074
7111
  let isVariadicTypeVarFullyMatched = false;
7075
7112
  // Expand any unpacked tuples in the arg list.
7076
- argList = expandArgList(argList);
7113
+ argList = expandArgList(argList, signatureTracker);
7077
7114
  // Build a map of parameters by name.
7078
7115
  const paramMap = new Map();
7079
7116
  paramDetails.params.forEach((paramInfo) => {
@@ -7083,7 +7120,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7083
7120
  paramMap.set(param.name, {
7084
7121
  argsNeeded: param.category === 0 /* ParameterCategory.Simple */ && !param.hasDefault ? 1 : 0,
7085
7122
  argsReceived: 0,
7086
- isPositionalOnly: paramInfo.source === parameterUtils_1.ParameterSource.PositionOnly,
7123
+ isPositionalOnly: paramInfo.kind === parameterUtils_1.ParameterKind.Positional,
7087
7124
  });
7088
7125
  }
7089
7126
  });
@@ -7197,7 +7234,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7197
7234
  // If this is an unpacked iterable, we will conservatively assume that it
7198
7235
  // might have zero iterations unless we can tell from its type that it
7199
7236
  // definitely has at least one iterable value.
7200
- const argType = getTypeOfArgument(argList[argIndex]).type;
7237
+ const argType = getTypeOfArgument(argList[argIndex],
7238
+ /* inferenceContext */ undefined, signatureTracker).type;
7201
7239
  if ((0, types_1.isClassInstance)(argType) &&
7202
7240
  (0, typeUtils_1.isTupleClass)(argType) &&
7203
7241
  !(0, typeUtils_1.isUnboundedTupleClass)(argType) &&
@@ -7232,7 +7270,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7232
7270
  (0, types_1.isVariadicTypeVar)(paramType);
7233
7271
  if (argList[argIndex].argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
7234
7272
  let isArgCompatibleWithVariadic = false;
7235
- const argTypeResult = getTypeOfArgument(argList[argIndex]);
7273
+ const argTypeResult = getTypeOfArgument(argList[argIndex],
7274
+ /* inferenceContext */ undefined, signatureTracker);
7236
7275
  let listElementType;
7237
7276
  let advanceToNextArg = false;
7238
7277
  // Handle the case where *args is being passed to a function defined
@@ -7467,7 +7506,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7467
7506
  while (argIndex < argList.length) {
7468
7507
  if (argList[argIndex].argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */) {
7469
7508
  // Verify that the type used in this expression is a SupportsKeysAndGetItem[str, T].
7470
- const argType = getTypeOfArgument(argList[argIndex], (0, typeUtils_1.makeInferenceContext)(paramDetails.unpackedKwargsTypedDictType)).type;
7509
+ const argType = getTypeOfArgument(argList[argIndex], (0, typeUtils_1.makeInferenceContext)(paramDetails.unpackedKwargsTypedDictType), signatureTracker).type;
7471
7510
  if ((0, types_1.isAnyOrUnknown)(argType)) {
7472
7511
  unpackedDictionaryArgType = argType;
7473
7512
  }
@@ -7682,7 +7721,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7682
7721
  // Handle the case where a *args: P.args (or *args: Any) is passed as an
7683
7722
  // argument to a function that accepts a ParamSpec.
7684
7723
  if (typeResult.type.details.paramSpec) {
7685
- const argTypeResult = getTypeOfArgument(argList[argIndex]);
7724
+ const argTypeResult = getTypeOfArgument(argList[argIndex],
7725
+ /* inferenceContext */ undefined, signatureTracker);
7686
7726
  const argType = argTypeResult.type;
7687
7727
  if (argTypeResult.isIncomplete) {
7688
7728
  isTypeIncomplete = true;
@@ -7805,7 +7845,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7805
7845
  if ((0, types_1.isVariadicTypeVar)(paramType) && !paramType.isVariadicInUnion) {
7806
7846
  const tupleTypeArgs = variadicArgs.map((argParam) => {
7807
7847
  var _a;
7808
- const argType = getTypeOfArgument(argParam.argument).type;
7848
+ const argType = getTypeOfArgument(argParam.argument,
7849
+ /* inferenceContext */ undefined, signatureTracker).type;
7809
7850
  const containsVariadicTypeVar = (0, types_1.isUnpackedVariadicTypeVar)(argType) ||
7810
7851
  ((0, types_1.isClassInstance)(argType) &&
7811
7852
  (0, typeUtils_1.isTupleClass)(argType) &&
@@ -7885,10 +7926,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7885
7926
  // After having matched arguments with parameters, this function evaluates the
7886
7927
  // types of each argument expression and validates that the resulting type is
7887
7928
  // compatible with the declared type of the corresponding parameter.
7888
- function validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
7889
- var _a, _b;
7929
+ function validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext, signatureTracker) {
7930
+ var _a;
7890
7931
  const type = matchResults.overload;
7891
- const signatureTracker = (_a = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.signatureTracker) !== null && _a !== void 0 ? _a : new typeUtils_1.UniqueSignatureTracker();
7932
+ if (!signatureTracker) {
7933
+ signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7934
+ }
7892
7935
  matchResults.overload = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(matchResults.overload, signatureTracker, errorNode.start);
7893
7936
  // Can we safely ignore the inference context (either because it's not provided
7894
7937
  // or will have no effect)? If so, we can eliminate a bunch of extra work.
@@ -7896,7 +7939,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7896
7939
  (0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) ||
7897
7940
  (0, types_1.isNever)(inferenceContext.expectedType) ||
7898
7941
  !type.details.declaredReturnType ||
7899
- !(0, typeUtils_1.requiresSpecialization)((_b = types_1.FunctionType.getSpecializedReturnType(type)) !== null && _b !== void 0 ? _b : types_1.UnknownType.create())) {
7942
+ !(0, typeUtils_1.requiresSpecialization)((_a = types_1.FunctionType.getSpecializedReturnType(type)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create())) {
7900
7943
  return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck);
7901
7944
  }
7902
7945
  const effectiveReturnType = getFunctionEffectiveReturnType(type);
@@ -7979,7 +8022,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7979
8022
  }
7980
8023
  return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck);
7981
8024
  }
7982
- function validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck = false) {
8025
+ function validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck) {
7983
8026
  const type = matchResults.overload;
7984
8027
  let isTypeIncomplete = matchResults.isTypeIncomplete;
7985
8028
  let argumentErrors = false;
@@ -8182,7 +8225,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8182
8225
  // call to a generic function or if this isn't a callable
8183
8226
  // return with type parameters that are rescoped from the original
8184
8227
  // function to the returned callable.
8185
- const unknownIfNotFound = !ParseTreeUtils.getTypeVarScopesForNode(errorNode).some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope)) && !type.details.rescopedTypeParameters;
8228
+ const unknownIfNotFound = !ParseTreeUtils.getTypeVarScopesForNode(errorNode).some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope));
8186
8229
  let specializedReturnType = (0, typeUtils_1.applySolvedTypeVars)(returnType, typeVarContext, {
8187
8230
  unknownIfNotFound,
8188
8231
  unknownExemptTypeVars: getUnknownExemptTypeVarsForReturnType(type, returnType),
@@ -8296,11 +8339,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8296
8339
  // Tries to assign the call arguments to the function parameter
8297
8340
  // list and reports any mismatches in types or counts. Returns the
8298
8341
  // specialized return type of the call.
8299
- function validateFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
8300
- var _a;
8301
- const signatureTracker = (_a = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.signatureTracker) !== null && _a !== void 0 ? _a : new typeUtils_1.UniqueSignatureTracker();
8342
+ function validateFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck = false, inferenceContext, signatureTracker) {
8343
+ if (!signatureTracker) {
8344
+ signatureTracker = new typeUtils_1.UniqueSignatureTracker();
8345
+ }
8302
8346
  typeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(typeResult.type, signatureTracker, errorNode.start);
8303
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, typeResult, 0);
8347
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, typeResult, 0, signatureTracker);
8304
8348
  if (matchResults.argumentErrors) {
8305
8349
  // Evaluate types of all args. This will ensure that referenced symbols are
8306
8350
  // not reported as unaccessed.
@@ -8315,7 +8359,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8315
8359
  overloadsUsedForCall: [],
8316
8360
  };
8317
8361
  }
8318
- return validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck, (0, typeUtils_1.makeInferenceContext)(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete, signatureTracker));
8362
+ return validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck, (0, typeUtils_1.makeInferenceContext)(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete), signatureTracker);
8319
8363
  }
8320
8364
  // Determines whether the specified argument list satisfies the function
8321
8365
  // signature bound to the specified ParamSpec. Return value indicates success.
@@ -8351,7 +8395,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8351
8395
  if (!paramSpecType) {
8352
8396
  paramSpecType = (0, typeUtils_1.convertTypeToParamSpecValue)(paramSpec);
8353
8397
  }
8354
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: paramSpecType }, 0);
8398
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: paramSpecType }, 0, signatureTracker);
8355
8399
  const functionType = matchResults.overload;
8356
8400
  const srcTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(paramSpecType));
8357
8401
  if (matchResults.argumentErrors) {
@@ -8376,7 +8420,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8376
8420
  let argumentErrors = false;
8377
8421
  let argErrorNode;
8378
8422
  for (const arg of argList) {
8379
- const argType = (_a = getTypeOfArgument(arg)) === null || _a === void 0 ? void 0 : _a.type;
8423
+ const argType = (_a = getTypeOfArgument(arg, /* inferenceContext */ undefined, signatureTracker)) === null || _a === void 0 ? void 0 : _a.type;
8380
8424
  const isArgTypeCompatible = argType && ((0, types_1.isTypeSame)(argType, paramSpec, { ignoreTypeFlags: true }) || (0, types_1.isAnyOrUnknown)(argType));
8381
8425
  if (arg.argumentCategory === 1 /* ArgumentCategory.UnpackedList */ && !sawArgs && isArgTypeCompatible) {
8382
8426
  sawArgs = true;
@@ -8401,7 +8445,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8401
8445
  }
8402
8446
  return { argumentErrors, typeVarContexts: [srcTypeVarContext] };
8403
8447
  }
8404
- const result = validateFunctionArgumentTypes(errorNode, matchResults, srcTypeVarContext, signatureTracker);
8448
+ const result = validateFunctionArgumentTypes(errorNode, matchResults, srcTypeVarContext, signatureTracker,
8449
+ /* skipUnknownArgCheck */ undefined);
8405
8450
  return { argumentErrors: !!result.argumentErrors, typeVarContexts: [srcTypeVarContext] };
8406
8451
  }
8407
8452
  function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, options) {
@@ -8461,9 +8506,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8461
8506
  8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
8462
8507
  32 /* EvaluatorFlags.DisallowParamSpec */ |
8463
8508
  64 /* EvaluatorFlags.DisallowTypeVarTuple */ |
8464
- 16 /* EvaluatorFlags.DisallowFinal */
8509
+ 16 /* EvaluatorFlags.DisallowFinal */ |
8510
+ 2 /* EvaluatorFlags.DoNotSpecialize */
8465
8511
  : 2 /* EvaluatorFlags.DoNotSpecialize */ | 16 /* EvaluatorFlags.DisallowFinal */;
8466
- const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete), signatureTracker));
8512
+ const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete)), signatureTracker);
8467
8513
  argType = exprTypeResult.type;
8468
8514
  // If the type includes multiple instances of a generic function
8469
8515
  // signature, force the type arguments for the duplicates to have
@@ -8498,7 +8544,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8498
8544
  argType = argParam.argType;
8499
8545
  }
8500
8546
  else {
8501
- const argTypeResult = getTypeOfArgument(argParam.argument);
8547
+ const argTypeResult = getTypeOfArgument(argParam.argument,
8548
+ /* inferenceContext */ undefined, signatureTracker);
8502
8549
  argType = argTypeResult.type;
8503
8550
  if (argTypeResult.isIncomplete) {
8504
8551
  isTypeIncomplete = true;
@@ -8942,9 +8989,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8942
8989
  return paramSpec;
8943
8990
  }
8944
8991
  function getParamSpecDefaultType(node, isPep695Syntax) {
8945
- const functionType = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */ | 65536 /* FunctionTypeFlags.ParamSpecValue */);
8992
+ const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
8946
8993
  if (node.nodeType === 18 /* ParseNodeType.Ellipsis */) {
8947
8994
  types_1.FunctionType.addDefaultParameters(functionType);
8995
+ functionType.details.flags |= 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
8948
8996
  return functionType;
8949
8997
  }
8950
8998
  if (node.nodeType === 31 /* ParseNodeType.List */) {
@@ -9195,12 +9243,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9195
9243
  // Implements the semantics of the multi-parameter variant of the "type" call.
9196
9244
  function createClassFromMetaclass(errorNode, argList, metaclass) {
9197
9245
  const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
9198
- const arg0Type = getTypeOfArgument(argList[0]).type;
9246
+ const arg0Type = getTypeOfArgument(argList[0],
9247
+ /* inferenceContext */ undefined,
9248
+ /* signatureTracker */ undefined).type;
9199
9249
  if (!(0, types_1.isClassInstance)(arg0Type) || !types_1.ClassType.isBuiltIn(arg0Type, 'str')) {
9200
9250
  return undefined;
9201
9251
  }
9202
9252
  const className = arg0Type.literalValue || '_';
9203
- const arg1Type = getTypeOfArgument(argList[1]).type;
9253
+ const arg1Type = getTypeOfArgument(argList[1],
9254
+ /* inferenceContext */ undefined,
9255
+ /* signatureTracker */ undefined).type;
9204
9256
  // TODO - properly handle case where tuple of base classes is provided.
9205
9257
  if (!(0, types_1.isClassInstance)(arg1Type) || !(0, typeUtils_1.isTupleClass)(arg1Type) || arg1Type.tupleTypeArguments === undefined) {
9206
9258
  return undefined;
@@ -9263,7 +9315,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9263
9315
  (0, debug_1.assert)(magicMethodType !== undefined);
9264
9316
  return validateCallArguments(errorNode, functionArgs, { type: magicMethodType },
9265
9317
  /* typeVarContext */ undefined,
9266
- /* skipUnknownArgCheck */ true, inferenceContext);
9318
+ /* skipUnknownArgCheck */ true, inferenceContext,
9319
+ /* signatureTracker */ undefined);
9267
9320
  });
9268
9321
  // If there were errors with the expected type, try
9269
9322
  // to evaluate without the expected type.
@@ -9272,7 +9325,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9272
9325
  (0, debug_1.assert)(magicMethodType !== undefined);
9273
9326
  return validateCallArguments(errorNode, functionArgs, { type: magicMethodType },
9274
9327
  /* typeVarContext */ undefined,
9275
- /* skipUnknownArgCheck */ true);
9328
+ /* skipUnknownArgCheck */ true,
9329
+ /* inferenceContext */ undefined,
9330
+ /* signatureTracker */ undefined);
9276
9331
  });
9277
9332
  }
9278
9333
  if (callResult.argumentErrors) {
@@ -9330,7 +9385,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9330
9385
  return;
9331
9386
  }
9332
9387
  const subtypeResult = useSpeculativeMode(node, () => {
9333
- return getTypeOfDictionaryWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype));
9388
+ return getTypeOfDictionaryWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(subtype));
9334
9389
  });
9335
9390
  if (subtypeResult && assignType(subtype, subtypeResult.type)) {
9336
9391
  // If this is the first result we're seeing or it's the first result
@@ -9347,15 +9402,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9347
9402
  let expectedTypeDiagAddendum = undefined;
9348
9403
  if (effectiveExpectedType) {
9349
9404
  expectedTypeDiagAddendum = new diagnostic_1.DiagnosticAddendum();
9350
- const result = getTypeOfDictionaryWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType), expectedTypeDiagAddendum);
9405
+ const result = getTypeOfDictionaryWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType), expectedTypeDiagAddendum);
9351
9406
  if (result) {
9352
9407
  return result;
9353
9408
  }
9354
9409
  }
9355
- const result = getTypeOfDictionaryInferred(node, /* hasExpectedType */ !!inferenceContext);
9410
+ const result = getTypeOfDictionaryInferred(node, flags, /* hasExpectedType */ !!inferenceContext);
9356
9411
  return { ...result, expectedTypeDiagAddendum };
9357
9412
  }
9358
- function getTypeOfDictionaryWithContext(node, inferenceContext, expectedDiagAddendum) {
9413
+ function getTypeOfDictionaryWithContext(node, flags, inferenceContext, expectedDiagAddendum) {
9359
9414
  inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
9360
9415
  let concreteExpectedType = makeTopLevelTypeVarsConcrete(inferenceContext.expectedType);
9361
9416
  if (!(0, types_1.isClassInstance)(concreteExpectedType)) {
@@ -9372,7 +9427,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9372
9427
  concreteExpectedType = types_1.TypeBase.cloneForCondition(concreteExpectedType, undefined);
9373
9428
  const expectedTypedDictEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, concreteExpectedType);
9374
9429
  // Infer the key and value types if possible.
9375
- const keyValueTypeResult = getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
9430
+ const keyValueTypeResult = getKeyAndValueTypesFromDictionary(node, flags, keyTypes, valueTypes,
9376
9431
  /* forceStrictInference */ true,
9377
9432
  /* isValueTypeInvariant */ true,
9378
9433
  /* expectedKeyType */ undefined,
@@ -9430,7 +9485,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9430
9485
  }
9431
9486
  }
9432
9487
  // Infer the key and value types if possible.
9433
- const keyValueResult = getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
9488
+ const keyValueResult = getKeyAndValueTypesFromDictionary(node, flags, keyTypes, valueTypes,
9434
9489
  /* forceStrictInference */ true, isValueTypeInvariant, expectedKeyType, expectedValueType, undefined, expectedDiagAddendum);
9435
9490
  if (keyValueResult.isIncomplete) {
9436
9491
  isIncomplete = true;
@@ -9449,7 +9504,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9449
9504
  }
9450
9505
  // Attempts to infer the type of a dictionary statement. If hasExpectedType
9451
9506
  // is true, strict inference is used for the subexpressions.
9452
- function getTypeOfDictionaryInferred(node, hasExpectedType) {
9507
+ function getTypeOfDictionaryInferred(node, flags, hasExpectedType) {
9453
9508
  const fallbackType = hasExpectedType ? types_1.AnyType.create() : types_1.UnknownType.create();
9454
9509
  let keyType = fallbackType;
9455
9510
  let valueType = fallbackType;
@@ -9459,7 +9514,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9459
9514
  let isIncomplete = false;
9460
9515
  let typeErrors = false;
9461
9516
  // Infer the key and value types if possible.
9462
- const keyValueResult = getKeyAndValueTypesFromDictionary(node, keyTypeResults, valueTypeResults,
9517
+ const keyValueResult = getKeyAndValueTypesFromDictionary(node, flags, keyTypeResults, valueTypeResults,
9463
9518
  /* forceStrictInference */ hasExpectedType,
9464
9519
  /* isValueTypeInvariant */ false);
9465
9520
  if (keyValueResult.isIncomplete) {
@@ -9503,16 +9558,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9503
9558
  }
9504
9559
  return { type, isIncomplete, typeErrors };
9505
9560
  }
9506
- function getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes, forceStrictInference, isValueTypeInvariant, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum) {
9561
+ function getKeyAndValueTypesFromDictionary(node, flags, keyTypes, valueTypes, forceStrictInference, isValueTypeInvariant, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum) {
9507
9562
  let isIncomplete = false;
9508
9563
  let typeErrors = false;
9564
+ // Mask out some of the flags that are not applicable for a dictionary key
9565
+ // even if it appears within an inlined TypedDict annotation.
9566
+ const keyFlags = flags &
9567
+ ~(256 /* EvaluatorFlags.ExpectingTypeAnnotation */ |
9568
+ 8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
9569
+ 128 /* EvaluatorFlags.ExpectingInstantiableType */);
9509
9570
  // Infer the key and value types if possible.
9510
9571
  node.entries.forEach((entryNode, index) => {
9511
9572
  var _a, _b, _c, _d;
9512
9573
  let addUnknown = true;
9513
9574
  if (entryNode.nodeType === 17 /* ParseNodeType.DictionaryKeyEntry */) {
9514
- const keyTypeResult = getTypeOfExpression(entryNode.keyExpression,
9515
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedKeyType !== null && expectedKeyType !== void 0 ? expectedKeyType : (forceStrictInference ? types_1.NeverType.createNever() : undefined)));
9575
+ const keyTypeResult = getTypeOfExpression(entryNode.keyExpression, keyFlags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedKeyType !== null && expectedKeyType !== void 0 ? expectedKeyType : (forceStrictInference ? types_1.NeverType.createNever() : undefined)));
9516
9576
  if (keyTypeResult.isIncomplete) {
9517
9577
  isIncomplete = true;
9518
9578
  }
@@ -9535,14 +9595,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9535
9595
  expectedTypedDictEntries.knownItems.has(keyType.literalValue)) {
9536
9596
  const effectiveValueType = expectedTypedDictEntries.knownItems.get(keyType.literalValue).valueType;
9537
9597
  entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
9538
- valueTypeResult = getTypeOfExpression(entryNode.valueExpression,
9539
- /* flags */ undefined, entryInferenceContext);
9598
+ valueTypeResult = getTypeOfExpression(entryNode.valueExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, entryInferenceContext);
9540
9599
  }
9541
9600
  else {
9542
9601
  const effectiveValueType = expectedValueType !== null && expectedValueType !== void 0 ? expectedValueType : (forceStrictInference ? types_1.NeverType.createNever() : undefined);
9543
9602
  entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
9544
- valueTypeResult = getTypeOfExpression(entryNode.valueExpression,
9545
- /* flags */ undefined, entryInferenceContext);
9603
+ valueTypeResult = getTypeOfExpression(entryNode.valueExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, entryInferenceContext);
9546
9604
  }
9547
9605
  if (entryInferenceContext && !valueTypeResult.typeErrors) {
9548
9606
  const fromExpectedType = inferTypeArgFromExpectedEntryType(entryInferenceContext, [valueTypeResult.type], !isValueTypeInvariant);
@@ -9584,8 +9642,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9584
9642
  }
9585
9643
  }
9586
9644
  const entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(expectedType);
9587
- let unexpandedTypeResult = getTypeOfExpression(entryNode.expandExpression,
9588
- /* flags */ undefined, entryInferenceContext);
9645
+ let unexpandedTypeResult = getTypeOfExpression(entryNode.expandExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, entryInferenceContext);
9589
9646
  if (entryInferenceContext && !unexpandedTypeResult.typeErrors) {
9590
9647
  const fromExpectedType = inferTypeArgFromExpectedEntryType(entryInferenceContext, [unexpandedTypeResult.type], !isValueTypeInvariant);
9591
9648
  if (fromExpectedType) {
@@ -9650,7 +9707,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9650
9707
  }
9651
9708
  }
9652
9709
  else if (entryNode.nodeType === 32 /* ParseNodeType.ListComprehension */) {
9653
- const dictEntryTypeResult = getElementTypeFromListComprehension(entryNode, expectedValueType, expectedKeyType);
9710
+ const dictEntryTypeResult = getElementTypeFromListComprehension(entryNode, flags, expectedValueType, expectedKeyType);
9654
9711
  const dictEntryType = dictEntryTypeResult.type;
9655
9712
  if (dictEntryTypeResult.isIncomplete) {
9656
9713
  isIncomplete = true;
@@ -9688,6 +9745,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9688
9745
  diag.addMessage(localize_1.LocAddendum.useListInstead());
9689
9746
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.listInAnnotation() + diag.getString(), node);
9690
9747
  }
9748
+ flags &= ~(256 /* EvaluatorFlags.ExpectingTypeAnnotation */ |
9749
+ 8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
9750
+ 128 /* EvaluatorFlags.ExpectingInstantiableType */);
9691
9751
  // If the expected type is a union, recursively call for each of the subtypes
9692
9752
  // to find one that matches.
9693
9753
  let effectiveExpectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
@@ -9700,7 +9760,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9700
9760
  return;
9701
9761
  }
9702
9762
  const subtypeResult = useSpeculativeMode(node, () => {
9703
- return getTypeOfListOrSetWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype));
9763
+ return getTypeOfListOrSetWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(subtype));
9704
9764
  });
9705
9765
  if (subtypeResult && assignType(subtype, subtypeResult.type)) {
9706
9766
  // If this is the first result we're seeing or it's the first result
@@ -9716,18 +9776,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9716
9776
  }
9717
9777
  let expectedTypeDiagAddendum;
9718
9778
  if (effectiveExpectedType) {
9719
- const result = getTypeOfListOrSetWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType));
9779
+ const result = getTypeOfListOrSetWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType));
9720
9780
  if (result && !result.typeErrors) {
9721
9781
  return result;
9722
9782
  }
9723
9783
  expectedTypeDiagAddendum = result === null || result === void 0 ? void 0 : result.expectedTypeDiagAddendum;
9724
9784
  }
9725
- const typeResult = getTypeOfListOrSetInferred(node, /* hasExpectedType */ inferenceContext !== undefined);
9785
+ const typeResult = getTypeOfListOrSetInferred(node, flags,
9786
+ /* hasExpectedType */ inferenceContext !== undefined);
9726
9787
  return { ...typeResult, expectedTypeDiagAddendum };
9727
9788
  }
9728
9789
  // Attempts to determine the type of a list or set statement based on an expected type.
9729
9790
  // Returns undefined if that type cannot be honored.
9730
- function getTypeOfListOrSetWithContext(node, inferenceContext) {
9791
+ function getTypeOfListOrSetWithContext(node, flags, inferenceContext) {
9731
9792
  const builtInClassName = node.nodeType === 31 /* ParseNodeType.List */ ? 'list' : 'set';
9732
9793
  inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
9733
9794
  let isIncomplete = false;
@@ -9742,11 +9803,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9742
9803
  node.entries.forEach((entry) => {
9743
9804
  let entryTypeResult;
9744
9805
  if (entry.nodeType === 32 /* ParseNodeType.ListComprehension */) {
9745
- entryTypeResult = getElementTypeFromListComprehension(entry, expectedEntryType);
9806
+ entryTypeResult = getElementTypeFromListComprehension(entry, flags, expectedEntryType);
9746
9807
  }
9747
9808
  else {
9748
- entryTypeResult = getTypeOfExpression(entry,
9749
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedEntryType));
9809
+ entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedEntryType));
9750
9810
  }
9751
9811
  entryTypes.push(entryTypeResult.type);
9752
9812
  if (entryTypeResult.isIncomplete) {
@@ -9800,7 +9860,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9800
9860
  return specializedListOrSet.typeArguments[0];
9801
9861
  }
9802
9862
  // Attempts to infer the type of a list or set statement with no "expected type".
9803
- function getTypeOfListOrSetInferred(node, hasExpectedType) {
9863
+ function getTypeOfListOrSetInferred(node, flags, hasExpectedType) {
9804
9864
  const builtInClassName = node.nodeType === 31 /* ParseNodeType.List */ ? 'list' : 'set';
9805
9865
  const verifyHashable = node.nodeType === 45 /* ParseNodeType.Set */;
9806
9866
  let isEmptyContainer = false;
@@ -9810,10 +9870,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9810
9870
  node.entries.forEach((entry, index) => {
9811
9871
  let entryTypeResult;
9812
9872
  if (entry.nodeType === 32 /* ParseNodeType.ListComprehension */ && !entry.isGenerator) {
9813
- entryTypeResult = getElementTypeFromListComprehension(entry);
9873
+ entryTypeResult = getElementTypeFromListComprehension(entry, flags);
9814
9874
  }
9815
9875
  else {
9816
- entryTypeResult = getTypeOfExpression(entry);
9876
+ entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */);
9817
9877
  }
9818
9878
  if (entryTypeResult.isIncomplete) {
9819
9879
  isIncomplete = true;
@@ -10129,7 +10189,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10129
10189
  }
10130
10190
  return { type: functionType, isIncomplete, typeErrors };
10131
10191
  }
10132
- function getTypeOfListComprehension(node, inferenceContext) {
10192
+ function getTypeOfListComprehension(node, flags, inferenceContext) {
10133
10193
  let isIncomplete = false;
10134
10194
  let typeErrors = false;
10135
10195
  // If any of the "for" clauses are marked async or any of the "if" clauses
@@ -10147,7 +10207,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10147
10207
  }
10148
10208
  const builtInIteratorType = getTypingType(node, isAsync ? 'AsyncGenerator' : 'Generator');
10149
10209
  const expectedEntryType = getExpectedEntryTypeForIterable(node, builtInIteratorType, inferenceContext);
10150
- const elementTypeResult = getElementTypeFromListComprehension(node, expectedEntryType);
10210
+ const elementTypeResult = getElementTypeFromListComprehension(node, flags, expectedEntryType);
10151
10211
  if (elementTypeResult.isIncomplete) {
10152
10212
  isIncomplete = true;
10153
10213
  }
@@ -10217,7 +10277,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10217
10277
  }
10218
10278
  // Returns the type of one entry returned by the list comprehension,
10219
10279
  // as opposed to the entire list.
10220
- function getElementTypeFromListComprehension(node, expectedValueOrElementType, expectedKeyType) {
10280
+ function getElementTypeFromListComprehension(node, flags, expectedValueOrElementType, expectedKeyType) {
10221
10281
  let isIncomplete = false;
10222
10282
  let typeErrors = false;
10223
10283
  // "Execute" the list comprehensions from start to finish.
@@ -10229,8 +10289,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10229
10289
  let type = types_1.UnknownType.create();
10230
10290
  if (node.expression.nodeType === 17 /* ParseNodeType.DictionaryKeyEntry */) {
10231
10291
  // Create a tuple with the key/value types.
10232
- const keyTypeResult = getTypeOfExpression(node.expression.keyExpression,
10233
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedKeyType));
10292
+ const keyTypeResult = getTypeOfExpression(node.expression.keyExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedKeyType));
10234
10293
  if (keyTypeResult.isIncomplete) {
10235
10294
  isIncomplete = true;
10236
10295
  }
@@ -10241,8 +10300,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10241
10300
  if (!expectedKeyType || !(0, typeUtils_1.containsLiteralType)(expectedKeyType)) {
10242
10301
  keyType = stripLiteralValue(keyType);
10243
10302
  }
10244
- const valueTypeResult = getTypeOfExpression(node.expression.valueExpression,
10245
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10303
+ const valueTypeResult = getTypeOfExpression(node.expression.valueExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10246
10304
  if (valueTypeResult.isIncomplete) {
10247
10305
  isIncomplete = true;
10248
10306
  }
@@ -10260,12 +10318,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10260
10318
  }
10261
10319
  else if (node.expression.nodeType === 16 /* ParseNodeType.DictionaryExpandEntry */) {
10262
10320
  // The parser should have reported an error in this case because it's not allowed.
10263
- getTypeOfExpression(node.expression.expandExpression,
10264
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10321
+ getTypeOfExpression(node.expression.expandExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10265
10322
  }
10266
10323
  else if ((0, parseNodes_1.isExpressionNode)(node)) {
10267
- const exprTypeResult = getTypeOfExpression(node.expression,
10268
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10324
+ const exprTypeResult = getTypeOfExpression(node.expression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10269
10325
  if (exprTypeResult.isIncomplete) {
10270
10326
  isIncomplete = true;
10271
10327
  }
@@ -11310,7 +11366,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11310
11366
  return undefined;
11311
11367
  }
11312
11368
  function evaluateTypesForAssignmentStatement(node) {
11313
- var _a, _b;
11369
+ var _a;
11314
11370
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
11315
11371
  // If the entire statement has already been evaluated, don't
11316
11372
  // re-evaluate it.
@@ -11411,20 +11467,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11411
11467
  }
11412
11468
  // If this is an enum, transform the type as required.
11413
11469
  rightHandType = srcType;
11414
- let targetName;
11415
- if (node.leftExpression.nodeType === 38 /* ParseNodeType.Name */) {
11416
- targetName = node.leftExpression;
11417
- }
11418
- else if (node.leftExpression.nodeType === 54 /* ParseNodeType.TypeAnnotation */ &&
11419
- node.leftExpression.valueExpression.nodeType === 38 /* ParseNodeType.Name */) {
11420
- targetName = node.leftExpression.valueExpression;
11421
- }
11422
- if (targetName) {
11423
- rightHandType =
11424
- (_a = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node, targetName, () => {
11425
- return { assignedType: rightHandType };
11426
- })) !== null && _a !== void 0 ? _a : rightHandType;
11427
- }
11428
11470
  if (typeAliasNameNode) {
11429
11471
  // If this was a speculative type alias, it becomes a real type alias
11430
11472
  // only if the evaluated type is an instantiable type.
@@ -11445,7 +11487,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11445
11487
  typeAliasTypeVar.details.boundType = rightHandType;
11446
11488
  // Record the type parameters within the recursive type alias so it
11447
11489
  // can be specialized.
11448
- typeAliasTypeVar.details.recursiveTypeParameters = (_b = rightHandType.typeAliasInfo) === null || _b === void 0 ? void 0 : _b.typeParameters;
11490
+ typeAliasTypeVar.details.recursiveTypeParameters = (_a = rightHandType.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.typeParameters;
11449
11491
  }
11450
11492
  }
11451
11493
  }
@@ -12467,7 +12509,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12467
12509
  if (initSubclassMethodType && initSubclassMethodInfo.classType) {
12468
12510
  const callResult = validateCallArguments(errorNode, argList, { type: initSubclassMethodType },
12469
12511
  /* typeVarContext */ undefined,
12470
- /* skipUnknownArgCheck */ false, (0, typeUtils_1.makeInferenceContext)(getNoneType()));
12512
+ /* skipUnknownArgCheck */ false, (0, typeUtils_1.makeInferenceContext)(getNoneType()),
12513
+ /* signatureTracker */ undefined);
12471
12514
  if (callResult.argumentErrors) {
12472
12515
  const diag = addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.initSubclassCallFailed(), node.name);
12473
12516
  const initSubclassFunction = (0, types_1.isOverloadedFunction)(initSubclassMethodType)
@@ -12493,7 +12536,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12493
12536
  });
12494
12537
  }
12495
12538
  function getTypeOfFunction(node) {
12496
- var _a;
12497
12539
  initializedBasicTypes(node);
12498
12540
  // Is this predecorated function type cached?
12499
12541
  let functionType = readTypeCache(node.name, 0 /* EvaluatorFlags.None */);
@@ -12541,11 +12583,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12541
12583
  decoratedType = newDecoratedType;
12542
12584
  }
12543
12585
  }
12544
- // In case this is an enum class and a method wrapped in an enum.member.
12545
- decoratedType =
12546
- (_a = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node, node.name, () => {
12547
- return { assignedType: decoratedType };
12548
- })) !== null && _a !== void 0 ? _a : decoratedType;
12549
12586
  // See if there are any overloads provided by previous function declarations.
12550
12587
  if ((0, types_1.isFunction)(decoratedType)) {
12551
12588
  decoratedType.details.deprecatedMessage = functionType.details.deprecatedMessage;
@@ -12879,7 +12916,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12879
12916
  }
12880
12917
  // Accumulate any type parameters used in the return type.
12881
12918
  if (functionType.details.declaredReturnType && returnTypeAnnotationNode) {
12882
- rescopeTypeVarsForCallableReturnType(functionType.details.declaredReturnType, functionType, typeParametersSeen);
12919
+ (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionType.details.declaredReturnType), functionType.details.typeVarScopeId);
12883
12920
  }
12884
12921
  // If the return type is explicitly annotated as a generator, mark the
12885
12922
  // function as a generator even though it may not contain a "yield" statement.
@@ -12920,34 +12957,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12920
12957
  }
12921
12958
  }
12922
12959
  }
12923
- // If the declared return type of a function contains type variables that
12924
- // are found nowhere else in the signature and are contained within a
12925
- // Callable, these type variables are "rescoped" from the function to
12926
- // the Callable.
12927
- function rescopeTypeVarsForCallableReturnType(returnType, functionType, typeParametersSeen) {
12928
- const typeVarsInReturnType = (0, typeUtils_1.getTypeVarArgumentsRecursive)(returnType).filter((t) => t.scopeId === functionType.details.typeVarScopeId);
12929
- const rescopedTypeVars = [];
12930
- typeVarsInReturnType.forEach((typeVar) => {
12931
- if (types_1.TypeBase.isInstantiable(typeVar)) {
12932
- typeVar = types_1.TypeVarType.cloneAsInstance(typeVar);
12933
- }
12934
- // If this type variable was already seen in one or more input parameters,
12935
- // don't attempt to rescope it.
12936
- if (typeParametersSeen.some((tp) => (0, types_1.isTypeSame)((0, typeUtils_1.convertToInstance)(tp), typeVar))) {
12937
- return;
12938
- }
12939
- // Is this type variable seen outside of a single callable?
12940
- if ((0, typeUtils_1.isTypeVarLimitedToCallable)(returnType, typeVar)) {
12941
- rescopedTypeVars.push(typeVar);
12942
- }
12943
- });
12944
- (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, typeVarsInReturnType);
12945
- // Note that the type parameters have been rescoped so they are not
12946
- // considered valid for the body of this function.
12947
- if (rescopedTypeVars.length > 0) {
12948
- functionType.details.rescopedTypeParameters = rescopedTypeVars;
12949
- }
12950
- }
12951
12960
  function adjustParameterAnnotatedType(param, type) {
12952
12961
  var _a;
12953
12962
  // PEP 484 indicates that if a parameter has a default value of 'None'
@@ -14600,9 +14609,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14600
14609
  const specializedClass = types_1.ClassType.cloneForSpecialization(classType, typeArgTypes, typeArgs !== undefined);
14601
14610
  return { type: specializedClass };
14602
14611
  }
14603
- function getTypeOfArgument(arg, inferenceContext) {
14612
+ function getTypeOfArgument(arg, inferenceContext, signatureTracker) {
14613
+ var _a, _b;
14604
14614
  if (arg.typeResult) {
14605
- return { type: arg.typeResult.type, isIncomplete: arg.typeResult.isIncomplete };
14615
+ const type = (_b = (_a = arg.typeResult.type) === null || _a === void 0 ? void 0 : _a.specialForm) !== null && _b !== void 0 ? _b : arg.typeResult.type;
14616
+ return { type, isIncomplete: arg.typeResult.isIncomplete };
14606
14617
  }
14607
14618
  if (!arg.valueExpression) {
14608
14619
  // We shouldn't ever get here, but just in case.
@@ -14610,7 +14621,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14610
14621
  }
14611
14622
  // If there was no defined type provided, there should always
14612
14623
  // be a value expression from which we can retrieve the type.
14613
- return getTypeOfExpression(arg.valueExpression, /* flags */ undefined, inferenceContext);
14624
+ const typeResult = getTypeOfExpression(arg.valueExpression,
14625
+ /* flags */ undefined, inferenceContext, signatureTracker);
14626
+ if (signatureTracker) {
14627
+ typeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(typeResult.type, signatureTracker, arg.valueExpression.start);
14628
+ }
14629
+ return typeResult;
14614
14630
  }
14615
14631
  // This function is like getTypeOfArgument except that it is
14616
14632
  // used in cases where the argument is expected to be a type
@@ -15065,7 +15081,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15065
15081
  return declarations;
15066
15082
  }
15067
15083
  function getTypeForDeclaration(declaration) {
15068
- var _a, _b, _c, _d;
15084
+ var _a, _b;
15069
15085
  switch (declaration.type) {
15070
15086
  case 0 /* DeclarationType.Intrinsic */: {
15071
15087
  if (declaration.intrinsicType === 'Any') {
@@ -15172,16 +15188,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15172
15188
  });
15173
15189
  }
15174
15190
  if (declaredType) {
15175
- // Apply enum transform if appropriate.
15176
- if (declaration.node.nodeType === 38 /* ParseNodeType.Name */) {
15177
- const variableNode = (_c = ParseTreeUtils.getParentNodeOfType(declaration.node, 3 /* ParseNodeType.Assignment */)) !== null && _c !== void 0 ? _c : ParseTreeUtils.getParentNodeOfType(declaration.node, 54 /* ParseNodeType.TypeAnnotation */);
15178
- if (variableNode) {
15179
- declaredType =
15180
- (_d = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, variableNode, declaration.node, () => {
15181
- return { declaredType };
15182
- })) !== null && _d !== void 0 ? _d : declaredType;
15183
- }
15184
- }
15185
15191
  if ((0, types_1.isClassInstance)(declaredType) && types_1.ClassType.isBuiltIn(declaredType, 'TypeAlias')) {
15186
15192
  return { type: undefined, isTypeAlias: true };
15187
15193
  }
@@ -15321,7 +15327,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15321
15327
  return typeVar;
15322
15328
  }
15323
15329
  function getInferredTypeOfDeclaration(symbol, decl) {
15324
- var _a, _b, _c, _d;
15330
+ var _a, _b, _c;
15325
15331
  const resolvedDecl = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
15326
15332
  allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
15327
15333
  });
@@ -15444,25 +15450,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15444
15450
  let inferredType = (_c = evaluateTypeForSubnode(resolvedDecl.node, () => {
15445
15451
  evaluateTypesForStatement(typeSource);
15446
15452
  })) === null || _c === void 0 ? void 0 : _c.type;
15447
- if (inferredType && resolvedDecl.node.nodeType === 38 /* ParseNodeType.Name */) {
15448
- const variableNode = (_d = ParseTreeUtils.getParentNodeOfType(resolvedDecl.node, 3 /* ParseNodeType.Assignment */)) !== null && _d !== void 0 ? _d : ParseTreeUtils.getParentNodeOfType(resolvedDecl.node, 54 /* ParseNodeType.TypeAnnotation */);
15449
- if (variableNode) {
15450
- // See if this is an enum member. If so, we need to handle it as a special case.
15451
- const enumMemberType = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, variableNode, resolvedDecl.node, () => {
15452
- var _a, _b;
15453
- (0, debug_1.assert)(resolvedDecl.inferredTypeSource !== undefined);
15454
- const inferredTypeSource = resolvedDecl.inferredTypeSource;
15455
- return {
15456
- assignedType: (_b = (_a = evaluateTypeForSubnode(inferredTypeSource, () => {
15457
- evaluateTypesForStatement(inferredTypeSource);
15458
- })) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create(),
15459
- };
15460
- });
15461
- if (enumMemberType) {
15462
- inferredType = enumMemberType;
15463
- }
15464
- }
15465
- }
15466
15453
  if (inferredType && isTypeAlias && resolvedDecl.typeAliasName) {
15467
15454
  // If this was a speculative type alias, it becomes a real type alias only
15468
15455
  // in the event that its inferred type is instantiable or explicitly Any
@@ -15914,7 +15901,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15914
15901
  function getFunctionEffectiveReturnType(type, callSiteInfo, inferTypeIfNeeded = true) {
15915
15902
  const specializedReturnType = types_1.FunctionType.getSpecializedReturnType(type, /* includeInferred */ false);
15916
15903
  if (specializedReturnType && !(0, types_1.isUnknown)(specializedReturnType)) {
15917
- return adjustCallableReturnType(type, specializedReturnType, /* liveTypeVarScopes */ []);
15904
+ const liveTypeVarScopes = (callSiteInfo === null || callSiteInfo === void 0 ? void 0 : callSiteInfo.errorNode)
15905
+ ? ParseTreeUtils.getTypeVarScopesForNode(callSiteInfo === null || callSiteInfo === void 0 ? void 0 : callSiteInfo.errorNode)
15906
+ : [];
15907
+ return adjustCallableReturnType(type, specializedReturnType, liveTypeVarScopes);
15918
15908
  }
15919
15909
  if (inferTypeIfNeeded) {
15920
15910
  return getFunctionInferredReturnType(type, callSiteInfo);
@@ -16306,24 +16296,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16306
16296
  return true;
16307
16297
  }
16308
16298
  }
16309
- const destErrorType = reportErrorsUsingObjType ? types_1.ClassType.cloneAsInstance(destType) : destType;
16310
- const srcErrorType = reportErrorsUsingObjType ? types_1.ClassType.cloneAsInstance(srcType) : srcType;
16311
- let destErrorTypeText = printType(destErrorType);
16312
- let srcErrorTypeText = printType(srcErrorType);
16313
- // If the text is the same, use the fully-qualified name rather than the short name.
16314
- if (destErrorTypeText === srcErrorTypeText && destType.details.fullName && srcType.details.fullName) {
16315
- destErrorTypeText = destType.details.fullName;
16316
- srcErrorTypeText = srcType.details.fullName;
16317
- }
16318
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeIncompatible().format({
16319
- sourceType: srcErrorTypeText,
16320
- destType: destErrorTypeText,
16321
- }));
16322
- // Tell the user about the disableBytesTypePromotions if that is involved.
16323
- if (types_1.ClassType.isBuiltIn(destType, 'bytes')) {
16324
- const promotions = typePromotions.get(destType.details.fullName);
16325
- if (promotions && promotions.some((name) => name === srcType.details.fullName)) {
16326
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.bytesTypePromotions());
16299
+ if (diag) {
16300
+ const destErrorType = reportErrorsUsingObjType ? types_1.ClassType.cloneAsInstance(destType) : destType;
16301
+ const srcErrorType = reportErrorsUsingObjType ? types_1.ClassType.cloneAsInstance(srcType) : srcType;
16302
+ let destErrorTypeText = printType(destErrorType);
16303
+ let srcErrorTypeText = printType(srcErrorType);
16304
+ // If the text is the same, use the fully-qualified name rather than the short name.
16305
+ if (destErrorTypeText === srcErrorTypeText && destType.details.fullName && srcType.details.fullName) {
16306
+ destErrorTypeText = destType.details.fullName;
16307
+ srcErrorTypeText = srcType.details.fullName;
16308
+ }
16309
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeIncompatible().format({
16310
+ sourceType: srcErrorTypeText,
16311
+ destType: destErrorTypeText,
16312
+ }));
16313
+ // Tell the user about the disableBytesTypePromotions if that is involved.
16314
+ if (types_1.ClassType.isBuiltIn(destType, 'bytes')) {
16315
+ const promotions = typePromotions.get(destType.details.fullName);
16316
+ if (promotions && promotions.some((name) => name === srcType.details.fullName)) {
16317
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.bytesTypePromotions());
16318
+ }
16327
16319
  }
16328
16320
  }
16329
16321
  return false;
@@ -16808,7 +16800,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16808
16800
  // in the dest type is not in the type map already, it is assigned a type
16809
16801
  // and added to the map.
16810
16802
  function assignType(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags = 0 /* AssignTypeFlags.Default */, recursionCount = 0) {
16811
- var _a, _b;
16803
+ var _a, _b, _c;
16812
16804
  // Handle the case where the dest and src types are the same object.
16813
16805
  // We can normally shortcut this and say that they are compatible,
16814
16806
  // but if the type includes TypeVars, we need to go through
@@ -17137,9 +17129,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17137
17129
  return false;
17138
17130
  }
17139
17131
  }
17140
- if (!isSpecialFormClass(expandedSrcType, flags) &&
17141
- assignClass(destType, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
17142
- /* reportErrorsUsingObjType */ false)) {
17132
+ if (types_1.ClassType.isBuiltIn(destType, 'type') && ((_c = srcType.instantiableNestingLevel) !== null && _c !== void 0 ? _c : 0) > 0) {
17133
+ return true;
17134
+ }
17135
+ if (isSpecialFormClass(expandedSrcType, flags)) {
17136
+ if (destType.specialForm) {
17137
+ return assignType(destType.specialForm, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17138
+ }
17139
+ }
17140
+ else if (assignClass(destType, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
17141
+ /* reportErrorsUsingObjType */ false)) {
17143
17142
  return true;
17144
17143
  }
17145
17144
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
@@ -17867,21 +17866,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17867
17866
  }
17868
17867
  }
17869
17868
  if (!assignType(specializedSrcType, specializedDestType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), srcTypeVarContext, destTypeVarContext, flags, recursionCount)) {
17870
- // There are cases involving lambdas where the parameter types are type
17871
- // variables and match exactly but fail the assignment check because the
17872
- // TypeVars are out of scope. This happens because parameter types assigned
17873
- // to lambdas during bidirectional inference do not match the TypeVar scope
17874
- // of the lambda itself.
17875
- if (!(0, types_1.isTypeSame)(destType, srcType)) {
17876
- if (diag && paramIndex !== undefined) {
17877
- diag.addMessage(localize_1.LocAddendum.paramAssignment().format({
17878
- index: paramIndex + 1,
17879
- sourceType: printType(destType),
17880
- destType: printType(srcType),
17881
- }));
17882
- }
17883
- return false;
17869
+ if (diag && paramIndex !== undefined) {
17870
+ diag.addMessage(localize_1.LocAddendum.paramAssignment().format({
17871
+ index: paramIndex + 1,
17872
+ sourceType: printType(destType),
17873
+ destType: printType(srcType),
17874
+ }));
17884
17875
  }
17876
+ return false;
17885
17877
  }
17886
17878
  return true;
17887
17879
  }
@@ -17904,11 +17896,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17904
17896
  }
17905
17897
  let srcLastToPackIndex = srcDetails.params.findIndex((p, i) => {
17906
17898
  (0, debug_1.assert)(destDetails.argsIndex !== undefined);
17907
- return i >= destDetails.argsIndex && p.source === parameterUtils_1.ParameterSource.KeywordOnly;
17899
+ return i >= destDetails.argsIndex && p.kind === parameterUtils_1.ParameterKind.Keyword;
17908
17900
  });
17909
17901
  if (srcLastToPackIndex < 0) {
17910
17902
  srcLastToPackIndex = srcDetails.params.length;
17911
17903
  }
17904
+ // If both the source and dest have an *args parameter but the dest's is
17905
+ // in a later position, then we can't assign the source's *args to the dest.
17906
+ // Don't make any adjustment in this case.
17907
+ if (srcDetails.argsIndex !== undefined && destDetails.argsIndex > srcDetails.argsIndex) {
17908
+ return;
17909
+ }
17912
17910
  const destFirstNonPositional = (_a = destDetails.firstKeywordOnlyIndex) !== null && _a !== void 0 ? _a : destDetails.params.length;
17913
17911
  const suffixLength = destFirstNonPositional - destDetails.argsIndex - 1;
17914
17912
  const srcPositionalsToPack = srcDetails.params.slice(destDetails.argsIndex, srcLastToPackIndex - suffixLength);
@@ -17946,7 +17944,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17946
17944
  },
17947
17945
  type: srcPositionalsType,
17948
17946
  index: -1,
17949
- source: parameterUtils_1.ParameterSource.PositionOnly,
17947
+ kind: parameterUtils_1.ParameterKind.Positional,
17950
17948
  },
17951
17949
  ...srcDetails.params.slice(destDetails.argsIndex + srcPositionalsToPack.length, srcDetails.params.length),
17952
17950
  ];
@@ -17954,15 +17952,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17954
17952
  srcDetails.argsIndex = argsIndex >= 0 ? argsIndex : undefined;
17955
17953
  const kwargsIndex = srcDetails.params.findIndex((param) => param.param.category === 2 /* ParameterCategory.KwargsDict */);
17956
17954
  srcDetails.kwargsIndex = kwargsIndex >= 0 ? kwargsIndex : undefined;
17957
- const firstKeywordOnlyIndex = srcDetails.params.findIndex((param) => param.source === parameterUtils_1.ParameterSource.KeywordOnly);
17955
+ const firstKeywordOnlyIndex = srcDetails.params.findIndex((param) => param.kind === parameterUtils_1.ParameterKind.Keyword);
17958
17956
  srcDetails.firstKeywordOnlyIndex = firstKeywordOnlyIndex >= 0 ? firstKeywordOnlyIndex : undefined;
17959
- srcDetails.positionOnlyParamCount = Math.max(0, srcDetails.params.findIndex((p) => p.source !== parameterUtils_1.ParameterSource.PositionOnly ||
17957
+ srcDetails.positionOnlyParamCount = Math.max(0, srcDetails.params.findIndex((p) => p.kind !== parameterUtils_1.ParameterKind.Positional ||
17960
17958
  p.param.category !== 0 /* ParameterCategory.Simple */ ||
17961
17959
  p.param.hasDefault));
17962
17960
  }
17963
17961
  }
17964
17962
  function assignFunction(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
17965
- var _a, _b, _c, _d, _e, _f, _g, _h;
17963
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
17966
17964
  let canAssign = true;
17967
17965
  const checkReturnType = (flags & 64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */) === 0;
17968
17966
  const reverseMatching = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) !== 0;
@@ -17998,11 +17996,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17998
17996
  const destParamName = (_c = destParam.param.name) !== null && _c !== void 0 ? _c : '';
17999
17997
  const srcParamName = (_d = srcParam.param.name) !== null && _d !== void 0 ? _d : '';
18000
17998
  if (destParamName) {
18001
- const isDestPositionalOnly = destParam.source === parameterUtils_1.ParameterSource.PositionOnly;
17999
+ const isDestPositionalOnly = destParam.kind === parameterUtils_1.ParameterKind.Positional;
18002
18000
  if (!isDestPositionalOnly &&
18003
18001
  destParam.param.category !== 1 /* ParameterCategory.ArgsList */ &&
18004
18002
  srcParam.param.category !== 1 /* ParameterCategory.ArgsList */) {
18005
- if (srcParam.source === parameterUtils_1.ParameterSource.PositionOnly) {
18003
+ if (srcParam.kind === parameterUtils_1.ParameterKind.Positional) {
18006
18004
  diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionParamPositionOnly().format({
18007
18005
  name: destParamName,
18008
18006
  }));
@@ -18036,7 +18034,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18036
18034
  destParam.param.hasDeclaredType) {
18037
18035
  continue;
18038
18036
  }
18039
- if (!assignFunctionParameter(destParamType, srcParamType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18037
+ if ((0, types_1.isUnpacked)(srcParamType)) {
18038
+ canAssign = false;
18039
+ }
18040
+ else if (!assignFunctionParameter(destParamType, srcParamType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18040
18041
  // Handle the special case where the source parameter is a synthesized
18041
18042
  // TypeVar for "self" or "cls".
18042
18043
  if ((flags & 512 /* AssignTypeFlags.SkipSelfClsTypeCheck */) === 0 ||
@@ -18045,6 +18046,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18045
18046
  canAssign = false;
18046
18047
  }
18047
18048
  }
18049
+ else if (destParam.kind !== parameterUtils_1.ParameterKind.Positional &&
18050
+ srcParam.kind === parameterUtils_1.ParameterKind.Positional &&
18051
+ srcParamDetails.kwargsIndex === undefined &&
18052
+ !srcParamDetails.params.some((p) => p.kind === parameterUtils_1.ParameterKind.Keyword &&
18053
+ p.param.category === 0 /* ParameterCategory.Simple */ &&
18054
+ p.param.name === destParam.param.name)) {
18055
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.namedParamMissingInSource().format({
18056
+ name: (_e = destParam.param.name) !== null && _e !== void 0 ? _e : '',
18057
+ }));
18058
+ canAssign = false;
18059
+ }
18048
18060
  }
18049
18061
  if (!types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType) &&
18050
18062
  destParamDetails.firstPositionOrKeywordIndex < srcParamDetails.positionOnlyParamCount &&
@@ -18055,36 +18067,50 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18055
18067
  }));
18056
18068
  canAssign = false;
18057
18069
  }
18058
- if (destPositionalCount < srcPositionalCount) {
18059
- // If the dest type includes a ParamSpec, the additional parameters
18060
- // can be assigned to it, so no need to report an error here.
18061
- if (!targetIncludesParamSpec) {
18062
- const nonDefaultSrcParamCount = srcParamDetails.params.filter((p) => !!p.param.name && !p.param.hasDefault && p.param.category === 0 /* ParameterCategory.Simple */).length;
18063
- if (destParamDetails.argsIndex === undefined) {
18064
- if (destPositionalCount < nonDefaultSrcParamCount) {
18065
- if (destParamDetails.firstPositionOrKeywordIndex > 0 &&
18066
- destParamDetails.firstPositionOrKeywordIndex < srcPositionalCount) {
18067
- diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionTooFewParams().format({
18068
- expected: nonDefaultSrcParamCount,
18069
- received: destPositionalCount,
18070
- }));
18071
- canAssign = false;
18072
- }
18070
+ if (destPositionalCount < srcPositionalCount && !targetIncludesParamSpec) {
18071
+ for (let i = destPositionalCount; i < srcPositionalCount; i++) {
18072
+ // If the dest has an *args parameter, make sure it can accept the remaining
18073
+ // positional arguments in the source.
18074
+ if (destParamDetails.argsIndex !== undefined) {
18075
+ const destArgsType = destParamDetails.params[destParamDetails.argsIndex].type;
18076
+ const srcParamType = srcParamDetails.params[i].type;
18077
+ if (!assignFunctionParameter(destArgsType, srcParamType, i, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18078
+ canAssign = false;
18073
18079
  }
18080
+ continue;
18074
18081
  }
18075
- else {
18076
- // Make sure the remaining positional arguments are of the
18077
- // correct type for the *args parameter.
18078
- const destArgsType = destParamDetails.params[destParamDetails.argsIndex].type;
18079
- if (!(0, types_1.isAnyOrUnknown)(destArgsType)) {
18080
- for (let paramIndex = destPositionalCount; paramIndex < srcPositionalCount; paramIndex++) {
18081
- const srcParamType = srcParamDetails.params[paramIndex].type;
18082
- if (!assignFunctionParameter(destArgsType, srcParamType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18083
- canAssign = false;
18084
- }
18085
- }
18082
+ // If The source parameter has a default value, it is OK for the
18083
+ // corresponding dest parameter to be missing.
18084
+ const srcParam = srcParamDetails.params[i];
18085
+ if (srcParam.param.hasDefault) {
18086
+ // Assign default arg value in case it is needed for
18087
+ // populating TypeVar constraints.
18088
+ const paramInfo = srcParamDetails.params[i];
18089
+ const defaultArgType = (_f = paramInfo.defaultArgType) !== null && _f !== void 0 ? _f : paramInfo.param.defaultType;
18090
+ if (defaultArgType &&
18091
+ !assignType(paramInfo.type, defaultArgType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), srcTypeVarContext,
18092
+ /* destTypeVarContext */ undefined, flags, recursionCount)) {
18093
+ canAssign = false;
18086
18094
  }
18095
+ continue;
18096
+ }
18097
+ // If the source parameter is also addressible by keyword, it is OK
18098
+ // that there is no matching positional parameter in the dest.
18099
+ if (srcParam.kind === parameterUtils_1.ParameterKind.Standard) {
18100
+ continue;
18101
+ }
18102
+ // If the source parameter is a variadic, it is OK that there is no
18103
+ // matching positional parameter in the dest.
18104
+ if (srcParam.param.category === 1 /* ParameterCategory.ArgsList */) {
18105
+ continue;
18087
18106
  }
18107
+ const nonDefaultSrcParamCount = srcParamDetails.params.filter((p) => !!p.param.name && !p.param.hasDefault && p.param.category === 0 /* ParameterCategory.Simple */).length;
18108
+ diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionTooFewParams().format({
18109
+ expected: nonDefaultSrcParamCount,
18110
+ received: destPositionalCount,
18111
+ }));
18112
+ canAssign = false;
18113
+ break;
18088
18114
  }
18089
18115
  }
18090
18116
  else if (srcPositionalCount < destPositionalCount) {
@@ -18105,10 +18131,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18105
18131
  if (!assignFunctionParameter(destParamType, srcArgsType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18106
18132
  canAssign = false;
18107
18133
  }
18108
- if (destParamDetails.params[paramIndex].source !== parameterUtils_1.ParameterSource.PositionOnly &&
18134
+ if (destParamDetails.params[paramIndex].kind !== parameterUtils_1.ParameterKind.Positional &&
18109
18135
  srcParamDetails.kwargsIndex === undefined) {
18110
18136
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.namedParamMissingInSource().format({
18111
- name: (_e = destParamDetails.params[paramIndex].param.name) !== null && _e !== void 0 ? _e : '',
18137
+ name: (_g = destParamDetails.params[paramIndex].param.name) !== null && _g !== void 0 ? _g : '',
18112
18138
  }));
18113
18139
  canAssign = false;
18114
18140
  }
@@ -18156,7 +18182,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18156
18182
  destParamDetails.argsIndex !== undefined &&
18157
18183
  !destParamDetails.hasUnpackedVariadicTypeVar) {
18158
18184
  diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.argsParamMissing().format({
18159
- paramName: (_f = destParamDetails.params[destParamDetails.argsIndex].param.name) !== null && _f !== void 0 ? _f : '',
18185
+ paramName: (_h = destParamDetails.params[destParamDetails.argsIndex].param.name) !== null && _h !== void 0 ? _h : '',
18160
18186
  }));
18161
18187
  canAssign = false;
18162
18188
  }
@@ -18183,16 +18209,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18183
18209
  }
18184
18210
  if (srcStartOfNamed >= 0) {
18185
18211
  srcParamDetails.params.forEach((srcParamInfo, index) => {
18212
+ var _a;
18186
18213
  if (index >= srcStartOfNamed) {
18187
18214
  if (srcParamInfo.param.name &&
18188
18215
  srcParamInfo.param.category === 0 /* ParameterCategory.Simple */ &&
18189
- srcParamInfo.source !== parameterUtils_1.ParameterSource.PositionOnly) {
18216
+ srcParamInfo.kind !== parameterUtils_1.ParameterKind.Positional) {
18190
18217
  const destParamInfo = destParamMap.get(srcParamInfo.param.name);
18191
18218
  const paramDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
18192
18219
  const srcParamType = srcParamInfo.type;
18193
18220
  if (!destParamInfo) {
18194
18221
  if (destParamDetails.kwargsIndex === undefined && !srcParamInfo.param.hasDefault) {
18195
- if (paramDiag && srcParamDetails.firstKeywordOnlyIndex !== undefined) {
18222
+ if (paramDiag) {
18196
18223
  paramDiag.addMessage(localize_1.LocAddendum.namedParamMissingInDest().format({
18197
18224
  name: srcParamInfo.param.name,
18198
18225
  }));
@@ -18205,6 +18232,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18205
18232
  canAssign = false;
18206
18233
  }
18207
18234
  }
18235
+ else if (srcParamInfo.param.hasDefault) {
18236
+ // Assign default arg values in case they are needed for
18237
+ // populating TypeVar constraints.
18238
+ const defaultArgType = (_a = srcParamInfo.defaultArgType) !== null && _a !== void 0 ? _a : srcParamInfo.param.defaultType;
18239
+ if (defaultArgType &&
18240
+ !assignType(srcParamInfo.type, defaultArgType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), srcTypeVarContext,
18241
+ /* destTypeVarContext */ undefined, flags, recursionCount)) {
18242
+ canAssign = false;
18243
+ }
18244
+ }
18208
18245
  }
18209
18246
  else {
18210
18247
  const destParamType = destParamInfo.type;
@@ -18269,7 +18306,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18269
18306
  // If the source and the dest are using the same ParamSpec, any additional
18270
18307
  // concatenated parameters must match.
18271
18308
  if (targetIncludesParamSpec &&
18272
- ((_g = srcType.details.paramSpec) === null || _g === void 0 ? void 0 : _g.nameWithScope) === ((_h = destType.details.paramSpec) === null || _h === void 0 ? void 0 : _h.nameWithScope)) {
18309
+ ((_j = srcType.details.paramSpec) === null || _j === void 0 ? void 0 : _j.nameWithScope) === ((_k = destType.details.paramSpec) === null || _k === void 0 ? void 0 : _k.nameWithScope)) {
18273
18310
  if (srcParamDetails.params.length !== destParamDetails.params.length) {
18274
18311
  canAssign = false;
18275
18312
  }
@@ -18739,13 +18776,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18739
18776
  const overrideParam = overrideParamDetails.params[i].param;
18740
18777
  if (i >= baseParamDetails.positionOnlyParamCount &&
18741
18778
  !(0, symbolNameUtils_1.isPrivateOrProtectedName)(baseParam.name || '') &&
18742
- baseParamDetails.params[i].source !== parameterUtils_1.ParameterSource.PositionOnly &&
18779
+ baseParamDetails.params[i].kind !== parameterUtils_1.ParameterKind.Positional &&
18743
18780
  baseParam.category === 0 /* ParameterCategory.Simple */ &&
18744
18781
  enforceParamNames &&
18745
18782
  baseParam.name !== overrideParam.name) {
18746
18783
  if (overrideParam.category === 0 /* ParameterCategory.Simple */) {
18747
18784
  if (!baseParam.isNameSynthesized) {
18748
- if (overrideParamDetails.params[i].source === parameterUtils_1.ParameterSource.PositionOnly) {
18785
+ if (overrideParamDetails.params[i].kind === parameterUtils_1.ParameterKind.Positional) {
18749
18786
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
18750
18787
  index: i + 1,
18751
18788
  baseName: baseParam.name || '*',
@@ -18764,8 +18801,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18764
18801
  }
18765
18802
  else if (i < overrideParamDetails.positionOnlyParamCount &&
18766
18803
  i >= baseParamDetails.positionOnlyParamCount) {
18767
- if (!baseParam.isNameSynthesized &&
18768
- baseParamDetails.params[i].source !== parameterUtils_1.ParameterSource.PositionOnly) {
18804
+ if (!baseParam.isNameSynthesized && baseParamDetails.params[i].kind !== parameterUtils_1.ParameterKind.Positional) {
18769
18805
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
18770
18806
  index: i + 1,
18771
18807
  baseName: baseParam.name || '*',
@@ -18803,7 +18839,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18803
18839
  if (enforceParamNames && overrideParamDetails.kwargsIndex === undefined) {
18804
18840
  for (let i = positionalParamCount; i < baseParamDetails.positionParamCount; i++) {
18805
18841
  const baseParam = baseParamDetails.params[i];
18806
- if (baseParam.source === parameterUtils_1.ParameterSource.PositionOrKeyword &&
18842
+ if (baseParam.kind === parameterUtils_1.ParameterKind.Standard &&
18807
18843
  baseParam.param.category === 0 /* ParameterCategory.Simple */) {
18808
18844
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
18809
18845
  index: i + 1,
@@ -18836,10 +18872,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18836
18872
  }
18837
18873
  }
18838
18874
  // Now check any keyword-only parameters.
18839
- const baseKwOnlyParams = baseParamDetails.params.filter((paramInfo) => paramInfo.source === parameterUtils_1.ParameterSource.KeywordOnly &&
18840
- paramInfo.param.category === 0 /* ParameterCategory.Simple */);
18841
- const overrideKwOnlyParams = overrideParamDetails.params.filter((paramInfo) => paramInfo.source === parameterUtils_1.ParameterSource.KeywordOnly &&
18842
- paramInfo.param.category === 0 /* ParameterCategory.Simple */);
18875
+ const baseKwOnlyParams = baseParamDetails.params.filter((paramInfo) => paramInfo.kind === parameterUtils_1.ParameterKind.Keyword && paramInfo.param.category === 0 /* ParameterCategory.Simple */);
18876
+ const overrideKwOnlyParams = overrideParamDetails.params.filter((paramInfo) => paramInfo.kind === parameterUtils_1.ParameterKind.Keyword && paramInfo.param.category === 0 /* ParameterCategory.Simple */);
18843
18877
  baseKwOnlyParams.forEach((paramInfo) => {
18844
18878
  var _a, _b, _c;
18845
18879
  const overrideParamInfo = overrideKwOnlyParams.find((pi) => paramInfo.param.name === pi.param.name);