@zzzen/pyright-internal 1.2.0-dev.20230416 → 1.2.0-dev.20230430

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 (224) hide show
  1. package/dist/analyzer/analyzerFileInfo.d.ts +4 -1
  2. package/dist/analyzer/analyzerFileInfo.js.map +1 -1
  3. package/dist/analyzer/backgroundAnalysisProgram.d.ts +4 -4
  4. package/dist/analyzer/backgroundAnalysisProgram.js +10 -7
  5. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  6. package/dist/analyzer/binder.js +13 -10
  7. package/dist/analyzer/binder.js.map +1 -1
  8. package/dist/analyzer/checker.js +6 -3
  9. package/dist/analyzer/checker.js.map +1 -1
  10. package/dist/analyzer/codeFlowEngine.js +17 -0
  11. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  12. package/dist/analyzer/commentUtils.d.ts +1 -1
  13. package/dist/analyzer/commentUtils.js +18 -3
  14. package/dist/analyzer/commentUtils.js.map +1 -1
  15. package/dist/analyzer/dataClasses.js +5 -2
  16. package/dist/analyzer/dataClasses.js.map +1 -1
  17. package/dist/analyzer/declarationUtils.d.ts +6 -1
  18. package/dist/analyzer/declarationUtils.js +10 -8
  19. package/dist/analyzer/declarationUtils.js.map +1 -1
  20. package/dist/analyzer/docStringConversion.js +2 -3
  21. package/dist/analyzer/docStringConversion.js.map +1 -1
  22. package/dist/analyzer/importResolver.d.ts +15 -15
  23. package/dist/analyzer/importResolver.js +477 -477
  24. package/dist/analyzer/importResolver.js.map +1 -1
  25. package/dist/analyzer/namedTuples.d.ts +1 -1
  26. package/dist/analyzer/namedTuples.js +29 -41
  27. package/dist/analyzer/namedTuples.js.map +1 -1
  28. package/dist/analyzer/packageTypeReport.d.ts +2 -1
  29. package/dist/analyzer/packageTypeReport.js +2 -1
  30. package/dist/analyzer/packageTypeReport.js.map +1 -1
  31. package/dist/analyzer/packageTypeVerifier.d.ts +1 -1
  32. package/dist/analyzer/packageTypeVerifier.js +27 -13
  33. package/dist/analyzer/packageTypeVerifier.js.map +1 -1
  34. package/dist/analyzer/patternMatching.d.ts +6 -2
  35. package/dist/analyzer/patternMatching.js +108 -2
  36. package/dist/analyzer/patternMatching.js.map +1 -1
  37. package/dist/analyzer/program.d.ts +34 -44
  38. package/dist/analyzer/program.js +1382 -1529
  39. package/dist/analyzer/program.js.map +1 -1
  40. package/dist/analyzer/protocols.js +1 -1
  41. package/dist/analyzer/protocols.js.map +1 -1
  42. package/dist/analyzer/service.d.ts +14 -27
  43. package/dist/analyzer/service.js +81 -114
  44. package/dist/analyzer/service.js.map +1 -1
  45. package/dist/analyzer/sourceFile.d.ts +7 -21
  46. package/dist/analyzer/sourceFile.js +58 -130
  47. package/dist/analyzer/sourceFile.js.map +1 -1
  48. package/dist/analyzer/sourceFileInfoUtils.d.ts +7 -1
  49. package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
  50. package/dist/analyzer/typeEvaluator.js +398 -334
  51. package/dist/analyzer/typeEvaluator.js.map +1 -1
  52. package/dist/analyzer/typeEvaluatorTypes.d.ts +6 -3
  53. package/dist/analyzer/typeEvaluatorTypes.js +0 -2
  54. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  55. package/dist/analyzer/typeGuards.d.ts +2 -0
  56. package/dist/analyzer/typeGuards.js +175 -176
  57. package/dist/analyzer/typeGuards.js.map +1 -1
  58. package/dist/analyzer/typeStubWriter.js.map +1 -1
  59. package/dist/analyzer/typeUtils.d.ts +1 -0
  60. package/dist/analyzer/typeUtils.js +44 -17
  61. package/dist/analyzer/typeUtils.js.map +1 -1
  62. package/dist/analyzer/types.js +10 -2
  63. package/dist/analyzer/types.js.map +1 -1
  64. package/dist/backgroundAnalysisBase.d.ts +10 -11
  65. package/dist/backgroundAnalysisBase.js +87 -87
  66. package/dist/backgroundAnalysisBase.js.map +1 -1
  67. package/dist/commands/dumpFileDebugInfoCommand.js +8 -8
  68. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  69. package/dist/commands/quickActionCommand.js +4 -1
  70. package/dist/commands/quickActionCommand.js.map +1 -1
  71. package/dist/common/cancellationUtils.d.ts +1 -1
  72. package/dist/common/cancellationUtils.js +9 -9
  73. package/dist/common/cancellationUtils.js.map +1 -1
  74. package/dist/common/commandLineOptions.d.ts +1 -2
  75. package/dist/common/commandLineOptions.js.map +1 -1
  76. package/dist/common/configOptions.d.ts +2 -2
  77. package/dist/common/configOptions.js.map +1 -1
  78. package/dist/common/console.d.ts +5 -9
  79. package/dist/common/console.js +46 -33
  80. package/dist/common/console.js.map +1 -1
  81. package/dist/common/deferred.js +10 -10
  82. package/dist/common/deferred.js.map +1 -1
  83. package/dist/common/extensibility.d.ts +33 -9
  84. package/dist/common/extensibility.js +1 -1
  85. package/dist/common/extensibility.js.map +1 -1
  86. package/dist/common/fileBasedCancellationUtils.js +5 -5
  87. package/dist/common/fileBasedCancellationUtils.js.map +1 -1
  88. package/dist/common/fileSystem.d.ts +12 -10
  89. package/dist/common/fileSystem.js.map +1 -1
  90. package/dist/common/fullAccessHost.d.ts +3 -3
  91. package/dist/common/fullAccessHost.js +6 -6
  92. package/dist/common/fullAccessHost.js.map +1 -1
  93. package/dist/common/pathUtils.d.ts +2 -2
  94. package/dist/common/pathUtils.js.map +1 -1
  95. package/dist/common/realFileSystem.js +12 -7
  96. package/dist/common/realFileSystem.js.map +1 -1
  97. package/dist/common/uriParser.d.ts +2 -2
  98. package/dist/common/uriParser.js +3 -3
  99. package/dist/common/uriParser.js.map +1 -1
  100. package/dist/common/workspaceEditUtils.js +7 -4
  101. package/dist/common/workspaceEditUtils.js.map +1 -1
  102. package/dist/languageServerBase.d.ts +32 -30
  103. package/dist/languageServerBase.js +276 -337
  104. package/dist/languageServerBase.js.map +1 -1
  105. package/dist/languageService/analyzerServiceExecutor.js +0 -1
  106. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  107. package/dist/languageService/callHierarchyProvider.d.ts +16 -12
  108. package/dist/languageService/callHierarchyProvider.js +138 -41
  109. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  110. package/dist/languageService/completionProvider.js +119 -10
  111. package/dist/languageService/completionProvider.js.map +1 -1
  112. package/dist/languageService/definitionProvider.d.ts +23 -9
  113. package/dist/languageService/definitionProvider.js +116 -91
  114. package/dist/languageService/definitionProvider.js.map +1 -1
  115. package/dist/languageService/documentHighlightProvider.d.ts +8 -3
  116. package/dist/languageService/documentHighlightProvider.js +17 -6
  117. package/dist/languageService/documentHighlightProvider.js.map +1 -1
  118. package/dist/languageService/documentSymbolCollector.d.ts +2 -2
  119. package/dist/languageService/documentSymbolCollector.js +4 -3
  120. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  121. package/dist/languageService/documentSymbolProvider.js +5 -3
  122. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  123. package/dist/languageService/hoverProvider.d.ts +28 -28
  124. package/dist/languageService/hoverProvider.js +142 -120
  125. package/dist/languageService/hoverProvider.js.map +1 -1
  126. package/dist/languageService/importAdder.d.ts +13 -2
  127. package/dist/languageService/importAdder.js +73 -26
  128. package/dist/languageService/importAdder.js.map +1 -1
  129. package/dist/languageService/indentationUtils.js +6 -1
  130. package/dist/languageService/indentationUtils.js.map +1 -1
  131. package/dist/languageService/insertionPointUtils.js +3 -3
  132. package/dist/languageService/insertionPointUtils.js.map +1 -1
  133. package/dist/languageService/navigationUtils.d.ts +6 -0
  134. package/dist/languageService/navigationUtils.js +28 -0
  135. package/dist/languageService/navigationUtils.js.map +1 -0
  136. package/dist/languageService/quickActions.d.ts +2 -2
  137. package/dist/languageService/quickActions.js +12 -1
  138. package/dist/languageService/quickActions.js.map +1 -1
  139. package/dist/languageService/referencesProvider.d.ts +8 -2
  140. package/dist/languageService/referencesProvider.js +81 -3
  141. package/dist/languageService/referencesProvider.js.map +1 -1
  142. package/dist/languageService/renameModuleProvider.d.ts +13 -13
  143. package/dist/languageService/renameModuleProvider.js +43 -43
  144. package/dist/languageService/renameModuleProvider.js.map +1 -1
  145. package/dist/languageService/signatureHelpProvider.d.ts +19 -23
  146. package/dist/languageService/signatureHelpProvider.js +111 -18
  147. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  148. package/dist/localization/localize.d.ts +2 -0
  149. package/dist/localization/localize.js +2 -0
  150. package/dist/localization/localize.js.map +1 -1
  151. package/dist/localization/package.nls.en-us.json +2 -0
  152. package/dist/parser/characterStream.d.ts +3 -3
  153. package/dist/parser/characterStream.js +12 -12
  154. package/dist/parser/characterStream.js.map +1 -1
  155. package/dist/parser/parser.d.ts +1 -1
  156. package/dist/parser/parser.js.map +1 -1
  157. package/dist/pyright.js +57 -54
  158. package/dist/pyright.js.map +1 -1
  159. package/dist/pyrightFileSystem.d.ts +1 -1
  160. package/dist/pyrightFileSystem.js +21 -21
  161. package/dist/pyrightFileSystem.js.map +1 -1
  162. package/dist/readonlyAugmentedFileSystem.d.ts +6 -6
  163. package/dist/readonlyAugmentedFileSystem.js +28 -28
  164. package/dist/readonlyAugmentedFileSystem.js.map +1 -1
  165. package/dist/server.js +6 -6
  166. package/dist/server.js.map +1 -1
  167. package/dist/tests/chainedSourceFiles.test.js +1 -1
  168. package/dist/tests/chainedSourceFiles.test.js.map +1 -1
  169. package/dist/tests/checker.test.js +2 -2
  170. package/dist/tests/completions.test.js +173 -0
  171. package/dist/tests/completions.test.js.map +1 -1
  172. package/dist/tests/docStringConversion.test.js +11 -1
  173. package/dist/tests/docStringConversion.test.js.map +1 -1
  174. package/dist/tests/fourslash/completions.override2.fourslash.js +15 -0
  175. package/dist/tests/fourslash/completions.override2.fourslash.js.map +1 -1
  176. package/dist/tests/fourslash/fourslash.d.ts +11 -1
  177. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedFunction.fourslash.js +5 -6
  178. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedFunction.fourslash.js.map +1 -1
  179. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedVariable.fourslash.js +1 -4
  180. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.aliasedVariable.fourslash.js.map +1 -1
  181. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.function.fourslash.js +10 -9
  182. package/dist/tests/fourslash/showcallhierarchy.incomingCalls.function.fourslash.js.map +1 -1
  183. package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.aliasedFunction1.fourslash.d.ts +1 -0
  184. package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.aliasedFunction1.fourslash.js +54 -0
  185. package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.aliasedFunction1.fourslash.js.map +1 -0
  186. package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.aliasedFunction2.fourslash.d.ts +1 -0
  187. package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.aliasedFunction2.fourslash.js +46 -0
  188. package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.aliasedFunction2.fourslash.js.map +1 -0
  189. package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.function.fourslash.d.ts +1 -0
  190. package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.function.fourslash.js +39 -0
  191. package/dist/tests/fourslash/showcallhierarchy.outgoingCalls.function.fourslash.js.map +1 -0
  192. package/dist/tests/harness/fourslash/testLanguageService.d.ts +3 -3
  193. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  194. package/dist/tests/harness/fourslash/testState.d.ts +14 -9
  195. package/dist/tests/harness/fourslash/testState.js +144 -102
  196. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  197. package/dist/tests/harness/vfs/filesystem.d.ts +8 -8
  198. package/dist/tests/harness/vfs/filesystem.js +68 -68
  199. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  200. package/dist/tests/importAdder.test.js +69 -1
  201. package/dist/tests/importAdder.test.js.map +1 -1
  202. package/dist/tests/importStatementUtils.test.js +34 -0
  203. package/dist/tests/importStatementUtils.test.js.map +1 -1
  204. package/dist/tests/indentationUtils.ptvs.test.js +2 -2
  205. package/dist/tests/indentationUtils.ptvs.test.js.map +1 -1
  206. package/dist/tests/indentationUtils.test.js +18 -0
  207. package/dist/tests/indentationUtils.test.js.map +1 -1
  208. package/dist/tests/moveSymbol.updateReference.test.js +14 -0
  209. package/dist/tests/moveSymbol.updateReference.test.js.map +1 -1
  210. package/dist/tests/signatureHelp.test.js +5 -1
  211. package/dist/tests/signatureHelp.test.js.map +1 -1
  212. package/dist/tests/sourceFile.test.js +1 -1
  213. package/dist/tests/sourceFile.test.js.map +1 -1
  214. package/dist/tests/testStateUtils.js +1 -1
  215. package/dist/tests/testStateUtils.js.map +1 -1
  216. package/dist/tests/typeEvaluator1.test.js +8 -0
  217. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  218. package/dist/tests/typeEvaluator2.test.js +12 -0
  219. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  220. package/dist/tests/typeEvaluator3.test.js +7 -1
  221. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  222. package/dist/tests/typeEvaluator4.test.js +5 -1
  223. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  224. package/package.json +1 -1
