@zzzen/pyright-internal 1.2.0-dev.20240602 → 1.2.0-dev.20240616

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 (178) hide show
  1. package/dist/analyzer/binder.d.ts +3 -1
  2. package/dist/analyzer/binder.js +23 -11
  3. package/dist/analyzer/binder.js.map +1 -1
  4. package/dist/analyzer/checker.js +50 -33
  5. package/dist/analyzer/checker.js.map +1 -1
  6. package/dist/analyzer/constraintSolver.js +27 -38
  7. package/dist/analyzer/constraintSolver.js.map +1 -1
  8. package/dist/analyzer/constructorTransform.js +1 -1
  9. package/dist/analyzer/constructorTransform.js.map +1 -1
  10. package/dist/analyzer/constructors.js +2 -7
  11. package/dist/analyzer/constructors.js.map +1 -1
  12. package/dist/analyzer/dataClasses.d.ts +0 -1
  13. package/dist/analyzer/dataClasses.js +52 -78
  14. package/dist/analyzer/dataClasses.js.map +1 -1
  15. package/dist/analyzer/decorators.d.ts +2 -1
  16. package/dist/analyzer/decorators.js +34 -39
  17. package/dist/analyzer/decorators.js.map +1 -1
  18. package/dist/analyzer/docStringUtils.d.ts +0 -1
  19. package/dist/analyzer/docStringUtils.js +1 -6
  20. package/dist/analyzer/docStringUtils.js.map +1 -1
  21. package/dist/analyzer/enums.d.ts +1 -1
  22. package/dist/analyzer/enums.js +20 -17
  23. package/dist/analyzer/enums.js.map +1 -1
  24. package/dist/analyzer/importResolver.js +11 -9
  25. package/dist/analyzer/importResolver.js.map +1 -1
  26. package/dist/analyzer/namedTuples.js +3 -3
  27. package/dist/analyzer/namedTuples.js.map +1 -1
  28. package/dist/analyzer/operations.js +6 -7
  29. package/dist/analyzer/operations.js.map +1 -1
  30. package/dist/analyzer/parameterUtils.js +1 -13
  31. package/dist/analyzer/parameterUtils.js.map +1 -1
  32. package/dist/analyzer/parseTreeUtils.d.ts +1 -1
  33. package/dist/analyzer/patternMatching.js +4 -4
  34. package/dist/analyzer/patternMatching.js.map +1 -1
  35. package/dist/analyzer/properties.js +4 -4
  36. package/dist/analyzer/properties.js.map +1 -1
  37. package/dist/analyzer/protocols.js +16 -5
  38. package/dist/analyzer/protocols.js.map +1 -1
  39. package/dist/analyzer/service.js +27 -48
  40. package/dist/analyzer/service.js.map +1 -1
  41. package/dist/analyzer/sourceFile.d.ts +2 -1
  42. package/dist/analyzer/sourceFile.js +7 -5
  43. package/dist/analyzer/sourceFile.js.map +1 -1
  44. package/dist/analyzer/typeDocStringUtils.d.ts +1 -0
  45. package/dist/analyzer/typeDocStringUtils.js +8 -1
  46. package/dist/analyzer/typeDocStringUtils.js.map +1 -1
  47. package/dist/analyzer/typeEvaluator.js +746 -667
  48. package/dist/analyzer/typeEvaluator.js.map +1 -1
  49. package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -3
  50. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  51. package/dist/analyzer/typeGuards.js +3 -2
  52. package/dist/analyzer/typeGuards.js.map +1 -1
  53. package/dist/analyzer/typePrinter.js +25 -16
  54. package/dist/analyzer/typePrinter.js.map +1 -1
  55. package/dist/analyzer/typeUtils.d.ts +3 -5
  56. package/dist/analyzer/typeUtils.js +96 -144
  57. package/dist/analyzer/typeUtils.js.map +1 -1
  58. package/dist/analyzer/typeVarContext.js +4 -0
  59. package/dist/analyzer/typeVarContext.js.map +1 -1
  60. package/dist/analyzer/typedDicts.js +6 -6
  61. package/dist/analyzer/typedDicts.js.map +1 -1
  62. package/dist/analyzer/types.d.ts +51 -54
  63. package/dist/analyzer/types.js +221 -260
  64. package/dist/analyzer/types.js.map +1 -1
  65. package/dist/backgroundAnalysisBase.d.ts +1 -1
  66. package/dist/backgroundAnalysisBase.js +3 -3
  67. package/dist/commands/dumpFileDebugInfoCommand.js +17 -25
  68. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  69. package/dist/common/cancellationUtils.d.ts +1 -0
  70. package/dist/common/cancellationUtils.js +15 -1
  71. package/dist/common/cancellationUtils.js.map +1 -1
  72. package/dist/common/configOptions.d.ts +2 -1
  73. package/dist/common/configOptions.js +13 -4
  74. package/dist/common/configOptions.js.map +1 -1
  75. package/dist/common/docStringService.d.ts +15 -0
  76. package/dist/common/docStringService.js +38 -0
  77. package/dist/common/docStringService.js.map +1 -0
  78. package/dist/common/envVarUtils.js +3 -1
  79. package/dist/common/envVarUtils.js.map +1 -1
  80. package/dist/common/extensibility.d.ts +1 -7
  81. package/dist/common/extensibility.js.map +1 -1
  82. package/dist/common/languageServerInterface.d.ts +1 -2
  83. package/dist/common/languageServerInterface.js.map +1 -1
  84. package/dist/common/realFileSystem.d.ts +3 -3
  85. package/dist/common/realFileSystem.js +6 -6
  86. package/dist/common/realFileSystem.js.map +1 -1
  87. package/dist/common/serviceKeys.d.ts +2 -0
  88. package/dist/common/serviceKeys.js +1 -0
  89. package/dist/common/serviceKeys.js.map +1 -1
  90. package/dist/common/serviceProvider.js +3 -0
  91. package/dist/common/serviceProvider.js.map +1 -1
  92. package/dist/common/serviceProviderExtensions.d.ts +2 -0
  93. package/dist/common/serviceProviderExtensions.js +8 -0
  94. package/dist/common/serviceProviderExtensions.js.map +1 -1
  95. package/dist/common/stringUtils.d.ts +1 -0
  96. package/dist/common/stringUtils.js +5 -1
  97. package/dist/common/stringUtils.js.map +1 -1
  98. package/dist/common/uri/uriUtils.d.ts +1 -1
  99. package/dist/common/uri/uriUtils.js +1 -1
  100. package/dist/common/uri/uriUtils.js.map +1 -1
  101. package/dist/languageServerBase.d.ts +1 -1
  102. package/dist/languageServerBase.js +3 -3
  103. package/dist/languageServerBase.js.map +1 -1
  104. package/dist/languageService/completionProvider.d.ts +1 -0
  105. package/dist/languageService/completionProvider.js +16 -7
  106. package/dist/languageService/completionProvider.js.map +1 -1
  107. package/dist/languageService/completionProviderUtils.d.ts +2 -1
  108. package/dist/languageService/completionProviderUtils.js +6 -4
  109. package/dist/languageService/completionProviderUtils.js.map +1 -1
  110. package/dist/languageService/definitionProvider.d.ts +2 -1
  111. package/dist/languageService/definitionProvider.js.map +1 -1
  112. package/dist/languageService/hoverProvider.d.ts +2 -1
  113. package/dist/languageService/hoverProvider.js +7 -5
  114. package/dist/languageService/hoverProvider.js.map +1 -1
  115. package/dist/languageService/signatureHelpProvider.d.ts +3 -1
  116. package/dist/languageService/signatureHelpProvider.js +8 -6
  117. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  118. package/dist/languageService/workspaceSymbolProvider.js +1 -1
  119. package/dist/localization/localize.d.ts +6 -0
  120. package/dist/localization/localize.js +3 -0
  121. package/dist/localization/localize.js.map +1 -1
  122. package/dist/localization/package.nls.cs.json +4 -3
  123. package/dist/localization/package.nls.de.json +4 -3
  124. package/dist/localization/package.nls.en-us.json +3 -0
  125. package/dist/localization/package.nls.es.json +3 -2
  126. package/dist/localization/package.nls.fr.json +4 -3
  127. package/dist/localization/package.nls.it.json +4 -3
  128. package/dist/localization/package.nls.ja.json +4 -3
  129. package/dist/localization/package.nls.ko.json +5 -4
  130. package/dist/localization/package.nls.pl.json +4 -3
  131. package/dist/localization/package.nls.pt-br.json +4 -3
  132. package/dist/localization/package.nls.qps-ploc.json +4 -3
  133. package/dist/localization/package.nls.ru.json +4 -3
  134. package/dist/localization/package.nls.tr.json +4 -3
  135. package/dist/localization/package.nls.zh-cn.json +4 -3
  136. package/dist/localization/package.nls.zh-tw.json +4 -3
  137. package/dist/pyright.js +3 -0
  138. package/dist/pyright.js.map +1 -1
  139. package/dist/tests/checker.test.js +8 -0
  140. package/dist/tests/checker.test.js.map +1 -1
  141. package/dist/tests/config.test.js +3 -3
  142. package/dist/tests/config.test.js.map +1 -1
  143. package/dist/tests/diagnosticOverrides.test.js +7 -6
  144. package/dist/tests/diagnosticOverrides.test.js.map +1 -1
  145. package/dist/tests/docStringConversion.test.d.ts +2 -1
  146. package/dist/tests/docStringConversion.test.js +300 -293
  147. package/dist/tests/docStringConversion.test.js.map +1 -1
  148. package/dist/tests/fourslash/rename.externallyHidden.fourslash.js +2 -2
  149. package/dist/tests/fourslash/rename.externallyHidden.fourslash.js.map +1 -1
  150. package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.js +1 -1
  151. package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.js.map +1 -1
  152. package/dist/tests/harness/fourslash/testState.js +2 -1
  153. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  154. package/dist/tests/pathUtils.test.js +6 -0
  155. package/dist/tests/pathUtils.test.js.map +1 -1
  156. package/dist/tests/signatureHelp.test.js +2 -1
  157. package/dist/tests/signatureHelp.test.js.map +1 -1
  158. package/dist/tests/testState.test.js +1 -1
  159. package/dist/tests/testState.test.js.map +1 -1
  160. package/dist/tests/testUtils.js +1 -1
  161. package/dist/tests/testUtils.js.map +1 -1
  162. package/dist/tests/typeEvaluator2.test.js +4 -0
  163. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  164. package/dist/tests/typeEvaluator3.test.js +8 -0
  165. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  166. package/dist/tests/typeEvaluator4.test.js +7 -3
  167. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  168. package/dist/tests/typeEvaluator7.test.js +15 -9
  169. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  170. package/dist/tests/typePrinter.test.js +2 -2
  171. package/dist/tests/typePrinter.test.js.map +1 -1
  172. package/dist/tests/uri.test.js +6 -0
  173. package/dist/tests/uri.test.js.map +1 -1
  174. package/dist/workspaceFactory.d.ts +1 -1
  175. package/package.json +1 -1
  176. package/dist/tests/docStringUtils.test.d.ts +0 -1
  177. package/dist/tests/docStringUtils.test.js +0 -74
  178. package/dist/tests/docStringUtils.test.js.map +0 -1
@@ -466,7 +466,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
466
466
  functionClass = getBuiltInType(node, 'function');
467
467
  unionTypeClass = getTypesType(node, 'UnionType');
468
468
  if (unionTypeClass && (0, types_1.isClass)(unionTypeClass)) {
469
- unionTypeClass.details.flags |= -2147483648 /* ClassTypeFlags.SpecialFormClass */;
469
+ unionTypeClass.details.flags |= 8388608 /* ClassTypeFlags.SpecialFormClass */;
470
470
  }
471
471
  // Initialize and cache "Collection" to break a cyclical dependency
472
472
  // that occurs when resolving tuple below.
@@ -487,7 +487,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
487
487
  }
488
488
  // Wire up the `Any` class to the special-form version of our internal AnyType.
489
489
  if (objectClass && (0, types_1.isInstantiableClass)(objectClass) && typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
490
- const anyClass = types_1.ClassType.createInstantiable('Any', 'typing.Any', 'typing', uri_1.Uri.empty(), 1 /* ClassTypeFlags.BuiltInClass */ | -2147483648 /* ClassTypeFlags.SpecialFormClass */,
490
+ const anyClass = types_1.ClassType.createInstantiable('Any', 'typing.Any', 'typing', uri_1.Uri.empty(), 1 /* ClassTypeFlags.BuiltInClass */ | 8388608 /* ClassTypeFlags.SpecialFormClass */,
491
491
  /* typeSourceId */ -1,
492
492
  /* declaredMetaclass */ undefined,
493
493
  /* effectiveMetaclass */ typeClass);
@@ -679,7 +679,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
679
679
  }
680
680
  case 3 /* ParseNodeType.Assignment */: {
681
681
  typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext, signatureTracker);
682
- assignTypeToExpression(node.leftExpression, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
682
+ assignTypeToExpression(node.leftExpression, typeResult, node.rightExpression,
683
683
  /* ignoreEmptyContainers */ true,
684
684
  /* allowAssignmentToFinalVar */ true);
685
685
  break;
@@ -689,8 +689,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
689
689
  addError(localize_1.LocMessage.walrusNotAllowed(), node);
690
690
  }
691
691
  typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext, signatureTracker);
692
- assignTypeToExpression(node.name, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
693
- /* ignoreEmptyContainers */ true);
692
+ assignTypeToExpression(node.name, typeResult, node.rightExpression, /* ignoreEmptyContainers */ true);
694
693
  break;
695
694
  }
696
695
  case 60 /* ParseNodeType.Yield */: {
@@ -741,6 +740,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
741
740
  if (expectingInstantiable) {
742
741
  validateTypeIsInstantiable(typeResult, flags, node);
743
742
  }
743
+ // If this is a PEP 695 type alias, remove the special form so the type
744
+ // printer prints it as its aliased type rather than TypeAliasType.
745
+ if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
746
+ if (typeResult.type.specialForm && types_1.ClassType.isBuiltIn(typeResult.type.specialForm, 'TypeAliasType')) {
747
+ typeResult.type = types_1.TypeBase.cloneAsSpecialForm(typeResult.type, undefined);
748
+ }
749
+ }
744
750
  return typeResult;
745
751
  }
746
752
  // Reports the case where a function or class has been decorated with
@@ -1271,9 +1277,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1271
1277
  const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
1272
1278
  if ((0, types_1.isClassInstance)(concreteSubtype)) {
1273
1279
  if (concreteSubtype.literalValue !== undefined) {
1280
+ let isLiteralFalsy;
1281
+ if (concreteSubtype.literalValue instanceof types_1.EnumLiteral) {
1282
+ isLiteralFalsy = !canBeTruthy(concreteSubtype);
1283
+ }
1284
+ else {
1285
+ isLiteralFalsy = !concreteSubtype.literalValue;
1286
+ }
1274
1287
  // If the object is already definitely falsy, it's fine to
1275
1288
  // include, otherwise it should be removed.
1276
- return !concreteSubtype.literalValue ? subtype : undefined;
1289
+ return isLiteralFalsy ? subtype : undefined;
1277
1290
  }
1278
1291
  // If the object is a bool, make it "false", since
1279
1292
  // "true" is a truthy value.
@@ -1307,9 +1320,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1307
1320
  const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
1308
1321
  if ((0, types_1.isClassInstance)(concreteSubtype)) {
1309
1322
  if (concreteSubtype.literalValue !== undefined) {
1323
+ let isLiteralTruthy;
1324
+ if (concreteSubtype.literalValue instanceof types_1.EnumLiteral) {
1325
+ isLiteralTruthy = !canBeFalsy(concreteSubtype);
1326
+ }
1327
+ else {
1328
+ isLiteralTruthy = !!concreteSubtype.literalValue;
1329
+ }
1310
1330
  // If the object is already definitely truthy, it's fine to
1311
1331
  // include, otherwise it should be removed.
1312
- return concreteSubtype.literalValue ? subtype : undefined;
1332
+ return isLiteralTruthy ? subtype : undefined;
1313
1333
  }
1314
1334
  // If the object is a bool, make it "true", since
1315
1335
  // "false" is a falsy value.
@@ -1447,7 +1467,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1447
1467
  }
1448
1468
  // If this is a type[Any] or type[Unknown], allow any other members.
1449
1469
  if ((0, types_1.isClassInstance)(objectType) && types_1.ClassType.isBuiltIn(objectType, 'type') && objectType.includeSubclasses) {
1450
- if ((flags & 8 /* MemberAccessFlags.SkipTypeBaseClass */) === 0) {
1470
+ if ((flags & (8 /* MemberAccessFlags.SkipTypeBaseClass */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */)) === 0) {
1451
1471
  const typeArg = objectType.typeArguments && objectType.typeArguments.length >= 1
1452
1472
  ? objectType.typeArguments[0]
1453
1473
  : types_1.UnknownType.create();
@@ -2022,7 +2042,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2022
2042
  errorRange = { start: 0, length: 0 };
2023
2043
  }
2024
2044
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
2025
- addDiagnosticForTextRange(fileInfo, fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.codeTooComplexToAnalyze(), errorRange);
2045
+ addDiagnosticForTextRange(fileInfo, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.codeTooComplexToAnalyze(), errorRange);
2026
2046
  return true;
2027
2047
  }
2028
2048
  return false;
@@ -2163,7 +2183,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2163
2183
  }
2164
2184
  return diagnostic;
2165
2185
  }
2166
- function addDiagnosticForTextRange(fileInfo, diagLevel, rule, message, range) {
2186
+ function addDiagnosticForTextRange(fileInfo, rule, message, range) {
2187
+ const diagLevel = fileInfo.diagnosticRuleSet[rule];
2167
2188
  if (diagLevel === 'none') {
2168
2189
  return undefined;
2169
2190
  }
@@ -2184,7 +2205,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2184
2205
  }
2185
2206
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeExpectedClass().format({ type: printType(type) }) + diag.getString(), node);
2186
2207
  }
2187
- function assignTypeToNameNode(nameNode, type, isTypeIncomplete, ignoreEmptyContainers, srcExpression, allowAssignmentToFinalVar = false, expectedTypeDiagAddendum) {
2208
+ function assignTypeToNameNode(nameNode, typeResult, ignoreEmptyContainers, srcExpression, allowAssignmentToFinalVar = false, expectedTypeDiagAddendum) {
2188
2209
  var _a, _b, _c;
2189
2210
  const nameValue = nameNode.value;
2190
2211
  const symbolWithScope = lookUpSymbolRecursive(nameNode, nameValue, /* honorCodeFlow */ false);
@@ -2211,18 +2232,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2211
2232
  }
2212
2233
  }
2213
2234
  // We found an existing declared type. Make sure the type is assignable.
2214
- let destType = type;
2235
+ let destType = typeResult.type;
2215
2236
  const isTypeAlias = !!declaredType && (0, types_1.isClassInstance)(declaredType) && types_1.ClassType.isBuiltIn(declaredType, 'TypeAlias');
