@zzzen/pyright-internal 1.2.0-dev.20230423 → 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 (166) 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 +12 -7
  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/dataClasses.js +5 -2
  11. package/dist/analyzer/dataClasses.js.map +1 -1
  12. package/dist/analyzer/declarationUtils.d.ts +6 -1
  13. package/dist/analyzer/declarationUtils.js +10 -8
  14. package/dist/analyzer/declarationUtils.js.map +1 -1
  15. package/dist/analyzer/importResolver.d.ts +15 -15
  16. package/dist/analyzer/importResolver.js +477 -477
  17. package/dist/analyzer/importResolver.js.map +1 -1
  18. package/dist/analyzer/namedTuples.d.ts +1 -1
  19. package/dist/analyzer/namedTuples.js +29 -41
  20. package/dist/analyzer/namedTuples.js.map +1 -1
  21. package/dist/analyzer/packageTypeReport.d.ts +2 -1
  22. package/dist/analyzer/packageTypeReport.js +2 -1
  23. package/dist/analyzer/packageTypeReport.js.map +1 -1
  24. package/dist/analyzer/packageTypeVerifier.d.ts +1 -1
  25. package/dist/analyzer/packageTypeVerifier.js +27 -13
  26. package/dist/analyzer/packageTypeVerifier.js.map +1 -1
  27. package/dist/analyzer/program.d.ts +25 -37
  28. package/dist/analyzer/program.js +1356 -1508
  29. package/dist/analyzer/program.js.map +1 -1
  30. package/dist/analyzer/protocols.js +1 -1
  31. package/dist/analyzer/protocols.js.map +1 -1
  32. package/dist/analyzer/service.d.ts +12 -25
  33. package/dist/analyzer/service.js +76 -109
  34. package/dist/analyzer/service.js.map +1 -1
  35. package/dist/analyzer/sourceFile.d.ts +6 -18
  36. package/dist/analyzer/sourceFile.js +57 -121
  37. package/dist/analyzer/sourceFile.js.map +1 -1
  38. package/dist/analyzer/sourceFileInfoUtils.d.ts +7 -1
  39. package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
  40. package/dist/analyzer/typeEvaluator.js +354 -322
  41. package/dist/analyzer/typeEvaluator.js.map +1 -1
  42. package/dist/analyzer/typeEvaluatorTypes.d.ts +6 -2
  43. package/dist/analyzer/typeGuards.js +3 -1
  44. package/dist/analyzer/typeGuards.js.map +1 -1
  45. package/dist/analyzer/typeStubWriter.js.map +1 -1
  46. package/dist/analyzer/typeUtils.d.ts +1 -0
  47. package/dist/analyzer/typeUtils.js +35 -8
  48. package/dist/analyzer/typeUtils.js.map +1 -1
  49. package/dist/backgroundAnalysisBase.d.ts +10 -11
  50. package/dist/backgroundAnalysisBase.js +87 -87
  51. package/dist/backgroundAnalysisBase.js.map +1 -1
  52. package/dist/commands/dumpFileDebugInfoCommand.js +8 -8
  53. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  54. package/dist/commands/quickActionCommand.js +4 -1
  55. package/dist/commands/quickActionCommand.js.map +1 -1
  56. package/dist/common/cancellationUtils.d.ts +1 -1
  57. package/dist/common/cancellationUtils.js +9 -9
  58. package/dist/common/cancellationUtils.js.map +1 -1
  59. package/dist/common/commandLineOptions.d.ts +1 -2
  60. package/dist/common/commandLineOptions.js.map +1 -1
  61. package/dist/common/configOptions.d.ts +2 -2
  62. package/dist/common/configOptions.js.map +1 -1
  63. package/dist/common/console.d.ts +5 -9
  64. package/dist/common/console.js +46 -33
  65. package/dist/common/console.js.map +1 -1
  66. package/dist/common/deferred.js +10 -10
  67. package/dist/common/deferred.js.map +1 -1
  68. package/dist/common/extensibility.d.ts +26 -5
  69. package/dist/common/extensibility.js +1 -1
  70. package/dist/common/extensibility.js.map +1 -1
  71. package/dist/common/fileBasedCancellationUtils.js +5 -5
  72. package/dist/common/fileBasedCancellationUtils.js.map +1 -1
  73. package/dist/common/fileSystem.d.ts +12 -10
  74. package/dist/common/fileSystem.js.map +1 -1
  75. package/dist/common/fullAccessHost.d.ts +3 -3
  76. package/dist/common/fullAccessHost.js +6 -6
  77. package/dist/common/fullAccessHost.js.map +1 -1
  78. package/dist/common/pathUtils.d.ts +2 -2
  79. package/dist/common/pathUtils.js.map +1 -1
  80. package/dist/common/realFileSystem.js +12 -7
  81. package/dist/common/realFileSystem.js.map +1 -1
  82. package/dist/common/uriParser.d.ts +2 -2
  83. package/dist/common/uriParser.js +3 -3
  84. package/dist/common/uriParser.js.map +1 -1
  85. package/dist/common/workspaceEditUtils.js +7 -4
  86. package/dist/common/workspaceEditUtils.js.map +1 -1
  87. package/dist/languageServerBase.d.ts +32 -30
  88. package/dist/languageServerBase.js +274 -336
  89. package/dist/languageServerBase.js.map +1 -1
  90. package/dist/languageService/analyzerServiceExecutor.js +0 -1
  91. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  92. package/dist/languageService/callHierarchyProvider.d.ts +16 -12
  93. package/dist/languageService/callHierarchyProvider.js +125 -41
  94. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  95. package/dist/languageService/definitionProvider.d.ts +23 -9
  96. package/dist/languageService/definitionProvider.js +116 -91
  97. package/dist/languageService/definitionProvider.js.map +1 -1
  98. package/dist/languageService/documentHighlightProvider.d.ts +8 -3
  99. package/dist/languageService/documentHighlightProvider.js +17 -6
  100. package/dist/languageService/documentHighlightProvider.js.map +1 -1
  101. package/dist/languageService/documentSymbolCollector.d.ts +2 -2
  102. package/dist/languageService/documentSymbolCollector.js +4 -3
  103. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  104. package/dist/languageService/documentSymbolProvider.js +5 -3
  105. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  106. package/dist/languageService/hoverProvider.js +1 -1
  107. package/dist/languageService/hoverProvider.js.map +1 -1
  108. package/dist/languageService/insertionPointUtils.js +3 -3
  109. package/dist/languageService/insertionPointUtils.js.map +1 -1
  110. package/dist/languageService/navigationUtils.d.ts +6 -0
  111. package/dist/languageService/navigationUtils.js +28 -0
  112. package/dist/languageService/navigationUtils.js.map +1 -0
  113. package/dist/languageService/quickActions.d.ts +2 -2
  114. package/dist/languageService/quickActions.js +12 -1
  115. package/dist/languageService/quickActions.js.map +1 -1
  116. package/dist/languageService/referencesProvider.d.ts +8 -2
  117. package/dist/languageService/referencesProvider.js +81 -3
  118. package/dist/languageService/referencesProvider.js.map +1 -1
  119. package/dist/languageService/renameModuleProvider.d.ts +13 -13
  120. package/dist/languageService/renameModuleProvider.js +43 -43
  121. package/dist/languageService/renameModuleProvider.js.map +1 -1
  122. package/dist/languageService/signatureHelpProvider.d.ts +19 -23
  123. package/dist/languageService/signatureHelpProvider.js +111 -18
  124. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  125. package/dist/parser/characterStream.d.ts +3 -3
  126. package/dist/parser/characterStream.js +12 -12
  127. package/dist/parser/characterStream.js.map +1 -1
  128. package/dist/parser/parser.d.ts +1 -1
  129. package/dist/parser/parser.js.map +1 -1
  130. package/dist/pyright.js +57 -54
  131. package/dist/pyright.js.map +1 -1
  132. package/dist/pyrightFileSystem.d.ts +1 -1
  133. package/dist/pyrightFileSystem.js +21 -21
  134. package/dist/pyrightFileSystem.js.map +1 -1
  135. package/dist/readonlyAugmentedFileSystem.d.ts +6 -6
  136. package/dist/readonlyAugmentedFileSystem.js +28 -28
  137. package/dist/readonlyAugmentedFileSystem.js.map +1 -1
  138. package/dist/server.js +6 -6
  139. package/dist/server.js.map +1 -1
  140. package/dist/tests/chainedSourceFiles.test.js +1 -1
  141. package/dist/tests/chainedSourceFiles.test.js.map +1 -1
  142. package/dist/tests/checker.test.js +1 -1
  143. package/dist/tests/harness/fourslash/testLanguageService.d.ts +3 -3
  144. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  145. package/dist/tests/harness/fourslash/testState.d.ts +8 -8
  146. package/dist/tests/harness/fourslash/testState.js +109 -99
  147. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  148. package/dist/tests/harness/vfs/filesystem.d.ts +8 -8
  149. package/dist/tests/harness/vfs/filesystem.js +68 -68
  150. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  151. package/dist/tests/importStatementUtils.test.js +34 -0
  152. package/dist/tests/importStatementUtils.test.js.map +1 -1
  153. package/dist/tests/moveSymbol.updateReference.test.js +14 -0
  154. package/dist/tests/moveSymbol.updateReference.test.js.map +1 -1
  155. package/dist/tests/signatureHelp.test.js +5 -1
  156. package/dist/tests/signatureHelp.test.js.map +1 -1
  157. package/dist/tests/sourceFile.test.js +1 -1
  158. package/dist/tests/sourceFile.test.js.map +1 -1
  159. package/dist/tests/testStateUtils.js +1 -1
  160. package/dist/tests/testStateUtils.js.map +1 -1
  161. package/dist/tests/typeEvaluator1.test.js +8 -0
  162. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  163. package/dist/tests/typeEvaluator2.test.js +12 -0
  164. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  165. package/dist/tests/typeEvaluator3.test.js +1 -1
  166. package/package.json +1 -1