@@ -751,9 +751,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
751
751
  if ((flags & 1 /* ConvertEllipsisToAny */) !== 0) {
752
752
  typeResult = { type: types_1.AnyType.create(/* isEllipsis */ true) };
753
753
  }
754
- else if ((flags & 512 /* ConvertEllipsisToUnknown */) !== 0) {
755
- typeResult = { type: types_1.UnknownType.create() };
756
- }
757
754
  else {
758
755
  const ellipsisType = getBuiltInObject(node, 'ellipsis') || types_1.AnyType.create();
759
756
  typeResult = { type: ellipsisType };
@@ -5751,7 +5748,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5751
5748
  // Use speculative mode so we don't output any diagnostics or
5752
5749
  // record any final types in the type cache.
5753
5750
  const callResult = useSpeculativeMode(errorNode, () => {
5754
- return validateFunctionArgumentTypesWithExpectedType(errorNode, matchResults, effectiveTypeVarContext,
5751
+ return validateFunctionArgumentTypesWithContext(errorNode, matchResults, effectiveTypeVarContext,
5755
5752
  /* skipUnknownArgCheck */ true, inferenceContext);
5756
5753
  });
5757
5754
  if (callResult.isTypeIncomplete) {
@@ -5835,7 +5832,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5835
5832
  const finalTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : matchedOverloads[0].typeVarContext;
5836
5833
  finalTypeVarContext.unlock();
5837
5834
  finalTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(matchedOverloads[0].overload));
5838
- const finalCallResult = validateFunctionArgumentTypesWithExpectedType(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck, inferenceContext);
5835
+ const finalCallResult = validateFunctionArgumentTypesWithContext(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck, inferenceContext);
5839
5836
  if (finalCallResult.isTypeIncomplete) {
5840
5837
  isTypeIncomplete = true;
5841
5838
  }
@@ -5963,7 +5960,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5963
5960
  effectiveTypeVarContext.addSolveForScope(lastMatch.overload.details.constructorTypeVarScopeId);
5964
5961
  }
5965
5962
  effectiveTypeVarContext.unlock();
5966
- return validateFunctionArgumentTypesWithExpectedType(errorNode, lastMatch, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
5963
+ return validateFunctionArgumentTypesWithContext(errorNode, lastMatch, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
5967
5964
  };
5968
5965
  // If there is only one possible arg/param match among the overloads,
5969
5966
  // use the normal type matching mechanism because it is faster and
@@ -6096,13 +6093,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6096
6093
  // for each of the subtypes that comprise the expected type. If
6097
6094
  // one or more analyzes with no errors, use those results.
6098
6095
  if (inferenceContext) {
6099
- const expectedCallResult = validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, initMethodType);
6096
+ const expectedCallResult = validateConstructorMethodWithContext(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, initMethodType);
6100
6097
  if (expectedCallResult && !expectedCallResult.argumentErrors) {
6101
6098
  returnType = expectedCallResult.returnType;
6102
6099
  if (expectedCallResult.isTypeIncomplete) {
6103
6100
  isTypeIncomplete = true;
6104
6101
  }
6105
- overloadsUsedForCall.push(...expectedCallResult.overloadsUsedForCall);
6106
6102
  }
6107
6103
  }
6108
6104
  if (!returnType) {
@@ -6111,18 +6107,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6111
6107
  : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type));
6112
6108
  typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(initMethodType));
6113
6109
  const callResult = validateCallArguments(errorNode, argList, { type: initMethodType }, typeVarContext, skipUnknownArgCheck);
6110
+ let adjustedClassType = type;
6111
+ if (callResult.specializedInitSelfType &&
6112
+ (0, types_1.isClassInstance)(callResult.specializedInitSelfType) &&
6113
+ types_1.ClassType.isSameGenericClass(callResult.specializedInitSelfType, type)) {
6114
+ adjustedClassType = types_1.ClassType.cloneAsInstantiable(callResult.specializedInitSelfType);
6115
+ }
6116
+ returnType = applyExpectedTypeForConstructor(adjustedClassType,
6117
+ /* inferenceContext */ undefined, typeVarContext);
6118
+ if (callResult.isTypeIncomplete) {
6119
+ isTypeIncomplete = true;
6120
+ }
6114
6121
  if (!callResult.argumentErrors) {
6115
- let adjustedClassType = type;
6116
- if (callResult.specializedInitSelfType &&
6117
- (0, types_1.isClassInstance)(callResult.specializedInitSelfType) &&
6118
- types_1.ClassType.isSameGenericClass(callResult.specializedInitSelfType, type)) {
6119
- adjustedClassType = types_1.ClassType.cloneAsInstantiable(callResult.specializedInitSelfType);
6120
- }
6121
- returnType = applyExpectedTypeForConstructor(adjustedClassType,
6122
- /* inferenceContext */ undefined, typeVarContext);
6123
- if (callResult.isTypeIncomplete) {
6124
- isTypeIncomplete = true;
6125
- }
6126
6122
  overloadsUsedForCall.push(...callResult.overloadsUsedForCall);
6127
6123
  }
6128
6124
  else {
@@ -6163,7 +6159,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6163
6159
  // If there is an expected type that was not applied above when
6164
6160
  // handling the __init__ method, try to apply it with the __new__ method.
6165
6161
  if (inferenceContext && !returnType) {
6166
- const expectedCallResult = validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, constructorMethodType);
6162
+ const expectedCallResult = validateConstructorMethodWithContext(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, constructorMethodType);
6167
6163
  if (expectedCallResult && !expectedCallResult.argumentErrors) {
6168
6164
  newReturnType = expectedCallResult.returnType;
6169
6165
  returnType = newReturnType;
@@ -6198,6 +6194,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6198
6194
  }
6199
6195
  else if (!newReturnType) {
6200
6196
  newReturnType = callResult.returnType;
6197
+ if (overloadsUsedForCall.length === 0) {
6198
+ overloadsUsedForCall.push(...callResult.overloadsUsedForCall);
6199
+ }
6201
6200
  // If the constructor returned an object whose type matches the class of
6202
6201
  // the original type being constructed, use the return type in case it was
6203
6202
  // specialized. If it doesn't match, we'll fall back on the assumption that
@@ -6304,22 +6303,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6304
6303
  // For a constructor call that targets a generic class and an "expected type"
6305
6304
  // (i.e. bidirectional inference), this function attempts to infer the correct
6306
6305
  // specialized return type for the constructor.
6307
- function validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, constructorMethodType) {
6306
+ function validateConstructorMethodWithContext(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, constructorMethodType) {
6308
6307
  let isTypeIncomplete = false;
6309
6308
  let argumentErrors = false;
6310
6309
  const overloadsUsedForCall = [];
6311
6310
  const returnType = (0, typeUtils_1.mapSubtypes)(inferenceContext.expectedType, (expectedSubType) => {
6312
6311
  expectedSubType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expectedSubType);
6313
6312
  const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type));
6313
+ typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(constructorMethodType));
6314
6314
  if ((0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(type), expectedSubType, typeVarContext, getTypeVarScopesForNode(errorNode))) {
6315
+ const specializedConstructor = (0, typeUtils_1.applySolvedTypeVars)(constructorMethodType, typeVarContext);
6315
6316
  let callResult;
6316
6317
  useSpeculativeMode(errorNode, () => {
6317
- callResult = validateCallArguments(errorNode, argList, { type: constructorMethodType }, typeVarContext.clone(), skipUnknownArgCheck);
6318
+ callResult = validateCallArguments(errorNode, argList, { type: specializedConstructor }, typeVarContext.clone(), skipUnknownArgCheck);
6318
6319
  });
6319
6320
  if (!callResult.argumentErrors) {
6320
6321
  // Call validateCallArguments again, this time without speculative
6321
6322
  // mode, so any errors are reported.
6322
- callResult = validateCallArguments(errorNode, argList, { type: constructorMethodType }, typeVarContext, skipUnknownArgCheck);
6323
+ callResult = validateCallArguments(errorNode, argList, { type: specializedConstructor }, typeVarContext, skipUnknownArgCheck);
6323
6324
  if (callResult.isTypeIncomplete) {
6324
6325
  isTypeIncomplete = true;
6325
6326
  }
@@ -6327,7 +6328,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6327
6328
  argumentErrors = true;
6328
6329
  }
6329
6330
  overloadsUsedForCall.push(...callResult.overloadsUsedForCall);
6330
- return applyExpectedSubtypeForConstructor(type, expectedSubType, typeVarContext);
6331
+ return applyExpectedSubtypeForConstructor(type, expectedSubType, inferenceContext, typeVarContext);
6331
6332
  }
6332
6333
  }
