@zzzen/pyright-internal 1.2.0-dev.20250216 → 1.2.0-dev.20250302

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 (96) hide show
  1. package/dist/analyzer/backgroundAnalysisProgram.d.ts +4 -4
  2. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  3. package/dist/analyzer/cacheManager.d.ts +5 -2
  4. package/dist/analyzer/cacheManager.js +1 -0
  5. package/dist/analyzer/cacheManager.js.map +1 -1
  6. package/dist/analyzer/checker.js +170 -163
  7. package/dist/analyzer/checker.js.map +1 -1
  8. package/dist/analyzer/constructorTransform.js +1 -1
  9. package/dist/analyzer/constructorTransform.js.map +1 -1
  10. package/dist/analyzer/constructors.js +1 -1
  11. package/dist/analyzer/constructors.js.map +1 -1
  12. package/dist/analyzer/parameterUtils.js +1 -1
  13. package/dist/analyzer/parameterUtils.js.map +1 -1
  14. package/dist/analyzer/parseTreeUtils.d.ts +2 -1
  15. package/dist/analyzer/parseTreeUtils.js +12 -0
  16. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  17. package/dist/analyzer/program.d.ts +0 -1
  18. package/dist/analyzer/program.js +13 -29
  19. package/dist/analyzer/program.js.map +1 -1
  20. package/dist/analyzer/service.d.ts +3 -3
  21. package/dist/analyzer/service.js.map +1 -1
  22. package/dist/analyzer/sourceFile.d.ts +1 -1
  23. package/dist/analyzer/sourceFile.js +1 -1
  24. package/dist/analyzer/sourceFile.js.map +1 -1
  25. package/dist/analyzer/tracePrinter.d.ts +1 -1
  26. package/dist/analyzer/tracePrinter.js +3 -2
  27. package/dist/analyzer/tracePrinter.js.map +1 -1
  28. package/dist/analyzer/tuples.js +3 -2
  29. package/dist/analyzer/tuples.js.map +1 -1
  30. package/dist/analyzer/typeEvaluator.js +144 -94
  31. package/dist/analyzer/typeEvaluator.js.map +1 -1
  32. package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -1
  33. package/dist/analyzer/typePrinter.d.ts +2 -0
  34. package/dist/analyzer/typePrinter.js +20 -0
  35. package/dist/analyzer/typePrinter.js.map +1 -1
  36. package/dist/analyzer/typeUtils.js +3 -3
  37. package/dist/analyzer/typeUtils.js.map +1 -1
  38. package/dist/analyzer/typeWalker.js +1 -1
  39. package/dist/analyzer/typeWalker.js.map +1 -1
  40. package/dist/analyzer/typedDicts.js +6 -7
  41. package/dist/analyzer/typedDicts.js.map +1 -1
  42. package/dist/analyzer/types.d.ts +4 -1
  43. package/dist/analyzer/types.js +20 -4
  44. package/dist/analyzer/types.js.map +1 -1
  45. package/dist/backgroundAnalysisBase.d.ts +26 -4
  46. package/dist/backgroundAnalysisBase.js +23 -15
  47. package/dist/backgroundAnalysisBase.js.map +1 -1
  48. package/dist/common/cancellationUtils.d.ts +4 -1
  49. package/dist/common/cancellationUtils.js +27 -2
  50. package/dist/common/cancellationUtils.js.map +1 -1
  51. package/dist/common/core.d.ts +1 -0
  52. package/dist/common/core.js +10 -0
  53. package/dist/common/core.js.map +1 -1
  54. package/dist/common/fileBasedCancellationUtils.js +4 -0
  55. package/dist/common/fileBasedCancellationUtils.js.map +1 -1
  56. package/dist/common/languageServerInterface.d.ts +3 -3
  57. package/dist/languageServerBase.d.ts +3 -3
  58. package/dist/languageServerBase.js.map +1 -1
  59. package/dist/localization/localize.d.ts +4 -0
  60. package/dist/localization/localize.js +2 -0
  61. package/dist/localization/localize.js.map +1 -1
  62. package/dist/localization/package.nls.cs.json +2 -0
  63. package/dist/localization/package.nls.de.json +2 -0
  64. package/dist/localization/package.nls.en-us.json +5 -0
  65. package/dist/localization/package.nls.es.json +2 -0
  66. package/dist/localization/package.nls.fr.json +2 -0
  67. package/dist/localization/package.nls.it.json +2 -0
  68. package/dist/localization/package.nls.ja.json +2 -0
  69. package/dist/localization/package.nls.ko.json +2 -0
  70. package/dist/localization/package.nls.pl.json +2 -0
  71. package/dist/localization/package.nls.pt-br.json +2 -0
  72. package/dist/localization/package.nls.qps-ploc.json +2 -0
  73. package/dist/localization/package.nls.ru.json +2 -0
  74. package/dist/localization/package.nls.tr.json +2 -0
  75. package/dist/localization/package.nls.zh-cn.json +2 -0
  76. package/dist/localization/package.nls.zh-tw.json +2 -0
  77. package/dist/parser/tokenizer.js +3 -2
  78. package/dist/parser/tokenizer.js.map +1 -1
  79. package/dist/server.d.ts +2 -2
  80. package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js +2 -2
  81. package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js.map +1 -1
  82. package/dist/tests/fourslash/completions.wildcardimports.fourslash.js +2 -2
  83. package/dist/tests/fourslash/completions.wildcardimports.fourslash.js.map +1 -1
  84. package/dist/tests/fourslash/hover.wildcardimports.fourslash.js +2 -2
  85. package/dist/tests/fourslash/hover.wildcardimports.fourslash.js.map +1 -1
  86. package/dist/tests/fourslash/signature.docstrings.wildcardimports.fourslash.js +2 -2
  87. package/dist/tests/fourslash/signature.docstrings.wildcardimports.fourslash.js.map +1 -1
  88. package/dist/tests/harness/fourslash/testLanguageService.d.ts +2 -2
  89. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  90. package/dist/tests/serialization.test.js +7 -0
  91. package/dist/tests/serialization.test.js.map +1 -1
  92. package/dist/tests/typeEvaluator4.test.js +2 -2
  93. package/dist/tests/typeEvaluator5.test.js +1 -1
  94. package/dist/tests/typeEvaluator6.test.js +1 -1
  95. package/dist/tests/typeEvaluator8.test.js +1 -1
  96. package/package.json +1 -1
