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

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 (188) hide show
  1. package/dist/analyzer/analysis.d.ts +5 -1
  2. package/dist/analyzer/analysis.js +3 -3
  3. package/dist/analyzer/analysis.js.map +1 -1
  4. package/dist/analyzer/analyzerNodeInfo.d.ts +2 -2
  5. package/dist/analyzer/backgroundAnalysisProgram.js +1 -1
  6. package/dist/analyzer/binder.d.ts +3 -3
  7. package/dist/analyzer/binder.js +38 -32
  8. package/dist/analyzer/binder.js.map +1 -1
  9. package/dist/analyzer/checker.d.ts +3 -3
  10. package/dist/analyzer/checker.js +45 -37
  11. package/dist/analyzer/checker.js.map +1 -1
  12. package/dist/analyzer/codeFlowEngine.js +9 -5
  13. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  14. package/dist/analyzer/codeFlowTypes.js +3 -3
  15. package/dist/analyzer/constraintSolver.js +2 -1
  16. package/dist/analyzer/constraintSolver.js.map +1 -1
  17. package/dist/analyzer/constructorTransform.d.ts +2 -1
  18. package/dist/analyzer/constructorTransform.js +7 -6
  19. package/dist/analyzer/constructorTransform.js.map +1 -1
  20. package/dist/analyzer/constructors.d.ts +2 -2
  21. package/dist/analyzer/constructors.js +35 -25
  22. package/dist/analyzer/constructors.js.map +1 -1
  23. package/dist/analyzer/declarationUtils.js +3 -3
  24. package/dist/analyzer/decorators.js +3 -1
  25. package/dist/analyzer/decorators.js.map +1 -1
  26. package/dist/analyzer/enums.js +9 -8
  27. package/dist/analyzer/enums.js.map +1 -1
  28. package/dist/analyzer/importResolver.d.ts +1 -0
  29. package/dist/analyzer/importResolver.js +17 -7
  30. package/dist/analyzer/importResolver.js.map +1 -1
  31. package/dist/analyzer/importStatementUtils.js +6 -6
  32. package/dist/analyzer/namedTuples.js +2 -2
  33. package/dist/analyzer/operations.js +2 -2
  34. package/dist/analyzer/parameterUtils.d.ts +5 -5
  35. package/dist/analyzer/parameterUtils.js +16 -16
  36. package/dist/analyzer/parameterUtils.js.map +1 -1
  37. package/dist/analyzer/parentDirectoryCache.js +1 -2
  38. package/dist/analyzer/parentDirectoryCache.js.map +1 -1
  39. package/dist/analyzer/parseTreeUtils.d.ts +1 -1
  40. package/dist/analyzer/parseTreeUtils.js +94 -94
  41. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  42. package/dist/analyzer/parseTreeWalker.d.ts +5 -5
  43. package/dist/analyzer/parseTreeWalker.js +64 -64
  44. package/dist/analyzer/parseTreeWalker.js.map +1 -1
  45. package/dist/analyzer/patternMatching.js +1 -1
  46. package/dist/analyzer/program.d.ts +2 -1
  47. package/dist/analyzer/program.js +36 -35
  48. package/dist/analyzer/program.js.map +1 -1
  49. package/dist/analyzer/scope.d.ts +1 -1
  50. package/dist/analyzer/scope.js +2 -2
  51. package/dist/analyzer/scope.js.map +1 -1
  52. package/dist/analyzer/service.d.ts +4 -2
  53. package/dist/analyzer/service.js +67 -33
  54. package/dist/analyzer/service.js.map +1 -1
  55. package/dist/analyzer/sourceFile.d.ts +1 -1
  56. package/dist/analyzer/sourceFile.js +20 -6
  57. package/dist/analyzer/sourceFile.js.map +1 -1
  58. package/dist/analyzer/sourceMapper.js +4 -4
  59. package/dist/analyzer/staticExpressions.js +3 -3
  60. package/dist/analyzer/testWalker.js +1 -1
  61. package/dist/analyzer/tracePrinter.js +4 -4
  62. package/dist/analyzer/typeDocStringUtils.js +7 -4
  63. package/dist/analyzer/typeDocStringUtils.js.map +1 -1
  64. package/dist/analyzer/typeEvaluator.js +638 -559
  65. package/dist/analyzer/typeEvaluator.js.map +1 -1
  66. package/dist/analyzer/typeEvaluatorTypes.d.ts +5 -4
  67. package/dist/analyzer/typeEvaluatorTypes.js +3 -0
  68. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  69. package/dist/analyzer/typeGuards.js +6 -6
  70. package/dist/analyzer/typePrinter.js +7 -1
  71. package/dist/analyzer/typePrinter.js.map +1 -1
  72. package/dist/analyzer/typeStubWriter.js +1 -1
  73. package/dist/analyzer/typeUtils.d.ts +4 -5
  74. package/dist/analyzer/typeUtils.js +18 -11
  75. package/dist/analyzer/typeUtils.js.map +1 -1
  76. package/dist/analyzer/typedDicts.d.ts +1 -2
  77. package/dist/analyzer/typedDicts.js +5 -17
  78. package/dist/analyzer/typedDicts.js.map +1 -1
  79. package/dist/backgroundAnalysisBase.js +4 -4
  80. package/dist/backgroundAnalysisBase.js.map +1 -1
  81. package/dist/backgroundThreadBase.d.ts +2 -0
  82. package/dist/backgroundThreadBase.js +7 -3
  83. package/dist/backgroundThreadBase.js.map +1 -1
  84. package/dist/commands/createTypeStub.d.ts +7 -1
  85. package/dist/commands/createTypeStub.js +45 -32
  86. package/dist/commands/createTypeStub.js.map +1 -1
  87. package/dist/commands/dumpFileDebugInfoCommand.d.ts +1 -1
  88. package/dist/commands/dumpFileDebugInfoCommand.js +14 -14
  89. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  90. package/dist/common/configOptions.d.ts +4 -3
  91. package/dist/common/configOptions.js +36 -31
  92. package/dist/common/configOptions.js.map +1 -1
  93. package/dist/common/console.d.ts +3 -0
  94. package/dist/common/console.js +4 -0
  95. package/dist/common/console.js.map +1 -1
  96. package/dist/common/languageServerInterface.d.ts +46 -0
  97. package/dist/common/languageServerInterface.js.map +1 -1
  98. package/dist/common/textEditTracker.js +5 -5
  99. package/dist/common/uri/fileUri.js +1 -0
  100. package/dist/common/uri/fileUri.js.map +1 -1
  101. package/dist/common/uri/uri.d.ts +3 -0
  102. package/dist/common/uri/uri.js +18 -0
  103. package/dist/common/uri/uri.js.map +1 -1
  104. package/dist/common/uri/uriUtils.d.ts +1 -1
  105. package/dist/common/uri/uriUtils.js +3 -3
  106. package/dist/common/uri/uriUtils.js.map +1 -1
  107. package/dist/common/workspaceEditUtils.js +8 -6
  108. package/dist/common/workspaceEditUtils.js.map +1 -1
  109. package/dist/languageServerBase.d.ts +4 -45
  110. package/dist/languageServerBase.js +36 -28
  111. package/dist/languageServerBase.js.map +1 -1
  112. package/dist/languageService/analyzerServiceExecutor.d.ts +2 -2
  113. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  114. package/dist/languageService/autoImporter.js +4 -4
  115. package/dist/languageService/callHierarchyProvider.js +6 -6
  116. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  117. package/dist/languageService/completionProvider.js +31 -31
  118. package/dist/languageService/completionProvider.js.map +1 -1
  119. package/dist/languageService/documentSymbolCollector.js +7 -7
  120. package/dist/languageService/documentSymbolProvider.js +1 -1
  121. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  122. package/dist/languageService/fileWatcherDynamicFeature.d.ts +2 -2
  123. package/dist/languageService/fileWatcherDynamicFeature.js +2 -2
  124. package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
  125. package/dist/languageService/hoverProvider.js +2 -2
  126. package/dist/languageService/importSorter.js +1 -1
  127. package/dist/languageService/navigationUtils.js +1 -1
  128. package/dist/languageService/navigationUtils.js.map +1 -1
  129. package/dist/languageService/referencesProvider.js +4 -4
  130. package/dist/languageService/referencesProvider.js.map +1 -1
  131. package/dist/languageService/symbolIndexer.js +3 -3
  132. package/dist/languageService/tooltipUtils.js +2 -2
  133. package/dist/languageService/workspaceSymbolProvider.js +1 -1
  134. package/dist/languageService/workspaceSymbolProvider.js.map +1 -1
  135. package/dist/localization/localize.d.ts +1 -1
  136. package/dist/localization/localize.js +1 -1
  137. package/dist/localization/localize.js.map +1 -1
  138. package/dist/localization/package.nls.cs.json +4 -2
  139. package/dist/localization/package.nls.de.json +5 -3
  140. package/dist/localization/package.nls.en-us.json +3 -3
  141. package/dist/localization/package.nls.es.json +5 -3
  142. package/dist/localization/package.nls.fr.json +5 -3
  143. package/dist/localization/package.nls.it.json +4 -2
  144. package/dist/localization/package.nls.ja.json +5 -3
  145. package/dist/localization/package.nls.ko.json +4 -2
  146. package/dist/localization/package.nls.pl.json +4 -2
  147. package/dist/localization/package.nls.pt-br.json +4 -2
  148. package/dist/localization/package.nls.qps-ploc.json +5 -3
  149. package/dist/localization/package.nls.ru.json +5 -3
  150. package/dist/localization/package.nls.tr.json +4 -2
  151. package/dist/localization/package.nls.zh-cn.json +5 -3
  152. package/dist/localization/package.nls.zh-tw.json +4 -2
  153. package/dist/parser/parseNodes.d.ts +42 -42
  154. package/dist/parser/parseNodes.js +69 -69
  155. package/dist/parser/parseNodes.js.map +1 -1
  156. package/dist/parser/parser.d.ts +1 -1
  157. package/dist/parser/parser.js +35 -35
  158. package/dist/parser/parser.js.map +1 -1
  159. package/dist/parser/tokenizer.js +2 -2
  160. package/dist/parser/tokenizer.js.map +1 -1
  161. package/dist/pyright.js +4 -4
  162. package/dist/pyright.js.map +1 -1
  163. package/dist/tests/classDeclaration.test.js +1 -1
  164. package/dist/tests/config.test.js +15 -3
  165. package/dist/tests/config.test.js.map +1 -1
  166. package/dist/tests/harness/fourslash/testState.js +2 -1
  167. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  168. package/dist/tests/harness/fourslash/testStateUtils.js +1 -1
  169. package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
  170. package/dist/tests/hoverProvider.test.js +17 -0
  171. package/dist/tests/hoverProvider.test.js.map +1 -1
  172. package/dist/tests/importResolver.test.js +16 -0
  173. package/dist/tests/importResolver.test.js.map +1 -1
  174. package/dist/tests/parseTreeUtils.test.js +4 -4
  175. package/dist/tests/parser.test.js +3 -3
  176. package/dist/tests/typeEvaluator1.test.js +4 -0
  177. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  178. package/dist/tests/typeEvaluator2.test.js +8 -4
  179. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  180. package/dist/tests/typeEvaluator4.test.js +6 -2
  181. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  182. package/dist/tests/typeEvaluator7.test.js +5 -7
  183. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  184. package/dist/tests/uri.test.js +11 -3
  185. package/dist/tests/uri.test.js.map +1 -1
  186. package/dist/workspaceFactory.js +16 -14
  187. package/dist/workspaceFactory.js.map +1 -1
  188. package/package.json +1 -1
@@ -183,27 +183,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
183
183
  let expectedTypeCache = new Map();
184
184
  let deferredClassCompletions = [];
185
185
  let cancellationToken;
186
- let isBasicTypesInitialized = false;
187
- let noneClassType;
188
- let noneType;
189
- let objectType;
190
- let typeClassType;
191
- let unionClassType;
192
- let awaitableProtocolType;
193
- let functionObj;
194
- let tupleClassType;
195
- let boolClassType;
196
- let intClassType;
197
- let strClassType;
198
- let dictClassType;
199
- let typedDictClassType;
200
- let typedDictPrivateClassType;
201
- let supportsKeysAndGetItemProtocolType;
202
- let mappingType;
203
186
  let printExpressionSpaceCount = 0;
204
187
  let incompleteGenerationCount = 0;
205
188
  const returnTypeInferenceContextStack = [];
206
189
  let returnTypeInferenceTypeCache;