@@ -5748,7 +5748,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5748
5748
  // Use speculative mode so we don't output any diagnostics or
5749
5749
  // record any final types in the type cache.
5750
5750
  const callResult = useSpeculativeMode(errorNode, () => {
5751
- return validateFunctionArgumentTypesWithExpectedType(errorNode, matchResults, effectiveTypeVarContext,
5751
+ return validateFunctionArgumentTypesWithContext(errorNode, matchResults, effectiveTypeVarContext,
5752
5752
  /* skipUnknownArgCheck */ true, inferenceContext);
5753
5753
  });
5754
5754
  if (callResult.isTypeIncomplete) {
@@ -5832,7 +5832,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5832
5832
  const finalTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : matchedOverloads[0].typeVarContext;
5833
5833
  finalTypeVarContext.unlock();
5834
5834
  finalTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(matchedOverloads[0].overload));
5835
- const finalCallResult = validateFunctionArgumentTypesWithExpectedType(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck, inferenceContext);
5835
+ const finalCallResult = validateFunctionArgumentTypesWithContext(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck, inferenceContext);
5836
5836
  if (finalCallResult.isTypeIncomplete) {
5837
5837
  isTypeIncomplete = true;
5838
5838
  }
@@ -5960,7 +5960,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5960
5960
  effectiveTypeVarContext.addSolveForScope(lastMatch.overload.details.constructorTypeVarScopeId);
5961
5961
  }
5962
5962
  effectiveTypeVarContext.unlock();
5963
- return validateFunctionArgumentTypesWithExpectedType(errorNode, lastMatch, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
5963
+ return validateFunctionArgumentTypesWithContext(errorNode, lastMatch, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
5964
5964
  };
5965
5965
  // If there is only one possible arg/param match among the overloads,
5966
5966
  // use the normal type matching mechanism because it is faster and
@@ -6093,7 +6093,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6093
6093
  // for each of the subtypes that comprise the expected type. If
6094
6094
  // one or more analyzes with no errors, use those results.
6095
6095
  if (inferenceContext) {
6096
- const expectedCallResult = validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, initMethodType);
6096
+ const expectedCallResult = validateConstructorMethodWithContext(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, initMethodType);
6097
6097
  if (expectedCallResult && !expectedCallResult.argumentErrors) {
6098
6098
  returnType = expectedCallResult.returnType;
6099
6099
  if (expectedCallResult.isTypeIncomplete) {
@@ -6107,18 +6107,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6107
6107
  : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type));
6108
6108
  typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(initMethodType));
6109
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
+ }
6110
6121
  if (!callResult.argumentErrors) {
6111
- let adjustedClassType = type;
6112
- if (callResult.specializedInitSelfType &&
6113
- (0, types_1.isClassInstance)(callResult.specializedInitSelfType) &&
6114
- types_1.ClassType.isSameGenericClass(callResult.specializedInitSelfType, type)) {
6115
- adjustedClassType = types_1.ClassType.cloneAsInstantiable(callResult.specializedInitSelfType);
6116
- }
6117
- returnType = applyExpectedTypeForConstructor(adjustedClassType,
6118
- /* inferenceContext */ undefined, typeVarContext);
6119
- if (callResult.isTypeIncomplete) {
6120
- isTypeIncomplete = true;
6121
- }
6122
6122
  overloadsUsedForCall.push(...callResult.overloadsUsedForCall);
6123
6123
  }