@@ -42,6 +42,7 @@ exports.maxCodeComplexity = void 0;
42
42
  exports.createTypeEvaluator = createTypeEvaluator;
43
43
  const cancellationUtils_1 = require("../common/cancellationUtils");
44
44
  const collectionUtils_1 = require("../common/collectionUtils");
45
+ const core_1 = require("../common/core");
45
46
  const debug_1 = require("../common/debug");
46
47
  const diagnostic_1 = require("../common/diagnostic");
47
48
  const diagnosticRules_1 = require("../common/diagnosticRules");
@@ -199,12 +200,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
199
200
  const signatureTrackerStack = [];
200
201
  let prefetched;
201
202
  function runWithCancellationToken(token, callback) {
203
+ // Save the current token and restore it after the callback to support nested calls
204
+ const oldToken = cancellationToken;
205
+ let result = undefined;
202
206
  try {
203
207
  cancellationToken = token;
204
- return callback();
208
+ result = callback();
209
+ if (!(0, core_1.isThenable)(result)) {
210
+ return result;
211
+ }
212
+ return result.finally(() => {
213
+ cancellationToken = oldToken;
214
+ });
205
215
  }
206
216
  finally {
207
- cancellationToken = undefined;
217
+ if (!(0, core_1.isThenable)(result)) {
218
+ cancellationToken = oldToken;
219
+ }
208
220
  }
209
221
  }