6333
6334
  return undefined;
@@ -6337,9 +6338,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6337
6338
  }
6338
6339
  return { returnType, isTypeIncomplete, argumentErrors, overloadsUsedForCall };
6339
6340
  }
6340
- function applyExpectedSubtypeForConstructor(type, expectedSubtype, typeVarContext) {
6341
+ function applyExpectedSubtypeForConstructor(type, expectedSubtype, inferenceContext, typeVarContext) {
6342
+ var _a;
6341
6343
  const specializedType = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstance(type), typeVarContext);
6342
- if (!assignType(expectedSubtype, specializedType)) {
6344
+ if (!assignType(expectedSubtype, specializedType,
6345
+ /* diag */ undefined,
6346
+ /* destTypeVarContext */ (_a = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext) === null || _a === void 0 ? void 0 : _a.clone(),
6347
+ /* srcTypeVarContext */ undefined)) {
6343
6348
  return undefined;
6344
6349
  }
6345
6350
  // If the expected type is "Any", transform it to an Any.
@@ -6354,7 +6359,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6354
6359
  let unsolvedTypeVarsAreUnknown = true;
6355
6360
  if (inferenceContext) {
6356
6361
  const specializedExpectedType = (0, typeUtils_1.mapSubtypes)(inferenceContext.expectedType, (expectedSubtype) => {
6357
- return applyExpectedSubtypeForConstructor(type, expectedSubtype, typeVarContext);
6362
+ return applyExpectedSubtypeForConstructor(type, expectedSubtype, inferenceContext, typeVarContext);
6358
6363
  });
6359
6364
  if (!(0, types_1.isNever)(specializedExpectedType)) {
6360
6365
  return specializedExpectedType;
@@ -7578,13 +7583,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7578
7583
  // After having matched arguments with parameters, this function evaluates the
7579
7584
  // types of each argument expression and validates that the resulting type is
7580
7585
  // compatible with the declared type of the corresponding parameter.
7581
- function validateFunctionArgumentTypesWithExpectedType(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
7586
+ function validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
7582
7587
  var _a;
7583
7588
  const type = matchResults.overload;
7584
7589
  if (!inferenceContext ||
7585
7590
  (0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) ||
7586
7591
  (0, types_1.isNever)(inferenceContext.expectedType) ||
7587
- (0, typeUtils_1.requiresSpecialization)(inferenceContext.expectedType) ||
7588
7592
  !type.details.declaredReturnType ||
7589
7593
  !(0, typeUtils_1.requiresSpecialization)((_a = types_1.FunctionType.getSpecializedReturnType(type)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create())) {
7590
7594
  return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, skipUnknownArgCheck);
@@ -7599,17 +7603,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7599
7603
  // We may or may not be able to make use of the expected type. We'll evaluate
7600
7604
  // speculatively to see if using the expected type works.
7601
7605
  if ((0, types_1.isUnion)(inferenceContext.expectedType)) {
7602
- let speculativeResults;
7603
7606
  useSpeculativeMode(errorNode, () => {
7604
7607
  const typeVarContextCopy = typeVarContext.clone();
7605
7608
  assignType(effectiveReturnType, effectiveExpectedType,
7606
7609
  /* diag */ undefined, typeVarContextCopy,
7607
7610
  /* srcTypeVarContext */ undefined, effectiveFlags | 1024 /* PopulatingExpectedType */);
7608
- speculativeResults = validateFunctionArgumentTypes(errorNode, matchResults, typeVarContextCopy, skipUnknownArgCheck);
7611
+ const speculativeResults = validateFunctionArgumentTypes(errorNode, matchResults, typeVarContextCopy, skipUnknownArgCheck);
7612
+ if (speculativeResults === null || speculativeResults === void 0 ? void 0 : speculativeResults.argumentErrors) {
7613
+ effectiveExpectedType = undefined;
7614
+ }
7609
7615
  });
7610
- if (speculativeResults && speculativeResults.argumentErrors) {
7611
- effectiveExpectedType = undefined;
7612
- }
7613
7616
  }
7614
7617
  if (effectiveExpectedType) {
7615
7618
  // Prepopulate the typeVarContext based on the specialized expected type if the
@@ -7628,6 +7631,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7628
7631
  /* isTypeArgumentExplicit */ false);
7629
7632
  effectiveExpectedType = (0, typeUtils_1.applySolvedTypeVars)(genericReturnType, tempTypeVarContext);
7630
7633
  }
7634
+ else if ((0, types_1.isFunction)(effectiveReturnType)) {
7635
+ // If the return type is a callable and the expected type is a union that
7636
+ // includes one or more non-callables, filter those out.
7637
+ if ((0, types_1.isUnion)(effectiveExpectedType)) {
7638
+ effectiveExpectedType = (0, typeUtils_1.mapSubtypes)(effectiveExpectedType, (subtype) => {
7639
+ return (0, typeUtils_1.isCallableType)(subtype) ? subtype : undefined;
7640
+ });
7641
+ }
7642
+ }
7631
7643
  assignType(effectiveReturnType, effectiveExpectedType,
7632
7644
  /* diag */ undefined, typeVarContext,
7633
7645
  /* srcTypeVarContext */ undefined, effectiveFlags | 1024 /* PopulatingExpectedType */);
@@ -7706,12 +7718,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7706
7718
  // is an overload function, skip it during the first pass
7707
7719
  // because the selection of the proper overload may depend
7708
7720
  // on type arguments supplied by other function arguments.
7709
- // Set useNarrowBoundOnly to true the first time through
7710
- // the loop if we're going to go through the loop multiple
7711
- // times.
7712
- const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7713
- /* skipOverloadArg */ i === 0,
7714
- /* isFirstPass */ passCount > 1 && i === 0, typeCondition);
7721
+ // We set useNarrowBoundOnly to true if this is the first
7722
+ // (but not only) pass through the parameter list because a wide
7723
+ // bound on a TypeVar (if a narrow bound has not yet been
7724
+ // established) will unnecessarily constrain the expected type.
7725
+ // If the param type is a "bare" TypeVar, don't use it as an
7726
+ // expected type during the first pass. This causes problems for
7727
+ // cases where the the call expression result can influence the
7728
+ // type of the TypeVar, such as in the expression "min(1, max(2, 0.5))".
7729
+ const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, {
7730
+ skipUnknownArgCheck,
7731
+ skipOverloadArg: i === 0,
7732
+ skipBareTypeVarExpectedType: i === 0,
7733
+ useNarrowBoundOnly: passCount > 1 && i === 0,
7734
+ conditionFilter: typeCondition,
7735
+ });
7715
7736
  if (argResult.isTypeIncomplete) {
7716
7737
  isTypeIncomplete = true;
7717
7738
  }
@@ -7735,9 +7756,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7735
7756
  const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7736
7757
  matchResults.argParams.forEach((argParam) => {
7737
7758
  var _a;
7738
- const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7739
- /* skipOverloadArg */ false,
7740
- /* isFirstPass */ false, typeCondition);
7759
+ const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, {
7760
+ skipUnknownArgCheck,
7761
+ conditionFilter: typeCondition,
7762
+ });
7741
7763
  argResults.push(argResult);
7742
7764
  if (!argResult.isCompatible) {
7743
7765
  argumentErrors = true;
@@ -7907,7 +7929,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7907
7929
  overloadsUsedForCall: [],
7908
7930
  };
7909
7931
  }
7910
- return validateFunctionArgumentTypesWithExpectedType(errorNode, matchResults, typeVarContext, skipUnknownArgCheck, inferenceContext);
7932
+ return validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck, inferenceContext);
7911
7933
  }
7912
7934
  // Determines whether the specified argument list satisfies the function
7913
7935
  // signature bound to the specified ParamSpec. Return value indicates success.
@@ -7958,6 +7980,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7958
7980
  const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* VarArgList */);
7959
7981
  const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* VarArgDictionary */);
7960
7982
  const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7983
+ let sawUnpackedListArgument = false;
7984
+ let sawUnpackedDictArgument = false;
7961
7985
  argList.forEach((arg) => {
7962
7986
  var _a;
7963
7987
  if (arg.argumentCategory === 0 /* Simple */) {
@@ -8005,18 +8029,30 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8005
8029
  argument: arg,
8006
8030
  errorNode: arg.valueExpression || errorNode,
8007
8031
  }, srcTypeVarContext, signatureTracker,
8008
- /* functionType */ undefined,
8009
- /* skipUnknownArgCheck */ false,
8010
- /* skipOverloadArg */ false,
8011
- /* isFirstPass */ false, conditionFilter);
8032
+ /* functionType */ undefined, { conditionFilter });
8012
8033
  if (!argResult.isCompatible) {
8013
8034
  reportedArgError = true;
8014
8035
  }
8015
8036
  }
8016
8037
  }