6124
6124
  else {
@@ -6159,7 +6159,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6159
6159
  // If there is an expected type that was not applied above when
6160
6160
  // handling the __init__ method, try to apply it with the __new__ method.
6161
6161
  if (inferenceContext && !returnType) {
6162
- const expectedCallResult = validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, constructorMethodType);
6162
+ const expectedCallResult = validateConstructorMethodWithContext(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, constructorMethodType);
6163
6163
  if (expectedCallResult && !expectedCallResult.argumentErrors) {
6164
6164
  newReturnType = expectedCallResult.returnType;
6165
6165
  returnType = newReturnType;
@@ -6303,22 +6303,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6303
6303
  // For a constructor call that targets a generic class and an "expected type"
6304
6304
  // (i.e. bidirectional inference), this function attempts to infer the correct
6305
6305
  // specialized return type for the constructor.
6306
- function validateConstructorMethodWithExpectedType(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, constructorMethodType) {
6306
+ function validateConstructorMethodWithContext(errorNode, argList, type, skipUnknownArgCheck, inferenceContext, constructorMethodType) {
6307
6307
  let isTypeIncomplete = false;
6308
6308
  let argumentErrors = false;
6309
6309
  const overloadsUsedForCall = [];
6310
6310
  const returnType = (0, typeUtils_1.mapSubtypes)(inferenceContext.expectedType, (expectedSubType) => {
6311
6311
  expectedSubType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expectedSubType);
6312
6312
  const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type));
6313
+ typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(constructorMethodType));
6313
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);
6314
6316
  let callResult;
6315
6317
  useSpeculativeMode(errorNode, () => {
6316
- callResult = validateCallArguments(errorNode, argList, { type: constructorMethodType }, typeVarContext.clone(), skipUnknownArgCheck);
6318
+ callResult = validateCallArguments(errorNode, argList, { type: specializedConstructor }, typeVarContext.clone(), skipUnknownArgCheck);
6317
6319
  });
6318
6320
  if (!callResult.argumentErrors) {
6319
6321
  // Call validateCallArguments again, this time without speculative
6320
6322
  // mode, so any errors are reported.
6321
- callResult = validateCallArguments(errorNode, argList, { type: constructorMethodType }, typeVarContext, skipUnknownArgCheck);
6323
+ callResult = validateCallArguments(errorNode, argList, { type: specializedConstructor }, typeVarContext, skipUnknownArgCheck);
6322
6324
  if (callResult.isTypeIncomplete) {
6323
6325
  isTypeIncomplete = true;
6324
6326
  }
@@ -6326,7 +6328,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6326
6328
  argumentErrors = true;
6327
6329
  }
6328
6330
  overloadsUsedForCall.push(...callResult.overloadsUsedForCall);
6329
- return applyExpectedSubtypeForConstructor(type, expectedSubType, typeVarContext);
6331
+ return applyExpectedSubtypeForConstructor(type, expectedSubType, inferenceContext, typeVarContext);
6330
6332
  }
6331
6333
  }
6332
6334
  return undefined;
@@ -6336,9 +6338,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6336
6338
  }
6337
6339
  return { returnType, isTypeIncomplete, argumentErrors, overloadsUsedForCall };
6338
6340
  }
6339
- function applyExpectedSubtypeForConstructor(type, expectedSubtype, typeVarContext) {
6341
+ function applyExpectedSubtypeForConstructor(type, expectedSubtype, inferenceContext, typeVarContext) {
6342
+ var _a;
6340
6343
  const specializedType = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstance(type), typeVarContext);
6341
- 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)) {
6342
6348
  return undefined;
6343
6349
  }
6344
6350
  // If the expected type is "Any", transform it to an Any.
@@ -6353,7 +6359,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6353
6359
  let unsolvedTypeVarsAreUnknown = true;
6354
6360
  if (inferenceContext) {
6355
6361
  const specializedExpectedType = (0, typeUtils_1.mapSubtypes)(inferenceContext.expectedType, (expectedSubtype) => {
6356
- return applyExpectedSubtypeForConstructor(type, expectedSubtype, typeVarContext);
6362
+ return applyExpectedSubtypeForConstructor(type, expectedSubtype, inferenceContext, typeVarContext);
6357
6363
  });
6358
6364
  if (!(0, types_1.isNever)(specializedExpectedType)) {
6359
6365
  return specializedExpectedType;
@@ -7577,13 +7583,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7577
7583
  // After having matched arguments with parameters, this function evaluates the
7578
7584
  // types of each argument expression and validates that the resulting type is
7579
7585
  // compatible with the declared type of the corresponding parameter.
7580
- function validateFunctionArgumentTypesWithExpectedType(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
7586
+ function validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
7581
7587
  var _a;
7582
7588
  const type = matchResults.overload;
7583
7589
  if (!inferenceContext ||
7584
7590
  (0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) ||
7585
7591
  (0, types_1.isNever)(inferenceContext.expectedType) ||
7586
- (0, typeUtils_1.requiresSpecialization)(inferenceContext.expectedType) ||
7587
7592
  !type.details.declaredReturnType ||
7588
7593
  !(0, typeUtils_1.requiresSpecialization)((_a = types_1.FunctionType.getSpecializedReturnType(type)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create())) {
7589
7594
  return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, skipUnknownArgCheck);
@@ -7598,17 +7603,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7598
7603
  // We may or may not be able to make use of the expected type. We'll evaluate
7599
7604
  // speculatively to see if using the expected type works.
7600
7605
  if ((0, types_1.isUnion)(inferenceContext.expectedType)) {
7601
- let speculativeResults;
7602
7606
  useSpeculativeMode(errorNode, () => {
7603
7607
  const typeVarContextCopy = typeVarContext.clone();
7604
7608
  assignType(effectiveReturnType, effectiveExpectedType,
7605
7609
  /* diag */ undefined, typeVarContextCopy,
7606
7610
  /* srcTypeVarContext */ undefined, effectiveFlags | 1024 /* PopulatingExpectedType */);
7607
- 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
+ }
7608
7615
  });
7609
- if (speculativeResults && speculativeResults.argumentErrors) {
7610
- effectiveExpectedType = undefined;
7611
- }
7612
7616
  }
7613
7617
  if (effectiveExpectedType) {
7614
7618
  // Prepopulate the typeVarContext based on the specialized expected type if the
@@ -7627,6 +7631,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7627
7631
  /* isTypeArgumentExplicit */ false);
7628
7632
  effectiveExpectedType = (0, typeUtils_1.applySolvedTypeVars)(genericReturnType, tempTypeVarContext);
7629
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
+ }
7630
7643
  assignType(effectiveReturnType, effectiveExpectedType,
7631
7644
  /* diag */ undefined, typeVarContext,
7632
7645
  /* srcTypeVarContext */ undefined, effectiveFlags | 1024 /* PopulatingExpectedType */);
@@ -7705,12 +7718,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7705
7718
  // is an overload function, skip it during the first pass
7706
7719
  // because the selection of the proper overload may depend
7707
7720
  // on type arguments supplied by other function arguments.
7708
- // Set useNarrowBoundOnly to true the first time through
7709
- // the loop if we're going to go through the loop multiple
7710
- // times.
7711
- const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7712
- /* skipOverloadArg */ i === 0,
7713
- /* 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
+ });
7714
7736
  if (argResult.isTypeIncomplete) {
7715
7737
  isTypeIncomplete = true;
7716
7738
  }
@@ -7734,9 +7756,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7734
7756
  const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7735
7757
  matchResults.argParams.forEach((argParam) => {
7736
7758
  var _a;
7737
- const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7738
- /* skipOverloadArg */ false,
7739
- /* isFirstPass */ false, typeCondition);
7759
+ const argResult = validateArgType(argParam, typeVarContext, signatureTracker, { type, isIncomplete: matchResults.isTypeIncomplete }, {
7760
+ skipUnknownArgCheck,
7761
+ conditionFilter: typeCondition,
7762
+ });
7740
7763
  argResults.push(argResult);
7741
7764
  if (!argResult.isCompatible) {
7742
7765
  argumentErrors = true;
@@ -7906,7 +7929,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7906
7929
  overloadsUsedForCall: [],
7907
7930
  };
7908
7931
  }