2216
2237
  if (declaredType && !isTypeAlias) {
2217
2238
  let diagAddendum = new diagnostic_1.DiagnosticAddendum();
2218
- if (!assignType(declaredType, type, diagAddendum)) {
2239
+ if (!assignType(declaredType, typeResult.type, diagAddendum)) {
2219
2240
  // If there was an expected type mismatch, use that diagnostic
2220
2241
  // addendum because it will be more informative.
2221
2242
  if (expectedTypeDiagAddendum) {
2222
2243
  diagAddendum = expectedTypeDiagAddendum;
2223
2244
  }
2224
- if (!isTypeIncomplete) {
2225
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, localize_1.LocMessage.typeAssignmentMismatch().format(printSrcDestTypes(type, declaredType)) +
2245
+ if (!typeResult.isIncomplete) {
2246
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, localize_1.LocMessage.typeAssignmentMismatch().format(printSrcDestTypes(typeResult.type, declaredType)) +
2226
2247
  diagAddendum.getString(), srcExpression !== null && srcExpression !== void 0 ? srcExpression : nameNode, (_c = (_b = diagAddendum.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : srcExpression) !== null && _c !== void 0 ? _c : nameNode);
2227
2248
  }
2228
2249
  // Replace the assigned type with the (unnarrowed) declared type.
@@ -2230,7 +2251,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2230
2251
  }
2231
2252
  else {
2232
2253
  // Constrain the resulting type to match the declared type.
2233
- destType = narrowTypeBasedOnAssignment(nameNode, declaredType, type);
2254
+ destType = narrowTypeBasedOnAssignment(nameNode, declaredType, typeResult).type;
2234
2255
  }
2235
2256
  }
2236
2257
  else {
@@ -2263,12 +2284,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2263
2284
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.finalReassigned().format({ name: nameValue }), nameNode);
2264
2285
  }
2265
2286
  }
2266
- if (!isTypeIncomplete) {
2287
+ if (!typeResult.isIncomplete) {
2267
2288
  reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, nameNode, destType, nameNode, ignoreEmptyContainers);
2268
2289
  }
2269
- writeTypeCache(nameNode, { type: destType, isIncomplete: isTypeIncomplete }, 0 /* EvaluatorFlags.None */);
2290
+ writeTypeCache(nameNode, { type: destType, isIncomplete: typeResult.isIncomplete }, 0 /* EvaluatorFlags.None */);
2270
2291
  }
2271
- function assignTypeToMemberAccessNode(target, type, isTypeIncomplete, srcExpr, expectedTypeDiagAddendum) {
2292
+ function assignTypeToMemberAccessNode(target, typeResult, srcExpr, expectedTypeDiagAddendum) {
2272
2293
  var _a;
2273
2294
  const baseTypeResult = getTypeOfExpression(target.leftExpression, 2 /* EvaluatorFlags.MemberAccessBaseDefaults */);
2274
2295
  const baseType = makeTopLevelTypeVarsConcrete(baseTypeResult.type);
@@ -2281,14 +2302,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2281
2302
  if (classTypeResults && (0, types_1.isInstantiableClass)(classTypeResults.classType)) {
2282
2303
  if ((0, types_1.isClassInstance)(baseType)) {
2283
2304
  if (types_1.ClassType.isSameGenericClass(baseType, classTypeResults.classType)) {
2284
- assignTypeToMemberVariable(target, type, isTypeIncomplete,
2285
- /* isInstanceMember */ true, srcExpr);
2305
+ assignTypeToMemberVariable(target, typeResult, /* isInstanceMember */ true, srcExpr);
2286
2306
  }
2287
2307
  }
2288
2308
  else if ((0, types_1.isInstantiableClass)(baseType)) {
2289
2309
  if (types_1.ClassType.isSameGenericClass(baseType, classTypeResults.classType)) {
2290
- assignTypeToMemberVariable(target, type, isTypeIncomplete,
2291
- /* isInstanceMember */ false, srcExpr);
2310
+ assignTypeToMemberVariable(target, typeResult, /* isInstanceMember */ false, srcExpr);
2292
2311
  }
2293
2312
  }
2294
2313
  // Assignments to instance or class variables through "self" or "cls" is not
@@ -2309,7 +2328,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2309
2328
  }
2310
2329
  const setTypeResult = getTypeOfMemberAccessWithBaseType(target, baseTypeResult, {
2311
2330
  method: 'set',
2312
- setType: { type, isIncomplete: isTypeIncomplete },
2331
+ setType: typeResult,
2313
2332
  setErrorNode: srcExpr,
2314
2333
  setExpectedTypeDiag: expectedTypeDiagAddendum,
2315
2334
  }, 0 /* EvaluatorFlags.None */);
@@ -2317,14 +2336,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2317
2336
  setAsymmetricDescriptorAssignment(target);
2318
2337
  }
2319
2338
  const resultToCache = {
2320
- type: (_a = setTypeResult.narrowedTypeForSet) !== null && _a !== void 0 ? _a : type,
2321
- isIncomplete: isTypeIncomplete,
2339
+ type: (_a = setTypeResult.narrowedTypeForSet) !== null && _a !== void 0 ? _a : typeResult.type,
2340
+ isIncomplete: typeResult.isIncomplete,
2322
2341
  memberAccessDeprecationInfo: setTypeResult.memberAccessDeprecationInfo,
2323
2342
  };
2324
2343
  writeTypeCache(target.memberName, resultToCache, 0 /* EvaluatorFlags.None */);
2325
2344
  writeTypeCache(target, resultToCache, 0 /* EvaluatorFlags.None */);
2326
2345
  }
2327
- function assignTypeToMemberVariable(node, srcType, isTypeIncomplete, isInstanceMember, srcExprNode) {
2346
+ function assignTypeToMemberVariable(node, typeResult, isInstanceMember, srcExprNode) {
2328
2347
  var _a;
2329
2348
  const memberName = node.memberName.value;
2330
2349
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
@@ -2394,20 +2413,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2394
2413
  // The class variable is accessed in this case.
2395
2414
  setSymbolAccessed(fileInfo, memberInfo.symbol, node.memberName);
2396
2415
  const memberType = getTypeOfMember(memberInfo);
2397
- srcType = (0, types_1.combineTypes)([srcType, memberType]);
2416
+ typeResult = { ...typeResult, type: (0, types_1.combineTypes)([typeResult.type, memberType]) };
2398
2417
  }
2399
2418
  }
2400
2419
  }
2401
2420
  }
2402
2421
  // Look up the member info again, now that we've potentially updated it.
2403
2422
  memberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, memberName, 64 /* MemberAccessFlags.DeclaredTypesOnly */);
2404
- if (!memberInfo && srcExprNode && !isTypeIncomplete) {
2405
- reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownMemberType, diagnosticRules_1.DiagnosticRule.reportUnknownMemberType, node.memberName, srcType, node,
2423
+ if (!memberInfo && srcExprNode && !typeResult.isIncomplete) {
2424
+ reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownMemberType, diagnosticRules_1.DiagnosticRule.reportUnknownMemberType, node.memberName, typeResult.type, node,
2406
2425
  /* ignoreEmptyContainers */ true);
2407
2426
  }
2408
2427
  }
2409
2428
  }