8038
+ else if (arg.argumentCategory === 1 /* UnpackedList */) {
8039
+ sawUnpackedListArgument = true;
8040
+ // See if there is an *args parameter.
8041
+ const argsParam = paramSpecParams.find((param) => param.category === 1 /* VarArgList */ && param.name);
8042
+ if (argsParam && paramMap.has(argsParam.name)) {
8043
+ // TODO - validate args type
8044
+ paramMap.delete(argsParam.name);
8045
+ }
8046
+ }
8017
8047
  else {
8018
- // TODO - handle *args and **kwargs
8019
- paramMap.clear();
8048
+ sawUnpackedDictArgument = true;
8049
+ (0, debug_1.assert)(arg.argumentCategory === 2 /* UnpackedDictionary */);
8050
+ // See if there is an *kwargs parameter.
8051
+ const kwargsParam = paramSpecParams.find((param) => param.category === 2 /* VarArgDictionary */);
8052
+ if (kwargsParam && paramMap.has(kwargsParam.name)) {
8053
+ // TODO - validate kwargs type
8054
+ paramMap.delete(kwargsParam.name);
8055
+ }
8020
8056
  }
8021
8057
  });
8022
8058
  // Report any missing parameters.
@@ -8027,7 +8063,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8027
8063
  const paramInfo = paramMap.get(name);
8028
8064
  return paramInfo.category === 0 /* Simple */ && !paramInfo.hasDefault;
8029
8065
  });
8030
- if (unassignedParams.length > 0 && !paramSpecType.details.paramSpec) {
8066
+ if (unassignedParams.length > 0 &&
8067
+ !paramSpecType.details.paramSpec &&
8068
+ !sawUnpackedListArgument &&
8069
+ !sawUnpackedDictArgument) {
8031
8070
  const missingParamNames = unassignedParams.map((p) => `"${p}"`).join(', ');
8032
8071
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, unassignedParams.length === 1
8033
8072
  ? localize_1.Localizer.Diagnostic.argMissingForParam().format({ name: missingParamNames })
@@ -8040,7 +8079,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8040
8079
  }
8041
8080
  return !reportedArgError;
8042
8081
  }
8043
- function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, skipUnknownCheck, skipOverloadArg, isFirstPass, conditionFilter) {
8082
+ function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, options) {
8044
8083
  var _a;
8045
8084
  let argType;
8046
8085
  let expectedTypeDiag;
@@ -8048,19 +8087,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8048
8087
  let isCompatible = true;
8049
8088
  const functionName = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.name;
8050
8089
  if (argParam.argument.valueExpression) {
8051
- // If the param type is a "bare" TypeVar, don't use it as an expected
8052
- // type during the first pass. This causes problems for cases where the the
8053
- // call expression result can influence the type of the TypeVar, such as in
8054
- // the expression "min(1, max(2, 0.5))". We set useNarrowBoundOnly
8055
- // to true if this is the first pass through the parameter list because
8056
- // a wide bound on a TypeVar (if a narrow bound has not yet been established)
8057
- // will unnecessarily constrain the expected type.
8058
8090
  let expectedType;
8059
- if (!isFirstPass ||
8091
+ if (!options.skipBareTypeVarExpectedType ||
8060
8092
  !(0, types_1.isTypeVar)(argParam.paramType) ||
8061
8093
  argParam.paramType.scopeId !== (typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.typeVarScopeId)) {
8062
8094
  expectedType = (0, typeUtils_1.applySolvedTypeVars)(argParam.paramType, typeVarContext, {
8063
- useNarrowBoundOnly: isFirstPass,
8095
+ useNarrowBoundOnly: !!options.useNarrowBoundOnly,
8064
8096
  });
8065
8097
  }
8066
8098
  // If the expected type is unknown, don't use an expected type. Instead,
@@ -8129,8 +8161,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8129
8161
  // If there's a constraint filter, apply it to top-level type variables
8130
8162
  // if appropriate. This doesn't properly handle non-top-level constrained
8131
8163
  // type variables.
8132
- if (conditionFilter) {
8133
- argType = mapSubtypesExpandTypeVars(argType, conditionFilter, (expandedSubtype) => {
8164
+ if (options.conditionFilter) {
8165
+ argType = mapSubtypesExpandTypeVars(argType, options.conditionFilter, (expandedSubtype) => {
8134
8166
  return expandedSubtype;
8135
8167
  });
8136
8168
  }
@@ -8149,7 +8181,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8149
8181
  // If we are asked to skip overload arguments, determine whether the argument
8150
8182
  // is an explicit overload type, an overloaded class constructor, or a
8151
8183
  // an overloaded callback protocol.
8152
- if (skipOverloadArg) {
8184
+ if (options.skipOverloadArg) {
8153
8185
  if ((0, types_1.isOverloadedFunction)(argType)) {
8154
8186
  return { isCompatible, argType, isTypeIncomplete, skippedOverloadArg: true, condition };
8155
8187
  }
@@ -8225,7 +8257,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8225
8257
  }
8226
8258
  return { isCompatible: false, argType, isTypeIncomplete, condition };
8227
8259
  }
8228
- if (!skipUnknownCheck) {
8260
+ if (!options.skipUnknownArgCheck) {
8229
8261
  const simplifiedType = (0, types_1.removeUnbound)(argType);
8230
8262
  const fileInfo = AnalyzerNodeInfo.getFileInfo(argParam.errorNode);
8231
8263
  const getDiagAddendum = () => {
@@ -8915,16 +8947,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8915
8947
  // assume that it was due to a "None" not being supported. Report
8916
8948
  // this as a reportOptionalOperand diagnostic rather than a
8917
8949
  // reportGeneralTypeIssues diagnostic.
8918
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportOptionalOperand, diagnosticRules_1.DiagnosticRule.reportOptionalOperand, localize_1.Localizer.Diagnostic.noneOperator().format({
8950
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportOptionalOperand, diagnosticRules_1.DiagnosticRule.reportOptionalOperand, localize_1.Localizer.Diagnostic.noneOperator().format({
8919
8951
  operator: ParseTreeUtils.printOperator(node.operator),
8920
8952
  }), node.leftExpression);
8921
8953
  }
8922
8954
  else {
8955
+ // If neither the LHS or RHS are unions, don't include a diagnostic addendum
8956
+ // because it will be redundant with the main diagnostic message. The addenda
8957
+ // are useful only if union expansion was used for one or both operands.
8958
+ let diagString = '';
8959
+ if ((0, types_1.isUnion)(makeTopLevelTypeVarsConcrete(leftType)) ||
8960
+ (0, types_1.isUnion)(makeTopLevelTypeVarsConcrete(rightType))) {
8961
+ diagString = diag.getString();
8962
+ }
8923
8963
  addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotSupportBinaryOperator().format({
8924
8964
  operator: ParseTreeUtils.printOperator(node.operator),
8925
8965
  leftType: printType(leftType),
8926
8966
  rightType: printType(rightType),
8927
- }) + diag.getString(), node);
8967
+ }) + diagString, node);
8928
8968
  }
8929
8969
  }
8930
8970
  type = types_1.UnknownType.create();
@@ -9472,7 +9512,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9472
9512
  const expectedValueType = specializedDict.typeArguments[1];
9473
9513
  // Infer the key and value types if possible.
9474
9514
  if (getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
9475
- /* forceStrictInference */ true, expectedKeyType, expectedValueType, undefined, expectedDiagAddendum)) {
9515
+ /* forceStrictInference */ true, expectedKeyType, expectedValueType, undefined, expectedDiagAddendum, inferenceContext)) {
9476
9516
  isIncomplete = true;
9477
9517
  }
9478
9518
  // Dict and MutableMapping types have invariant value types, so they
@@ -9481,10 +9521,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9481
9521
  const isValueTypeInvariant = (0, types_1.isClassInstance)(inferenceContext.expectedType) &&
9482
9522
  (types_1.ClassType.isBuiltIn(inferenceContext.expectedType, 'dict') ||
9483
9523
  types_1.ClassType.isBuiltIn(inferenceContext.expectedType, 'MutableMapping'));
9484
- const specializedKeyType = inferTypeArgFromExpectedType(expectedKeyType, keyTypes.map((result) => result.type),
9524
+ const specializedKeyType = inferTypeArgFromExpectedType((0, typeUtils_1.makeInferenceContext)(expectedKeyType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext), keyTypes.map((result) => result.type),
9485
9525
  /* isNarrowable */ false);
9486
- const specializedValueType = inferTypeArgFromExpectedType(expectedValueType, valueTypes.map((result) => result.type),
9487
- /* isNarrowable */ !isValueTypeInvariant);
9526
+ const specializedValueType = inferTypeArgFromExpectedType((0, typeUtils_1.makeInferenceContext)(expectedValueType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext), valueTypes.map((result) => result.type), !isValueTypeInvariant);
9488
9527
  if (!specializedKeyType || !specializedValueType) {
9489
9528
  return undefined;
9490
9529
  }
@@ -9541,7 +9580,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9541
9580
  }
9542
9581
  return { type, isIncomplete };
9543
9582
  }
9544
- function getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes, forceStrictInference, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum) {
9583
+ function getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes, forceStrictInference, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum, inferenceContext) {
9545
9584
  let isIncomplete = false;
9546
9585
  // Infer the key and value types if possible.
9547
9586
  node.entries.forEach((entryNode, index) => {
@@ -9549,7 +9588,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9549
9588
  let addUnknown = true;
9550
9589
  if (entryNode.nodeType === 17 /* DictionaryKeyEntry */) {
9551
9590
  const keyTypeResult = getTypeOfExpression(entryNode.keyExpression,
9552
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedKeyType !== null && expectedKeyType !== void 0 ? expectedKeyType : (forceStrictInference ? types_1.NeverType.createNever() : undefined)));
9591
+ /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedKeyType !== null && expectedKeyType !== void 0 ? expectedKeyType : (forceStrictInference ? types_1.NeverType.createNever() : undefined), inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext));
9553
9592
  if (keyTypeResult.isIncomplete) {
9554
9593
  isIncomplete = true;
9555
9594
  }
@@ -9568,12 +9607,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9568
9607
  expectedTypedDictEntries.has(keyType.literalValue)) {
9569
9608
  const effectiveValueType = expectedTypedDictEntries.get(keyType.literalValue).valueType;
9570
9609
  valueTypeResult = getTypeOfExpression(entryNode.valueExpression,
9571
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(effectiveValueType));
9610
+ /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(effectiveValueType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext));
9572
9611
  }
9573
9612
  else {
9574
9613
  const effectiveValueType = expectedValueType !== null && expectedValueType !== void 0 ? expectedValueType : (forceStrictInference ? types_1.NeverType.createNever() : undefined);
9575
9614
  valueTypeResult = getTypeOfExpression(entryNode.valueExpression,
9576
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(effectiveValueType));
9615
+ /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(effectiveValueType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext));
9577
9616
  }