7909
- return validateFunctionArgumentTypesWithExpectedType(errorNode, matchResults, typeVarContext, skipUnknownArgCheck, inferenceContext);
7932
+ return validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck, inferenceContext);
7910
7933
  }
7911
7934
  // Determines whether the specified argument list satisfies the function
7912
7935
  // signature bound to the specified ParamSpec. Return value indicates success.
@@ -8006,10 +8029,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8006
8029
  argument: arg,
8007
8030
  errorNode: arg.valueExpression || errorNode,
8008
8031
  }, srcTypeVarContext, signatureTracker,
8009
- /* functionType */ undefined,
8010
- /* skipUnknownArgCheck */ false,
8011
- /* skipOverloadArg */ false,
8012
- /* isFirstPass */ false, conditionFilter);
8032
+ /* functionType */ undefined, { conditionFilter });
8013
8033
  if (!argResult.isCompatible) {
8014
8034
  reportedArgError = true;
8015
8035
  }
@@ -8059,7 +8079,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8059
8079
  }
8060
8080
  return !reportedArgError;
8061
8081
  }
8062
- function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, skipUnknownCheck, skipOverloadArg, isFirstPass, conditionFilter) {
8082
+ function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, options) {
8063
8083
  var _a;
8064
8084
  let argType;
8065
8085
  let expectedTypeDiag;
@@ -8067,19 +8087,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8067
8087
  let isCompatible = true;
8068
8088
  const functionName = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.name;
8069
8089
  if (argParam.argument.valueExpression) {
8070
- // If the param type is a "bare" TypeVar, don't use it as an expected
8071
- // type during the first pass. This causes problems for cases where the the
8072
- // call expression result can influence the type of the TypeVar, such as in
8073
- // the expression "min(1, max(2, 0.5))". We set useNarrowBoundOnly
8074
- // to true if this is the first pass through the parameter list because
8075
- // a wide bound on a TypeVar (if a narrow bound has not yet been established)
8076
- // will unnecessarily constrain the expected type.
8077
8090
  let expectedType;
8078
- if (!isFirstPass ||
8091
+ if (!options.skipBareTypeVarExpectedType ||
8079
8092
  !(0, types_1.isTypeVar)(argParam.paramType) ||
8080
8093
  argParam.paramType.scopeId !== (typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.typeVarScopeId)) {
8081
8094
  expectedType = (0, typeUtils_1.applySolvedTypeVars)(argParam.paramType, typeVarContext, {
8082
- useNarrowBoundOnly: isFirstPass,
8095
+ useNarrowBoundOnly: !!options.useNarrowBoundOnly,
8083
8096
  });
8084
8097
  }
8085
8098
  // If the expected type is unknown, don't use an expected type. Instead,
@@ -8148,8 +8161,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8148
8161
  // If there's a constraint filter, apply it to top-level type variables
8149
8162
  // if appropriate. This doesn't properly handle non-top-level constrained
8150
8163
  // type variables.
8151
- if (conditionFilter) {
8152
- argType = mapSubtypesExpandTypeVars(argType, conditionFilter, (expandedSubtype) => {
8164
+ if (options.conditionFilter) {
8165
+ argType = mapSubtypesExpandTypeVars(argType, options.conditionFilter, (expandedSubtype) => {
8153
8166
  return expandedSubtype;
8154
8167
  });
8155
8168
  }
@@ -8168,7 +8181,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8168
8181
  // If we are asked to skip overload arguments, determine whether the argument
8169
8182
  // is an explicit overload type, an overloaded class constructor, or a
8170
8183
  // an overloaded callback protocol.
8171
- if (skipOverloadArg) {
8184
+ if (options.skipOverloadArg) {
8172
8185
  if ((0, types_1.isOverloadedFunction)(argType)) {
8173
8186
  return { isCompatible, argType, isTypeIncomplete, skippedOverloadArg: true, condition };
8174
8187
  }
@@ -8244,7 +8257,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8244
8257
  }
8245
8258
  return { isCompatible: false, argType, isTypeIncomplete, condition };
8246
8259
  }
8247
- if (!skipUnknownCheck) {
8260
+ if (!options.skipUnknownArgCheck) {
8248
8261
  const simplifiedType = (0, types_1.removeUnbound)(argType);
8249
8262
  const fileInfo = AnalyzerNodeInfo.getFileInfo(argParam.errorNode);
8250
8263
  const getDiagAddendum = () => {
@@ -8934,16 +8947,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8934
8947
  // assume that it was due to a "None" not being supported. Report
8935
8948
  // this as a reportOptionalOperand diagnostic rather than a
8936
8949
  // reportGeneralTypeIssues diagnostic.
8937
- 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({
8938
8951
  operator: ParseTreeUtils.printOperator(node.operator),
8939
8952
  }), node.leftExpression);
8940
8953
  }
8941
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
+ }
8942
8963
  addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotSupportBinaryOperator().format({
8943
8964
  operator: ParseTreeUtils.printOperator(node.operator),
8944
8965
  leftType: printType(leftType),
8945
8966
  rightType: printType(rightType),
8946
- }) + diag.getString(), node);
8967
+ }) + diagString, node);
8947
8968
  }
8948
8969
  }
8949
8970
  type = types_1.UnknownType.create();
@@ -9491,7 +9512,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9491
9512
  const expectedValueType = specializedDict.typeArguments[1];