210
222
  function checkForCancellation() {
@@ -590,7 +602,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
590
602
  // Make sure the resulting type is assignable to the expected type.
591
603
  if (!assignType(inferenceContext.expectedType, typeResult.type, diag,
592
604
  /* constraints */ undefined, 0 /* AssignTypeFlags.Default */)) {
593
- typeResult.typeErrors = true;
605
+ // Set the typeErrors to true, but first make a copy of the
606
+ // type result because the (non-error) version may already
607
+ // be cached.
608
+ typeResult = { ...typeResult, typeErrors: true };
594
609
  typeResult.expectedTypeDiagAddendum = diag;
595
610
  diag.addTextRange(node);
596
611
  }
@@ -5763,7 +5778,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5763
5778
  }
5764
5779
  return typeResult;
5765
5780
  }
5766
- function buildTupleTypesList(entryTypeResults, stripLiterals) {
5781
+ function buildTupleTypesList(entryTypeResults, stripLiterals, convertModule) {
5767
5782
  const entryTypes = [];
5768
5783
  for (const typeResult of entryTypeResults) {
5769
5784
  let possibleUnpackedTuple;
@@ -5792,8 +5807,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5792
5807
  entryTypes.push({ type: types_1.UnknownType.create(/* isIncomplete */ true), isUnbounded: false });
5793
5808
  }
5794
5809
  else {
5795
- let entryType = convertSpecialFormToRuntimeValue(typeResult.type, 0 /* EvalFlags.None */,
5796
- /* convertModule */ true);
5810
+ let entryType = convertSpecialFormToRuntimeValue(typeResult.type, 0 /* EvalFlags.None */, convertModule);
5797
5811
  entryType = stripLiterals ? (0, typeUtils_1.stripTypeForm)(stripLiteralValue(entryType)) : entryType;
5798
5812
  entryTypes.push({ type: entryType, isUnbounded: !!typeResult.unpackedType });
5799
5813
  }
@@ -7607,6 +7621,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7607
7621
  if (paramInfo.param.category === 1 /* ParamCategory.ArgsList */) {
7608
7622
  matchedUnpackedListOfUnknownLength = true;
7609
7623
  }
7624
+ if (isParamVariadic && listElementType) {
7625
+ isArgCompatibleWithVariadic = true;
7626
+ listElementType = (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type: listElementType, isUnbounded: true }],
7627
+ /* isUnpacked */ true);
7628
+ }
7610
7629
  }
7611
7630
  const funcArg = listElementType
7612
7631
  ? {
@@ -8111,20 +8130,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8111
8130
  const param = paramInfo.param;
8112
8131
  if (param.category === 0 /* ParamCategory.Simple */ && param.name) {
8113
8132
  const entry = paramMap.get(param.name);
8114
- if (entry && entry.argsNeeded === 0 && entry.argsReceived === 0 && paramInfo.defaultType) {
8115
- validateArgTypeParams.push({
8116
- paramCategory: param.category,
8117
- paramType: paramInfo.type,
8118
- requiresTypeVarMatching: true,
8119
- argument: {
8120
- argCategory: 0 /* ArgCategory.Simple */,
8121
- typeResult: { type: paramInfo.defaultType },
8122
- },
8123
- isDefaultArg: true,
8124
- errorNode,
8125
- paramName: param.name,
8126
- isParamNameSynthesized: types_1.FunctionParam.isNameSynthesized(param),
8127
- });
8133
+ if (entry && entry.argsNeeded === 0 && entry.argsReceived === 0) {
8134
+ const defaultArgType = paramInfo.defaultType;
8135
+ if (defaultArgType &&
8136
+ !(0, typeUtils_1.isEllipsisType)(defaultArgType) &&
8137
+ (0, typeUtils_1.requiresSpecialization)(paramInfo.declaredType)) {
8138
+ validateArgTypeParams.push({
8139
+ paramCategory: param.category,
8140
+ paramType: paramInfo.type,
8141
+ requiresTypeVarMatching: true,
8142
+ argument: {
8143
+ argCategory: 0 /* ArgCategory.Simple */,
8144
+ typeResult: { type: defaultArgType },
8145
+ },
8146
+ isDefaultArg: true,
8147
+ errorNode,
8148
+ paramName: param.name,
8149
+ isParamNameSynthesized: types_1.FunctionParam.isNameSynthesized(param),
8150
+ });
8151
+ }
8128
8152
  }
8129
8153
  }
8130
8154
  });