9578
9617
  if (expectedDiagAddendum && valueTypeResult.expectedTypeDiagAddendum) {
9579
9618
  expectedDiagAddendum.addAddendum(valueTypeResult.expectedTypeDiagAddendum);
@@ -9597,7 +9636,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9597
9636
  }
9598
9637
  }
9599
9638
  const unexpandedTypeResult = getTypeOfExpression(entryNode.expandExpression,
9600
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedType));
9639
+ /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext));
9601
9640
  if (unexpandedTypeResult.isIncomplete) {
9602
9641
  isIncomplete = true;
9603
9642
  }
@@ -9757,10 +9796,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9757
9796
  verifySetEntryOrDictKeyIsHashable(entry, entryTypeResult.type, /* isDictKey */ false);
9758
9797
  }
9759
9798
  });
9760
- const isExpectedTypeListOrSet = (0, types_1.isClassInstance)(inferenceContext.expectedType) &&
9799
+ const isTypeInvariant = (0, types_1.isClassInstance)(inferenceContext.expectedType) &&
9761
9800
  types_1.ClassType.isBuiltIn(inferenceContext.expectedType, builtInClassName);
9762
- const specializedEntryType = inferTypeArgFromExpectedType(expectedEntryType, entryTypes,
9763
- /* isNarrowable */ !isExpectedTypeListOrSet);
9801
+ const specializedEntryType = inferTypeArgFromExpectedType((0, typeUtils_1.makeInferenceContext)(expectedEntryType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext), entryTypes, !isTypeInvariant);
9764
9802
  if (!specializedEntryType) {
9765
9803
  return { type: types_1.UnknownType.create(), isIncomplete, typeErrors: true, expectedTypeDiagAddendum };
9766
9804
  }
@@ -9843,48 +9881,33 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9843
9881
  addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message + diag.getString(), entry);
9844
9882
  }
9845
9883
  }