9492
9513
  // Infer the key and value types if possible.
9493
9514
  if (getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
9494
- /* forceStrictInference */ true, expectedKeyType, expectedValueType, undefined, expectedDiagAddendum)) {
9515
+ /* forceStrictInference */ true, expectedKeyType, expectedValueType, undefined, expectedDiagAddendum, inferenceContext)) {
9495
9516
  isIncomplete = true;
9496
9517
  }
9497
9518
  // Dict and MutableMapping types have invariant value types, so they
@@ -9500,10 +9521,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9500
9521
  const isValueTypeInvariant = (0, types_1.isClassInstance)(inferenceContext.expectedType) &&
9501
9522
  (types_1.ClassType.isBuiltIn(inferenceContext.expectedType, 'dict') ||
9502
9523
  types_1.ClassType.isBuiltIn(inferenceContext.expectedType, 'MutableMapping'));
9503
- 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),
9504
9525
  /* isNarrowable */ false);
9505
- const specializedValueType = inferTypeArgFromExpectedType(expectedValueType, valueTypes.map((result) => result.type),
9506
- /* 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);
9507
9527
  if (!specializedKeyType || !specializedValueType) {
9508
9528
  return undefined;
9509
9529
  }
@@ -9560,7 +9580,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9560
9580
  }
9561
9581
  return { type, isIncomplete };
9562
9582
  }
9563
- function getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes, forceStrictInference, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum) {
9583
+ function getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes, forceStrictInference, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum, inferenceContext) {
9564
9584
  let isIncomplete = false;
9565
9585
  // Infer the key and value types if possible.
9566
9586
  node.entries.forEach((entryNode, index) => {
@@ -9568,7 +9588,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9568
9588
  let addUnknown = true;
9569
9589
  if (entryNode.nodeType === 17 /* DictionaryKeyEntry */) {
9570
9590
  const keyTypeResult = getTypeOfExpression(entryNode.keyExpression,
9571
- /* 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));
9572
9592
  if (keyTypeResult.isIncomplete) {
9573
9593
  isIncomplete = true;
9574
9594
  }
@@ -9587,12 +9607,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9587
9607
  expectedTypedDictEntries.has(keyType.literalValue)) {
9588
9608
  const effectiveValueType = expectedTypedDictEntries.get(keyType.literalValue).valueType;
9589
9609
  valueTypeResult = getTypeOfExpression(entryNode.valueExpression,
9590
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(effectiveValueType));
9610
+ /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(effectiveValueType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext));
9591
9611
  }
9592
9612
  else {
9593
9613
  const effectiveValueType = expectedValueType !== null && expectedValueType !== void 0 ? expectedValueType : (forceStrictInference ? types_1.NeverType.createNever() : undefined);
9594
9614
  valueTypeResult = getTypeOfExpression(entryNode.valueExpression,
9595
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(effectiveValueType));
9615
+ /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(effectiveValueType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext));
9596
9616
  }
9597
9617
  if (expectedDiagAddendum && valueTypeResult.expectedTypeDiagAddendum) {
9598
9618
  expectedDiagAddendum.addAddendum(valueTypeResult.expectedTypeDiagAddendum);
@@ -9616,7 +9636,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9616
9636
  }
9617
9637
  }
9618
9638
  const unexpandedTypeResult = getTypeOfExpression(entryNode.expandExpression,
9619
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedType));
9639
+ /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext));
9620
9640
  if (unexpandedTypeResult.isIncomplete) {
9621
9641
  isIncomplete = true;
9622
9642
  }
@@ -9776,10 +9796,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9776
9796
  verifySetEntryOrDictKeyIsHashable(entry, entryTypeResult.type, /* isDictKey */ false);
9777
9797
  }
9778
9798
  });
9779
- const isExpectedTypeListOrSet = (0, types_1.isClassInstance)(inferenceContext.expectedType) &&
9799
+ const isTypeInvariant = (0, types_1.isClassInstance)(inferenceContext.expectedType) &&
9780
9800
  types_1.ClassType.isBuiltIn(inferenceContext.expectedType, builtInClassName);
9781
- const specializedEntryType = inferTypeArgFromExpectedType(expectedEntryType, entryTypes,
9782
- /* isNarrowable */ !isExpectedTypeListOrSet);
9801
+ const specializedEntryType = inferTypeArgFromExpectedType((0, typeUtils_1.makeInferenceContext)(expectedEntryType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext), entryTypes, !isTypeInvariant);
9783
9802
  if (!specializedEntryType) {
9784
9803
  return { type: types_1.UnknownType.create(), isIncomplete, typeErrors: true, expectedTypeDiagAddendum };
9785
9804
  }
@@ -9862,48 +9881,33 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9862
9881
  addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message + diag.getString(), entry);
9863
9882
  }
9864
9883
  }
9865
- function inferTypeArgFromExpectedType(expectedType, entryTypes, isNarrowable) {
9866
- let targetTypeVar;
9867
- let useSynthesizedTypeVar = false;
9868
- // If the expected type is a TypeVar, use it as a target to find
9869
- // a common (narrowest) type among the entry types.
9870
- if ((0, types_1.isTypeVar)(expectedType)) {
9871
- if (expectedType.details.isParamSpec || expectedType.details.isVariadic) {
9872
- 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;
9873
9896
  }
9874
- targetTypeVar = expectedType;
9897
+ });
9898
+ if (!isCompatible) {
9899
+ return undefined;
9875
9900
  }
9876
- else {
9877
- // Synthesize a temporary bound type var. We will attempt to assign all list
9878
- // entries to this type var, possibly narrowing the type in the process.
9879
- targetTypeVar = types_1.TypeVarType.createInstance('__typeArg');
9880
- targetTypeVar.details.isSynthesized = true;
9881
- targetTypeVar.details.boundType = makeTopLevelTypeVarsConcrete(expectedType);
9882
- // Use a dummy scope ID. It needs to be a non-empty string.
9883
- targetTypeVar.scopeId = '__typeArgScopeId';
9884
- useSynthesizedTypeVar = true;
9885
- }
9886
- // First, try to assign entries with their literal values stripped.
9887
- // The only time we don't want to strip them is if the expected
9888
- // type explicitly includes literals.
9889
- let typeVarContext = new typeVarContext_1.TypeVarContext(targetTypeVar.scopeId);
9890
- if (useSynthesizedTypeVar) {
9891
- typeVarContext.setTypeVarType(targetTypeVar, isNarrowable ? undefined : expectedType,
9892
- /* narrowBoundNoLiterals */ undefined, expectedType);
9893
- }
9894
- if (entryTypes.every((entryType) => assignType(targetTypeVar, stripLiteralValue(entryType), /* diag */ undefined, typeVarContext))) {
9895
- return (0, typeUtils_1.applySolvedTypeVars)(targetTypeVar, typeVarContext);
9896
- }
9897
- // Allocate a fresh typeVarContext before we try again with literals not stripped.
9898
- typeVarContext = new typeVarContext_1.TypeVarContext(targetTypeVar.scopeId);
9899
- if (useSynthesizedTypeVar) {
9900
- typeVarContext.setTypeVarType(targetTypeVar, isNarrowable ? undefined : expectedType,
9901
- /* narrowBoundNoLiterals */ undefined, expectedType);
9902
- }
9903
- if (entryTypes.every((entryType) => assignType(targetTypeVar, entryType, /* diag */ undefined, typeVarContext))) {
9904
- 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);
9905
9906
  }