@@ -9244,6 +9268,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9244
9268
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeMustBeAssigned(), errorNode);
9245
9269
  return undefined;
9246
9270
  }
9271
+ const scope = ScopeUtils.getScopeForNode(errorNode);
9272
+ if (scope) {
9273
+ if (scope.type !== 3 /* ScopeType.Class */ && scope.type !== 4 /* ScopeType.Module */ && scope.type !== 5 /* ScopeType.Builtin */) {
9274
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasTypeBadScope(), errorNode.parent.d.leftExpr);
9275
+ }
9276
+ }
9247
9277
  const nameNode = errorNode.parent.d.leftExpr;
9248
9278
  const firstArg = argList[0];
9249
9279
  if (firstArg.valueExpression && firstArg.valueExpression.nodeType === 48 /* ParseNodeType.StringList */) {
@@ -9715,8 +9745,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9715
9745
  typeErrors = true;
9716
9746
  }
9717
9747
  // Strip any literal values and TypeForm types.
9718
- const keyTypes = keyTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, /* convertModule */ true)));
9719
- const valueTypes = valueTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, /* convertModule */ true)));
9748
+ const keyTypes = keyTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, !hasExpectedType)));
9749
+ const valueTypes = valueTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, !hasExpectedType)));
9720
9750
  if (keyTypes.length > 0) {
9721
9751
  if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.strictDictionaryInference || hasExpectedType) {
9722
9752
  keyType = (0, types_1.combineTypes)(keyTypes);
@@ -10085,7 +10115,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10085
10115
  else {
10086
10116
  entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvalFlags.StripTupleLiterals */);
10087
10117
  }
10088
- entryTypeResult.type = (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(entryTypeResult.type, flags, /* convertModule */ true));
10118
+ entryTypeResult.type = (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(entryTypeResult.type, flags, !hasExpectedType));
10089
10119
  if (entryTypeResult.isIncomplete) {
10090
10120
  isIncomplete = true;
10091
10121
  }