2410
- function assignTypeToTupleOrListNode(target, type, isTypeIncomplete, srcExpr) {
2429
+ function assignTypeToTupleOrListNode(target, typeResult, srcExpr) {
2411
2430
  const targetExpressions = target.nodeType === 34 /* ParseNodeType.List */ ? target.entries : target.expressions;
2412
2431
  // Initialize the array of target types, one for each target.
2413
2432
  const targetTypes = new Array(targetExpressions.length);
@@ -2418,9 +2437,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2418
2437
  // Do any of the targets use an unpack operator? If so, it will consume all of the
2419
2438
  // entries at that location.
2420
2439
  const unpackIndex = targetExpressions.findIndex((expr) => expr.nodeType === 56 /* ParseNodeType.Unpack */);
2421
- type = makeTopLevelTypeVarsConcrete(type);
2440
+ typeResult = { ...typeResult, type: makeTopLevelTypeVarsConcrete(typeResult.type) };
2422
2441
  const diagAddendum = new diagnostic_1.DiagnosticAddendum();
2423
- (0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
2442
+ (0, typeUtils_1.doForEachSubtype)(typeResult.type, (subtype) => {
2424
2443
  var _a, _b;
2425
2444
  // Is this subtype a tuple?
2426
2445
  const tupleType = (0, typeUtils_1.getSpecializedTupleType)(subtype);
@@ -2475,7 +2494,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2475
2494
  else {
2476
2495
  // The assigned expression isn't a tuple, so it had better
2477
2496
  // be some iterable type.
2478
- const iterableType = (_b = (_a = getTypeOfIterator({ type: subtype, isIncomplete: isTypeIncomplete }, /* isAsync */ false, srcExpr)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
2497
+ const iterableType = (_b = (_a = getTypeOfIterator({ type: subtype, isIncomplete: typeResult.isIncomplete },
2498
+ /* isAsync */ false, srcExpr)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
2479
2499
  for (let index = 0; index < targetExpressions.length; index++) {
2480
2500
  targetTypes[index].push((0, typeUtils_1.addConditionToType)(iterableType, (0, typeUtils_1.getTypeCondition)(subtype)));
2481
2501
  }
@@ -2485,7 +2505,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2485
2505
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, (target.nodeType === 34 /* ParseNodeType.List */
2486
2506
  ? localize_1.LocMessage.listAssignmentMismatch()
2487
2507
  : localize_1.LocMessage.tupleAssignmentMismatch()).format({
2488
- type: printType(type),
2508
+ type: printType(typeResult.type),
2489
2509
  }) + diagAddendum.getString(), target);
2490
2510
  }
2491
2511
  // Assign the resulting types to the individual names in the tuple
@@ -2493,9 +2513,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2493
2513
  targetExpressions.forEach((expr, index) => {
2494
2514
  const typeList = targetTypes[index];
2495
2515
  const targetType = typeList.length === 0 ? types_1.UnknownType.create() : (0, types_1.combineTypes)(typeList);
2496
- assignTypeToExpression(expr, targetType, isTypeIncomplete, srcExpr, /* ignoreEmptyContainers */ true);
2516
+ assignTypeToExpression(expr, { type: targetType, isIncomplete: typeResult.isIncomplete }, srcExpr,
2517
+ /* ignoreEmptyContainers */ true);
2497
2518
  });
2498
- writeTypeCache(target, { type, isIncomplete: isTypeIncomplete }, 0 /* EvaluatorFlags.None */);
2519
+ writeTypeCache(target, typeResult, 0 /* EvaluatorFlags.None */);
2499
2520
  }
2500
2521
  // If the type includes promotion types, expand these to their constituent types.
2501
2522
  function expandPromotionTypes(node, type, excludeBytes = false) {
@@ -2546,11 +2567,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2546
2567
  }
2547
2568
  // If this is a function that contains only a ParamSpec (no additional
2548
2569
  // parameters), convert it to a concrete type of (*args: Any, **kwargs: Any).
2549
- if (makeParamSpecsConcrete &&
2550
- (0, types_1.isFunction)(subtype) &&
2551
- subtype.details.parameters.length === 0 &&
2552
- subtype.details.paramSpec) {
2553
- return types_1.FunctionType.cloneForParamSpec(subtype, (0, typeUtils_1.getUnknownTypeForCallable)());
2570
+ if (makeParamSpecsConcrete && (0, types_1.isFunction)(subtype)) {
2571
+ const convertedType = (0, typeUtils_1.convertParamSpecValueToType)(subtype);
2572
+ if ((0, types_1.isParamSpec)(convertedType)) {
2573
+ return types_1.FunctionType.applyParamSpecValue(subtype, (0, typeUtils_1.getUnknownTypeForCallable)());
2574
+ }
2554
2575
  }
2555
2576
  if ((0, types_1.isTypeVar)(subtype) && subtype.details.isVariadic) {
2556
2577
  // If it's in a union, convert to type or object.
@@ -2719,9 +2740,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2719
2740
  });
2720
2741
  }
2721
2742
  }
2722
- function assignTypeToExpression(target, type, isTypeIncomplete, srcExpr, ignoreEmptyContainers = false, allowAssignmentToFinalVar = false, expectedTypeDiagAddendum) {
2743
+ function assignTypeToExpression(target, typeResult, srcExpr, ignoreEmptyContainers = false, allowAssignmentToFinalVar = false, expectedTypeDiagAddendum) {
2723
2744
  // Is the source expression a TypeVar() call?
2724
- if ((0, types_1.isTypeVar)(type)) {
2745
+ if ((0, types_1.isTypeVar)(typeResult.type)) {
2725
2746
  if (srcExpr && srcExpr.nodeType === 9 /* ParseNodeType.Call */) {
2726
2747
  const callType = getTypeOfExpression(srcExpr.leftExpression, 2 /* EvaluatorFlags.CallBaseDefaults */).type;
2727
2748
  if ((0, types_1.isInstantiableClass)(callType) &&
@@ -2729,13 +2750,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2729
2750
  types_1.ClassType.isBuiltIn(callType, 'TypeVarTuple') ||
2730
2751
  types_1.ClassType.isBuiltIn(callType, 'ParamSpec'))) {
2731
2752
  const typeVarTarget = target.nodeType === 54 /* ParseNodeType.TypeAnnotation */ ? target.valueExpression : target;
2732
- if (typeVarTarget.nodeType !== 38 /* ParseNodeType.Name */ || typeVarTarget.value !== type.details.name) {
2733
- addError(type.details.isParamSpec
2753
+ if (typeVarTarget.nodeType !== 38 /* ParseNodeType.Name */ ||
2754
+ typeVarTarget.value !== typeResult.type.details.name) {
2755
+ addError(typeResult.type.details.isParamSpec
2734
2756
  ? localize_1.LocMessage.paramSpecAssignedName().format({
2735
- name: types_1.TypeVarType.getReadableName(type),
2757
+ name: types_1.TypeVarType.getReadableName(typeResult.type),
2736
2758
  })
2737
2759
  : localize_1.LocMessage.typeVarAssignedName().format({
2738
- name: types_1.TypeVarType.getReadableName(type),
2760
+ name: types_1.TypeVarType.getReadableName(typeResult.type),
2739
2761
  }), typeVarTarget);
2740
2762
  }
2741
2763
  }
@@ -2744,30 +2766,32 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2744
2766
  // If the type was partially unbound, an error will have already been logged.
2745
2767
  // Remove the unbound before assigning to the target expression so the unbound
2746
2768
  // error doesn't propagate.
2747
- type = (0, types_1.removeUnbound)(type);
2769
+ if ((0, types_1.findSubtype)(typeResult.type, (subtype) => (0, types_1.isUnbound)(subtype))) {
2770
+ typeResult = { ...typeResult, type: (0, types_1.removeUnbound)(typeResult.type) };
2771
+ }
2748
2772
  switch (target.nodeType) {
2749
2773
  case 38 /* ParseNodeType.Name */: {
2750
- assignTypeToNameNode(target, type, isTypeIncomplete, ignoreEmptyContainers, srcExpr, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
2774
+ assignTypeToNameNode(target, typeResult, ignoreEmptyContainers, srcExpr, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
2751
2775
  break;
2752
2776
  }
2753
2777
  case 35 /* ParseNodeType.MemberAccess */: {
2754
- assignTypeToMemberAccessNode(target, type, isTypeIncomplete, srcExpr, expectedTypeDiagAddendum);
2778
+ assignTypeToMemberAccessNode(target, typeResult, srcExpr, expectedTypeDiagAddendum);
2755
2779
  break;
2756
2780
  }
2757
2781
  case 27 /* ParseNodeType.Index */: {
2758
2782
  const baseTypeResult = getTypeOfExpression(target.baseExpression, 2 /* EvaluatorFlags.IndexBaseDefaults */);
2759
2783
  getTypeOfIndexWithBaseType(target, baseTypeResult, {
2760
2784
  method: 'set',
2761
- setType: { type, isIncomplete: isTypeIncomplete },
2785
+ setType: typeResult,
2762
2786
  setErrorNode: srcExpr,
2763
2787
  setExpectedTypeDiag: expectedTypeDiagAddendum,
2764
2788
  }, 0 /* EvaluatorFlags.None */);
2765
- writeTypeCache(target, { type, isIncomplete: isTypeIncomplete }, 0 /* EvaluatorFlags.None */);
2789
+ writeTypeCache(target, typeResult, 0 /* EvaluatorFlags.None */);
2766
2790
  break;
2767
2791
  }
2768
2792
  case 34 /* ParseNodeType.List */:
2769
2793
  case 52 /* ParseNodeType.Tuple */: {
2770
- assignTypeToTupleOrListNode(target, type, isTypeIncomplete, srcExpr);
2794
+ assignTypeToTupleOrListNode(target, typeResult, srcExpr);
2771
2795
  break;
2772
2796
  }
2773
2797
  case 54 /* ParseNodeType.TypeAnnotation */: {
@@ -2782,23 +2806,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2782
2806
  if (!isBareFinalOrClassVar) {
2783
2807
  const isTypeAliasAnnotation = (0, types_1.isClassInstance)(annotationType) && types_1.ClassType.isBuiltIn(annotationType, 'TypeAlias');
2784
2808
  if (!isTypeAliasAnnotation) {
2785
- if (assignType(annotationType, type)) {
2809
+ if (assignType(annotationType, typeResult.type)) {
2786
2810
  // Don't attempt to narrow based on the annotated type if the type
2787
2811
  // is a enum because the annotated type in an enum doesn't reflect
2788
2812
  // the type of the symbol.
2789
- if (!(0, types_1.isClassInstance)(type) || !types_1.ClassType.isEnumClass(type)) {
2790
- type = narrowTypeBasedOnAssignment(target, annotationType, type);
2813
+ if (!(0, types_1.isClassInstance)(typeResult.type) || !types_1.ClassType.isEnumClass(typeResult.type)) {
2814
+ typeResult = narrowTypeBasedOnAssignment(target, annotationType, typeResult);
2791
2815
  }
2792
2816
  }
2793
2817
  }
2794
2818
  }
2795
- assignTypeToExpression(target.valueExpression, type, isTypeIncomplete, srcExpr, ignoreEmptyContainers, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
2819
+ assignTypeToExpression(target.valueExpression, typeResult, srcExpr, ignoreEmptyContainers, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
2796
2820
  break;
2797
2821
  }
2798
2822
  case 56 /* ParseNodeType.Unpack */: {
2799
2823
  if (target.expression.nodeType === 38 /* ParseNodeType.Name */) {
2800
- assignTypeToNameNode(target.expression, getBuiltInObject(target.expression, 'list', [type]),
2801
- /* isIncomplete */ false, ignoreEmptyContainers, srcExpr);
2824
+ assignTypeToNameNode(target.expression, {
2825
+ type: getBuiltInObject(target.expression, 'list', [typeResult.type]),
2826
+ isIncomplete: typeResult.isIncomplete,
2827
+ }, ignoreEmptyContainers, srcExpr);
2802
2828
  }
2803
2829
  break;
2804
2830
  }
@@ -4014,7 +4040,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4014
4040
  // descriptor-based accesses.
4015
4041
  narrowedTypeForSet = isDescriptorApplied
4016
4042
  ? usage.setType.type
4017
- : narrowTypeBasedOnAssignment(errorNode, type, usage.setType.type);
4043
+ : narrowTypeBasedOnAssignment(errorNode, type, usage.setType).type;
4018
4044
  }
4019
4045
  // Verify that the assigned type is compatible.
4020
4046
  if (!assignType(type, usage.setType.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum())) {
@@ -4030,7 +4056,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4030
4056
  isDescriptorError = true;
4031
4057
  }
4032
4058
  if ((0, types_1.isInstantiableClass)(memberInfo.classType) &&
4033
- types_1.ClassType.isFrozenDataClass(memberInfo.classType) &&
4059
+ types_1.ClassType.isDataClassFrozen(memberInfo.classType) &&
4034
4060
  isAccessedThroughObject) {
4035
4061
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.dataClassFrozen().format({
4036
4062
  name: printType(types_1.ClassType.cloneAsInstance(memberInfo.classType)),
@@ -4301,7 +4327,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4301
4327
  // If there's no declared return type on the getter, assume it's symmetric.
4302
4328
  if (setterType.details.parameters.length >= 3 && getterType.details.declaredReturnType) {
4303
4329
  const setterValueType = types_1.FunctionType.getEffectiveParameterType(setterType, 2);
4304
- const getterReturnType = (_a = types_1.FunctionType.getSpecializedReturnType(getterType)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
4330
+ const getterReturnType = (_a = types_1.FunctionType.getEffectiveReturnType(getterType)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
4305
4331
  if (!(0, types_1.isTypeSame)(setterValueType, getterReturnType)) {
4306
4332
  isAsymmetric = true;
4307
4333
  }
@@ -4333,7 +4359,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4333
4359
  // If there's no declared return type on the getter, assume it's symmetric.
4334
4360
  if (setterType.details.parameters.length >= 3 && getterType.details.declaredReturnType) {
4335
4361
  const setterValueType = types_1.FunctionType.getEffectiveParameterType(setterType, 2);
4336
- const getterReturnType = (_a = types_1.FunctionType.getSpecializedReturnType(getterType)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
4362
+ const getterReturnType = (_a = types_1.FunctionType.getEffectiveReturnType(getterType)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
4337
4363
  if (!(0, types_1.isTypeSame)(setterValueType, getterReturnType)) {
4338
4364
  isAsymmetric = true;
4339
4365
  }
@@ -4699,11 +4725,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4699
4725
  if (index === concatTypeArgs.length - 1) {
4700
4726
  types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
4701
4727
  if ((0, types_1.isParamSpec)(typeArg)) {
4702
- functionType.details.paramSpec = typeArg;
4728
+ types_1.FunctionType.addParamSpecVariadics(functionType, typeArg);
4703
4729
  }
4704
4730
  else if ((0, typeUtils_1.isEllipsisType)(typeArg)) {
4705
4731
  types_1.FunctionType.addDefaultParameters(functionType);
4706
- functionType.details.flags |= 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
4732
+ functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
4707
4733
  }
4708
4734
  }
4709
4735
  else {
@@ -4720,7 +4746,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4720
4746
  (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4721
4747
  }
4722
4748
  else if ((0, typeUtils_1.isEllipsisType)(typeArgType)) {
4723
- const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */);
4749
+ const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.GradualCallableForm */);
4724
4750
  types_1.FunctionType.addDefaultParameters(functionType);
4725
4751
  (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext);
4726
4752
  }
@@ -5628,7 +5654,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5628
5654
  // the base type of this call is not the same as one of the tracked signatures.
5629
5655
  // This is important for nested generic calls (e.g. "foo(foo(x))").
5630
5656
  if (signatureTracker) {
5631
- baseTypeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(baseTypeResult.type, signatureTracker, node.leftExpression.start);
5657
+ baseTypeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(baseTypeResult.type, signatureTracker, node.start);
5632
5658
  }
5633
5659
  if (!(0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
5634
5660
  if (node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ && node.leftExpression.value === 'super') {
@@ -5822,24 +5848,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5822
5848
  const type = typeResult.type;
5823
5849
  const exprString = ParseTreeUtils.printExpression(arg0Value);
5824
5850
  const typeString = printType(type, { expandTypeAlias: true });
5825
- if (expectedText !== undefined) {
5826
- if (expectedText !== typeString) {
5827
- addError(localize_1.LocMessage.revealTypeExpectedTextMismatch().format({
5828
- expected: expectedText,
5829
- received: typeString,
5830
- }), expectedTextNode !== null && expectedTextNode !== void 0 ? expectedTextNode : arg0Value);
5851
+ if (!typeResult.isIncomplete) {
5852
+ if (expectedText !== undefined) {
5853
+ if (expectedText !== typeString) {
5854
+ addError(localize_1.LocMessage.revealTypeExpectedTextMismatch().format({
5855
+ expected: expectedText,
5856
+ received: typeString,
5857
+ }), expectedTextNode !== null && expectedTextNode !== void 0 ? expectedTextNode : arg0Value);
5858
+ }
5831
5859
  }
5832
- }
5833
- if (expectedRevealType) {
5834
- if (!(0, types_1.isTypeSame)(expectedRevealType, type, { ignorePseudoGeneric: true })) {
5835
- const expectedRevealTypeText = printType(expectedRevealType);
5836
- addError(localize_1.LocMessage.revealTypeExpectedTypeMismatch().format({
5837
- expected: expectedRevealTypeText,
5838
- received: typeString,
5839
- }), expectedRevealTypeNode !== null && expectedRevealTypeNode !== void 0 ? expectedRevealTypeNode : arg0Value);
5860
+ if (expectedRevealType) {
5861
+ if (!(0, types_1.isTypeSame)(expectedRevealType, type, { ignorePseudoGeneric: true })) {
5862
+ const expectedRevealTypeText = printType(expectedRevealType);
5863
+ addError(localize_1.LocMessage.revealTypeExpectedTypeMismatch().format({
5864
+ expected: expectedRevealTypeText,
5865
+ received: typeString,
5866
+ }), expectedRevealTypeNode !== null && expectedRevealTypeNode !== void 0 ? expectedRevealTypeNode : arg0Value);
5867
+ }
5840
5868
  }
5869
+ addInformation(localize_1.LocAddendum.typeOfSymbol().format({ name: exprString, type: typeString }), node.arguments[0]);
5841
5870
  }
5842
- addInformation(localize_1.LocAddendum.typeOfSymbol().format({ name: exprString, type: typeString }), node.arguments[0]);
5843
5871
  return { type, isIncomplete: typeResult.isIncomplete };
5844
5872
  }
5845
5873
  function getTypeOfRevealLocals(node) {
@@ -6943,6 +6971,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6943
6971
  if ((0, types_1.isTypeVar)(unexpandedCallType)) {
6944
6972
  returnType = (0, typeUtils_1.convertToInstance)(unexpandedCallType);
6945
6973
  }
6974
+ // If we instantiated the "deprecated" class, attach the deprecation
6975
+ // message to the instance.
6976
+ if (errorNode.nodeType === 9 /* ParseNodeType.Call */ &&
6977
+ returnType &&
6978
+ (0, types_1.isClassInstance)(returnType) &&
6979
+ types_1.ClassType.isBuiltIn(returnType, 'deprecated')) {
6980
+ returnType = types_1.ClassType.cloneForDeprecatedInstance(returnType, (0, decorators_1.getDeprecatedMessageFromCall)(errorNode));
6981
+ }
6946
6982
  // If we instantiated a type, transform it into a class.
6947
6983
  // This can happen if someone directly instantiates a metaclass
6948
6984
  // deriving from type.
@@ -7074,6 +7110,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7074
7110
  let reportedArgError = false;
7075
7111
  let isTypeIncomplete = !!typeResult.isIncomplete;
7076
7112
  let isVariadicTypeVarFullyMatched = false;
7113
+ const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(typeResult.type);
7077
7114
  // Expand any unpacked tuples in the arg list.
7078
7115
  argList = expandArgList(argList, signatureTracker);
7079
7116
  // Build a map of parameters by name.
@@ -7099,6 +7136,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7099
7136
  let paramSpecArgList;
7100
7137
  let paramSpecTarget;
7101
7138
  let hasParamSpecArgsKwargs = false;
7139
+ // Determine how many positional args are being passed before
7140
+ // we see a keyword arg.
7141
+ let positionalArgCount = argList.findIndex((arg) => arg.argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */ || arg.name !== undefined);
7142
+ if (positionalArgCount < 0) {
7143
+ positionalArgCount = argList.length;
7144
+ }
7102
7145
  if (varArgListParamIndex !== undefined && varArgDictParamIndex !== undefined) {
7103
7146
  (0, debug_1.assert)(paramDetails.params[varArgListParamIndex], 'varArgListParamIndex params entry is undefined');
7104
7147
  const varArgListParam = paramDetails.params[varArgListParamIndex].param;
@@ -7120,16 +7163,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7120
7163
  }
7121
7164
  else {
7122
7165
  positionalOnlyLimitIndex = varArgListParamIndex;
7166
+ positionalArgCount = varArgListParamIndex;
7167
+ positionParamLimitIndex = varArgListParamIndex;
7123
7168
  }
7124
7169
  }
7125
7170
  }
7126
- else if (typeResult.type.details.paramSpec) {
7127
- const paramSpecScopeId = typeResult.type.details.paramSpec.scopeId;
7128
- if ((_c = (0, typeUtils_1.getTypeVarScopeIds)(typeResult.type)) === null || _c === void 0 ? void 0 : _c.some((id) => id === paramSpecScopeId)) {
7171
+ else if (paramSpec) {
7172
+ if ((_c = (0, typeUtils_1.getTypeVarScopeIds)(typeResult.type)) === null || _c === void 0 ? void 0 : _c.some((id) => id === paramSpec.scopeId)) {
7129
7173
  hasParamSpecArgsKwargs = true;
7130
7174
  paramSpecArgList = [];
7131
- paramSpecTarget = types_1.TypeVarType.cloneForParamSpecAccess(typeResult.type.details.paramSpec,
7132
- /* access */ undefined);
7175
+ paramSpecTarget = paramSpec;
7133
7176
  }
7134
7177
  }
7135
7178
  // If there are keyword arguments present after a *args argument,
@@ -7159,12 +7202,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7159
7202
  if (positionParamLimitIndex < 0) {
7160
7203
  positionParamLimitIndex = paramDetails.params.length;
7161
7204
  }
7162
- // Determine how many positional args are being passed before
7163
- // we see a keyword arg.
7164
- let positionalArgCount = argList.findIndex((arg) => arg.argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */ || arg.name !== undefined);
7165
- if (positionalArgCount < 0) {
7166
- positionalArgCount = argList.length;
7167
- }
7168
7205
  let validateArgTypeParams = [];
7169
7206
  let activeParam;
7170
7207
  function trySetActive(arg, param) {
@@ -7541,13 +7578,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7541
7578
  reportedArgError = true;
7542
7579
  }
7543
7580
  }
7544
- else if (typeResult.type.details.paramSpec &&
7545
- (0, parameterUtils_1.isParamSpecKwargsArgument)(typeResult.type.details.paramSpec, argType)) {
7581
+ else if (paramSpec && (0, parameterUtils_1.isParamSpecKwargsArgument)(paramSpec, argType)) {
7546
7582
  unpackedDictionaryArgType = types_1.AnyType.create();
7547
7583
  if (!paramSpecArgList) {
7548
7584
  validateArgTypeParams.push({
7549
7585
  paramCategory: 2 /* ParameterCategory.KwargsDict */,
7550
- paramType: typeResult.type.details.paramSpec,
7586
+ paramType: paramSpec,
7551
7587
  requiresTypeVarMatching: false,
7552
7588
  argument: argList[argIndex],
7553
7589
  argType: (0, types_1.isParamSpec)(argType) ? undefined : types_1.AnyType.create(),
@@ -7685,17 +7721,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7685
7721
  else if (argList[argIndex].argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
7686
7722
  // Handle the case where a *args: P.args (or *args: Any) is passed as an
7687
7723
  // argument to a function that accepts a ParamSpec.
7688
- if (typeResult.type.details.paramSpec) {
7724
+ if (paramSpec) {
7689
7725
  const argTypeResult = getTypeOfArgument(argList[argIndex],
7690
7726
  /* inferenceContext */ undefined, signatureTracker);
7691
7727
  const argType = argTypeResult.type;
7692
7728
  if (argTypeResult.isIncomplete) {
7693
7729
  isTypeIncomplete = true;
7694
7730
  }
7695
- if ((0, parameterUtils_1.isParamSpecArgsArgument)(typeResult.type.details.paramSpec, argType)) {
7731
+ if ((0, parameterUtils_1.isParamSpecArgsArgument)(paramSpec, argType)) {
7696
7732
  validateArgTypeParams.push({
7697
7733
  paramCategory: 1 /* ParameterCategory.ArgsList */,
7698
- paramType: typeResult.type.details.paramSpec,
7734
+ paramType: paramSpec,
7699
7735
  requiresTypeVarMatching: false,
7700
7736
  argument: argList[argIndex],
7701
7737
  argType: (0, types_1.isParamSpec)(argType) ? undefined : types_1.AnyType.create(),
@@ -7904,7 +7940,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7904
7940
  (0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) ||
7905
7941
  (0, types_1.isNever)(inferenceContext.expectedType) ||
7906
7942
  !type.details.declaredReturnType ||
7907
- !(0, typeUtils_1.requiresSpecialization)((_a = types_1.FunctionType.getSpecializedReturnType(type)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create())) {
7943
+ !(0, typeUtils_1.requiresSpecialization)((_a = types_1.FunctionType.getEffectiveReturnType(type)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create())) {
7908
7944
  return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck);
7909
7945
  }
7910
7946
  const effectiveReturnType = getFunctionEffectiveReturnType(type);
@@ -7995,6 +8031,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7995
8031
  let specializedInitSelfType;
7996
8032
  let anyOrUnknownArgument;
7997
8033
  const typeCondition = (0, typeUtils_1.getTypeCondition)(type);
8034
+ const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
7998
8035
  // Check for an attempt to invoke an unimplemented abstract method.
7999
8036
  if (type.boundToType && !type.boundToType.includeSubclasses && type.details.methodClass) {
8000
8037
  const abstractSymbolInfo = getAbstractSymbolInfo(type.details.methodClass, type.details.name);
@@ -8004,36 +8041,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8004
8041
  }), errorNode.nodeType === 9 /* ParseNodeType.Call */ ? errorNode.leftExpression : errorNode);
8005
8042
  }
8006
8043
  }
8007
- if (type.boundTypeVarScopeId) {
8008
- // If the function was bound to a class or object and was a constructor, a
8009
- // static method or a class method, it's possible that some of that class's
8010
- // type variables have not yet been solved. Add that class's TypeVar scope ID.
8011
- if (type.preBoundFlags !== undefined && type.boundToType && (0, typeUtils_1.requiresSpecialization)(type.boundToType)) {
8012
- if (type.preBoundFlags &
8013
- (4 /* FunctionTypeFlags.StaticMethod */ | 2 /* FunctionTypeFlags.ClassMethod */ | 4 /* FunctionTypeFlags.StaticMethod */)) {
8014
- typeVarContext.addSolveForScope(type.boundTypeVarScopeId);
8015
- }
8016
- }
8017
- // The type annotation for the "self" parameter in an __init__ method to
8018
- // can incluence the type being constructed.
8019
- if (type.details.name === '__init__' &&
8020
- type.strippedFirstParamType &&
8021
- type.boundToType &&
8022
- (0, types_1.isClassInstance)(type.strippedFirstParamType) &&
8023
- (0, types_1.isClassInstance)(type.boundToType) &&
8024
- types_1.ClassType.isSameGenericClass(type.strippedFirstParamType, type.boundToType) &&
8025
- type.strippedFirstParamType.typeArguments) {
8026
- const typeParams = type.strippedFirstParamType.details.typeParameters;
8027
- specializedInitSelfType = type.strippedFirstParamType;
8028
- type.strippedFirstParamType.typeArguments.forEach((typeArg, index) => {
8029
- if (index < typeParams.length) {
8030
- const typeParam = typeParams[index];
8031
- if (!(0, types_1.isTypeSame)(typeParam, typeArg, { ignorePseudoGeneric: true })) {
8032
- typeVarContext.setTypeVarType(typeParams[index], typeArg);
8033
- }
8044
+ // The type annotation for the "self" parameter in an __init__ method to
8045
+ // can influence the type being constructed.
8046
+ if (type.details.name === '__init__' &&
8047
+ type.strippedFirstParamType &&
8048
+ type.boundToType &&
8049
+ (0, types_1.isClassInstance)(type.strippedFirstParamType) &&
8050
+ (0, types_1.isClassInstance)(type.boundToType) &&
8051
+ types_1.ClassType.isSameGenericClass(type.strippedFirstParamType, type.boundToType) &&
8052
+ type.strippedFirstParamType.typeArguments) {
8053
+ const typeParams = type.strippedFirstParamType.details.typeParameters;
8054
+ specializedInitSelfType = type.strippedFirstParamType;
8055
+ type.strippedFirstParamType.typeArguments.forEach((typeArg, index) => {
8056
+ if (index < typeParams.length) {
8057
+ const typeParam = typeParams[index];
8058
+ if (!(0, types_1.isTypeSame)(typeParam, typeArg, { ignorePseudoGeneric: true })) {
8059
+ typeVarContext.setTypeVarType(typeParams[index], typeArg);
8034
8060
  }
8035
- });
8036
- }
8061
+ }
8062
+ });
8037
8063
  }
8038
8064
  // Special-case a few built-in calls that are often used for
8039
8065
  // casting or checking for unknown types.
@@ -8124,14 +8150,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8124
8150
  ? (0, typeUtils_1.preserveUnknown)(argResult.argType, anyOrUnknownArgument)
8125
8151
  : argResult.argType;
8126
8152
  }
8127
- if (type.details.paramSpec) {
8153
+ if (paramSpec) {
8128
8154
  if (argParam.argument.argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
8129
- if ((0, parameterUtils_1.isParamSpecArgsArgument)(type.details.paramSpec, argResult.argType)) {
8155
+ if ((0, parameterUtils_1.isParamSpecArgsArgument)(paramSpec, argResult.argType)) {
8130
8156
  sawParamSpecArgs = true;
8131
8157
  }
8132
8158
  }
8133
8159
  if (argParam.argument.argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */) {
8134
- if ((0, parameterUtils_1.isParamSpecKwargsArgument)(type.details.paramSpec, argResult.argType)) {
8160
+ if ((0, parameterUtils_1.isParamSpecKwargsArgument)(paramSpec, argResult.argType)) {
8135
8161
  sawParamSpecKwargs = true;
8136
8162
  }
8137
8163
  }
@@ -8147,10 +8173,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8147
8173
  }
8148
8174
  paramSpecTypeVarContext = paramSpecArgResult.typeVarContexts;
8149
8175
  }
8150
- else if (type.details.paramSpec) {
8176
+ else if (paramSpec) {
8151
8177
  if (!sawParamSpecArgs || !sawParamSpecKwargs) {
8152
8178
  if (!isTypeIncomplete) {
8153
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramSpecArgsMissing().format({ type: printType(type.details.paramSpec) }), errorNode);
8179
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramSpecArgsMissing().format({ type: printType(paramSpec) }), errorNode);
8154
8180
  }
8155
8181
  argumentErrors = true;
8156
8182
  argumentMatchScore += 1;
@@ -8373,39 +8399,42 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8373
8399
  });
8374
8400
  return { argumentErrors: true, typeVarContexts: [srcTypeVarContext] };
8375
8401
  }
8402
+ const functionParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(functionType);
8403
+ const functionWithoutParamSpec = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(functionType);
8376
8404
  // Handle the recursive case where we're passing (*args: P.args, **kwargs: P.args)
8377
8405
  // a remaining function of type (*P).
8378
- if (functionType.details.paramSpec &&
8379
- functionType.details.parameters.length === 0 &&
8380
- (0, types_1.isTypeSame)(functionType.details.paramSpec, paramSpec)) {
8406
+ if (functionParamSpec &&
8407
+ functionWithoutParamSpec.details.parameters.length === 0 &&
8408
+ (0, types_1.isTypeSame)(functionParamSpec, paramSpec)) {
8381
8409
  // If there are any arguments other than *args: P.args or **kwargs: P.kwargs,
8382
8410
  // report an error.
8383
- let sawArgs = false;
8384
- let sawKwargs = false;
8411
+ let argsCount = 0;
8412
+ let kwargsCount = 0;
8385
8413
  let argumentErrors = false;
8386
8414
  let argErrorNode;
8387
8415
  for (const arg of argList) {
8388
8416
  const argType = (_a = getTypeOfArgument(arg, /* inferenceContext */ undefined, signatureTracker)) === null || _a === void 0 ? void 0 : _a.type;
8389
- const isArgTypeCompatible = argType && ((0, types_1.isTypeSame)(argType, paramSpec, { ignoreTypeFlags: true }) || (0, types_1.isAnyOrUnknown)(argType));
8390
- if (arg.argumentCategory === 1 /* ArgumentCategory.UnpackedList */ && !sawArgs && isArgTypeCompatible) {
8391
- sawArgs = true;
8417
+ if (arg.argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
8418
+ if ((0, parameterUtils_1.isParamSpecArgsArgument)(paramSpec, argType)) {
8419
+ argsCount++;
8420
+ }
8392
8421
  }
8393
- else if (arg.argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */ &&
8394
- !sawKwargs &&
8395
- isArgTypeCompatible) {
8396
- sawKwargs = true;
8422
+ else if (arg.argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */) {
8423
+ if ((0, parameterUtils_1.isParamSpecKwargsArgument)(paramSpec, argType)) {
8424
+ kwargsCount++;
8425
+ }
8397
8426
  }
8398
8427
  else {
8399
8428
  argErrorNode = argErrorNode !== null && argErrorNode !== void 0 ? argErrorNode : arg.valueExpression;
8400
8429
  argumentErrors = true;
8401
8430
  }
8402
8431
  }
8403
- if (!sawArgs || !sawKwargs) {
8432
+ if (argsCount !== 1 || kwargsCount !== 1) {
8404
8433
  argumentErrors = true;
8405
8434
  }
8406
8435
  if (argumentErrors) {
8407
8436
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramSpecArgsMissing().format({
8408
- type: printType(functionType.details.paramSpec),
8437
+ type: printType(functionParamSpec),
8409
8438
  }), argErrorNode !== null && argErrorNode !== void 0 ? argErrorNode : errorNode);
8410
8439
  }
8411
8440
  return { argumentErrors, typeVarContexts: [srcTypeVarContext] };
@@ -8438,7 +8467,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8438
8467
  // the solved TypeVars if the typeVarContext has more than one signature.
8439
8468
  // This will expand the ParamSpec into an overload, which will cause problems.
8440
8469
  const skipApplySolvedTypeVars = (0, types_1.isFunction)(argParam.paramType) &&
8441
- !!argParam.paramType.details.paramSpec &&
8470
+ types_1.FunctionType.getParamSpecFromArgsKwargs(argParam.paramType) &&
8442
8471
  typeVarContext.getSignatureContexts().length > 1;
8443
8472
  if (!skipApplySolvedTypeVars) {
8444
8473
  expectedType = (0, typeUtils_1.applySolvedTypeVars)(expectedType, typeVarContext, {
@@ -8957,7 +8986,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8957
8986
  const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
8958
8987
  if (node.nodeType === 21 /* ParseNodeType.Ellipsis */) {
8959
8988
  types_1.FunctionType.addDefaultParameters(functionType);
8960
- functionType.details.flags |= 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
8989
+ functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
8961
8990
  return functionType;
8962
8991
  }
8963
8992
  if (node.nodeType === 34 /* ParseNodeType.List */) {
@@ -8991,7 +9020,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8991
9020
  return undefined;
8992
9021
  }
8993
9022
  if ((0, types_1.isParamSpec)(typeResult.type)) {
8994
- functionType.details.paramSpec = typeResult.type;
9023
+ types_1.FunctionType.addParamSpecVariadics(functionType, typeResult.type);
8995
9024
  return functionType;
8996
9025
  }
8997
9026
  if ((0, types_1.isClassInstance)(typeResult.type) &&
@@ -9166,7 +9195,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9166
9195
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeLiteral(), argList[1].node || errorNode);
9167
9196
  }
9168
9197
  let classFlags = baseClass.details.flags & ~(1 /* ClassTypeFlags.BuiltInClass */ | 2 /* ClassTypeFlags.SpecialBuiltIn */);
9169
- classFlags |= 8192 /* ClassTypeFlags.Final */ | 536870912 /* ClassTypeFlags.NewTypeClass */ | 1073741824 /* ClassTypeFlags.ValidTypeAliasClass */;
9198
+ classFlags |= 256 /* ClassTypeFlags.Final */ | 2097152 /* ClassTypeFlags.NewTypeClass */ | 4194304 /* ClassTypeFlags.ValidTypeAliasClass */;
9170
9199
  const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, classFlags, ParseTreeUtils.getTypeSourceId(errorNode),
9171
9200
  /* declaredMetaclass */ undefined, baseClass.details.effectiveMetaclass);
9172
9201
  classType.details.baseClasses.push(isBaseClassAny ? types_1.AnyType.create() : baseClass);
@@ -9198,7 +9227,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9198
9227
  });
9199
9228
  types_1.FunctionType.addDefaultParameters(newType);
9200
9229
  newType.details.declaredReturnType = types_1.ClassType.cloneAsInstance(classType);
9201
- newType.details.constructorTypeVarScopeId = classType.details.typeVarScopeId;
9230
+ newType.details.constructorTypeVarScopeId = (0, typeUtils_1.getTypeVarScopeId)(classType);
9202
9231
  types_1.ClassType.getSymbolTable(classType).set('__new__', symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, newType));
9203
9232
  }
9204
9233
  return classType;
@@ -9220,7 +9249,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9220
9249
  if (!(0, types_1.isClassInstance)(arg1Type) || !(0, typeUtils_1.isTupleClass)(arg1Type) || arg1Type.tupleTypeArguments === undefined) {
9221
9250
  return undefined;
9222
9251
  }
9223
- const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 1073741824 /* ClassTypeFlags.ValidTypeAliasClass */, ParseTreeUtils.getTypeSourceId(errorNode), metaclass, arg1Type.details.effectiveMetaclass);
9252
+ const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 4194304 /* ClassTypeFlags.ValidTypeAliasClass */, ParseTreeUtils.getTypeSourceId(errorNode), metaclass, arg1Type.details.effectiveMetaclass);
9224
9253
  arg1Type.tupleTypeArguments.forEach((typeArg) => {
9225
9254
  const specializedType = makeTopLevelTypeVarsConcrete(typeArg.type);
9226
9255
  if ((0, typeUtils_1.isEffectivelyInstantiable)(specializedType)) {
@@ -9944,7 +9973,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9944
9973
  if (enclosingFunction) {
9945
9974
  const functionTypeInfo = getTypeOfFunction(enclosingFunction);
9946
9975
  if (functionTypeInfo) {
9947
- const returnType = types_1.FunctionType.getSpecializedReturnType(functionTypeInfo.functionType);
9976
+ const returnType = types_1.FunctionType.getEffectiveReturnType(functionTypeInfo.functionType);
9948
9977
  if (returnType) {
9949
9978
  expectedYieldType = (0, typeUtils_1.getGeneratorYieldType)(returnType, !!enclosingFunction.isAsync);
9950
9979
  const generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(returnType);
@@ -10033,128 +10062,134 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10033
10062
  }
10034
10063
  let functionType = types_1.FunctionType.createInstance('', '', '', 131072 /* FunctionTypeFlags.PartiallyEvaluated */);
10035
10064
  functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(node);
10036
- // Pre-cache the incomplete function type in case the evaluation of the
10037
- // lambda depends on itself.
10038
- writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /* EvaluatorFlags.None */);
10039
- // We assume for simplicity that the parameter signature of the lambda is
10040
- // the same as the expected type. If this isn't the case, we'll use
10041
- // object for any lambda parameters that don't match. We could make this
10042
- // more sophisticated in the future, but it becomes very complex to handle
10043
- // all of the permutations.
10044
- let sawParamMismatch = false;
10045
- node.parameters.forEach((param, index) => {
10046
- let paramType;
10047
- if (expectedParamDetails && !sawParamMismatch) {
10048
- if (index < expectedParamDetails.params.length) {
10049
- const expectedParam = expectedParamDetails.params[index];
10050
- // If the parameter category matches and both of the parameters are
10051
- // either separators (/ or *) or not separators, copy the type
10052
- // from the expected parameter.
10053
- if (expectedParam.param.category === param.category && !param.name === !expectedParam.param.name) {
10054
- paramType = expectedParam.type;
10065
+ return (0, cancellationUtils_1.invalidateTypeCacheIfCanceled)(() => {
10066
+ // Pre-cache the incomplete function type in case the evaluation of the
10067
+ // lambda depends on itself.
10068
+ writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /* EvaluatorFlags.None */);
10069
+ // We assume for simplicity that the parameter signature of the lambda is
10070
+ // the same as the expected type. If this isn't the case, we'll use
10071
+ // object for any lambda parameters that don't match. We could make this
10072
+ // more sophisticated in the future, but it becomes very complex to handle
10073
+ // all of the permutations.
10074
+ let sawParamMismatch = false;
10075
+ node.parameters.forEach((param, index) => {
10076
+ let paramType;
10077
+ if (expectedParamDetails && !sawParamMismatch) {
10078
+ if (index < expectedParamDetails.params.length) {
10079
+ const expectedParam = expectedParamDetails.params[index];
10080
+ // If the parameter category matches and both of the parameters are
10081
+ // either separators (/ or *) or not separators, copy the type
10082
+ // from the expected parameter.
10083
+ if (expectedParam.param.category === param.category &&
10084
+ !param.name === !expectedParam.param.name) {
10085
+ paramType = expectedParam.type;
10086
+ }
10087
+ else {
10088
+ sawParamMismatch = true;
10089
+ }
10055
10090
  }
10056
- else {
10057
- sawParamMismatch = true;
10091
+ else if (param.defaultValue) {
10092
+ // If the lambda param has a default value but there is no associated
10093
+ // parameter in the expected type, assume that the default value is
10094
+ // being used to explicitly capture a value from an outer scope. Infer
10095
+ // its type from the default value expression.
10096
+ paramType = getTypeOfExpression(param.defaultValue, undefined, inferenceContext).type;
10058
10097
  }
10059
10098
  }
10060
10099
  else if (param.defaultValue) {
10061
- // If the lambda param has a default value but there is no associated
10062
- // parameter in the expected type, assume that the default value is
10063
- // being used to explicitly capture a value from an outer scope. Infer
10064
- // its type from the default value expression.
10065
- paramType = getTypeOfExpression(param.defaultValue, undefined, inferenceContext).type;
10066
- }
10067
- }
10068
- else if (param.defaultValue) {
10069
- // If there is no inference context but we have a default value,
10070
- // use the default value to infer the parameter's type.
10071
- paramType = inferParameterTypeFromDefaultValue(param.defaultValue);
10072
- }
10073
- if (param.name) {
10074
- writeTypeCache(param.name, { type: transformVariadicParamType(node, param.category, paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create()) }, 0 /* EvaluatorFlags.None */);
10075
- }
10076
- if (param.defaultValue) {
10077
- // Evaluate the default value if it's present.
10078
- getTypeOfExpression(param.defaultValue, 1 /* EvaluatorFlags.ConvertEllipsisToAny */);
10079
- }
10080
- // Determine whether we need to insert an implied position-only parameter.
10081
- // This is needed when a function's parameters are named using the old-style
10082
- // way of specifying position-only parameters.
10083
- if (index >= 0) {
10084
- let isImplicitPositionOnlyParam = false;
10085
- if (param.category === 0 /* ParameterCategory.Simple */ && param.name) {
10086
- if ((0, symbolNameUtils_1.isPrivateName)(param.name.value)) {
10087
- isImplicitPositionOnlyParam = true;
10100
+ // If there is no inference context but we have a default value,
10101
+ // use the default value to infer the parameter's type.
10102
+ paramType = inferParameterTypeFromDefaultValue(param.defaultValue);
10103
+ }
10104
+ if (param.name) {
10105
+ writeTypeCache(param.name, { type: transformVariadicParamType(node, param.category, paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create()) }, 0 /* EvaluatorFlags.None */);
10106
+ }
10107
+ if (param.defaultValue) {
10108
+ // Evaluate the default value if it's present.
10109
+ getTypeOfExpression(param.defaultValue, 1 /* EvaluatorFlags.ConvertEllipsisToAny */);
10110
+ }
10111
+ // Determine whether we need to insert an implied position-only parameter.
10112
+ // This is needed when a function's parameters are named using the old-style
10113
+ // way of specifying position-only parameters.
10114
+ if (index >= 0) {
10115
+ let isImplicitPositionOnlyParam = false;
10116
+ if (param.category === 0 /* ParameterCategory.Simple */ && param.name) {
10117
+ if ((0, symbolNameUtils_1.isPrivateName)(param.name.value)) {
10118
+ isImplicitPositionOnlyParam = true;
10119
+ }
10120
+ }
10121
+ else {
10122
+ paramsArePositionOnly = false;
10123
+ }
10124
+ if (paramsArePositionOnly &&
10125
+ !isImplicitPositionOnlyParam &&
10126
+ functionType.details.parameters.length > 0) {
10127
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
10128
+ }
10129
+ if (!isImplicitPositionOnlyParam) {
10130
+ paramsArePositionOnly = false;
10088
10131
  }
10089
10132
  }
10090
- else {
10091
- paramsArePositionOnly = false;
10092
- }
10093
- if (paramsArePositionOnly &&
10094
- !isImplicitPositionOnlyParam &&
10095
- functionType.details.parameters.length > 0) {
10096
- types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
10133
+ const functionParam = {
10134
+ category: param.category,
10135
+ name: param.name ? param.name.value : undefined,
10136
+ hasDefault: !!param.defaultValue,
10137
+ defaultValueExpression: param.defaultValue,
10138
+ hasDeclaredType: true,
10139
+ type: paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create(),
10140
+ };
10141
+ types_1.FunctionType.addParameter(functionType, functionParam);
10142
+ });
10143
+ if (paramsArePositionOnly && functionType.details.parameters.length > 0) {
10144
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
10145
+ }
10146
+ let typeErrors = false;
10147
+ // If we're speculatively evaluating the lambda, create another speculative
10148
+ // evaluation scope for the return expression and do not allow retention
10149
+ // of the cached types.
10150
+ // We need to set allowCacheRetention to false because we don't want to
10151
+ // cache the type of the lambda return expression because it depends on
10152
+ // the parameter types that we set above, and the speculative type cache
10153
+ // doesn't know about that context.
10154
+ useSpeculativeMode(forceSpeculative || isSpeculativeModeInUse(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete)
10155
+ ? node.expression
10156
+ : undefined, () => {
10157
+ const returnTypeResult = getTypeOfExpression(node.expression,
10158
+ /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
10159
+ functionType.inferredReturnType = returnTypeResult.type;
10160
+ if (returnTypeResult.isIncomplete) {
10161
+ isIncomplete = true;
10097
10162
  }
10098
- if (!isImplicitPositionOnlyParam) {
10099
- paramsArePositionOnly = false;
10163
+ if (returnTypeResult.typeErrors) {
10164
+ typeErrors = true;
10100
10165
  }
10101
- }
10102
- const functionParam = {
10103
- category: param.category,
10104
- name: param.name ? param.name.value : undefined,
10105
- hasDefault: !!param.defaultValue,
10106
- defaultValueExpression: param.defaultValue,
10107
- hasDeclaredType: true,
10108
- type: paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create(),
10109
- };
10110
- types_1.FunctionType.addParameter(functionType, functionParam);
10111
- });
10112
- if (paramsArePositionOnly && functionType.details.parameters.length > 0) {
10113
- types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
10114
- }
10115
- let typeErrors = false;
10116
- // If we're speculatively evaluating the lambda, create another speculative
10117
- // evaluation scope for the return expression and do not allow retention
10118
- // of the cached types.
10119
- // We need to set allowCacheRetention to false because we don't want to
10120
- // cache the type of the lambda return expression because it depends on
10121
- // the parameter types that we set above, and the speculative type cache
10122
- // doesn't know about that context.
10123
- useSpeculativeMode(forceSpeculative || isSpeculativeModeInUse(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete)
10124
- ? node.expression
10125
- : undefined, () => {
10126
- const returnTypeResult = getTypeOfExpression(node.expression,
10127
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
10128
- functionType.inferredReturnType = returnTypeResult.type;
10129
- if (returnTypeResult.isIncomplete) {
10130
- isIncomplete = true;
10131
- }
10132
- if (returnTypeResult.typeErrors) {
10133
- typeErrors = true;
10134
- }
10135
- else if (expectedReturnType) {
10136
- // If the expectedReturnType is generic, see if the actual return type
10137
- // provides types for some or all type variables.
10138
- if ((0, typeUtils_1.requiresSpecialization)(expectedReturnType)) {
10139
- const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(functionType));
10140
- if (assignType(expectedReturnType, returnTypeResult.type, /* diag */ undefined, typeVarContext)) {
10141
- functionType = (0, typeUtils_1.applySolvedTypeVars)(functionType, typeVarContext, {
10142
- applyInScopePlaceholders: true,
10143
- });
10166
+ else if (expectedReturnType) {
10167
+ // If the expectedReturnType is generic, see if the actual return type
10168
+ // provides types for some or all type variables.
10169
+ if ((0, typeUtils_1.requiresSpecialization)(expectedReturnType)) {
10170
+ const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(functionType));
10171
+ if (assignType(expectedReturnType, returnTypeResult.type,
10172
+ /* diag */ undefined, typeVarContext)) {
10173
+ functionType = (0, typeUtils_1.applySolvedTypeVars)(functionType, typeVarContext, {
10174
+ applyInScopePlaceholders: true,
10175
+ });
10176
+ }
10144
10177
  }
10145
10178
  }
10179
+ }, {
10180
+ dependentType: inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType,
10181
+ allowDiagnostics: !forceSpeculative &&
10182
+ !isDiagnosticSuppressedForNode(node) &&
10183
+ !(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete),
10184
+ });
10185
+ // Mark the function type as no longer being evaluated.
10186
+ functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
10187
+ // Is the resulting function compatible with the expected type?
10188
+ if (expectedType && !assignType(expectedType, functionType)) {
10189
+ typeErrors = true;
10146
10190
  }
10147
- }, {
10148
- dependentType: inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType,
10149
- allowDiagnostics: !forceSpeculative && !isDiagnosticSuppressedForNode(node) && !(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete),
10191
+ return { type: functionType, isIncomplete, typeErrors };
10150
10192
  });
10151
- // Mark the function type as no longer being evaluated.
10152
- functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
10153
- // Is the resulting function compatible with the expected type?
10154
- if (expectedType && !assignType(expectedType, functionType)) {
10155
- typeErrors = true;
10156
- }
10157
- return { type: functionType, isIncomplete, typeErrors };
10158
10193
  }
10159
10194
  function getTypeOfComprehension(node, flags, inferenceContext) {
10160
10195
  let isIncomplete = false;
@@ -10229,16 +10264,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10229
10264
  const iterableType = stripLiteralValue(iterableTypeResult.type);
10230
10265
  const itemTypeResult = (_a = getTypeOfIterator({ type: iterableType, isIncomplete: iterableTypeResult.isIncomplete }, !!node.isAsync, node.iterableExpression)) !== null && _a !== void 0 ? _a : { type: types_1.UnknownType.create(), isIncomplete: iterableTypeResult.isIncomplete };
10231
10266
  const targetExpr = node.targetExpression;
10232
- assignTypeToExpression(targetExpr, itemTypeResult.type, !!itemTypeResult.isIncomplete, node.iterableExpression);
10267
+ assignTypeToExpression(targetExpr, itemTypeResult, node.iterableExpression);
10233
10268
  }
10234
10269
  else {
10235
10270
  (0, debug_1.assert)(node.nodeType === 13 /* ParseNodeType.ComprehensionIf */);
10236
10271
  // Evaluate the test expression to validate it and mark symbols
10237
- // as referenced. Don't bother doing this if we're in speculative
10238
- // mode because it doesn't affect the element type.
10239
- if (!isSpeculativeModeInUse(node.testExpression)) {
10240
- getTypeOfExpression(node.testExpression);
10241
- }
10272
+ // as referenced. This doesn't affect the type of the evaluated
10273
+ // comprehension, but it is important for evaluating intermediate
10274
+ // expressions such as assignment expressions that can affect other
10275
+ // subexpressions.
10276
+ getTypeOfExpression(node.testExpression);
10242
10277
  }
10243
10278
  return isIncomplete;
10244
10279
  }
@@ -10370,6 +10405,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10370
10405
  // The second argument, if present, should specify the return type.
10371
10406
  function createCallableType(classType, typeArgs, errorNode) {
10372
10407
  const functionType = types_1.FunctionType.createInstantiable(0 /* FunctionTypeFlags.None */);
10408
+ let paramSpec;
10373
10409
  functionType.specialForm = classType;
10374
10410
  functionType.details.declaredReturnType = types_1.UnknownType.create();
10375
10411
  functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(errorNode);
@@ -10424,10 +10460,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10424
10460
  }
10425
10461
  else if ((0, typeUtils_1.isEllipsisType)(typeArgs[0].type)) {
10426
10462
  types_1.FunctionType.addDefaultParameters(functionType);
10427
- functionType.details.flags |= 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
10463
+ functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
10428
10464
  }
10429
10465
  else if ((0, types_1.isParamSpec)(typeArgs[0].type)) {
10430
- functionType.details.paramSpec = typeArgs[0].type;
10466
+ paramSpec = typeArgs[0].type;
10431
10467
  }
10432
10468
  else {
10433
10469
  if ((0, types_1.isInstantiableClass)(typeArgs[0].type) && types_1.ClassType.isBuiltIn(typeArgs[0].type, 'Concatenate')) {
@@ -10437,11 +10473,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10437
10473
  if (index === concatTypeArgs.length - 1) {
10438
10474
  types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
10439
10475
  if ((0, types_1.isParamSpec)(typeArg)) {
10440
- functionType.details.paramSpec = typeArg;
10476
+ paramSpec = typeArg;
10441
10477
  }
10442
10478
  else if ((0, typeUtils_1.isEllipsisType)(typeArg)) {
10443
10479
  types_1.FunctionType.addDefaultParameters(functionType);
10444
- functionType.details.flags |= 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
10480
+ functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
10445
10481
  }
10446
10482
  }
10447
10483
  else {
@@ -10477,7 +10513,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10477
10513
  }
10478
10514
  else {
10479
10515
  types_1.FunctionType.addDefaultParameters(functionType, /* useUnknown */ true);
10480
- functionType.details.flags |= 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
10516
+ functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
10517
+ }
10518
+ if (paramSpec) {
10519
+ types_1.FunctionType.addParamSpecVariadics(functionType, paramSpec);
10481
10520
  }
10482
10521
  return functionType;
10483
10522
  }
@@ -10866,8 +10905,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10866
10905
  return createSpecialType(classType, typeArgs, /* paramLimit */ undefined, /* allowParamSpec */ true);
10867
10906
  }
10868
10907
  function createAnnotatedType(classType, errorNode, typeArgs) {
10869
- if (typeArgs && typeArgs.length < 2) {
10870
- addError(localize_1.LocMessage.annotatedTypeArgMissing(), errorNode);
10908
+ if (typeArgs) {
10909
+ if (typeArgs.length < 2) {
10910
+ addError(localize_1.LocMessage.annotatedTypeArgMissing(), errorNode);
10911
+ }
10912
+ else {
10913
+ validateAnnotatedMetadata(errorNode, typeArgs[0].type, typeArgs.slice(1));
10914
+ }
10871
10915
  }
10872
10916
  if (!typeArgs || typeArgs.length === 0) {
10873
10917
  return { type: types_1.AnyType.create() };
@@ -10882,6 +10926,46 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10882
10926
  isNotRequired: typeArgs[0].isNotRequired,
10883
10927
  };
10884
10928
  }
10929
+ // Enforces metadata consistency as specified in PEP 746.
10930
+ function validateAnnotatedMetadata(errorNode, annotatedType, metaArgs) {
10931
+ var _a;
10932
+ // This is an experimental feature because PEP 746 hasn't been accepted.
10933
+ if (!AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.enableExperimentalFeatures) {
10934
+ return;
10935
+ }
10936
+ for (const metaArg of metaArgs) {
10937
+ if ((0, types_1.isClass)(metaArg.type)) {
10938
+ const supportsTypeMethod = (_a = getTypeOfBoundMember(
10939
+ /* errorNode */ undefined, metaArg.type, '__supports_type__')) === null || _a === void 0 ? void 0 : _a.type;
10940
+ if (!supportsTypeMethod) {
10941
+ continue;
10942
+ }
10943
+ // "Call" the __supports_type__ method to determine if the type is supported.
10944
+ const callResult = useSpeculativeMode(errorNode, () => validateCallArguments(errorNode, [
10945
+ {
10946
+ argumentCategory: 0 /* ArgumentCategory.Simple */,
10947
+ typeResult: { type: (0, typeUtils_1.convertToInstance)(annotatedType) },
10948
+ },
10949
+ ], { type: supportsTypeMethod },
10950
+ /* typeVarContext */ undefined,
10951
+ /* skipUnknownArgCheck */ true,
10952
+ /* inferenceContext */ undefined,
10953
+ /* signatureTracker */ undefined));
10954
+ if (callResult.isTypeIncomplete || !callResult.returnType) {
10955
+ continue;
10956
+ }
10957
+ // If there are no errors and the return type is potentially truthy,
10958
+ // we know that the type is supported by this metadata object.
10959
+ if (!callResult.argumentErrors && canBeTruthy(callResult.returnType)) {
10960
+ continue;
10961
+ }
10962
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.annotatedMetadataInconsistent().format({
10963
+ metadataType: printType(metaArg.type),
10964
+ type: printType((0, typeUtils_1.convertToInstance)(annotatedType)),
10965
+ }), metaArg.node);
10966
+ }
10967
+ }
10968
+ }
10885
10969
  // Creates one of several "special" types that are defined in typing.pyi
10886
10970
  // but not declared in their entirety. This includes the likes of "Tuple",
10887
10971
  // "Dict", etc.
@@ -11113,10 +11197,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11113
11197
  // Determine if there are any generic type parameters associated
11114
11198
  // with this type alias.
11115
11199
  typeParameters = [];
11116
- (0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
11117
- (0, debug_1.assert)(typeParameters !== undefined);
11118
- (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParameters, (0, typeUtils_1.getTypeVarArgumentsRecursive)(subtype));
11119
- });
11200
+ (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParameters, (0, typeUtils_1.getTypeVarArgumentsRecursive)(type));
11120
11201
  // Don't include any synthesized type variables.
11121
11202
  typeParameters = typeParameters.filter((typeVar) => !typeVar.details.isSynthesized);
11122
11203
  }
@@ -11185,7 +11266,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11185
11266
  /* declaredMetaclass */ undefined,
11186
11267
  /* effectiveMetaclass */ undefined);
11187
11268
  if (aliasMapEntry.isSpecialForm) {
11188
- specialClassType.details.flags |= -2147483648 /* ClassTypeFlags.SpecialFormClass */;
11269
+ specialClassType.details.flags |= 8388608 /* ClassTypeFlags.SpecialFormClass */;
11189
11270
  }
11190
11271
  // Synthesize a single type parameter with the specified variance if
11191
11272
  // specified in the alias map entry.
@@ -11198,7 +11279,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11198
11279
  const specialBuiltInClassDeclaration = ((_a = AnalyzerNodeInfo.getDeclaration(node)) !== null && _a !== void 0 ? _a : (node.parent ? AnalyzerNodeInfo.getDeclaration(node.parent) : undefined));
11199
11280
  specialClassType.details.declaration = specialBuiltInClassDeclaration;
11200
11281
  if (fileInfo.isTypingExtensionsStubFile) {
11201
- specialClassType.details.flags |= 131072 /* ClassTypeFlags.TypingExtensionClass */;
11282
+ specialClassType.details.flags |= 4096 /* ClassTypeFlags.TypingExtensionClass */;
11202
11283
  }
11203
11284
  const baseClassName = aliasMapEntry.alias || 'object';
11204
11285
  let baseClass;
@@ -11218,7 +11299,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11218
11299
  // cause the TypedDict to be marked as abstract.
11219
11300
  if ((0, types_1.isInstantiableClass)(baseClass) && types_1.ClassType.isBuiltIn(baseClass, '_TypedDict')) {
11220
11301
  baseClass = types_1.ClassType.cloneWithNewFlags(baseClass, baseClass.details.flags &
11221
- ~(2048 /* ClassTypeFlags.SupportsAbstractMethods */ | 268435456 /* ClassTypeFlags.TypeCheckOnly */));
11302
+ ~(64 /* ClassTypeFlags.SupportsAbstractMethods */ | 1048576 /* ClassTypeFlags.TypeCheckOnly */));
11222
11303
  }
11223
11304
  }
11224
11305
  }
@@ -11461,7 +11542,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11461
11542
  }
11462
11543
  }
11463
11544
  }
11464
- assignTypeToExpression(node.leftExpression, rightHandType, isIncomplete, node.rightExpression,
11545
+ assignTypeToExpression(node.leftExpression, { type: rightHandType, isIncomplete }, node.rightExpression,
11465
11546
  /* ignoreEmptyContainers */ true,
11466
11547
  /* allowAssignmentToFinalVar */ true, expectedTypeDiagAddendum);
11467
11548
  writeTypeCache(node, { type: rightHandType, isIncomplete }, 0 /* EvaluatorFlags.None */);
@@ -11593,17 +11674,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11593
11674
  fileInfo.isTypeshedStubFile) {
11594
11675
  classFlags |= 1 /* ClassTypeFlags.BuiltInClass */;
11595
11676
  if (fileInfo.isTypingExtensionsStubFile) {
11596
- classFlags |= 131072 /* ClassTypeFlags.TypingExtensionClass */;
11677
+ classFlags |= 4096 /* ClassTypeFlags.TypingExtensionClass */;
11597
11678
  }
11598
11679
  if (node.name.value === 'property') {
11599
- classFlags |= 4096 /* ClassTypeFlags.PropertyClass */;
11680
+ classFlags |= 128 /* ClassTypeFlags.PropertyClass */;
11600
11681
  }
11601
11682
  if (node.name.value === 'tuple') {
11602
- classFlags |= 1048576 /* ClassTypeFlags.TupleClass */;
11683
+ classFlags |= 32768 /* ClassTypeFlags.TupleClass */;
11603
11684
  }
11604
11685
  }
11605
11686
  if (fileInfo.isStubFile) {
11606
- classFlags |= 16777216 /* ClassTypeFlags.DefinedInStub */;
11687
+ classFlags |= 262144 /* ClassTypeFlags.DefinedInStub */;
11607
11688
  }
11608
11689
  const classType = types_1.ClassType.createInstantiable(node.name.value, ParseTreeUtils.getClassFullName(node, fileInfo.moduleName, node.name.value), fileInfo.moduleName, fileInfo.fileUri, classFlags,
11609
11690
  /* typeSourceId */ 0,
@@ -11626,9 +11707,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11626
11707
  if (classDecl && classSymbol) {
11627
11708
  setSymbolResolutionPartialType(classSymbol, classDecl, classType);
11628
11709
  }
11629
- classType.details.flags |= 262144 /* ClassTypeFlags.PartiallyEvaluated */;
11710
+ classType.details.flags |= 8192 /* ClassTypeFlags.PartiallyEvaluated */;
11630
11711
  classType.details.declaration = classDecl;
11631
- try {
11712
+ return (0, cancellationUtils_1.invalidateTypeCacheIfCanceled)(() => {
11632
11713
  writeTypeCache(node, { type: classType }, /* flags */ undefined);
11633
11714
  writeTypeCache(node.name, { type: classType }, /* flags */ undefined);
11634
11715
  // Keep a list of unique type parameters that are used in the
@@ -11712,29 +11793,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11712
11793
  fileInfo.executionEnvironment.pythonVersion.isLessThan(pythonVersion_1.pythonVersion3_7)) {
11713
11794
  addError(localize_1.LocMessage.protocolIllegal(), arg.valueExpression);
11714
11795
  }
11715
- classType.details.flags |= 16384 /* ClassTypeFlags.ProtocolClass */;
11796
+ classType.details.flags |= 512 /* ClassTypeFlags.ProtocolClass */;
11716
11797
  }
11717
11798
  if (types_1.ClassType.isBuiltIn(argType, 'property')) {
11718
- classType.details.flags |= 4096 /* ClassTypeFlags.PropertyClass */;
11799
+ classType.details.flags |= 128 /* ClassTypeFlags.PropertyClass */;
11719
11800
  }
11720
11801
  // If the class directly derives from NamedTuple (in Python 3.6 or
11721
11802
  // newer), it's considered a (read-only) dataclass.
11722
11803
  if (fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(pythonVersion_1.pythonVersion3_6)) {
11723
11804
  if (types_1.ClassType.isBuiltIn(argType, 'NamedTuple')) {
11724
11805
  isNamedTupleSubclass = true;
11725
- classType.details.flags |=
11726
- 4 /* ClassTypeFlags.DataClass */ |
11727
- 32 /* ClassTypeFlags.SkipSynthesizedDataClassEq */ |
11728
- 33554432 /* ClassTypeFlags.ReadOnlyInstanceVariables */;
11806
+ classType.details.flags |= 524288 /* ClassTypeFlags.ReadOnlyInstanceVariables */;
11729
11807
  }
11730
11808
  }
11731
11809
  // If the class directly derives from TypedDict or from a class that is
11732
11810
  // a TypedDict, it is considered a TypedDict.
11733
11811
  if (types_1.ClassType.isBuiltIn(argType, 'TypedDict') || types_1.ClassType.isTypedDictClass(argType)) {
11734
- classType.details.flags |= 128 /* ClassTypeFlags.TypedDictClass */;
11812
+ classType.details.flags |= 4 /* ClassTypeFlags.TypedDictClass */;
11735
11813
  // Propagate the "effectively closed" flag from base classes.
11736
11814
  if (types_1.ClassType.isTypedDictEffectivelyClosed(argType)) {
11737
- classType.details.flags |= 512 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
11815
+ classType.details.flags |= 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
11738
11816
  }
11739
11817
  }
11740
11818
  // Validate that the class isn't deriving from itself, creating a
@@ -11765,7 +11843,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11765
11843
  classType.details.baseClasses.push(argType);
11766
11844
  if ((0, types_1.isInstantiableClass)(argType)) {
11767
11845
  if (types_1.ClassType.isEnumClass(argType)) {
11768
- classType.details.flags |= 2097152 /* ClassTypeFlags.EnumClass */;
11846
+ classType.details.flags |= 65536 /* ClassTypeFlags.EnumClass */;
11769
11847
  }
11770
11848
  // Determine if the class is abstract. Protocol classes support abstract methods
11771
11849
  // because they are constructed by the _ProtocolMeta metaclass, which derives
@@ -11774,10 +11852,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11774
11852
  // because of dependencies on some of these built-in protocol classes.
11775
11853
  if (types_1.ClassType.supportsAbstractMethods(argType) ||
11776
11854
  (types_1.ClassType.isProtocolClass(argType) && !types_1.ClassType.isBuiltIn(argType))) {
11777
- classType.details.flags |= 2048 /* ClassTypeFlags.SupportsAbstractMethods */;
11855
+ classType.details.flags |= 64 /* ClassTypeFlags.SupportsAbstractMethods */;
11778
11856
  }
11779
11857
  if (types_1.ClassType.isPropertyClass(argType)) {
11780
- classType.details.flags |= 4096 /* ClassTypeFlags.PropertyClass */;
11858
+ classType.details.flags |= 128 /* ClassTypeFlags.PropertyClass */;
11781
11859
  }
11782
11860
  if (types_1.ClassType.isFinal(argType)) {
11783
11861
  const className = printObjectTypeForClass(argType);
@@ -11827,13 +11905,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11827
11905
  addError(localize_1.LocMessage.typedDictBoolParam().format({ name: arg.name.value }), arg.valueExpression);
11828
11906
  }
11829
11907
  else if (arg.name.value === 'total' && !constArgValue) {
11830
- classType.details.flags |= 1024 /* ClassTypeFlags.CanOmitDictValues */;
11908
+ classType.details.flags |= 32 /* ClassTypeFlags.CanOmitDictValues */;
11831
11909
  }
11832
11910
  else if (arg.name.value === 'closed' && constArgValue) {
11833
11911
  // This is an experimental feature because PEP 728 hasn't been accepted yet.
11834
11912
  if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
11835
11913
  classType.details.flags |=
11836
- 256 /* ClassTypeFlags.TypedDictMarkedClosed */ | 512 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
11914
+ 8 /* ClassTypeFlags.TypedDictMarkedClosed */ | 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
11837
11915
  }
11838
11916
  }
11839
11917
  }
@@ -11966,7 +12044,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11966
12044
  param.category === 0 /* ParameterCategory.Simple */ &&
11967
12045
  !param.defaultValue);
11968
12046
  if (genericParams.length > 0) {
11969
- classType.details.flags |= 32768 /* ClassTypeFlags.PseudoGenericClass */;
12047
+ classType.details.flags |= 1024 /* ClassTypeFlags.PseudoGenericClass */;
11970
12048
  // Create a type parameter for each simple, named parameter
11971
12049
  // in the __init__ method.
11972
12050
  classType.details.typeParameters = genericParams.map((param) => {
@@ -11987,7 +12065,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11987
12065
  if (classType.details.typeParameters.length === 0 && !types_1.ClassType.isBuiltIn(classType, 'type')) {
11988
12066
  if (classType.details.baseClasses.some((baseClass) => (0, types_1.isInstantiableClass)(baseClass) && types_1.ClassType.hasCustomClassGetItem(baseClass)) ||
11989
12067
  classType.details.fields.has('__class_getitem__')) {
11990
- classType.details.flags |= 524288 /* ClassTypeFlags.HasCustomClassGetItem */;
12068
+ classType.details.flags |= 16384 /* ClassTypeFlags.HasCustomClassGetItem */;
11991
12069
  }
11992
12070
  }
11993
12071
  // Determine the effective metaclass.
@@ -12000,17 +12078,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12000
12078
  classType.details.declaredMetaclass = metaclassType;
12001
12079
  if ((0, types_1.isInstantiableClass)(metaclassType)) {
12002
12080
  if ((0, enums_1.isEnumMetaclass)(metaclassType)) {
12003
- classType.details.flags |= 2097152 /* ClassTypeFlags.EnumClass */;
12081
+ classType.details.flags |= 65536 /* ClassTypeFlags.EnumClass */;
12004
12082
  }
12005
12083
  if (types_1.ClassType.isBuiltIn(metaclassType, 'ABCMeta')) {
12006
- classType.details.flags |= 2048 /* ClassTypeFlags.SupportsAbstractMethods */;
12084
+ classType.details.flags |= 64 /* ClassTypeFlags.SupportsAbstractMethods */;
12007
12085
  }
12008
12086
  }
12009
12087
  }
12010
12088
  }
12011
12089
  const effectiveMetaclass = computeEffectiveMetaclass(classType, node.name);
12012
12090
  // Clear the "partially constructed" flag.
12013
- classType.details.flags &= ~262144 /* ClassTypeFlags.PartiallyEvaluated */;
12091
+ classType.details.flags &= ~8192 /* ClassTypeFlags.PartiallyEvaluated */;
12014
12092
  // Now determine the decorated type of the class.
12015
12093
  let decoratedType = classType;
12016
12094
  let foundUnknown = false;
@@ -12047,7 +12125,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12047
12125
  }
12048
12126
  }
12049
12127
  if (dataClassBehaviors) {
12050
- (0, dataClasses_1.applyDataClassDefaultBehaviors)(classType, dataClassBehaviors);
12051
12128
  (0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, node.name, classType, initSubclassArgs, dataClassBehaviors);
12052
12129
  }
12053
12130
  // Run any deferred class completions that depend on this class.
@@ -12075,8 +12152,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12075
12152
  (0, typedDicts_1.synthesizeTypedDictClassMethods)(evaluatorInterface, node, classType);
12076
12153
  }
12077
12154
  // Synthesize dataclass methods.
12078
- if (types_1.ClassType.isDataClass(classType)) {
12079
- const skipSynthesizedInit = types_1.ClassType.isSkipSynthesizedDataClassInit(classType);
12155
+ if (types_1.ClassType.isDataClass(classType) || isNamedTupleSubclass) {
12156
+ const skipSynthesizedInit = types_1.ClassType.isDataClassSkipGenerateInit(classType);
12080
12157
  let hasExistingInitMethod = skipSynthesizedInit;
12081
12158
  // See if there's already a non-synthesized __init__ method.
12082
12159
  // We shouldn't override it.
@@ -12142,15 +12219,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12142
12219
  // Update the decorated class type.
12143
12220
  writeTypeCache(node, { type: decoratedType }, 0 /* EvaluatorFlags.None */);
12144
12221
  return { classType, decoratedType };
12145
- }
12146
- catch (e) {
12147
- if (cancellationUtils_1.OperationCanceledException.is(e)) {
12148
- // If the work was canceled before the class types were updated, the
12149
- // class type in the type cache is in an invalid, partially-constructed state.
12150
- e.isTypeCacheInvalid = true;
12151
- }
12152
- throw e;
12153
- }
12222
+ });
12154
12223
  }
12155
12224
  // Determines whether the type parameters has a default that refers to another
12156
12225
  // type parameter. If so, validates that it is in the list of "live" type
@@ -12566,7 +12635,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12566
12635
  // Evaluates the type of a "def" statement without applying an async
12567
12636
  // modifier or any decorators.
12568
12637
  function getTypeOfFunctionPredecorated(node) {
12569
- var _a, _b, _c;
12638
+ var _a;
12570
12639
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
12571
12640
  // Is this type already cached?
12572
12641
  const cachedFunctionType = readTypeCache(node.name, 0 /* EvaluatorFlags.None */);
@@ -12621,299 +12690,303 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12621
12690
  if (functionDecl && functionSymbol) {
12622
12691
  setSymbolResolutionPartialType(functionSymbol.symbol, functionDecl, functionType);
12623
12692
  }
12624
- writeTypeCache(node.name, { type: functionType }, /* flags */ undefined);
12625
- // Is this an "__init__" method within a pseudo-generic class? If so,
12626
- // we'll add generic types to the constructor's parameters.
12627
- const addGenericParamTypes = containingClassType &&
12628
- types_1.ClassType.isPseudoGenericClass(containingClassType) &&
12629
- node.name.value === '__init__';
12630
- const paramTypes = [];
12631
- // Determine if the first parameter should be skipped for comment-based
12632
- // function annotations.
12633
- let firstCommentAnnotationIndex = 0;
12634
- if (containingClassType && (functionType.details.flags & 4 /* FunctionTypeFlags.StaticMethod */) === 0) {
12635
- firstCommentAnnotationIndex = 1;
12636
- }
12637
- // If there is a function annotation comment, validate that it has the correct
12638
- // number of parameter annotations.
12639
- if (node.functionAnnotationComment && !node.functionAnnotationComment.isParamListEllipsis) {
12640
- const expected = node.parameters.length - firstCommentAnnotationIndex;
12641
- const received = node.functionAnnotationComment.paramTypeAnnotations.length;
12642
- // For methods with "self" or "cls" parameters, the annotation list
12643
- // can either include or exclude the annotation for the first parameter.
12644
- if (firstCommentAnnotationIndex > 0 && received === node.parameters.length) {
12645
- firstCommentAnnotationIndex = 0;
12646
- }
12647
- else if (received !== expected) {
12648
- addError(localize_1.LocMessage.annotatedParamCountMismatch().format({
12649
- expected,
12650
- received,
12651
- }), node.functionAnnotationComment);
12652
- }
12653
- }
12654
- // If this function uses PEP 695 syntax for type parameters,
12655
- // accumulate the list of type parameters upfront.
12656
- const typeParametersSeen = [];
12657
- if (node.typeParameters) {
12658
- functionType.details.typeParameters = evaluateTypeParameterList(node.typeParameters).map((typeParam) => (0, typeUtils_1.convertToInstance)(typeParam));
12659
- }
12660
- else {
12661
- functionType.details.typeParameters = typeParametersSeen;
12662
- }
12663
- let paramsArePositionOnly = true;
12664
- const isFirstParamClsOrSelf = containingClassType &&
12665
- (types_1.FunctionType.isClassMethod(functionType) ||
12666
- types_1.FunctionType.isInstanceMethod(functionType) ||
12667
- types_1.FunctionType.isConstructorMethod(functionType));
12668
- const firstNonClsSelfParamIndex = isFirstParamClsOrSelf ? 1 : 0;
12669
- node.parameters.forEach((param, index) => {
12670
- let paramType;
12671
- let annotatedType;
12672
- let paramTypeNode;
12673
- if (param.name) {
12674
- if (index === 0 && isFirstParamClsOrSelf) {
12675
- // Mark "self/cls" as accessed.
12676
- markParamAccessed(param);
12677
- }
12678
- else if (types_1.FunctionType.isAbstractMethod(functionType)) {
12679
- // Mark all parameters in abstract methods as accessed.
12680
- markParamAccessed(param);
12681
- }
12682
- else if (containingClassType && types_1.ClassType.isProtocolClass(containingClassType)) {
12683
- // Mark all parameters in protocol methods as accessed.
12684
- markParamAccessed(param);
12685
- }
12686
- }
12687
- if (param.typeAnnotation) {
12688
- paramTypeNode = param.typeAnnotation;
12689
- }
12690
- else if (param.typeAnnotationComment) {
12691
- paramTypeNode = param.typeAnnotationComment;
12693
+ return (0, cancellationUtils_1.invalidateTypeCacheIfCanceled)(() => {
12694
+ var _a, _b;
12695
+ writeTypeCache(node.name, { type: functionType }, /* flags */ undefined);
12696
+ // Is this an "__init__" method within a pseudo-generic class? If so,
12697
+ // we'll add generic types to the constructor's parameters.
12698
+ const addGenericParamTypes = containingClassType &&
12699
+ types_1.ClassType.isPseudoGenericClass(containingClassType) &&
12700
+ node.name.value === '__init__';
12701
+ const paramTypes = [];
12702
+ // Determine if the first parameter should be skipped for comment-based
12703
+ // function annotations.
12704
+ let firstCommentAnnotationIndex = 0;
12705
+ if (containingClassType && (functionType.details.flags & 4 /* FunctionTypeFlags.StaticMethod */) === 0) {
12706
+ firstCommentAnnotationIndex = 1;
12707
+ }
12708
+ // If there is a function annotation comment, validate that it has the correct
12709
+ // number of parameter annotations.
12710
+ if (node.functionAnnotationComment && !node.functionAnnotationComment.isParamListEllipsis) {
12711
+ const expected = node.parameters.length - firstCommentAnnotationIndex;
12712
+ const received = node.functionAnnotationComment.paramTypeAnnotations.length;
12713
+ // For methods with "self" or "cls" parameters, the annotation list
12714
+ // can either include or exclude the annotation for the first parameter.
12715
+ if (firstCommentAnnotationIndex > 0 && received === node.parameters.length) {
12716
+ firstCommentAnnotationIndex = 0;
12717
+ }
12718
+ else if (received !== expected) {
12719
+ addError(localize_1.LocMessage.annotatedParamCountMismatch().format({
12720
+ expected,
12721
+ received,
12722
+ }), node.functionAnnotationComment);
12723
+ }
12724
+ }
12725
+ // If this function uses PEP 695 syntax for type parameters,
12726
+ // accumulate the list of type parameters upfront.
12727
+ const typeParametersSeen = [];
12728
+ if (node.typeParameters) {
12729
+ functionType.details.typeParameters = evaluateTypeParameterList(node.typeParameters).map((typeParam) => (0, typeUtils_1.convertToInstance)(typeParam));
12692
12730
  }
12693
- else if (node.functionAnnotationComment && !node.functionAnnotationComment.isParamListEllipsis) {
12694
- const adjustedIndex = index - firstCommentAnnotationIndex;
12695
- if (adjustedIndex >= 0 && adjustedIndex < node.functionAnnotationComment.paramTypeAnnotations.length) {
12696
- paramTypeNode = node.functionAnnotationComment.paramTypeAnnotations[adjustedIndex];
12697
- }
12731
+ else {
12732
+ functionType.details.typeParameters = typeParametersSeen;
12698
12733
  }
12699
- if (paramTypeNode) {
12700
- if ((functionInfo.flags & 524288 /* FunctionTypeFlags.NoTypeCheck */) !== 0) {
12701
- annotatedType = types_1.UnknownType.create();
12734
+ let paramsArePositionOnly = true;
12735
+ const isFirstParamClsOrSelf = containingClassType &&
12736
+ (types_1.FunctionType.isClassMethod(functionType) ||
12737
+ types_1.FunctionType.isInstanceMethod(functionType) ||
12738
+ types_1.FunctionType.isConstructorMethod(functionType));
12739
+ const firstNonClsSelfParamIndex = isFirstParamClsOrSelf ? 1 : 0;
12740
+ node.parameters.forEach((param, index) => {
12741
+ let paramType;
12742
+ let annotatedType;
12743
+ let paramTypeNode;
12744
+ if (param.name) {
12745
+ if (index === 0 && isFirstParamClsOrSelf) {
12746
+ // Mark "self/cls" as accessed.
12747
+ markParamAccessed(param);
12748
+ }
12749
+ else if (types_1.FunctionType.isAbstractMethod(functionType)) {
12750
+ // Mark all parameters in abstract methods as accessed.
12751
+ markParamAccessed(param);
12752
+ }
12753
+ else if (containingClassType && types_1.ClassType.isProtocolClass(containingClassType)) {
12754
+ // Mark all parameters in protocol methods as accessed.
12755
+ markParamAccessed(param);
12756
+ }
12702
12757
  }
12703
- else {
12704
- annotatedType = getTypeOfParameterAnnotation(paramTypeNode, param.category);
12758
+ if (param.typeAnnotation) {
12759
+ paramTypeNode = param.typeAnnotation;
12705
12760
  }
12706
- if (annotatedType) {
12707
- (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(annotatedType), functionType.details.typeVarScopeId);
12761
+ else if (param.typeAnnotationComment) {
12762
+ paramTypeNode = param.typeAnnotationComment;
12708
12763
  }
12709
- if ((0, types_1.isVariadicTypeVar)(annotatedType) && !annotatedType.isVariadicUnpacked) {
12710
- addError(localize_1.LocMessage.unpackedTypeVarTupleExpected().format({
12711
- name1: annotatedType.details.name,
12712
- name2: annotatedType.details.name,
12713
- }), paramTypeNode);
12714
- annotatedType = types_1.UnknownType.create();
12764
+ else if (node.functionAnnotationComment && !node.functionAnnotationComment.isParamListEllipsis) {
12765
+ const adjustedIndex = index - firstCommentAnnotationIndex;
12766
+ if (adjustedIndex >= 0 &&
12767
+ adjustedIndex < node.functionAnnotationComment.paramTypeAnnotations.length) {
12768
+ paramTypeNode = node.functionAnnotationComment.paramTypeAnnotations[adjustedIndex];
12769
+ }
12715
12770
  }
12716
- }
12717
- if (!annotatedType && addGenericParamTypes) {
12718
- if (index > 0 && param.category === 0 /* ParameterCategory.Simple */ && param.name && !param.defaultValue) {
12719
- const typeParamName = getPseudoGenericTypeVarName(param.name.value);
12720
- annotatedType = containingClassType.details.typeParameters.find((param) => param.details.name === typeParamName);
12771
+ if (paramTypeNode) {
12772
+ if ((functionInfo.flags & 524288 /* FunctionTypeFlags.NoTypeCheck */) !== 0) {
12773
+ annotatedType = types_1.UnknownType.create();
12774
+ }
12775
+ else {
12776
+ annotatedType = getTypeOfParameterAnnotation(paramTypeNode, param.category);
12777
+ }
12778
+ if (annotatedType) {
12779
+ (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(annotatedType), functionType.details.typeVarScopeId);
12780
+ }
12781
+ if ((0, types_1.isVariadicTypeVar)(annotatedType) && !annotatedType.isVariadicUnpacked) {
12782
+ addError(localize_1.LocMessage.unpackedTypeVarTupleExpected().format({
12783
+ name1: annotatedType.details.name,
12784
+ name2: annotatedType.details.name,
12785
+ }), paramTypeNode);
12786
+ annotatedType = types_1.UnknownType.create();
12787
+ }
12721
12788
  }
12722
- }
12723
- if (annotatedType) {
12724
- const adjustedAnnotatedType = adjustParameterAnnotatedType(param, annotatedType);
12725
- if (adjustedAnnotatedType !== annotatedType) {
12726
- annotatedType = adjustedAnnotatedType;
12789
+ if (!annotatedType && addGenericParamTypes) {
12790
+ if (index > 0 && param.category === 0 /* ParameterCategory.Simple */ && param.name && !param.defaultValue) {
12791
+ const typeParamName = getPseudoGenericTypeVarName(param.name.value);
12792
+ annotatedType = containingClassType.details.typeParameters.find((param) => param.details.name === typeParamName);
12793
+ }
12727
12794
  }
12728
- }
12729
- let defaultValueType;
12730
- if (param.defaultValue) {
12731
- // If this is a stub file, a protocol, an overload, or a class
12732
- // whose body is a placeholder implementation, treat a "...", as
12733
- // an "Any" value.
12734
- let treatEllipsisAsAny = fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.suite);
12735
- if (containingClassType && types_1.ClassType.isProtocolClass(containingClassType)) {
12736
- treatEllipsisAsAny = true;
12795
+ if (annotatedType) {
12796
+ const adjustedAnnotatedType = adjustParameterAnnotatedType(param, annotatedType);
12797
+ if (adjustedAnnotatedType !== annotatedType) {
12798
+ annotatedType = adjustedAnnotatedType;
12799
+ }
12737
12800
  }
12738
- if (types_1.FunctionType.isOverloaded(functionType) || types_1.FunctionType.isAbstractMethod(functionType)) {
12739
- treatEllipsisAsAny = true;
12801
+ let defaultValueType;
12802
+ if (param.defaultValue) {
12803
+ // If this is a stub file, a protocol, an overload, or a class
12804
+ // whose body is a placeholder implementation, treat a "...", as
12805
+ // an "Any" value.
12806
+ let treatEllipsisAsAny = fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.suite);
12807
+ if (containingClassType && types_1.ClassType.isProtocolClass(containingClassType)) {
12808
+ treatEllipsisAsAny = true;
12809
+ }
12810
+ if (types_1.FunctionType.isOverloaded(functionType) || types_1.FunctionType.isAbstractMethod(functionType)) {
12811
+ treatEllipsisAsAny = true;
12812
+ }
12813
+ defaultValueType = getTypeOfExpression(param.defaultValue, treatEllipsisAsAny ? 1 /* EvaluatorFlags.ConvertEllipsisToAny */ : 0 /* EvaluatorFlags.None */, (0, typeUtils_1.makeInferenceContext)(annotatedType)).type;
12740
12814
  }
12741
- defaultValueType = getTypeOfExpression(param.defaultValue, treatEllipsisAsAny ? 1 /* EvaluatorFlags.ConvertEllipsisToAny */ : 0 /* EvaluatorFlags.None */, (0, typeUtils_1.makeInferenceContext)(annotatedType)).type;
12742
- }
12743
- if (annotatedType) {
12744
- // If there was both a type annotation and a default value, verify
12745
- // that the default value matches the annotation.
12746
- if (param.defaultValue && defaultValueType) {
12747
- const diagAddendum = new diagnostic_1.DiagnosticAddendum();
12748
- const typeVarContext = new typeVarContext_1.TypeVarContext(functionType.details.typeVarScopeId);
12749
- if (containingClassType && containingClassType.details.typeVarScopeId !== undefined) {
12750
- if (node.name.value === '__init__' || node.name.value === '__new__') {
12751
- typeVarContext.addSolveForScope(containingClassType.details.typeVarScopeId);
12815
+ if (annotatedType) {
12816
+ // If there was both a type annotation and a default value, verify
12817
+ // that the default value matches the annotation.
12818
+ if (param.defaultValue && defaultValueType) {
12819
+ const diagAddendum = new diagnostic_1.DiagnosticAddendum();
12820
+ const typeVarContext = new typeVarContext_1.TypeVarContext(functionType.details.typeVarScopeId);
12821
+ if (containingClassType && containingClassType.details.typeVarScopeId !== undefined) {
12822
+ if (node.name.value === '__init__' || node.name.value === '__new__') {
12823
+ typeVarContext.addSolveForScope(containingClassType.details.typeVarScopeId);
12824
+ }
12825
+ }
12826
+ if (!assignType(annotatedType, defaultValueType, diagAddendum, typeVarContext)) {
12827
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportArgumentType, localize_1.LocMessage.paramAssignmentMismatch().format({
12828
+ sourceType: printType(defaultValueType),
12829
+ paramType: printType(annotatedType),
12830
+ }) + diagAddendum.getString(), param.defaultValue);
12752
12831
  }
12753
12832
  }
12754
- if (!assignType(annotatedType, defaultValueType, diagAddendum, typeVarContext)) {
12755
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportArgumentType, localize_1.LocMessage.paramAssignmentMismatch().format({
12756
- sourceType: printType(defaultValueType),
12757
- paramType: printType(annotatedType),
12758
- }) + diagAddendum.getString(), param.defaultValue);
12759
- }
12760
- }
12761
- paramType = annotatedType;
12762
- }
12763
- // Determine whether we need to insert an implied position-only parameter.
12764
- // This is needed when a function's parameters are named using the old-style
12765
- // way of specifying position-only parameters.
12766
- if (index >= firstNonClsSelfParamIndex) {
12767
- let isImplicitPositionOnlyParam = false;
12768
- if (param.category === 0 /* ParameterCategory.Simple */ && param.name) {
12769
- if ((0, symbolNameUtils_1.isPrivateName)(param.name.value) &&
12770
- !node.parameters.some((p) => p.category === 0 /* ParameterCategory.Simple */ && !p.name)) {
12771
- isImplicitPositionOnlyParam = true;
12772
- // If the parameter name indicates an implicit position-only parameter
12773
- // but we have already seen non-position-only parameters, report an error.
12774
- if (!paramsArePositionOnly &&
12775
- functionType.details.parameters.every((p) => p.category === 0 /* ParameterCategory.Simple */)) {
12776
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.positionOnlyAfterNon(), param.name);
12833
+ paramType = annotatedType;
12834
+ }
12835
+ // Determine whether we need to insert an implied position-only parameter.
12836
+ // This is needed when a function's parameters are named using the old-style
12837
+ // way of specifying position-only parameters.
12838
+ if (index >= firstNonClsSelfParamIndex) {
12839
+ let isImplicitPositionOnlyParam = false;
12840
+ if (param.category === 0 /* ParameterCategory.Simple */ && param.name) {
12841
+ if ((0, symbolNameUtils_1.isPrivateName)(param.name.value) &&
12842
+ !node.parameters.some((p) => p.category === 0 /* ParameterCategory.Simple */ && !p.name)) {
12843
+ isImplicitPositionOnlyParam = true;
12844
+ // If the parameter name indicates an implicit position-only parameter
12845
+ // but we have already seen non-position-only parameters, report an error.
12846
+ if (!paramsArePositionOnly &&
12847
+ functionType.details.parameters.every((p) => p.category === 0 /* ParameterCategory.Simple */)) {
12848
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.positionOnlyAfterNon(), param.name);
12849
+ }
12777
12850
  }
12778
12851
  }
12852
+ else {
12853
+ paramsArePositionOnly = false;
12854
+ }
12855
+ if (paramsArePositionOnly &&
12856
+ !isImplicitPositionOnlyParam &&
12857
+ functionType.details.parameters.length > firstNonClsSelfParamIndex) {
12858
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
12859
+ }
12860
+ if (!isImplicitPositionOnlyParam) {
12861
+ paramsArePositionOnly = false;
12862
+ }
12863
+ }
12864
+ // If there was no annotation for the parameter, infer its type if possible.
12865
+ let isTypeInferred = false;
12866
+ if (!paramTypeNode) {
12867
+ isTypeInferred = true;
12868
+ const inferredType = inferParameterType(node, functionType.details.flags, index, containingClassType);
12869
+ if (inferredType) {
12870
+ paramType = inferredType;
12871
+ }
12872
+ }
12873
+ const functionParam = {
12874
+ category: param.category,
12875
+ name: param.name ? param.name.value : undefined,
12876
+ hasDefault: !!param.defaultValue,
12877
+ defaultValueExpression: param.defaultValue,
12878
+ defaultType: defaultValueType,
12879
+ type: paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create(),
12880
+ typeAnnotation: paramTypeNode,
12881
+ hasDeclaredType: !!paramTypeNode,
12882
+ isTypeInferred,
12883
+ };
12884
+ types_1.FunctionType.addParameter(functionType, functionParam);
12885
+ if (functionParam.hasDeclaredType) {
12886
+ (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionParam.type), functionType.details.typeVarScopeId);
12779
12887
  }
12780
- else {
12781
- paramsArePositionOnly = false;
12888
+ if (param.name) {
12889
+ const variadicParamType = transformVariadicParamType(node, param.category, functionParam.type);
12890
+ paramTypes.push(variadicParamType);
12782
12891
  }
12783
- if (paramsArePositionOnly &&
12784
- !isImplicitPositionOnlyParam &&
12785
- functionType.details.parameters.length > firstNonClsSelfParamIndex) {
12786
- types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
12892
+ else {
12893
+ paramTypes.push(functionParam.type);
12787
12894
  }
12788
- if (!isImplicitPositionOnlyParam) {
12789
- paramsArePositionOnly = false;
12790
- }
12791
- }
12792
- // If there was no annotation for the parameter, infer its type if possible.
12793
- let isTypeInferred = false;
12794
- if (!paramTypeNode) {
12795
- isTypeInferred = true;
12796
- const inferredType = inferParameterType(node, functionType.details.flags, index, containingClassType);
12797
- if (inferredType) {
12798
- paramType = inferredType;
12799
- }
12800
- }
12801
- const functionParam = {
12802
- category: param.category,
12803
- name: param.name ? param.name.value : undefined,
12804
- hasDefault: !!param.defaultValue,
12805
- defaultValueExpression: param.defaultValue,
12806
- defaultType: defaultValueType,
12807
- type: paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create(),
12808
- typeAnnotation: paramTypeNode,
12809
- hasDeclaredType: !!paramTypeNode,
12810
- isTypeInferred,
12811
- };
12812
- types_1.FunctionType.addParameter(functionType, functionParam);
12813
- if (functionParam.hasDeclaredType) {
12814
- (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionParam.type), functionType.details.typeVarScopeId);
12815
- }
12816
- if (param.name) {
12817
- const variadicParamType = transformVariadicParamType(node, param.category, functionParam.type);
12818
- paramTypes.push(variadicParamType);
12819
- }
12820
- else {
12821
- paramTypes.push(functionParam.type);
12895
+ });
12896
+ if (paramsArePositionOnly && functionType.details.parameters.length > firstNonClsSelfParamIndex) {
12897
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
12822
12898
  }
12823
- });
12824
- if (paramsArePositionOnly && functionType.details.parameters.length > firstNonClsSelfParamIndex) {
12825
- types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
12826
- }
12827
- // Update the types for the nodes associated with the parameters.
12828
- paramTypes.forEach((paramType, index) => {
12829
- const paramNameNode = node.parameters[index].name;
12830
- if (paramNameNode) {
12831
- if ((0, types_1.isUnknown)(paramType)) {
12832
- functionType.details.flags |= 16384 /* FunctionTypeFlags.UnannotatedParams */;
12899
+ // Update the types for the nodes associated with the parameters.
12900
+ paramTypes.forEach((paramType, index) => {
12901
+ const paramNameNode = node.parameters[index].name;
12902
+ if (paramNameNode) {
12903
+ if ((0, types_1.isUnknown)(paramType)) {
12904
+ functionType.details.flags |= 16384 /* FunctionTypeFlags.UnannotatedParams */;
12905
+ }
12906
+ writeTypeCache(paramNameNode, { type: paramType }, 0 /* EvaluatorFlags.None */);
12833
12907
  }
12834
- writeTypeCache(paramNameNode, { type: paramType }, 0 /* EvaluatorFlags.None */);
12835
- }
12836
- });
12837
- // If the function ends in P.args and P.kwargs parameters, make it exempt from
12838
- // args/kwargs compatibility checks. This is important for protocol comparisons.
12839
- if (paramTypes.length >= 2) {
12840
- const paramType1 = paramTypes[paramTypes.length - 2];
12841
- const paramType2 = paramTypes[paramTypes.length - 1];
12842
- if ((0, types_1.isParamSpec)(paramType1) &&
12843
- paramType1.paramSpecAccess === 'args' &&
12844
- (0, types_1.isParamSpec)(paramType2) &&
12845
- paramType2.paramSpecAccess === 'kwargs') {
12846
- functionType.details.flags |= 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
12847
- }
12848
- }
12849
- // If the function contains an *args and a **kwargs parameter and both
12850
- // are annotated as Any or are unannotated, make it exempt from
12851
- // args/kwargs compatibility checks.
12852
- const variadicsWithAnyType = functionType.details.parameters.filter((param) => param.category !== 0 /* ParameterCategory.Simple */ && param.name && (0, types_1.isAnyOrUnknown)(param.type));
12853
- if (variadicsWithAnyType.length >= 2) {
12854
- functionType.details.flags |= 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
12855
- }
12856
- // If there was a defined return type, analyze that first so when we
12857
- // walk the contents of the function, return statements can be
12858
- // validated against this type.
12859
- const returnTypeAnnotationNode = (_b = node.returnTypeAnnotation) !== null && _b !== void 0 ? _b : (_c = node.functionAnnotationComment) === null || _c === void 0 ? void 0 : _c.returnTypeAnnotation;
12860
- if (returnTypeAnnotationNode) {
12861
- // Temporarily set the return type to unknown in case of recursion.
12862
- functionType.details.declaredReturnType = types_1.UnknownType.create();
12863
- const returnType = getTypeOfAnnotation(returnTypeAnnotationNode, {
12864
- associateTypeVarsWithScope: true,
12865
12908
  });
12866
- functionType.details.declaredReturnType = returnType;
12867
- }
12868
- else {
12869
- // If there was no return type annotation and this is a type stub,
12870
- // we have no opportunity to infer the return type, so we'll indicate
12871
- // that it's unknown.
12872
- if (fileInfo.isStubFile) {
12873
- // Special-case the __init__ method, which is commonly left without
12874
- // an annotated return type, but we can assume it returns None.
12875
- if (node.name.value === '__init__') {
12876
- functionType.details.declaredReturnType = getNoneType();
12877
- }
12878
- else {
12879
- functionType.details.declaredReturnType = types_1.UnknownType.create();
12909
+ // If the function ends in P.args and P.kwargs parameters, make it exempt from
12910
+ // args/kwargs compatibility checks. This is important for protocol comparisons.
12911
+ if (paramTypes.length >= 2) {
12912
+ const paramType1 = paramTypes[paramTypes.length - 2];
12913
+ const paramType2 = paramTypes[paramTypes.length - 1];
12914
+ if ((0, types_1.isParamSpec)(paramType1) &&
12915
+ paramType1.paramSpecAccess === 'args' &&
12916
+ (0, types_1.isParamSpec)(paramType2) &&
12917
+ paramType2.paramSpecAccess === 'kwargs') {
12918
+ functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
12919
+ }
12920
+ }
12921
+ // If the function contains an *args and a **kwargs parameter and both
12922
+ // are annotated as Any or are unannotated, make it exempt from
12923
+ // args/kwargs compatibility checks.
12924
+ const variadicsWithAnyType = functionType.details.parameters.filter((param) => param.category !== 0 /* ParameterCategory.Simple */ && param.name && (0, types_1.isAnyOrUnknown)(param.type));
12925
+ if (variadicsWithAnyType.length >= 2) {
12926
+ functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
12927
+ }
12928
+ // If there was a defined return type, analyze that first so when we
12929
+ // walk the contents of the function, return statements can be
12930
+ // validated against this type.
12931
+ const returnTypeAnnotationNode = (_a = node.returnTypeAnnotation) !== null && _a !== void 0 ? _a : (_b = node.functionAnnotationComment) === null || _b === void 0 ? void 0 : _b.returnTypeAnnotation;
12932
+ if (returnTypeAnnotationNode) {
12933
+ // Temporarily set the return type to unknown in case of recursion.
12934
+ functionType.details.declaredReturnType = types_1.UnknownType.create();
12935
+ const returnType = getTypeOfAnnotation(returnTypeAnnotationNode, {
12936
+ associateTypeVarsWithScope: true,
12937
+ });
12938
+ functionType.details.declaredReturnType = returnType;
12939
+ }
12940
+ else {
12941
+ // If there was no return type annotation and this is a type stub,
12942
+ // we have no opportunity to infer the return type, so we'll indicate
12943
+ // that it's unknown.
12944
+ if (fileInfo.isStubFile) {
12945
+ // Special-case the __init__ method, which is commonly left without
12946
+ // an annotated return type, but we can assume it returns None.
12947
+ if (node.name.value === '__init__') {
12948
+ functionType.details.declaredReturnType = getNoneType();
12949
+ }
12950
+ else {
12951
+ functionType.details.declaredReturnType = types_1.UnknownType.create();
12952
+ }
12880
12953
  }
12881
12954
  }
12882
- }
12883
- // Accumulate any type parameters used in the return type.
12884
- if (functionType.details.declaredReturnType && returnTypeAnnotationNode) {
12885
- (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionType.details.declaredReturnType), functionType.details.typeVarScopeId);
12886
- }
12887
- // If the return type is explicitly annotated as a generator, mark the
12888
- // function as a generator even though it may not contain a "yield" statement.
12889
- // This is important for generator functions declared in stub files, abstract
12890
- // methods or protocol definitions.
12891
- if (fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.suite)) {
12892
- if (functionType.details.declaredReturnType &&
12893
- (0, types_1.isClassInstance)(functionType.details.declaredReturnType) &&
12894
- types_1.ClassType.isBuiltIn(functionType.details.declaredReturnType, [
12895
- 'Generator',
12896
- 'AsyncGenerator',
12897
- 'AwaitableGenerator',
12898
- ])) {
12899
- functionType.details.flags |= 16 /* FunctionTypeFlags.Generator */;
12955
+ // Accumulate any type parameters used in the return type.
12956
+ if (functionType.details.declaredReturnType && returnTypeAnnotationNode) {
12957
+ (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionType.details.declaredReturnType), functionType.details.typeVarScopeId);
12900
12958
  }
12901
- }
12902
- // Validate the default types for all type parameters.
12903
- functionType.details.typeParameters.forEach((typeParam, index) => {
12904
- var _a;
12905
- let bestErrorNode = node.name;
12906
- if (node.typeParameters && index < node.typeParameters.parameters.length) {
12907
- const typeParamNode = node.typeParameters.parameters[index];
12908
- bestErrorNode = (_a = typeParamNode.defaultExpression) !== null && _a !== void 0 ? _a : typeParamNode.name;
12959
+ // If the return type is explicitly annotated as a generator, mark the
12960
+ // function as a generator even though it may not contain a "yield" statement.
12961
+ // This is important for generator functions declared in stub files, abstract
12962
+ // methods or protocol definitions.
12963
+ if (fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.suite)) {
12964
+ if (functionType.details.declaredReturnType &&
12965
+ (0, types_1.isClassInstance)(functionType.details.declaredReturnType) &&
12966
+ types_1.ClassType.isBuiltIn(functionType.details.declaredReturnType, [
12967
+ 'Generator',
12968
+ 'AsyncGenerator',
12969
+ 'AwaitableGenerator',
12970
+ ])) {
12971
+ functionType.details.flags |= 16 /* FunctionTypeFlags.Generator */;
12972
+ }
12909
12973
  }
12910
- validateTypeParameterDefault(bestErrorNode, typeParam, functionType.details.typeParameters.slice(0, index), functionType.details.typeVarScopeId);
12974
+ // Validate the default types for all type parameters.
12975
+ functionType.details.typeParameters.forEach((typeParam, index) => {
12976
+ var _a;
12977
+ let bestErrorNode = node.name;
12978
+ if (node.typeParameters && index < node.typeParameters.parameters.length) {
12979
+ const typeParamNode = node.typeParameters.parameters[index];
12980
+ bestErrorNode = (_a = typeParamNode.defaultExpression) !== null && _a !== void 0 ? _a : typeParamNode.name;
12981
+ }
12982
+ validateTypeParameterDefault(bestErrorNode, typeParam, functionType.details.typeParameters.slice(0, index), functionType.details.typeVarScopeId);
12983
+ });
12984
+ // Clear the "partially evaluated" flag to indicate that the functionType
12985
+ // is fully evaluated.
12986
+ functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
12987
+ writeTypeCache(node.name, { type: functionType }, 0 /* EvaluatorFlags.None */);
12988
+ return functionType;
12911
12989
  });
12912
- // Clear the "partially evaluated" flag to indicate that the functionType
12913
- // is fully evaluated.
12914
- functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
12915
- writeTypeCache(node.name, { type: functionType }, 0 /* EvaluatorFlags.None */);
12916
- return functionType;
12917
12990
  }
12918
12991
  function markParamAccessed(param) {
12919
12992
  if (param.name) {
@@ -13226,8 +13299,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13226
13299
  const iteratorTypeResult = getTypeOfExpression(yieldNode.expression);
13227
13300
  if ((0, types_1.isClassInstance)(iteratorTypeResult.type) &&
13228
13301
  types_1.ClassType.isBuiltIn(iteratorTypeResult.type, 'Coroutine')) {
13302
+ const yieldType = iteratorTypeResult.type.typeArguments &&
13303
+ iteratorTypeResult.type.typeArguments.length > 0
13304
+ ? iteratorTypeResult.type.typeArguments[0]
13305
+ : types_1.UnknownType.create();
13229
13306
  // Handle old-style (pre-await) Coroutines.
13230
- inferredYieldTypes.push();
13307
+ inferredYieldTypes.push(yieldType);
13231
13308
  useAwaitableGenerator = true;
13232
13309
  }
13233
13310
  else {
@@ -13253,9 +13330,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13253
13330
  }
13254
13331
  });
13255
13332
  }
13256
- if (inferredYieldTypes.length === 0) {
13257
- inferredYieldTypes.push(getNoneType());
13258
- }
13259
13333
  const inferredYieldType = (0, types_1.combineTypes)(inferredYieldTypes);
13260
13334
  // Inferred yield types need to be wrapped in a Generator or
13261
13335
  // AwaitableGenerator to produce the final result.
@@ -13322,7 +13396,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13322
13396
  }
13323
13397
  const iteratorTypeResult = getTypeOfExpression(node.iterableExpression);
13324
13398
  const iteratedType = (_b = (_a = getTypeOfIterator(iteratorTypeResult, !!node.isAsync, node.iterableExpression)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
13325
- assignTypeToExpression(node.targetExpression, iteratedType, !!iteratorTypeResult.isIncomplete, node.targetExpression);
13399
+ assignTypeToExpression(node.targetExpression, { type: iteratedType, isIncomplete: iteratorTypeResult.isIncomplete }, node.targetExpression);
13326
13400
  writeTypeCache(node, { type: iteratedType, isIncomplete: !!iteratorTypeResult.isIncomplete }, 0 /* EvaluatorFlags.None */);
13327
13401
  }
13328
13402
  function evaluateTypesForExceptStatement(node) {
@@ -13371,7 +13445,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13371
13445
  targetType = getBuiltInObject(node, 'BaseExceptionGroup', [targetType]);
13372
13446
  }
13373
13447
  if (node.name) {
13374
- assignTypeToExpression(node.name, targetType, /* isIncomplete */ false, node.name);
13448
+ assignTypeToExpression(node.name, { type: targetType }, node.name);
13375
13449
  }
13376
13450
  writeTypeCache(node, { type: targetType }, 0 /* EvaluatorFlags.None */);
13377
13451
  }
@@ -13433,7 +13507,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13433
13507
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeNotUsableWith().format({ type: printType(subtype), method: exitMethodName }), node.expression);
13434
13508
  });
13435
13509
  if (node.target) {
13436
- assignTypeToExpression(node.target, scopedType, !!exprTypeResult.isIncomplete, node.target);
13510
+ assignTypeToExpression(node.target, { type: scopedType, isIncomplete: exprTypeResult.isIncomplete }, node.target);
13437
13511
  }
13438
13512
  writeTypeCache(node, { type: scopedType, isIncomplete: !!exprTypeResult.isIncomplete }, 0 /* EvaluatorFlags.None */);
13439
13513
  }
@@ -13466,7 +13540,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13466
13540
  symbolType = cachedModuleType;
13467
13541
  }
13468
13542
  }
13469
- assignTypeToNameNode(symbolNameNode, symbolType, /* isIncomplete */ false, /* ignoreEmptyContainers */ false);
13543
+ assignTypeToNameNode(symbolNameNode, { type: symbolType }, /* ignoreEmptyContainers */ false);
13470
13544
  writeTypeCache(node, { type: symbolType }, 0 /* EvaluatorFlags.None */);
13471
13545
  }
13472
13546
  function evaluateTypesForImportFromAs(node) {
@@ -13532,7 +13606,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13532
13606
  symbolType = types_1.UnknownType.create();
13533
13607
  }
13534
13608
  }
13535
- assignTypeToNameNode(aliasNode, symbolType, /* isIncomplete */ false, /* ignoreEmptyContainers */ false);
13609
+ assignTypeToNameNode(aliasNode, { type: symbolType }, /* ignoreEmptyContainers */ false);
13536
13610
  writeTypeCache(node, { type: symbolType }, 0 /* EvaluatorFlags.None */);
13537
13611
  }
13538
13612
  function evaluateTypesForMatchStatement(node) {
@@ -13630,9 +13704,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13630
13704
  symbolType = cachedModuleType;
13631
13705
  }
13632
13706
  }
13633
- assignTypeToNameNode(symbolNameNode, symbolType,
13634
- /* isIncomplete */ false,
13635
- /* ignoreEmptyContainers */ false);
13707
+ assignTypeToNameNode(symbolNameNode, { type: symbolType }, /* ignoreEmptyContainers */ false);
13636
13708
  writeTypeCache(node, { type: symbolType }, 0 /* EvaluatorFlags.None */);
13637
13709
  }
13638
13710
  }
@@ -14052,7 +14124,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14052
14124
  return;
14053
14125
  }
14054
14126
  case 4 /* ParseNodeType.AssignmentExpression */: {
14055
- getTypeOfExpression(curNode);
14127
+ evaluateTypesForExpressionInContext(curNode);
14056
14128
  return;
14057
14129
  }
14058
14130
  case 5 /* ParseNodeType.AugmentedAssignment */: {
@@ -14469,7 +14541,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14469
14541
  const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
14470
14542
  if ((0, typeUtils_1.isEllipsisType)(typeArg.type)) {
14471
14543
  types_1.FunctionType.addDefaultParameters(functionType);
14472
- functionType.details.flags |= 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
14544
+ functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
14473
14545
  typeArgTypes.push(functionType);
14474
14546
  typeVarContext.setTypeVarType(typeParam, (0, typeUtils_1.convertTypeToParamSpecValue)(functionType));
14475
14547
  return;
@@ -14497,12 +14569,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14497
14569
  concatTypeArgs.forEach((typeArg, index) => {
14498
14570
  if (index === concatTypeArgs.length - 1) {
14499
14571
  if ((0, types_1.isParamSpec)(typeArg)) {
14500
- functionType.details.paramSpec = typeArg;
14572
+ types_1.FunctionType.addParamSpecVariadics(functionType, typeArg);
14501
14573
  }
14502
14574
  else if ((0, typeUtils_1.isEllipsisType)(typeArg)) {
14503
14575
  types_1.FunctionType.addDefaultParameters(functionType);
14504
- functionType.details.flags |=
14505
- 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
14576
+ functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
14506
14577
  }
14507
14578
  }
14508
14579
  else {
@@ -15865,7 +15936,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15865
15936
  // the return type. If a list of args is provided, the inference logic may take
15866
15937
  // into account argument types to infer the return type.
15867
15938
  function getFunctionEffectiveReturnType(type, callSiteInfo, inferTypeIfNeeded = true) {
15868
- const specializedReturnType = types_1.FunctionType.getSpecializedReturnType(type, /* includeInferred */ false);
15939
+ const specializedReturnType = types_1.FunctionType.getEffectiveReturnType(type, /* includeInferred */ false);
15869
15940
  if (specializedReturnType && !(0, types_1.isUnknown)(specializedReturnType)) {
15870
15941
  const liveTypeVarScopes = (callSiteInfo === null || callSiteInfo === void 0 ? void 0 : callSiteInfo.errorNode)
15871
15942
  ? ParseTreeUtils.getTypeVarScopesForNode(callSiteInfo === null || callSiteInfo === void 0 ? void 0 : callSiteInfo.errorNode)
@@ -16136,20 +16207,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16136
16207
  // and cache the return type if necessary. This needs to be done
16137
16208
  // prior to specializing.
16138
16209
  inferReturnTypeIfNecessary(typeResult.type);
16139
- if (member.isInstanceMember &&
16140
- (flags & 1024 /* MemberAccessFlags.DisallowGenericInstanceVariableAccess */) !== 0) {
16141
- let isGenericNonCallable = false;
16142
- (0, typeUtils_1.doForEachSubtype)(typeResult.type, (subtype) => {
16143
- if (!(0, types_1.isAnyOrUnknown)(subtype) && !(0, types_1.isFunction)(subtype) && !(0, types_1.isOverloadedFunction)(subtype)) {
16144
- if ((0, typeUtils_1.requiresSpecialization)(typeResult.type, {
16145
- ignoreSelf: true,
16146
- ignoreImplicitTypeArgs: true,
16147
- })) {
16148
- isGenericNonCallable = true;
16149
- }
16150
- }
16151
- });
16152
- if (isGenericNonCallable && errorNode) {
16210
+ // Check for ambiguous accesses to attributes with generic types?
16211
+ if (errorNode &&
16212
+ selfClass &&
16213
+ (0, types_1.isClass)(selfClass) &&
16214
+ member.isInstanceMember &&
16215
+ (0, types_1.isClass)(member.unspecializedClassType) &&
16216
+ (flags & 1024 /* MemberAccessFlags.DisallowGenericInstanceVariableAccess */) !== 0 &&
16217
+ (0, typeUtils_1.requiresSpecialization)(typeResult.type, { ignoreSelf: true, ignoreImplicitTypeArgs: true })) {
16218
+ const specializedType = (0, typeUtils_1.partiallySpecializeType)(typeResult.type, member.unspecializedClassType, (0, typeUtils_1.selfSpecializeClass)(selfClass, /* overrideTypeArgs */ true));
16219
+ if ((0, types_1.findSubtype)(specializedType, (subtype) => !(0, types_1.isFunction)(subtype) &&
16220
+ !(0, types_1.isOverloadedFunction)(subtype) &&
16221
+ (0, typeUtils_1.requiresSpecialization)(subtype, { ignoreSelf: true, ignoreImplicitTypeArgs: true }))) {
16153
16222
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.genericInstanceVariableAccess(), errorNode);
16154
16223
  }
16155
16224
  }
@@ -16331,7 +16400,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16331
16400
  let flags = 0 /* AssignTypeFlags.Default */;
16332
16401
  if ((primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* DeclarationType.Variable */ &&
16333
16402
  !isFinalVariableDeclaration(primaryDecl) &&
16334
- !types_1.ClassType.isFrozenDataClass(destType)) {
16403
+ !types_1.ClassType.isDataClassFrozen(destType)) {
16335
16404
  // Class and instance variables that are mutable need to
16336
16405
  // enforce invariance. We will exempt variables that are
16337
16406
  // private or protected, since these are presumably
@@ -16963,7 +17032,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16963
17032
  // it's Any.
16964
17033
  if ((0, types_1.isParamSpec)(srcType) &&
16965
17034
  (0, types_1.isFunction)(destType) &&
16966
- types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType) &&
17035
+ types_1.FunctionType.isGradualCallableForm(destType) &&
16967
17036
  destType.details.parameters.length <= 2) {
16968
17037
  return true;
16969
17038
  }
@@ -17245,7 +17314,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17245
17314
  /* selfType */ undefined,
17246
17315
  /* diag */ undefined, recursionCount);
17247
17316
  if (boundMethod) {
17248
- concreteSrcType = (0, typeUtils_1.removeParamSpecVariadicsFromSignature)(boundMethod);
17317
+ concreteSrcType = boundMethod;
17249
17318
  }
17250
17319
  }
17251
17320
  // If it's a class, use the constructor for type compatibility checking.
@@ -17789,13 +17858,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17789
17858
  }
17790
17859
  }
17791
17860
  }
17792
- const boundMethod = getBoundMagicMethod(objType, '__call__',
17793
- /* selfType */ undefined,
17794
- /* diag */ undefined, recursionCount);
17795
- if (boundMethod) {
17796
- return (0, typeUtils_1.removeParamSpecVariadicsFromSignature)(boundMethod);
17797
- }
17798
- return undefined;
17861
+ return getBoundMagicMethod(objType, '__call__', /* selfType */ undefined, /* diag */ undefined, recursionCount);
17799
17862
  }
17800
17863
  function assignFunctionParameter(destType, srcType, paramIndex, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
17801
17864
  // Handle the special case where the dest type is a synthesized
@@ -17927,17 +17990,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17927
17990
  }
17928
17991
  }
17929
17992
  function assignFunction(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
17930
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
17993
+ var _a, _b, _c, _d, _e, _f, _g, _h;
17931
17994
  let canAssign = true;
17932
17995
  const checkReturnType = (flags & 64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */) === 0;
17933
17996
  const reverseMatching = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) !== 0;
17934
17997
  flags &= ~64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */;
17935
- destType = (0, typeUtils_1.removeParamSpecVariadicsFromFunction)(destType);
17936
- srcType = (0, typeUtils_1.removeParamSpecVariadicsFromFunction)(srcType);
17998
+ const destParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(destType);
17999
+ if (destParamSpec) {
18000
+ destType = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(destType);
18001
+ }
18002
+ const srcParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(srcType);
18003
+ if (srcParamSpec) {
18004
+ srcType = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(srcType);
18005
+ }
17937
18006
  const destParamDetails = (0, parameterUtils_1.getParameterListDetails)(destType);
17938
18007
  const srcParamDetails = (0, parameterUtils_1.getParameterListDetails)(srcType);
17939
18008
  adjustSourceParamDetailsForDestVariadic(reverseMatching ? destParamDetails : srcParamDetails, reverseMatching ? srcParamDetails : destParamDetails);
17940
- const targetIncludesParamSpec = reverseMatching ? !!srcType.details.paramSpec : !!destType.details.paramSpec;
18009
+ const targetIncludesParamSpec = reverseMatching ? !!srcParamSpec : !!destParamSpec;
17941
18010
  const destPositionalCount = (_a = destParamDetails.firstKeywordOnlyIndex) !== null && _a !== void 0 ? _a : destParamDetails.params.length;
17942
18011
  const srcPositionalCount = (_b = srcParamDetails.firstKeywordOnlyIndex) !== null && _b !== void 0 ? _b : srcParamDetails.params.length;
17943
18012
  const positionalsToMatch = Math.min(destPositionalCount, srcPositionalCount);
@@ -18025,7 +18094,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18025
18094
  canAssign = false;
18026
18095
  }
18027
18096
  }
18028
- if (!types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType) &&
18097
+ if (!types_1.FunctionType.isGradualCallableForm(destType) &&
18029
18098
  destParamDetails.firstPositionOrKeywordIndex < srcParamDetails.positionOnlyParamCount &&
18030
18099
  !targetIncludesParamSpec) {
18031
18100
  diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.argsPositionOnly().format({
@@ -18061,7 +18130,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18061
18130
  }
18062
18131
  continue;
18063
18132
  }
18064
- // If the source parameter is also addressible by keyword, it is OK
18133
+ // If the source parameter is also addressable by keyword, it is OK
18065
18134
  // that there is no matching positional parameter in the dest.
18066
18135
  if (srcParam.kind === parameterUtils_1.ParameterKind.Standard) {
18067
18136
  continue;
@@ -18128,7 +18197,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18128
18197
  // their types are compatible.
18129
18198
  if (srcParamDetails.argsIndex !== undefined &&
18130
18199
  destParamDetails.argsIndex !== undefined &&
18131
- !types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType)) {
18200
+ !types_1.FunctionType.isGradualCallableForm(destType)) {
18132
18201
  let destArgsType = destParamDetails.params[destParamDetails.argsIndex].type;
18133
18202
  let srcArgsType = srcParamDetails.params[srcParamDetails.argsIndex].type;
18134
18203
  if (!(0, types_1.isUnpacked)(destArgsType)) {
@@ -18143,9 +18212,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18143
18212
  }
18144
18213
  // If the dest has an "*args" but the source doesn't, report the incompatibility.
18145
18214
  // The converse situation is OK.
18146
- if (!types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType) &&
18215
+ if (!types_1.FunctionType.isGradualCallableForm(destType) &&
18147
18216
  srcParamDetails.argsIndex === undefined &&
18148
- srcType.details.paramSpec === undefined &&
18217
+ srcParamSpec === undefined &&
18149
18218
  destParamDetails.argsIndex !== undefined &&
18150
18219
  !destParamDetails.hasUnpackedVariadicTypeVar) {
18151
18220
  diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.argsParamMissing().format({
@@ -18260,9 +18329,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18260
18329
  }
18261
18330
  // If the dest has a "**kwargs" but the source doesn't, report the incompatibility.
18262
18331
  // The converse situation is OK.
18263
- if (!types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(destType) &&
18332
+ if (!types_1.FunctionType.isGradualCallableForm(destType) &&
18264
18333
  srcParamDetails.kwargsIndex === undefined &&
18265
- srcType.details.paramSpec === undefined &&
18334
+ srcParamSpec === undefined &&
18266
18335
  destParamDetails.kwargsIndex !== undefined) {
18267
18336
  diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.kwargsParamMissing().format({
18268
18337
  paramName: destParamDetails.params[destParamDetails.kwargsIndex].param.name,
@@ -18272,8 +18341,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18272
18341
  }
18273
18342
  // If the source and the dest are using the same ParamSpec, any additional
18274
18343
  // concatenated parameters must match.
18275
- if (targetIncludesParamSpec &&
18276
- ((_j = srcType.details.paramSpec) === null || _j === void 0 ? void 0 : _j.nameWithScope) === ((_k = destType.details.paramSpec) === null || _k === void 0 ? void 0 : _k.nameWithScope)) {
18344
+ if (targetIncludesParamSpec && (srcParamSpec === null || srcParamSpec === void 0 ? void 0 : srcParamSpec.nameWithScope) === (destParamSpec === null || destParamSpec === void 0 ? void 0 : destParamSpec.nameWithScope)) {
18277
18345
  if (srcParamDetails.params.length !== destParamDetails.params.length) {
18278
18346
  canAssign = false;
18279
18347
  }
@@ -18288,9 +18356,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18288
18356
  });
18289
18357
  // Are we assigning to a function with a ParamSpec?
18290
18358
  if (targetIncludesParamSpec) {
18291
- const effectiveDestType = reverseMatching ? srcType : destType;
18292
18359
  const effectiveSrcType = reverseMatching ? destType : srcType;
18293
- if (effectiveDestType.details.paramSpec) {
18360
+ const effectiveDestType = reverseMatching ? srcType : destType;
18361
+ const effectiveSrcParamSpec = reverseMatching ? destParamSpec : srcParamSpec;
18362
+ const effectiveDestParamSpec = reverseMatching ? srcParamSpec : destParamSpec;
18363
+ if (effectiveDestParamSpec) {
18294
18364
  const requiredMatchParamCount = effectiveDestType.details.parameters.filter((p) => {
18295
18365
  if (!p.name) {
18296
18366
  return false;
@@ -18327,13 +18397,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18327
18397
  });
18328
18398
  }
18329
18399
  });
18330
- const srcParamSpec = effectiveSrcType.details.paramSpec;
18331
- const destParamSpec = effectiveDestType.details.paramSpec;
18332
18400
  // If there are remaining parameters and the source and dest do not contain
18333
18401
  // the same ParamSpec, synthesize a function for the remaining parameters.
18334
18402
  if (remainingParams.length > 0 ||
18335
- !srcParamSpec ||
18336
- !(0, types_1.isTypeSame)(srcParamSpec, destParamSpec, { ignoreTypeFlags: true })) {
18403
+ !effectiveSrcParamSpec ||
18404
+ !(0, types_1.isTypeSame)(effectiveSrcParamSpec, effectiveDestParamSpec, { ignoreTypeFlags: true })) {
18337
18405
  const remainingFunction = types_1.FunctionType.createInstance('', '', '', effectiveSrcType.details.flags | 64 /* FunctionTypeFlags.SynthesizedMethod */, effectiveSrcType.details.docString);
18338
18406
  remainingFunction.details.deprecatedMessage = effectiveSrcType.details.deprecatedMessage;
18339
18407
  remainingFunction.details.typeVarScopeId = effectiveSrcType.details.typeVarScopeId;
@@ -18343,16 +18411,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18343
18411
  remainingParams.forEach((param) => {
18344
18412
  types_1.FunctionType.addParameter(remainingFunction, param);
18345
18413
  });
18346
- remainingFunction.details.paramSpec = srcParamSpec ? (0, typeUtils_1.convertToInstance)(srcParamSpec) : undefined;
18414
+ if (effectiveSrcParamSpec) {
18415
+ types_1.FunctionType.addParamSpecVariadics(remainingFunction, (0, typeUtils_1.convertToInstance)(effectiveSrcParamSpec));
18416
+ }
18347
18417
  types_1.FunctionType.addHigherOrderTypeVarScopeIds(remainingFunction, effectiveSrcType.details.higherOrderTypeVarScopeIds);
18348
- if (!assignType(destParamSpec, remainingFunction,
18418
+ if (!assignType(effectiveDestParamSpec, remainingFunction,
18349
18419
  /* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags)) {
18350
18420
  // If we couldn't assign the function to the ParamSpec, see if we can
18351
18421
  // assign only the ParamSpec. This is possible if there were no
18352
18422
  // remaining parameters.
18353
18423
  if (remainingParams.length > 0 ||
18354
- !srcParamSpec ||
18355
- !assignType((0, typeUtils_1.convertToInstance)(destParamSpec), (0, typeUtils_1.convertToInstance)(srcParamSpec),
18424
+ !effectiveSrcParamSpec ||
18425
+ !assignType((0, typeUtils_1.convertToInstance)(effectiveDestParamSpec), (0, typeUtils_1.convertToInstance)(effectiveSrcParamSpec),
18356
18426
  /* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags)) {
18357
18427
  canAssign = false;
18358
18428
  }
@@ -18473,13 +18543,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18473
18543
  }
18474
18544
  // When a value is assigned to a variable with a declared type,
18475
18545
  // we may be able to narrow the type based on the assignment.
18476
- function narrowTypeBasedOnAssignment(node, declaredType, assignedType) {
18477
- // TODO: The rules for narrowing types on assignment are defined in
18546
+ function narrowTypeBasedOnAssignment(node, declaredType, assignedTypeResult) {
18547
+ // TODO: The rules for narrowing types on assignment are not defined in
18478
18548
  // the typing spec. Pyright's current logic is currently not even internally
18479
18549
  // consistent and probably not sound from a type theory perspective. It
18480
18550
  // should be completely reworked once there has been a public discussion
18481
18551
  // about the correct behavior.
18482
- const narrowedType = (0, typeUtils_1.mapSubtypes)(assignedType, (assignedSubtype) => {
18552
+ // If the result is incomplete, do not attempt to narrow the type.
18553
+ if (assignedTypeResult.isIncomplete) {
18554
+ return assignedTypeResult;
18555
+ }
18556
+ const narrowedType = (0, typeUtils_1.mapSubtypes)(assignedTypeResult.type, (assignedSubtype) => {
18483
18557
  // Handle the special case where the assigned type is a literal type.
18484
18558
  // Some types include very large unions of literal types, and we don't
18485
18559
  // want to use an n^2 loop to compare them.
@@ -18541,12 +18615,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18541
18615
  // with the declared type. In strict mode, this will retain the "unknown type"
18542
18616
  // diagnostics while still providing reasonable completion suggestions.
18543
18617
  if ((0, typeUtils_1.isIncompleteUnknown)(narrowedType)) {
18544
- return narrowedType;
18618
+ return { type: narrowedType };
18545
18619
  }
18546
18620
  else if ((0, types_1.isUnknown)(narrowedType)) {
18547
- return (0, types_1.combineTypes)([narrowedType, declaredType]);
18621
+ return { type: (0, types_1.combineTypes)([narrowedType, declaredType]) };
18548
18622
  }
18549
- return narrowedType;
18623
+ return { type: narrowedType };
18550
18624
  }
18551
18625
  function validateOverrideMethod(baseMethod, overrideMethod, baseClass, diag, enforceParamNames = true) {
18552
18626
  // If we're overriding a non-method with a method, report it as an error.
@@ -18676,8 +18750,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18676
18750
  const baseParamDetails = (0, parameterUtils_1.getParameterListDetails)(baseMethod);
18677
18751
  const overrideParamDetails = (0, parameterUtils_1.getParameterListDetails)(overrideMethod);
18678
18752
  let canOverride = true;
18679
- if (!types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(baseMethod) &&
18680
- !types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(overrideMethod)) {
18753
+ if (!types_1.FunctionType.isGradualCallableForm(baseMethod) && !types_1.FunctionType.isGradualCallableForm(overrideMethod)) {
18681
18754
  // Verify that we're not overriding a static, class or instance method with
18682
18755
  // an incompatible type.
18683
18756
  if (types_1.FunctionType.isStaticMethod(baseMethod)) {
@@ -19137,7 +19210,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19137
19210
  memberTypeFirstParam.hasDeclaredType) {
19138
19211
  if (subDiag) {
19139
19212
  subDiag.addMessage(localize_1.LocMessage.bindTypeMismatch().format({
19140
- type: printType(baseType),
19213
+ type: printType(firstParamType),
19141
19214
  methodName: memberType.details.name || '<anonymous>',
19142
19215
  paramName: memberTypeFirstParam.name,
19143
19216
  }));
@@ -19151,7 +19224,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19151
19224
  // evaluating (and caching) the inferred return type if there is no defined return type.
19152
19225
  getFunctionEffectiveReturnType(memberType);
19153
19226
  const specializedFunction = (0, typeUtils_1.applySolvedTypeVars)(memberType, typeVarContext);
19154
- return types_1.FunctionType.clone(specializedFunction, stripFirstParam, baseType, (0, typeUtils_1.getTypeVarScopeId)(baseType));
19227
+ // If this is a constructor method, provide the base type's TypeVar scope ID
19228
+ // so any TypeVars in this type can be solved.
19229
+ let baseTypeTypeVarScopeId;
19230
+ if (types_1.FunctionType.isConstructorMethod(specializedFunction) || specializedFunction.details.name === '__init__') {
19231
+ baseTypeTypeVarScopeId = (0, typeUtils_1.getTypeVarScopeId)(baseType);
19232
+ }
19233
+ return types_1.FunctionType.clone(specializedFunction, stripFirstParam, baseType, baseTypeTypeVarScopeId);
19155
19234
  }
19156
19235
  function isFinalVariable(symbol) {
19157
19236
  return symbol.getDeclarations().some((decl) => isFinalVariableDeclaration(decl));