9906
- return undefined;
9907
+ if (typeVarContext) {
9908
+ return (0, typeUtils_1.applySolvedTypeVars)(inferenceContext.expectedType, typeVarContext);
9909
+ }
9910
+ return inferenceContext.expectedType;
9907
9911
  }
9908
9912
  function getTypeOfTernary(node, flags, inferenceContext) {
9909
9913
  getTypeOfExpression(node.testExpression);
@@ -9962,28 +9966,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9962
9966
  return { type: sentType || types_1.UnknownType.create(), isIncomplete };
9963
9967
  }
9964
9968
  function getTypeOfYieldFrom(node) {
9965
- var _a, _b;
9966
9969
  const yieldFromTypeResult = getTypeOfExpression(node.expression);
9967
9970
  const yieldFromType = yieldFromTypeResult.type;
9968
- let generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(yieldFromType);
9969
- let returnedType;
9970
- // Is the expression a Generator type?
9971
- if (generatorTypeArgs) {
9972
- returnedType = generatorTypeArgs.length >= 2 ? generatorTypeArgs[2] : types_1.UnknownType.create();
9973
- }
9974
- 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
+ }
9975
9978
  // Handle old-style (pre-await) Coroutines as a special case.
9976
- returnedType = types_1.UnknownType.create();
9977
- }
9978
- 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.
9979
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();
9980
9984
  // Does the iterable return a Generator?
9981
9985
  generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(iterableType);
9982
- if (generatorTypeArgs) {
9983
- returnedType = generatorTypeArgs.length >= 2 ? generatorTypeArgs[2] : types_1.UnknownType.create();
9984
- }
9985
- }
9986
- return { type: returnedType || types_1.UnknownType.create() };
9986
+ return generatorTypeArgs && generatorTypeArgs.length >= 2 ? generatorTypeArgs[2] : types_1.UnknownType.create();
9987
+ });
9988
+ return { type: returnedType };
9987
9989
  }
9988
9990
  function getTypeOfLambda(node, inferenceContext) {
9989
9991
  let isIncomplete = !!(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete);
@@ -10077,15 +10079,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10077
10079
  type: types_1.UnknownType.create(),
10078
10080
  });
10079
10081
  }
10080
- const expectedReturnType = expectedFunctionType
10082
+ let expectedReturnType = expectedFunctionType
10081
10083
  ? getFunctionEffectiveReturnType(expectedFunctionType)
10082
10084
  : undefined;
10085
+ if (expectedReturnType && (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext)) {
10086
+ expectedReturnType = (0, typeUtils_1.applySolvedTypeVars)(expectedReturnType, inferenceContext.typeVarContext);
10087
+ }
10083
10088
  // If we're speculatively evaluating the lambda, create another speculative
10084
10089
  // evaluation scope for the return expression and do not allow retention
10085
10090
  // of the cached types.
10086
10091
  const inferLambdaReturnType = () => {
10087
10092
  const returnTypeResult = getTypeOfExpression(node.expression,
10088
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
10093
+ /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext));
10089
10094
  functionType.inferredReturnType = returnTypeResult.type;
10090
10095
  if (returnTypeResult.isIncomplete) {
10091
10096
  isIncomplete = true;
@@ -12257,11 +12262,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12257
12262
  argument: arg,
12258
12263
  errorNode: (_b = arg.valueExpression) !== null && _b !== void 0 ? _b : errorNode,
12259
12264
  };
12260
- validateArgType(argParam, new typeVarContext_1.TypeVarContext(), signatureTracker, { type: newMethodType },
12261
- /* skipUnknownCheck */ true,
12262
- /* skipOverloadArg */ true,
12263
- /* useNarrowBoundOnly */ false,
12264
- /* conditionFilter */ undefined);
12265
+ validateArgType(argParam, new typeVarContext_1.TypeVarContext(), signatureTracker, { type: newMethodType }, { skipUnknownArgCheck: true, skipOverloadArg: true });
12265
12266
  paramMap.delete(arg.name.value);
12266
12267
  }
12267
12268
  else {
@@ -13681,9 +13682,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13681
13682
  (0, debug_1.assert)(aliasDecl.type === 8 /* Alias */);
13682
13683
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
13683
13684
  // Try to resolve the alias while honoring external visibility.
13684
- const resolvedAliasInfo = resolveAliasDeclarationWithInfo(aliasDecl,
13685
- /* resolveLocalNames */ true,
13686
- /* allowExternallyHiddenAccess */ fileInfo.isStubFile);
13685
+ const resolvedAliasInfo = resolveAliasDeclarationWithInfo(aliasDecl, /* resolveLocalNames */ true, {
13686
+ allowExternallyHiddenAccess: fileInfo.isStubFile,
13687
+ });
13687
13688
  if (!resolvedAliasInfo) {
13688
13689
  return undefined;
13689
13690
  }
@@ -15161,9 +15162,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15161
15162
  }
15162
15163
  function getInferredTypeOfDeclaration(symbol, decl) {
15163
15164
  var _a, _b, _c;
15164
- const resolvedDecl = resolveAliasDeclaration(decl,
15165
- /* resolveLocalNames */ true,
15166
- /* allowExternallyHiddenAccess */ AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile);
15165
+ const resolvedDecl = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
15166
+ allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
15167
+ });
15167
15168
  // We couldn't resolve the alias. Substitute an unknown
15168
15169
  // type in this case.
15169
15170
  if (!resolvedDecl) {
@@ -15395,12 +15396,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15395
15396
  // associated with that symbol. It does this recursively if necessary. If a symbol
15396
15397
  // lookup fails, undefined is returned. If resolveLocalNames is true, the method
15397
15398
  // resolves aliases through local renames ("as" clauses found in import statements).
15398
- function resolveAliasDeclaration(declaration, resolveLocalNames, allowExternallyHiddenAccess = false) {
15399
- var _a;
15400
- 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;
15401
15406
  }
15402
- function resolveAliasDeclarationWithInfo(declaration, resolveLocalNames, allowExternallyHiddenAccess = false) {
15403
- 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
+ });
15404
15414
  }