@@ -10373,7 +10403,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10373
10403
  : undefined, () => {
10374
10404
  const returnTypeResult = getTypeOfExpression(node.d.expr,
10375
10405
  /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
10376
- functionType.priv.inferredReturnType = returnTypeResult.type;
10406
+ functionType.priv.inferredReturnType = {
10407
+ type: returnTypeResult.type,
10408
+ };
10377
10409
  if (returnTypeResult.isIncomplete) {
10378
10410
  isIncomplete = true;
10379
10411
  }
@@ -12252,16 +12284,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12252
12284
  else if (arg.d.name.d.value === 'total' && !constArgValue) {
12253
12285
  classType.shared.flags |= 32 /* ClassTypeFlags.CanOmitDictValues */;
12254
12286
  }
12255
- else if (arg.d.name.d.value === 'closed') {
12287
+ else if (arg.d.name.d.value === 'closed' &&
12288
+ AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
12256
12289
  if (constArgValue) {
12257
- // This is an experimental feature because PEP 728 hasn't been accepted yet.
12258
- if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
12259
- classType.shared.flags |=
12260
- 8 /* ClassTypeFlags.TypedDictMarkedClosed */ |
12261
- 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
12262
- if (classType.shared.typedDictExtraItemsExpr) {
12263
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
12264
- }
12290
+ classType.shared.flags |=
12291
+ 8 /* ClassTypeFlags.TypedDictMarkedClosed */ | 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
12292
+ if (classType.shared.typedDictExtraItemsExpr) {
12293
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
12265
12294
  }
12266
12295
  }
12267
12296
  if (sawClosedOrExtraItems) {
@@ -12270,16 +12299,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12270
12299
  sawClosedOrExtraItems = true;
12271
12300
  }
12272
12301
  }
12273
- else if (arg.d.name.d.value === 'extra_items') {
12274
- // This is an experimental feature because PEP 728 hasn't been accepted yet.
12275
- if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
12276
- // Record a reference to the expression but don't evaluate it yet.
12277
- // It may refer to the class itself.
12278
- classType.shared.typedDictExtraItemsExpr = arg.d.valueExpr;
12279
- classType.shared.flags |= 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
12280
- if (types_1.ClassType.isTypedDictMarkedClosed(classType)) {
12281
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
12282
- }
12302
+ else if (arg.d.name.d.value === 'extra_items' &&
12303
+ AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
12304
+ // Record a reference to the expression but don't evaluate it yet.
12305
+ // It may refer to the class itself.
12306
+ classType.shared.typedDictExtraItemsExpr = arg.d.valueExpr;
12307
+ classType.shared.flags |= 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
12308
+ if (types_1.ClassType.isTypedDictMarkedClosed(classType)) {
12309
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
12283
12310
  }
12284
12311
  if (sawClosedOrExtraItems) {
12285
12312
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), arg.d.valueExpr);
@@ -12592,6 +12619,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12592
12619
  }
12593
12620
  }
12594
12621
  };
12622
+ // If Any is defined using a class statement, treat it as a special form.
12623
+ if (node.d.name.d.value === 'Any' && fileInfo.isTypingStubFile) {
12624
+ decoratedType = types_1.AnyType.createSpecialForm();
12625
+ }
12595
12626
  // Update the undecorated class type.
12596
12627
  writeTypeCache(node.d.name, { type: classType }, 0 /* EvalFlags.None */);
12597
12628
  // Update the decorated class type.
@@ -13335,21 +13366,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13335
13366
  if (functionType.shared.declaredReturnType && returnTypeAnnotationNode) {
13336
13367
  (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParamsSeen, (0, typeUtils_1.getTypeVarArgsRecursive)(functionType.shared.declaredReturnType), functionType.shared.typeVarScopeId);
13337
13368
  }
13338
- // If the return type is explicitly annotated as a generator, mark the
13339
- // function as a generator even though it may not contain a "yield" statement.
13340
- // This is important for generator functions declared in stub files, abstract
13341
- // methods or protocol definitions.
13342
- if (fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.d.suite)) {
13343
- if (functionType.shared.declaredReturnType &&
13344
- (0, types_1.isClassInstance)(functionType.shared.declaredReturnType) &&
13345
- types_1.ClassType.isBuiltIn(functionType.shared.declaredReturnType, [
13346
- 'Generator',
13347
- 'AsyncGenerator',
13348
- 'AwaitableGenerator',
13349
- ])) {
13350
- functionType.shared.flags |= 16 /* FunctionTypeFlags.Generator */;
13351
- }
13352
- }
13353
13369
  // Validate the default types for all type parameters.
13354
13370
  functionType.shared.typeParams.forEach((typeParam, index) => {
13355
13371
  let bestErrorNode = node.d.name;
@@ -13533,7 +13549,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13533
13549
  awaitableFunctionType.shared.declaredReturnType = createAwaitableReturnType(node, functionType.shared.declaredReturnType, types_1.FunctionType.isGenerator(functionType));
13534
13550
  }
13535
13551
  else {
13536
- awaitableFunctionType.priv.inferredReturnType = createAwaitableReturnType(node, getInferredReturnType(functionType), types_1.FunctionType.isGenerator(functionType));
13552
+ awaitableFunctionType.priv.inferredReturnType = {
13553
+ type: createAwaitableReturnType(node, getInferredReturnType(functionType), types_1.FunctionType.isGenerator(functionType)),
13554
+ };
13537
13555
  }
13538
13556
  return awaitableFunctionType;
13539
13557
  }
@@ -13556,11 +13574,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13556
13574
  awaitableReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(asyncGeneratorType, typeArgs));
13557
13575
  }
13558
13576
  }
