@zzzen/pyright-internal 1.2.0-dev.20240609 → 1.2.0-dev.20240623

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 (168) hide show
  1. package/dist/analyzer/binder.d.ts +3 -1
  2. package/dist/analyzer/binder.js +9 -3
  3. package/dist/analyzer/binder.js.map +1 -1
  4. package/dist/analyzer/cacheManager.js +3 -0
  5. package/dist/analyzer/cacheManager.js.map +1 -1
  6. package/dist/analyzer/checker.d.ts +3 -0
  7. package/dist/analyzer/checker.js +164 -85
  8. package/dist/analyzer/checker.js.map +1 -1
  9. package/dist/analyzer/codeFlowEngine.d.ts +1 -1
  10. package/dist/analyzer/codeFlowEngine.js +7 -12
  11. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  12. package/dist/analyzer/constraintSolver.js +1 -4
  13. package/dist/analyzer/constraintSolver.js.map +1 -1
  14. package/dist/analyzer/constructors.js +0 -2
  15. package/dist/analyzer/constructors.js.map +1 -1
  16. package/dist/analyzer/dataClasses.d.ts +2 -2
  17. package/dist/analyzer/dataClasses.js +55 -78
  18. package/dist/analyzer/dataClasses.js.map +1 -1
  19. package/dist/analyzer/decorators.d.ts +2 -1
  20. package/dist/analyzer/decorators.js +34 -39
  21. package/dist/analyzer/decorators.js.map +1 -1
  22. package/dist/analyzer/docStringUtils.d.ts +0 -1
  23. package/dist/analyzer/docStringUtils.js +1 -6
  24. package/dist/analyzer/docStringUtils.js.map +1 -1
  25. package/dist/analyzer/enums.js +1 -1
  26. package/dist/analyzer/enums.js.map +1 -1
  27. package/dist/analyzer/importResolver.js +11 -9
  28. package/dist/analyzer/importResolver.js.map +1 -1
  29. package/dist/analyzer/namedTuples.js +3 -3
  30. package/dist/analyzer/namedTuples.js.map +1 -1
  31. package/dist/analyzer/parseTreeUtils.d.ts +1 -1
  32. package/dist/analyzer/parseTreeUtils.js +18 -2
  33. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  34. package/dist/analyzer/patternMatching.js +11 -2
  35. package/dist/analyzer/patternMatching.js.map +1 -1
  36. package/dist/analyzer/properties.js +2 -2
  37. package/dist/analyzer/properties.js.map +1 -1
  38. package/dist/analyzer/protocols.js +14 -3
  39. package/dist/analyzer/protocols.js.map +1 -1
  40. package/dist/analyzer/service.js +27 -48
  41. package/dist/analyzer/service.js.map +1 -1
  42. package/dist/analyzer/sourceFile.d.ts +2 -1
  43. package/dist/analyzer/sourceFile.js +4 -2
  44. package/dist/analyzer/sourceFile.js.map +1 -1
  45. package/dist/analyzer/typeDocStringUtils.d.ts +1 -0
  46. package/dist/analyzer/typeDocStringUtils.js +8 -1
  47. package/dist/analyzer/typeDocStringUtils.js.map +1 -1
  48. package/dist/analyzer/typeEvaluator.js +555 -580
  49. package/dist/analyzer/typeEvaluator.js.map +1 -1
  50. package/dist/analyzer/typeEvaluatorTypes.d.ts +0 -1
  51. package/dist/analyzer/typePrinter.js +4 -2
  52. package/dist/analyzer/typePrinter.js.map +1 -1
  53. package/dist/analyzer/typeUtils.d.ts +0 -1
  54. package/dist/analyzer/typeUtils.js +13 -24
  55. package/dist/analyzer/typeUtils.js.map +1 -1
  56. package/dist/analyzer/typedDicts.js +6 -6
  57. package/dist/analyzer/typedDicts.js.map +1 -1
  58. package/dist/analyzer/types.d.ts +40 -42
  59. package/dist/analyzer/types.js +93 -97
  60. package/dist/analyzer/types.js.map +1 -1
  61. package/dist/commands/dumpFileDebugInfoCommand.js +16 -24
  62. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  63. package/dist/common/cancellationUtils.d.ts +1 -0
  64. package/dist/common/cancellationUtils.js +15 -1
  65. package/dist/common/cancellationUtils.js.map +1 -1
  66. package/dist/common/configOptions.js +1 -1
  67. package/dist/common/configOptions.js.map +1 -1
  68. package/dist/common/diagnostic.d.ts +1 -0
  69. package/dist/common/diagnostic.js +5 -0
  70. package/dist/common/diagnostic.js.map +1 -1
  71. package/dist/common/docStringService.d.ts +16 -0
  72. package/dist/common/docStringService.js +38 -0
  73. package/dist/common/docStringService.js.map +1 -0
  74. package/dist/common/envVarUtils.js +3 -1
  75. package/dist/common/envVarUtils.js.map +1 -1
  76. package/dist/common/extensibility.d.ts +1 -7
  77. package/dist/common/extensibility.js.map +1 -1
  78. package/dist/common/languageServerInterface.d.ts +1 -2
  79. package/dist/common/languageServerInterface.js.map +1 -1
  80. package/dist/common/serviceKeys.d.ts +2 -0
  81. package/dist/common/serviceKeys.js +1 -0
  82. package/dist/common/serviceKeys.js.map +1 -1
  83. package/dist/common/serviceProvider.js +3 -0
  84. package/dist/common/serviceProvider.js.map +1 -1
  85. package/dist/common/serviceProviderExtensions.d.ts +2 -0
  86. package/dist/common/serviceProviderExtensions.js +8 -0
  87. package/dist/common/serviceProviderExtensions.js.map +1 -1
  88. package/dist/common/stringUtils.d.ts +1 -0
  89. package/dist/common/stringUtils.js +5 -1
  90. package/dist/common/stringUtils.js.map +1 -1
  91. package/dist/common/textRangeCollection.d.ts +1 -1
  92. package/dist/common/textRangeCollection.js +14 -14
  93. package/dist/common/textRangeCollection.js.map +1 -1
  94. package/dist/common/uri/uriUtils.d.ts +1 -1
  95. package/dist/common/uri/uriUtils.js +1 -1
  96. package/dist/common/uri/uriUtils.js.map +1 -1
  97. package/dist/languageServerBase.d.ts +1 -1
  98. package/dist/languageServerBase.js +2 -2
  99. package/dist/languageServerBase.js.map +1 -1
  100. package/dist/languageService/autoImporter.js +2 -2
  101. package/dist/languageService/autoImporter.js.map +1 -1
  102. package/dist/languageService/completionProvider.d.ts +1 -0
  103. package/dist/languageService/completionProvider.js +16 -7
  104. package/dist/languageService/completionProvider.js.map +1 -1
  105. package/dist/languageService/completionProviderUtils.d.ts +2 -1
  106. package/dist/languageService/completionProviderUtils.js +6 -4
  107. package/dist/languageService/completionProviderUtils.js.map +1 -1
  108. package/dist/languageService/definitionProvider.d.ts +2 -1
  109. package/dist/languageService/definitionProvider.js.map +1 -1
  110. package/dist/languageService/hoverProvider.d.ts +2 -1
  111. package/dist/languageService/hoverProvider.js +17 -11
  112. package/dist/languageService/hoverProvider.js.map +1 -1
  113. package/dist/languageService/signatureHelpProvider.d.ts +3 -1
  114. package/dist/languageService/signatureHelpProvider.js +26 -7
  115. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  116. package/dist/localization/localize.d.ts +1 -0
  117. package/dist/localization/localize.js +1 -0
  118. package/dist/localization/localize.js.map +1 -1
  119. package/dist/localization/package.nls.cs.json +4 -1
  120. package/dist/localization/package.nls.de.json +4 -1
  121. package/dist/localization/package.nls.en-us.json +1 -0
  122. package/dist/localization/package.nls.es.json +3 -0
  123. package/dist/localization/package.nls.fr.json +4 -1
  124. package/dist/localization/package.nls.it.json +4 -1
  125. package/dist/localization/package.nls.ja.json +4 -1
  126. package/dist/localization/package.nls.ko.json +4 -1
  127. package/dist/localization/package.nls.pl.json +4 -1
  128. package/dist/localization/package.nls.pt-br.json +4 -1
  129. package/dist/localization/package.nls.qps-ploc.json +4 -1
  130. package/dist/localization/package.nls.ru.json +4 -1
  131. package/dist/localization/package.nls.tr.json +4 -1
  132. package/dist/localization/package.nls.zh-cn.json +4 -1
  133. package/dist/localization/package.nls.zh-tw.json +4 -1
  134. package/dist/tests/checker.test.js +10 -2
  135. package/dist/tests/checker.test.js.map +1 -1
  136. package/dist/tests/config.test.js +1 -1
  137. package/dist/tests/config.test.js.map +1 -1
  138. package/dist/tests/docStringConversion.test.d.ts +2 -1
  139. package/dist/tests/docStringConversion.test.js +300 -293
  140. package/dist/tests/docStringConversion.test.js.map +1 -1
  141. package/dist/tests/fourslash/hover.docstring.alias.fourslash.js +5 -5
  142. package/dist/tests/fourslash/hover.docstring.alias.fourslash.js.map +1 -1
  143. package/dist/tests/fourslash/hover.init.fourslash.js +1 -1
  144. package/dist/tests/fourslash/hover.init.fourslash.js.map +1 -1
  145. package/dist/tests/fourslash/hover.variable.docString.fourslash.js +1 -1
  146. package/dist/tests/fourslash/hover.variable.docString.fourslash.js.map +1 -1
  147. package/dist/tests/fourslash/rename.externallyHidden.fourslash.js +2 -2
  148. package/dist/tests/fourslash/rename.externallyHidden.fourslash.js.map +1 -1
  149. package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.js +1 -1
  150. package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.js.map +1 -1
  151. package/dist/tests/harness/fourslash/testState.js +2 -1
  152. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  153. package/dist/tests/parseTreeUtils.test.js +89 -0
  154. package/dist/tests/parseTreeUtils.test.js.map +1 -1
  155. package/dist/tests/pathUtils.test.js +6 -0
  156. package/dist/tests/pathUtils.test.js.map +1 -1
  157. package/dist/tests/signatureHelp.test.js +2 -1
  158. package/dist/tests/signatureHelp.test.js.map +1 -1
  159. package/dist/tests/typeEvaluator1.test.js +1 -1
  160. package/dist/tests/typeEvaluator3.test.js +1 -1
  161. package/dist/tests/typeEvaluator7.test.js +1 -1
  162. package/dist/tests/uri.test.js +6 -0
  163. package/dist/tests/uri.test.js.map +1 -1
  164. package/dist/workspaceFactory.d.ts +1 -1
  165. package/package.json +1 -1
  166. package/dist/tests/docStringUtils.test.d.ts +0 -1
  167. package/dist/tests/docStringUtils.test.js +0 -74
  168. 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);
@@ -740,6 +740,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
740
740
  if (expectingInstantiable) {
741
741
  validateTypeIsInstantiable(typeResult, flags, node);
742
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
+ }
743
750
  return typeResult;
744
751
  }
745
752
  // Reports the case where a function or class has been decorated with
@@ -1460,7 +1467,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1460
1467
  }
1461
1468
  // If this is a type[Any] or type[Unknown], allow any other members.