15405
15415
  // Returns the type of the symbol. If the type is explicitly declared, that type
15406
15416
  // is returned. If not, the type is inferred from assignments to the symbol. All
@@ -15523,9 +15533,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15523
15533
  }
15524
15534
  }
15525
15535
  if (considerDecl) {
15526
- const resolvedDecl = (_a = resolveAliasDeclaration(decl,
15527
- /* resolveLocalNames */ true,
15528
- /* allowExternallyHiddenAccess */ AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile)) !== null && _a !== void 0 ? _a : decl;
15536
+ const resolvedDecl = (_a = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
15537
+ allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
15538
+ })) !== null && _a !== void 0 ? _a : decl;
15529
15539
  const isExplicitTypeAlias = isExplicitTypeAliasDeclaration(resolvedDecl);
15530
15540
  const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasOrTypedDict(resolvedDecl);
15531
15541
  if (isExplicitTypeAlias) {
@@ -16239,6 +16249,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16239
16249
  // specified inheritance chain, taking into account its type arguments.
16240
16250
  function assignClassWithTypeArgs(destType, srcType, inheritanceChain, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
16241
16251
  let curSrcType = srcType;
16252
+ let prevSrcType;
16242
16253
  let curDestTypeVarContext = destTypeVarContext;
16243
16254
  let effectiveFlags = flags;
16244
16255
  inferTypeParameterVarianceForClass(destType);
@@ -16268,7 +16279,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16268
16279
  // If this isn't the first time through the loop, specialize
16269
16280
  // for the next ancestor in the chain.
16270
16281
  if (ancestorIndex < inheritanceChain.length - 1) {
16271
- 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);
16272
16292
  }
16273
16293
  // Handle built-in types that support arbitrary numbers
16274
16294
  // of type parameters like Tuple.
@@ -16291,6 +16311,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16291
16311
  // Allocate a new type var map for the next time through the loop.
16292
16312
  curDestTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(ancestorType));
16293
16313
  effectiveFlags &= ~8 /* SkipSolveTypeVars */;
16314
+ prevSrcType = curSrcType;
16294
16315
  }
16295
16316
  if (destType.typeArguments) {
16296
16317
  // If the dest type is specialized, make sure the specialized source
@@ -17784,7 +17805,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17784
17805
  const srcParamType = srcParamInfo.type;
17785
17806
  if (!destParamInfo) {
17786
17807
  if (destParamDetails.kwargsIndex === undefined && !srcParamInfo.param.hasDefault) {
17787
- if (paramDiag) {
17808
+ if (paramDiag && srcParamDetails.firstKeywordOnlyIndex !== undefined) {
17788
17809
  paramDiag.addMessage(localize_1.Localizer.DiagnosticAddendum.namedParamMissingInDest().format({
17789
17810
  name: srcParamInfo.param.name,
17790
17811
  }));
@@ -18153,213 +18174,224 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18153
18174
  const baseParamDetails = (0, parameterUtils_1.getParameterListDetails)(baseMethod);
18154
18175
  const overrideParamDetails = (0, parameterUtils_1.getParameterListDetails)(overrideMethod);
18155
18176
  let canOverride = true;
18156
- // Verify that we're not overriding a static, class or instance method with
18157
- // an incompatible type.
18158
- if (types_1.FunctionType.isStaticMethod(baseMethod)) {
18159
- if (!types_1.FunctionType.isStaticMethod(overrideMethod)) {
18160
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotStaticMethod());
18161
- canOverride = false;
18162
- }
18163
- }
18164
- else if (types_1.FunctionType.isClassMethod(baseMethod)) {
18165
- if (!types_1.FunctionType.isClassMethod(overrideMethod)) {
18166
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotClassMethod());
18167
- canOverride = false;
18168
- }
18169
- }
18170
- if (types_1.FunctionType.isInstanceMethod(baseMethod)) {
18171
- if (!types_1.FunctionType.isInstanceMethod(overrideMethod)) {
18172
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideNotInstanceMethod());
18173
- canOverride = false;
18174
- }
18175
- }
18176
- // Verify that the positional param count matches exactly or that the override
18177
- // adds only params that preserve the original signature.
18178
- let foundParamCountMismatch = false;
18179
- if (overrideParamDetails.positionParamCount < baseParamDetails.positionParamCount) {
18180
- if (overrideParamDetails.argsIndex === undefined) {
18181
- foundParamCountMismatch = true;
18182
- }
18183
- else {
18184
- const overrideArgsType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
18185
- for (let i = overrideParamDetails.positionParamCount; i < baseParamDetails.positionParamCount; i++) {
18186
- 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 */)) {
18187
- localize_1.Localizer.DiagnosticAddendum.overrideParamType().format({
18188
- index: i + 1,
18189
- baseType: printType(baseParamDetails.params[i].type),
18190
- overrideType: printType(overrideArgsType),
18191
- });
18192
- canOverride = false;
18193
- }
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;
18194
18185
  }
18195
18186
  }
18196
- }
18197
- else if (overrideParamDetails.positionParamCount > baseParamDetails.positionParamCount) {
18198
- // Verify that all of the override parameters that extend the
18199
- // signature are either *args, **kwargs or parameters with
18200
- // default values.
18201
- for (let i = baseParamDetails.positionParamCount; i < overrideParamDetails.positionParamCount; i++) {
18202
- const overrideParam = overrideParamDetails.params[i].param;
18203
- if (overrideParam.category === 0 /* Simple */ &&
18204
- overrideParam.name &&
18205
- !overrideParam.hasDefault) {
18206
- 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;
18207
18191
  }
18208
18192
  }
18209
- }
18210
- if (foundParamCountMismatch) {
18211
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overridePositionalParamCount().format({
18212
- baseCount: baseParamDetails.params.length,
18213
- overrideCount: overrideParamDetails.params.length,
18214
- }));
18215
- canOverride = false;
18216
- }
18217
- const positionalParamCount = Math.min(baseParamDetails.positionParamCount, overrideParamDetails.positionParamCount);
18218
- for (let i = 0; i < positionalParamCount; i++) {
18219
- // If the first parameter is a "self" or "cls" parameter, skip the
18220
- // test because these are allowed to violate the Liskov substitution
18221
- // principle.
18222
- if (i === 0) {
18223
- if (types_1.FunctionType.isInstanceMethod(overrideMethod) ||
18224
- types_1.FunctionType.isClassMethod(overrideMethod) ||
18225
- types_1.FunctionType.isConstructorMethod(overrideMethod)) {
18226
- 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;
18227
18197
  }
18228
18198
  }
18229
- const baseParam = baseParamDetails.params[i].param;
18230
- const overrideParam = overrideParamDetails.params[i].param;
18231
- if (i >= baseParamDetails.positionOnlyParamCount &&
18232
- !(0, symbolNameUtils_1.isPrivateOrProtectedName)(baseParam.name || '') &&
18233
- baseParamDetails.params[i].source !== parameterUtils_1.ParameterSource.PositionOnly &&
18234
- baseParam.category === 0 /* Simple */ &&
18235
- baseParam.name !== overrideParam.name) {
18236
- if (overrideParam.category === 0 /* Simple */) {
18237
- if (enforceParamNames) {
18238
- if (overrideParamDetails.params[i].source === parameterUtils_1.ParameterSource.PositionOnly) {
18239
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
18240
- index: i + 1,
18241
- baseName: baseParam.name || '*',
18242
- }));
18243
- }
18244
- else {
18245
- 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({
18246
18211
  index: i + 1,
18247
- baseName: baseParam.name || '*',
18248
- overrideName: overrideParam.name || '*',
18249
- }));
18212
+ baseType: printType(baseParamDetails.params[i].type),
18213
+ overrideType: printType(overrideArgsType),
18214
+ });
18215
+ canOverride = false;
18250
18216
  }