13559
- else if (['AsyncGenerator', 'AsyncIterator', 'AsyncIterable'].some((name) => name === returnType.shared.name)) {
13560
- // If it's already an AsyncGenerator, AsyncIterator or AsyncIterable,
13561
- // leave it as is.
13577
+ else if (['AsyncIterator', 'AsyncIterable'].some((name) => name === returnType.shared.name)) {
13578
+ // If it's already an AsyncIterator or AsyncIterable, leave it as is.
13562
13579
  awaitableReturnType = returnType;
13563
13580
  }
13581
+ else if (returnType.shared.name === 'AsyncGenerator') {
13582
+ // If it's already an AsyncGenerator and the function is a generator,
13583
+ // leave it as is.
13584
+ if (isGenerator) {
13585
+ awaitableReturnType = returnType;
13586
+ }
13587
+ }
13564
13588
  }
13565
13589
  }
13566
13590
  if (!awaitableReturnType || !isGenerator) {
@@ -16594,8 +16618,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16594
16618
  }
16595
16619
  // If the return type has already been lazily evaluated,
16596
16620
  // don't bother computing it again.
16597
- if (type.priv.inferredReturnType) {
16598
- returnType = type.priv.inferredReturnType;
16621
+ if (type.priv.inferredReturnType && !type.priv.inferredReturnType.isIncomplete) {
16622
+ returnType = type.priv.inferredReturnType.type;
16599
16623
  }
16600
16624
  else {
16601
16625
  // Don't bother inferring the return type of __init__ because it's
@@ -16642,9 +16666,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16642
16666
  }
16643
16667
  returnType = (0, typeUtils_1.makeTypeVarsFree)(returnType, typeVarScopes);
16644
16668
  // Cache the type for next time.
16645
- if (!isIncomplete) {
16646
- type.priv.inferredReturnType = returnType;
16647
- }
16669
+ type.priv.inferredReturnType = { type: returnType, isIncomplete };
16648
16670
  }
16649
16671
  // If the type is partially unknown and the function has one or more unannotated
16650
16672
  // params, try to analyze the function with the provided argument types and
@@ -17640,6 +17662,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17640
17662
  }
17641
17663
  }
17642
17664
  let concreteSrcType = makeTopLevelTypeVarsConcrete(srcType);