1462
1469
  if ((0, types_1.isClassInstance)(objectType) && types_1.ClassType.isBuiltIn(objectType, 'type') && objectType.includeSubclasses) {
1463
- if ((flags & 8 /* MemberAccessFlags.SkipTypeBaseClass */) === 0) {
1470
+ if ((flags & (8 /* MemberAccessFlags.SkipTypeBaseClass */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */)) === 0) {
1464
1471
  const typeArg = objectType.typeArguments && objectType.typeArguments.length >= 1
1465
1472
  ? objectType.typeArguments[0]
1466
1473
  : types_1.UnknownType.create();
@@ -2136,15 +2143,38 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2136
2143
  }
2137
2144
  }
2138
2145
  function addDiagnosticWithSuppressionCheck(diagLevel, message, node, range) {
2139
- if (!isDiagnosticSuppressedForNode(node) && isNodeReachable(node)) {
2146
+ var _a;
2147
+ if (isDiagnosticSuppressedForNode(node)) {
2148
+ // See if this node is suppressed but the diagnostic should be generated
2149
+ // anyway so it can be used by the caller that requested the suppression.
2150
+ const suppressionEntry = suppressedNodeStack.find((suppressedNode) => ParseTreeUtils.isNodeContainedWithin(node, suppressedNode.node) && suppressedNode.suppressedDiags);
2151
+ (_a = suppressionEntry === null || suppressionEntry === void 0 ? void 0 : suppressionEntry.suppressedDiags) === null || _a === void 0 ? void 0 : _a.push(message);
2152
+ return undefined;
2153
+ }
2154
+ if (isNodeReachable(node)) {
2140
2155
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
2141
- return fileInfo.diagnosticSink.addDiagnosticWithTextRange(diagLevel, message, range || node);
2156
+ return fileInfo.diagnosticSink.addDiagnosticWithTextRange(diagLevel, message, range !== null && range !== void 0 ? range : node);
2142
2157
  }
2143
2158
  return undefined;
2144
2159
  }
2145
2160
  function isDiagnosticSuppressedForNode(node) {
2146
- return (suppressedNodeStack.some((suppressedNode) => ParseTreeUtils.isNodeContainedWithin(node, suppressedNode)) ||
2147
- speculativeTypeTracker.isSpeculative(node, /* ignoreIfDiagnosticsAllowed */ true));
2161
+ if (speculativeTypeTracker.isSpeculative(node, /* ignoreIfDiagnosticsAllowed */ true)) {
2162
+ return true;
2163
+ }
2164
+ return suppressedNodeStack.some((suppressedNode) => ParseTreeUtils.isNodeContainedWithin(node, suppressedNode.node));
2165
+ }
2166
+ // This function is similar to isDiagnosticSuppressedForNode except that it
2167
+ // returns false if diagnostics are suppressed for the node but the caller
2168
+ // has requested that diagnostics be generated anyway.
2169
+ function canSkipDiagnosticForNode(node) {
2170
+ if (speculativeTypeTracker.isSpeculative(node, /* ignoreIfDiagnosticsAllowed */ true)) {
2171
+ return true;
2172
+ }
2173
+ const suppressedEntries = suppressedNodeStack.filter((suppressedNode) => ParseTreeUtils.isNodeContainedWithin(node, suppressedNode.node));
2174
+ if (suppressedEntries.length === 0) {
2175
+ return false;
2176
+ }
2177
+ return suppressedEntries.every((entry) => !entry.suppressedDiags);
2148
2178
  }
2149
2179
  function addDiagnostic(rule, message, node, range) {
2150
2180
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
@@ -4049,7 +4079,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4049
4079
  isDescriptorError = true;
4050
4080
  }
4051
4081
  if ((0, types_1.isInstantiableClass)(memberInfo.classType) &&
4052
- types_1.ClassType.isFrozenDataClass(memberInfo.classType) &&
4082
+ types_1.ClassType.isDataClassFrozen(memberInfo.classType) &&
4053
4083
  isAccessedThroughObject) {
4054
4084
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.dataClassFrozen().format({
4055
4085
  name: printType(types_1.ClassType.cloneAsInstance(memberInfo.classType)),
@@ -4223,6 +4253,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4223
4253
  /* skipUnknownArgCheck */ true,
4224
4254
  /* inferenceContext */ undefined,
4225
4255
  /* signatureTracker */ undefined);
4256
+ }, (suppressedDiags) => {
4257
+ // If diagnostics were recorded when suppressed, add them to the
4258
+ // diagnostic as messages.
4259
+ if (diag) {
4260
+ suppressedDiags.forEach((message) => {
4261
+ diag === null || diag === void 0 ? void 0 : diag.addMessageMultiline(message);
4262
+ });
4263
+ }
4226
4264
  });
4227
4265
  // Collect deprecation information associated with the member access method.
4228
4266
  let deprecationInfo;
@@ -4245,28 +4283,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4245
4283
  memberAccessDeprecationInfo: deprecationInfo,
4246
4284
  };
4247
4285
  }
4248
- // Errors were detected when evaluating the access method call.
4249
- if (usage.method === 'set') {
4250
- if (usage.setType &&
4251
- (0, types_1.isFunction)(methodType) &&
4252
- methodType.details.parameters.length >= 2 &&
4253
- !usage.setType.isIncomplete) {
4254
- const setterType = types_1.FunctionType.getEffectiveParameterType(methodType, 1);
4255
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeIncompatible().format({
4256
- destType: printType(setterType),
4257
- sourceType: printType(usage.setType.type),
4258
- }));
4259
- }
4260
- else if ((0, types_1.isOverloadedFunction)(methodType)) {
4261
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocMessage.noOverload().format({ name: accessMethodName }));
4262
- }
4263
- }
4264
- else {
4265
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.descriptorAccessCallFailed().format({
4266
- name: accessMethodName,
4267
- className: printType((0, typeUtils_1.convertToInstance)(methodClassType)),
4268
- }));
4269
- }
4270
4286
  return {
4271
4287
  type: types_1.UnknownType.create(),
4272
4288
  typeErrors: true,
@@ -5172,7 +5188,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5172
5188
  });
5173
5189
  positionalIndexType = makeTupleObject(tupleTypeArgs);
5174
5190
  }
5175
- let argList = [
5191
+ const argList = [
5176
5192
  {
5177
5193
  argumentCategory: 0 /* ArgumentCategory.Simple */,
5178
5194
  typeResult: { type: positionalIndexType, isIncomplete: isPositionalIndexTypeIncomplete },
@@ -5209,44 +5225,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5209
5225
  node: arg,
5210
5226
  });
5211
5227
  });