18251
- canOverride = false;
18252
18217
  }
18253
18218
  }
18254
18219
  }
18255
- else if (i < overrideParamDetails.positionOnlyParamCount &&
18256
- i >= baseParamDetails.positionOnlyParamCount) {
18257
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
18258
- index: i + 1,
18259
- 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,
18260
18237
  }));
18261
18238
  canOverride = false;
18262
18239
  }
18263
- else {
18264
- const baseParamType = baseParamDetails.params[i].type;
18265
- const overrideParamType = overrideParamDetails.params[i].type;
18266
- const baseIsSynthesizedTypeVar = (0, types_1.isTypeVar)(baseParamType) && baseParamType.details.isSynthesized;
18267
- const overrideIsSynthesizedTypeVar = (0, types_1.isTypeVar)(overrideParamType) && overrideParamType.details.isSynthesized;
18268
- if (!baseIsSynthesizedTypeVar && !overrideIsSynthesizedTypeVar) {
18269
- if (baseParam.category !== overrideParam.category ||
18270
- !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 */)) {
18271
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamType().format({
18272
- index: i + 1,
18273
- baseType: printType(baseParamType),
18274
- overrideType: printType(overrideParamType),
18275
- }));
18276
- 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;
18277
18250
  }
18278
18251
  }
18279
- if (baseParamDetails.params[i].param.hasDefault && !overrideParamDetails.params[i].param.hasDefault) {
18280
- 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({
18281
18281
  index: i + 1,
18282
+ baseName: baseParam.name || '*',
18282
18283
  }));
18283
18284
  canOverride = false;
18284
18285
  }
18285
- }
18286
- }
18287
- // Check for a *args match.
18288
- if (baseParamDetails.argsIndex !== undefined) {
18289
- if (overrideParamDetails.argsIndex === undefined) {
18290
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameMissing().format({
18291
- name: (_a = baseParamDetails.params[baseParamDetails.argsIndex].param.name) !== null && _a !== void 0 ? _a : '?',
18292
- }));
18293
- canOverride = false;
18294
- }
18295
- else {
18296
- const overrideParamType = overrideParamDetails.params[overrideParamDetails.argsIndex].type;
18297
- const baseParamType = baseParamDetails.params[baseParamDetails.argsIndex].type;
18298
- if (!assignType(overrideParamType, baseParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
18299
- /* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
18300
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
18301
- name: (_b = overrideParamDetails.params[overrideParamDetails.argsIndex].param.name) !== null && _b !== void 0 ? _b : '?',
18302
- baseType: printType(baseParamType),
18303
- overrideType: printType(overrideParamType),
18304
- }));
18305
- 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
+ }
18306
18309
  }
18307
18310
  }
18308
- }
18309
- // Now check any keyword-only parameters.
18310
- const baseKwOnlyParams = baseParamDetails.params.filter((paramInfo) => paramInfo.source === parameterUtils_1.ParameterSource.KeywordOnly &&
18311
- paramInfo.param.category === 0 /* Simple */);
18312
- const overrideWkOnlyParams = overrideParamDetails.params.filter((paramInfo) => paramInfo.source === parameterUtils_1.ParameterSource.KeywordOnly &&
18313
- paramInfo.param.category === 0 /* Simple */);
18314
- baseKwOnlyParams.forEach((paramInfo) => {
18315
- var _a, _b, _c;
18316
- const overrideParamInfo = overrideWkOnlyParams.find((pi) => paramInfo.param.name === pi.param.name);
18317
- if (!overrideParamInfo && overrideParamDetails.kwargsIndex === undefined) {
18318
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameMissing().format({
18319
- name: (_a = paramInfo.param.name) !== null && _a !== void 0 ? _a : '?',
18320
- }));
18321
- canOverride = false;
18322
- }
18323
- else {
18324
- let targetParamType = overrideParamInfo === null || overrideParamInfo === void 0 ? void 0 : overrideParamInfo.type;
18325
- if (!targetParamType) {
18326
- targetParamType = overrideParamDetails.params[overrideParamDetails.kwargsIndex].type;
18327
- }
18328
- if (!assignType(targetParamType, paramInfo.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
18329
- /* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
18330
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
18331
- name: (_b = paramInfo.param.name) !== null && _b !== void 0 ? _b : '?',
18332
- baseType: printType(paramInfo.type),
18333
- 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 : '?',
18334
18316
  }));
18335
18317
  canOverride = false;
18336
18318
  }
18337
- if (overrideParamInfo) {
18338
- if (paramInfo.param.hasDefault && !overrideParamInfo.param.hasDefault) {
18339
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordNoDefault().format({
18340
- 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),
18341
18328
  }));
18342
18329
  canOverride = false;
18343
18330
  }
18344
18331
  }
18345
18332
  }
18346
- });
18347
- // Verify that any keyword-only parameters added by the overload are compatible
18348
- // with the **kwargs in the base.
18349
- overrideWkOnlyParams.forEach((paramInfo) => {
18350
- var _a;
18351
- const baseParamInfo = baseKwOnlyParams.find((pi) => paramInfo.param.name === pi.param.name);
18352
- if (!baseParamInfo) {
18353
- if (baseParamDetails.kwargsIndex === undefined) {
18354
- if (!paramInfo.param.hasDefault) {
18355
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNameExtra().format({
18356
- 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),
18357
18358
  }));
18358
18359
  canOverride = false;
18359
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
+ }
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
+ }
18360
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;
18361
18393
  }
18362
- });
18394
+ }
18363
18395
  // Now check the return type.
18364
18396
  const baseReturnType = getFunctionEffectiveReturnType(baseMethod);
18365
18397
  const overrideReturnType = getFunctionEffectiveReturnType(overrideMethod);