17665
+ // Handle the TypeForm special form. Add a special case for
17666
+ // type[T] to be assignable to TypeForm[T].
17667
+ if (types_1.ClassType.isBuiltIn(destType, 'TypeForm')) {
17668
+ const destTypeArg = destType.priv.typeArgs && destType.priv.typeArgs.length > 0
17669
+ ? destType.priv.typeArgs[0]
17670
+ : types_1.UnknownType.create();
17671
+ let srcTypeArg;
17672
+ if ((0, types_1.isClassInstance)(concreteSrcType) && types_1.ClassType.isBuiltIn(concreteSrcType, 'type')) {
17673
+ srcTypeArg = concreteSrcType;
17674
+ }
17675
+ else if ((0, types_1.isInstantiableClass)(concreteSrcType)) {
17676
+ srcTypeArg = (0, typeUtils_1.convertToInstance)(concreteSrcType);
17677
+ }
17678
+ if (srcTypeArg) {
17679
+ return assignType(destTypeArg, srcTypeArg, diag, constraints, flags, recursionCount);
17680
+ }
17681
+ }
17643
17682
  if ((0, types_1.isClass)(concreteSrcType) && types_1.TypeBase.isInstance(concreteSrcType)) {
17644
17683
  // Handle the case where the source is an unpacked tuple.
17645
17684
  if (!destType.priv.isUnpacked &&
@@ -19850,37 +19889,48 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19850
19889
  // is the type used to reference the member.
19851
19890
  function partiallySpecializeBoundMethod(baseType, memberType, diag, recursionCount, firstParamType, stripFirstParam = true) {
19852
19891
  const constraints = new constraintTracker_1.ConstraintTracker();
19853
- if (firstParamType && memberType.shared.parameters.length > 0) {
19854
- const memberTypeFirstParam = memberType.shared.parameters[0];
19855
- const memberTypeFirstParamType = types_1.FunctionType.getParamType(memberType, 0);
19856
- if ((0, types_1.isTypeVar)(memberTypeFirstParamType) &&
19857
- memberTypeFirstParamType.shared.boundType &&
19858
- (0, types_1.isClassInstance)(memberTypeFirstParamType.shared.boundType) &&
19859
- types_1.ClassType.isProtocolClass(memberTypeFirstParamType.shared.boundType)) {
19860
- // Handle the protocol class specially. Some protocol classes
19861
- // contain references to themselves or their subclasses, so if
19862
- // we attempt to call assignType, we'll risk infinite recursion.
19863
- // Instead, we'll assume it's assignable.
19864
- constraints.setBounds(memberTypeFirstParamType, types_1.TypeBase.isInstantiable(memberTypeFirstParamType)
19865
- ? (0, typeUtils_1.convertToInstance)(firstParamType)
19866
- : firstParamType);
19892
+ if (firstParamType) {
19893
+ if (memberType.shared.parameters.length > 0) {
19894
+ const memberTypeFirstParam = memberType.shared.parameters[0];
19895
+ const memberTypeFirstParamType = types_1.FunctionType.getParamType(memberType, 0);
19896
+ if ((0, types_1.isTypeVar)(memberTypeFirstParamType) &&
19897
+ memberTypeFirstParamType.shared.boundType &&
19898
+ (0, types_1.isClassInstance)(memberTypeFirstParamType.shared.boundType) &&
19899
+ types_1.ClassType.isProtocolClass(memberTypeFirstParamType.shared.boundType)) {
19900
+ // Handle the protocol class specially. Some protocol classes
19901
+ // contain references to themselves or their subclasses, so if
19902
+ // we attempt to call assignType, we'll risk infinite recursion.
19903
+ // Instead, we'll assume it's assignable.
19904
+ constraints.setBounds(memberTypeFirstParamType, types_1.TypeBase.isInstantiable(memberTypeFirstParamType)
19905
+ ? (0, typeUtils_1.convertToInstance)(firstParamType)
19906
+ : firstParamType);
19907
+ }
19908
+ else {
19909
+ const subDiag = diag?.createAddendum();
19910
+ if (!assignType(memberTypeFirstParamType, firstParamType, subDiag?.createAddendum(), constraints, 8192 /* AssignTypeFlags.AllowUnspecifiedTypeArgs */, recursionCount)) {
19911
+ if (memberTypeFirstParam.name &&
19912
+ !types_1.FunctionParam.isNameSynthesized(memberTypeFirstParam) &&
19913
+ types_1.FunctionParam.isTypeDeclared(memberTypeFirstParam)) {
19914
+ if (subDiag) {
19915
+ subDiag.addMessage(localize_1.LocMessage.bindTypeMismatch().format({
19916
+ type: printType(firstParamType),
19917
+ methodName: memberType.shared.name || '<anonymous>',
19918
+ paramName: memberTypeFirstParam.name,
19919
+ }));
19920
+ }
19921
+ return undefined;
19922
+ }
19923
+ }
19924
+ }
19867
19925
  }
19868
19926
  else {
19869
19927
  const subDiag = diag?.createAddendum();
19870
- if (!assignType(memberTypeFirstParamType, firstParamType, subDiag?.createAddendum(), constraints, 8192 /* AssignTypeFlags.AllowUnspecifiedTypeArgs */, recursionCount)) {
19871
- if (memberTypeFirstParam.name &&
19872
- !types_1.FunctionParam.isNameSynthesized(memberTypeFirstParam) &&
19873
- types_1.FunctionParam.isTypeDeclared(memberTypeFirstParam)) {
19874
- if (subDiag) {
19875
- subDiag.addMessage(localize_1.LocMessage.bindTypeMismatch().format({
19876
- type: printType(firstParamType),
19877
- methodName: memberType.shared.name || '<anonymous>',
19878
- paramName: memberTypeFirstParam.name,
19879
- }));
19880
- }
19881
- return undefined;
19882
- }
19928
+ if (subDiag) {
19929
+ subDiag.addMessage(localize_1.LocMessage.bindParamMissing().format({
19930
+ methodName: memberType.shared.name || '<anonymous>',
19931
+ }));
19883
19932
  }
19933
+ return undefined;
19884
19934
  }
19885
19935
  }
19886
19936
  // Get the effective return type, which will have the side effect of lazily