5212
- let callResult;
5213
- // Speculatively attempt the call. We may need to replace the index
5214
- // type with 'int', and we don't want to emit errors before we know
5215
- // which type to use.
5216
- if (keywordArgs.length === 0 && unpackedDictArgs.length === 0 && positionalArgs.length === 1) {
5217
- useSpeculativeMode(node, () => {
5218
- callResult = validateCallArguments(node, argList, { type: itemMethodType },
5219
- /* typeVarContext */ undefined,
5220
- /* skipUnknownArgCheck */ true,
5221
- /* inferenceContext */ undefined,
5222
- /* signatureTracker */ undefined);
5223
- if (callResult.argumentErrors) {
5224
- // If the object supports "__index__" magic method, convert
5225
- // the index to an int and try again.
5226
- if ((0, types_1.isClassInstance)(positionalIndexType)) {
5227
- const altArgList = [...argList];
5228
- altArgList[0] = { ...altArgList[0] };
5229
- const indexMethod = getBoundMagicMethod(positionalIndexType, '__index__');
5230
- if (indexMethod) {
5231
- const intType = getBuiltInObject(node, 'int');
5232
- if ((0, types_1.isClassInstance)(intType)) {
5233
- altArgList[0].typeResult = { type: intType };
5234
- }
5235
- }
5236
- callResult = validateCallArguments(node, altArgList, { type: itemMethodType },
5237
- /* typeVarContext */ undefined,
5238
- /* skipUnknownArgCheck */ true,
5239
- /* inferenceContext */ undefined,
5240
- /* signatureTracker */ undefined);
5241
- // We were successful, so replace the arg list.
5242
- if (!callResult.argumentErrors) {
5243
- argList = altArgList;
5244
- }
5245
- }
5246
- }
5247
- });
5248
- }
5249
- callResult = validateCallArguments(node, argList, { type: itemMethodType },
5228
+ const callResult = validateCallArguments(node, argList, { type: itemMethodType },
5250
5229
  /* typeVarContext */ undefined,
5251
5230
  /* skipUnknownArgCheck */ true,
5252
5231
  /* inferenceContext */ undefined,
@@ -5647,7 +5626,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5647
5626
  // the base type of this call is not the same as one of the tracked signatures.
5648
5627
  // This is important for nested generic calls (e.g. "foo(foo(x))").
5649
5628
  if (signatureTracker) {
5650
- baseTypeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(baseTypeResult.type, signatureTracker, node.leftExpression.start);
5629
+ baseTypeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(baseTypeResult.type, signatureTracker, node.start);
5651
5630
  }
5652
5631
  if (!(0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
5653
5632
  if (node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ && node.leftExpression.value === 'super') {
@@ -6391,7 +6370,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6391
6370
  if (filteredMatchResults.length === 0) {
6392
6371
  // Skip the error message if we're in speculative mode because it's very
6393
6372
  // expensive, and we're going to suppress the diagnostic anyway.
6394
- if (!isDiagnosticSuppressedForNode(errorNode)) {
6373
+ if (!canSkipDiagnosticForNode(errorNode)) {
6395
6374
  const functionName = typeResult.type.overloads[0].details.name || '<anonymous function>';
6396
6375
  const diagAddendum = new diagnostic_1.DiagnosticAddendum();
6397
6376
  const argTypes = argList.map((t) => {
@@ -6483,7 +6462,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6483
6462
  // We couldn't find any valid overloads. Skip the error message if we're
6484
6463
  // in speculative mode because it's very expensive, and we're going to
6485
6464
  // suppress the diagnostic anyway.
6486
- if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
6465
+ if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
6487
6466
  const result = evaluateUsingBestMatchingOverload(
6488
6467
  /* skipUnknownArgCheck */ true,
6489
6468
  /* emitNoOverloadFoundError */ true);
@@ -6964,6 +6943,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6964
6943
  if ((0, types_1.isTypeVar)(unexpandedCallType)) {
6965
6944
  returnType = (0, typeUtils_1.convertToInstance)(unexpandedCallType);
6966
6945
  }
6946
+ // If we instantiated the "deprecated" class, attach the deprecation
6947
+ // message to the instance.
6948
+ if (errorNode.nodeType === 9 /* ParseNodeType.Call */ &&
6949
+ returnType &&
6950
+ (0, types_1.isClassInstance)(returnType) &&
6951
+ types_1.ClassType.isBuiltIn(returnType, 'deprecated')) {
6952
+ returnType = types_1.ClassType.cloneForDeprecatedInstance(returnType, (0, decorators_1.getDeprecatedMessageFromCall)(errorNode));
6953
+ }
6967
6954
  // If we instantiated a type, transform it into a class.
6968
6955
  // This can happen if someone directly instantiates a metaclass
6969
6956
  // deriving from type.
@@ -7235,7 +7222,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7235
7222
  tooManyPositionals = true;
7236
7223
  }
7237
7224
  if (tooManyPositionals) {
7238
- if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
7225
+ if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
7239
7226
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, positionParamLimitIndex === 1
7240
7227
  ? localize_1.LocMessage.argPositionalExpectedOne()
7241
7228
  : localize_1.LocMessage.argPositionalExpectedCount().format({
@@ -7269,7 +7256,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7269
7256
  if ((0, types_1.isTypeVar)(argTypeResult.type) &&
7270
7257
  argTypeResult.type.paramSpecAccess === 'args' &&
7271
7258
  paramDetails.params[paramIndex].param.category !== 1 /* ParameterCategory.ArgsList */) {
7272
- if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
7259
+ if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
7273
7260
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, positionParamLimitIndex === 1
7274
7261
  ? localize_1.LocMessage.argPositionalExpectedOne()
7275
7262
  : localize_1.LocMessage.argPositionalExpectedCount().format({
@@ -7335,7 +7322,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7335
7322
  // It's not allowed to use unpacked arguments with a variadic *args
7336
7323
  // parameter unless the argument is a variadic arg as well.
7337
7324
  if (isParamVariadic && !isArgCompatibleWithVariadic) {
7338
- if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
7325
+ if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
7339
7326
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.unpackedArgWithVariadicParam(), argList[argIndex].valueExpression || errorNode);
7340
7327
  }
7341
7328
  reportedArgError = true;
@@ -7392,7 +7379,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7392
7379
  : 0 /* ParameterCategory.Simple */;
7393
7380
  if (remainingArgCount <= remainingParamCount) {
7394
7381
  if (remainingArgCount < remainingParamCount) {
7395
- if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
7382
+ if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
7396
7383
  // Have we run out of arguments and still have parameters left to fill?
7397
7384
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, remainingArgCount === 1
7398
7385
  ? localize_1.LocMessage.argMorePositionalExpectedOne()
@@ -7475,7 +7462,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7475
7462
  argsRemainingCount--;
7476
7463
  }
7477
7464
  if (argsRemainingCount > 0) {
7478
- if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
7465
+ if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
7479
7466
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, argsRemainingCount === 1
7480
7467
  ? localize_1.LocMessage.argMorePositionalExpectedOne()
7481
7468
  : localize_1.LocMessage.argMorePositionalExpectedCount().format({
@@ -7557,7 +7544,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7557
7544
  }
7558
7545
  });
7559
7546
  if (!diag.isEmpty()) {
7560
- if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
7547
+ if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
7561
7548
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.unpackedTypedDictArgument() + diag.getString(), argList[argIndex].valueExpression || errorNode);
7562
7549
  }
7563
7550
  reportedArgError = true;
@@ -7617,7 +7604,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7617
7604
  });
7618
7605
  }
7619
7606
  if (!isValidMappingType) {
7620
- if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
7607
+ if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
7621
7608
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.unpackedDictArgumentNotMapping(), argList[argIndex].valueExpression || errorNode);
7622
7609
  }
7623
7610
  reportedArgError = true;
@@ -7638,7 +7625,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7638
7625
  const paramEntry = paramMap.get(paramNameValue);
7639
7626
  if (paramEntry && !paramEntry.isPositionalOnly) {
7640
7627
  if (paramEntry.argsReceived > 0) {
7641
- if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
7628
+ if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
7642
7629
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramAlreadyAssigned().format({ name: paramNameValue }), paramName);
7643
7630
  }
7644
7631
  reportedArgError = true;
@@ -7682,7 +7669,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7682
7669
  trySetActive(argList[argIndex], paramDetails.params[paramDetails.kwargsIndex].param);
7683
7670
  }
7684
7671
  else {
7685
- if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
7672
+ if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
7686
7673
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.paramNameMissing().format({ name: paramName.value }), paramName);
7687
7674
  }
7688
7675
  reportedArgError = true;
@@ -7693,7 +7680,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7693
7680
  paramSpecArgList.push(argList[argIndex]);
7694
7681
  }
7695
7682
  else {
7696
- if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
7683
+ if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
7697
7684
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, positionParamLimitIndex === 1
7698
7685
  ? localize_1.LocMessage.argPositionalExpectedOne()
7699
7686
  : localize_1.LocMessage.argPositionalExpectedCount().format({
@@ -7769,9 +7756,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7769
7756
  return !entry || entry.argsReceived < entry.argsNeeded;
7770
7757
  });
7771
7758
  if (unassignedParams.length > 0) {
7772
- if (!isDiagnosticSuppressedForNode(errorNode)) {
7759
+ if (!canSkipDiagnosticForNode(errorNode)) {
7773
7760
  const missingParamNames = unassignedParams.map((p) => `"${p}"`).join(', ');
7774
- if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
7761
+ if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
7775
7762
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, unassignedParams.length === 1
7776
7763
  ? localize_1.LocMessage.argMissingForParam().format({ name: missingParamNames })
7777
7764
  : localize_1.LocMessage.argMissingForParams().format({ names: missingParamNames }), errorNode);
@@ -7842,7 +7829,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7842
7829
  if (containsVariadicTypeVar &&
7843
7830
  argParam.argument.argumentCategory !== 1 /* ArgumentCategory.UnpackedList */ &&
7844
7831
  !argParam.mapsToVarArgList) {
7845
- if (!isDiagnosticSuppressedForNode(errorNode) && !isTypeIncomplete) {
7832
+ if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
7846
7833
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.typeVarTupleMustBeUnpacked(), (_a = argParam.argument.valueExpression) !== null && _a !== void 0 ? _a : errorNode);
7847
7834
  }
7848
7835
  reportedArgError = true;
@@ -8026,36 +8013,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8026
8013
  }), errorNode.nodeType === 9 /* ParseNodeType.Call */ ? errorNode.leftExpression : errorNode);
8027
8014
  }
8028
8015
  }
8029
- if (type.boundTypeVarScopeId) {
8030
- // If the function was bound to a class or object and was a constructor, a
8031
- // static method or a class method, it's possible that some of that class's
8032
- // type variables have not yet been solved. Add that class's TypeVar scope ID.
8033
- if (type.preBoundFlags !== undefined && type.boundToType && (0, typeUtils_1.requiresSpecialization)(type.boundToType)) {
8034
- if (type.preBoundFlags &
8035
- (4 /* FunctionTypeFlags.StaticMethod */ | 2 /* FunctionTypeFlags.ClassMethod */ | 4 /* FunctionTypeFlags.StaticMethod */)) {
8036
- typeVarContext.addSolveForScope(type.boundTypeVarScopeId);
8037
- }
8038
- }
8039
- // The type annotation for the "self" parameter in an __init__ method to
8040
- // can influence the type being constructed.
8041
- if (type.details.name === '__init__' &&
8042
- type.strippedFirstParamType &&
8043
- type.boundToType &&
8044
- (0, types_1.isClassInstance)(type.strippedFirstParamType) &&
8045
- (0, types_1.isClassInstance)(type.boundToType) &&
8046
- types_1.ClassType.isSameGenericClass(type.strippedFirstParamType, type.boundToType) &&
8047
- type.strippedFirstParamType.typeArguments) {
8048
- const typeParams = type.strippedFirstParamType.details.typeParameters;
8049
- specializedInitSelfType = type.strippedFirstParamType;
8050
- type.strippedFirstParamType.typeArguments.forEach((typeArg, index) => {
8051
- if (index < typeParams.length) {
8052
- const typeParam = typeParams[index];
8053
- if (!(0, types_1.isTypeSame)(typeParam, typeArg, { ignorePseudoGeneric: true })) {
8054
- typeVarContext.setTypeVarType(typeParams[index], typeArg);
8055
- }
8016
+ // The type annotation for the "self" parameter in an __init__ method to
8017
+ // can influence the type being constructed.
8018
+ if (type.details.name === '__init__' &&
8019
+ type.strippedFirstParamType &&
8020
+ type.boundToType &&
8021
+ (0, types_1.isClassInstance)(type.strippedFirstParamType) &&
8022
+ (0, types_1.isClassInstance)(type.boundToType) &&
8023
+ types_1.ClassType.isSameGenericClass(type.strippedFirstParamType, type.boundToType) &&
8024
+ type.strippedFirstParamType.typeArguments) {
8025
+ const typeParams = type.strippedFirstParamType.details.typeParameters;
8026
+ specializedInitSelfType = type.strippedFirstParamType;
8027
+ type.strippedFirstParamType.typeArguments.forEach((typeArg, index) => {
8028
+ if (index < typeParams.length) {
8029
+ const typeParam = typeParams[index];
8030
+ if (!(0, types_1.isTypeSame)(typeParam, typeArg, { ignorePseudoGeneric: true })) {
8031
+ typeVarContext.setTypeVarType(typeParams[index], typeArg);
8056
8032
  }
8057
- });
8058
- }
8033
+ }
8034
+ });
8059
8035
  }
8060
8036
  // Special-case a few built-in calls that are often used for
8061
8037
  // casting or checking for unknown types.
@@ -8632,7 +8608,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8632
8608
  // printing types if the diagnostic is disabled.
8633
8609
  const fileInfo = AnalyzerNodeInfo.getFileInfo(argParam.errorNode);
8634
8610
  if (fileInfo.diagnosticRuleSet.reportArgumentType !== 'none' &&
8635
- !isDiagnosticSuppressedForNode(argParam.errorNode) &&
8611
+ !canSkipDiagnosticForNode(argParam.errorNode) &&
8636
8612
  !isTypeIncomplete) {
8637
8613
  const argTypeText = printType(argType);
8638
8614
  const paramTypeText = printType(argParam.paramType);
@@ -9191,7 +9167,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9191
9167
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeLiteral(), argList[1].node || errorNode);
9192
9168
  }
9193
9169
  let classFlags = baseClass.details.flags & ~(1 /* ClassTypeFlags.BuiltInClass */ | 2 /* ClassTypeFlags.SpecialBuiltIn */);
9194
- classFlags |= 8192 /* ClassTypeFlags.Final */ | 536870912 /* ClassTypeFlags.NewTypeClass */ | 1073741824 /* ClassTypeFlags.ValidTypeAliasClass */;
9170
+ classFlags |= 256 /* ClassTypeFlags.Final */ | 2097152 /* ClassTypeFlags.NewTypeClass */ | 4194304 /* ClassTypeFlags.ValidTypeAliasClass */;
9195
9171
  const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, classFlags, ParseTreeUtils.getTypeSourceId(errorNode),
9196
9172
  /* declaredMetaclass */ undefined, baseClass.details.effectiveMetaclass);
9197
9173
  classType.details.baseClasses.push(isBaseClassAny ? types_1.AnyType.create() : baseClass);
@@ -9223,7 +9199,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9223
9199
  });
9224
9200
  types_1.FunctionType.addDefaultParameters(newType);
9225
9201
  newType.details.declaredReturnType = types_1.ClassType.cloneAsInstance(classType);
9226
- newType.details.constructorTypeVarScopeId = classType.details.typeVarScopeId;
9202
+ newType.details.constructorTypeVarScopeId = (0, typeUtils_1.getTypeVarScopeId)(classType);
9227
9203
  types_1.ClassType.getSymbolTable(classType).set('__new__', symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, newType));
9228
9204
  }
9229
9205
  return classType;
@@ -9245,7 +9221,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9245
9221
  if (!(0, types_1.isClassInstance)(arg1Type) || !(0, typeUtils_1.isTupleClass)(arg1Type) || arg1Type.tupleTypeArguments === undefined) {
9246
9222
  return undefined;
9247
9223
  }
9248
- 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);
9224
+ 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);
9249
9225
  arg1Type.tupleTypeArguments.forEach((typeArg) => {
9250
9226
  const specializedType = makeTopLevelTypeVarsConcrete(typeArg.type);
9251
9227
  if ((0, typeUtils_1.isEffectivelyInstantiable)(specializedType)) {
@@ -10058,128 +10034,132 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10058
10034
  }
10059
10035
  let functionType = types_1.FunctionType.createInstance('', '', '', 131072 /* FunctionTypeFlags.PartiallyEvaluated */);
10060
10036
  functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(node);
10061
- // Pre-cache the incomplete function type in case the evaluation of the
10062
- // lambda depends on itself.
10063
- writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /* EvaluatorFlags.None */);
10064
- // We assume for simplicity that the parameter signature of the lambda is
10065
- // the same as the expected type. If this isn't the case, we'll use
10066
- // object for any lambda parameters that don't match. We could make this
10067
- // more sophisticated in the future, but it becomes very complex to handle
10068
- // all of the permutations.
10069
- let sawParamMismatch = false;
10070
- node.parameters.forEach((param, index) => {
10071
- let paramType;
10072
- if (expectedParamDetails && !sawParamMismatch) {
10073
- if (index < expectedParamDetails.params.length) {
10074
- const expectedParam = expectedParamDetails.params[index];
10075
- // If the parameter category matches and both of the parameters are
10076
- // either separators (/ or *) or not separators, copy the type
10077
- // from the expected parameter.
10078
- if (expectedParam.param.category === param.category && !param.name === !expectedParam.param.name) {
10079
- paramType = expectedParam.type;
10037
+ return (0, cancellationUtils_1.invalidateTypeCacheIfCanceled)(() => {
10038
+ // Pre-cache the incomplete function type in case the evaluation of the
10039
+ // lambda depends on itself.
10040
+ writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /* EvaluatorFlags.None */);
10041
+ // We assume for simplicity that the parameter signature of the lambda is
10042
+ // the same as the expected type. If this isn't the case, we'll use
10043
+ // object for any lambda parameters that don't match. We could make this
10044
+ // more sophisticated in the future, but it becomes very complex to handle
10045
+ // all of the permutations.
10046
+ let sawParamMismatch = false;
10047
+ node.parameters.forEach((param, index) => {
10048
+ let paramType;
10049
+ if (expectedParamDetails && !sawParamMismatch) {
10050
+ if (index < expectedParamDetails.params.length) {
10051
+ const expectedParam = expectedParamDetails.params[index];
10052
+ // If the parameter category matches and both of the parameters are
10053
+ // either separators (/ or *) or not separators, copy the type
10054
+ // from the expected parameter.
10055
+ if (expectedParam.param.category === param.category &&
10056
+ !param.name === !expectedParam.param.name) {
10057
+ paramType = expectedParam.type;
10058
+ }
10059
+ else {
10060
+ sawParamMismatch = true;
10061
+ }
10080
10062
  }
10081
- else {
10082
- sawParamMismatch = true;
10063
+ else if (param.defaultValue) {
10064
+ // If the lambda param has a default value but there is no associated
10065
+ // parameter in the expected type, assume that the default value is
10066
+ // being used to explicitly capture a value from an outer scope. Infer
10067
+ // its type from the default value expression.
10068
+ paramType = getTypeOfExpression(param.defaultValue, undefined, inferenceContext).type;
10083
10069
  }
10084
10070
  }
10085
10071
  else if (param.defaultValue) {
10086
- // If the lambda param has a default value but there is no associated
10087
- // parameter in the expected type, assume that the default value is
10088
- // being used to explicitly capture a value from an outer scope. Infer
10089
- // its type from the default value expression.
10090
- paramType = getTypeOfExpression(param.defaultValue, undefined, inferenceContext).type;
10091
- }
10092
- }
10093
- else if (param.defaultValue) {
10094
- // If there is no inference context but we have a default value,
10095
- // use the default value to infer the parameter's type.
10096
- paramType = inferParameterTypeFromDefaultValue(param.defaultValue);
10097
- }
10098
- if (param.name) {
10099
- writeTypeCache(param.name, { type: transformVariadicParamType(node, param.category, paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create()) }, 0 /* EvaluatorFlags.None */);
10100
- }
10101
- if (param.defaultValue) {
10102
- // Evaluate the default value if it's present.
10103
- getTypeOfExpression(param.defaultValue, 1 /* EvaluatorFlags.ConvertEllipsisToAny */);
10104
- }
10105
- // Determine whether we need to insert an implied position-only parameter.
10106
- // This is needed when a function's parameters are named using the old-style
10107
- // way of specifying position-only parameters.
10108
- if (index >= 0) {
10109
- let isImplicitPositionOnlyParam = false;
10110
- if (param.category === 0 /* ParameterCategory.Simple */ && param.name) {
10111
- if ((0, symbolNameUtils_1.isPrivateName)(param.name.value)) {
10112
- isImplicitPositionOnlyParam = true;
10072
+ // If there is no inference context but we have a default value,
10073
+ // use the default value to infer the parameter's type.
10074
+ paramType = inferParameterTypeFromDefaultValue(param.defaultValue);
10075
+ }
10076
+ if (param.name) {
10077
+ writeTypeCache(param.name, { type: transformVariadicParamType(node, param.category, paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create()) }, 0 /* EvaluatorFlags.None */);
10078
+ }
10079
+ if (param.defaultValue) {
10080
+ // Evaluate the default value if it's present.
10081
+ getTypeOfExpression(param.defaultValue, 1 /* EvaluatorFlags.ConvertEllipsisToAny */);
10082
+ }
10083
+ // Determine whether we need to insert an implied position-only parameter.
10084
+ // This is needed when a function's parameters are named using the old-style
10085
+ // way of specifying position-only parameters.
10086
+ if (index >= 0) {
10087
+ let isImplicitPositionOnlyParam = false;
10088
+ if (param.category === 0 /* ParameterCategory.Simple */ && param.name) {
10089
+ if ((0, symbolNameUtils_1.isPrivateName)(param.name.value)) {
10090
+ isImplicitPositionOnlyParam = true;
10091
+ }
10092
+ }
10093
+ else {
10094
+ paramsArePositionOnly = false;
10095
+ }
10096
+ if (paramsArePositionOnly &&
10097
+ !isImplicitPositionOnlyParam &&
10098
+ functionType.details.parameters.length > 0) {
10099
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
10100
+ }
10101
+ if (!isImplicitPositionOnlyParam) {
10102
+ paramsArePositionOnly = false;
10113
10103
  }
10114
10104
  }
10115
- else {
10116
- paramsArePositionOnly = false;
10117
- }
10118
- if (paramsArePositionOnly &&
10119
- !isImplicitPositionOnlyParam &&
10120
- functionType.details.parameters.length > 0) {
10121
- types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
10105
+ const functionParam = {
10106
+ category: param.category,
10107
+ name: param.name ? param.name.value : undefined,
10108
+ hasDefault: !!param.defaultValue,
10109
+ defaultValueExpression: param.defaultValue,
10110
+ hasDeclaredType: true,
10111
+ type: paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create(),
10112
+ };
10113
+ types_1.FunctionType.addParameter(functionType, functionParam);
10114
+ });
10115
+ if (paramsArePositionOnly && functionType.details.parameters.length > 0) {
10116
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
10117
+ }
10118
+ let typeErrors = false;
10119
+ // If we're speculatively evaluating the lambda, create another speculative
10120
+ // evaluation scope for the return expression and do not allow retention
10121
+ // of the cached types.
10122
+ // We need to set allowCacheRetention to false because we don't want to
10123
+ // cache the type of the lambda return expression because it depends on
10124
+ // the parameter types that we set above, and the speculative type cache
10125
+ // doesn't know about that context.
10126
+ useSpeculativeMode(forceSpeculative || isSpeculativeModeInUse(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete)
10127
+ ? node.expression
10128
+ : undefined, () => {
10129
+ const returnTypeResult = getTypeOfExpression(node.expression,
10130
+ /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
10131
+ functionType.inferredReturnType = returnTypeResult.type;
10132
+ if (returnTypeResult.isIncomplete) {
10133
+ isIncomplete = true;
10122
10134
  }
10123
- if (!isImplicitPositionOnlyParam) {
10124
- paramsArePositionOnly = false;
10135
+ if (returnTypeResult.typeErrors) {
10136
+ typeErrors = true;
10125
10137
  }
10126
- }
10127
- const functionParam = {
10128
- category: param.category,
10129
- name: param.name ? param.name.value : undefined,
10130
- hasDefault: !!param.defaultValue,
10131
- defaultValueExpression: param.defaultValue,
10132
- hasDeclaredType: true,
10133
- type: paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create(),
10134
- };
10135
- types_1.FunctionType.addParameter(functionType, functionParam);
10136
- });
10137
- if (paramsArePositionOnly && functionType.details.parameters.length > 0) {
10138
- types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
10139
- }
10140
- let typeErrors = false;
10141
- // If we're speculatively evaluating the lambda, create another speculative
10142
- // evaluation scope for the return expression and do not allow retention
10143
- // of the cached types.
10144
- // We need to set allowCacheRetention to false because we don't want to
10145
- // cache the type of the lambda return expression because it depends on
10146
- // the parameter types that we set above, and the speculative type cache
10147
- // doesn't know about that context.
10148
- useSpeculativeMode(forceSpeculative || isSpeculativeModeInUse(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete)
10149
- ? node.expression
10150
- : undefined, () => {
10151
- const returnTypeResult = getTypeOfExpression(node.expression,
10152
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
10153
- functionType.inferredReturnType = returnTypeResult.type;
10154
- if (returnTypeResult.isIncomplete) {
10155
- isIncomplete = true;
10156
- }
10157
- if (returnTypeResult.typeErrors) {
10158
- typeErrors = true;
10159
- }
10160
- else if (expectedReturnType) {
10161
- // If the expectedReturnType is generic, see if the actual return type
10162
- // provides types for some or all type variables.
10163
- if ((0, typeUtils_1.requiresSpecialization)(expectedReturnType)) {
10164
- const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(functionType));
10165
- if (assignType(expectedReturnType, returnTypeResult.type, /* diag */ undefined, typeVarContext)) {
10166
- functionType = (0, typeUtils_1.applySolvedTypeVars)(functionType, typeVarContext, {
10167
- applyInScopePlaceholders: true,
10168
- });
10138
+ else if (expectedReturnType) {
10139
+ // If the expectedReturnType is generic, see if the actual return type
10140
+ // provides types for some or all type variables.
10141
+ if ((0, typeUtils_1.requiresSpecialization)(expectedReturnType)) {
10142
+ const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(functionType));
10143
+ if (assignType(expectedReturnType, returnTypeResult.type,
10144
+ /* diag */ undefined, typeVarContext)) {
10145
+ functionType = (0, typeUtils_1.applySolvedTypeVars)(functionType, typeVarContext, {
10146
+ applyInScopePlaceholders: true,
10147
+ });
10148
+ }
10169
10149
  }
10170
10150
  }
10151
+ }, {
10152
+ dependentType: inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType,
10153
+ allowDiagnostics: !forceSpeculative && !canSkipDiagnosticForNode(node) && !(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete),
10154
+ });
10155
+ // Mark the function type as no longer being evaluated.
10156
+ functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
10157
+ // Is the resulting function compatible with the expected type?
10158
+ if (expectedType && !assignType(expectedType, functionType)) {
10159
+ typeErrors = true;
10171
10160
  }
10172
- }, {
10173
- dependentType: inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType,
10174
- allowDiagnostics: !forceSpeculative && !isDiagnosticSuppressedForNode(node) && !(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete),
10161
+ return { type: functionType, isIncomplete, typeErrors };
10175
10162
  });
10176
- // Mark the function type as no longer being evaluated.
10177
- functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
10178
- // Is the resulting function compatible with the expected type?
10179
- if (expectedType && !assignType(expectedType, functionType)) {
10180
- typeErrors = true;
10181
- }
10182
- return { type: functionType, isIncomplete, typeErrors };
10183
10163
  }
10184
10164
  function getTypeOfComprehension(node, flags, inferenceContext) {
10185
10165
  let isIncomplete = false;
@@ -11256,7 +11236,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11256
11236
  /* declaredMetaclass */ undefined,
11257
11237
  /* effectiveMetaclass */ undefined);
11258
11238
  if (aliasMapEntry.isSpecialForm) {
11259
- specialClassType.details.flags |= -2147483648 /* ClassTypeFlags.SpecialFormClass */;
11239
+ specialClassType.details.flags |= 8388608 /* ClassTypeFlags.SpecialFormClass */;
11260
11240
  }
11261
11241
  // Synthesize a single type parameter with the specified variance if
11262
11242
  // specified in the alias map entry.
@@ -11269,7 +11249,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11269
11249
  const specialBuiltInClassDeclaration = ((_a = AnalyzerNodeInfo.getDeclaration(node)) !== null && _a !== void 0 ? _a : (node.parent ? AnalyzerNodeInfo.getDeclaration(node.parent) : undefined));
11270
11250
  specialClassType.details.declaration = specialBuiltInClassDeclaration;
11271
11251
  if (fileInfo.isTypingExtensionsStubFile) {
11272
- specialClassType.details.flags |= 131072 /* ClassTypeFlags.TypingExtensionClass */;
11252
+ specialClassType.details.flags |= 4096 /* ClassTypeFlags.TypingExtensionClass */;
11273
11253
  }
11274
11254
  const baseClassName = aliasMapEntry.alias || 'object';
11275
11255
  let baseClass;
@@ -11289,7 +11269,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11289
11269
  // cause the TypedDict to be marked as abstract.
11290
11270
  if ((0, types_1.isInstantiableClass)(baseClass) && types_1.ClassType.isBuiltIn(baseClass, '_TypedDict')) {
11291
11271
  baseClass = types_1.ClassType.cloneWithNewFlags(baseClass, baseClass.details.flags &
11292
- ~(2048 /* ClassTypeFlags.SupportsAbstractMethods */ | 268435456 /* ClassTypeFlags.TypeCheckOnly */));
11272
+ ~(64 /* ClassTypeFlags.SupportsAbstractMethods */ | 1048576 /* ClassTypeFlags.TypeCheckOnly */));
11293
11273
  }
11294
11274
  }
11295
11275
  }
@@ -11664,17 +11644,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11664
11644
  fileInfo.isTypeshedStubFile) {
11665
11645
  classFlags |= 1 /* ClassTypeFlags.BuiltInClass */;
11666
11646
  if (fileInfo.isTypingExtensionsStubFile) {
11667
- classFlags |= 131072 /* ClassTypeFlags.TypingExtensionClass */;
11647
+ classFlags |= 4096 /* ClassTypeFlags.TypingExtensionClass */;
11668
11648
  }
11669
11649
  if (node.name.value === 'property') {
11670
- classFlags |= 4096 /* ClassTypeFlags.PropertyClass */;
11650
+ classFlags |= 128 /* ClassTypeFlags.PropertyClass */;
11671
11651
  }
11672
11652
  if (node.name.value === 'tuple') {
11673
- classFlags |= 1048576 /* ClassTypeFlags.TupleClass */;
11653
+ classFlags |= 32768 /* ClassTypeFlags.TupleClass */;
11674
11654
  }
11675
11655
  }
11676
11656
  if (fileInfo.isStubFile) {
11677
- classFlags |= 16777216 /* ClassTypeFlags.DefinedInStub */;
11657
+ classFlags |= 262144 /* ClassTypeFlags.DefinedInStub */;
11678
11658
  }
11679
11659
  const classType = types_1.ClassType.createInstantiable(node.name.value, ParseTreeUtils.getClassFullName(node, fileInfo.moduleName, node.name.value), fileInfo.moduleName, fileInfo.fileUri, classFlags,
11680
11660
  /* typeSourceId */ 0,
@@ -11697,9 +11677,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11697
11677
  if (classDecl && classSymbol) {
11698
11678
  setSymbolResolutionPartialType(classSymbol, classDecl, classType);
11699
11679
  }
11700
- classType.details.flags |= 262144 /* ClassTypeFlags.PartiallyEvaluated */;
11680
+ classType.details.flags |= 8192 /* ClassTypeFlags.PartiallyEvaluated */;
11701
11681
  classType.details.declaration = classDecl;
11702
- try {
11682
+ return (0, cancellationUtils_1.invalidateTypeCacheIfCanceled)(() => {
11703
11683
  writeTypeCache(node, { type: classType }, /* flags */ undefined);
11704
11684
  writeTypeCache(node.name, { type: classType }, /* flags */ undefined);
11705
11685
  // Keep a list of unique type parameters that are used in the
@@ -11783,29 +11763,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11783
11763
  fileInfo.executionEnvironment.pythonVersion.isLessThan(pythonVersion_1.pythonVersion3_7)) {
11784
11764
  addError(localize_1.LocMessage.protocolIllegal(), arg.valueExpression);
11785
11765
  }
11786
- classType.details.flags |= 16384 /* ClassTypeFlags.ProtocolClass */;
11766
+ classType.details.flags |= 512 /* ClassTypeFlags.ProtocolClass */;
11787
11767
  }
11788
11768
  if (types_1.ClassType.isBuiltIn(argType, 'property')) {
11789
- classType.details.flags |= 4096 /* ClassTypeFlags.PropertyClass */;
11769
+ classType.details.flags |= 128 /* ClassTypeFlags.PropertyClass */;
11790
11770
  }
11791
11771
  // If the class directly derives from NamedTuple (in Python 3.6 or
11792
11772
  // newer), it's considered a (read-only) dataclass.
11793
11773
  if (fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(pythonVersion_1.pythonVersion3_6)) {
11794
11774
  if (types_1.ClassType.isBuiltIn(argType, 'NamedTuple')) {
11795
11775
  isNamedTupleSubclass = true;
11796
- classType.details.flags |=
11797
- 4 /* ClassTypeFlags.DataClass */ |
11798
- 32 /* ClassTypeFlags.SkipSynthesizedDataClassEq */ |
11799
- 33554432 /* ClassTypeFlags.ReadOnlyInstanceVariables */;
11776
+ classType.details.flags |= 524288 /* ClassTypeFlags.ReadOnlyInstanceVariables */;
11800
11777
  }
11801
11778
  }
11802
11779
  // If the class directly derives from TypedDict or from a class that is
11803
11780
  // a TypedDict, it is considered a TypedDict.
11804
11781
  if (types_1.ClassType.isBuiltIn(argType, 'TypedDict') || types_1.ClassType.isTypedDictClass(argType)) {
11805
- classType.details.flags |= 128 /* ClassTypeFlags.TypedDictClass */;
11782
+ classType.details.flags |= 4 /* ClassTypeFlags.TypedDictClass */;
11806
11783
  // Propagate the "effectively closed" flag from base classes.
11807
11784
  if (types_1.ClassType.isTypedDictEffectivelyClosed(argType)) {
11808
- classType.details.flags |= 512 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
11785
+ classType.details.flags |= 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
11809
11786
  }
11810
11787
  }
11811
11788
  // Validate that the class isn't deriving from itself, creating a
@@ -11836,7 +11813,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11836
11813
  classType.details.baseClasses.push(argType);
11837
11814
  if ((0, types_1.isInstantiableClass)(argType)) {
11838
11815
  if (types_1.ClassType.isEnumClass(argType)) {
11839
- classType.details.flags |= 2097152 /* ClassTypeFlags.EnumClass */;
11816
+ classType.details.flags |= 65536 /* ClassTypeFlags.EnumClass */;
11840
11817
  }
11841
11818
  // Determine if the class is abstract. Protocol classes support abstract methods
11842
11819
  // because they are constructed by the _ProtocolMeta metaclass, which derives
@@ -11845,10 +11822,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11845
11822
  // because of dependencies on some of these built-in protocol classes.
11846
11823
  if (types_1.ClassType.supportsAbstractMethods(argType) ||
11847
11824
  (types_1.ClassType.isProtocolClass(argType) && !types_1.ClassType.isBuiltIn(argType))) {
11848
- classType.details.flags |= 2048 /* ClassTypeFlags.SupportsAbstractMethods */;
11825
+ classType.details.flags |= 64 /* ClassTypeFlags.SupportsAbstractMethods */;
11849
11826
  }
11850
11827
  if (types_1.ClassType.isPropertyClass(argType)) {
11851
- classType.details.flags |= 4096 /* ClassTypeFlags.PropertyClass */;
11828
+ classType.details.flags |= 128 /* ClassTypeFlags.PropertyClass */;
11852
11829
  }
11853
11830
  if (types_1.ClassType.isFinal(argType)) {
11854
11831
  const className = printObjectTypeForClass(argType);
@@ -11898,13 +11875,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11898
11875
  addError(localize_1.LocMessage.typedDictBoolParam().format({ name: arg.name.value }), arg.valueExpression);
11899
11876
  }
11900
11877
  else if (arg.name.value === 'total' && !constArgValue) {
11901
- classType.details.flags |= 1024 /* ClassTypeFlags.CanOmitDictValues */;
11878
+ classType.details.flags |= 32 /* ClassTypeFlags.CanOmitDictValues */;
11902
11879
  }
11903
11880
  else if (arg.name.value === 'closed' && constArgValue) {
11904
11881
  // This is an experimental feature because PEP 728 hasn't been accepted yet.
11905
11882
  if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
11906
11883
  classType.details.flags |=
11907
- 256 /* ClassTypeFlags.TypedDictMarkedClosed */ | 512 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
11884
+ 8 /* ClassTypeFlags.TypedDictMarkedClosed */ | 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
11908
11885
  }
11909
11886
  }
11910
11887
  }
@@ -12037,7 +12014,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12037
12014
  param.category === 0 /* ParameterCategory.Simple */ &&
12038
12015
  !param.defaultValue);
12039
12016
  if (genericParams.length > 0) {
12040
- classType.details.flags |= 32768 /* ClassTypeFlags.PseudoGenericClass */;
12017
+ classType.details.flags |= 1024 /* ClassTypeFlags.PseudoGenericClass */;
12041
12018
  // Create a type parameter for each simple, named parameter
12042
12019
  // in the __init__ method.
12043
12020
  classType.details.typeParameters = genericParams.map((param) => {
@@ -12058,7 +12035,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12058
12035
  if (classType.details.typeParameters.length === 0 && !types_1.ClassType.isBuiltIn(classType, 'type')) {
12059
12036
  if (classType.details.baseClasses.some((baseClass) => (0, types_1.isInstantiableClass)(baseClass) && types_1.ClassType.hasCustomClassGetItem(baseClass)) ||
12060
12037
  classType.details.fields.has('__class_getitem__')) {
12061
- classType.details.flags |= 524288 /* ClassTypeFlags.HasCustomClassGetItem */;
12038
+ classType.details.flags |= 16384 /* ClassTypeFlags.HasCustomClassGetItem */;
12062
12039
  }
12063
12040
  }
12064
12041
  // Determine the effective metaclass.
@@ -12071,17 +12048,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12071
12048
  classType.details.declaredMetaclass = metaclassType;
12072
12049
  if ((0, types_1.isInstantiableClass)(metaclassType)) {
12073
12050
  if ((0, enums_1.isEnumMetaclass)(metaclassType)) {
12074
- classType.details.flags |= 2097152 /* ClassTypeFlags.EnumClass */;
12051
+ classType.details.flags |= 65536 /* ClassTypeFlags.EnumClass */;
12075
12052
  }
12076
12053
  if (types_1.ClassType.isBuiltIn(metaclassType, 'ABCMeta')) {
12077
- classType.details.flags |= 2048 /* ClassTypeFlags.SupportsAbstractMethods */;
12054
+ classType.details.flags |= 64 /* ClassTypeFlags.SupportsAbstractMethods */;
12078
12055
  }
12079
12056
  }
12080
12057
  }
12081
12058
  }
12082
12059
  const effectiveMetaclass = computeEffectiveMetaclass(classType, node.name);
12083
12060
  // Clear the "partially constructed" flag.
12084
- classType.details.flags &= ~262144 /* ClassTypeFlags.PartiallyEvaluated */;
12061
+ classType.details.flags &= ~8192 /* ClassTypeFlags.PartiallyEvaluated */;
12085
12062
  // Now determine the decorated type of the class.
12086
12063
  let decoratedType = classType;
12087
12064
  let foundUnknown = false;
@@ -12118,7 +12095,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12118
12095
  }
12119
12096
  }
12120
12097
  if (dataClassBehaviors) {
12121
- (0, dataClasses_1.applyDataClassDefaultBehaviors)(classType, dataClassBehaviors);
12122
12098
  (0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, node.name, classType, initSubclassArgs, dataClassBehaviors);
12123
12099
  }
12124
12100
  // Run any deferred class completions that depend on this class.
@@ -12146,8 +12122,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12146
12122
  (0, typedDicts_1.synthesizeTypedDictClassMethods)(evaluatorInterface, node, classType);
12147
12123
  }
12148
12124
  // Synthesize dataclass methods.
12149
- if (types_1.ClassType.isDataClass(classType)) {
12150
- const skipSynthesizedInit = types_1.ClassType.isSkipSynthesizedDataClassInit(classType);
12125
+ if (types_1.ClassType.isDataClass(classType) || isNamedTupleSubclass) {
12126
+ const skipSynthesizedInit = types_1.ClassType.isDataClassSkipGenerateInit(classType);
12151
12127
  let hasExistingInitMethod = skipSynthesizedInit;
12152
12128
  // See if there's already a non-synthesized __init__ method.
12153
12129
  // We shouldn't override it.
@@ -12213,15 +12189,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12213
12189
  // Update the decorated class type.
12214
12190
  writeTypeCache(node, { type: decoratedType }, 0 /* EvaluatorFlags.None */);
12215
12191
  return { classType, decoratedType };
12216
- }
12217
- catch (e) {
12218
- if (cancellationUtils_1.OperationCanceledException.is(e)) {
12219
- // If the work was canceled before the class types were updated, the
12220
- // class type in the type cache is in an invalid, partially-constructed state.
12221
- e.isTypeCacheInvalid = true;
12222
- }
12223
- throw e;
12224
- }
12192
+ });
12225
12193
  }
12226
12194
  // Determines whether the type parameters has a default that refers to another
12227
12195
  // type parameter. If so, validates that it is in the list of "live" type
@@ -12637,7 +12605,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12637
12605
  // Evaluates the type of a "def" statement without applying an async
12638
12606
  // modifier or any decorators.
12639
12607
  function getTypeOfFunctionPredecorated(node) {
12640
- var _a, _b, _c;
12608
+ var _a;
12641
12609
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
12642
12610
  // Is this type already cached?
12643
12611
  const cachedFunctionType = readTypeCache(node.name, 0 /* EvaluatorFlags.None */);
@@ -12692,299 +12660,303 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12692
12660
  if (functionDecl && functionSymbol) {
12693
12661
  setSymbolResolutionPartialType(functionSymbol.symbol, functionDecl, functionType);
12694
12662
  }
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));
12730
- }
12731
- else {
12732
- functionType.details.typeParameters = typeParametersSeen;
12733
- }
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
- }
12757
- }
12758
- if (param.typeAnnotation) {
12759
- paramTypeNode = param.typeAnnotation;
12663
+ return (0, cancellationUtils_1.invalidateTypeCacheIfCanceled)(() => {
12664
+ var _a, _b;
12665
+ writeTypeCache(node.name, { type: functionType }, /* flags */ undefined);
12666
+ // Is this an "__init__" method within a pseudo-generic class? If so,
12667
+ // we'll add generic types to the constructor's parameters.
12668
+ const addGenericParamTypes = containingClassType &&
12669
+ types_1.ClassType.isPseudoGenericClass(containingClassType) &&
12670
+ node.name.value === '__init__';
12671
+ const paramTypes = [];
12672
+ // Determine if the first parameter should be skipped for comment-based
12673
+ // function annotations.
12674
+ let firstCommentAnnotationIndex = 0;
12675
+ if (containingClassType && (functionType.details.flags & 4 /* FunctionTypeFlags.StaticMethod */) === 0) {
12676
+ firstCommentAnnotationIndex = 1;
12677
+ }
12678
+ // If there is a function annotation comment, validate that it has the correct
12679
+ // number of parameter annotations.
12680
+ if (node.functionAnnotationComment && !node.functionAnnotationComment.isParamListEllipsis) {
12681
+ const expected = node.parameters.length - firstCommentAnnotationIndex;
12682
+ const received = node.functionAnnotationComment.paramTypeAnnotations.length;
12683
+ // For methods with "self" or "cls" parameters, the annotation list
12684
+ // can either include or exclude the annotation for the first parameter.
12685
+ if (firstCommentAnnotationIndex > 0 && received === node.parameters.length) {
12686
+ firstCommentAnnotationIndex = 0;
12687
+ }
12688
+ else if (received !== expected) {
12689
+ addError(localize_1.LocMessage.annotatedParamCountMismatch().format({
12690
+ expected,
12691
+ received,
12692
+ }), node.functionAnnotationComment);
12693
+ }
12694
+ }
12695
+ // If this function uses PEP 695 syntax for type parameters,
12696
+ // accumulate the list of type parameters upfront.
12697
+ const typeParametersSeen = [];
12698
+ if (node.typeParameters) {
12699
+ functionType.details.typeParameters = evaluateTypeParameterList(node.typeParameters).map((typeParam) => (0, typeUtils_1.convertToInstance)(typeParam));
12760
12700
  }
12761
- else if (param.typeAnnotationComment) {
12762
- paramTypeNode = param.typeAnnotationComment;
12701
+ else {
12702
+ functionType.details.typeParameters = typeParametersSeen;
12763
12703
  }
12764
- else if (node.functionAnnotationComment && !node.functionAnnotationComment.isParamListEllipsis) {
12765
- const adjustedIndex = index - firstCommentAnnotationIndex;
12766
- if (adjustedIndex >= 0 && adjustedIndex < node.functionAnnotationComment.paramTypeAnnotations.length) {
12767
- paramTypeNode = node.functionAnnotationComment.paramTypeAnnotations[adjustedIndex];
12704
+ let paramsArePositionOnly = true;
12705
+ const isFirstParamClsOrSelf = containingClassType &&
12706
+ (types_1.FunctionType.isClassMethod(functionType) ||
12707
+ types_1.FunctionType.isInstanceMethod(functionType) ||
12708
+ types_1.FunctionType.isConstructorMethod(functionType));
12709
+ const firstNonClsSelfParamIndex = isFirstParamClsOrSelf ? 1 : 0;
12710
+ node.parameters.forEach((param, index) => {
12711
+ let paramType;
12712
+ let annotatedType;
12713
+ let paramTypeNode;
12714
+ if (param.name) {
12715
+ if (index === 0 && isFirstParamClsOrSelf) {
12716
+ // Mark "self/cls" as accessed.
12717
+ markParamAccessed(param);
12718
+ }
12719
+ else if (types_1.FunctionType.isAbstractMethod(functionType)) {
12720
+ // Mark all parameters in abstract methods as accessed.
12721
+ markParamAccessed(param);
12722
+ }
12723
+ else if (containingClassType && types_1.ClassType.isProtocolClass(containingClassType)) {
12724
+ // Mark all parameters in protocol methods as accessed.
12725
+ markParamAccessed(param);
12726
+ }
12768
12727
  }
12769
- }
12770
- if (paramTypeNode) {
12771
- if ((functionInfo.flags & 524288 /* FunctionTypeFlags.NoTypeCheck */) !== 0) {
12772
- annotatedType = types_1.UnknownType.create();
12728
+ if (param.typeAnnotation) {
12729
+ paramTypeNode = param.typeAnnotation;
12773
12730
  }
12774
- else {
12775
- annotatedType = getTypeOfParameterAnnotation(paramTypeNode, param.category);
12731
+ else if (param.typeAnnotationComment) {
12732
+ paramTypeNode = param.typeAnnotationComment;
12776
12733
  }
12777
- if (annotatedType) {
12778
- (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(annotatedType), functionType.details.typeVarScopeId);
12779
- }
12780
- if ((0, types_1.isVariadicTypeVar)(annotatedType) && !annotatedType.isVariadicUnpacked) {
12781
- addError(localize_1.LocMessage.unpackedTypeVarTupleExpected().format({
12782
- name1: annotatedType.details.name,
12783
- name2: annotatedType.details.name,
12784
- }), paramTypeNode);
12785
- annotatedType = types_1.UnknownType.create();
12734
+ else if (node.functionAnnotationComment && !node.functionAnnotationComment.isParamListEllipsis) {
12735
+ const adjustedIndex = index - firstCommentAnnotationIndex;
12736
+ if (adjustedIndex >= 0 &&
12737
+ adjustedIndex < node.functionAnnotationComment.paramTypeAnnotations.length) {
12738
+ paramTypeNode = node.functionAnnotationComment.paramTypeAnnotations[adjustedIndex];
12739
+ }
12786
12740
  }
12787
- }
12788
- if (!annotatedType && addGenericParamTypes) {
12789
- if (index > 0 && param.category === 0 /* ParameterCategory.Simple */ && param.name && !param.defaultValue) {
12790
- const typeParamName = getPseudoGenericTypeVarName(param.name.value);
12791
- annotatedType = containingClassType.details.typeParameters.find((param) => param.details.name === typeParamName);
12741
+ if (paramTypeNode) {
12742
+ if ((functionInfo.flags & 524288 /* FunctionTypeFlags.NoTypeCheck */) !== 0) {
12743
+ annotatedType = types_1.UnknownType.create();
12744
+ }
12745
+ else {
12746
+ annotatedType = getTypeOfParameterAnnotation(paramTypeNode, param.category);
12747
+ }
12748
+ if (annotatedType) {
12749
+ (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(annotatedType), functionType.details.typeVarScopeId);
12750
+ }
12751
+ if ((0, types_1.isVariadicTypeVar)(annotatedType) && !annotatedType.isVariadicUnpacked) {
12752
+ addError(localize_1.LocMessage.unpackedTypeVarTupleExpected().format({
12753
+ name1: annotatedType.details.name,
12754
+ name2: annotatedType.details.name,
12755
+ }), paramTypeNode);
12756
+ annotatedType = types_1.UnknownType.create();
12757
+ }
12792
12758
  }
12793
- }
12794
- if (annotatedType) {
12795
- const adjustedAnnotatedType = adjustParameterAnnotatedType(param, annotatedType);
12796
- if (adjustedAnnotatedType !== annotatedType) {
12797
- annotatedType = adjustedAnnotatedType;
12759
+ if (!annotatedType && addGenericParamTypes) {
12760
+ if (index > 0 && param.category === 0 /* ParameterCategory.Simple */ && param.name && !param.defaultValue) {
12761
+ const typeParamName = getPseudoGenericTypeVarName(param.name.value);
12762
+ annotatedType = containingClassType.details.typeParameters.find((param) => param.details.name === typeParamName);
12763
+ }
12798
12764
  }
12799
- }
12800
- let defaultValueType;
12801
- if (param.defaultValue) {
12802
- // If this is a stub file, a protocol, an overload, or a class
12803
- // whose body is a placeholder implementation, treat a "...", as
12804
- // an "Any" value.
12805
- let treatEllipsisAsAny = fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.suite);
12806
- if (containingClassType && types_1.ClassType.isProtocolClass(containingClassType)) {
12807
- treatEllipsisAsAny = true;
12765
+ if (annotatedType) {
12766
+ const adjustedAnnotatedType = adjustParameterAnnotatedType(param, annotatedType);
12767
+ if (adjustedAnnotatedType !== annotatedType) {
12768
+ annotatedType = adjustedAnnotatedType;
12769
+ }
12808
12770
  }
12809
- if (types_1.FunctionType.isOverloaded(functionType) || types_1.FunctionType.isAbstractMethod(functionType)) {
12810
- treatEllipsisAsAny = true;
12771
+ let defaultValueType;
12772
+ if (param.defaultValue) {
12773
+ // If this is a stub file, a protocol, an overload, or a class
12774
+ // whose body is a placeholder implementation, treat a "...", as
12775
+ // an "Any" value.
12776
+ let treatEllipsisAsAny = fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.suite);
12777
+ if (containingClassType && types_1.ClassType.isProtocolClass(containingClassType)) {
12778
+ treatEllipsisAsAny = true;
12779
+ }
12780
+ if (types_1.FunctionType.isOverloaded(functionType) || types_1.FunctionType.isAbstractMethod(functionType)) {
12781
+ treatEllipsisAsAny = true;
12782
+ }
12783
+ defaultValueType = getTypeOfExpression(param.defaultValue, treatEllipsisAsAny ? 1 /* EvaluatorFlags.ConvertEllipsisToAny */ : 0 /* EvaluatorFlags.None */, (0, typeUtils_1.makeInferenceContext)(annotatedType)).type;
12811
12784
  }
12812
- defaultValueType = getTypeOfExpression(param.defaultValue, treatEllipsisAsAny ? 1 /* EvaluatorFlags.ConvertEllipsisToAny */ : 0 /* EvaluatorFlags.None */, (0, typeUtils_1.makeInferenceContext)(annotatedType)).type;
12813
- }
12814
- if (annotatedType) {
12815
- // If there was both a type annotation and a default value, verify
12816
- // that the default value matches the annotation.
12817
- if (param.defaultValue && defaultValueType) {
12818
- const diagAddendum = new diagnostic_1.DiagnosticAddendum();
12819
- const typeVarContext = new typeVarContext_1.TypeVarContext(functionType.details.typeVarScopeId);
12820
- if (containingClassType && containingClassType.details.typeVarScopeId !== undefined) {
12821
- if (node.name.value === '__init__' || node.name.value === '__new__') {
12822
- typeVarContext.addSolveForScope(containingClassType.details.typeVarScopeId);
12785
+ if (annotatedType) {
12786
+ // If there was both a type annotation and a default value, verify
12787
+ // that the default value matches the annotation.
12788
+ if (param.defaultValue && defaultValueType) {
12789
+ const diagAddendum = new diagnostic_1.DiagnosticAddendum();
12790
+ const typeVarContext = new typeVarContext_1.TypeVarContext(functionType.details.typeVarScopeId);
12791
+ if (containingClassType && containingClassType.details.typeVarScopeId !== undefined) {
12792
+ if (node.name.value === '__init__' || node.name.value === '__new__') {
12793
+ typeVarContext.addSolveForScope(containingClassType.details.typeVarScopeId);
12794
+ }
12795
+ }
12796
+ if (!assignType(annotatedType, defaultValueType, diagAddendum, typeVarContext)) {
12797
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportArgumentType, localize_1.LocMessage.paramAssignmentMismatch().format({
12798
+ sourceType: printType(defaultValueType),
12799
+ paramType: printType(annotatedType),
12800
+ }) + diagAddendum.getString(), param.defaultValue);
12823
12801
  }
12824
12802
  }
12825
- if (!assignType(annotatedType, defaultValueType, diagAddendum, typeVarContext)) {
12826
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportArgumentType, localize_1.LocMessage.paramAssignmentMismatch().format({
12827
- sourceType: printType(defaultValueType),
12828
- paramType: printType(annotatedType),
12829
- }) + diagAddendum.getString(), param.defaultValue);
12830
- }
12831
- }
12832
- paramType = annotatedType;
12833
- }
12834
- // Determine whether we need to insert an implied position-only parameter.
12835
- // This is needed when a function's parameters are named using the old-style
12836
- // way of specifying position-only parameters.
12837
- if (index >= firstNonClsSelfParamIndex) {
12838
- let isImplicitPositionOnlyParam = false;
12839
- if (param.category === 0 /* ParameterCategory.Simple */ && param.name) {
12840
- if ((0, symbolNameUtils_1.isPrivateName)(param.name.value) &&
12841
- !node.parameters.some((p) => p.category === 0 /* ParameterCategory.Simple */ && !p.name)) {
12842
- isImplicitPositionOnlyParam = true;
12843
- // If the parameter name indicates an implicit position-only parameter
12844
- // but we have already seen non-position-only parameters, report an error.
12845
- if (!paramsArePositionOnly &&
12846
- functionType.details.parameters.every((p) => p.category === 0 /* ParameterCategory.Simple */)) {
12847
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.positionOnlyAfterNon(), param.name);
12803
+ paramType = annotatedType;
12804
+ }
12805
+ // Determine whether we need to insert an implied position-only parameter.
12806
+ // This is needed when a function's parameters are named using the old-style
12807
+ // way of specifying position-only parameters.
12808
+ if (index >= firstNonClsSelfParamIndex) {
12809
+ let isImplicitPositionOnlyParam = false;
12810
+ if (param.category === 0 /* ParameterCategory.Simple */ && param.name) {
12811
+ if ((0, symbolNameUtils_1.isPrivateName)(param.name.value) &&
12812
+ !node.parameters.some((p) => p.category === 0 /* ParameterCategory.Simple */ && !p.name)) {
12813
+ isImplicitPositionOnlyParam = true;
12814
+ // If the parameter name indicates an implicit position-only parameter
12815
+ // but we have already seen non-position-only parameters, report an error.
12816
+ if (!paramsArePositionOnly &&
12817
+ functionType.details.parameters.every((p) => p.category === 0 /* ParameterCategory.Simple */)) {
12818
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.positionOnlyAfterNon(), param.name);
12819
+ }
12848
12820
  }
12849
12821
  }
12822
+ else {
12823
+ paramsArePositionOnly = false;
12824
+ }
12825
+ if (paramsArePositionOnly &&
12826
+ !isImplicitPositionOnlyParam &&
12827
+ functionType.details.parameters.length > firstNonClsSelfParamIndex) {
12828
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
12829
+ }
12830
+ if (!isImplicitPositionOnlyParam) {
12831
+ paramsArePositionOnly = false;
12832
+ }
12833
+ }
12834
+ // If there was no annotation for the parameter, infer its type if possible.
12835
+ let isTypeInferred = false;
12836
+ if (!paramTypeNode) {
12837
+ isTypeInferred = true;
12838
+ const inferredType = inferParameterType(node, functionType.details.flags, index, containingClassType);
12839
+ if (inferredType) {
12840
+ paramType = inferredType;
12841
+ }
12842
+ }
12843
+ const functionParam = {
12844
+ category: param.category,
12845
+ name: param.name ? param.name.value : undefined,
12846
+ hasDefault: !!param.defaultValue,
12847
+ defaultValueExpression: param.defaultValue,
12848
+ defaultType: defaultValueType,
12849
+ type: paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create(),
12850
+ typeAnnotation: paramTypeNode,
12851
+ hasDeclaredType: !!paramTypeNode,
12852
+ isTypeInferred,
12853
+ };
12854
+ types_1.FunctionType.addParameter(functionType, functionParam);
12855
+ if (functionParam.hasDeclaredType) {
12856
+ (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionParam.type), functionType.details.typeVarScopeId);
12857
+ }
12858
+ if (param.name) {
12859
+ const variadicParamType = transformVariadicParamType(node, param.category, functionParam.type);
12860
+ paramTypes.push(variadicParamType);
12850
12861
  }
12851
12862
  else {
12852
- paramsArePositionOnly = false;
12863
+ paramTypes.push(functionParam.type);
12853
12864
  }
12854
- if (paramsArePositionOnly &&
12855
- !isImplicitPositionOnlyParam &&
12856
- functionType.details.parameters.length > firstNonClsSelfParamIndex) {
12857
- types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
12865
+ });
12866
+ if (paramsArePositionOnly && functionType.details.parameters.length > firstNonClsSelfParamIndex) {
12867
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
12868
+ }
12869
+ // Update the types for the nodes associated with the parameters.
12870
+ paramTypes.forEach((paramType, index) => {
12871
+ const paramNameNode = node.parameters[index].name;
12872
+ if (paramNameNode) {
12873
+ if ((0, types_1.isUnknown)(paramType)) {
12874
+ functionType.details.flags |= 16384 /* FunctionTypeFlags.UnannotatedParams */;
12875
+ }
12876
+ writeTypeCache(paramNameNode, { type: paramType }, 0 /* EvaluatorFlags.None */);
12858
12877
  }
12859
- if (!isImplicitPositionOnlyParam) {
12860
- paramsArePositionOnly = false;
12861
- }
12862
- }
12863
- // If there was no annotation for the parameter, infer its type if possible.
12864
- let isTypeInferred = false;
12865
- if (!paramTypeNode) {
12866
- isTypeInferred = true;
12867
- const inferredType = inferParameterType(node, functionType.details.flags, index, containingClassType);
12868
- if (inferredType) {
12869
- paramType = inferredType;
12870
- }
12871
- }
12872
- const functionParam = {
12873
- category: param.category,
12874
- name: param.name ? param.name.value : undefined,
12875
- hasDefault: !!param.defaultValue,
12876
- defaultValueExpression: param.defaultValue,
12877
- defaultType: defaultValueType,
12878
- type: paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create(),
12879
- typeAnnotation: paramTypeNode,
12880
- hasDeclaredType: !!paramTypeNode,
12881
- isTypeInferred,
12882
- };
12883
- types_1.FunctionType.addParameter(functionType, functionParam);
12884
- if (functionParam.hasDeclaredType) {
12885
- (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionParam.type), functionType.details.typeVarScopeId);
12878
+ });
12879
+ // If the function ends in P.args and P.kwargs parameters, make it exempt from
12880
+ // args/kwargs compatibility checks. This is important for protocol comparisons.
12881
+ if (paramTypes.length >= 2) {
12882
+ const paramType1 = paramTypes[paramTypes.length - 2];
12883
+ const paramType2 = paramTypes[paramTypes.length - 1];
12884
+ if ((0, types_1.isParamSpec)(paramType1) &&
12885
+ paramType1.paramSpecAccess === 'args' &&
12886
+ (0, types_1.isParamSpec)(paramType2) &&
12887
+ paramType2.paramSpecAccess === 'kwargs') {
12888
+ functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
12889
+ }
12890
+ }
12891
+ // If the function contains an *args and a **kwargs parameter and both
12892
+ // are annotated as Any or are unannotated, make it exempt from
12893
+ // args/kwargs compatibility checks.
12894
+ const variadicsWithAnyType = functionType.details.parameters.filter((param) => param.category !== 0 /* ParameterCategory.Simple */ && param.name && (0, types_1.isAnyOrUnknown)(param.type));
12895
+ if (variadicsWithAnyType.length >= 2) {
12896
+ functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
12886
12897
  }
12887
- if (param.name) {
12888
- const variadicParamType = transformVariadicParamType(node, param.category, functionParam.type);
12889
- paramTypes.push(variadicParamType);
12898
+ // If there was a defined return type, analyze that first so when we
12899
+ // walk the contents of the function, return statements can be
12900
+ // validated against this type.
12901
+ const returnTypeAnnotationNode = (_a = node.returnTypeAnnotation) !== null && _a !== void 0 ? _a : (_b = node.functionAnnotationComment) === null || _b === void 0 ? void 0 : _b.returnTypeAnnotation;
12902
+ if (returnTypeAnnotationNode) {
12903
+ // Temporarily set the return type to unknown in case of recursion.
12904
+ functionType.details.declaredReturnType = types_1.UnknownType.create();
12905
+ const returnType = getTypeOfAnnotation(returnTypeAnnotationNode, {
12906
+ associateTypeVarsWithScope: true,
12907
+ });
12908
+ functionType.details.declaredReturnType = returnType;
12890
12909
  }
12891
12910
  else {
12892
- paramTypes.push(functionParam.type);
12893
- }
12894
- });
12895
- if (paramsArePositionOnly && functionType.details.parameters.length > firstNonClsSelfParamIndex) {
12896
- types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
12897
- }
12898
- // Update the types for the nodes associated with the parameters.
12899
- paramTypes.forEach((paramType, index) => {
12900
- const paramNameNode = node.parameters[index].name;
12901
- if (paramNameNode) {
12902
- if ((0, types_1.isUnknown)(paramType)) {
12903
- functionType.details.flags |= 16384 /* FunctionTypeFlags.UnannotatedParams */;
12911
+ // If there was no return type annotation and this is a type stub,
12912
+ // we have no opportunity to infer the return type, so we'll indicate
12913
+ // that it's unknown.
12914
+ if (fileInfo.isStubFile) {
12915
+ // Special-case the __init__ method, which is commonly left without
12916
+ // an annotated return type, but we can assume it returns None.
12917
+ if (node.name.value === '__init__') {
12918
+ functionType.details.declaredReturnType = getNoneType();
12919
+ }
12920
+ else {
12921
+ functionType.details.declaredReturnType = types_1.UnknownType.create();
12922
+ }
12904
12923
  }
12905
- writeTypeCache(paramNameNode, { type: paramType }, 0 /* EvaluatorFlags.None */);
12906
12924
  }
12907
- });
12908
- // If the function ends in P.args and P.kwargs parameters, make it exempt from
12909
- // args/kwargs compatibility checks. This is important for protocol comparisons.
12910
- if (paramTypes.length >= 2) {
12911
- const paramType1 = paramTypes[paramTypes.length - 2];
12912
- const paramType2 = paramTypes[paramTypes.length - 1];
12913
- if ((0, types_1.isParamSpec)(paramType1) &&
12914
- paramType1.paramSpecAccess === 'args' &&
12915
- (0, types_1.isParamSpec)(paramType2) &&
12916
- paramType2.paramSpecAccess === 'kwargs') {
12917
- functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
12925
+ // Accumulate any type parameters used in the return type.
12926
+ if (functionType.details.declaredReturnType && returnTypeAnnotationNode) {
12927
+ (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionType.details.declaredReturnType), functionType.details.typeVarScopeId);
12918
12928
  }
12919
- }
12920
- // If the function contains an *args and a **kwargs parameter and both
12921
- // are annotated as Any or are unannotated, make it exempt from
12922
- // args/kwargs compatibility checks.
12923
- const variadicsWithAnyType = functionType.details.parameters.filter((param) => param.category !== 0 /* ParameterCategory.Simple */ && param.name && (0, types_1.isAnyOrUnknown)(param.type));
12924
- if (variadicsWithAnyType.length >= 2) {
12925
- functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
12926
- }
12927
- // If there was a defined return type, analyze that first so when we
12928
- // walk the contents of the function, return statements can be
12929
- // validated against this type.
12930
- const returnTypeAnnotationNode = (_b = node.returnTypeAnnotation) !== null && _b !== void 0 ? _b : (_c = node.functionAnnotationComment) === null || _c === void 0 ? void 0 : _c.returnTypeAnnotation;
12931
- if (returnTypeAnnotationNode) {
12932
- // Temporarily set the return type to unknown in case of recursion.
12933
- functionType.details.declaredReturnType = types_1.UnknownType.create();
12934
- const returnType = getTypeOfAnnotation(returnTypeAnnotationNode, {
12935
- associateTypeVarsWithScope: true,
12936
- });
12937
- functionType.details.declaredReturnType = returnType;
12938
- }
12939
- else {
12940
- // If there was no return type annotation and this is a type stub,
12941
- // we have no opportunity to infer the return type, so we'll indicate
12942
- // that it's unknown.
12943
- if (fileInfo.isStubFile) {
12944
- // Special-case the __init__ method, which is commonly left without
12945
- // an annotated return type, but we can assume it returns None.
12946
- if (node.name.value === '__init__') {
12947
- functionType.details.declaredReturnType = getNoneType();
12948
- }
12949
- else {
12950
- functionType.details.declaredReturnType = types_1.UnknownType.create();
12929
+ // If the return type is explicitly annotated as a generator, mark the
12930
+ // function as a generator even though it may not contain a "yield" statement.
12931
+ // This is important for generator functions declared in stub files, abstract
12932
+ // methods or protocol definitions.
12933
+ if (fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.suite)) {
12934
+ if (functionType.details.declaredReturnType &&
12935
+ (0, types_1.isClassInstance)(functionType.details.declaredReturnType) &&
12936
+ types_1.ClassType.isBuiltIn(functionType.details.declaredReturnType, [
12937
+ 'Generator',
12938
+ 'AsyncGenerator',
12939
+ 'AwaitableGenerator',
12940
+ ])) {
12941
+ functionType.details.flags |= 16 /* FunctionTypeFlags.Generator */;
12951
12942
  }
12952
12943
  }
12953
- }
12954
- // Accumulate any type parameters used in the return type.
12955
- if (functionType.details.declaredReturnType && returnTypeAnnotationNode) {
12956
- (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionType.details.declaredReturnType), functionType.details.typeVarScopeId);
12957
- }
12958
- // If the return type is explicitly annotated as a generator, mark the
12959
- // function as a generator even though it may not contain a "yield" statement.
12960
- // This is important for generator functions declared in stub files, abstract
12961
- // methods or protocol definitions.
12962
- if (fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.suite)) {
12963
- if (functionType.details.declaredReturnType &&
12964
- (0, types_1.isClassInstance)(functionType.details.declaredReturnType) &&
12965
- types_1.ClassType.isBuiltIn(functionType.details.declaredReturnType, [
12966
- 'Generator',
12967
- 'AsyncGenerator',
12968
- 'AwaitableGenerator',
12969
- ])) {
12970
- functionType.details.flags |= 16 /* FunctionTypeFlags.Generator */;
12971
- }
12972
- }
12973
- // Validate the default types for all type parameters.
12974
- functionType.details.typeParameters.forEach((typeParam, index) => {
12975
- var _a;
12976
- let bestErrorNode = node.name;
12977
- if (node.typeParameters && index < node.typeParameters.parameters.length) {
12978
- const typeParamNode = node.typeParameters.parameters[index];
12979
- bestErrorNode = (_a = typeParamNode.defaultExpression) !== null && _a !== void 0 ? _a : typeParamNode.name;
12980
- }
12981
- validateTypeParameterDefault(bestErrorNode, typeParam, functionType.details.typeParameters.slice(0, index), functionType.details.typeVarScopeId);
12944
+ // Validate the default types for all type parameters.
12945
+ functionType.details.typeParameters.forEach((typeParam, index) => {
12946
+ var _a;
12947
+ let bestErrorNode = node.name;
12948
+ if (node.typeParameters && index < node.typeParameters.parameters.length) {
12949
+ const typeParamNode = node.typeParameters.parameters[index];
12950
+ bestErrorNode = (_a = typeParamNode.defaultExpression) !== null && _a !== void 0 ? _a : typeParamNode.name;
12951
+ }
12952
+ validateTypeParameterDefault(bestErrorNode, typeParam, functionType.details.typeParameters.slice(0, index), functionType.details.typeVarScopeId);
12953
+ });
12954
+ // Clear the "partially evaluated" flag to indicate that the functionType
12955
+ // is fully evaluated.
12956
+ functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
12957
+ writeTypeCache(node.name, { type: functionType }, 0 /* EvaluatorFlags.None */);
12958
+ return functionType;
12982
12959
  });
12983
- // Clear the "partially evaluated" flag to indicate that the functionType
12984
- // is fully evaluated.
12985
- functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
12986
- writeTypeCache(node.name, { type: functionType }, 0 /* EvaluatorFlags.None */);
12987
- return functionType;
12988
12960
  }
12989
12961
  function markParamAccessed(param) {
12990
12962
  if (param.name) {
@@ -13297,8 +13269,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13297
13269
  const iteratorTypeResult = getTypeOfExpression(yieldNode.expression);
13298
13270
  if ((0, types_1.isClassInstance)(iteratorTypeResult.type) &&
13299
13271
  types_1.ClassType.isBuiltIn(iteratorTypeResult.type, 'Coroutine')) {
13272
+ const yieldType = iteratorTypeResult.type.typeArguments &&
13273
+ iteratorTypeResult.type.typeArguments.length > 0
13274
+ ? iteratorTypeResult.type.typeArguments[0]
13275
+ : types_1.UnknownType.create();
13300
13276
  // Handle old-style (pre-await) Coroutines.
13301
- inferredYieldTypes.push();
13277
+ inferredYieldTypes.push(yieldType);
13302
13278
  useAwaitableGenerator = true;
13303
13279
  }
13304
13280
  else {
@@ -13324,9 +13300,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13324
13300
  }
13325
13301
  });
13326
13302
  }
13327
- if (inferredYieldTypes.length === 0) {
13328
- inferredYieldTypes.push(getNoneType());
13329
- }
13330
13303
  const inferredYieldType = (0, types_1.combineTypes)(inferredYieldTypes);
13331
13304
  // Inferred yield types need to be wrapped in a Generator or
13332
13305
  // AwaitableGenerator to produce the final result.
@@ -14231,7 +14204,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14231
14204
  }
14232
14205
  }
14233
14206
  // Allocate a new code flow analyzer.
14234
- const analyzer = codeFlowEngine.createCodeFlowAnalyzer(typeAtStart);
14207
+ const analyzer = codeFlowEngine.createCodeFlowAnalyzer();
14235
14208
  if (entries) {
14236
14209
  entries.push({ typeAtStart, codeFlowAnalyzer: analyzer });
14237
14210
  }
@@ -14324,6 +14297,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14324
14297
  0) {
14325
14298
  addError(localize_1.LocMessage.protocolNotAllowed(), errorNode);
14326
14299
  }
14300
+ typeArgs === null || typeArgs === void 0 ? void 0 : typeArgs.forEach((typeArg) => {
14301
+ if (typeArg.typeList || !(0, types_1.isTypeVar)(typeArg.type)) {
14302
+ addError(localize_1.LocMessage.protocolTypeArgMustBeTypeParam(), typeArg.node);
14303
+ }
14304
+ });
14327
14305
  return {
14328
14306
  type: createSpecialType(classType, typeArgs,
14329
14307
  /* paramLimit */ undefined,
@@ -14442,18 +14420,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14442
14420
  if (firstDefaultParamIndex >= 0) {
14443
14421
  minTypeArgCount = firstDefaultParamIndex;
14444
14422
  }
14445
- // Classes that accept inlined type dict type args allow only one.
14446
- if (typeArgs[0].inlinedTypeDict) {
14447
- if (typeArgs.length > 1) {
14448
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.typeArgsTooMany().format({
14449
- name: classType.aliasName || classType.details.name,
14450
- expected: 1,
14451
- received: typeArgCount,
14452
- }), typeArgs[1].node);
14453
- }
14454
- return { type: typeArgs[0].inlinedTypeDict };
14455
- }
14456
- else if (typeArgCount > typeParameters.length) {
14423
+ if (typeArgCount > typeParameters.length) {
14457
14424
  if (!types_1.ClassType.isPartiallyEvaluated(classType) && !types_1.ClassType.isTupleClass(classType)) {
14458
14425
  if (typeParameters.length === 0) {
14459
14426
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.typeArgsExpectingNone().format({
@@ -14836,11 +14803,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14836
14803
  return symbolWithScope;
14837
14804
  }
14838
14805
  // Disables recording of errors and warnings.
14839
- function suppressDiagnostics(node, callback) {
14840
- suppressedNodeStack.push(node);
14806
+ function suppressDiagnostics(node, callback, diagCallback) {
14807
+ suppressedNodeStack.push({ node, suppressedDiags: diagCallback ? [] : undefined });
14841
14808
  try {
14842
14809
  const result = callback();
14843
- suppressedNodeStack.pop();
14810
+ const poppedNode = suppressedNodeStack.pop();
14811
+ if (diagCallback && (poppedNode === null || poppedNode === void 0 ? void 0 : poppedNode.suppressedDiags)) {
14812
+ diagCallback(poppedNode.suppressedDiags);
14813
+ }
14844
14814
  return result;
14845
14815
  }
14846
14816
  catch (e) {
@@ -16087,7 +16057,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16087
16057
  const prevTypeCache = returnTypeInferenceTypeCache;
16088
16058
  returnTypeInferenceContextStack.push({
16089
16059
  functionNode,
16090
- codeFlowAnalyzer: codeFlowEngine.createCodeFlowAnalyzer(/* typeAtStart */ undefined),
16060
+ codeFlowAnalyzer: codeFlowEngine.createCodeFlowAnalyzer(),
16091
16061
  });
16092
16062
  try {
16093
16063
  returnTypeInferenceTypeCache = new Map();
@@ -16397,7 +16367,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16397
16367
  let flags = 0 /* AssignTypeFlags.Default */;
16398
16368
  if ((primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* DeclarationType.Variable */ &&
16399
16369
  !isFinalVariableDeclaration(primaryDecl) &&
16400
- !types_1.ClassType.isFrozenDataClass(destType)) {
16370
+ !types_1.ClassType.isDataClassFrozen(destType)) {
16401
16371
  // Class and instance variables that are mutable need to
16402
16372
  // enforce invariance. We will exempt variables that are
16403
16373
  // private or protected, since these are presumably
@@ -16500,6 +16470,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16500
16470
  while (destTypeArgs.length > srcTypeArgs.length && destTypeArgs[destTypeArgs.length - 1].isOptional) {
16501
16471
  destTypeArgs.splice(destTypeArgs.length - 1, 1);
16502
16472
  }
16473
+ const srcArgsToCapture = srcTypeArgs.length - destTypeArgs.length + 1;
16474
+ let skipAdjustSrc = false;
16503
16475
  // If we're doing reverse type mappings and the source contains a variadic
16504
16476
  // TypeVar, we need to adjust the dest so the reverse type mapping assignment
16505
16477
  // can be performed.
@@ -16525,10 +16497,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16525
16497
  isUnbounded: false,
16526
16498
  });
16527
16499
  }
16500
+ skipAdjustSrc = true;
16528
16501
  }
16529
16502
  }
16530
16503
  else {
16531
- const srcArgsToCapture = srcTypeArgs.length - destTypeArgs.length + 1;
16532
16504
  if (destUnboundedOrVariadicIndex >= 0 && srcArgsToCapture >= 0) {
16533
16505
  // If the dest contains a variadic element, determine which source
16534
16506
  // args map to this element and package them up into an unpacked tuple.
@@ -16557,30 +16529,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16557
16529
  isUnbounded: false,
16558
16530
  });
16559
16531
  }
16532
+ skipAdjustSrc = true;
16560
16533
  }
16561
- else {
16562
- // If possible, package up the source entries that correspond to
16563
- // the dest unbounded tuple. This isn't possible if the source contains
16564
- // an unbounded tuple outside of this range.
16565
- if (srcUnboundedIndex < 0 ||
16566
- (srcUnboundedIndex >= destUnboundedOrVariadicIndex &&
16567
- srcUnboundedIndex < destUnboundedOrVariadicIndex + srcArgsToCapture)) {
16568
- const removedArgTypes = srcTypeArgs
16569
- .splice(destUnboundedOrVariadicIndex, srcArgsToCapture)
16570
- .map((t) => {
16571
- if ((0, types_1.isTypeVar)(t.type) &&
16572
- (0, types_1.isUnpackedVariadicTypeVar)(t.type) &&
16573
- !t.type.isVariadicInUnion) {
16574
- return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
16575
- }
16576
- return t.type;
16577
- });
16578
- srcTypeArgs.splice(destUnboundedOrVariadicIndex, 0, {
16579
- type: removedArgTypes.length > 0 ? (0, types_1.combineTypes)(removedArgTypes) : types_1.AnyType.create(),
16580
- isUnbounded: false,
16581
- });
16534
+ }
16535
+ }
16536
+ if (!skipAdjustSrc && destUnboundedOrVariadicIndex >= 0 && srcArgsToCapture >= 0) {
16537
+ // If possible, package up the source entries that correspond to
16538
+ // the dest unbounded tuple. This isn't possible if the source contains
16539
+ // an unbounded tuple outside of this range.
16540
+ if (srcUnboundedIndex < 0 ||
16541
+ (srcUnboundedIndex >= destUnboundedOrVariadicIndex &&
16542
+ srcUnboundedIndex < destUnboundedOrVariadicIndex + srcArgsToCapture)) {
16543
+ const removedArgTypes = srcTypeArgs.splice(destUnboundedOrVariadicIndex, srcArgsToCapture).map((t) => {
16544
+ if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedVariadicTypeVar)(t.type) && !t.type.isVariadicInUnion) {
16545
+ return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
16582
16546
  }
16583
- }
16547
+ return t.type;
16548
+ });
16549
+ srcTypeArgs.splice(destUnboundedOrVariadicIndex, 0, {
16550
+ type: removedArgTypes.length > 0 ? (0, types_1.combineTypes)(removedArgTypes) : types_1.AnyType.create(),
16551
+ isUnbounded: false,
16552
+ });
16584
16553
  }
16585
16554
  }
16586
16555
  return destTypeArgs.length === srcTypeArgs.length;
@@ -19221,7 +19190,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19221
19190
  // evaluating (and caching) the inferred return type if there is no defined return type.
19222
19191
  getFunctionEffectiveReturnType(memberType);
19223
19192
  const specializedFunction = (0, typeUtils_1.applySolvedTypeVars)(memberType, typeVarContext);
19224
- return types_1.FunctionType.clone(specializedFunction, stripFirstParam, baseType, (0, typeUtils_1.getTypeVarScopeId)(baseType));
19193
+ // If this is a constructor method, provide the base type's TypeVar scope ID
19194
+ // so any TypeVars in this type can be solved.
19195
+ let baseTypeTypeVarScopeId;
19196
+ if (types_1.FunctionType.isConstructorMethod(specializedFunction) || specializedFunction.details.name === '__init__') {
19197
+ baseTypeTypeVarScopeId = (0, typeUtils_1.getTypeVarScopeId)(baseType);
19198
+ }
19199
+ return types_1.FunctionType.clone(specializedFunction, stripFirstParam, baseType, baseTypeTypeVarScopeId);
19225
19200
  }
19226
19201
  function isFinalVariable(symbol) {
19227
19202
  return symbol.getDeclarations().some((decl) => isFinalVariableDeclaration(decl));