190
+ let isPrefetchedTypesInitialized = false;
191
+ // Various types prefetched from stdlib stubs
192
+ let noneTypeClass;
193
+ let objectClass;
194
+ let typeClass;
195
+ let unionTypeClass;
196
+ let awaitableClass;
197
+ let functionClass;
198
+ let tupleClass;
199
+ let boolClass;
200
+ let intClass;
201
+ let strClass;
202
+ let dictClass;
203
+ let typedDictPrivateClass;
204
+ let supportsKeysAndGetItemClass;
205
+ let mappingClass;
207
206
  function runWithCancellationToken(token, callback) {
208
207
  try {
209
208
  cancellationToken = token;
@@ -383,7 +382,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
383
382
  // type of surrounding statements to be evaluated.
384
383
  function getType(node) {
385
384
  var _a, _b;
386
- initializedBasicTypes(node);
385
+ initializePrefetchedTypes(node);
387
386
  let type = (_a = evaluateTypeForSubnode(node, () => {
388
387
  evaluateTypesForExpressionInContext(node);
389
388
  })) === null || _a === void 0 ? void 0 : _a.type;
@@ -456,50 +455,42 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
456
455
  }
457
456
  return undefined;
458
457
  }
459
- function initializedBasicTypes(node) {
458
+ function initializePrefetchedTypes(node) {
460
459
  var _a;
461
- if (!isBasicTypesInitialized) {
460
+ if (!isPrefetchedTypesInitialized) {
462
461
  // Some of these types have cyclical dependencies on each other,
463
462
  // so don't re-enter this block once we start executing it.
464
- isBasicTypesInitialized = true;
465
- objectType = getBuiltInObject(node, 'object');
466
- typeClassType = getBuiltInType(node, 'type');
467
- functionObj = getBuiltInObject(node, 'function');
468
- unionClassType = getTypesType(node, 'UnionType');
469
- if (unionClassType && (0, types_1.isClass)(unionClassType)) {
470
- unionClassType.details.flags |= -2147483648 /* ClassTypeFlags.SpecialFormClass */;
463
+ isPrefetchedTypesInitialized = true;
464
+ objectClass = getBuiltInType(node, 'object');
465
+ typeClass = getBuiltInType(node, 'type');
466
+ functionClass = getBuiltInType(node, 'function');
467
+ unionTypeClass = getTypesType(node, 'UnionType');
468
+ if (unionTypeClass && (0, types_1.isClass)(unionTypeClass)) {
469
+ unionTypeClass.details.flags |= -2147483648 /* ClassTypeFlags.SpecialFormClass */;
471
470
  }
472
471
  // Initialize and cache "Collection" to break a cyclical dependency
473
472
  // that occurs when resolving tuple below.
474
473
  getTypingType(node, 'Collection');
475
- noneClassType = (_a = getTypeshedType(node, 'NoneType')) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
476
- noneType = (0, types_1.isInstantiableClass)(noneClassType)
477
- ? types_1.ClassType.cloneAsInstance(noneClassType)
478
- : types_1.UnknownType.create();
479
- tupleClassType = getBuiltInType(node, 'tuple');
480
- boolClassType = getBuiltInType(node, 'bool');
481
- intClassType = getBuiltInType(node, 'int');
482
- strClassType = getBuiltInType(node, 'str');
483
- dictClassType = getBuiltInType(node, 'dict');
484
- typedDictClassType = getTypingType(node, 'TypedDict');
485
- typedDictPrivateClassType = getTypingType(node, '_TypedDict');
486
- awaitableProtocolType = getTypingType(node, 'Awaitable');
487
- mappingType = getTypingType(node, 'Mapping');
488
- supportsKeysAndGetItemProtocolType = getTypeshedType(node, 'SupportsKeysAndGetItem');
489
- if (!supportsKeysAndGetItemProtocolType) {
474
+ noneTypeClass = (_a = getTypeshedType(node, 'NoneType')) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
475
+ tupleClass = getBuiltInType(node, 'tuple');
476
+ boolClass = getBuiltInType(node, 'bool');
477
+ intClass = getBuiltInType(node, 'int');
478
+ strClass = getBuiltInType(node, 'str');
479
+ dictClass = getBuiltInType(node, 'dict');
480
+ typedDictPrivateClass = getTypingType(node, '_TypedDict');
481
+ awaitableClass = getTypingType(node, 'Awaitable');
482
+ mappingClass = getTypingType(node, 'Mapping');
483
+ supportsKeysAndGetItemClass = getTypeshedType(node, 'SupportsKeysAndGetItem');
484
+ if (!supportsKeysAndGetItemClass) {
490
485
  // Fall back on 'Mapping' if 'SupportsKeysAndGetItem' is not available.
491
- supportsKeysAndGetItemProtocolType = mappingType;
486
+ supportsKeysAndGetItemClass = mappingClass;
492
487
  }
493
488
  // Wire up the `Any` class to the special-form version of our internal AnyType.
494
- const objectClass = getBuiltInType(node, 'object');
495
- if (objectClass &&
496
- (0, types_1.isInstantiableClass)(objectClass) &&
497
- typeClassType &&
498
- (0, types_1.isInstantiableClass)(typeClassType)) {
489
+ if (objectClass && (0, types_1.isInstantiableClass)(objectClass) && typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
499
490
  const anyClass = types_1.ClassType.createInstantiable('Any', 'typing.Any', 'typing', uri_1.Uri.empty(), 1 /* ClassTypeFlags.BuiltInClass */ | -2147483648 /* ClassTypeFlags.SpecialFormClass */,
500
491
  /* typeSourceId */ -1,
501
492
  /* declaredMetaclass */ undefined,
502
- /* effectiveMetaclass */ typeClassType);
493
+ /* effectiveMetaclass */ typeClass);
503
494
  anyClass.details.baseClasses.push(objectClass);
504
495
  (0, typeUtils_1.computeMroLinearization)(anyClass);
505
496
  const anySpecialForm = types_1.AnyType.createSpecialForm();
@@ -509,7 +500,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
509
500
  }
510
501
  }
511
502
  }
512
- function getTypeOfExpression(node, flags = 0 /* EvaluatorFlags.None */, inferenceContext) {
503
+ function getTypeOfExpression(node, flags = 0 /* EvaluatorFlags.None */, inferenceContext, signatureTracker) {
513
504
  // Is this type already cached?
514
505
  const cacheEntry = readTypeCacheEntry(node);
515
506
  if (cacheEntry &&
@@ -546,10 +537,56 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
546
537
  // typeshed stubs, do so here. It would be better to fetch this when it's
547
538
  // needed in assignType, but we don't have access to the parse tree
548
539
  // at that point.
549
- initializedBasicTypes(node);
540
+ initializePrefetchedTypes(node);
541
+ let typeResult = getTypeOfExpressionCore(node, flags, inferenceContext, signatureTracker);
542
+ // Should we disable type promotions for bytes?
543
+ if ((0, types_1.isInstantiableClass)(typeResult.type) &&
544
+ typeResult.type.includePromotions &&
545
+ !typeResult.type.includeSubclasses &&
546
+ types_1.ClassType.isBuiltIn(typeResult.type, 'bytes')) {
547
+ if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.disableBytesTypePromotions) {
548
+ typeResult = {
549
+ ...typeResult,
550
+ type: types_1.ClassType.cloneRemoveTypePromotions(typeResult.type),
551
+ };
552
+ }
553
+ }
554
+ // Don't allow speculative caching for assignment expressions because
555
+ // the target name node won't have a corresponding type cached speculatively.
556
+ const allowSpeculativeCaching = node.nodeType !== 4 /* ParseNodeType.AssignmentExpression */;
557
+ writeTypeCache(node, typeResult, flags, inferenceContext, allowSpeculativeCaching);
558
+ // If there was an expected type, make sure that the result type is compatible.
559
+ if (inferenceContext &&
560
+ !(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) &&
561
+ !(0, types_1.isNever)(inferenceContext.expectedType)) {
562
+ expectedTypeCache.set(node.id, inferenceContext.expectedType);
563
+ // If this is a generic function and there is a signature tracker,
564
+ // make sure the signature is unique.
565
+ if (signatureTracker && (0, types_1.isFunction)(typeResult.type)) {
566
+ typeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(typeResult.type, signatureTracker, node.start);
567
+ }
568
+ if (!typeResult.isIncomplete && !typeResult.expectedTypeDiagAddendum) {
569
+ const diag = new diagnostic_1.DiagnosticAddendum();
570
+ // Make sure the resulting type is assignable to the expected type.
571
+ if (!assignType(inferenceContext.expectedType, typeResult.type, diag,
572
+ /* destTypeVarContext */ undefined,
573
+ /* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */)) {
574
+ typeResult.typeErrors = true;
575
+ typeResult.expectedTypeDiagAddendum = diag;
576
+ diag.addTextRange(node);
577
+ }
578
+ }
579
+ }
580
+ if (printExpressionTypes) {
581
+ printExpressionSpaceCount--;
582
+ console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Post ${printType(typeResult.type)}${typeResult.isIncomplete ? ' Incomplete' : ''}`);
583
+ }
584
+ return typeResult;
585
+ }
586
+ // This is a helper function that implements the core of getTypeOfExpression.
587
+ function getTypeOfExpressionCore(node, flags = 0 /* EvaluatorFlags.None */, inferenceContext, signatureTracker) {
550
588
  let typeResult;
551
589
  let expectingInstantiable = (flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) !== 0;
552
- let allowSpeculativeCaching = true;
553
590
  switch (node.nodeType) {
554
591
  case 38 /* ParseNodeType.Name */: {
555
592
  typeResult = getTypeOfName(node, flags);
@@ -559,19 +596,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
559
596
  typeResult = getTypeOfMemberAccess(node, flags);
560
597
  break;
561
598
  }
562
- case 24 /* ParseNodeType.Index */: {
599
+ case 27 /* ParseNodeType.Index */: {
563
600
  typeResult = getTypeOfIndex(node, flags);
564
601
  break;
565
602
  }
566
603
  case 9 /* ParseNodeType.Call */: {
567
- typeResult = getTypeOfCall(node, flags, inferenceContext);
604
+ typeResult = getTypeOfCall(node, flags, inferenceContext, signatureTracker);
568
605
  break;
569
606
  }
570
607
  case 52 /* ParseNodeType.Tuple */: {
571
- typeResult = getTypeOfTuple(node, flags, inferenceContext);
608
+ typeResult = getTypeOfTuple(node, flags, inferenceContext, signatureTracker);
572
609
  break;
573
610
  }
574
- case 11 /* ParseNodeType.Constant */: {
611
+ case 14 /* ParseNodeType.Constant */: {
575
612
  typeResult = getTypeOfConstant(node, flags);
576
613
  break;
577
614
  }
@@ -589,7 +626,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
589
626
  typeResult = getTypeOfNumber(node, typeResult);
590
627
  break;
591
628
  }
592
- case 18 /* ParseNodeType.Ellipsis */: {
629
+ case 21 /* ParseNodeType.Ellipsis */: {
593
630
  typeResult = getTypeOfEllipsis(flags, typeResult, node);
594
631
  break;
595
632
  }
@@ -611,7 +648,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
611
648
  typeResult = (0, operations_1.getTypeOfAugmentedAssignment)(evaluatorInterface, node, inferenceContext);
612
649
  break;
613
650
  }
614
- case 31 /* ParseNodeType.List */:
651
+ case 34 /* ParseNodeType.List */:
615
652
  case 45 /* ParseNodeType.Set */: {
616
653
  typeResult = getTypeOfListOrSet(node, flags, inferenceContext);
617
654
  break;
@@ -628,20 +665,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
628
665
  typeResult = (0, operations_1.getTypeOfTernaryOperation)(evaluatorInterface, node, flags, inferenceContext);
629
666
  break;
630
667
  }
631
- case 32 /* ParseNodeType.ListComprehension */: {
632
- typeResult = getTypeOfListComprehension(node, inferenceContext);
668
+ case 11 /* ParseNodeType.Comprehension */: {
669
+ typeResult = getTypeOfComprehension(node, flags, inferenceContext);
633
670
  break;
634
671
  }
635
- case 15 /* ParseNodeType.Dictionary */: {
672
+ case 18 /* ParseNodeType.Dictionary */: {
636
673
  typeResult = getTypeOfDictionary(node, flags, inferenceContext);
637
674
  break;
638
675
  }
639
- case 30 /* ParseNodeType.Lambda */: {
676
+ case 33 /* ParseNodeType.Lambda */: {
640
677
  typeResult = getTypeOfLambda(node, inferenceContext);
641
678
  break;
642
679
  }
643
680
  case 3 /* ParseNodeType.Assignment */: {
644
- typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext);
681
+ typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext, signatureTracker);
645
682
  assignTypeToExpression(node.leftExpression, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
646
683
  /* ignoreEmptyContainers */ true,
647
684
  /* allowAssignmentToFinalVar */ true);
@@ -651,12 +688,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
651
688
  if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
652
689
  addError(localize_1.LocMessage.walrusNotAllowed(), node);
653
690
  }
654
- typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext);
691
+ typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext, signatureTracker);
655
692
  assignTypeToExpression(node.name, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
656
693
  /* ignoreEmptyContainers */ true);
657
- // Don't allow speculative caching for assignment expressions because
658
- // the target name node won't have a corresponding type cached speculatively.
659
- allowSpeculativeCaching = false;
660
694
  break;
661
695
  }
662
696
  case 60 /* ParseNodeType.Yield */: {
@@ -681,7 +715,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
681
715
  break;
682
716
  }
683
717
  case 49 /* ParseNodeType.String */:
684
- case 27 /* ParseNodeType.FormatString */: {
718
+ case 30 /* ParseNodeType.FormatString */: {
685
719
  typeResult = getTypeOfString(node);
686
720
  break;
687
721
  }
@@ -707,45 +741,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
707
741
  if (expectingInstantiable) {
708
742
  validateTypeIsInstantiable(typeResult, flags, node);
709
743
  }
710
- // Should we disable type promotions for bytes?
711
- if ((0, types_1.isInstantiableClass)(typeResult.type) &&
712
- typeResult.type.includePromotions &&
713
- !typeResult.type.includeSubclasses &&
714
- types_1.ClassType.isBuiltIn(typeResult.type, 'bytes')) {
715
- if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.disableBytesTypePromotions) {
716
- typeResult = {
717
- ...typeResult,
718
- type: types_1.ClassType.cloneRemoveTypePromotions(typeResult.type),
719
- };
720
- }
721
- }
722
- writeTypeCache(node, typeResult, flags, inferenceContext, allowSpeculativeCaching);
723
- // If there was an expected type, make sure that the result type is compatible.
724
- if (inferenceContext &&
725
- !(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) &&
726
- !(0, types_1.isNever)(inferenceContext.expectedType)) {
727
- expectedTypeCache.set(node.id, inferenceContext.expectedType);
728
- // If this is a generic function and there is a signature tracker,
729
- // make sure the signature is unique.
730
- if (inferenceContext.signatureTracker && (0, types_1.isFunction)(typeResult.type)) {
731
- typeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(typeResult.type, inferenceContext.signatureTracker, node.start);
732
- }
733
- if (!typeResult.isIncomplete && !typeResult.expectedTypeDiagAddendum) {
734
- const diag = new diagnostic_1.DiagnosticAddendum();
735
- // Make sure the resulting type is assignable to the expected type.
736
- if (!assignType(inferenceContext.expectedType, typeResult.type, diag,
737
- /* destTypeVarContext */ undefined,
738
- /* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */)) {
739
- typeResult.typeErrors = true;
740
- typeResult.expectedTypeDiagAddendum = diag;
741
- diag.addTextRange(node);
742
- }
743
- }
744
- }
745
- if (printExpressionTypes) {
746
- printExpressionSpaceCount--;
747
- console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Post ${printType(typeResult.type)}${typeResult.isIncomplete ? ' Incomplete' : ''}`);
748
- }
749
744
  return typeResult;
750
745
  }
751
746
  // Reports the case where a function or class has been decorated with
@@ -942,7 +937,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
942
937
  });
943
938
  const isBytes = (node.strings[0].token.flags & 32 /* StringTokenFlags.Bytes */) !== 0;
944
939
  // Don't create a literal type if it's an f-string.
945
- if (node.strings.some((str) => str.nodeType === 27 /* ParseNodeType.FormatString */)) {
940
+ if (node.strings.some((str) => str.nodeType === 30 /* ParseNodeType.FormatString */)) {
946
941
  if (isLiteralString) {
947
942
  const literalStringType = getTypingType(node, 'LiteralString');
948
943
  if (literalStringType && (0, types_1.isInstantiableClass)(literalStringType)) {
@@ -970,7 +965,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
970
965
  let typeResult;
971
966
  let isIncomplete = false;
972
967
  // Don't create a literal type if it's an f-string.
973
- if (node.nodeType === 27 /* ParseNodeType.FormatString */) {
968
+ if (node.nodeType === 30 /* ParseNodeType.FormatString */) {
974
969
  let isLiteralString = true;
975
970
  // If all of the format expressions are of type LiteralString, then
976
971
  // the resulting formatted string is also LiteralString.
@@ -1036,8 +1031,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1036
1031
  }
1037
1032
  if (types_1.ClassType.isBuiltIn(subtype, 'LiteralString')) {
1038
1033
  // Handle "LiteralString" specially.
1039
- if (strClassType && (0, types_1.isInstantiableClass)(strClassType)) {
1040
- let strInstance = types_1.ClassType.cloneAsInstance(strClassType);
1034
+ if (strClass && (0, types_1.isInstantiableClass)(strClass)) {
1035
+ let strInstance = types_1.ClassType.cloneAsInstance(strClass);
1041
1036
  if (subtype.condition) {
1042
1037
  strInstance = types_1.TypeBase.cloneForCondition(strInstance, (0, typeUtils_1.getTypeCondition)(subtype));
1043
1038
  }
@@ -1536,7 +1531,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1536
1531
  let callResult;
1537
1532
  useSpeculativeMode(callNode, () => {
1538
1533
  callResult = validateFunctionArguments(exprNode, argList, { type }, new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type)),
1539
- /* skipUnknownArgCheck */ true);
1534
+ /* skipUnknownArgCheck */ true,
1535
+ /* inferenceContext */ undefined,
1536
+ /* signatureTracker */ undefined);
1540
1537
  });
1541
1538
  signatures.push({
1542
1539
  type: expandTypedKwargs(type),
@@ -1727,7 +1724,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1727
1724
  }
1728
1725
  break;
1729
1726
  }
1730
- case 24 /* ParseNodeType.Index */: {
1727
+ case 27 /* ParseNodeType.Index */: {
1731
1728
  const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.baseExpression, 2 /* EvaluatorFlags.IndexBaseDefaults */).type);
1732
1729
  if (baseType && (0, types_1.isClassInstance)(baseType)) {
1733
1730
  const setItemType = getBoundMagicMethod(baseType, '__setitem__');
@@ -1780,12 +1777,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1780
1777
  // (object that provides an __await__ that returns a generator object).
1781
1778
  // If errorNode is undefined, no errors are reported.
1782
1779
  function getTypeOfAwaitable(type, errorNode) {
1783
- if (!awaitableProtocolType ||
1784
- !(0, types_1.isInstantiableClass)(awaitableProtocolType) ||
1785
- awaitableProtocolType.details.typeParameters.length !== 1) {
1780
+ if (!awaitableClass ||
1781
+ !(0, types_1.isInstantiableClass)(awaitableClass) ||
1782
+ awaitableClass.details.typeParameters.length !== 1) {
1786
1783
  return types_1.UnknownType.create();
1787
1784
  }
1788
- const awaitableProtocolObj = types_1.ClassType.cloneAsInstance(awaitableProtocolType);
1785
+ const awaitableProtocolObj = types_1.ClassType.cloneAsInstance(awaitableClass);
1789
1786
  return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
1790
1787
  subtype = makeTopLevelTypeVarsConcrete(subtype);
1791
1788
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
@@ -1846,8 +1843,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1846
1843
  if (!isAsync && (0, types_1.isClassInstance)(subtype)) {
1847
1844
  const getItemReturnType = getTypeOfMagicMethodCall(subtype, '__getitem__', [
1848
1845
  {
1849
- type: intClassType && (0, types_1.isInstantiableClass)(intClassType)
1850
- ? types_1.ClassType.cloneAsInstance(intClassType)
1846
+ type: intClass && (0, types_1.isInstantiableClass)(intClass)
1847
+ ? types_1.ClassType.cloneAsInstance(intClass)
1851
1848
  : types_1.UnknownType.create(),
1852
1849
  },
1853
1850
  ], errorNode);
@@ -1876,7 +1873,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1876
1873
  // know anything more about them.
1877
1874
  nextReturnType = (0, typeUtils_1.mapSubtypes)(nextReturnType, (returnSubtype) => {
1878
1875
  if ((0, types_1.isTypeVar)(returnSubtype) && (0, types_1.isUnpackedVariadicTypeVar)(returnSubtype)) {
1879
- return objectType !== null && objectType !== void 0 ? objectType : types_1.UnknownType.create();
1876
+ return getObjectType();
1880
1877
  }
1881
1878
  return returnSubtype;
1882
1879
  });
@@ -1977,21 +1974,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1977
1974
  return isTypeHashable;
1978
1975
  }
1979
1976
  function getTypedDictClassType() {
1980
- return typedDictPrivateClassType && (0, types_1.isInstantiableClass)(typedDictPrivateClassType)
1981
- ? typedDictPrivateClassType
1982
- : undefined;
1977
+ return typedDictPrivateClass && (0, types_1.isInstantiableClass)(typedDictPrivateClass) ? typedDictPrivateClass : undefined;
1983
1978
  }
1984
1979
  function getTupleClassType() {
1985
- return tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType) ? tupleClassType : undefined;
1980
+ return tupleClass && (0, types_1.isInstantiableClass)(tupleClass) ? tupleClass : undefined;
1986
1981
  }
1987
1982
  function getObjectType() {
1988
- return objectType !== null && objectType !== void 0 ? objectType : types_1.UnknownType.create();
1983
+ return objectClass ? (0, typeUtils_1.convertToInstance)(objectClass) : types_1.UnknownType.create();
1989
1984
  }
1990
1985
  function getNoneType() {
1991
- return noneType !== null && noneType !== void 0 ? noneType : types_1.UnknownType.create();
1986
+ return noneTypeClass ? (0, typeUtils_1.convertToInstance)(noneTypeClass) : types_1.UnknownType.create();
1992
1987
  }
1993
1988
  function getUnionClassType() {
1994
- return unionClassType !== null && unionClassType !== void 0 ? unionClassType : types_1.UnknownType.create();
1989
+ return unionTypeClass !== null && unionTypeClass !== void 0 ? unionTypeClass : types_1.UnknownType.create();
1995
1990
  }
1996
1991
  function getTypingType(node, symbolName) {
1997
1992
  var _a;
@@ -2016,11 +2011,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2016
2011
  return getEffectiveTypeOfSymbol(symbol);
2017
2012
  }
2018
2013
  function checkCodeFlowTooComplex(node) {
2019
- const scopeNode = node.nodeType === 28 /* ParseNodeType.Function */ ? node : ParseTreeUtils.getExecutionScopeNode(node);
2014
+ const scopeNode = node.nodeType === 31 /* ParseNodeType.Function */ ? node : ParseTreeUtils.getExecutionScopeNode(node);
2020
2015
  const codeComplexity = AnalyzerNodeInfo.getCodeFlowComplexity(scopeNode);
2021
2016
  if (codeComplexity > exports.maxCodeComplexity) {
2022
2017
  let errorRange = scopeNode;
2023
- if (scopeNode.nodeType === 28 /* ParseNodeType.Function */) {
2018
+ if (scopeNode.nodeType === 31 /* ParseNodeType.Function */) {
2024
2019
  errorRange = scopeNode.name;
2025
2020
  }
2026
2021
  else if (scopeNode.nodeType === 36 /* ParseNodeType.Module */) {
@@ -2093,7 +2088,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2093
2088
  // of a Literal['xxx'] statement. If so, we will not treat
2094
2089
  // the string as a normal forward-declared type annotation.
2095
2090
  function isAnnotationLiteralValue(node) {
2096
- if (node.parent && node.parent.nodeType === 24 /* ParseNodeType.Index */) {
2091
+ if (node.parent && node.parent.nodeType === 27 /* ParseNodeType.Index */) {
2097
2092
  const baseType = getTypeOfExpression(node.parent.baseExpression).type;
2098
2093
  if (baseType && (0, types_1.isInstantiableClass)(baseType)) {
2099
2094
  if (types_1.ClassType.isSpecialBuiltIn(baseType, 'Literal')) {
@@ -2413,7 +2408,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2413
2408
  }
2414
2409
  }
2415
2410
  function assignTypeToTupleOrListNode(target, type, isTypeIncomplete, srcExpr) {
2416
- const targetExpressions = target.nodeType === 31 /* ParseNodeType.List */ ? target.entries : target.expressions;
2411
+ const targetExpressions = target.nodeType === 34 /* ParseNodeType.List */ ? target.entries : target.expressions;
2417
2412
  // Initialize the array of target types, one for each target.
2418
2413
  const targetTypes = new Array(targetExpressions.length);
2419
2414
  for (let i = 0; i < targetExpressions.length; i++) {
@@ -2447,7 +2442,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2447
2442
  if (sourceEntryTypes.length > targetTypes.length) {
2448
2443
  const removedEntries = sourceEntryTypes.splice(targetUnpackIndex, sourceEntryTypes.length - targetTypes.length + 1);
2449
2444
  let combinedTypes = (0, types_1.combineTypes)(removedEntries);
2450
- if (target.nodeType === 31 /* ParseNodeType.List */) {
2445
+ if (target.nodeType === 34 /* ParseNodeType.List */) {
2451
2446
  combinedTypes = stripLiteralValue(combinedTypes);
2452
2447
  }
2453
2448
  sourceEntryTypes.splice(targetUnpackIndex, 0, combinedTypes);
@@ -2464,7 +2459,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2464
2459
  // Have we accounted for all of the targets and sources? If not, we have a size mismatch.
2465
2460
  if (sourceEntryTypes.length !== targetExpressions.length) {
2466
2461
  const subDiag = diagAddendum.createAddendum();
2467
- subDiag.addMessage((target.nodeType === 31 /* ParseNodeType.List */
2462
+ subDiag.addMessage((target.nodeType === 34 /* ParseNodeType.List */
2468
2463
  ? localize_1.LocAddendum.listAssignmentMismatch()
2469
2464
  : localize_1.LocAddendum.tupleAssignmentMismatch()).format({
2470
2465
  type: printType(subtype),
@@ -2487,7 +2482,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2487
2482
  }
2488
2483
  });
2489
2484
  if (!diagAddendum.isEmpty()) {
2490
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, (target.nodeType === 31 /* ParseNodeType.List */
2485
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, (target.nodeType === 34 /* ParseNodeType.List */
2491
2486
  ? localize_1.LocMessage.listAssignmentMismatch()
2492
2487
  : localize_1.LocMessage.tupleAssignmentMismatch()).format({
2493
2488
  type: printType(type),
@@ -2536,22 +2531,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2536
2531
  // TypeVar, only the conditions that match the filter will be included.
2537
2532
  function makeTopLevelTypeVarsConcrete(type, makeParamSpecsConcrete = false, conditionFilter) {
2538
2533
  return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
2539
- var _a, _b;
2534
+ var _a;
2540
2535
  if ((0, types_1.isParamSpec)(subtype)) {
2541
2536
  if (subtype.paramSpecAccess === 'args') {
2542
- if (objectType && (0, types_1.isClassInstance)(objectType)) {
2543
- return makeTupleObject([{ type: objectType, isUnbounded: true }]);
2544
- }
2545
- return types_1.UnknownType.create();
2537
+ return makeTupleObject([{ type: getObjectType(), isUnbounded: true }]);
2546
2538
  }
2547
2539
  else if (subtype.paramSpecAccess === 'kwargs') {
2548
- if (dictClassType &&
2549
- (0, types_1.isInstantiableClass)(dictClassType) &&
2550
- strClassType &&
2551
- (0, types_1.isInstantiableClass)(strClassType) &&
2552
- objectType &&
2553
- (0, types_1.isClassInstance)(objectType)) {
2554
- return types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(dictClassType, [(0, typeUtils_1.convertToInstance)(strClassType), objectType],
2540
+ if (dictClass && (0, types_1.isInstantiableClass)(dictClass) && strClass && (0, types_1.isInstantiableClass)(strClass)) {
2541
+ return types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(dictClass, [(0, typeUtils_1.convertToInstance)(strClass), getObjectType()],
2555
2542
  /* isTypeArgumentExplicit */ true));
2556
2543
  }
2557
2544
  return types_1.UnknownType.create();
@@ -2569,18 +2556,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2569
2556
  // If it's in a union, convert to type or object.
2570
2557
  if (subtype.isVariadicInUnion) {
2571
2558
  if (types_1.TypeBase.isInstantiable(subtype)) {
2572
- if (typeClassType && (0, types_1.isInstantiableClass)(typeClassType)) {
2573
- return typeClassType;
2559
+ if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
2560
+ return typeClass;
2574
2561
  }
2575
2562
  }
2576
- else if (objectType) {
2577
- return objectType;
2563
+ else {
2564
+ return getObjectType();
2578
2565
  }
2579
2566
  return types_1.AnyType.create();
2580
2567
  }
2581
2568
  // Fall back to "*tuple[object, ...]".
2582
- return makeTupleObject([{ type: objectType !== null && objectType !== void 0 ? objectType : types_1.UnknownType.create(), isUnbounded: true }],
2583
- /* isUnpacked */ true);
2569
+ return makeTupleObject([{ type: getObjectType(), isUnbounded: true }], /* isUnpacked */ true);
2584
2570
  }
2585
2571
  if ((0, types_1.isTypeVar)(subtype)) {
2586
2572
  // If this is a recursive type alias placeholder
@@ -2613,7 +2599,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2613
2599
  return types_1.AnyType.create();
2614
2600
  }
2615
2601
  // Fall back to a bound of "object" if no bound is provided.
2616
- let boundType = (_b = (_a = subtype.details.boundType) !== null && _a !== void 0 ? _a : objectType) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
2602
+ let boundType = (_a = subtype.details.boundType) !== null && _a !== void 0 ? _a : getObjectType();
2617
2603
  boundType = types_1.TypeBase.isInstantiable(subtype) ? (0, typeUtils_1.convertToInstantiable)(boundType) : boundType;
2618
2604
  return (0, typeUtils_1.addConditionToType)(boundType, [{ typeVar: subtype, constraintIndex: 0 }]);
2619
2605
  }
@@ -2768,7 +2754,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2768
2754
  assignTypeToMemberAccessNode(target, type, isTypeIncomplete, srcExpr, expectedTypeDiagAddendum);
2769
2755
  break;
2770
2756
  }
2771
- case 24 /* ParseNodeType.Index */: {
2757
+ case 27 /* ParseNodeType.Index */: {
2772
2758
  const baseTypeResult = getTypeOfExpression(target.baseExpression, 2 /* EvaluatorFlags.IndexBaseDefaults */);
2773
2759
  getTypeOfIndexWithBaseType(target, baseTypeResult, {
2774
2760
  method: 'set',
@@ -2779,7 +2765,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2779
2765
  writeTypeCache(target, { type, isIncomplete: isTypeIncomplete }, 0 /* EvaluatorFlags.None */);
2780
2766
  break;
2781
2767
  }
2782
- case 31 /* ParseNodeType.List */:
2768
+ case 34 /* ParseNodeType.List */:
2783
2769
  case 52 /* ParseNodeType.Tuple */: {
2784
2770
  assignTypeToTupleOrListNode(target, type, isTypeIncomplete, srcExpr);
2785
2771
  break;
@@ -2856,7 +2842,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2856
2842
  suppressDiagnostics(node.typeExpression, () => {
2857
2843
  callResult = (0, constructors_1.validateConstructorArguments)(evaluatorInterface, node.typeExpression, [], concreteSubtype,
2858
2844
  /* skipUnknownArgCheck */ false,
2859
- /* inferenceContext */ undefined);
2845
+ /* inferenceContext */ undefined,
2846
+ /* signatureTracker */ undefined);
2860
2847
  });
2861
2848
  if (callResult && callResult.argumentErrors) {
2862
2849
  diagAddendum.addMessage(localize_1.LocMessage.exceptionTypeNotInstantiable().format({
@@ -2905,7 +2892,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2905
2892
  writeTypeCache(node, resultToCache, 0 /* EvaluatorFlags.None */);
2906
2893
  break;
2907
2894
  }
2908
- case 24 /* ParseNodeType.Index */: {
2895
+ case 27 /* ParseNodeType.Index */: {
2909
2896
  const baseTypeResult = getTypeOfExpression(node.baseExpression, 2 /* EvaluatorFlags.IndexBaseDefaults */);
2910
2897
  getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* EvaluatorFlags.None */);
2911
2898
  writeTypeCache(node, { type: types_1.UnboundType.create() }, 0 /* EvaluatorFlags.None */);
@@ -3155,8 +3142,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3155
3142
  // Find the parse node associated with the scope that is just inside of the
3156
3143
  // scope that declares the captured variable.
3157
3144
  const innerScopeNode = ScopeUtils.findTopNodeInScope(node, scopeHierarchy[scopeHierarchy.length - 2]);
3158
- if ((innerScopeNode === null || innerScopeNode === void 0 ? void 0 : innerScopeNode.nodeType) === 28 /* ParseNodeType.Function */ ||
3159
- (innerScopeNode === null || innerScopeNode === void 0 ? void 0 : innerScopeNode.nodeType) === 30 /* ParseNodeType.Lambda */ ||
3145
+ if ((innerScopeNode === null || innerScopeNode === void 0 ? void 0 : innerScopeNode.nodeType) === 31 /* ParseNodeType.Function */ ||
3146
+ (innerScopeNode === null || innerScopeNode === void 0 ? void 0 : innerScopeNode.nodeType) === 33 /* ParseNodeType.Lambda */ ||
3160
3147
  (innerScopeNode === null || innerScopeNode === void 0 ? void 0 : innerScopeNode.nodeType) === 10 /* ParseNodeType.Class */) {
3161
3148
  const innerScopeCodeFlowNode = AnalyzerNodeInfo.getFlowNode(innerScopeNode);
3162
3149
  if (innerScopeCodeFlowNode) {
@@ -3229,7 +3216,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3229
3216
  const memberName = node.parent.memberName.value;
3230
3217
  if (memberName === 'args' || memberName === 'kwargs') {
3231
3218
  const outerFunctionScope = ParseTreeUtils.getEnclosingClassOrFunction(enclosingScope);
3232
- if ((outerFunctionScope === null || outerFunctionScope === void 0 ? void 0 : outerFunctionScope.nodeType) === 28 /* ParseNodeType.Function */) {
3219
+ if ((outerFunctionScope === null || outerFunctionScope === void 0 ? void 0 : outerFunctionScope.nodeType) === 31 /* ParseNodeType.Function */) {
3233
3220
  enclosingScope = outerFunctionScope;
3234
3221
  }
3235
3222
  else if (!scopedTypeVarInfo.type.scopeId) {
@@ -3249,7 +3236,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3249
3236
  container: enclosingScope.name.value,
3250
3237
  }), node);
3251
3238
  }
3252
- type = types_1.TypeVarType.cloneForScopeId(type, ParseTreeUtils.getScopeIdForNode(enclosingScope), enclosingScope.name.value, enclosingScope.nodeType === 28 /* ParseNodeType.Function */
3239
+ type = types_1.TypeVarType.cloneForScopeId(type, ParseTreeUtils.getScopeIdForNode(enclosingScope), enclosingScope.name.value, enclosingScope.nodeType === 31 /* ParseNodeType.Function */
3253
3240
  ? 1 /* TypeVarScopeType.Function */
3254
3241
  : 0 /* TypeVarScopeType.Class */);
3255
3242
  }
@@ -3320,7 +3307,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3320
3307
  if (param.details.isDefaultExplicit || param.details.isParamSpec) {
3321
3308
  defaultType = (0, typeUtils_1.applySolvedTypeVars)(param, typeVarContext, { unknownIfNotFound: true });
3322
3309
  }
3323
- else if (param.details.isVariadic && tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
3310
+ else if (param.details.isVariadic && tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
3324
3311
  defaultType = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }],
3325
3312
  /* isUnpackedTuple */ true);
3326
3313
  }
@@ -3360,7 +3347,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3360
3347
  scopeUsesTypeParameterSyntax = !!curNode.typeParameters;
3361
3348
  nestedClassCount++;
3362
3349
  }
3363
- else if (curNode.nodeType === 28 /* ParseNodeType.Function */) {
3350
+ else if (curNode.nodeType === 31 /* ParseNodeType.Function */) {
3364
3351
  const functionType = getTypeOfFunctionPredecorated(curNode);
3365
3352
  if (functionType) {
3366
3353
  const functionDetails = functionType.details;
@@ -3724,8 +3711,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3724
3711
  // be reported elsewhere.
3725
3712
  return undefined;
3726
3713
  }
3727
- if ((0, typeUtils_1.isNoneInstance)(subtype) && noneType && (0, types_1.isClassInstance)(noneType)) {
3728
- const typeResult = getTypeOfBoundMember(node.memberName, noneType, memberName, usage, diag);
3714
+ if ((0, typeUtils_1.isNoneInstance)(subtype)) {
3715
+ (0, debug_1.assert)((0, types_1.isClassInstance)(subtype));
3716
+ const typeResult = getTypeOfBoundMember(node.memberName, subtype, memberName, usage, diag);
3729
3717
  if (typeResult && !typeResult.typeErrors) {
3730
3718
  type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType));
3731
3719
  if (typeResult.isIncomplete) {
@@ -3767,7 +3755,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3767
3755
  }
3768
3756
  }
3769
3757
  else {
3770
- type = getTypeOfMemberAccessWithBaseType(node, { type: functionObj !== null && functionObj !== void 0 ? functionObj : types_1.AnyType.create() }, usage, flags).type;
3758
+ type = getTypeOfMemberAccessWithBaseType(node, { type: functionClass ? (0, typeUtils_1.convertToInstance)(functionClass) : types_1.UnknownType.create() }, usage, flags).type;
3771
3759
  }
3772
3760
  break;
3773
3761
  }
@@ -4001,7 +3989,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4001
3989
  // If a Final instance variable is declared in the class body but is
4002
3990
  // being assigned within an __init__ method, it's allowed.
4003
3991
  const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(errorNode);
4004
- if (!enclosingFunctionNode || enclosingFunctionNode.name.value !== '__init__') {
3992
+ if (!enclosingFunctionNode ||
3993
+ enclosingFunctionNode.name.value !== '__init__' ||
3994
+ finalVarTypeDecl.inferredTypeSource !== undefined ||
3995
+ (0, types_1.isInstantiableClass)(classType)) {
4005
3996
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocMessage.finalReassigned().format({ name: memberName }));
4006
3997
  isDescriptorError = true;
4007
3998
  }
@@ -4210,7 +4201,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4210
4201
  const callResult = suppressDiagnostics(errorNode, () => {
4211
4202
  return validateCallArguments(errorNode, argList, { type: methodType },
4212
4203
  /* typeVarContext */ undefined,
4213
- /* skipUnknownArgCheck */ true);
4204
+ /* skipUnknownArgCheck */ true,
4205
+ /* inferenceContext */ undefined,
4206
+ /* signatureTracker */ undefined);
4214
4207
  });
4215
4208
  // Collect deprecation information associated with the member access method.
4216
4209
  let deprecationInfo;
@@ -4383,8 +4376,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4383
4376
  argList.push({
4384
4377
  argumentCategory: 0 /* ArgumentCategory.Simple */,
4385
4378
  typeResult: {
4386
- type: strClassType && (0, types_1.isInstantiableClass)(strClassType)
4387
- ? types_1.ClassType.cloneWithLiteral(types_1.ClassType.cloneAsInstance(strClassType), memberName)
4379
+ type: strClass && (0, types_1.isInstantiableClass)(strClass)
4380
+ ? types_1.ClassType.cloneWithLiteral(types_1.ClassType.cloneAsInstance(strClass), memberName)
4388
4381
  : types_1.AnyType.create(),
4389
4382
  },
4390
4383
  });
@@ -4407,7 +4400,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4407
4400
  }
4408
4401
  const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(accessMemberType));
4409
4402
  const callResult = validateCallArguments(errorNode, argList, { type: accessMemberType }, typeVarContext,
4410
- /* skipUnknownArgCheck */ true);
4403
+ /* skipUnknownArgCheck */ true,
4404
+ /* inferenceContext */ undefined,
4405
+ /* signatureTracker */ undefined);
4411
4406
  let isAsymmetricAccessor = false;
4412
4407
  if (usage.method === 'set') {
4413
4408
  isAsymmetricAccessor = isClassWithAsymmetricAttributeAccessor(classType);
@@ -4890,17 +4885,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4890
4885
  types_1.ClassType.isPartiallyEvaluated(concreteSubtype);
4891
4886
  const isFinalAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'Final');
4892
4887
  const isClassVarAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'ClassVar');
4893
- // Inlined TypedDicts are supported only for 'dict' (and not for 'Dict').
4894
- // This feature is currently experimental.
4895
- const supportsTypedDictTypeArg = AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures &&
4896
- types_1.ClassType.isBuiltIn(concreteSubtype, 'dict') &&
4897
- !types_1.ClassType.isBuiltIn(concreteSubtype, 'Dict');
4898
4888
  let typeArgs = getTypeArgs(node, flags, {
4899
4889
  isAnnotatedClass,
4900
4890
  hasCustomClassGetItem: hasCustomClassGetItem || !isGenericClass,
4901
4891
  isFinalAnnotation,
4902
4892
  isClassVarAnnotation,
4903
- supportsTypedDictTypeArg,
4904
4893
  });
4905
4894
  if (!isAnnotatedClass) {
4906
4895
  typeArgs = adjustTypeArgumentsForVariadicTypeVar(typeArgs, concreteSubtype.details.typeParameters, node);
@@ -5048,8 +5037,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5048
5037
  });
5049
5038
  }
5050
5039
  function makeTupleObject(typeArgs, isUnpackedTuple = false) {
5051
- if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
5052
- return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, typeArgs, /* isTypeArgumentExplicit */ true, isUnpackedTuple));
5040
+ if (tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
5041
+ return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClass, typeArgs, /* isTypeArgumentExplicit */ true, isUnpackedTuple));
5053
5042
  }
5054
5043
  return types_1.UnknownType.create();
5055
5044
  }
@@ -5209,7 +5198,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5209
5198
  useSpeculativeMode(node, () => {
5210
5199
  callResult = validateCallArguments(node, argList, { type: itemMethodType },
5211
5200
  /* typeVarContext */ undefined,
5212
- /* skipUnknownArgCheck */ true);
5201
+ /* skipUnknownArgCheck */ true,
5202
+ /* inferenceContext */ undefined,
5203
+ /* signatureTracker */ undefined);
5213
5204
  if (callResult.argumentErrors) {
5214
5205
  // If the object supports "__index__" magic method, convert
5215
5206
  // the index to an int and try again.
@@ -5223,7 +5214,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5223
5214
  altArgList[0].typeResult = { type: intType };
5224
5215
  }
5225
5216
  }
5226
- callResult = validateCallArguments(node, altArgList, { type: itemMethodType });
5217
+ callResult = validateCallArguments(node, altArgList, { type: itemMethodType },
5218
+ /* typeVarContext */ undefined,
5219
+ /* skipUnknownArgCheck */ true,
5220
+ /* inferenceContext */ undefined,
5221
+ /* signatureTracker */ undefined);
5227
5222
  // We were successful, so replace the arg list.
5228
5223
  if (!callResult.argumentErrors) {
5229
5224
  argList = altArgList;
@@ -5234,7 +5229,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5234
5229
  }
5235
5230
  callResult = validateCallArguments(node, argList, { type: itemMethodType },
5236
5231
  /* typeVarContext */ undefined,
5237
- /* skipUnknownArgCheck */ true);
5232
+ /* skipUnknownArgCheck */ true,
5233
+ /* inferenceContext */ undefined,
5234
+ /* signatureTracker */ undefined);
5238
5235
  return {
5239
5236
  type: (_d = callResult.returnType) !== null && _d !== void 0 ? _d : types_1.UnknownType.create(),
5240
5237
  isIncomplete: !!callResult.isTypeIncomplete,
@@ -5288,9 +5285,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5288
5285
  function getTypeArgs(node, flags, options) {
5289
5286
  const typeArgs = [];
5290
5287
  let adjFlags = flags;
5291
- if ((options === null || options === void 0 ? void 0 : options.isFinalAnnotation) || (options === null || options === void 0 ? void 0 : options.isClassVarAnnotation)) {
5288
+ if (options === null || options === void 0 ? void 0 : options.isFinalAnnotation) {
5292
5289
  adjFlags |= 131072 /* EvaluatorFlags.DisallowClassVar */ | 16 /* EvaluatorFlags.DisallowFinal */;
5293
5290
  }
5291
+ else if (options === null || options === void 0 ? void 0 : options.isClassVarAnnotation) {
5292
+ adjFlags |= 131072 /* EvaluatorFlags.DisallowClassVar */;
5293
+ // If the annotation is a variable within the body of a dataclass, a
5294
+ // Final is allowed within the ClassVar annotation. In all other cases,
5295
+ // it's disallowed.
5296
+ let disallowFinal = true;
5297
+ const enclosingClassNode = ParseTreeUtils.getEnclosingClass(node, /* stopeAtFunction */ true);
5298
+ if (enclosingClassNode) {
5299
+ const classTypeInfo = getTypeOfClass(enclosingClassNode);
5300
+ if (classTypeInfo && types_1.ClassType.isDataClass(classTypeInfo.classType)) {
5301
+ disallowFinal = false;
5302
+ }
5303
+ }
5304
+ if (disallowFinal) {
5305
+ adjFlags |= 16 /* EvaluatorFlags.DisallowFinal */;
5306
+ }
5307
+ }
5294
5308
  else {
5295
5309
  adjFlags &= ~(2 /* EvaluatorFlags.DoNotSpecialize */ |
5296
5310
  32 /* EvaluatorFlags.DisallowParamSpec */ |
@@ -5335,7 +5349,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5335
5349
  };
5336
5350
  }
5337
5351
  else {
5338
- typeResult = getTypeArg(expr, adjFlags, !!(options === null || options === void 0 ? void 0 : options.supportsTypedDictTypeArg) && argIndex === 0);
5352
+ typeResult = getTypeArg(expr, adjFlags);
5339
5353
  }
5340
5354
  return typeResult;
5341
5355
  };
@@ -5379,7 +5393,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5379
5393
  }
5380
5394
  return typeArgs;
5381
5395
  }
5382
- function getTypeArg(node, flags, supportsDictExpression) {
5396
+ function getTypeArg(node, flags) {
5383
5397
  let typeResult;
5384
5398
  let adjustedFlags = flags |
5385
5399
  128 /* EvaluatorFlags.ExpectingInstantiableType */ |
@@ -5389,7 +5403,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5389
5403
  if (fileInfo.isStubFile) {
5390
5404
  adjustedFlags |= 4 /* EvaluatorFlags.AllowForwardReferences */;
5391
5405
  }
5392
- if (node.nodeType === 31 /* ParseNodeType.List */) {
5406
+ if (node.nodeType === 34 /* ParseNodeType.List */) {
5393
5407
  typeResult = {
5394
5408
  type: types_1.UnknownType.create(),
5395
5409
  typeList: node.entries.map((entry) => {
@@ -5400,20 +5414,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5400
5414
  // Set the node's type so it isn't reevaluated later.
5401
5415
  setTypeResultForNode(node, { type: types_1.UnknownType.create() });
5402
5416
  }
5403
- else if (node.nodeType === 15 /* ParseNodeType.Dictionary */ && supportsDictExpression) {
5404
- const inlinedTypeDict = typedDictClassType && (0, types_1.isInstantiableClass)(typedDictClassType)
5405
- ? (0, typedDicts_1.createTypedDictTypeInlined)(evaluatorInterface, node, typedDictClassType)
5406
- : undefined;
5407
- const keyTypeFallback = strClassType && (0, types_1.isInstantiableClass)(strClassType) ? strClassType : types_1.UnknownType.create();
5408
- typeResult = {
5409
- type: keyTypeFallback,
5410
- inlinedTypeDict,
5411
- node,
5412
- };
5413
- }
5414
5417
  else {
5415
5418
  typeResult = { ...getTypeOfExpression(node, adjustedFlags), node };
5416
- if (node.nodeType === 15 /* ParseNodeType.Dictionary */) {
5419
+ if (node.nodeType === 18 /* ParseNodeType.Dictionary */) {
5417
5420
  addError(localize_1.LocMessage.dictInAnnotation(), node);
5418
5421
  }
5419
5422
  if ((flags & 131072 /* EvaluatorFlags.DisallowClassVar */) !== 0) {
@@ -5425,7 +5428,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5425
5428
  }
5426
5429
  return typeResult;
5427
5430
  }
5428
- function getTypeOfTuple(node, flags, inferenceContext) {
5431
+ function getTypeOfTuple(node, flags, inferenceContext, signatureTracker) {
5429
5432
  var _a;
5430
5433
  if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0 &&
5431
5434
  ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
@@ -5442,6 +5445,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5442
5445
  !inferenceContext) {
5443
5446
  return { type: makeTupleObject([]), isEmptyTupleShorthand: true };
5444
5447
  }
5448
+ flags &= ~(256 /* EvaluatorFlags.ExpectingTypeAnnotation */ |
5449
+ 8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
5450
+ 128 /* EvaluatorFlags.ExpectingInstantiableType */);
5445
5451
  // If the expected type is a union, recursively call for each of the subtypes
5446
5452
  // to find one that matches.
5447
5453
  let effectiveExpectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
@@ -5454,7 +5460,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5454
5460
  }
5455
5461
  if (!matchingSubtype) {
5456
5462
  const subtypeResult = useSpeculativeMode(node, () => {
5457
- return getTypeOfTupleWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype));
5463
+ return getTypeOfTupleWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(subtype),
5464
+ /* signatureTracker */ undefined);
5458
5465
  });
5459
5466
  if (subtypeResult && assignType(subtype, subtypeResult.type)) {
5460
5467
  matchingSubtype = subtype;
@@ -5466,14 +5473,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5466
5473
  }
5467
5474
  let expectedTypeDiagAddendum;
5468
5475
  if (effectiveExpectedType) {
5469
- const result = getTypeOfTupleWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType,
5470
- /* isTypeIncomplete */ false, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.signatureTracker));
5476
+ const result = getTypeOfTupleWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType), signatureTracker);
5471
5477
  if (result && !result.typeErrors) {
5472
5478
  return result;
5473
5479
  }
5474
5480
  expectedTypeDiagAddendum = result === null || result === void 0 ? void 0 : result.expectedTypeDiagAddendum;
5475
5481
  }
5476
- const typeResult = getTypeOfTupleInferred(node);
5482
+ const typeResult = getTypeOfTupleInferred(node, flags);
5477
5483
  // If there was an expected type of Any, replace the resulting type
5478
5484
  // with Any rather than return a type with unknowns.
5479
5485
  if (expectedTypeContainsAny) {
@@ -5481,12 +5487,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5481
5487
  }
5482
5488
  return { ...typeResult, expectedTypeDiagAddendum };
5483
5489
  }
5484
- function getTypeOfTupleWithContext(node, inferenceContext) {
5490
+ function getTypeOfTupleWithContext(node, flags, inferenceContext, signatureTracker) {
5485
5491
  inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
5486
5492
  if (!(0, types_1.isClassInstance)(inferenceContext.expectedType)) {
5487
5493
  return undefined;
5488
5494
  }
5489
- if (!tupleClassType || !(0, types_1.isInstantiableClass)(tupleClassType)) {
5495
+ if (!tupleClass || !(0, types_1.isInstantiableClass)(tupleClass)) {
5490
5496
  return undefined;
5491
5497
  }
5492
5498
  // Build an array of expected types.
@@ -5506,11 +5512,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5506
5512
  }
5507
5513
  }
5508
5514
  else {
5509
- const tupleTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(tupleClassType));
5510
- if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(tupleClassType), inferenceContext.expectedType, tupleTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
5515
+ const tupleTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(tupleClass));
5516
+ if (!(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(tupleClass), inferenceContext.expectedType, tupleTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
5511
5517
  return undefined;
5512
5518
  }
5513
- const specializedTuple = (0, typeUtils_1.applySolvedTypeVars)(tupleClassType, tupleTypeVarContext);
5519
+ const specializedTuple = (0, typeUtils_1.applySolvedTypeVars)(tupleClass, tupleTypeVarContext);
5514
5520
  if (!specializedTuple.typeArguments || specializedTuple.typeArguments.length !== 1) {
5515
5521
  return undefined;
5516
5522
  }
@@ -5519,10 +5525,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5519
5525
  expectedTypes.push(homogenousType);
5520
5526
  }
5521
5527
  }
5522
- const entryTypeResults = node.expressions.map((expr, index) => getTypeOfExpression(expr,
5523
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(index < expectedTypes.length ? expectedTypes[index] : undefined, inferenceContext.isTypeIncomplete, inferenceContext.signatureTracker)));
5528
+ const entryTypeResults = node.expressions.map((expr, index) => getTypeOfExpression(expr, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(index < expectedTypes.length ? expectedTypes[index] : undefined, inferenceContext.isTypeIncomplete), signatureTracker));
5524
5529
  const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
5525
- const type = makeTupleObject(buildTupleTypesList(entryTypeResults));
5530
+ const type = makeTupleObject(buildTupleTypesList(entryTypeResults, /* stripLiterals */ false));
5526
5531
  // Copy any expected type diag addenda for precision error reporting.
5527
5532
  let expectedTypeDiagAddendum;
5528
5533
  if (entryTypeResults.some((result) => result.expectedTypeDiagAddendum)) {
@@ -5535,10 +5540,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5535
5540
  }
5536
5541
  return { type, expectedTypeDiagAddendum, isIncomplete };
5537
5542
  }
5538
- function getTypeOfTupleInferred(node) {
5539
- const entryTypeResults = node.expressions.map((expr) => getTypeOfExpression(expr));
5543
+ function getTypeOfTupleInferred(node, flags) {
5544
+ const entryTypeResults = node.expressions.map((expr) => getTypeOfExpression(expr, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */));
5540
5545
  const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
5541
- const type = makeTupleObject(buildTupleTypesList(entryTypeResults));
5546
+ const type = makeTupleObject(buildTupleTypesList(entryTypeResults, (flags & 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */) !== 0));
5542
5547
  if (isIncomplete) {
5543
5548
  if ((0, typeUtils_1.getContainerDepth)(type) > maxInferredContainerDepth) {
5544
5549
  return { type: types_1.UnknownType.create() };
@@ -5546,7 +5551,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5546
5551
  }
5547
5552
  return { type, isIncomplete };
5548
5553
  }
5549
- function buildTupleTypesList(entryTypeResults) {
5554
+ function buildTupleTypesList(entryTypeResults, stripLiterals) {
5550
5555
  const entryTypes = [];
5551
5556
  for (const typeResult of entryTypeResults) {
5552
5557
  let possibleUnpackedTuple;
@@ -5575,7 +5580,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5575
5580
  entryTypes.push({ type: types_1.UnknownType.create(/* isIncomplete */ true), isUnbounded: false });
5576
5581
  }
5577
5582
  else {
5578
- entryTypes.push({ type: typeResult.type, isUnbounded: !!typeResult.unpackedType });
5583
+ const entryType = stripLiterals ? stripLiteralValue(typeResult.type) : typeResult.type;
5584
+ entryTypes.push({ type: entryType, isUnbounded: !!typeResult.unpackedType });
5579
5585
  }
5580
5586
  }
5581
5587
  // If there are multiple unbounded entries, combine all of them into a single
@@ -5588,7 +5594,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5588
5594
  }
5589
5595
  return entryTypes;
5590
5596
  }
5591
- function getTypeOfCall(node, flags, inferenceContext) {
5597
+ function getTypeOfCall(node, flags, inferenceContext, signatureTracker) {
5592
5598
  var _a;
5593
5599
  let baseTypeResult;
5594
5600
  // Check for the use of `type(x)` within a type annotation. This isn't
@@ -5602,7 +5608,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5602
5608
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeCallNotAllowed() + diag.getString(), node);
5603
5609
  }
5604
5610
  // Handle immediate calls of lambdas specially.
5605
- if (node.leftExpression.nodeType === 30 /* ParseNodeType.Lambda */) {
5611
+ if (node.leftExpression.nodeType === 33 /* ParseNodeType.Lambda */) {
5606
5612
  baseTypeResult = getTypeOfLambdaForCall(node, inferenceContext);
5607
5613
  }
5608
5614
  else {
@@ -5621,8 +5627,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5621
5627
  // If the inference context has an associated signature tracker, make sure
5622
5628
  // the base type of this call is not the same as one of the tracked signatures.
5623
5629
  // This is important for nested generic calls (e.g. "foo(foo(x))").
5624
- if (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.signatureTracker) {
5625
- baseTypeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(baseTypeResult.type, inferenceContext.signatureTracker, node.leftExpression.start);
5630
+ if (signatureTracker) {
5631
+ baseTypeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(baseTypeResult.type, signatureTracker, node.leftExpression.start);
5626
5632
  }
5627
5633
  if (!(0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
5628
5634
  if (node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ && node.leftExpression.value === 'super') {
@@ -5633,15 +5639,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5633
5639
  node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
5634
5640
  node.leftExpression.value === 'reveal_type') {
5635
5641
  // Handle the implicit "reveal_type" call.
5636
- typeResult = getTypeOfRevealType(node, inferenceContext);
5642
+ typeResult = getTypeOfRevealType(node, inferenceContext, signatureTracker);
5637
5643
  }
5638
5644
  else if ((0, types_1.isFunction)(baseTypeResult.type) && baseTypeResult.type.details.builtInName === 'reveal_type') {
5639
5645
  // Handle the "typing.reveal_type" call.
5640
- typeResult = getTypeOfRevealType(node, inferenceContext);
5646
+ typeResult = getTypeOfRevealType(node, inferenceContext, signatureTracker);
5641
5647
  }
5642
5648
  else if ((0, types_1.isFunction)(baseTypeResult.type) && baseTypeResult.type.details.builtInName === 'assert_type') {
5643
5649
  // Handle the "typing.assert_type" call.
5644
- typeResult = getTypeOfAssertType(node, inferenceContext);
5650
+ typeResult = getTypeOfAssertType(node, inferenceContext, signatureTracker);
5645
5651
  }
5646
5652
  else if ((0, types_1.isAnyOrUnknown)(baseTypeResult.type) &&
5647
5653
  node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
@@ -5657,7 +5663,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5657
5663
  else {
5658
5664
  const callResult = validateCallArguments(node, argList, baseTypeResult,
5659
5665
  /* typeVarContext */ undefined,
5660
- /* skipUnknownArgCheck */ false, inferenceContext);
5666
+ /* skipUnknownArgCheck */ false, inferenceContext, signatureTracker);
5661
5667
  typeResult.type = (_a = callResult.returnType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
5662
5668
  if (callResult.argumentErrors) {
5663
5669
  typeResult.typeErrors = true;
@@ -5709,7 +5715,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5709
5715
  // to determine the lambda's type. It needs to be inferred from the argument
5710
5716
  // types instead.
5711
5717
  function getTypeOfLambdaForCall(node, inferenceContext) {
5712
- (0, debug_1.assert)(node.leftExpression.nodeType === 30 /* ParseNodeType.Lambda */);
5718
+ (0, debug_1.assert)(node.leftExpression.nodeType === 33 /* ParseNodeType.Lambda */);
5713
5719
  const expectedType = types_1.FunctionType.createSynthesizedInstance('');
5714
5720
  expectedType.details.declaredReturnType = inferenceContext
5715
5721
  ? inferenceContext.expectedType
@@ -5751,7 +5757,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5751
5757
  }
5752
5758
  return typeResult;
5753
5759
  }
5754
- function getTypeOfAssertType(node, inferenceContext) {
5760
+ function getTypeOfAssertType(node, inferenceContext, signatureTracker) {
5755
5761
  if (node.arguments.length !== 2 ||
5756
5762
  node.arguments[0].argumentCategory !== 0 /* ArgumentCategory.Simple */ ||
5757
5763
  node.arguments[0].name !== undefined ||
@@ -5761,7 +5767,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5761
5767
  return { type: types_1.UnknownType.create() };
5762
5768
  }
5763
5769
  const arg0TypeResult = getTypeOfExpression(node.arguments[0].valueExpression,
5764
- /* flags */ undefined, inferenceContext);
5770
+ /* flags */ undefined, inferenceContext, signatureTracker);
5765
5771
  if (arg0TypeResult.isIncomplete) {
5766
5772
  return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
5767
5773
  }
@@ -5775,7 +5781,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5775
5781
  }
5776
5782
  return { type: arg0TypeResult.type };
5777
5783
  }
5778
- function getTypeOfRevealType(node, inferenceContext) {
5784
+ function getTypeOfRevealType(node, inferenceContext, signatureTracker) {
5779
5785
  let arg0Value;
5780
5786
  let expectedRevealTypeNode;
5781
5787
  let expectedRevealType;
@@ -5812,7 +5818,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5812
5818
  addError(localize_1.LocMessage.revealTypeArgs(), node);
5813
5819
  return { type: types_1.UnknownType.create() };
5814
5820
  }
5815
- const typeResult = getTypeOfExpression(arg0Value, /* flags */ undefined, inferenceContext);
5821
+ const typeResult = getTypeOfExpression(arg0Value, /* flags */ undefined, inferenceContext, signatureTracker);
5816
5822
  const type = typeResult.type;
5817
5823
  const exprString = ParseTreeUtils.printExpression(arg0Value);
5818
5824
  const typeString = printType(type, { expandTypeAlias: true });
@@ -5843,7 +5849,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5843
5849
  scope = ScopeUtils.getScopeForNode(curNode);
5844
5850
  // Stop when we get a valid scope that's not a list comprehension
5845
5851
  // scope. That includes lambdas, functions, classes, and modules.
5846
- if (scope && scope.type !== 1 /* ScopeType.ListComprehension */) {
5852
+ if (scope && scope.type !== 1 /* ScopeType.Comprehension */) {
5847
5853
  break;
5848
5854
  }
5849
5855
  curNode = curNode.parent;
@@ -6019,10 +6025,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6019
6025
  }
6020
6026
  else if (effectiveTargetClass &&
6021
6027
  !(0, types_1.isAnyOrUnknown)(effectiveTargetClass) &&
6022
- !(0, typeUtils_1.derivesFromAnyOrUnknown)(effectiveTargetClass) &&
6023
- objectType &&
6024
- (0, types_1.isClassInstance)(objectType)) {
6025
- resultType = types_1.ClassType.cloneAsInstantiable(objectType);
6028
+ !(0, typeUtils_1.derivesFromAnyOrUnknown)(effectiveTargetClass)) {
6029
+ resultType = objectClass !== null && objectClass !== void 0 ? objectClass : types_1.UnknownType.create();
6026
6030
  }
6027
6031
  else {
6028
6032
  resultType = types_1.UnknownType.create();
@@ -6063,9 +6067,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6063
6067
  return { type: resultIsInstance ? (0, typeUtils_1.convertToInstance)(nextBaseClassType) : nextBaseClassType };
6064
6068
  }
6065
6069
  // There's not much we can say about the type. Simply return object or type.
6066
- if (objectType && (0, types_1.isClassInstance)(objectType) && typeClassType && (0, types_1.isInstantiableClass)(typeClassType)) {
6070
+ if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
6067
6071
  return {
6068
- type: resultIsInstance ? objectType : (0, typeUtils_1.convertToInstance)(typeClassType),
6072
+ type: resultIsInstance ? getObjectType() : (0, typeUtils_1.convertToInstance)(typeClass),
6069
6073
  };
6070
6074
  }
6071
6075
  }
@@ -6095,7 +6099,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6095
6099
  // there will be only one argument list in expandedArgTypes, and all entries
6096
6100
  // (one for each argument) will be undefined. On subsequent calls, this
6097
6101
  // list will grow to include union expansions.
6098
- function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, inferenceContext) {
6102
+ function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker) {
6099
6103
  var _a, _b;
6100
6104
  const returnTypes = [];
6101
6105
  const matchedOverloads = [];
@@ -6131,7 +6135,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6131
6135
  // record any final types in the type cache.
6132
6136
  const callResult = useSpeculativeMode(errorNode, () => {
6133
6137
  return validateFunctionArgumentTypesWithContext(errorNode, matchResults, effectiveTypeVarContext,
6134
- /* skipUnknownArgCheck */ true, inferenceContext);
6138
+ /* skipUnknownArgCheck */ true, inferenceContext, signatureTracker);
6135
6139
  });
6136
6140
  if (callResult.isTypeIncomplete) {
6137
6141
  isTypeIncomplete = true;
@@ -6240,7 +6244,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6240
6244
  const finalTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : matchedOverloads[0].typeVarContext;
6241
6245
  finalTypeVarContext.unlock();
6242
6246
  finalTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(matchedOverloads[0].overload));
6243
- const finalCallResult = validateFunctionArgumentTypesWithContext(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck, inferenceContext);
6247
+ const finalCallResult = validateFunctionArgumentTypesWithContext(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6244
6248
  if (finalCallResult.isTypeIncomplete) {
6245
6249
  isTypeIncomplete = true;
6246
6250
  }
@@ -6306,7 +6310,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6306
6310
  // Create a list of potential overload matches based on arguments.
6307
6311
  types_1.OverloadedFunctionType.getOverloads(typeResult.type).forEach((overload) => {
6308
6312
  useSpeculativeMode(errorNode, () => {
6309
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
6313
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex,
6314
+ /* signatureTracker */ undefined);
6310
6315
  if (!matchResults.argumentErrors) {
6311
6316
  matches.push(matchResults);
6312
6317
  }
@@ -6337,7 +6342,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6337
6342
  return a.overloadIndex - b.overloadIndex;
6338
6343
  });
6339
6344
  }
6340
- function validateOverloadedFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck, inferenceContext) {
6345
+ function validateOverloadedFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker) {
6341
6346
  let filteredMatchResults = [];
6342
6347
  let contextFreeArgTypes;
6343
6348
  let isTypeIncomplete = !!typeResult.isIncomplete;
@@ -6352,7 +6357,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6352
6357
  // Consider only the functions that have the @overload decorator,
6353
6358
  // not the final function that omits the overload. This is the
6354
6359
  // intended behavior according to PEP 484.
6355
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
6360
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex, signatureTracker);
6356
6361
  if (!matchResults.argumentErrors) {
6357
6362
  filteredMatchResults.push(matchResults);
6358
6363
  }
@@ -6369,7 +6374,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6369
6374
  const functionName = typeResult.type.overloads[0].details.name || '<anonymous function>';
6370
6375
  const diagAddendum = new diagnostic_1.DiagnosticAddendum();
6371
6376
  const argTypes = argList.map((t) => {
6372
- const typeString = printType(getTypeOfArgument(t).type);
6377
+ const typeString = printType(getTypeOfArgument(t, /* inferenceContext */ undefined, signatureTracker).type);
6373
6378
  if (t.argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
6374
6379
  return `*${typeString}`;
6375
6380
  }
@@ -6408,7 +6413,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6408
6413
  const effectiveTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : new typeVarContext_1.TypeVarContext();
6409
6414
  effectiveTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeIds)(bestMatch.overload));
6410
6415
  effectiveTypeVarContext.unlock();
6411
- return validateFunctionArgumentTypesWithContext(errorNode, bestMatch, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
6416
+ return validateFunctionArgumentTypesWithContext(errorNode, bestMatch, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6412
6417
  }
6413
6418
  // If there is only one possible arg/param match among the overloads,
6414
6419
  // use the normal type matching mechanism because it is faster and
@@ -6420,7 +6425,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6420
6425
  }
6421
6426
  let expandedArgTypes = [argList.map((arg) => undefined)];
6422
6427
  while (true) {
6423
- const callResult = validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, filteredMatchResults, typeVarContext, skipUnknownArgCheck, inferenceContext);
6428
+ const callResult = validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, filteredMatchResults, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6424
6429
  if (callResult.isTypeIncomplete) {
6425
6430
  isTypeIncomplete = true;
6426
6431
  }
@@ -6518,7 +6523,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6518
6523
  // list, specializes the call based on arg types, and returns the
6519
6524
  // specialized type of the return value. If it detects an error along
6520
6525
  // the way, it emits a diagnostic and sets argumentErrors to true.
6521
- function validateCallArguments(errorNode, argList, callTypeResult, typeVarContext, skipUnknownArgCheck = false, inferenceContext, recursionCount = 0) {
6526
+ function validateCallArguments(errorNode, argList, callTypeResult, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount = 0) {
6522
6527
  let argumentErrors = false;
6523
6528
  let isTypeIncomplete = false;
6524
6529
  let specializedInitSelfType;
@@ -6537,7 +6542,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6537
6542
  }
6538
6543
  let returnType = mapSubtypesExpandTypeVars(callTypeResult.type, { sortSubtypes: true }, (expandedSubtype, unexpandedSubtype, isLastIteration) => {
6539
6544
  return useSpeculativeMode(isLastIteration ? undefined : errorNode, () => {
6540
- const callResult = validateCallArgumentsForSubtype(errorNode, argList, expandedSubtype, unexpandedSubtype, !!callTypeResult.isIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
6545
+ const callResult = validateCallArgumentsForSubtype(errorNode, argList, expandedSubtype, unexpandedSubtype, !!callTypeResult.isIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount);
6541
6546
  if (callResult.argumentErrors) {
6542
6547
  argumentErrors = true;
6543
6548
  }
@@ -6567,7 +6572,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6567
6572
  overloadsUsedForCall,
6568
6573
  };
6569
6574
  }
6570
- function validateCallArgumentsForSubtype(errorNode, argList, expandedCallType, unexpandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount) {
6575
+ function validateCallArgumentsForSubtype(errorNode, argList, expandedCallType, unexpandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount) {
6571
6576
  switch (expandedCallType.category) {
6572
6577
  case 3 /* TypeCategory.Never */:
6573
6578
  case 1 /* TypeCategory.Unknown */:
@@ -6578,17 +6583,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6578
6583
  if (!isCallTypeIncomplete) {
6579
6584
  argList.forEach((arg) => {
6580
6585
  if (arg.valueExpression && !isSpeculativeModeInUse(arg.valueExpression)) {
6581
- getTypeOfArgument(arg);
6586
+ getTypeOfArgument(arg, /* inferenceContext */ undefined, signatureTracker);
6582
6587
  }
6583
6588
  });
6584
6589
  }
6585
6590
  return { returnType: expandedCallType };
6586
6591
  }
6587
6592
  case 4 /* TypeCategory.Function */: {
6588
- return validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext);
6593
+ return validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6589
6594
  }
6590
6595
  case 5 /* TypeCategory.OverloadedFunction */: {
6591
- return validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext);
6596
+ return validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6592
6597
  }
6593
6598
  case 6 /* TypeCategory.Class */: {
6594
6599
  if ((0, typeUtils_1.isNoneInstance)(expandedCallType)) {
@@ -6596,16 +6601,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6596
6601
  return { argumentErrors: true };
6597
6602
  }
6598
6603
  if (types_1.TypeBase.isInstantiable(expandedCallType)) {
6599
- return validateCallForInstantiableClass(errorNode, argList, expandedCallType, unexpandedCallType, skipUnknownArgCheck, inferenceContext);
6604
+ return validateCallForInstantiableClass(errorNode, argList, expandedCallType, unexpandedCallType, skipUnknownArgCheck, inferenceContext, signatureTracker);
6600
6605
  }
6601
- return validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
6606
+ return validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount);
6602
6607
  }
6603
6608
  // TypeVars should have been expanded in most cases,
6604
6609
  // but we still need to handle the case of Type[T] where
6605
6610
  // T is a constrained type that contains a union. We also
6606
6611
  // need to handle recursive type aliases.
6607
6612
  case 9 /* TypeCategory.TypeVar */: {
6608
- return validateCallArguments(errorNode, argList, { type: (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expandedCallType), isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
6613
+ return validateCallArguments(errorNode, argList, { type: (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expandedCallType), isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount);
6609
6614
  }
6610
6615
  case 7 /* TypeCategory.Module */: {
6611
6616
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.moduleNotCallable(), errorNode);
@@ -6614,7 +6619,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6614
6619
  }
6615
6620
  return { argumentErrors: true };
6616
6621
  }
6617
- function validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext) {
6622
+ function validateCallForFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker) {
6618
6623
  var _a;
6619
6624
  if (types_1.TypeBase.isInstantiable(expandedCallType)) {
6620
6625
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.callableNotInstantiable().format({
@@ -6634,14 +6639,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6634
6639
  const result = {
6635
6640
  returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList, /* includesTypes */ false),
6636
6641
  };
6637
- validateFunctionArguments(errorNode, argList, { type: expandedCallType }, effectiveTypeVarContext, skipUnknownArgCheck);
6642
+ validateFunctionArguments(errorNode, argList, { type: expandedCallType }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6638
6643
  return result;
6639
6644
  }
6640
6645
  // Handle the NewType specially, replacing the normal return type.
6641
6646
  if (expandedCallType.details.builtInName === 'NewType') {
6642
6647
  return { returnType: createNewType(errorNode, argList) };
6643
6648
  }
6644
- const functionResult = validateFunctionArguments(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
6649
+ const functionResult = validateFunctionArguments(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6645
6650
  let isTypeIncomplete = !!functionResult.isTypeIncomplete;
6646
6651
  let returnType = functionResult.returnType;
6647
6652
  let argumentErrors = !!functionResult.argumentErrors;
@@ -6748,13 +6753,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6748
6753
  }
6749
6754
  return { symbol, symbolName, classType, hasImplementation };
6750
6755
  }
6751
- function validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext) {
6756
+ function validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker) {
6752
6757
  var _a, _b;
6753
6758
  // Handle the 'cast' call as a special case.
6754
6759
  if (expandedCallType.overloads[0].details.builtInName === 'cast' && argList.length === 2) {
6755
6760
  return { returnType: evaluateCastCall(argList, errorNode) };
6756
6761
  }
6757
- const callResult = validateOverloadedFunctionArguments(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext);
6762
+ const callResult = validateOverloadedFunctionArguments(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker);
6758
6763
  let returnType = (_a = callResult.returnType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
6759
6764
  let isTypeIncomplete = !!callResult.isTypeIncomplete;
6760
6765
  let argumentErrors = !!callResult.argumentErrors;
@@ -6781,7 +6786,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6781
6786
  specializedInitSelfType: callResult.specializedInitSelfType,
6782
6787
  };
6783
6788
  }
6784
- function validateCallForInstantiableClass(errorNode, argList, expandedCallType, unexpandedCallType, skipUnknownArgCheck, inferenceContext) {
6789
+ function validateCallForInstantiableClass(errorNode, argList, expandedCallType, unexpandedCallType, skipUnknownArgCheck, inferenceContext, signatureTracker) {
6785
6790
  var _a, _b;
6786
6791
  if (expandedCallType.literalValue !== undefined) {
6787
6792
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.literalNotCallable(), errorNode);
@@ -6798,11 +6803,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6798
6803
  return { returnType: types_1.UnknownType.create(), argumentErrors: true };
6799
6804
  }
6800
6805
  // Validate the constructor arguments.
6801
- (0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedCallType, skipUnknownArgCheck, inferenceContext);
6806
+ (0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedCallType, skipUnknownArgCheck, inferenceContext, signatureTracker);
6802
6807
  // The one-parameter form of "type" returns the class
6803
6808
  // for the specified object.
6804
6809
  if (expandedCallType.details.name === 'type' && argList.length === 1) {
6805
- const argType = getTypeOfArgument(argList[0]).type;
6810
+ const argType = getTypeOfArgument(argList[0],
6811
+ /* inferenceContext */ undefined, signatureTracker).type;
6806
6812
  const returnType = (0, typeUtils_1.mapSubtypes)(argType, (subtype) => {
6807
6813
  if ((0, types_1.isInstantiableClass)(subtype) && subtype.details.effectiveMetaclass) {
6808
6814
  return subtype.details.effectiveMetaclass;
@@ -6864,7 +6870,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6864
6870
  if (initTypeResult && (0, types_1.isOverloadedFunction)(initTypeResult.type)) {
6865
6871
  validateOverloadedFunctionArguments(errorNode, argList, { type: initTypeResult.type },
6866
6872
  /* typeVarContext */ undefined, skipUnknownArgCheck,
6867
- /* inferenceContext */ undefined);
6873
+ /* inferenceContext */ undefined, signatureTracker);
6868
6874
  }
6869
6875
  return result;
6870
6876
  }
@@ -6926,7 +6932,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6926
6932
  }), errorNode);
6927
6933
  }
6928
6934
  // Assume this is a call to the constructor.
6929
- const constructorResult = (0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedCallType, skipUnknownArgCheck, inferenceContext);
6935
+ const constructorResult = (0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedCallType, skipUnknownArgCheck, inferenceContext, signatureTracker);
6930
6936
  const overloadsUsedForCall = constructorResult.overloadsUsedForCall;
6931
6937
  const argumentErrors = constructorResult.argumentErrors;
6932
6938
  const isTypeIncomplete = constructorResult.isTypeIncomplete;
@@ -6945,7 +6951,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6945
6951
  returnType.details.mro.some((baseClass) => (0, types_1.isInstantiableClass)(baseClass) && types_1.ClassType.isBuiltIn(baseClass, 'type'))) {
6946
6952
  let newClassName = '__class_' + returnType.details.name;
6947
6953
  if (argList.length === 3) {
6948
- const firstArgType = getTypeOfArgument(argList[0]).type;
6954
+ const firstArgType = getTypeOfArgument(argList[0],
6955
+ /* inferenceContext */ undefined, signatureTracker).type;
6949
6956
  if ((0, types_1.isClassInstance)(firstArgType) &&
6950
6957
  types_1.ClassType.isBuiltIn(firstArgType, 'str') &&
6951
6958
  typeof firstArgType.literalValue === 'string') {
@@ -6961,7 +6968,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6961
6968
  }
6962
6969
  return { returnType, overloadsUsedForCall, argumentErrors, isTypeIncomplete };
6963
6970
  }
6964
- function validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount) {
6971
+ function validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount) {
6965
6972
  var _a;
6966
6973
  const callDiag = new diagnostic_1.DiagnosticAddendum();
6967
6974
  const callMethodResult = getTypeOfBoundMember(errorNode, expandedCallType, '__call__',
@@ -6974,7 +6981,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6974
6981
  }) + callDiag.getString(), errorNode);
6975
6982
  return { returnType: types_1.UnknownType.create(), argumentErrors: true };
6976
6983
  }
6977
- const callResult = validateCallArguments(errorNode, argList, { type: callMethodType }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
6984
+ const callResult = validateCallArguments(errorNode, argList, { type: callMethodType }, typeVarContext, skipUnknownArgCheck, inferenceContext, signatureTracker, recursionCount);
6978
6985
  let returnType = (_a = callResult.returnType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
6979
6986
  if ((0, types_1.isTypeVar)(unexpandedCallType) &&
6980
6987
  types_1.TypeBase.isInstantiable(unexpandedCallType) &&
@@ -6994,7 +7001,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6994
7001
  function evaluateCastCall(argList, errorNode) {
6995
7002
  // Verify that the cast is necessary.
6996
7003
  const castToType = getTypeOfArgumentExpectingType(argList[0], { enforceTypeAnnotationRules: true }).type;
6997
- let castFromType = getTypeOfArgument(argList[1]).type;
7004
+ let castFromType = getTypeOfArgument(argList[1],
7005
+ /* inferenceContext */ undefined,
7006
+ /* signatureTracker */ undefined).type;
6998
7007
  if (castFromType.specialForm) {
6999
7008
  castFromType = castFromType.specialForm;
7000
7009
  }
@@ -7010,16 +7019,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7010
7019
  return (0, typeUtils_1.convertToInstance)(castToType);
7011
7020
  }
7012
7021
  // Expands any unpacked tuples within an argument list.
7013
- function expandArgList(argList) {
7022
+ function expandArgList(argList, signatureTracker) {
7014
7023
  var _a;
7015
7024
  const expandedArgList = [];
7016
7025
  for (const arg of argList) {
7017
7026
  if (arg.argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
7018
- const argType = getTypeOfArgument(arg).type;
7027
+ const argType = getTypeOfArgument(arg, /* inferenceContext */ undefined, signatureTracker).type;
7019
7028
  // If this is a tuple with specified element types, use those
7020
7029
  // specified types rather than using the more generic iterator
7021
7030
  // type which will be a union of all element types.
7022
- const combinedArgType = (0, typeUtils_1.combineSameSizedTuples)(makeTopLevelTypeVarsConcrete(argType), tupleClassType);
7031
+ const combinedArgType = (0, typeUtils_1.combineSameSizedTuples)(makeTopLevelTypeVarsConcrete(argType), tupleClass);
7023
7032
  if ((0, types_1.isClassInstance)(combinedArgType) && (0, typeUtils_1.isTupleClass)(combinedArgType)) {
7024
7033
  const tupleTypeArgs = (_a = combinedArgType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [];
7025
7034
  if (tupleTypeArgs.length !== 1 || !tupleTypeArgs[0].isUnbounded) {
@@ -7057,7 +7066,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7057
7066
  // function. This matching is done based on positions and keywords. Type evaluation and
7058
7067
  // validation is left to the caller.
7059
7068
  // This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
7060
- function matchFunctionArgumentsToParameters(errorNode, argList, typeResult, overloadIndex) {
7069
+ function matchFunctionArgumentsToParameters(errorNode, argList, typeResult, overloadIndex, signatureTracker) {
7061
7070
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
7062
7071
  const paramDetails = (0, parameterUtils_1.getParameterListDetails)(typeResult.type);
7063
7072
  let argIndex = 0;
@@ -7066,7 +7075,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7066
7075
  let isTypeIncomplete = !!typeResult.isIncomplete;
7067
7076
  let isVariadicTypeVarFullyMatched = false;
7068
7077
  // Expand any unpacked tuples in the arg list.
7069
- argList = expandArgList(argList);
7078
+ argList = expandArgList(argList, signatureTracker);
7070
7079
  // Build a map of parameters by name.
7071
7080
  const paramMap = new Map();
7072
7081
  paramDetails.params.forEach((paramInfo) => {
@@ -7076,7 +7085,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7076
7085
  paramMap.set(param.name, {
7077
7086
  argsNeeded: param.category === 0 /* ParameterCategory.Simple */ && !param.hasDefault ? 1 : 0,
7078
7087
  argsReceived: 0,
7079
- isPositionalOnly: paramInfo.source === parameterUtils_1.ParameterSource.PositionOnly,
7088
+ isPositionalOnly: paramInfo.kind === parameterUtils_1.ParameterKind.Positional,
7080
7089
  });
7081
7090
  }
7082
7091
  });
@@ -7190,7 +7199,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7190
7199
  // If this is an unpacked iterable, we will conservatively assume that it
7191
7200
  // might have zero iterations unless we can tell from its type that it
7192
7201
  // definitely has at least one iterable value.
7193
- const argType = getTypeOfArgument(argList[argIndex]).type;
7202
+ const argType = getTypeOfArgument(argList[argIndex],
7203
+ /* inferenceContext */ undefined, signatureTracker).type;
7194
7204
  if ((0, types_1.isClassInstance)(argType) &&
7195
7205
  (0, typeUtils_1.isTupleClass)(argType) &&
7196
7206
  !(0, typeUtils_1.isUnboundedTupleClass)(argType) &&
@@ -7225,7 +7235,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7225
7235
  (0, types_1.isVariadicTypeVar)(paramType);
7226
7236
  if (argList[argIndex].argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
7227
7237
  let isArgCompatibleWithVariadic = false;
7228
- const argTypeResult = getTypeOfArgument(argList[argIndex]);
7238
+ const argTypeResult = getTypeOfArgument(argList[argIndex],
7239
+ /* inferenceContext */ undefined, signatureTracker);
7229
7240
  let listElementType;
7230
7241
  let advanceToNextArg = false;
7231
7242
  // Handle the case where *args is being passed to a function defined
@@ -7460,7 +7471,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7460
7471
  while (argIndex < argList.length) {
7461
7472
  if (argList[argIndex].argumentCategory === 2 /* ArgumentCategory.UnpackedDictionary */) {
7462
7473
  // Verify that the type used in this expression is a SupportsKeysAndGetItem[str, T].
7463
- const argType = getTypeOfArgument(argList[argIndex], (0, typeUtils_1.makeInferenceContext)(paramDetails.unpackedKwargsTypedDictType)).type;
7474
+ const argType = getTypeOfArgument(argList[argIndex], (0, typeUtils_1.makeInferenceContext)(paramDetails.unpackedKwargsTypedDictType), signatureTracker).type;
7464
7475
  if ((0, types_1.isAnyOrUnknown)(argType)) {
7465
7476
  unpackedDictionaryArgType = argType;
7466
7477
  }
@@ -7546,20 +7557,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7546
7557
  }
7547
7558
  else {
7548
7559
  const strObjType = getBuiltInObject(errorNode, 'str');
7549
- if (supportsKeysAndGetItemProtocolType &&
7550
- (0, types_1.isInstantiableClass)(supportsKeysAndGetItemProtocolType) &&
7560
+ if (supportsKeysAndGetItemClass &&
7561
+ (0, types_1.isInstantiableClass)(supportsKeysAndGetItemClass) &&
7551
7562
  strObjType &&
7552
7563
  (0, types_1.isClassInstance)(strObjType)) {
7553
- const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(supportsKeysAndGetItemProtocolType));
7564
+ const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(supportsKeysAndGetItemClass));
7554
7565
  let isValidMappingType = false;
7555
7566
  // If this was a TypeVar (e.g. for pseudo-generic classes),
7556
7567
  // don't emit this error.
7557
7568
  if ((0, types_1.isTypeVar)(argType)) {
7558
7569
  isValidMappingType = true;
7559
7570
  }
7560
- else if (assignType(types_1.ClassType.cloneAsInstance(supportsKeysAndGetItemProtocolType), argType,
7571
+ else if (assignType(types_1.ClassType.cloneAsInstance(supportsKeysAndGetItemClass), argType,
7561
7572
  /* diag */ undefined, mappingTypeVarContext)) {
7562
- const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(supportsKeysAndGetItemProtocolType, mappingTypeVarContext);
7573
+ const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(supportsKeysAndGetItemClass, mappingTypeVarContext);
7563
7574
  const typeArgs = specializedMapping.typeArguments;
7564
7575
  if (typeArgs && typeArgs.length >= 2) {
7565
7576
  if (assignType(strObjType, typeArgs[0])) {
@@ -7675,7 +7686,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7675
7686
  // Handle the case where a *args: P.args (or *args: Any) is passed as an
7676
7687
  // argument to a function that accepts a ParamSpec.
7677
7688
  if (typeResult.type.details.paramSpec) {
7678
- const argTypeResult = getTypeOfArgument(argList[argIndex]);
7689
+ const argTypeResult = getTypeOfArgument(argList[argIndex],
7690
+ /* inferenceContext */ undefined, signatureTracker);
7679
7691
  const argType = argTypeResult.type;
7680
7692
  if (argTypeResult.isIncomplete) {
7681
7693
  isTypeIncomplete = true;
@@ -7798,7 +7810,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7798
7810
  if ((0, types_1.isVariadicTypeVar)(paramType) && !paramType.isVariadicInUnion) {
7799
7811
  const tupleTypeArgs = variadicArgs.map((argParam) => {
7800
7812
  var _a;
7801
- const argType = getTypeOfArgument(argParam.argument).type;
7813
+ const argType = getTypeOfArgument(argParam.argument,
7814
+ /* inferenceContext */ undefined, signatureTracker).type;
7802
7815
  const containsVariadicTypeVar = (0, types_1.isUnpackedVariadicTypeVar)(argType) ||
7803
7816
  ((0, types_1.isClassInstance)(argType) &&
7804
7817
  (0, typeUtils_1.isTupleClass)(argType) &&
@@ -7878,10 +7891,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7878
7891
  // After having matched arguments with parameters, this function evaluates the
7879
7892
  // types of each argument expression and validates that the resulting type is
7880
7893
  // compatible with the declared type of the corresponding parameter.
7881
- function validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
7882
- var _a, _b;
7894
+ function validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext, signatureTracker) {
7895
+ var _a;
7883
7896
  const type = matchResults.overload;
7884
- const signatureTracker = (_a = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.signatureTracker) !== null && _a !== void 0 ? _a : new typeUtils_1.UniqueSignatureTracker();
7897
+ if (!signatureTracker) {
7898
+ signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7899
+ }
7885
7900
  matchResults.overload = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(matchResults.overload, signatureTracker, errorNode.start);
7886
7901
  // Can we safely ignore the inference context (either because it's not provided
7887
7902
  // or will have no effect)? If so, we can eliminate a bunch of extra work.
@@ -7889,7 +7904,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7889
7904
  (0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) ||
7890
7905
  (0, types_1.isNever)(inferenceContext.expectedType) ||
7891
7906
  !type.details.declaredReturnType ||
7892
- !(0, typeUtils_1.requiresSpecialization)((_b = types_1.FunctionType.getSpecializedReturnType(type)) !== null && _b !== void 0 ? _b : types_1.UnknownType.create())) {
7907
+ !(0, typeUtils_1.requiresSpecialization)((_a = types_1.FunctionType.getSpecializedReturnType(type)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create())) {
7893
7908
  return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck);
7894
7909
  }
7895
7910
  const effectiveReturnType = getFunctionEffectiveReturnType(type);
@@ -7972,7 +7987,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7972
7987
  }
7973
7988
  return validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck);
7974
7989
  }
7975
- function validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck = false) {
7990
+ function validateFunctionArgumentTypes(errorNode, matchResults, typeVarContext, signatureTracker, skipUnknownArgCheck) {
7976
7991
  const type = matchResults.overload;
7977
7992
  let isTypeIncomplete = matchResults.isTypeIncomplete;
7978
7993
  let argumentErrors = false;
@@ -8202,7 +8217,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8202
8217
  types_1.ClassType.isBuiltIn(specializedReturnType, ['TypeGuard', 'TypeIs']) &&
8203
8218
  specializedReturnType.typeArguments &&
8204
8219
  specializedReturnType.typeArguments.length > 0) {
8205
- if (boolClassType && (0, types_1.isInstantiableClass)(boolClassType)) {
8220
+ if (boolClass && (0, types_1.isInstantiableClass)(boolClass)) {
8206
8221
  let typeGuardType = specializedReturnType.typeArguments[0];
8207
8222
  // If the first argument is a simple (non-constrained) TypeVar,
8208
8223
  // associate that TypeVar with the resulting TypeGuard type.
@@ -8217,7 +8232,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8217
8232
  }
8218
8233
  }
8219
8234
  const useTypeIsSemantics = types_1.ClassType.isBuiltIn(specializedReturnType, 'TypeIs');
8220
- specializedReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForTypeGuard(boolClassType, typeGuardType, useTypeIsSemantics));
8235
+ specializedReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForTypeGuard(boolClass, typeGuardType, useTypeIsSemantics));
8221
8236
  }
8222
8237
  }
8223
8238
  const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
@@ -8289,11 +8304,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8289
8304
  // Tries to assign the call arguments to the function parameter
8290
8305
  // list and reports any mismatches in types or counts. Returns the
8291
8306
  // specialized return type of the call.
8292
- function validateFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
8293
- var _a;
8294
- const signatureTracker = (_a = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.signatureTracker) !== null && _a !== void 0 ? _a : new typeUtils_1.UniqueSignatureTracker();
8307
+ function validateFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck = false, inferenceContext, signatureTracker) {
8308
+ if (!signatureTracker) {
8309
+ signatureTracker = new typeUtils_1.UniqueSignatureTracker();
8310
+ }
8295
8311
  typeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(typeResult.type, signatureTracker, errorNode.start);
8296
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, typeResult, 0);
8312
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, typeResult, 0, signatureTracker);
8297
8313
  if (matchResults.argumentErrors) {
8298
8314
  // Evaluate types of all args. This will ensure that referenced symbols are
8299
8315
  // not reported as unaccessed.
@@ -8308,7 +8324,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8308
8324
  overloadsUsedForCall: [],
8309
8325
  };
8310
8326
  }
8311
- return validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck, (0, typeUtils_1.makeInferenceContext)(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete, signatureTracker));
8327
+ return validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck, (0, typeUtils_1.makeInferenceContext)(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete), signatureTracker);
8312
8328
  }
8313
8329
  // Determines whether the specified argument list satisfies the function
8314
8330
  // signature bound to the specified ParamSpec. Return value indicates success.
@@ -8344,7 +8360,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8344
8360
  if (!paramSpecType) {
8345
8361
  paramSpecType = (0, typeUtils_1.convertTypeToParamSpecValue)(paramSpec);
8346
8362
  }
8347
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: paramSpecType }, 0);
8363
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: paramSpecType }, 0, signatureTracker);
8348
8364
  const functionType = matchResults.overload;
8349
8365
  const srcTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(paramSpecType));
8350
8366
  if (matchResults.argumentErrors) {
@@ -8369,7 +8385,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8369
8385
  let argumentErrors = false;
8370
8386
  let argErrorNode;
8371
8387
  for (const arg of argList) {
8372
- const argType = (_a = getTypeOfArgument(arg)) === null || _a === void 0 ? void 0 : _a.type;
8388
+ const argType = (_a = getTypeOfArgument(arg, /* inferenceContext */ undefined, signatureTracker)) === null || _a === void 0 ? void 0 : _a.type;
8373
8389
  const isArgTypeCompatible = argType && ((0, types_1.isTypeSame)(argType, paramSpec, { ignoreTypeFlags: true }) || (0, types_1.isAnyOrUnknown)(argType));
8374
8390
  if (arg.argumentCategory === 1 /* ArgumentCategory.UnpackedList */ && !sawArgs && isArgTypeCompatible) {
8375
8391
  sawArgs = true;
@@ -8394,7 +8410,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8394
8410
  }
8395
8411
  return { argumentErrors, typeVarContexts: [srcTypeVarContext] };
8396
8412
  }
8397
- const result = validateFunctionArgumentTypes(errorNode, matchResults, srcTypeVarContext, signatureTracker);
8413
+ const result = validateFunctionArgumentTypes(errorNode, matchResults, srcTypeVarContext, signatureTracker,
8414
+ /* skipUnknownArgCheck */ undefined);
8398
8415
  return { argumentErrors: !!result.argumentErrors, typeVarContexts: [srcTypeVarContext] };
8399
8416
  }
8400
8417
  function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, options) {
@@ -8457,7 +8474,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8457
8474
  16 /* EvaluatorFlags.DisallowFinal */ |
8458
8475
  2 /* EvaluatorFlags.DoNotSpecialize */
8459
8476
  : 2 /* EvaluatorFlags.DoNotSpecialize */ | 16 /* EvaluatorFlags.DisallowFinal */;
8460
- const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete), signatureTracker));
8477
+ const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete)), signatureTracker);
8461
8478
  argType = exprTypeResult.type;
8462
8479
  // If the type includes multiple instances of a generic function
8463
8480
  // signature, force the type arguments for the duplicates to have
@@ -8492,7 +8509,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8492
8509
  argType = argParam.argType;
8493
8510
  }
8494
8511
  else {
8495
- const argTypeResult = getTypeOfArgument(argParam.argument);
8512
+ const argTypeResult = getTypeOfArgument(argParam.argument,
8513
+ /* inferenceContext */ undefined, signatureTracker);
8496
8514
  argType = argTypeResult.type;
8497
8515
  if (argTypeResult.isIncomplete) {
8498
8516
  isTypeIncomplete = true;
@@ -8937,12 +8955,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8937
8955
  }
8938
8956
  function getParamSpecDefaultType(node, isPep695Syntax) {
8939
8957
  const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
8940
- if (node.nodeType === 18 /* ParseNodeType.Ellipsis */) {
8958
+ if (node.nodeType === 21 /* ParseNodeType.Ellipsis */) {
8941
8959
  types_1.FunctionType.addDefaultParameters(functionType);
8942
8960
  functionType.details.flags |= 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
8943
8961
  return functionType;
8944
8962
  }
8945
- if (node.nodeType === 31 /* ParseNodeType.List */) {
8963
+ if (node.nodeType === 34 /* ParseNodeType.List */) {
8946
8964
  node.entries.forEach((paramExpr, index) => {
8947
8965
  const typeResult = getTypeOfExpressionExpectingType(paramExpr, {
8948
8966
  allowTypeVarsWithoutScopeId: true,
@@ -9072,7 +9090,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9072
9090
  /* typeParamNodes */ undefined, () => typeParameters);
9073
9091
  }
9074
9092
  function getBooleanValue(node) {
9075
- if (node.nodeType === 11 /* ParseNodeType.Constant */) {
9093
+ if (node.nodeType === 14 /* ParseNodeType.Constant */) {
9076
9094
  if (node.constType === 15 /* KeywordType.False */) {
9077
9095
  return false;
9078
9096
  }
@@ -9126,9 +9144,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9126
9144
  let baseClass = getTypeOfArgumentExpectingType(argList[1]).type;
9127
9145
  let isBaseClassAny = false;
9128
9146
  if ((0, types_1.isAnyOrUnknown)(baseClass)) {
9129
- if (objectType && (0, types_1.isClassInstance)(objectType)) {
9130
- baseClass = types_1.ClassType.cloneAsInstantiable(objectType);
9131
- }
9147
+ baseClass = objectClass !== null && objectClass !== void 0 ? objectClass : types_1.UnknownType.create();
9132
9148
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeAnyOrUnknown(), (_c = argList[1].node) !== null && _c !== void 0 ? _c : errorNode);
9133
9149
  isBaseClassAny = true;
9134
9150
  }
@@ -9190,12 +9206,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9190
9206
  // Implements the semantics of the multi-parameter variant of the "type" call.
9191
9207
  function createClassFromMetaclass(errorNode, argList, metaclass) {
9192
9208
  const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
9193
- const arg0Type = getTypeOfArgument(argList[0]).type;
9209
+ const arg0Type = getTypeOfArgument(argList[0],
9210
+ /* inferenceContext */ undefined,
9211
+ /* signatureTracker */ undefined).type;
9194
9212
  if (!(0, types_1.isClassInstance)(arg0Type) || !types_1.ClassType.isBuiltIn(arg0Type, 'str')) {
9195
9213
  return undefined;
9196
9214
  }
9197
9215
  const className = arg0Type.literalValue || '_';
9198
- const arg1Type = getTypeOfArgument(argList[1]).type;
9216
+ const arg1Type = getTypeOfArgument(argList[1],
9217
+ /* inferenceContext */ undefined,
9218
+ /* signatureTracker */ undefined).type;
9199
9219
  // TODO - properly handle case where tuple of base classes is provided.
9200
9220
  if (!(0, types_1.isClassInstance)(arg1Type) || !(0, typeUtils_1.isTupleClass)(arg1Type) || arg1Type.tupleTypeArguments === undefined) {
9201
9221
  return undefined;
@@ -9207,7 +9227,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9207
9227
  classType.details.baseClasses.push(specializedType);
9208
9228
  }
9209
9229
  else {
9210
- addExpectedClassDiagnostic(typeArg.type, argList[1].valueExpression || errorNode);
9230
+ classType.details.baseClasses.push(types_1.UnknownType.create());
9211
9231
  }
9212
9232
  });
9213
9233
  if (!(0, typeUtils_1.computeMroLinearization)(classType)) {
@@ -9218,7 +9238,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9218
9238
  function getTypeOfConstant(node, flags) {
9219
9239
  let type;
9220
9240
  if (node.constType === 26 /* KeywordType.None */) {
9221
- type = (flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) !== 0 ? noneClassType : noneType;
9241
+ if (noneTypeClass) {
9242
+ type =
9243
+ (flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) !== 0
9244
+ ? noneTypeClass
9245
+ : (0, typeUtils_1.convertToInstance)(noneTypeClass);
9246
+ }
9222
9247
  }
9223
9248
  else if (node.constType === 33 /* KeywordType.True */ ||
9224
9249
  node.constType === 15 /* KeywordType.False */ ||
@@ -9258,7 +9283,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9258
9283
  (0, debug_1.assert)(magicMethodType !== undefined);
9259
9284
  return validateCallArguments(errorNode, functionArgs, { type: magicMethodType },
9260
9285
  /* typeVarContext */ undefined,
9261
- /* skipUnknownArgCheck */ true, inferenceContext);
9286
+ /* skipUnknownArgCheck */ true, inferenceContext,
9287
+ /* signatureTracker */ undefined);
9262
9288
  });
9263
9289
  // If there were errors with the expected type, try
9264
9290
  // to evaluate without the expected type.
@@ -9267,7 +9293,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9267
9293
  (0, debug_1.assert)(magicMethodType !== undefined);
9268
9294
  return validateCallArguments(errorNode, functionArgs, { type: magicMethodType },
9269
9295
  /* typeVarContext */ undefined,
9270
- /* skipUnknownArgCheck */ true);
9296
+ /* skipUnknownArgCheck */ true,
9297
+ /* inferenceContext */ undefined,
9298
+ /* signatureTracker */ undefined);
9271
9299
  });
9272
9300
  }
9273
9301
  if (callResult.argumentErrors) {
@@ -9286,15 +9314,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9286
9314
  return handleSubtype(subtype);
9287
9315
  }
9288
9316
  if ((0, typeUtils_1.isNoneInstance)(subtype)) {
9289
- if (objectType && (0, types_1.isClassInstance)(objectType)) {
9317
+ if (objectClass && (0, types_1.isInstantiableClass)(objectClass)) {
9290
9318
  // Use 'object' for 'None'.
9291
- return handleSubtype(objectType);
9319
+ return handleSubtype((0, typeUtils_1.convertToInstance)(objectClass));
9292
9320
  }
9293
9321
  }
9294
9322
  if ((0, typeUtils_1.isNoneTypeClass)(subtype)) {
9295
- if (typeClassType && (0, types_1.isInstantiableClass)(typeClassType)) {
9323
+ if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
9296
9324
  // Use 'type' for 'type[None]'.
9297
- return handleSubtype(types_1.ClassType.cloneAsInstance(typeClassType));
9325
+ return handleSubtype(types_1.ClassType.cloneAsInstance(typeClass));
9298
9326
  }
9299
9327
  }
9300
9328
  magicMethodSupported = false;
@@ -9325,7 +9353,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9325
9353
  return;
9326
9354
  }
9327
9355
  const subtypeResult = useSpeculativeMode(node, () => {
9328
- return getTypeOfDictionaryWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype));
9356
+ return getTypeOfDictionaryWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(subtype));
9329
9357
  });
9330
9358
  if (subtypeResult && assignType(subtype, subtypeResult.type)) {
9331
9359
  // If this is the first result we're seeing or it's the first result
@@ -9342,15 +9370,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9342
9370
  let expectedTypeDiagAddendum = undefined;
9343
9371
  if (effectiveExpectedType) {
9344
9372
  expectedTypeDiagAddendum = new diagnostic_1.DiagnosticAddendum();
9345
- const result = getTypeOfDictionaryWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType), expectedTypeDiagAddendum);
9373
+ const result = getTypeOfDictionaryWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType), expectedTypeDiagAddendum);
9346
9374
  if (result) {
9347
9375
  return result;
9348
9376
  }
9349
9377
  }
9350
- const result = getTypeOfDictionaryInferred(node, /* hasExpectedType */ !!inferenceContext);
9378
+ const result = getTypeOfDictionaryInferred(node, flags, /* hasExpectedType */ !!inferenceContext);
9351
9379
  return { ...result, expectedTypeDiagAddendum };
9352
9380
  }
9353
- function getTypeOfDictionaryWithContext(node, inferenceContext, expectedDiagAddendum) {
9381
+ function getTypeOfDictionaryWithContext(node, flags, inferenceContext, expectedDiagAddendum) {
9354
9382
  inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
9355
9383
  let concreteExpectedType = makeTopLevelTypeVarsConcrete(inferenceContext.expectedType);
9356
9384
  if (!(0, types_1.isClassInstance)(concreteExpectedType)) {
@@ -9367,7 +9395,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9367
9395
  concreteExpectedType = types_1.TypeBase.cloneForCondition(concreteExpectedType, undefined);
9368
9396
  const expectedTypedDictEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, concreteExpectedType);
9369
9397
  // Infer the key and value types if possible.
9370
- const keyValueTypeResult = getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
9398
+ const keyValueTypeResult = getKeyAndValueTypesFromDictionary(node, flags, keyTypes, valueTypes,
9371
9399
  /* forceStrictInference */ true,
9372
9400
  /* isValueTypeInvariant */ true,
9373
9401
  /* expectedKeyType */ undefined,
@@ -9425,7 +9453,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9425
9453
  }
9426
9454
  }
9427
9455
  // Infer the key and value types if possible.
9428
- const keyValueResult = getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
9456
+ const keyValueResult = getKeyAndValueTypesFromDictionary(node, flags, keyTypes, valueTypes,
9429
9457
  /* forceStrictInference */ true, isValueTypeInvariant, expectedKeyType, expectedValueType, undefined, expectedDiagAddendum);
9430
9458
  if (keyValueResult.isIncomplete) {
9431
9459
  isIncomplete = true;
@@ -9444,7 +9472,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9444
9472
  }
9445
9473
  // Attempts to infer the type of a dictionary statement. If hasExpectedType
9446
9474
  // is true, strict inference is used for the subexpressions.
9447
- function getTypeOfDictionaryInferred(node, hasExpectedType) {
9475
+ function getTypeOfDictionaryInferred(node, flags, hasExpectedType) {
9448
9476
  const fallbackType = hasExpectedType ? types_1.AnyType.create() : types_1.UnknownType.create();
9449
9477
  let keyType = fallbackType;
9450
9478
  let valueType = fallbackType;
@@ -9454,7 +9482,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9454
9482
  let isIncomplete = false;
9455
9483
  let typeErrors = false;
9456
9484
  // Infer the key and value types if possible.
9457
- const keyValueResult = getKeyAndValueTypesFromDictionary(node, keyTypeResults, valueTypeResults,
9485
+ const keyValueResult = getKeyAndValueTypesFromDictionary(node, flags, keyTypeResults, valueTypeResults,
9458
9486
  /* forceStrictInference */ hasExpectedType,
9459
9487
  /* isValueTypeInvariant */ false);
9460
9488
  if (keyValueResult.isIncomplete) {
@@ -9498,16 +9526,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9498
9526
  }
9499
9527
  return { type, isIncomplete, typeErrors };
9500
9528
  }
9501
- function getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes, forceStrictInference, isValueTypeInvariant, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum) {
9529
+ function getKeyAndValueTypesFromDictionary(node, flags, keyTypes, valueTypes, forceStrictInference, isValueTypeInvariant, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum) {
9502
9530
  let isIncomplete = false;
9503
9531
  let typeErrors = false;
9532
+ // Mask out some of the flags that are not applicable for a dictionary key
9533
+ // even if it appears within an inlined TypedDict annotation.
9534
+ const keyFlags = flags &
9535
+ ~(256 /* EvaluatorFlags.ExpectingTypeAnnotation */ |
9536
+ 8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
9537
+ 128 /* EvaluatorFlags.ExpectingInstantiableType */);
9504
9538
  // Infer the key and value types if possible.
9505
9539
  node.entries.forEach((entryNode, index) => {
9506
- var _a, _b, _c, _d;
9540
+ var _a, _b, _c;
9507
9541
  let addUnknown = true;
9508
- if (entryNode.nodeType === 17 /* ParseNodeType.DictionaryKeyEntry */) {
9509
- const keyTypeResult = getTypeOfExpression(entryNode.keyExpression,
9510
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedKeyType !== null && expectedKeyType !== void 0 ? expectedKeyType : (forceStrictInference ? types_1.NeverType.createNever() : undefined)));
9542
+ if (entryNode.nodeType === 20 /* ParseNodeType.DictionaryKeyEntry */) {
9543
+ const keyTypeResult = getTypeOfExpression(entryNode.keyExpression, keyFlags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedKeyType !== null && expectedKeyType !== void 0 ? expectedKeyType : (forceStrictInference ? types_1.NeverType.createNever() : undefined)));
9511
9544
  if (keyTypeResult.isIncomplete) {
9512
9545
  isIncomplete = true;
9513
9546
  }
@@ -9530,14 +9563,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9530
9563
  expectedTypedDictEntries.knownItems.has(keyType.literalValue)) {
9531
9564
  const effectiveValueType = expectedTypedDictEntries.knownItems.get(keyType.literalValue).valueType;
9532
9565
  entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
9533
- valueTypeResult = getTypeOfExpression(entryNode.valueExpression,
9534
- /* flags */ undefined, entryInferenceContext);
9566
+ valueTypeResult = getTypeOfExpression(entryNode.valueExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, entryInferenceContext);
9535
9567
  }
9536
9568
  else {
9537
9569
  const effectiveValueType = expectedValueType !== null && expectedValueType !== void 0 ? expectedValueType : (forceStrictInference ? types_1.NeverType.createNever() : undefined);
9538
9570
  entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
9539
- valueTypeResult = getTypeOfExpression(entryNode.valueExpression,
9540
- /* flags */ undefined, entryInferenceContext);
9571
+ valueTypeResult = getTypeOfExpression(entryNode.valueExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, entryInferenceContext);
9541
9572
  }
9542
9573
  if (entryInferenceContext && !valueTypeResult.typeErrors) {
9543
9574
  const fromExpectedType = inferTypeArgFromExpectedEntryType(entryInferenceContext, [valueTypeResult.type], !isValueTypeInvariant);
@@ -9570,17 +9601,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9570
9601
  }
9571
9602
  addUnknown = false;
9572
9603
  }
9573
- else if (entryNode.nodeType === 16 /* ParseNodeType.DictionaryExpandEntry */) {
9604
+ else if (entryNode.nodeType === 19 /* ParseNodeType.DictionaryExpandEntry */) {
9574
9605
  let expectedType;
9575
9606
  if (expectedKeyType && expectedValueType) {
9576
- if (supportsKeysAndGetItemProtocolType && (0, types_1.isInstantiableClass)(supportsKeysAndGetItemProtocolType)) {
9577
- expectedType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(supportsKeysAndGetItemProtocolType, [expectedKeyType, expectedValueType],
9607
+ if (supportsKeysAndGetItemClass && (0, types_1.isInstantiableClass)(supportsKeysAndGetItemClass)) {
9608
+ expectedType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(supportsKeysAndGetItemClass, [expectedKeyType, expectedValueType],
9578
9609
  /* isTypeArgumentExplicit */ true));
9579
9610
  }
9580
9611
  }
9581
9612
  const entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(expectedType);
9582
- let unexpandedTypeResult = getTypeOfExpression(entryNode.expandExpression,
9583
- /* flags */ undefined, entryInferenceContext);
9613
+ let unexpandedTypeResult = getTypeOfExpression(entryNode.expandExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, entryInferenceContext);
9584
9614
  if (entryInferenceContext && !unexpandedTypeResult.typeErrors) {
9585
9615
  const fromExpectedType = inferTypeArgFromExpectedEntryType(entryInferenceContext, [unexpandedTypeResult.type], !isValueTypeInvariant);
9586
9616
  if (fromExpectedType) {
@@ -9599,8 +9629,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9599
9629
  }
9600
9630
  else if ((0, types_1.isClassInstance)(unexpandedType) && types_1.ClassType.isTypedDictClass(unexpandedType)) {
9601
9631
  // Handle dictionary expansion for a TypedDict.
9602
- if (strClassType && (0, types_1.isInstantiableClass)(strClassType)) {
9603
- const strObject = types_1.ClassType.cloneAsInstance(strClassType);
9632
+ if (strClass && (0, types_1.isInstantiableClass)(strClass)) {
9633
+ const strObject = types_1.ClassType.cloneAsInstance(strClass);
9604
9634
  const tdEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, unexpandedType,
9605
9635
  /* allowNarrowed */ true);
9606
9636
  tdEntries.knownItems.forEach((entry, name) => {
@@ -9616,20 +9646,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9616
9646
  keyTypes.push({ node: entryNode, type: types_1.ClassType.cloneAsInstance(strObject) });
9617
9647
  valueTypes.push({
9618
9648
  node: entryNode,
9619
- type: (_c = (_b = (_a = tdEntries.extraItems) === null || _a === void 0 ? void 0 : _a.valueType) !== null && _b !== void 0 ? _b : objectType) !== null && _c !== void 0 ? _c : types_1.UnknownType.create(),
9649
+ type: (_b = (_a = tdEntries.extraItems) === null || _a === void 0 ? void 0 : _a.valueType) !== null && _b !== void 0 ? _b : getObjectType(),
9620
9650
  });
9621
9651
  }
9622
9652
  addUnknown = false;
9623
9653
  }
9624
9654
  }
9625
- else if (supportsKeysAndGetItemProtocolType &&
9626
- (0, types_1.isInstantiableClass)(supportsKeysAndGetItemProtocolType)) {
9627
- const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(supportsKeysAndGetItemProtocolType));
9628
- supportsKeysAndGetItemProtocolType = (0, typeUtils_1.selfSpecializeClass)(supportsKeysAndGetItemProtocolType);
9629
- if (assignType(types_1.ClassType.cloneAsInstance(supportsKeysAndGetItemProtocolType), unexpandedType,
9655
+ else if (supportsKeysAndGetItemClass && (0, types_1.isInstantiableClass)(supportsKeysAndGetItemClass)) {
9656
+ const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(supportsKeysAndGetItemClass));
9657
+ supportsKeysAndGetItemClass = (0, typeUtils_1.selfSpecializeClass)(supportsKeysAndGetItemClass);
9658
+ if (assignType(types_1.ClassType.cloneAsInstance(supportsKeysAndGetItemClass), unexpandedType,
9630
9659
  /* diag */ undefined, mappingTypeVarContext,
9631
9660
  /* srcTypeVarContext */ undefined, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */)) {
9632
- const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(supportsKeysAndGetItemProtocolType, mappingTypeVarContext);
9661
+ const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(supportsKeysAndGetItemClass, mappingTypeVarContext);
9633
9662
  const typeArgs = specializedMapping.typeArguments;
9634
9663
  if (typeArgs && typeArgs.length >= 2) {
9635
9664
  if (forceStrictInference || index < maxEntriesToUseForInference) {
@@ -9644,8 +9673,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9644
9673
  }
9645
9674
  }
9646
9675
  }
9647
- else if (entryNode.nodeType === 32 /* ParseNodeType.ListComprehension */) {
9648
- const dictEntryTypeResult = getElementTypeFromListComprehension(entryNode, expectedValueType, expectedKeyType);
9676
+ else if (entryNode.nodeType === 11 /* ParseNodeType.Comprehension */) {
9677
+ const dictEntryTypeResult = getElementTypeFromComprehension(entryNode, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, expectedValueType, expectedKeyType);
9649
9678
  const dictEntryType = dictEntryTypeResult.type;
9650
9679
  if (dictEntryTypeResult.isIncomplete) {
9651
9680
  isIncomplete = true;
@@ -9655,7 +9684,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9655
9684
  }
9656
9685
  // The result should be a tuple.
9657
9686
  if ((0, types_1.isClassInstance)(dictEntryType) && (0, typeUtils_1.isTupleClass)(dictEntryType)) {
9658
- const typeArgs = (_d = dictEntryType.tupleTypeArguments) === null || _d === void 0 ? void 0 : _d.map((t) => t.type);
9687
+ const typeArgs = (_c = dictEntryType.tupleTypeArguments) === null || _c === void 0 ? void 0 : _c.map((t) => t.type);
9659
9688
  if (typeArgs && typeArgs.length === 2) {
9660
9689
  if (forceStrictInference || index < maxEntriesToUseForInference) {
9661
9690
  keyTypes.push({ node: entryNode, type: typeArgs[0] });
@@ -9677,12 +9706,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9677
9706
  function getTypeOfListOrSet(node, flags, inferenceContext) {
9678
9707
  var _a;
9679
9708
  if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0 &&
9680
- node.nodeType === 31 /* ParseNodeType.List */ &&
9709
+ node.nodeType === 34 /* ParseNodeType.List */ &&
9681
9710
  ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
9682
9711
  const diag = new diagnostic_1.DiagnosticAddendum();
9683
9712
  diag.addMessage(localize_1.LocAddendum.useListInstead());
9684
9713
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.listInAnnotation() + diag.getString(), node);
9685
9714
  }
9715
+ flags &= ~(256 /* EvaluatorFlags.ExpectingTypeAnnotation */ |
9716
+ 8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
9717
+ 128 /* EvaluatorFlags.ExpectingInstantiableType */);
9686
9718
  // If the expected type is a union, recursively call for each of the subtypes
9687
9719
  // to find one that matches.
9688
9720
  let effectiveExpectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
@@ -9695,7 +9727,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9695
9727
  return;
9696
9728
  }
9697
9729
  const subtypeResult = useSpeculativeMode(node, () => {
9698
- return getTypeOfListOrSetWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype));
9730
+ return getTypeOfListOrSetWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(subtype));
9699
9731
  });
9700
9732
  if (subtypeResult && assignType(subtype, subtypeResult.type)) {
9701
9733
  // If this is the first result we're seeing or it's the first result
@@ -9711,19 +9743,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9711
9743
  }
9712
9744
  let expectedTypeDiagAddendum;
9713
9745
  if (effectiveExpectedType) {
9714
- const result = getTypeOfListOrSetWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType));
9746
+ const result = getTypeOfListOrSetWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType));
9715
9747
  if (result && !result.typeErrors) {
9716
9748
  return result;
9717
9749
  }
9718
9750
  expectedTypeDiagAddendum = result === null || result === void 0 ? void 0 : result.expectedTypeDiagAddendum;
9719
9751
  }
9720
- const typeResult = getTypeOfListOrSetInferred(node, /* hasExpectedType */ inferenceContext !== undefined);
9752
+ const typeResult = getTypeOfListOrSetInferred(node, flags,
9753
+ /* hasExpectedType */ inferenceContext !== undefined);
9721
9754
  return { ...typeResult, expectedTypeDiagAddendum };
9722
9755
  }
9723
9756
  // Attempts to determine the type of a list or set statement based on an expected type.
9724
9757
  // Returns undefined if that type cannot be honored.
9725
- function getTypeOfListOrSetWithContext(node, inferenceContext) {
9726
- const builtInClassName = node.nodeType === 31 /* ParseNodeType.List */ ? 'list' : 'set';
9758
+ function getTypeOfListOrSetWithContext(node, flags, inferenceContext) {
9759
+ const builtInClassName = node.nodeType === 34 /* ParseNodeType.List */ ? 'list' : 'set';
9727
9760
  inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
9728
9761
  let isIncomplete = false;
9729
9762
  let typeErrors = false;
@@ -9736,12 +9769,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9736
9769
  const expectedTypeDiagAddendum = new diagnostic_1.DiagnosticAddendum();
9737
9770
  node.entries.forEach((entry) => {
9738
9771
  let entryTypeResult;
9739
- if (entry.nodeType === 32 /* ParseNodeType.ListComprehension */) {
9740
- entryTypeResult = getElementTypeFromListComprehension(entry, expectedEntryType);
9772
+ if (entry.nodeType === 11 /* ParseNodeType.Comprehension */) {
9773
+ entryTypeResult = getElementTypeFromComprehension(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, expectedEntryType);
9741
9774
  }
9742
9775
  else {
9743
- entryTypeResult = getTypeOfExpression(entry,
9744
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedEntryType));
9776
+ entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedEntryType));
9745
9777
  }
9746
9778
  entryTypes.push(entryTypeResult.type);
9747
9779
  if (entryTypeResult.isIncomplete) {
@@ -9795,8 +9827,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9795
9827
  return specializedListOrSet.typeArguments[0];
9796
9828
  }
9797
9829
  // Attempts to infer the type of a list or set statement with no "expected type".
9798
- function getTypeOfListOrSetInferred(node, hasExpectedType) {
9799
- const builtInClassName = node.nodeType === 31 /* ParseNodeType.List */ ? 'list' : 'set';
9830
+ function getTypeOfListOrSetInferred(node, flags, hasExpectedType) {
9831
+ const builtInClassName = node.nodeType === 34 /* ParseNodeType.List */ ? 'list' : 'set';
9800
9832
  const verifyHashable = node.nodeType === 45 /* ParseNodeType.Set */;
9801
9833
  let isEmptyContainer = false;
9802
9834
  let isIncomplete = false;
@@ -9804,11 +9836,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9804
9836
  let entryTypes = [];
9805
9837
  node.entries.forEach((entry, index) => {
9806
9838
  let entryTypeResult;
9807
- if (entry.nodeType === 32 /* ParseNodeType.ListComprehension */ && !entry.isGenerator) {
9808
- entryTypeResult = getElementTypeFromListComprehension(entry);
9839
+ if (entry.nodeType === 11 /* ParseNodeType.Comprehension */ && !entry.isGenerator) {
9840
+ entryTypeResult = getElementTypeFromComprehension(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */);
9809
9841
  }
9810
9842
  else {
9811
- entryTypeResult = getTypeOfExpression(entry);
9843
+ entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */);
9812
9844
  }
9813
9845
  if (entryTypeResult.isIncomplete) {
9814
9846
  isIncomplete = true;
@@ -10124,14 +10156,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10124
10156
  }
10125
10157
  return { type: functionType, isIncomplete, typeErrors };
10126
10158
  }
10127
- function getTypeOfListComprehension(node, inferenceContext) {
10159
+ function getTypeOfComprehension(node, flags, inferenceContext) {
10128
10160
  let isIncomplete = false;
10129
10161
  let typeErrors = false;
10130
10162
  // If any of the "for" clauses are marked async or any of the "if" clauses
10131
10163
  // or any clause other than the leftmost "for" contain an "await" operator,
10132
10164
  // it is treated as an async generator.
10133
10165
  let isAsync = node.forIfNodes.some((comp, index) => {
10134
- if (comp.nodeType === 33 /* ParseNodeType.ListComprehensionFor */ && comp.isAsync) {
10166
+ if (comp.nodeType === 12 /* ParseNodeType.ComprehensionFor */ && comp.isAsync) {
10135
10167
  return true;
10136
10168
  }
10137
10169
  return index > 0 && ParseTreeUtils.containsAwaitNode(comp);
@@ -10142,7 +10174,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10142
10174
  }
10143
10175
  const builtInIteratorType = getTypingType(node, isAsync ? 'AsyncGenerator' : 'Generator');
10144
10176
  const expectedEntryType = getExpectedEntryTypeForIterable(node, builtInIteratorType, inferenceContext);
10145
- const elementTypeResult = getElementTypeFromListComprehension(node, expectedEntryType);
10177
+ const elementTypeResult = getElementTypeFromComprehension(node, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, expectedEntryType);
10146
10178
  if (elementTypeResult.isIncomplete) {
10147
10179
  isIncomplete = true;
10148
10180
  }
@@ -10186,10 +10218,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10186
10218
  }
10187
10219
  }
10188
10220
  }
10189
- function evaluateListComprehensionForIf(node) {
10221
+ function evaluateComprehensionForIf(node) {
10190
10222
  var _a;
10191
10223
  let isIncomplete = false;
10192
- if (node.nodeType === 33 /* ParseNodeType.ListComprehensionFor */) {
10224
+ if (node.nodeType === 12 /* ParseNodeType.ComprehensionFor */) {
10193
10225
  const iterableTypeResult = getTypeOfExpression(node.iterableExpression);
10194
10226
  if (iterableTypeResult.isIncomplete) {
10195
10227
  isIncomplete = true;
@@ -10200,7 +10232,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10200
10232
  assignTypeToExpression(targetExpr, itemTypeResult.type, !!itemTypeResult.isIncomplete, node.iterableExpression);
10201
10233
  }
10202
10234
  else {
10203
- (0, debug_1.assert)(node.nodeType === 34 /* ParseNodeType.ListComprehensionIf */);
10235
+ (0, debug_1.assert)(node.nodeType === 13 /* ParseNodeType.ComprehensionIf */);
10204
10236
  // Evaluate the test expression to validate it and mark symbols
10205
10237
  // as referenced. Don't bother doing this if we're in speculative
10206
10238
  // mode because it doesn't affect the element type.
@@ -10210,22 +10242,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10210
10242
  }
10211
10243
  return isIncomplete;
10212
10244
  }
10213
- // Returns the type of one entry returned by the list comprehension,
10214
- // as opposed to the entire list.
10215
- function getElementTypeFromListComprehension(node, expectedValueOrElementType, expectedKeyType) {
10245
+ // Returns the type of one entry returned by the comprehension.
10246
+ function getElementTypeFromComprehension(node, flags, expectedValueOrElementType, expectedKeyType) {
10216
10247
  let isIncomplete = false;
10217
10248
  let typeErrors = false;
10218
10249
  // "Execute" the list comprehensions from start to finish.
10219
10250
  for (const forIfNode of node.forIfNodes) {
10220
- if (evaluateListComprehensionForIf(forIfNode)) {
10251
+ if (evaluateComprehensionForIf(forIfNode)) {
10221
10252
  isIncomplete = true;
10222
10253
  }
10223
10254
  }
10224
10255
  let type = types_1.UnknownType.create();
10225
- if (node.expression.nodeType === 17 /* ParseNodeType.DictionaryKeyEntry */) {
10256
+ if (node.expression.nodeType === 20 /* ParseNodeType.DictionaryKeyEntry */) {
10226
10257
  // Create a tuple with the key/value types.
10227
- const keyTypeResult = getTypeOfExpression(node.expression.keyExpression,
10228
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedKeyType));
10258
+ const keyTypeResult = getTypeOfExpression(node.expression.keyExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedKeyType));
10229
10259
  if (keyTypeResult.isIncomplete) {
10230
10260
  isIncomplete = true;
10231
10261
  }
@@ -10236,8 +10266,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10236
10266
  if (!expectedKeyType || !(0, typeUtils_1.containsLiteralType)(expectedKeyType)) {
10237
10267
  keyType = stripLiteralValue(keyType);
10238
10268
  }
10239
- const valueTypeResult = getTypeOfExpression(node.expression.valueExpression,
10240
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10269
+ const valueTypeResult = getTypeOfExpression(node.expression.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10241
10270
  if (valueTypeResult.isIncomplete) {
10242
10271
  isIncomplete = true;
10243
10272
  }
@@ -10253,14 +10282,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10253
10282
  { type: valueType, isUnbounded: false },
10254
10283
  ]);
10255
10284
  }
10256
- else if (node.expression.nodeType === 16 /* ParseNodeType.DictionaryExpandEntry */) {
10285
+ else if (node.expression.nodeType === 19 /* ParseNodeType.DictionaryExpandEntry */) {
10257
10286
  // The parser should have reported an error in this case because it's not allowed.
10258
- getTypeOfExpression(node.expression.expandExpression,
10259
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10287
+ getTypeOfExpression(node.expression.expandExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10260
10288
  }
10261
10289
  else if ((0, parseNodes_1.isExpressionNode)(node)) {
10262
- const exprTypeResult = getTypeOfExpression(node.expression,
10263
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10290
+ const exprTypeResult = getTypeOfExpression(node.expression, flags, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10264
10291
  if (exprTypeResult.isIncomplete) {
10265
10292
  isIncomplete = true;
10266
10293
  }
@@ -10478,9 +10505,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10478
10505
  addExpectedClassDiagnostic(typeArg0Type, typeArgs[0].node);
10479
10506
  typeArg0Type = types_1.UnknownType.create();
10480
10507
  }
10481
- let optionalType = (0, types_1.combineTypes)([typeArg0Type, noneClassType !== null && noneClassType !== void 0 ? noneClassType : types_1.UnknownType.create()]);
10482
- if (unionClassType && (0, types_1.isInstantiableClass)(unionClassType)) {
10483
- optionalType = types_1.TypeBase.cloneAsSpecialForm(optionalType, types_1.ClassType.cloneAsInstance(unionClassType));
10508
+ let optionalType = (0, types_1.combineTypes)([typeArg0Type, noneTypeClass !== null && noneTypeClass !== void 0 ? noneTypeClass : types_1.UnknownType.create()]);
10509
+ if (unionTypeClass && (0, types_1.isInstantiableClass)(unionTypeClass)) {
10510
+ optionalType = types_1.TypeBase.cloneAsSpecialForm(optionalType, types_1.ClassType.cloneAsInstance(unionTypeClass));
10484
10511
  }
10485
10512
  return optionalType;
10486
10513
  }
@@ -10540,7 +10567,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10540
10567
  type = cloneBuiltinClassWithLiteral(node, classType, 'int', itemExpr.value);
10541
10568
  }
10542
10569
  }
10543
- else if (itemExpr.nodeType === 11 /* ParseNodeType.Constant */) {
10570
+ else if (itemExpr.nodeType === 14 /* ParseNodeType.Constant */) {
10544
10571
  if (itemExpr.constType === 33 /* KeywordType.True */) {
10545
10572
  type = cloneBuiltinClassWithLiteral(node, classType, 'bool', true);
10546
10573
  }
@@ -10548,7 +10575,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10548
10575
  type = cloneBuiltinClassWithLiteral(node, classType, 'bool', false);
10549
10576
  }
10550
10577
  else if (itemExpr.constType === 26 /* KeywordType.None */) {
10551
- type = noneClassType !== null && noneClassType !== void 0 ? noneClassType : types_1.UnknownType.create();
10578
+ type = noneTypeClass !== null && noneTypeClass !== void 0 ? noneTypeClass : types_1.UnknownType.create();
10552
10579
  }
10553
10580
  }
10554
10581
  else if (itemExpr.nodeType === 55 /* ParseNodeType.UnaryOperation */) {
@@ -10592,8 +10619,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10592
10619
  literalTypes.push(type);
10593
10620
  }
10594
10621
  let result = (0, types_1.combineTypes)(literalTypes);
10595
- if ((0, types_1.isUnion)(result) && unionClassType && (0, types_1.isInstantiableClass)(unionClassType)) {
10596
- result = types_1.TypeBase.cloneAsSpecialForm(result, types_1.ClassType.cloneAsInstance(unionClassType));
10622
+ if ((0, types_1.isUnion)(result) && unionTypeClass && (0, types_1.isInstantiableClass)(unionTypeClass)) {
10623
+ result = types_1.TypeBase.cloneAsSpecialForm(result, types_1.ClassType.cloneAsInstance(unionTypeClass));
10597
10624
  }
10598
10625
  return result;
10599
10626
  }
@@ -10987,6 +11014,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10987
11014
  }
10988
11015
  for (const typeArg of typeArgs) {
10989
11016
  let typeArgType = typeArg.type;
11017
+ // This is an experimental feature because Unions of unpacked TypeVarTuples are not officially supported.
10990
11018
  if (!validateTypeArg(typeArg, {
10991
11019
  allowVariadicTypeVar: fileInfo.diagnosticRuleSet.enableExperimentalFeatures,
10992
11020
  })) {
@@ -10998,6 +11026,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10998
11026
  }
10999
11027
  // If this is an unpacked tuple, explode out the individual items.
11000
11028
  if ((0, types_1.isUnpackedClass)(typeArg.type) && typeArg.type.tupleTypeArguments) {
11029
+ // This is an experimental feature because Unions of unpacked TypeVarTuples are not officially supported.
11001
11030
  if (fileInfo.diagnosticRuleSet.enableExperimentalFeatures) {
11002
11031
  typeArg.type.tupleTypeArguments.forEach((tupleTypeArg) => {
11003
11032
  types.push((0, typeUtils_1.convertToInstantiable)(tupleTypeArg.type));
@@ -11011,6 +11040,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11011
11040
  }
11012
11041
  else {
11013
11042
  if ((0, types_1.isTypeVar)(typeArgType) && (0, types_1.isUnpackedVariadicTypeVar)(typeArgType)) {
11043
+ // This is an experimental feature because Unions of unpacked TypeVarTuples are not officially supported.
11014
11044
  if (fileInfo.diagnosticRuleSet.enableExperimentalFeatures) {
11015
11045
  // If this is an unpacked TypeVar, note that it is in a union so we can
11016
11046
  // differentiate between Unpack[Vs] and Union[Unpack[Vs]].
@@ -11032,8 +11062,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11032
11062
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.unionTypeArgCount(), errorNode);
11033
11063
  }
11034
11064
  let unionType = (0, types_1.combineTypes)(types);
11035
- if (unionClassType && (0, types_1.isInstantiableClass)(unionClassType)) {
11036
- unionType = types_1.TypeBase.cloneAsSpecialForm(unionType, types_1.ClassType.cloneAsInstance(unionClassType));
11065
+ if (unionTypeClass && (0, types_1.isInstantiableClass)(unionTypeClass)) {
11066
+ unionType = types_1.TypeBase.cloneAsSpecialForm(unionType, types_1.ClassType.cloneAsInstance(unionTypeClass));
11037
11067
  }
11038
11068
  return unionType;
11039
11069
  }
@@ -11260,7 +11290,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11260
11290
  // Handle 'LiteralString' specially because we want it to act as
11261
11291
  // though it derives from 'str'.
11262
11292
  if (assignedName === 'LiteralString') {
11263
- specialType.details.baseClasses.push(strClassType !== null && strClassType !== void 0 ? strClassType : types_1.AnyType.create());
11293
+ specialType.details.baseClasses.push(strClass !== null && strClass !== void 0 ? strClass : types_1.AnyType.create());
11264
11294
  (0, typeUtils_1.computeMroLinearization)(specialType);
11265
11295
  }
11266
11296
  writeTypeCache(node, { type: specialType }, 0 /* EvaluatorFlags.None */);
@@ -11538,7 +11568,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11538
11568
  return `__type_of_${paramName}`;
11539
11569
  }
11540
11570
  function getTypeOfClass(node) {
11541
- initializedBasicTypes(node);
11571
+ initializePrefetchedTypes(node);
11542
11572
  // Is this type already cached?
11543
11573
  const cachedClassType = readTypeCache(node.name, 0 /* EvaluatorFlags.None */);
11544
11574
  if (cachedClassType) {
@@ -11800,6 +11830,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11800
11830
  classType.details.flags |= 1024 /* ClassTypeFlags.CanOmitDictValues */;
11801
11831
  }
11802
11832
  else if (arg.name.value === 'closed' && constArgValue) {
11833
+ // This is an experimental feature because PEP 728 hasn't been accepted yet.
11803
11834
  if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
11804
11835
  classType.details.flags |=
11805
11836
  256 /* ClassTypeFlags.TypedDictMarkedClosed */ | 512 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
@@ -12155,9 +12186,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12155
12186
  if (!classType.details.requiresVarianceInference) {
12156
12187
  return;
12157
12188
  }
12158
- if (!objectType || !(0, types_1.isClassInstance)(objectType)) {
12159
- return;
12160
- }
12161
12189
  // Presumptively mark the variance inference as complete. This
12162
12190
  // prevents potential recursion.
12163
12191
  classType.details.requiresVarianceInference = false;
@@ -12184,8 +12212,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12184
12212
  if (p.details.isVariadic) {
12185
12213
  return p;
12186
12214
  }
12187
- (0, debug_1.assert)(objectType !== undefined);
12188
- return i === paramIndex ? objectType : dummyTypeObject;
12215
+ return i === paramIndex ? getObjectType() : dummyTypeObject;
12189
12216
  });
12190
12217
  // Replace all type arguments with a dummy type except for the
12191
12218
  // TypeVar of interest, which is replaced with itself.
@@ -12242,7 +12269,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12242
12269
  if (!effectiveMetaclass || (0, types_1.isInstantiableClass)(effectiveMetaclass)) {
12243
12270
  for (const baseClass of classType.details.baseClasses) {
12244
12271
  if ((0, types_1.isInstantiableClass)(baseClass)) {
12245
- const baseClassMeta = baseClass.details.effectiveMetaclass || typeClassType;
12272
+ const baseClassMeta = baseClass.details.effectiveMetaclass || typeClass;
12246
12273
  if (baseClassMeta && (0, types_1.isInstantiableClass)(baseClassMeta)) {
12247
12274
  // Make sure there is no metaclass conflict.
12248
12275
  if (!effectiveMetaclass) {
@@ -12448,7 +12475,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12448
12475
  if (initSubclassMethodType && initSubclassMethodInfo.classType) {
12449
12476
  const callResult = validateCallArguments(errorNode, argList, { type: initSubclassMethodType },
12450
12477
  /* typeVarContext */ undefined,
12451
- /* skipUnknownArgCheck */ false, (0, typeUtils_1.makeInferenceContext)(getNoneType()));
12478
+ /* skipUnknownArgCheck */ false, (0, typeUtils_1.makeInferenceContext)(getNoneType()),
12479
+ /* signatureTracker */ undefined);
12452
12480
  if (callResult.argumentErrors) {
12453
12481
  const diag = addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.initSubclassCallFailed(), node.name);
12454
12482
  const initSubclassFunction = (0, types_1.isOverloadedFunction)(initSubclassMethodType)
@@ -12474,7 +12502,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12474
12502
  });
12475
12503
  }
12476
12504
  function getTypeOfFunction(node) {
12477
- initializedBasicTypes(node);
12505
+ initializePrefetchedTypes(node);
12478
12506
  // Is this predecorated function type cached?
12479
12507
  let functionType = readTypeCache(node.name, 0 /* EvaluatorFlags.None */);
12480
12508
  if (functionType) {
@@ -12901,7 +12929,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12901
12929
  // the type checker should assume that the type is optional (i.e. a union
12902
12930
  // of the specified type and 'None'). Skip this step if the type is already
12903
12931
  // optional to avoid losing alias names when combining the types.
12904
- if (((_a = param.defaultValue) === null || _a === void 0 ? void 0 : _a.nodeType) === 11 /* ParseNodeType.Constant */ &&
12932
+ if (((_a = param.defaultValue) === null || _a === void 0 ? void 0 : _a.nodeType) === 14 /* ParseNodeType.Constant */ &&
12905
12933
  param.defaultValue.constType === 26 /* KeywordType.None */ &&
12906
12934
  !(0, typeUtils_1.isOptionalType)(type) &&
12907
12935
  !AnalyzerNodeInfo.getFileInfo(param).diagnosticRuleSet.strictParameterNoneValue) {
@@ -13467,7 +13495,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13467
13495
  let symbolType = getAliasedSymbolTypeForName(node, aliasNode.value);
13468
13496
  if (!symbolType) {
13469
13497
  const parentNode = node.parent;
13470
- (0, debug_1.assert)(parentNode && parentNode.nodeType === 22 /* ParseNodeType.ImportFrom */);
13498
+ (0, debug_1.assert)(parentNode && parentNode.nodeType === 25 /* ParseNodeType.ImportFrom */);
13471
13499
  (0, debug_1.assert)(!parentNode.isWildcardImport);
13472
13500
  const importInfo = AnalyzerNodeInfo.getImportInfo(parentNode.module);
13473
13501
  if (importInfo && importInfo.isImportFound && !importInfo.isNativeLib) {
@@ -13659,7 +13687,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13659
13687
  if (!resolvedAliasInfo.declaration) {
13660
13688
  return evaluatorOptions.evaluateUnknownImportsAsAny ? types_1.AnyType.create() : types_1.UnknownType.create();
13661
13689
  }
13662
- if (node.nodeType === 23 /* ParseNodeType.ImportFromAs */) {
13690
+ if (node.nodeType === 26 /* ParseNodeType.ImportFromAs */) {
13663
13691
  if (resolvedAliasInfo.isPrivate) {
13664
13692
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportPrivateUsage, localize_1.LocMessage.privateUsedOutsideOfModule().format({
13665
13693
  name: node.name.value,
@@ -13689,7 +13717,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13689
13717
  // is technically not part of an expression. We'll handle these here so
13690
13718
  // callers don't need to include special-case logic.
13691
13719
  if (node.nodeType === 38 /* ParseNodeType.Name */ && node.parent) {
13692
- if (node.parent.nodeType === 28 /* ParseNodeType.Function */ && node.parent.name === node) {
13720
+ if (node.parent.nodeType === 31 /* ParseNodeType.Function */ && node.parent.name === node) {
13693
13721
  getTypeOfFunction(node.parent);
13694
13722
  return;
13695
13723
  }
@@ -13697,11 +13725,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13697
13725
  getTypeOfClass(node.parent);
13698
13726
  return;
13699
13727
  }
13700
- if (node.parent.nodeType === 23 /* ParseNodeType.ImportFromAs */) {
13728
+ if (node.parent.nodeType === 26 /* ParseNodeType.ImportFromAs */) {
13701
13729
  evaluateTypesForImportFromAs(node.parent);
13702
13730
  return;
13703
13731
  }
13704
- if (node.parent.nodeType === 21 /* ParseNodeType.ImportAs */) {
13732
+ if (node.parent.nodeType === 24 /* ParseNodeType.ImportAs */) {
13705
13733
  evaluateTypesForImportAs(node.parent);
13706
13734
  return;
13707
13735
  }
@@ -13709,7 +13737,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13709
13737
  getTypeOfTypeAlias(node.parent);
13710
13738
  return;
13711
13739
  }
13712
- if (node.parent.nodeType === 29 /* ParseNodeType.Global */ || node.parent.nodeType === 39 /* ParseNodeType.Nonlocal */) {
13740
+ if (node.parent.nodeType === 32 /* ParseNodeType.Global */ || node.parent.nodeType === 39 /* ParseNodeType.Nonlocal */) {
13713
13741
  // For global and nonlocal statements, allow forward references so
13714
13742
  // we don't use code flow during symbol lookups.
13715
13743
  getTypeOfExpression(node, 4 /* EvaluatorFlags.AllowForwardReferences */);
@@ -13745,7 +13773,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13745
13773
  evaluateTypesForTypeAnnotationNode(annotationParent);
13746
13774
  return;
13747
13775
  }
13748
- if (annotationParent.nodeType === 28 /* ParseNodeType.Function */ &&
13776
+ if (annotationParent.nodeType === 31 /* ParseNodeType.Function */ &&
13749
13777
  annotationNode === annotationParent.returnTypeAnnotation) {
13750
13778
  getTypeOfAnnotation(annotationNode, {
13751
13779
  associateTypeVarsWithScope: true,
@@ -13781,7 +13809,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13781
13809
  if (argumentNode && argumentNode !== nodeToEvaluate) {
13782
13810
  (0, debug_1.assert)(argumentNode.parent !== undefined);
13783
13811
  if (argumentNode.parent.nodeType === 9 /* ParseNodeType.Call */ ||
13784
- argumentNode.parent.nodeType === 24 /* ParseNodeType.Index */) {
13812
+ argumentNode.parent.nodeType === 27 /* ParseNodeType.Index */) {
13785
13813
  nodeToEvaluate = argumentNode.parent;
13786
13814
  continue;
13787
13815
  }
@@ -13813,7 +13841,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13813
13841
  continue;
13814
13842
  }
13815
13843
  // Handle the special case where the LHS is a call to a lambda.
13816
- if (parent.nodeType === 9 /* ParseNodeType.Call */ && nodeToEvaluate.nodeType === 30 /* ParseNodeType.Lambda */) {
13844
+ if (parent.nodeType === 9 /* ParseNodeType.Call */ && nodeToEvaluate.nodeType === 33 /* ParseNodeType.Lambda */) {
13817
13845
  nodeToEvaluate = parent;
13818
13846
  continue;
13819
13847
  }
@@ -13821,7 +13849,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13821
13849
  break;
13822
13850
  }
13823
13851
  }
13824
- else if (parent.nodeType === 24 /* ParseNodeType.Index */) {
13852
+ else if (parent.nodeType === 27 /* ParseNodeType.Index */) {
13825
13853
  // The base expression of an index expression is not contextual.
13826
13854
  if (nodeToEvaluate === parent.baseExpression) {
13827
13855
  flags = 2 /* EvaluatorFlags.IndexBaseDefaults */;
@@ -13841,17 +13869,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13841
13869
  // stop. However, there are a few special "pass through"
13842
13870
  // node types that we can skip over to get to a known
13843
13871
  // expression node.
13844
- if (parent.nodeType === 17 /* ParseNodeType.DictionaryKeyEntry */ ||
13845
- parent.nodeType === 16 /* ParseNodeType.DictionaryExpandEntry */ ||
13846
- parent.nodeType === 33 /* ParseNodeType.ListComprehensionFor */ ||
13847
- parent.nodeType === 34 /* ParseNodeType.ListComprehensionIf */) {
13872
+ if (parent.nodeType === 20 /* ParseNodeType.DictionaryKeyEntry */ ||
13873
+ parent.nodeType === 19 /* ParseNodeType.DictionaryExpandEntry */ ||
13874
+ parent.nodeType === 12 /* ParseNodeType.ComprehensionFor */ ||
13875
+ parent.nodeType === 13 /* ParseNodeType.ComprehensionIf */) {
13848
13876
  (0, debug_1.assert)(parent.parent !== undefined && (0, parseNodes_1.isExpressionNode)(parent.parent));
13849
13877
  parent = parent.parent;
13850
13878
  }
13851
13879
  else if (parent.nodeType === 41 /* ParseNodeType.Parameter */) {
13852
13880
  (0, debug_1.assert)(parent.parent !== undefined);
13853
13881
  // Parameters are contextual for lambdas.
13854
- if (parent.parent.nodeType === 30 /* ParseNodeType.Lambda */) {
13882
+ if (parent.parent.nodeType === 33 /* ParseNodeType.Lambda */) {
13855
13883
  parent = parent.parent;
13856
13884
  }
13857
13885
  else {
@@ -13876,7 +13904,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13876
13904
  const parent = nodeToEvaluate.parent;
13877
13905
  (0, debug_1.assert)(parent !== undefined);
13878
13906
  switch (parent.nodeType) {
13879
- case 14 /* ParseNodeType.Del */: {
13907
+ case 17 /* ParseNodeType.Del */: {
13880
13908
  verifyDeleteExpression(nodeToEvaluate);
13881
13909
  return;
13882
13910
  }
@@ -13895,11 +13923,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13895
13923
  getTypeOfTypeAlias(parent);
13896
13924
  return;
13897
13925
  }
13898
- case 13 /* ParseNodeType.Decorator */: {
13926
+ case 16 /* ParseNodeType.Decorator */: {
13899
13927
  if (((_d = parent.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 10 /* ParseNodeType.Class */) {
13900
13928
  getTypeOfClass(parent.parent);
13901
13929
  }
13902
- else if (((_e = parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 28 /* ParseNodeType.Function */) {
13930
+ else if (((_e = parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 31 /* ParseNodeType.Function */) {
13903
13931
  getTypeOfFunction(parent.parent);
13904
13932
  }
13905
13933
  return;
@@ -13961,11 +13989,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13961
13989
  // be inferred, whereas the latter sometimes have type annotations
13962
13990
  // but cannot be inferred.
13963
13991
  const parent = node.parent;
13964
- if (parent.nodeType === 30 /* ParseNodeType.Lambda */) {
13992
+ if (parent.nodeType === 33 /* ParseNodeType.Lambda */) {
13965
13993
  evaluateTypesForExpressionInContext(parent);
13966
13994
  return;
13967
13995
  }
13968
- (0, debug_1.assert)(parent.nodeType === 28 /* ParseNodeType.Function */);
13996
+ (0, debug_1.assert)(parent.nodeType === 31 /* ParseNodeType.Function */);
13969
13997
  const functionNode = parent;
13970
13998
  const paramIndex = functionNode.parameters.findIndex((param) => param === node);
13971
13999
  const typeAnnotation = ParseTreeUtils.getTypeAnnotationForParameter(functionNode, paramIndex);
@@ -14001,7 +14029,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14001
14029
  // be evaluated to provide sufficient context for the type. Evaluated types
14002
14030
  // are written back to the type cache for later retrieval.
14003
14031
  function evaluateTypesForStatement(node) {
14004
- initializedBasicTypes(node);
14032
+ initializePrefetchedTypes(node);
14005
14033
  let curNode = node;
14006
14034
  while (curNode) {
14007
14035
  switch (curNode.nodeType) {
@@ -14039,19 +14067,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14039
14067
  evaluateTypeOfParameter(curNode);
14040
14068
  return;
14041
14069
  }
14042
- case 30 /* ParseNodeType.Lambda */: {
14070
+ case 33 /* ParseNodeType.Lambda */: {
14043
14071
  evaluateTypesForExpressionInContext(curNode);
14044
14072
  return;
14045
14073
  }
14046
- case 28 /* ParseNodeType.Function */: {
14074
+ case 31 /* ParseNodeType.Function */: {
14047
14075
  getTypeOfFunction(curNode);
14048
14076
  return;
14049
14077
  }
14050
- case 26 /* ParseNodeType.For */: {
14078
+ case 29 /* ParseNodeType.For */: {
14051
14079
  evaluateTypesForForStatement(curNode);
14052
14080
  return;
14053
14081
  }
14054
- case 25 /* ParseNodeType.Except */: {
14082
+ case 28 /* ParseNodeType.Except */: {
14055
14083
  evaluateTypesForExceptStatement(curNode);
14056
14084
  return;
14057
14085
  }
@@ -14059,17 +14087,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14059
14087
  evaluateTypesForWithStatement(curNode);
14060
14088
  return;
14061
14089
  }
14062
- case 33 /* ParseNodeType.ListComprehensionFor */: {
14063
- const listComprehension = curNode.parent;
14064
- (0, debug_1.assert)(listComprehension.nodeType === 32 /* ParseNodeType.ListComprehension */);
14065
- if (curNode === listComprehension.expression) {
14066
- evaluateTypesForExpressionInContext(listComprehension);
14090
+ case 12 /* ParseNodeType.ComprehensionFor */: {
14091
+ const comprehension = curNode.parent;
14092
+ (0, debug_1.assert)(comprehension.nodeType === 11 /* ParseNodeType.Comprehension */);
14093
+ if (curNode === comprehension.expression) {
14094
+ evaluateTypesForExpressionInContext(comprehension);
14067
14095
  }
14068
14096
  else {
14069
14097
  // Evaluate the individual iterations starting with the first
14070
14098
  // up to the curNode.
14071
- for (const forIfNode of listComprehension.forIfNodes) {
14072
- evaluateListComprehensionForIf(forIfNode);
14099
+ for (const forIfNode of comprehension.forIfNodes) {
14100
+ evaluateComprehensionForIf(forIfNode);
14073
14101
  if (forIfNode === curNode) {
14074
14102
  break;
14075
14103
  }
@@ -14077,15 +14105,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14077
14105
  }
14078
14106
  return;
14079
14107
  }
14080
- case 21 /* ParseNodeType.ImportAs */: {
14108
+ case 24 /* ParseNodeType.ImportAs */: {
14081
14109
  evaluateTypesForImportAs(curNode);
14082
14110
  return;
14083
14111
  }
14084
- case 23 /* ParseNodeType.ImportFromAs */: {
14112
+ case 26 /* ParseNodeType.ImportFromAs */: {
14085
14113
  evaluateTypesForImportFromAs(curNode);
14086
14114
  return;
14087
14115
  }
14088
- case 22 /* ParseNodeType.ImportFrom */: {
14116
+ case 25 /* ParseNodeType.ImportFrom */: {
14089
14117
  evaluateTypesForImportFrom(curNode);
14090
14118
  return;
14091
14119
  }
@@ -14309,8 +14337,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14309
14337
  return { type: types_1.UnknownType.create() };
14310
14338
  }
14311
14339
  }
14312
- if (typeClassType && (0, types_1.isInstantiableClass)(typeClassType)) {
14313
- let typeType = createSpecialType(typeClassType, typeArgs, 1,
14340
+ if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
14341
+ let typeType = createSpecialType(typeClass, typeArgs, 1,
14314
14342
  /* allowParamSpec */ undefined,
14315
14343
  /* isSpecialForm */ false);
14316
14344
  if ((0, types_1.isInstantiableClass)(typeType)) {
@@ -14547,9 +14575,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14547
14575
  const specializedClass = types_1.ClassType.cloneForSpecialization(classType, typeArgTypes, typeArgs !== undefined);
14548
14576
  return { type: specializedClass };
14549
14577
  }
14550
- function getTypeOfArgument(arg, inferenceContext) {
14578
+ function getTypeOfArgument(arg, inferenceContext, signatureTracker) {
14579
+ var _a, _b;
14551
14580
  if (arg.typeResult) {
14552
- return { type: arg.typeResult.type, isIncomplete: arg.typeResult.isIncomplete };
14581
+ const type = (_b = (_a = arg.typeResult.type) === null || _a === void 0 ? void 0 : _a.specialForm) !== null && _b !== void 0 ? _b : arg.typeResult.type;
14582
+ return { type, isIncomplete: arg.typeResult.isIncomplete };
14553
14583
  }
14554
14584
  if (!arg.valueExpression) {
14555
14585
  // We shouldn't ever get here, but just in case.
@@ -14557,7 +14587,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14557
14587
  }
14558
14588
  // If there was no defined type provided, there should always
14559
14589
  // be a value expression from which we can retrieve the type.
14560
- return getTypeOfExpression(arg.valueExpression, /* flags */ undefined, inferenceContext);
14590
+ const typeResult = getTypeOfExpression(arg.valueExpression,
14591
+ /* flags */ undefined, inferenceContext, signatureTracker);
14592
+ if (signatureTracker) {
14593
+ typeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(typeResult.type, signatureTracker, arg.valueExpression.start);
14594
+ }
14595
+ return typeResult;
14561
14596
  }
14562
14597
  // This function is like getTypeOfArgument except that it is
14563
14598
  // used in cases where the argument is expected to be a type
@@ -14641,7 +14676,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14641
14676
  // Functions and list comprehensions don't allow access to implicitly
14642
14677
  // aliased symbols in outer scopes if they haven't yet been assigned
14643
14678
  // within the local scope.
14644
- let scopeTypeHonorsCodeFlow = scopeType !== 2 /* ScopeType.Function */ && scopeType !== 1 /* ScopeType.ListComprehension */;
14679
+ let scopeTypeHonorsCodeFlow = scopeType !== 2 /* ScopeType.Function */ && scopeType !== 1 /* ScopeType.Comprehension */;
14645
14680
  // TypeParameter scopes don't honor code flow, but if the symbol is resolved
14646
14681
  // using the proxy scope for the TypeParameter scope, we should use code flow.
14647
14682
  if (scopeType === 0 /* ScopeType.TypeParameter */ && symbolWithScope && symbolWithScope.scope === scope) {
@@ -14845,7 +14880,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14845
14880
  }
14846
14881
  function getAliasFromImport(node) {
14847
14882
  if (node.parent &&
14848
- node.parent.nodeType === 23 /* ParseNodeType.ImportFromAs */ &&
14883
+ node.parent.nodeType === 26 /* ParseNodeType.ImportFromAs */ &&
14849
14884
  node.parent.alias &&
14850
14885
  node === node.parent.name) {
14851
14886
  return node.parent.alias;
@@ -15076,7 +15111,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15076
15111
  // has a function-level annotation comment that provides
15077
15112
  // this parameter's annotation type.
15078
15113
  if (!typeAnnotationNode) {
15079
- if (((_a = declaration.node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 28 /* ParseNodeType.Function */) {
15114
+ if (((_a = declaration.node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 31 /* ParseNodeType.Function */) {
15080
15115
  const functionNode = declaration.node.parent;
15081
15116
  if (functionNode.functionAnnotationComment &&
15082
15117
  !functionNode.functionAnnotationComment.isParamListEllipsis) {
@@ -15244,7 +15279,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15244
15279
  // Set the variance to "auto" for class-scoped TypeVars.
15245
15280
  typeVar.details.declaredVariance = 0 /* Variance.Auto */;
15246
15281
  }
15247
- else if (scopeNode.nodeType === 28 /* ParseNodeType.Function */) {
15282
+ else if (scopeNode.nodeType === 31 /* ParseNodeType.Function */) {
15248
15283
  scopeType = 1 /* TypeVarScopeType.Function */;
15249
15284
  }
15250
15285
  else {
@@ -15832,7 +15867,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15832
15867
  function getFunctionEffectiveReturnType(type, callSiteInfo, inferTypeIfNeeded = true) {
15833
15868
  const specializedReturnType = types_1.FunctionType.getSpecializedReturnType(type, /* includeInferred */ false);
15834
15869
  if (specializedReturnType && !(0, types_1.isUnknown)(specializedReturnType)) {
15835
- return adjustCallableReturnType(type, specializedReturnType, /* liveTypeVarScopes */ []);
15870
+ const liveTypeVarScopes = (callSiteInfo === null || callSiteInfo === void 0 ? void 0 : callSiteInfo.errorNode)
15871
+ ? ParseTreeUtils.getTypeVarScopesForNode(callSiteInfo === null || callSiteInfo === void 0 ? void 0 : callSiteInfo.errorNode)
15872
+ : [];
15873
+ return adjustCallableReturnType(type, specializedReturnType, liveTypeVarScopes);
15836
15874
  }
15837
15875
  if (inferTypeIfNeeded) {
15838
15876
  return getFunctionInferredReturnType(type, callSiteInfo);
@@ -16086,7 +16124,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16086
16124
  function getTypeOfMember(member) {
16087
16125
  if ((0, types_1.isInstantiableClass)(member.classType)) {
16088
16126
  return (0, typeUtils_1.partiallySpecializeType)(getEffectiveTypeOfSymbol(member.symbol), member.classType,
16089
- /* selfClass */ undefined, typeClassType !== null && typeClassType !== void 0 ? typeClassType : types_1.UnknownType.create());
16127
+ /* selfClass */ undefined, typeClass !== null && typeClass !== void 0 ? typeClass : types_1.UnknownType.create());
16090
16128
  }
16091
16129
  return types_1.UnknownType.create();
16092
16130
  }
@@ -16163,22 +16201,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16163
16201
  if (types_1.ClassType.isBuiltIn(destType, 'Mapping')) {
16164
16202
  const mappingValueType = (0, typedDicts_1.getTypedDictMappingEquivalent)(evaluatorInterface, srcType);
16165
16203
  if (mappingValueType &&
16166
- mappingType &&
16167
- (0, types_1.isInstantiableClass)(mappingType) &&
16168
- strClassType &&
16169
- (0, types_1.isInstantiableClass)(strClassType)) {
16170
- srcType = types_1.ClassType.cloneForSpecialization(mappingType, [types_1.ClassType.cloneAsInstance(strClassType), mappingValueType],
16204
+ mappingClass &&
16205
+ (0, types_1.isInstantiableClass)(mappingClass) &&
16206
+ strClass &&
16207
+ (0, types_1.isInstantiableClass)(strClass)) {
16208
+ srcType = types_1.ClassType.cloneForSpecialization(mappingClass, [types_1.ClassType.cloneAsInstance(strClass), mappingValueType],
16171
16209
  /* isTypeArgumentExplicit */ true);
16172
16210
  }
16173
16211
  }
16174
16212
  else if (types_1.ClassType.isBuiltIn(destType, ['dict', 'MutableMapping'])) {
16175
16213
  const dictValueType = (0, typedDicts_1.getTypedDictDictEquivalent)(evaluatorInterface, srcType, recursionCount);
16176
16214
  if (dictValueType &&
16177
- dictClassType &&
16178
- (0, types_1.isInstantiableClass)(dictClassType) &&
16179
- strClassType &&
16180
- (0, types_1.isInstantiableClass)(strClassType)) {
16181
- srcType = types_1.ClassType.cloneForSpecialization(dictClassType, [types_1.ClassType.cloneAsInstance(strClassType), dictValueType],
16215
+ dictClass &&
16216
+ (0, types_1.isInstantiableClass)(dictClass) &&
16217
+ strClass &&
16218
+ (0, types_1.isInstantiableClass)(strClass)) {
16219
+ srcType = types_1.ClassType.cloneForSpecialization(dictClass, [types_1.ClassType.cloneAsInstance(strClass), dictValueType],
16182
16220
  /* isTypeArgumentExplicit */ true);
16183
16221
  }
16184
16222
  }
@@ -16224,24 +16262,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16224
16262
  return true;
16225
16263
  }
16226
16264
  }
16227
- const destErrorType = reportErrorsUsingObjType ? types_1.ClassType.cloneAsInstance(destType) : destType;
16228
- const srcErrorType = reportErrorsUsingObjType ? types_1.ClassType.cloneAsInstance(srcType) : srcType;
16229
- let destErrorTypeText = printType(destErrorType);
16230
- let srcErrorTypeText = printType(srcErrorType);
16231
- // If the text is the same, use the fully-qualified name rather than the short name.
16232
- if (destErrorTypeText === srcErrorTypeText && destType.details.fullName && srcType.details.fullName) {
16233
- destErrorTypeText = destType.details.fullName;
16234
- srcErrorTypeText = srcType.details.fullName;
16235
- }
16236
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeIncompatible().format({
16237
- sourceType: srcErrorTypeText,
16238
- destType: destErrorTypeText,
16239
- }));
16240
- // Tell the user about the disableBytesTypePromotions if that is involved.
16241
- if (types_1.ClassType.isBuiltIn(destType, 'bytes')) {
16242
- const promotions = typePromotions.get(destType.details.fullName);
16243
- if (promotions && promotions.some((name) => name === srcType.details.fullName)) {
16244
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.bytesTypePromotions());
16265
+ if (diag) {
16266
+ const destErrorType = reportErrorsUsingObjType ? types_1.ClassType.cloneAsInstance(destType) : destType;
16267
+ const srcErrorType = reportErrorsUsingObjType ? types_1.ClassType.cloneAsInstance(srcType) : srcType;
16268
+ let destErrorTypeText = printType(destErrorType);
16269
+ let srcErrorTypeText = printType(srcErrorType);
16270
+ // If the text is the same, use the fully-qualified name rather than the short name.
16271
+ if (destErrorTypeText === srcErrorTypeText && destType.details.fullName && srcType.details.fullName) {
16272
+ destErrorTypeText = destType.details.fullName;
16273
+ srcErrorTypeText = srcType.details.fullName;
16274
+ }
16275
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeIncompatible().format({
16276
+ sourceType: srcErrorTypeText,
16277
+ destType: destErrorTypeText,
16278
+ }));
16279
+ // Tell the user about the disableBytesTypePromotions if that is involved.
16280
+ if (types_1.ClassType.isBuiltIn(destType, 'bytes')) {
16281
+ const promotions = typePromotions.get(destType.details.fullName);
16282
+ if (promotions && promotions.some((name) => name === srcType.details.fullName)) {
16283
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.bytesTypePromotions());
16284
+ }
16245
16285
  }
16246
16286
  }
16247
16287
  return false;
@@ -16403,7 +16443,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16403
16443
  // If the only removed arg from the dest type args is itself a variadic,
16404
16444
  // don't bother adjusting it.
16405
16445
  const skipAdjustment = destArgsToCapture === 1 && (0, types_1.isVariadicTypeVar)(destTypeArgs[srcVariadicIndex].type);
16406
- if (!skipAdjustment && tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
16446
+ if (!skipAdjustment && tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
16407
16447
  const removedArgs = destTypeArgs.splice(srcVariadicIndex, destArgsToCapture);
16408
16448
  // Package up the remaining type arguments into a tuple object.
16409
16449
  const variadicTuple = makeTupleObject(removedArgs.map((typeArg) => {
@@ -16427,7 +16467,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16427
16467
  // If the dest contains a variadic element, determine which source
16428
16468
  // args map to this element and package them up into an unpacked tuple.
16429
16469
  if ((0, types_1.isVariadicTypeVar)(destTypeArgs[destUnboundedOrVariadicIndex].type)) {
16430
- if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
16470
+ if (tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
16431
16471
  const removedArgs = srcTypeArgs.splice(destUnboundedOrVariadicIndex, srcArgsToCapture);
16432
16472
  let variadicTuple;
16433
16473
  // If we're left with a single unpacked variadic type var, there's no
@@ -16892,20 +16932,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16892
16932
  // rather than dest. If the type variable is not in the scope of the
16893
16933
  // provided TypeVarContext, simply verify that the concrete types are
16894
16934
  // compatible.
16895
- if (!srcTypeVarContext || !srcTypeVarContext.hasSolveForScope((0, typeUtils_1.getTypeVarScopeId)(srcType))) {
16935
+ if ((flags & 1024 /* AssignTypeFlags.IgnoreTypeVarScope */) === 0 &&
16936
+ (!srcTypeVarContext || !srcTypeVarContext.hasSolveForScope((0, typeUtils_1.getTypeVarScopeId)(srcType)))) {
16896
16937
  return assignType(makeTopLevelTypeVarsConcrete(destType), makeTopLevelTypeVarsConcrete(srcType), diag,
16897
16938
  /* destTypeVarContext */ undefined,
16898
16939
  /* srcTypeVarContext */ undefined, originalFlags, recursionCount);
16899
16940
  }
16900
16941
  else {
16901
- if ((0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, srcType, destType, diag, srcTypeVarContext, originalFlags, recursionCount)) {
16942
+ if ((0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, srcType, destType, diag, srcTypeVarContext !== null && srcTypeVarContext !== void 0 ? srcTypeVarContext : new typeVarContext_1.TypeVarContext(), originalFlags, recursionCount)) {
16902
16943
  return true;
16903
16944
  }
16904
16945
  // If the dest type is a union, only one of the subtypes needs to match.
16905
16946
  let isAssignable = false;
16906
16947
  if ((0, types_1.isUnion)(destType)) {
16907
16948
  (0, typeUtils_1.doForEachSubtype)(destType, (destSubtype) => {
16908
- if ((0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, srcType, destSubtype, diag, srcTypeVarContext, originalFlags, recursionCount)) {
16949
+ if ((0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, srcType, destSubtype, diag, srcTypeVarContext !== null && srcTypeVarContext !== void 0 ? srcTypeVarContext : new typeVarContext_1.TypeVarContext(), originalFlags, recursionCount)) {
16909
16950
  isAssignable = true;
16910
16951
  }
16911
16952
  });
@@ -17058,9 +17099,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17058
17099
  if (types_1.ClassType.isBuiltIn(destType, 'type') && ((_c = srcType.instantiableNestingLevel) !== null && _c !== void 0 ? _c : 0) > 0) {
17059
17100
  return true;
17060
17101
  }
17061
- if (!isSpecialFormClass(expandedSrcType, flags) &&
17062
- assignClass(destType, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
17063
- /* reportErrorsUsingObjType */ false)) {
17102
+ if (isSpecialFormClass(expandedSrcType, flags)) {
17103
+ if (destType.specialForm) {
17104
+ return assignType(destType.specialForm, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17105
+ }
17106
+ }
17107
+ else if (assignClass(destType, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
17108
+ /* reportErrorsUsingObjType */ false)) {
17064
17109
  return true;
17065
17110
  }
17066
17111
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
@@ -17131,10 +17176,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17131
17176
  }
17132
17177
  }
17133
17178
  else if (types_1.ClassType.isBuiltIn(concreteSrcType, 'LiteralString') &&
17134
- strClassType &&
17135
- (0, types_1.isInstantiableClass)(strClassType) &&
17179
+ strClass &&
17180
+ (0, types_1.isInstantiableClass)(strClass) &&
17136
17181
  (flags & 1 /* AssignTypeFlags.EnforceInvariance */) === 0) {
17137
- concreteSrcType = types_1.ClassType.cloneAsInstance(strClassType);
17182
+ concreteSrcType = types_1.ClassType.cloneAsInstance(strClass);
17138
17183
  }
17139
17184
  if (!assignClass(types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstantiable(concreteSrcType), diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
17140
17185
  /* reportErrorsUsingObjType */ true)) {
@@ -17149,8 +17194,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17149
17194
  return assignType(destCallbackType, concreteSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17150
17195
  }
17151
17196
  // All functions are considered instances of "builtins.function".
17152
- if (functionObj && (0, types_1.isClassInstance)(functionObj)) {
17153
- return assignType(destType, functionObj, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17197
+ if (functionClass) {
17198
+ return assignType(destType, (0, typeUtils_1.convertToInstance)(functionClass), diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17154
17199
  }
17155
17200
  }
17156
17201
  else if ((0, types_1.isModule)(concreteSrcType)) {
@@ -17304,8 +17349,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17304
17349
  }
17305
17350
  // Are we trying to assign None to a protocol?
17306
17351
  if ((0, typeUtils_1.isNoneInstance)(srcType) && (0, types_1.isClassInstance)(destType) && types_1.ClassType.isProtocolClass(destType)) {
17307
- if (noneClassType && (0, types_1.isInstantiableClass)(noneClassType)) {
17308
- return (0, protocols_1.assignClassToProtocol)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstance(noneClassType), diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17352
+ if (noneTypeClass && (0, types_1.isInstantiableClass)(noneTypeClass)) {
17353
+ return (0, protocols_1.assignClassToProtocol)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstance(noneTypeClass), diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17309
17354
  }
17310
17355
  }
17311
17356
  if ((0, typeUtils_1.isNoneInstance)(destType)) {
@@ -17732,8 +17777,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17732
17777
  for (const field of types_1.ClassType.getSymbolTable(mroClass)) {
17733
17778
  if (field[0] !== '__call__' && !field[1].isIgnoredForProtocolMatch()) {
17734
17779
  let fieldIsPartOfFunction = false;
17735
- if (functionObj && (0, types_1.isClass)(functionObj)) {
17736
- if (types_1.ClassType.getSymbolTable(functionObj).has(field[0])) {
17780
+ if (functionClass && (0, types_1.isClass)(functionClass)) {
17781
+ if (types_1.ClassType.getSymbolTable(functionClass).has(field[0])) {
17737
17782
  fieldIsPartOfFunction = true;
17738
17783
  }
17739
17784
  }
@@ -17818,7 +17863,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17818
17863
  }
17819
17864
  let srcLastToPackIndex = srcDetails.params.findIndex((p, i) => {
17820
17865
  (0, debug_1.assert)(destDetails.argsIndex !== undefined);
17821
- return i >= destDetails.argsIndex && p.source === parameterUtils_1.ParameterSource.KeywordOnly;
17866
+ return i >= destDetails.argsIndex && p.kind === parameterUtils_1.ParameterKind.Keyword;
17822
17867
  });
17823
17868
  if (srcLastToPackIndex < 0) {
17824
17869
  srcLastToPackIndex = srcDetails.params.length;
@@ -17866,7 +17911,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17866
17911
  },
17867
17912
  type: srcPositionalsType,
17868
17913
  index: -1,
17869
- source: parameterUtils_1.ParameterSource.PositionOnly,
17914
+ kind: parameterUtils_1.ParameterKind.Positional,
17870
17915
  },
17871
17916
  ...srcDetails.params.slice(destDetails.argsIndex + srcPositionalsToPack.length, srcDetails.params.length),
17872
17917
  ];
@@ -17874,15 +17919,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17874
17919
  srcDetails.argsIndex = argsIndex >= 0 ? argsIndex : undefined;
17875
17920
  const kwargsIndex = srcDetails.params.findIndex((param) => param.param.category === 2 /* ParameterCategory.KwargsDict */);
17876
17921
  srcDetails.kwargsIndex = kwargsIndex >= 0 ? kwargsIndex : undefined;
17877
- const firstKeywordOnlyIndex = srcDetails.params.findIndex((param) => param.source === parameterUtils_1.ParameterSource.KeywordOnly);
17922
+ const firstKeywordOnlyIndex = srcDetails.params.findIndex((param) => param.kind === parameterUtils_1.ParameterKind.Keyword);
17878
17923
  srcDetails.firstKeywordOnlyIndex = firstKeywordOnlyIndex >= 0 ? firstKeywordOnlyIndex : undefined;
17879
- srcDetails.positionOnlyParamCount = Math.max(0, srcDetails.params.findIndex((p) => p.source !== parameterUtils_1.ParameterSource.PositionOnly ||
17924
+ srcDetails.positionOnlyParamCount = Math.max(0, srcDetails.params.findIndex((p) => p.kind !== parameterUtils_1.ParameterKind.Positional ||
17880
17925
  p.param.category !== 0 /* ParameterCategory.Simple */ ||
17881
17926
  p.param.hasDefault));
17882
17927
  }
17883
17928
  }
17884
17929
  function assignFunction(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
17885
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
17930
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
17886
17931
  let canAssign = true;
17887
17932
  const checkReturnType = (flags & 64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */) === 0;
17888
17933
  const reverseMatching = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) !== 0;
@@ -17918,11 +17963,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17918
17963
  const destParamName = (_c = destParam.param.name) !== null && _c !== void 0 ? _c : '';
17919
17964
  const srcParamName = (_d = srcParam.param.name) !== null && _d !== void 0 ? _d : '';
17920
17965
  if (destParamName) {
17921
- const isDestPositionalOnly = destParam.source === parameterUtils_1.ParameterSource.PositionOnly;
17966
+ const isDestPositionalOnly = destParam.kind === parameterUtils_1.ParameterKind.Positional;
17922
17967
  if (!isDestPositionalOnly &&
17923
17968
  destParam.param.category !== 1 /* ParameterCategory.ArgsList */ &&
17924
17969
  srcParam.param.category !== 1 /* ParameterCategory.ArgsList */) {
17925
- if (srcParam.source === parameterUtils_1.ParameterSource.PositionOnly) {
17970
+ if (srcParam.kind === parameterUtils_1.ParameterKind.Positional) {
17926
17971
  diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionParamPositionOnly().format({
17927
17972
  name: destParamName,
17928
17973
  }));
@@ -17968,10 +18013,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17968
18013
  canAssign = false;
17969
18014
  }
17970
18015
  }
17971
- else if (destParam.source !== parameterUtils_1.ParameterSource.PositionOnly &&
17972
- srcParam.source === parameterUtils_1.ParameterSource.PositionOnly &&
18016
+ else if (destParam.kind !== parameterUtils_1.ParameterKind.Positional &&
18017
+ srcParam.kind === parameterUtils_1.ParameterKind.Positional &&
17973
18018
  srcParamDetails.kwargsIndex === undefined &&
17974
- !srcParamDetails.params.some((p) => p.source === parameterUtils_1.ParameterSource.KeywordOnly &&
18019
+ !srcParamDetails.params.some((p) => p.kind === parameterUtils_1.ParameterKind.Keyword &&
17975
18020
  p.param.category === 0 /* ParameterCategory.Simple */ &&
17976
18021
  p.param.name === destParam.param.name)) {
17977
18022
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.namedParamMissingInSource().format({
@@ -17989,36 +18034,50 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17989
18034
  }));
17990
18035
  canAssign = false;
17991
18036
  }
17992
- if (destPositionalCount < srcPositionalCount) {
17993
- // If the dest type includes a ParamSpec, the additional parameters
17994
- // can be assigned to it, so no need to report an error here.
17995
- if (!targetIncludesParamSpec) {
17996
- const nonDefaultSrcParamCount = srcParamDetails.params.filter((p) => !!p.param.name && !p.param.hasDefault && p.param.category === 0 /* ParameterCategory.Simple */).length;
17997
- if (destParamDetails.argsIndex === undefined) {
17998
- if (destPositionalCount < nonDefaultSrcParamCount) {
17999
- if (destParamDetails.firstPositionOrKeywordIndex > 0 &&
18000
- destParamDetails.firstPositionOrKeywordIndex < srcPositionalCount) {
18001
- diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionTooFewParams().format({
18002
- expected: nonDefaultSrcParamCount,
18003
- received: destPositionalCount,
18004
- }));
18005
- canAssign = false;
18006
- }
18037
+ if (destPositionalCount < srcPositionalCount && !targetIncludesParamSpec) {
18038
+ for (let i = destPositionalCount; i < srcPositionalCount; i++) {
18039
+ // If the dest has an *args parameter, make sure it can accept the remaining
18040
+ // positional arguments in the source.
18041
+ if (destParamDetails.argsIndex !== undefined) {
18042
+ const destArgsType = destParamDetails.params[destParamDetails.argsIndex].type;
18043
+ const srcParamType = srcParamDetails.params[i].type;
18044
+ if (!assignFunctionParameter(destArgsType, srcParamType, i, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18045
+ canAssign = false;
18007
18046
  }
18047
+ continue;
18008
18048
  }
18009
- else {
18010
- // Make sure the remaining positional arguments are of the
18011
- // correct type for the *args parameter.
18012
- const destArgsType = destParamDetails.params[destParamDetails.argsIndex].type;
18013
- if (!(0, types_1.isAnyOrUnknown)(destArgsType)) {
18014
- for (let paramIndex = destPositionalCount; paramIndex < srcPositionalCount; paramIndex++) {
18015
- const srcParamType = srcParamDetails.params[paramIndex].type;
18016
- if (!assignFunctionParameter(destArgsType, srcParamType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18017
- canAssign = false;
18018
- }
18019
- }
18049
+ // If The source parameter has a default value, it is OK for the
18050
+ // corresponding dest parameter to be missing.
18051
+ const srcParam = srcParamDetails.params[i];
18052
+ if (srcParam.param.hasDefault) {
18053
+ // Assign default arg value in case it is needed for
18054
+ // populating TypeVar constraints.
18055
+ const paramInfo = srcParamDetails.params[i];
18056
+ const defaultArgType = (_f = paramInfo.defaultArgType) !== null && _f !== void 0 ? _f : paramInfo.param.defaultType;
18057
+ if (defaultArgType &&
18058
+ !assignType(paramInfo.type, defaultArgType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), srcTypeVarContext,
18059
+ /* destTypeVarContext */ undefined, flags, recursionCount)) {
18060
+ canAssign = false;
18020
18061
  }
18062
+ continue;
18063
+ }
18064
+ // If the source parameter is also addressible by keyword, it is OK
18065
+ // that there is no matching positional parameter in the dest.
18066
+ if (srcParam.kind === parameterUtils_1.ParameterKind.Standard) {
18067
+ continue;
18068
+ }
18069
+ // If the source parameter is a variadic, it is OK that there is no
18070
+ // matching positional parameter in the dest.
18071
+ if (srcParam.param.category === 1 /* ParameterCategory.ArgsList */) {
18072
+ continue;
18021
18073
  }
18074
+ const nonDefaultSrcParamCount = srcParamDetails.params.filter((p) => !!p.param.name && !p.param.hasDefault && p.param.category === 0 /* ParameterCategory.Simple */).length;
18075
+ diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionTooFewParams().format({
18076
+ expected: nonDefaultSrcParamCount,
18077
+ received: destPositionalCount,
18078
+ }));
18079
+ canAssign = false;
18080
+ break;
18022
18081
  }
18023
18082
  }
18024
18083
  else if (srcPositionalCount < destPositionalCount) {
@@ -18039,10 +18098,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18039
18098
  if (!assignFunctionParameter(destParamType, srcArgsType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18040
18099
  canAssign = false;
18041
18100
  }
18042
- if (destParamDetails.params[paramIndex].source !== parameterUtils_1.ParameterSource.PositionOnly &&
18101
+ if (destParamDetails.params[paramIndex].kind !== parameterUtils_1.ParameterKind.Positional &&
18043
18102
  srcParamDetails.kwargsIndex === undefined) {
18044
18103
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.namedParamMissingInSource().format({
18045
- name: (_f = destParamDetails.params[paramIndex].param.name) !== null && _f !== void 0 ? _f : '',
18104
+ name: (_g = destParamDetails.params[paramIndex].param.name) !== null && _g !== void 0 ? _g : '',
18046
18105
  }));
18047
18106
  canAssign = false;
18048
18107
  }
@@ -18090,7 +18149,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18090
18149
  destParamDetails.argsIndex !== undefined &&
18091
18150
  !destParamDetails.hasUnpackedVariadicTypeVar) {
18092
18151
  diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.argsParamMissing().format({
18093
- paramName: (_g = destParamDetails.params[destParamDetails.argsIndex].param.name) !== null && _g !== void 0 ? _g : '',
18152
+ paramName: (_h = destParamDetails.params[destParamDetails.argsIndex].param.name) !== null && _h !== void 0 ? _h : '',
18094
18153
  }));
18095
18154
  canAssign = false;
18096
18155
  }
@@ -18117,16 +18176,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18117
18176
  }
18118
18177
  if (srcStartOfNamed >= 0) {
18119
18178
  srcParamDetails.params.forEach((srcParamInfo, index) => {
18179
+ var _a;
18120
18180
  if (index >= srcStartOfNamed) {
18121
18181
  if (srcParamInfo.param.name &&
18122
18182
  srcParamInfo.param.category === 0 /* ParameterCategory.Simple */ &&
18123
- srcParamInfo.source !== parameterUtils_1.ParameterSource.PositionOnly) {
18183
+ srcParamInfo.kind !== parameterUtils_1.ParameterKind.Positional) {
18124
18184
  const destParamInfo = destParamMap.get(srcParamInfo.param.name);
18125
18185
  const paramDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
18126
18186
  const srcParamType = srcParamInfo.type;
18127
18187
  if (!destParamInfo) {
18128
18188
  if (destParamDetails.kwargsIndex === undefined && !srcParamInfo.param.hasDefault) {
18129
- if (paramDiag && srcParamDetails.firstKeywordOnlyIndex !== undefined) {
18189
+ if (paramDiag) {
18130
18190
  paramDiag.addMessage(localize_1.LocAddendum.namedParamMissingInDest().format({
18131
18191
  name: srcParamInfo.param.name,
18132
18192
  }));
@@ -18139,6 +18199,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18139
18199
  canAssign = false;
18140
18200
  }
18141
18201
  }
18202
+ else if (srcParamInfo.param.hasDefault) {
18203
+ // Assign default arg values in case they are needed for
18204
+ // populating TypeVar constraints.
18205
+ const defaultArgType = (_a = srcParamInfo.defaultArgType) !== null && _a !== void 0 ? _a : srcParamInfo.param.defaultType;
18206
+ if (defaultArgType &&
18207
+ !assignType(srcParamInfo.type, defaultArgType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), srcTypeVarContext,
18208
+ /* destTypeVarContext */ undefined, flags, recursionCount)) {
18209
+ canAssign = false;
18210
+ }
18211
+ }
18142
18212
  }
18143
18213
  else {
18144
18214
  const destParamType = destParamInfo.type;
@@ -18203,7 +18273,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18203
18273
  // If the source and the dest are using the same ParamSpec, any additional
18204
18274
  // concatenated parameters must match.
18205
18275
  if (targetIncludesParamSpec &&
18206
- ((_h = srcType.details.paramSpec) === null || _h === void 0 ? void 0 : _h.nameWithScope) === ((_j = destType.details.paramSpec) === null || _j === void 0 ? void 0 : _j.nameWithScope)) {
18276
+ ((_j = srcType.details.paramSpec) === null || _j === void 0 ? void 0 : _j.nameWithScope) === ((_k = destType.details.paramSpec) === null || _k === void 0 ? void 0 : _k.nameWithScope)) {
18207
18277
  if (srcParamDetails.params.length !== destParamDetails.params.length) {
18208
18278
  canAssign = false;
18209
18279
  }
@@ -18314,9 +18384,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18314
18384
  // type at runtime.
18315
18385
  if ((0, types_1.isClassInstance)(srcReturnType) &&
18316
18386
  types_1.ClassType.isBuiltIn(srcReturnType, ['TypeGuard', 'TypeIs']) &&
18317
- boolClassType &&
18318
- (0, types_1.isInstantiableClass)(boolClassType)) {
18319
- if (assignType(destReturnType, types_1.ClassType.cloneAsInstance(boolClassType), returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18387
+ boolClass &&
18388
+ (0, types_1.isInstantiableClass)(boolClass)) {
18389
+ if (assignType(destReturnType, types_1.ClassType.cloneAsInstance(boolClass), returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
18320
18390
  isReturnTypeCompatible = true;
18321
18391
  }
18322
18392
  }
@@ -18364,7 +18434,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18364
18434
  replacedTypeArg = true;
18365
18435
  return expectedTypeArgType;
18366
18436
  }
18367
- else if ((0, types_1.isClassInstance)(expectedTypeArgType) && (0, types_1.isClassInstance)(typeArg)) {
18437
+ if ((0, types_1.isClassInstance)(expectedTypeArgType) && (0, types_1.isClassInstance)(typeArg)) {
18368
18438
  // Recursively replace Any in the type argument.
18369
18439
  const recursiveReplacement = replaceTypeArgsWithAny(node, expectedTypeArgType, typeArg, recursionCount);
18370
18440
  if (recursiveReplacement) {
@@ -18404,6 +18474,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18404
18474
  // When a value is assigned to a variable with a declared type,
18405
18475
  // we may be able to narrow the type based on the assignment.
18406
18476
  function narrowTypeBasedOnAssignment(node, declaredType, assignedType) {
18477
+ // TODO: The rules for narrowing types on assignment are defined in
18478
+ // the typing spec. Pyright's current logic is currently not even internally
18479
+ // consistent and probably not sound from a type theory perspective. It
18480
+ // should be completely reworked once there has been a public discussion
18481
+ // about the correct behavior.
18407
18482
  const narrowedType = (0, typeUtils_1.mapSubtypes)(assignedType, (assignedSubtype) => {
18408
18483
  // Handle the special case where the assigned type is a literal type.
18409
18484
  // Some types include very large unions of literal types, and we don't
@@ -18438,8 +18513,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18438
18513
  return declaredSubtype;
18439
18514
  }
18440
18515
  // If the declared type doesn't contain any `Any` but the assigned
18441
- // type does, stick with the declared type.
18442
- if ((0, typeUtils_1.containsAnyRecursive)(assignedSubtype) && !(0, typeUtils_1.containsAnyRecursive)(declaredSubtype)) {
18516
+ // type does, stick with the declared type. We don't include unknowns
18517
+ // in the assigned subtype check here so unknowns are preserved so
18518
+ // reportUnknownVariableType assignment diagnostics are reported.
18519
+ // TODO - this is an inconsistency because Any and Unknown should
18520
+ // always be treated the same for purposes of type narrowing. This
18521
+ // should be revisited once the narrowing-on-assignment behavior
18522
+ // is properly specified in the typing spec.
18523
+ if ((0, typeUtils_1.containsAnyRecursive)(assignedSubtype, /* includeUnknown */ false) &&
18524
+ !(0, typeUtils_1.containsAnyRecursive)(declaredSubtype)) {
18443
18525
  return declaredSubtype;
18444
18526
  }
18445
18527
  return assignedSubtype;
@@ -18673,13 +18755,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18673
18755
  const overrideParam = overrideParamDetails.params[i].param;
18674
18756
  if (i >= baseParamDetails.positionOnlyParamCount &&
18675
18757
  !(0, symbolNameUtils_1.isPrivateOrProtectedName)(baseParam.name || '') &&
18676
- baseParamDetails.params[i].source !== parameterUtils_1.ParameterSource.PositionOnly &&
18758
+ baseParamDetails.params[i].kind !== parameterUtils_1.ParameterKind.Positional &&
18677
18759
  baseParam.category === 0 /* ParameterCategory.Simple */ &&
18678
18760
  enforceParamNames &&
18679
18761
  baseParam.name !== overrideParam.name) {
18680
18762
  if (overrideParam.category === 0 /* ParameterCategory.Simple */) {
18681
18763
  if (!baseParam.isNameSynthesized) {
18682
- if (overrideParamDetails.params[i].source === parameterUtils_1.ParameterSource.PositionOnly) {
18764
+ if (overrideParamDetails.params[i].kind === parameterUtils_1.ParameterKind.Positional) {
18683
18765
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
18684
18766
  index: i + 1,
18685
18767
  baseName: baseParam.name || '*',
@@ -18698,8 +18780,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18698
18780
  }
18699
18781
  else if (i < overrideParamDetails.positionOnlyParamCount &&
18700
18782
  i >= baseParamDetails.positionOnlyParamCount) {
18701
- if (!baseParam.isNameSynthesized &&
18702
- baseParamDetails.params[i].source !== parameterUtils_1.ParameterSource.PositionOnly) {
18783
+ if (!baseParam.isNameSynthesized && baseParamDetails.params[i].kind !== parameterUtils_1.ParameterKind.Positional) {
18703
18784
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
18704
18785
  index: i + 1,
18705
18786
  baseName: baseParam.name || '*',
@@ -18737,7 +18818,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18737
18818
  if (enforceParamNames && overrideParamDetails.kwargsIndex === undefined) {
18738
18819
  for (let i = positionalParamCount; i < baseParamDetails.positionParamCount; i++) {
18739
18820
  const baseParam = baseParamDetails.params[i];
18740
- if (baseParam.source === parameterUtils_1.ParameterSource.PositionOrKeyword &&
18821
+ if (baseParam.kind === parameterUtils_1.ParameterKind.Standard &&
18741
18822
  baseParam.param.category === 0 /* ParameterCategory.Simple */) {
18742
18823
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
18743
18824
  index: i + 1,
@@ -18770,10 +18851,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18770
18851
  }
18771
18852
  }
18772
18853
  // Now check any keyword-only parameters.
18773
- const baseKwOnlyParams = baseParamDetails.params.filter((paramInfo) => paramInfo.source === parameterUtils_1.ParameterSource.KeywordOnly &&
18774
- paramInfo.param.category === 0 /* ParameterCategory.Simple */);
18775
- const overrideKwOnlyParams = overrideParamDetails.params.filter((paramInfo) => paramInfo.source === parameterUtils_1.ParameterSource.KeywordOnly &&
18776
- paramInfo.param.category === 0 /* ParameterCategory.Simple */);
18854
+ const baseKwOnlyParams = baseParamDetails.params.filter((paramInfo) => paramInfo.kind === parameterUtils_1.ParameterKind.Keyword && paramInfo.param.category === 0 /* ParameterCategory.Simple */);
18855
+ const overrideKwOnlyParams = overrideParamDetails.params.filter((paramInfo) => paramInfo.kind === parameterUtils_1.ParameterKind.Keyword && paramInfo.param.category === 0 /* ParameterCategory.Simple */);
18777
18856
  baseKwOnlyParams.forEach((paramInfo) => {
18778
18857
  var _a, _b, _c;
18779
18858
  const overrideParamInfo = overrideKwOnlyParams.find((pi) => paramInfo.param.name === pi.param.name);
@@ -19115,21 +19194,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19115
19194
  case 56 /* ParseNodeType.Unpack */:
19116
19195
  case 52 /* ParseNodeType.Tuple */:
19117
19196
  case 9 /* ParseNodeType.Call */:
19118
- case 32 /* ParseNodeType.ListComprehension */:
19197
+ case 11 /* ParseNodeType.Comprehension */:
19119
19198
  case 46 /* ParseNodeType.Slice */:
19120
19199
  case 60 /* ParseNodeType.Yield */:
19121
19200
  case 61 /* ParseNodeType.YieldFrom */:
19122
- case 30 /* ParseNodeType.Lambda */:
19201
+ case 33 /* ParseNodeType.Lambda */:
19123
19202
  case 40 /* ParseNodeType.Number */:
19124
- case 15 /* ParseNodeType.Dictionary */:
19125
- case 31 /* ParseNodeType.List */:
19203
+ case 18 /* ParseNodeType.Dictionary */:
19204
+ case 34 /* ParseNodeType.List */:
19126
19205
  case 45 /* ParseNodeType.Set */:
19127
19206
  return false;
19128
19207
  case 7 /* ParseNodeType.BinaryOperation */:
19129
19208
  return (node.operator === 6 /* OperatorType.BitwiseOr */ &&
19130
19209
  isLegalTypeAliasExpressionForm(node.leftExpression) &&
19131
19210
  isLegalTypeAliasExpressionForm(node.rightExpression));
19132
- case 24 /* ParseNodeType.Index */:
19211
+ case 27 /* ParseNodeType.Index */:
19133
19212
  return isLegalTypeAliasExpressionForm(node.baseExpression);
19134
19213
  case 35 /* ParseNodeType.MemberAccess */:
19135
19214
  return isLegalTypeAliasExpressionForm(node.leftExpression);