9846
- function inferTypeArgFromExpectedType(expectedType, entryTypes, isNarrowable) {
9847
- let targetTypeVar;
9848
- let useSynthesizedTypeVar = false;
9849
- // If the expected type is a TypeVar, use it as a target to find
9850
- // a common (narrowest) type among the entry types.
9851
- if ((0, types_1.isTypeVar)(expectedType)) {
9852
- if (expectedType.details.isParamSpec || expectedType.details.isVariadic) {
9853
- return undefined;
9884
+ function inferTypeArgFromExpectedType(inferenceContext, entryTypes, isNarrowable) {
9885
+ var _a;
9886
+ // If the expected type is Any, the resulting type becomes Any.
9887
+ if ((0, types_1.isAnyOrUnknown)(inferenceContext.expectedType)) {
9888
+ return inferenceContext.expectedType;
9889
+ }
9890
+ const typeVarContext = (_a = inferenceContext.typeVarContext) === null || _a === void 0 ? void 0 : _a.clone();
9891
+ let isCompatible = true;
9892
+ entryTypes.forEach((entryType) => {
9893
+ if (isCompatible &&
9894
+ !assignType(inferenceContext.expectedType, entryType, /* diag */ undefined, typeVarContext)) {
9895
+ isCompatible = false;
9854
9896
  }
9855
- targetTypeVar = expectedType;
9897
+ });
9898
+ if (!isCompatible) {
9899
+ return undefined;
9856
9900
  }
9857
- else {
9858
- // Synthesize a temporary bound type var. We will attempt to assign all list
9859
- // entries to this type var, possibly narrowing the type in the process.
9860
- targetTypeVar = types_1.TypeVarType.createInstance('__typeArg');
9861
- targetTypeVar.details.isSynthesized = true;
9862
- targetTypeVar.details.boundType = makeTopLevelTypeVarsConcrete(expectedType);
9863
- // Use a dummy scope ID. It needs to be a non-empty string.
9864
- targetTypeVar.scopeId = '__typeArgScopeId';
9865
- useSynthesizedTypeVar = true;
9866
- }
9867
- // First, try to assign entries with their literal values stripped.
9868
- // The only time we don't want to strip them is if the expected
9869
- // type explicitly includes literals.
9870
- let typeVarContext = new typeVarContext_1.TypeVarContext(targetTypeVar.scopeId);
9871
- if (useSynthesizedTypeVar) {
9872
- typeVarContext.setTypeVarType(targetTypeVar, isNarrowable ? undefined : expectedType,
9873
- /* narrowBoundNoLiterals */ undefined, expectedType);
9874
- }
9875
- if (entryTypes.every((entryType) => assignType(targetTypeVar, stripLiteralValue(entryType), /* diag */ undefined, typeVarContext))) {
9876
- return (0, typeUtils_1.applySolvedTypeVars)(targetTypeVar, typeVarContext);
9877
- }
9878
- // Allocate a fresh typeVarContext before we try again with literals not stripped.
9879
- typeVarContext = new typeVarContext_1.TypeVarContext(targetTypeVar.scopeId);
9880
- if (useSynthesizedTypeVar) {
9881
- typeVarContext.setTypeVarType(targetTypeVar, isNarrowable ? undefined : expectedType,
9882
- /* narrowBoundNoLiterals */ undefined, expectedType);
9883
- }
9884
- if (entryTypes.every((entryType) => assignType(targetTypeVar, entryType, /* diag */ undefined, typeVarContext))) {
9885
- return (0, typeUtils_1.applySolvedTypeVars)(targetTypeVar, typeVarContext);
9901
+ if (isNarrowable && entryTypes.length > 0) {
9902
+ const combinedTypes = (0, types_1.combineTypes)(entryTypes);
9903
+ return (0, typeUtils_1.containsLiteralType)(inferenceContext.expectedType)
9904
+ ? combinedTypes
9905
+ : stripLiteralValue(combinedTypes);
9886
9906
  }
9887
- return undefined;
9907
+ if (typeVarContext) {
9908
+ return (0, typeUtils_1.applySolvedTypeVars)(inferenceContext.expectedType, typeVarContext);
9909
+ }
9910
+ return inferenceContext.expectedType;
9888
9911
  }
9889
9912
  function getTypeOfTernary(node, flags, inferenceContext) {
9890
9913
  getTypeOfExpression(node.testExpression);
@@ -9943,28 +9966,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9943
9966
  return { type: sentType || types_1.UnknownType.create(), isIncomplete };
9944
9967
  }
9945
9968
  function getTypeOfYieldFrom(node) {
9946
- var _a, _b;
9947
9969
  const yieldFromTypeResult = getTypeOfExpression(node.expression);
9948
9970
  const yieldFromType = yieldFromTypeResult.type;
9949
- let generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(yieldFromType);
9950
- let returnedType;
9951
- // Is the expression a Generator type?
9952
- if (generatorTypeArgs) {
9953
- returnedType = generatorTypeArgs.length >= 2 ? generatorTypeArgs[2] : types_1.UnknownType.create();
9954
- }
9955
- else if ((0, types_1.isClassInstance)(yieldFromType) && types_1.ClassType.isBuiltIn(yieldFromType, 'Coroutine')) {
9971
+ const returnedType = (0, typeUtils_1.mapSubtypes)(yieldFromType, (yieldFromSubtype) => {
9972
+ var _a, _b;
9973
+ // Is the expression a Generator type?
9974
+ let generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(yieldFromSubtype);
9975
+ if (generatorTypeArgs) {
9976
+ return generatorTypeArgs.length >= 2 ? generatorTypeArgs[2] : types_1.UnknownType.create();
9977
+ }
9956
9978
  // Handle old-style (pre-await) Coroutines as a special case.
9957
- returnedType = types_1.UnknownType.create();
9958
- }
9959
- else {
9979
+ if ((0, types_1.isClassInstance)(yieldFromSubtype) && types_1.ClassType.isBuiltIn(yieldFromSubtype, 'Coroutine')) {
9980
+ return types_1.UnknownType.create();
9981
+ }
9982
+ // Handle simple iterables.
9960
9983
  const iterableType = (_b = (_a = getTypeOfIterable(yieldFromTypeResult, /* isAsync */ false, node)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
9961
9984
  // Does the iterable return a Generator?
9962
9985
  generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(iterableType);
9963
- if (generatorTypeArgs) {
9964
- returnedType = generatorTypeArgs.length >= 2 ? generatorTypeArgs[2] : types_1.UnknownType.create();
9965
- }
9966
- }
9967
- return { type: returnedType || types_1.UnknownType.create() };
9986
+ return generatorTypeArgs && generatorTypeArgs.length >= 2 ? generatorTypeArgs[2] : types_1.UnknownType.create();
9987
+ });
9988
+ return { type: returnedType };
9968
9989
  }
9969
9990
  function getTypeOfLambda(node, inferenceContext) {
9970
9991
  let isIncomplete = !!(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete);
@@ -10058,15 +10079,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10058
10079
  type: types_1.UnknownType.create(),
10059
10080
  });
10060
10081
  }
10061
- const expectedReturnType = expectedFunctionType
10082
+ let expectedReturnType = expectedFunctionType
10062
10083
  ? getFunctionEffectiveReturnType(expectedFunctionType)
10063
10084
  : undefined;
10085
+ if (expectedReturnType && (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext)) {
10086
+ expectedReturnType = (0, typeUtils_1.applySolvedTypeVars)(expectedReturnType, inferenceContext.typeVarContext);
10087
+ }
10064
10088
  // If we're speculatively evaluating the lambda, create another speculative
10065
10089
  // evaluation scope for the return expression and do not allow retention
10066
10090
  // of the cached types.
10067
10091
  const inferLambdaReturnType = () => {
10068
10092
  const returnTypeResult = getTypeOfExpression(node.expression,
10069
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
10093
+ /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext));
10070
10094
  functionType.inferredReturnType = returnTypeResult.type;
10071
10095
  if (returnTypeResult.isIncomplete) {
10072
10096
  isIncomplete = true;
@@ -11169,7 +11193,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11169
11193
  let flags = 0 /* None */;
11170
11194
  if (fileInfo.isStubFile) {
11171
11195
  // An assignment of ellipsis means "Any" within a type stub file.
11172
- flags |= 512 /* ConvertEllipsisToUnknown */;
11196
+ flags |= 1 /* ConvertEllipsisToAny */;
11173
11197
  }
11174
11198
  if (node.rightExpression.nodeType === 38 /* Name */ ||
11175
11199
  node.rightExpression.nodeType === 35 /* MemberAccess */) {
@@ -12238,11 +12262,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12238
12262
  argument: arg,
12239
12263
  errorNode: (_b = arg.valueExpression) !== null && _b !== void 0 ? _b : errorNode,
12240
12264
  };
12241
- validateArgType(argParam, new typeVarContext_1.TypeVarContext(), signatureTracker, { type: newMethodType },
12242
- /* skipUnknownCheck */ true,
12243
- /* skipOverloadArg */ true,
12244
- /* useNarrowBoundOnly */ false,
12245
- /* conditionFilter */ undefined);
12265
+ validateArgType(argParam, new typeVarContext_1.TypeVarContext(), signatureTracker, { type: newMethodType }, { skipUnknownArgCheck: true, skipOverloadArg: true });
12246
12266
  paramMap.delete(arg.name.value);
12247
12267
  }
12248
12268
  else {
@@ -13232,11 +13252,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13232
13252
  if (functionDecl === null || functionDecl === void 0 ? void 0 : functionDecl.isGenerator) {
13233
13253
  const inferredYieldTypes = [];
13234
13254
  let useAwaitableGenerator = false;
13255
+ let isYieldResultUsed = false;
13235
13256
  if (functionDecl.yieldStatements) {
13236
13257
  functionDecl.yieldStatements.forEach((yieldNode) => {
13237
- var _a;
13258
+ var _a, _b;
13238
13259
  if (isNodeReachable(yieldNode)) {
13239
13260
  if (yieldNode.nodeType === 61 /* YieldFrom */) {
13261
+ isYieldResultUsed = true;
13240
13262
  const iteratorTypeResult = getTypeOfExpression(yieldNode.expression);
13241
13263
  if ((0, types_1.isClassInstance)(iteratorTypeResult.type) &&
13242
13264
  types_1.ClassType.isBuiltIn(iteratorTypeResult.type, 'Coroutine')) {
@@ -13251,6 +13273,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13251
13273
  }
13252
13274
  }
13253
13275
  else {
13276
+ // If the yield expression is not by itself in a statement list,
13277
+ // assume that its result is consumed.
13278
+ if (((_b = yieldNode === null || yieldNode === void 0 ? void 0 : yieldNode.parent) === null || _b === void 0 ? void 0 : _b.nodeType) !== 47 /* StatementList */) {
13279
+ isYieldResultUsed = true;
13280
+ }
13254
13281
  if (yieldNode.expression) {
13255
13282
  const yieldType = getTypeOfExpression(yieldNode.expression).type;
13256
13283
  inferredYieldTypes.push(yieldType !== null && yieldType !== void 0 ? yieldType : types_1.UnknownType.create());
@@ -13271,10 +13298,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13271
13298
  const generatorType = getTypingType(node, useAwaitableGenerator ? 'AwaitableGenerator' : 'Generator');
13272
13299
  if (generatorType && (0, types_1.isInstantiableClass)(generatorType)) {
13273
13300
  const typeArgs = [];
13301
+ // The "send type" for the generator (the second type argument) is
13302
+ // not generally inferrable, but we can assume that it's Any
13303
+ // if the function never uses the value and Unknown if it does.
13304
+ // This eliminates any "partially unknown" errors in strict mode
13305
+ // in the common case.
13306
+ const sendType = isYieldResultUsed ? types_1.UnknownType.create() : types_1.AnyType.create();
13307
+ typeArgs.push(inferredYieldType, sendType, (0, types_1.isNever)(inferredReturnType) ? types_1.NoneType.createInstance() : inferredReturnType);
13274
13308
  if (useAwaitableGenerator) {
13275
13309
  typeArgs.push(types_1.AnyType.create());
13276
13310
  }
13277
- typeArgs.push(inferredYieldType, types_1.NoneType.createInstance(), (0, types_1.isNever)(inferredReturnType) ? types_1.NoneType.createInstance() : inferredReturnType);
13278
13311
  inferredReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(generatorType, typeArgs,
13279
13312
  /* isTypeArgumentExplicit */ true));
13280
13313
  }
@@ -13649,9 +13682,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13649
13682
  (0, debug_1.assert)(aliasDecl.type === 8 /* Alias */);
13650
13683
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
13651
13684
  // Try to resolve the alias while honoring external visibility.
13652
- const resolvedAliasInfo = resolveAliasDeclarationWithInfo(aliasDecl,
13653
- /* resolveLocalNames */ true,
13654
- /* allowExternallyHiddenAccess */ fileInfo.isStubFile);
13685
+ const resolvedAliasInfo = resolveAliasDeclarationWithInfo(aliasDecl, /* resolveLocalNames */ true, {
13686
+ allowExternallyHiddenAccess: fileInfo.isStubFile,
13687
+ });
13655
13688
  if (!resolvedAliasInfo) {
13656
13689
  return undefined;
13657
13690
  }
@@ -15129,9 +15162,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15129
15162
  }
15130
15163
  function getInferredTypeOfDeclaration(symbol, decl) {
15131
15164
  var _a, _b, _c;
15132
- const resolvedDecl = resolveAliasDeclaration(decl,
15133
- /* resolveLocalNames */ true,
15134
- /* allowExternallyHiddenAccess */ AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile);
15165
+ const resolvedDecl = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
15166
+ allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
15167
+ });
15135
15168
  // We couldn't resolve the alias. Substitute an unknown
15136
15169
  // type in this case.
15137
15170
  if (!resolvedDecl) {
@@ -15363,12 +15396,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15363
15396
  // associated with that symbol. It does this recursively if necessary. If a symbol
15364
15397
  // lookup fails, undefined is returned. If resolveLocalNames is true, the method
15365
15398
  // resolves aliases through local renames ("as" clauses found in import statements).
15366
- function resolveAliasDeclaration(declaration, resolveLocalNames, allowExternallyHiddenAccess = false) {
15367
- var _a;
15368
- return (_a = (0, declarationUtils_1.resolveAliasDeclaration)(importLookup, declaration, resolveLocalNames, allowExternallyHiddenAccess)) === null || _a === void 0 ? void 0 : _a.declaration;
15399
+ function resolveAliasDeclaration(declaration, resolveLocalNames, options) {
15400
+ var _a, _b, _c;
15401
+ return (_c = (0, declarationUtils_1.resolveAliasDeclaration)(importLookup, declaration, {
15402
+ resolveLocalNames,
15403
+ allowExternallyHiddenAccess: (_a = options === null || options === void 0 ? void 0 : options.allowExternallyHiddenAccess) !== null && _a !== void 0 ? _a : false,
15404
+ skipFileNeededCheck: (_b = options === null || options === void 0 ? void 0 : options.skipFileNeededCheck) !== null && _b !== void 0 ? _b : false,
15405
+ })) === null || _c === void 0 ? void 0 : _c.declaration;
15369
15406
  }
15370
- function resolveAliasDeclarationWithInfo(declaration, resolveLocalNames, allowExternallyHiddenAccess = false) {
15371
- return (0, declarationUtils_1.resolveAliasDeclaration)(importLookup, declaration, resolveLocalNames, allowExternallyHiddenAccess);
15407
+ function resolveAliasDeclarationWithInfo(declaration, resolveLocalNames, options) {
15408
+ var _a, _b;
15409
+ return (0, declarationUtils_1.resolveAliasDeclaration)(importLookup, declaration, {
15410
+ resolveLocalNames,
15411
+ allowExternallyHiddenAccess: (_a = options === null || options === void 0 ? void 0 : options.allowExternallyHiddenAccess) !== null && _a !== void 0 ? _a : false,
15412
+ skipFileNeededCheck: (_b = options === null || options === void 0 ? void 0 : options.skipFileNeededCheck) !== null && _b !== void 0 ? _b : false,
15413
+ });
15372
15414
  }
15373
15415
  // Returns the type of the symbol. If the type is explicitly declared, that type
15374
15416
  // is returned. If not, the type is inferred from assignments to the symbol. All
@@ -15491,11 +15533,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15491
15533
  }
15492
15534
  }
15493
15535
  if (considerDecl) {
15494
- const resolvedDecl = (_a = resolveAliasDeclaration(decl,
15495
- /* resolveLocalNames */ true,
15496
- /* allowExternallyHiddenAccess */ AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile)) !== null && _a !== void 0 ? _a : decl;
15497
- const isExplicitTypeAlias = isExplicitTypeAliasDeclaration(decl);
15498
- const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasOrTypedDict(decl);
15536
+ const resolvedDecl = (_a = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
15537
+ allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
15538
+ })) !== null && _a !== void 0 ? _a : decl;
15539
+ const isExplicitTypeAlias = isExplicitTypeAliasDeclaration(resolvedDecl);
15540
+ const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasOrTypedDict(resolvedDecl);
15499
15541
  if (isExplicitTypeAlias) {
15500
15542
  sawExplicitTypeAlias = true;
15501
15543
  }
@@ -16207,6 +16249,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16207
16249
  // specified inheritance chain, taking into account its type arguments.
16208
16250
  function assignClassWithTypeArgs(destType, srcType, inheritanceChain, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
16209
16251
  let curSrcType = srcType;
16252
+ let prevSrcType;
16210
16253
  let curDestTypeVarContext = destTypeVarContext;
16211
16254
  let effectiveFlags = flags;
16212
16255
  inferTypeParameterVarianceForClass(destType);
@@ -16236,7 +16279,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16236
16279
  // If this isn't the first time through the loop, specialize
16237
16280
  // for the next ancestor in the chain.
16238
16281
  if (ancestorIndex < inheritanceChain.length - 1) {
16239
- curSrcType = (0, typeUtils_1.specializeForBaseClass)(curSrcType, ancestorType);
16282
+ // If the curSrcType is a NamedTuple and the ancestorType is a tuple,
16283
+ // we need to handle this as a special case because the NamedTuple may
16284
+ // include typeParams from its parent class.
16285
+ let effectiveCurSrcType = curSrcType;
16286
+ if (types_1.ClassType.isBuiltIn(curSrcType, 'NamedTuple') &&
16287
+ types_1.ClassType.isBuiltIn(ancestorType, 'tuple') &&
16288
+ prevSrcType) {
16289
+ effectiveCurSrcType = prevSrcType;
16290
+ }
16291
+ curSrcType = (0, typeUtils_1.specializeForBaseClass)(effectiveCurSrcType, ancestorType);
16240
16292
  }
16241
16293
  // Handle built-in types that support arbitrary numbers
16242
16294
  // of type parameters like Tuple.
@@ -16259,6 +16311,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16259
16311
  // Allocate a new type var map for the next time through the loop.
16260
16312
  curDestTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(ancestorType));
16261
16313
  effectiveFlags &= ~8 /* SkipSolveTypeVars */;
16314
+ prevSrcType = curSrcType;
16262
16315
  }
16263
16316
  if (destType.typeArguments) {
16264
16317
  // If the dest type is specialized, make sure the specialized source
@@ -17752,7 +17805,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17752
17805
  const srcParamType = srcParamInfo.type;
17753
17806
  if (!destParamInfo) {
17754
17807
  if (destParamDetails.kwargsIndex === undefined && !srcParamInfo.param.hasDefault) {
17755
- if (paramDiag) {
17808
+ if (paramDiag && srcParamDetails.firstKeywordOnlyIndex !== undefined) {
17756
17809
  paramDiag.addMessage(localize_1.Localizer.DiagnosticAddendum.namedParamMissingInDest().format({
17757
17810
  name: srcParamInfo.param.name,
17758
17811
  }));
@@ -18121,213 +18174,224 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18121
18174
  const baseParamDetails = (0, parameterUtils_1.getParameterListDetails)(baseMethod);
18122
18175
  const overrideParamDetails = (0, parameterUtils_1.getParameterListDetails)(overrideMethod);
18123
18176
  let canOverride = true;
18124
- // Verify that we're not overriding a static, class or instance method with
18125
- // an incompatible type.
18126
- if (types_1.FunctionType.isStaticMethod(baseMethod)) {
18127
- if (!types_1.FunctionType.isStaticMethod(overrideMethod)) {
18128
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotStaticMethod());
18129
- canOverride = false;
18130
- }
18131
- }
18132
- else if (types_1.FunctionType.isClassMethod(baseMethod)) {
18133
- if (!types_1.FunctionType.isClassMethod(overrideMethod)) {
18134
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotClassMethod());
18135
- canOverride = false;
18136
- }
18137
- }
18138
- if (types_1.FunctionType.isInstanceMethod(baseMethod)) {
18139
- if (!types_1.FunctionType.isInstanceMethod(overrideMethod)) {
18140
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotInstanceMethod());
18141
- canOverride = false;
18142
- }
18143
- }
18144
- // Verify that the positional param count matches exactly or that the override
18145
- // adds only params that preserve the original signature.
18146
- let foundParamCountMismatch = false;
18147
- if (overrideParamDetails.positionParamCount < baseParamDetails.positionParamCount) {
18148
- if (overrideParamDetails.argsIndex === undefined) {
18149
- foundParamCountMismatch = true;
18150
- }
18151
- else {
18152
- const overrideArgsType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
18153
- for (let i = overrideParamDetails.positionParamCount; i < baseParamDetails.positionParamCount; i++) {
18154
- if (!assignType(overrideArgsType, baseParamDetails.params[i].type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), 8 /* SkipSolveTypeVars */)) {
18155
- localize_1.Localizer.DiagnosticAddendum.overrideParamType().format({
18156
- index: i + 1,
18157
- baseType: printType(baseParamDetails.params[i].type),
18158
- overrideType: printType(overrideArgsType),
18159
- });
18160
- canOverride = false;
18161
- }
18177
+ if (!types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(baseMethod) &&
18178
+ !types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(overrideMethod)) {
18179
+ // Verify that we're not overriding a static, class or instance method with
18180
+ // an incompatible type.
18181
+ if (types_1.FunctionType.isStaticMethod(baseMethod)) {
18182
+ if (!types_1.FunctionType.isStaticMethod(overrideMethod)) {
18183
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotStaticMethod());
18184
+ canOverride = false;
18162
18185
  }
18163
18186
  }
18164
- }
18165
- else if (overrideParamDetails.positionParamCount > baseParamDetails.positionParamCount) {
18166
- // Verify that all of the override parameters that extend the
18167
- // signature are either *args, **kwargs or parameters with
18168
- // default values.
18169
- for (let i = baseParamDetails.positionParamCount; i < overrideParamDetails.positionParamCount; i++) {
18170
- const overrideParam = overrideParamDetails.params[i].param;
18171
- if (overrideParam.category === 0 /* Simple */ &&
18172
- overrideParam.name &&
18173
- !overrideParam.hasDefault) {
18174
- foundParamCountMismatch = true;
18187
+ else if (types_1.FunctionType.isClassMethod(baseMethod)) {
18188
+ if (!types_1.FunctionType.isClassMethod(overrideMethod)) {
18189
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotClassMethod());
18190
+ canOverride = false;
18175
18191
  }
18176
18192
  }
18177
- }
18178
- if (foundParamCountMismatch) {
18179
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overridePositionalParamCount().format({
18180
- baseCount: baseParamDetails.params.length,
18181
- overrideCount: overrideParamDetails.params.length,
18182
- }));
18183
- canOverride = false;
18184
- }
18185
- const positionalParamCount = Math.min(baseParamDetails.positionParamCount, overrideParamDetails.positionParamCount);
18186
- for (let i = 0; i < positionalParamCount; i++) {
18187
- // If the first parameter is a "self" or "cls" parameter, skip the
18188
- // test because these are allowed to violate the Liskov substitution
18189
- // principle.
18190
- if (i === 0) {
18191
- if (types_1.FunctionType.isInstanceMethod(overrideMethod) ||
18192
- types_1.FunctionType.isClassMethod(overrideMethod) ||
18193
- types_1.FunctionType.isConstructorMethod(overrideMethod)) {
18194
- continue;
18193
+ if (types_1.FunctionType.isInstanceMethod(baseMethod)) {
18194
+ if (!types_1.FunctionType.isInstanceMethod(overrideMethod)) {
18195
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotInstanceMethod());
18196
+ canOverride = false;
18195
18197
  }
18196
18198
  }
18197
- const baseParam = baseParamDetails.params[i].param;
18198
- const overrideParam = overrideParamDetails.params[i].param;
18199
- if (i >= baseParamDetails.positionOnlyParamCount &&
18200
- !(0, symbolNameUtils_1.isPrivateOrProtectedName)(baseParam.name || '') &&
18201
- baseParamDetails.params[i].source !== parameterUtils_1.ParameterSource.PositionOnly &&
18202
- baseParam.category === 0 /* Simple */ &&
18203
- baseParam.name !== overrideParam.name) {
18204
- if (overrideParam.category === 0 /* Simple */) {
18205
- if (enforceParamNames) {
18206
- if (overrideParamDetails.params[i].source === parameterUtils_1.ParameterSource.PositionOnly) {
18207
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
18208
- index: i + 1,
18209
- baseName: baseParam.name || '*',
18210
- }));
18211
- }
18212
- else {
18213
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamName().format({
18199
+ // Verify that the positional param count matches exactly or that the override
18200
+ // adds only params that preserve the original signature.
18201
+ let foundParamCountMismatch = false;
18202
+ if (overrideParamDetails.positionParamCount < baseParamDetails.positionParamCount) {
18203
+ if (overrideParamDetails.argsIndex === undefined) {
18204
+ foundParamCountMismatch = true;
18205
+ }
18206
+ else {
18207
+ const overrideArgsType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
18208
+ for (let i = overrideParamDetails.positionParamCount; i < baseParamDetails.positionParamCount; i++) {
18209
+ if (!assignType(overrideArgsType, baseParamDetails.params[i].type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), 8 /* SkipSolveTypeVars */)) {
18210
+ localize_1.Localizer.DiagnosticAddendum.overrideParamType().format({
18214
18211
  index: i + 1,
18215
- baseName: baseParam.name || '*',
18216
- overrideName: overrideParam.name || '*',
18217
- }));
18212
+ baseType: printType(baseParamDetails.params[i].type),
18213
+ overrideType: printType(overrideArgsType),
18214
+ });
18215
+ canOverride = false;
18218
18216
  }
18219
- canOverride = false;
18220
18217
  }
18221
18218
  }
18222
18219
  }
18223
- else if (i < overrideParamDetails.positionOnlyParamCount &&
18224
- i >= baseParamDetails.positionOnlyParamCount) {
18225
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
18226
- index: i + 1,
18227
- baseName: baseParam.name || '*',
18220
+ else if (overrideParamDetails.positionParamCount > baseParamDetails.positionParamCount) {
18221
+ // Verify that all of the override parameters that extend the
18222
+ // signature are either *args, **kwargs or parameters with
18223
+ // default values.
18224
+ for (let i = baseParamDetails.positionParamCount; i < overrideParamDetails.positionParamCount; i++) {
18225
+ const overrideParam = overrideParamDetails.params[i].param;
18226
+ if (overrideParam.category === 0 /* Simple */ &&
18227
+ overrideParam.name &&
18228
+ !overrideParam.hasDefault) {
18229
+ foundParamCountMismatch = true;
18230
+ }
18231
+ }
18232
+ }
18233
+ if (foundParamCountMismatch) {
18234
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overridePositionalParamCount().format({
18235
+ baseCount: baseParamDetails.params.length,
18236
+ overrideCount: overrideParamDetails.params.length,
18228
18237
  }));
18229
18238
  canOverride = false;
18230
18239
  }
18231
- else {
18232
- const baseParamType = baseParamDetails.params[i].type;
18233
- const overrideParamType = overrideParamDetails.params[i].type;
18234
- const baseIsSynthesizedTypeVar = (0, types_1.isTypeVar)(baseParamType) && baseParamType.details.isSynthesized;
18235
- const overrideIsSynthesizedTypeVar = (0, types_1.isTypeVar)(overrideParamType) && overrideParamType.details.isSynthesized;
18236
- if (!baseIsSynthesizedTypeVar && !overrideIsSynthesizedTypeVar) {
18237
- if (baseParam.category !== overrideParam.category ||
18238
- !assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), 8 /* SkipSolveTypeVars */)) {
18239
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamType().format({
18240
- index: i + 1,
18241
- baseType: printType(baseParamType),
18242
- overrideType: printType(overrideParamType),
18243
- }));
18244
- canOverride = false;
18240
+ const positionalParamCount = Math.min(baseParamDetails.positionParamCount, overrideParamDetails.positionParamCount);
18241
+ for (let i = 0; i < positionalParamCount; i++) {
18242
+ // If the first parameter is a "self" or "cls" parameter, skip the
18243
+ // test because these are allowed to violate the Liskov substitution
18244
+ // principle.
18245
+ if (i === 0) {
18246
+ if (types_1.FunctionType.isInstanceMethod(overrideMethod) ||
18247
+ types_1.FunctionType.isClassMethod(overrideMethod) ||
18248
+ types_1.FunctionType.isConstructorMethod(overrideMethod)) {
18249
+ continue;
18245
18250
  }
18246
18251
  }
18247
- if (baseParamDetails.params[i].param.hasDefault && !overrideParamDetails.params[i].param.hasDefault) {
18248
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNoDefault().format({
18252
+ const baseParam = baseParamDetails.params[i].param;
18253
+ const overrideParam = overrideParamDetails.params[i].param;
18254
+ if (i >= baseParamDetails.positionOnlyParamCount &&
18255
+ !(0, symbolNameUtils_1.isPrivateOrProtectedName)(baseParam.name || '') &&
18256
+ baseParamDetails.params[i].source !== parameterUtils_1.ParameterSource.PositionOnly &&
18257
+ baseParam.category === 0 /* Simple */ &&
18258
+ baseParam.name !== overrideParam.name) {
18259
+ if (overrideParam.category === 0 /* Simple */) {
18260
+ if (enforceParamNames) {
18261
+ if (overrideParamDetails.params[i].source === parameterUtils_1.ParameterSource.PositionOnly) {
18262
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
18263
+ index: i + 1,
18264
+ baseName: baseParam.name || '*',
18265
+ }));
18266
+ }
18267
+ else {
18268
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamName().format({
18269
+ index: i + 1,
18270
+ baseName: baseParam.name || '*',
18271
+ overrideName: overrideParam.name || '*',
18272
+ }));
18273
+ }
18274
+ canOverride = false;
18275
+ }
18276
+ }
18277
+ }
18278
+ else if (i < overrideParamDetails.positionOnlyParamCount &&
18279
+ i >= baseParamDetails.positionOnlyParamCount) {
18280
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
18249
18281
  index: i + 1,
18282
+ baseName: baseParam.name || '*',
18250
18283
  }));
18251
18284
  canOverride = false;
18252
18285
  }
18253
- }
18254
- }
18255
- // Check for a *args match.
18256
- if (baseParamDetails.argsIndex !== undefined) {
18257
- if (overrideParamDetails.argsIndex === undefined) {
18258
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameMissing().format({
18259
- name: (_a = baseParamDetails.params[baseParamDetails.argsIndex].param.name) !== null && _a !== void 0 ? _a : '?',
18260
- }));
18261
- canOverride = false;
18262
- }
18263
- else {
18264
- const overrideParamType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
18265
- const baseParamType = baseParamDetails.params[baseParamDetails.argsIndex].type;
18266
- if (!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
18267
- /* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
18268
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
18269
- name: (_b = overrideParamDetails.params[overrideParamDetails.argsIndex].param.name) !== null && _b !== void 0 ? _b : '?',
18270
- baseType: printType(baseParamType),
18271
- overrideType: printType(overrideParamType),
18272
- }));
18273
- canOverride = false;
18286
+ else {
18287
+ const baseParamType = baseParamDetails.params[i].type;
18288
+ const overrideParamType = overrideParamDetails.params[i].type;
18289
+ const baseIsSynthesizedTypeVar = (0, types_1.isTypeVar)(baseParamType) && baseParamType.details.isSynthesized;
18290
+ const overrideIsSynthesizedTypeVar = (0, types_1.isTypeVar)(overrideParamType) && overrideParamType.details.isSynthesized;
18291
+ if (!baseIsSynthesizedTypeVar && !overrideIsSynthesizedTypeVar) {
18292
+ if (baseParam.category !== overrideParam.category ||
18293
+ !assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), 8 /* SkipSolveTypeVars */)) {
18294
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamType().format({
18295
+ index: i + 1,
18296
+ baseType: printType(baseParamType),
18297
+ overrideType: printType(overrideParamType),
18298
+ }));
18299
+ canOverride = false;
18300
+ }
18301
+ }
18302
+ if (baseParamDetails.params[i].param.hasDefault &&
18303
+ !overrideParamDetails.params[i].param.hasDefault) {
18304
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNoDefault().format({
18305
+ index: i + 1,
18306
+ }));
18307
+ canOverride = false;
18308
+ }
18274
18309
  }
18275
18310
  }
18276
- }
18277
- // Now check any keyword-only parameters.
18278
- const baseKwOnlyParams = baseParamDetails.params.filter((paramInfo) => paramInfo.source === parameterUtils_1.ParameterSource.KeywordOnly &&
18279
- paramInfo.param.category === 0 /* Simple */);
18280
- const overrideWkOnlyParams = overrideParamDetails.params.filter((paramInfo) => paramInfo.source === parameterUtils_1.ParameterSource.KeywordOnly &&
18281
- paramInfo.param.category === 0 /* Simple */);
18282
- baseKwOnlyParams.forEach((paramInfo) => {
18283
- var _a, _b, _c;
18284
- const overrideParamInfo = overrideWkOnlyParams.find((pi) => paramInfo.param.name === pi.param.name);
18285
- if (!overrideParamInfo && overrideParamDetails.kwargsIndex === undefined) {
18286
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameMissing().format({
18287
- name: (_a = paramInfo.param.name) !== null && _a !== void 0 ? _a : '?',
18288
- }));
18289
- canOverride = false;
18290
- }
18291
- else {
18292
- let targetParamType = overrideParamInfo === null || overrideParamInfo === void 0 ? void 0 : overrideParamInfo.type;
18293
- if (!targetParamType) {
18294
- targetParamType = overrideParamDetails.params[overrideParamDetails.kwargsIndex].type;
18295
- }
18296
- if (!assignType(targetParamType, paramInfo.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
18297
- /* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
18298
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
18299
- name: (_b = paramInfo.param.name) !== null && _b !== void 0 ? _b : '?',
18300
- baseType: printType(paramInfo.type),
18301
- overrideType: printType(targetParamType),
18311
+ // Check for a *args match.
18312
+ if (baseParamDetails.argsIndex !== undefined) {
18313
+ if (overrideParamDetails.argsIndex === undefined) {
18314
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameMissing().format({
18315
+ name: (_a = baseParamDetails.params[baseParamDetails.argsIndex].param.name) !== null && _a !== void 0 ? _a : '?',
18302
18316
  }));
18303
18317
  canOverride = false;
18304
18318
  }
18305
- if (overrideParamInfo) {
18306
- if (paramInfo.param.hasDefault && !overrideParamInfo.param.hasDefault) {
18307
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordNoDefault().format({
18308
- name: (_c = overrideParamInfo.param.name) !== null && _c !== void 0 ? _c : '?',
18319
+ else {
18320
+ const overrideParamType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
18321
+ const baseParamType = baseParamDetails.params[baseParamDetails.argsIndex].type;
18322
+ if (!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
18323
+ /* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
18324
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
18325
+ name: (_b = overrideParamDetails.params[overrideParamDetails.argsIndex].param.name) !== null && _b !== void 0 ? _b : '?',
18326
+ baseType: printType(baseParamType),
18327
+ overrideType: printType(overrideParamType),
18309
18328
  }));
18310
18329
  canOverride = false;
18311
18330
  }
18312
18331
  }
18313
18332
  }
18314
- });
18315
- // Verify that any keyword-only parameters added by the overload are compatible
18316
- // with the **kwargs in the base.
18317
- overrideWkOnlyParams.forEach((paramInfo) => {
18318
- var _a;
18319
- const baseParamInfo = baseKwOnlyParams.find((pi) => paramInfo.param.name === pi.param.name);
18320
- if (!baseParamInfo) {
18321
- if (baseParamDetails.kwargsIndex === undefined) {
18322
- if (!paramInfo.param.hasDefault) {
18323
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameExtra().format({
18324
- name: (_a = paramInfo.param.name) !== null && _a !== void 0 ? _a : '?',
18333
+ // Now check any keyword-only parameters.
18334
+ const baseKwOnlyParams = baseParamDetails.params.filter((paramInfo) => paramInfo.source === parameterUtils_1.ParameterSource.KeywordOnly &&
18335
+ paramInfo.param.category === 0 /* Simple */);
18336
+ const overrideWkOnlyParams = overrideParamDetails.params.filter((paramInfo) => paramInfo.source === parameterUtils_1.ParameterSource.KeywordOnly &&
18337
+ paramInfo.param.category === 0 /* Simple */);
18338
+ baseKwOnlyParams.forEach((paramInfo) => {
18339
+ var _a, _b, _c;
18340
+ const overrideParamInfo = overrideWkOnlyParams.find((pi) => paramInfo.param.name === pi.param.name);
18341
+ if (!overrideParamInfo && overrideParamDetails.kwargsIndex === undefined) {
18342
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameMissing().format({
18343
+ name: (_a = paramInfo.param.name) !== null && _a !== void 0 ? _a : '?',
18344
+ }));
18345
+ canOverride = false;
18346
+ }
18347
+ else {
18348
+ let targetParamType = overrideParamInfo === null || overrideParamInfo === void 0 ? void 0 : overrideParamInfo.type;
18349
+ if (!targetParamType) {
18350
+ targetParamType = overrideParamDetails.params[overrideParamDetails.kwargsIndex].type;
18351
+ }
18352
+ if (!assignType(targetParamType, paramInfo.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
18353
+ /* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
18354
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
18355
+ name: (_b = paramInfo.param.name) !== null && _b !== void 0 ? _b : '?',
18356
+ baseType: printType(paramInfo.type),
18357
+ overrideType: printType(targetParamType),
18325
18358
  }));
18326
18359
  canOverride = false;
18327
18360
  }
18361
+ if (overrideParamInfo) {
18362
+ if (paramInfo.param.hasDefault && !overrideParamInfo.param.hasDefault) {
18363
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordNoDefault().format({
18364
+ name: (_c = overrideParamInfo.param.name) !== null && _c !== void 0 ? _c : '?',
18365
+ }));
18366
+ canOverride = false;
18367
+ }
18368
+ }
18328
18369
  }
18370
+ });
18371
+ // Verify that any keyword-only parameters added by the overload are compatible
18372
+ // with the **kwargs in the base.
18373
+ overrideWkOnlyParams.forEach((paramInfo) => {
18374
+ var _a;
18375
+ const baseParamInfo = baseKwOnlyParams.find((pi) => paramInfo.param.name === pi.param.name);
18376
+ if (!baseParamInfo) {
18377
+ if (baseParamDetails.kwargsIndex === undefined) {
18378
+ if (!paramInfo.param.hasDefault) {
18379
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameExtra().format({
18380
+ name: (_a = paramInfo.param.name) !== null && _a !== void 0 ? _a : '?',
18381
+ }));
18382
+ canOverride = false;
18383
+ }
18384
+ }
18385
+ }
18386
+ });
18387
+ // Verify that if the base method has a **kwargs parameter, the override does too.
18388
+ if (baseParamDetails.kwargsIndex !== undefined && overrideParamDetails.kwargsIndex === undefined) {
18389
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.kwargsParamMissing().format({
18390
+ paramName: baseParamDetails.params[baseParamDetails.kwargsIndex].param.name,
18391
+ }));
18392
+ canOverride = false;
18329
18393
  }
18330
- });
18394
+ }
18331
18395
  // Now check the return type.
18332
18396
  const baseReturnType = getFunctionEffectiveReturnType(baseMethod);
18333
18397
  const overrideReturnType = getFunctionEffectiveReturnType(overrideMethod);