@zzzen/pyright-internal 1.2.0-dev.20240526 → 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 (108) hide show
  1. package/dist/analyzer/analyzerNodeInfo.d.ts +2 -2
  2. package/dist/analyzer/binder.d.ts +3 -3
  3. package/dist/analyzer/binder.js +32 -32
  4. package/dist/analyzer/binder.js.map +1 -1
  5. package/dist/analyzer/checker.d.ts +3 -3
  6. package/dist/analyzer/checker.js +35 -35
  7. package/dist/analyzer/checker.js.map +1 -1
  8. package/dist/analyzer/codeFlowEngine.js +4 -4
  9. package/dist/analyzer/codeFlowTypes.js +3 -3
  10. package/dist/analyzer/constructors.js +10 -3
  11. package/dist/analyzer/constructors.js.map +1 -1
  12. package/dist/analyzer/declarationUtils.js +3 -3
  13. package/dist/analyzer/enums.js +6 -6
  14. package/dist/analyzer/importResolver.d.ts +1 -0
  15. package/dist/analyzer/importResolver.js +6 -3
  16. package/dist/analyzer/importResolver.js.map +1 -1
  17. package/dist/analyzer/importStatementUtils.js +6 -6
  18. package/dist/analyzer/namedTuples.js +2 -2
  19. package/dist/analyzer/operations.js +2 -2
  20. package/dist/analyzer/parseTreeUtils.d.ts +1 -1
  21. package/dist/analyzer/parseTreeUtils.js +94 -94
  22. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  23. package/dist/analyzer/parseTreeWalker.d.ts +5 -5
  24. package/dist/analyzer/parseTreeWalker.js +64 -64
  25. package/dist/analyzer/parseTreeWalker.js.map +1 -1
  26. package/dist/analyzer/patternMatching.js +1 -1
  27. package/dist/analyzer/program.d.ts +1 -1
  28. package/dist/analyzer/program.js +23 -29
  29. package/dist/analyzer/program.js.map +1 -1
  30. package/dist/analyzer/scope.d.ts +1 -1
  31. package/dist/analyzer/scope.js +2 -2
  32. package/dist/analyzer/scope.js.map +1 -1
  33. package/dist/analyzer/sourceMapper.js +4 -4
  34. package/dist/analyzer/staticExpressions.js +3 -3
  35. package/dist/analyzer/testWalker.js +1 -1
  36. package/dist/analyzer/tracePrinter.js +4 -4
  37. package/dist/analyzer/typeDocStringUtils.js +1 -1
  38. package/dist/analyzer/typeEvaluator.js +290 -311
  39. package/dist/analyzer/typeEvaluator.js.map +1 -1
  40. package/dist/analyzer/typeGuards.js +6 -6
  41. package/dist/analyzer/typeStubWriter.js +1 -1
  42. package/dist/analyzer/typeUtils.d.ts +1 -1
  43. package/dist/analyzer/typeUtils.js +11 -4
  44. package/dist/analyzer/typeUtils.js.map +1 -1
  45. package/dist/analyzer/typedDicts.d.ts +1 -2
  46. package/dist/analyzer/typedDicts.js +5 -17
  47. package/dist/analyzer/typedDicts.js.map +1 -1
  48. package/dist/commands/dumpFileDebugInfoCommand.d.ts +1 -1
  49. package/dist/commands/dumpFileDebugInfoCommand.js +14 -14
  50. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  51. package/dist/common/textEditTracker.js +5 -5
  52. package/dist/common/uri/fileUri.js +1 -0
  53. package/dist/common/uri/fileUri.js.map +1 -1
  54. package/dist/common/uri/uri.d.ts +3 -0
  55. package/dist/common/uri/uri.js +16 -0
  56. package/dist/common/uri/uri.js.map +1 -1
  57. package/dist/languageService/autoImporter.js +4 -4
  58. package/dist/languageService/callHierarchyProvider.js +1 -1
  59. package/dist/languageService/completionProvider.js +30 -30
  60. package/dist/languageService/completionProvider.js.map +1 -1
  61. package/dist/languageService/documentSymbolCollector.js +7 -7
  62. package/dist/languageService/hoverProvider.js +2 -2
  63. package/dist/languageService/importSorter.js +1 -1
  64. package/dist/languageService/referencesProvider.js +4 -4
  65. package/dist/languageService/referencesProvider.js.map +1 -1
  66. package/dist/languageService/symbolIndexer.js +3 -3
  67. package/dist/languageService/tooltipUtils.js +2 -2
  68. package/dist/localization/localize.d.ts +1 -1
  69. package/dist/localization/localize.js +1 -1
  70. package/dist/localization/localize.js.map +1 -1
  71. package/dist/localization/package.nls.cs.json +3 -1
  72. package/dist/localization/package.nls.de.json +3 -1
  73. package/dist/localization/package.nls.en-us.json +1 -1
  74. package/dist/localization/package.nls.es.json +3 -1
  75. package/dist/localization/package.nls.fr.json +3 -1
  76. package/dist/localization/package.nls.it.json +3 -1
  77. package/dist/localization/package.nls.ja.json +3 -1
  78. package/dist/localization/package.nls.ko.json +3 -1
  79. package/dist/localization/package.nls.pl.json +3 -1
  80. package/dist/localization/package.nls.pt-br.json +3 -1
  81. package/dist/localization/package.nls.qps-ploc.json +3 -1
  82. package/dist/localization/package.nls.ru.json +3 -1
  83. package/dist/localization/package.nls.tr.json +3 -1
  84. package/dist/localization/package.nls.zh-cn.json +3 -1
  85. package/dist/localization/package.nls.zh-tw.json +3 -1
  86. package/dist/parser/parseNodes.d.ts +42 -42
  87. package/dist/parser/parseNodes.js +69 -69
  88. package/dist/parser/parseNodes.js.map +1 -1
  89. package/dist/parser/parser.d.ts +1 -1
  90. package/dist/parser/parser.js +35 -35
  91. package/dist/parser/parser.js.map +1 -1
  92. package/dist/pyright.js +3 -3
  93. package/dist/pyright.js.map +1 -1
  94. package/dist/tests/classDeclaration.test.js +1 -1
  95. package/dist/tests/importResolver.test.js +16 -0
  96. package/dist/tests/importResolver.test.js.map +1 -1
  97. package/dist/tests/parseTreeUtils.test.js +4 -4
  98. package/dist/tests/parser.test.js +3 -3
  99. package/dist/tests/typeEvaluator2.test.js +5 -1
  100. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  101. package/dist/tests/typeEvaluator4.test.js +1 -1
  102. package/dist/tests/typeEvaluator7.test.js +0 -6
  103. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  104. package/dist/tests/uri.test.js +11 -3
  105. package/dist/tests/uri.test.js.map +1 -1
  106. package/dist/workspaceFactory.js +16 -14
  107. package/dist/workspaceFactory.js.map +1 -1
  108. 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();
@@ -546,7 +537,7 @@ 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);
550
541
  let typeResult = getTypeOfExpressionCore(node, flags, inferenceContext, signatureTracker);
551
542
  // Should we disable type promotions for bytes?
552
543
  if ((0, types_1.isInstantiableClass)(typeResult.type) &&
@@ -605,7 +596,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
605
596
  typeResult = getTypeOfMemberAccess(node, flags);
606
597
  break;
607
598
  }
608
- case 24 /* ParseNodeType.Index */: {
599
+ case 27 /* ParseNodeType.Index */: {
609
600
  typeResult = getTypeOfIndex(node, flags);
610
601
  break;
611
602
  }
@@ -617,7 +608,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
617
608
  typeResult = getTypeOfTuple(node, flags, inferenceContext, signatureTracker);
618
609
  break;
619
610
  }
620
- case 11 /* ParseNodeType.Constant */: {
611
+ case 14 /* ParseNodeType.Constant */: {
621
612
  typeResult = getTypeOfConstant(node, flags);
622
613
  break;
623
614
  }
@@ -635,7 +626,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
635
626
  typeResult = getTypeOfNumber(node, typeResult);
636
627
  break;
637
628
  }
638
- case 18 /* ParseNodeType.Ellipsis */: {
629
+ case 21 /* ParseNodeType.Ellipsis */: {
639
630
  typeResult = getTypeOfEllipsis(flags, typeResult, node);
640
631
  break;
641
632
  }
@@ -657,7 +648,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
657
648
  typeResult = (0, operations_1.getTypeOfAugmentedAssignment)(evaluatorInterface, node, inferenceContext);
658
649
  break;
659
650
  }
660
- case 31 /* ParseNodeType.List */:
651
+ case 34 /* ParseNodeType.List */:
661
652
  case 45 /* ParseNodeType.Set */: {
662
653
  typeResult = getTypeOfListOrSet(node, flags, inferenceContext);
663
654
  break;
@@ -674,15 +665,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
674
665
  typeResult = (0, operations_1.getTypeOfTernaryOperation)(evaluatorInterface, node, flags, inferenceContext);
675
666
  break;
676
667
  }
677
- case 32 /* ParseNodeType.ListComprehension */: {
678
- typeResult = getTypeOfListComprehension(node, flags, inferenceContext);
668
+ case 11 /* ParseNodeType.Comprehension */: {
669
+ typeResult = getTypeOfComprehension(node, flags, inferenceContext);
679
670
  break;
680
671
  }
681
- case 15 /* ParseNodeType.Dictionary */: {
672
+ case 18 /* ParseNodeType.Dictionary */: {
682
673
  typeResult = getTypeOfDictionary(node, flags, inferenceContext);
683
674
  break;
684
675
  }
685
- case 30 /* ParseNodeType.Lambda */: {
676
+ case 33 /* ParseNodeType.Lambda */: {
686
677
  typeResult = getTypeOfLambda(node, inferenceContext);
687
678
  break;
688
679
  }
@@ -724,7 +715,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
724
715
  break;
725
716
  }
726
717
  case 49 /* ParseNodeType.String */:
727
- case 27 /* ParseNodeType.FormatString */: {
718
+ case 30 /* ParseNodeType.FormatString */: {
728
719
  typeResult = getTypeOfString(node);
729
720
  break;
730
721
  }
@@ -946,7 +937,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
946
937
  });
947
938
  const isBytes = (node.strings[0].token.flags & 32 /* StringTokenFlags.Bytes */) !== 0;
948
939
  // Don't create a literal type if it's an f-string.
949
- if (node.strings.some((str) => str.nodeType === 27 /* ParseNodeType.FormatString */)) {
940
+ if (node.strings.some((str) => str.nodeType === 30 /* ParseNodeType.FormatString */)) {
950
941
  if (isLiteralString) {
951
942
  const literalStringType = getTypingType(node, 'LiteralString');
952
943
  if (literalStringType && (0, types_1.isInstantiableClass)(literalStringType)) {
@@ -974,7 +965,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
974
965
  let typeResult;
975
966
  let isIncomplete = false;
976
967
  // Don't create a literal type if it's an f-string.
977
- if (node.nodeType === 27 /* ParseNodeType.FormatString */) {
968
+ if (node.nodeType === 30 /* ParseNodeType.FormatString */) {
978
969
  let isLiteralString = true;
979
970
  // If all of the format expressions are of type LiteralString, then
980
971
  // the resulting formatted string is also LiteralString.
@@ -1040,8 +1031,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1040
1031
  }
1041
1032
  if (types_1.ClassType.isBuiltIn(subtype, 'LiteralString')) {
1042
1033
  // Handle "LiteralString" specially.
1043
- if (strClassType && (0, types_1.isInstantiableClass)(strClassType)) {
1044
- let strInstance = types_1.ClassType.cloneAsInstance(strClassType);
1034
+ if (strClass && (0, types_1.isInstantiableClass)(strClass)) {
1035
+ let strInstance = types_1.ClassType.cloneAsInstance(strClass);
1045
1036
  if (subtype.condition) {
1046
1037
  strInstance = types_1.TypeBase.cloneForCondition(strInstance, (0, typeUtils_1.getTypeCondition)(subtype));
1047
1038
  }
@@ -1733,7 +1724,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1733
1724
  }
1734
1725
  break;
1735
1726
  }
1736
- case 24 /* ParseNodeType.Index */: {
1727
+ case 27 /* ParseNodeType.Index */: {
1737
1728
  const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.baseExpression, 2 /* EvaluatorFlags.IndexBaseDefaults */).type);
1738
1729
  if (baseType && (0, types_1.isClassInstance)(baseType)) {
1739
1730
  const setItemType = getBoundMagicMethod(baseType, '__setitem__');
@@ -1786,12 +1777,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1786
1777
  // (object that provides an __await__ that returns a generator object).
1787
1778
  // If errorNode is undefined, no errors are reported.
1788
1779
  function getTypeOfAwaitable(type, errorNode) {
1789
- if (!awaitableProtocolType ||
1790
- !(0, types_1.isInstantiableClass)(awaitableProtocolType) ||
1791
- awaitableProtocolType.details.typeParameters.length !== 1) {
1780
+ if (!awaitableClass ||
1781
+ !(0, types_1.isInstantiableClass)(awaitableClass) ||
1782
+ awaitableClass.details.typeParameters.length !== 1) {
1792
1783
  return types_1.UnknownType.create();
1793
1784
  }
1794
- const awaitableProtocolObj = types_1.ClassType.cloneAsInstance(awaitableProtocolType);
1785
+ const awaitableProtocolObj = types_1.ClassType.cloneAsInstance(awaitableClass);
1795
1786
  return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
1796
1787
  subtype = makeTopLevelTypeVarsConcrete(subtype);
1797
1788
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
@@ -1852,8 +1843,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1852
1843
  if (!isAsync && (0, types_1.isClassInstance)(subtype)) {
1853
1844
  const getItemReturnType = getTypeOfMagicMethodCall(subtype, '__getitem__', [
1854
1845
  {
1855
- type: intClassType && (0, types_1.isInstantiableClass)(intClassType)
1856
- ? types_1.ClassType.cloneAsInstance(intClassType)
1846
+ type: intClass && (0, types_1.isInstantiableClass)(intClass)
1847
+ ? types_1.ClassType.cloneAsInstance(intClass)
1857
1848
  : types_1.UnknownType.create(),
1858
1849
  },
1859
1850
  ], errorNode);
@@ -1882,7 +1873,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1882
1873
  // know anything more about them.
1883
1874
  nextReturnType = (0, typeUtils_1.mapSubtypes)(nextReturnType, (returnSubtype) => {
1884
1875
  if ((0, types_1.isTypeVar)(returnSubtype) && (0, types_1.isUnpackedVariadicTypeVar)(returnSubtype)) {
1885
- return objectType !== null && objectType !== void 0 ? objectType : types_1.UnknownType.create();
1876
+ return getObjectType();
1886
1877
  }
1887
1878
  return returnSubtype;
1888
1879
  });
@@ -1983,21 +1974,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1983
1974
  return isTypeHashable;
1984
1975
  }
1985
1976
  function getTypedDictClassType() {
1986
- return typedDictPrivateClassType && (0, types_1.isInstantiableClass)(typedDictPrivateClassType)
1987
- ? typedDictPrivateClassType
1988
- : undefined;
1977
+ return typedDictPrivateClass && (0, types_1.isInstantiableClass)(typedDictPrivateClass) ? typedDictPrivateClass : undefined;
1989
1978
  }
1990
1979
  function getTupleClassType() {
1991
- return tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType) ? tupleClassType : undefined;
1980
+ return tupleClass && (0, types_1.isInstantiableClass)(tupleClass) ? tupleClass : undefined;
1992
1981
  }
1993
1982
  function getObjectType() {
1994
- return objectType !== null && objectType !== void 0 ? objectType : types_1.UnknownType.create();
1983
+ return objectClass ? (0, typeUtils_1.convertToInstance)(objectClass) : types_1.UnknownType.create();
1995
1984
  }
1996
1985
  function getNoneType() {
1997
- return noneType !== null && noneType !== void 0 ? noneType : types_1.UnknownType.create();
1986
+ return noneTypeClass ? (0, typeUtils_1.convertToInstance)(noneTypeClass) : types_1.UnknownType.create();
1998
1987
  }
1999
1988
  function getUnionClassType() {
2000
- return unionClassType !== null && unionClassType !== void 0 ? unionClassType : types_1.UnknownType.create();
1989
+ return unionTypeClass !== null && unionTypeClass !== void 0 ? unionTypeClass : types_1.UnknownType.create();
2001
1990
  }
2002
1991
  function getTypingType(node, symbolName) {
2003
1992
  var _a;
@@ -2022,11 +2011,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2022
2011
  return getEffectiveTypeOfSymbol(symbol);
2023
2012
  }
2024
2013
  function checkCodeFlowTooComplex(node) {
2025
- const scopeNode = node.nodeType === 28 /* ParseNodeType.Function */ ? node : ParseTreeUtils.getExecutionScopeNode(node);
2014
+ const scopeNode = node.nodeType === 31 /* ParseNodeType.Function */ ? node : ParseTreeUtils.getExecutionScopeNode(node);
2026
2015
  const codeComplexity = AnalyzerNodeInfo.getCodeFlowComplexity(scopeNode);
2027
2016
  if (codeComplexity > exports.maxCodeComplexity) {
2028
2017
  let errorRange = scopeNode;
2029
- if (scopeNode.nodeType === 28 /* ParseNodeType.Function */) {
2018
+ if (scopeNode.nodeType === 31 /* ParseNodeType.Function */) {
2030
2019
  errorRange = scopeNode.name;
2031
2020
  }
2032
2021
  else if (scopeNode.nodeType === 36 /* ParseNodeType.Module */) {
@@ -2099,7 +2088,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2099
2088
  // of a Literal['xxx'] statement. If so, we will not treat
2100
2089
  // the string as a normal forward-declared type annotation.
2101
2090
  function isAnnotationLiteralValue(node) {
2102
- if (node.parent && node.parent.nodeType === 24 /* ParseNodeType.Index */) {
2091
+ if (node.parent && node.parent.nodeType === 27 /* ParseNodeType.Index */) {
2103
2092
  const baseType = getTypeOfExpression(node.parent.baseExpression).type;
2104
2093
  if (baseType && (0, types_1.isInstantiableClass)(baseType)) {
2105
2094
  if (types_1.ClassType.isSpecialBuiltIn(baseType, 'Literal')) {
@@ -2419,7 +2408,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2419
2408
  }
2420
2409
  }
2421
2410
  function assignTypeToTupleOrListNode(target, type, isTypeIncomplete, srcExpr) {
2422
- const targetExpressions = target.nodeType === 31 /* ParseNodeType.List */ ? target.entries : target.expressions;
2411
+ const targetExpressions = target.nodeType === 34 /* ParseNodeType.List */ ? target.entries : target.expressions;
2423
2412
  // Initialize the array of target types, one for each target.
2424
2413
  const targetTypes = new Array(targetExpressions.length);
2425
2414
  for (let i = 0; i < targetExpressions.length; i++) {
@@ -2453,7 +2442,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2453
2442
  if (sourceEntryTypes.length > targetTypes.length) {
2454
2443
  const removedEntries = sourceEntryTypes.splice(targetUnpackIndex, sourceEntryTypes.length - targetTypes.length + 1);
2455
2444
  let combinedTypes = (0, types_1.combineTypes)(removedEntries);
2456
- if (target.nodeType === 31 /* ParseNodeType.List */) {
2445
+ if (target.nodeType === 34 /* ParseNodeType.List */) {
2457
2446
  combinedTypes = stripLiteralValue(combinedTypes);
2458
2447
  }
2459
2448
  sourceEntryTypes.splice(targetUnpackIndex, 0, combinedTypes);
@@ -2470,7 +2459,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2470
2459
  // Have we accounted for all of the targets and sources? If not, we have a size mismatch.
2471
2460
  if (sourceEntryTypes.length !== targetExpressions.length) {
2472
2461
  const subDiag = diagAddendum.createAddendum();
2473
- subDiag.addMessage((target.nodeType === 31 /* ParseNodeType.List */
2462
+ subDiag.addMessage((target.nodeType === 34 /* ParseNodeType.List */
2474
2463
  ? localize_1.LocAddendum.listAssignmentMismatch()
2475
2464
  : localize_1.LocAddendum.tupleAssignmentMismatch()).format({
2476
2465
  type: printType(subtype),
@@ -2493,7 +2482,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2493
2482
  }
2494
2483
  });
2495
2484
  if (!diagAddendum.isEmpty()) {
2496
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, (target.nodeType === 31 /* ParseNodeType.List */
2485
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssignmentType, (target.nodeType === 34 /* ParseNodeType.List */
2497
2486
  ? localize_1.LocMessage.listAssignmentMismatch()
2498
2487
  : localize_1.LocMessage.tupleAssignmentMismatch()).format({
2499
2488
  type: printType(type),
@@ -2542,22 +2531,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2542
2531
  // TypeVar, only the conditions that match the filter will be included.
2543
2532
  function makeTopLevelTypeVarsConcrete(type, makeParamSpecsConcrete = false, conditionFilter) {
2544
2533
  return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
2545
- var _a, _b;
2534
+ var _a;
2546
2535
  if ((0, types_1.isParamSpec)(subtype)) {
2547
2536
  if (subtype.paramSpecAccess === 'args') {
2548
- if (objectType && (0, types_1.isClassInstance)(objectType)) {
2549
- return makeTupleObject([{ type: objectType, isUnbounded: true }]);
2550
- }
2551
- return types_1.UnknownType.create();
2537
+ return makeTupleObject([{ type: getObjectType(), isUnbounded: true }]);
2552
2538
  }
2553
2539
  else if (subtype.paramSpecAccess === 'kwargs') {
2554
- if (dictClassType &&
2555
- (0, types_1.isInstantiableClass)(dictClassType) &&
2556
- strClassType &&
2557
- (0, types_1.isInstantiableClass)(strClassType) &&
2558
- objectType &&
2559
- (0, types_1.isClassInstance)(objectType)) {
2560
- 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()],
2561
2542
  /* isTypeArgumentExplicit */ true));
2562
2543
  }
2563
2544
  return types_1.UnknownType.create();
@@ -2575,18 +2556,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2575
2556
  // If it's in a union, convert to type or object.
2576
2557
  if (subtype.isVariadicInUnion) {
2577
2558
  if (types_1.TypeBase.isInstantiable(subtype)) {
2578
- if (typeClassType && (0, types_1.isInstantiableClass)(typeClassType)) {
2579
- return typeClassType;
2559
+ if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
2560
+ return typeClass;
2580
2561
  }
2581
2562
  }
2582
- else if (objectType) {
2583
- return objectType;
2563
+ else {
2564
+ return getObjectType();
2584
2565
  }
2585
2566
  return types_1.AnyType.create();
2586
2567
  }
2587
2568
  // Fall back to "*tuple[object, ...]".
2588
- return makeTupleObject([{ type: objectType !== null && objectType !== void 0 ? objectType : types_1.UnknownType.create(), isUnbounded: true }],
2589
- /* isUnpacked */ true);
2569
+ return makeTupleObject([{ type: getObjectType(), isUnbounded: true }], /* isUnpacked */ true);
2590
2570
  }
2591
2571
  if ((0, types_1.isTypeVar)(subtype)) {
2592
2572
  // If this is a recursive type alias placeholder
@@ -2619,7 +2599,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2619
2599
  return types_1.AnyType.create();
2620
2600
  }
2621
2601
  // Fall back to a bound of "object" if no bound is provided.
2622
- 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();
2623
2603
  boundType = types_1.TypeBase.isInstantiable(subtype) ? (0, typeUtils_1.convertToInstantiable)(boundType) : boundType;
2624
2604
  return (0, typeUtils_1.addConditionToType)(boundType, [{ typeVar: subtype, constraintIndex: 0 }]);
2625
2605
  }
@@ -2774,7 +2754,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2774
2754
  assignTypeToMemberAccessNode(target, type, isTypeIncomplete, srcExpr, expectedTypeDiagAddendum);
2775
2755
  break;
2776
2756
  }
2777
- case 24 /* ParseNodeType.Index */: {
2757
+ case 27 /* ParseNodeType.Index */: {
2778
2758
  const baseTypeResult = getTypeOfExpression(target.baseExpression, 2 /* EvaluatorFlags.IndexBaseDefaults */);
2779
2759
  getTypeOfIndexWithBaseType(target, baseTypeResult, {
2780
2760
  method: 'set',
@@ -2785,7 +2765,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2785
2765
  writeTypeCache(target, { type, isIncomplete: isTypeIncomplete }, 0 /* EvaluatorFlags.None */);
2786
2766
  break;
2787
2767
  }
2788
- case 31 /* ParseNodeType.List */:
2768
+ case 34 /* ParseNodeType.List */:
2789
2769
  case 52 /* ParseNodeType.Tuple */: {
2790
2770
  assignTypeToTupleOrListNode(target, type, isTypeIncomplete, srcExpr);
2791
2771
  break;
@@ -2912,7 +2892,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2912
2892
  writeTypeCache(node, resultToCache, 0 /* EvaluatorFlags.None */);
2913
2893
  break;
2914
2894
  }
2915
- case 24 /* ParseNodeType.Index */: {
2895
+ case 27 /* ParseNodeType.Index */: {
2916
2896
  const baseTypeResult = getTypeOfExpression(node.baseExpression, 2 /* EvaluatorFlags.IndexBaseDefaults */);
2917
2897
  getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* EvaluatorFlags.None */);
2918
2898
  writeTypeCache(node, { type: types_1.UnboundType.create() }, 0 /* EvaluatorFlags.None */);
@@ -3162,8 +3142,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3162
3142
  // Find the parse node associated with the scope that is just inside of the
3163
3143
  // scope that declares the captured variable.
3164
3144
  const innerScopeNode = ScopeUtils.findTopNodeInScope(node, scopeHierarchy[scopeHierarchy.length - 2]);
3165
- if ((innerScopeNode === null || innerScopeNode === void 0 ? void 0 : innerScopeNode.nodeType) === 28 /* ParseNodeType.Function */ ||
3166
- (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 */ ||
3167
3147
  (innerScopeNode === null || innerScopeNode === void 0 ? void 0 : innerScopeNode.nodeType) === 10 /* ParseNodeType.Class */) {
3168
3148
  const innerScopeCodeFlowNode = AnalyzerNodeInfo.getFlowNode(innerScopeNode);
3169
3149
  if (innerScopeCodeFlowNode) {
@@ -3236,7 +3216,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3236
3216
  const memberName = node.parent.memberName.value;
3237
3217
  if (memberName === 'args' || memberName === 'kwargs') {
3238
3218
  const outerFunctionScope = ParseTreeUtils.getEnclosingClassOrFunction(enclosingScope);
3239
- 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 */) {
3240
3220
  enclosingScope = outerFunctionScope;
3241
3221
  }
3242
3222
  else if (!scopedTypeVarInfo.type.scopeId) {
@@ -3256,7 +3236,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3256
3236
  container: enclosingScope.name.value,
3257
3237
  }), node);
3258
3238
  }
3259
- 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 */
3260
3240
  ? 1 /* TypeVarScopeType.Function */
3261
3241
  : 0 /* TypeVarScopeType.Class */);
3262
3242
  }
@@ -3327,7 +3307,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3327
3307
  if (param.details.isDefaultExplicit || param.details.isParamSpec) {
3328
3308
  defaultType = (0, typeUtils_1.applySolvedTypeVars)(param, typeVarContext, { unknownIfNotFound: true });
3329
3309
  }
3330
- else if (param.details.isVariadic && tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
3310
+ else if (param.details.isVariadic && tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
3331
3311
  defaultType = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }],
3332
3312
  /* isUnpackedTuple */ true);
3333
3313
  }
@@ -3367,7 +3347,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3367
3347
  scopeUsesTypeParameterSyntax = !!curNode.typeParameters;
3368
3348
  nestedClassCount++;
3369
3349
  }
3370
- else if (curNode.nodeType === 28 /* ParseNodeType.Function */) {
3350
+ else if (curNode.nodeType === 31 /* ParseNodeType.Function */) {
3371
3351
  const functionType = getTypeOfFunctionPredecorated(curNode);
3372
3352
  if (functionType) {
3373
3353
  const functionDetails = functionType.details;
@@ -3731,8 +3711,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3731
3711
  // be reported elsewhere.
3732
3712
  return undefined;
3733
3713
  }
3734
- if ((0, typeUtils_1.isNoneInstance)(subtype) && noneType && (0, types_1.isClassInstance)(noneType)) {
3735
- 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);
3736
3717
  if (typeResult && !typeResult.typeErrors) {
3737
3718
  type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType));
3738
3719
  if (typeResult.isIncomplete) {
@@ -3774,7 +3755,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3774
3755
  }
3775
3756
  }
3776
3757
  else {
3777
- 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;
3778
3759
  }
3779
3760
  break;
3780
3761
  }
@@ -4008,7 +3989,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4008
3989
  // If a Final instance variable is declared in the class body but is
4009
3990
  // being assigned within an __init__ method, it's allowed.
4010
3991
  const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(errorNode);
4011
- if (!enclosingFunctionNode || enclosingFunctionNode.name.value !== '__init__') {
3992
+ if (!enclosingFunctionNode ||
3993
+ enclosingFunctionNode.name.value !== '__init__' ||
3994
+ finalVarTypeDecl.inferredTypeSource !== undefined ||
3995
+ (0, types_1.isInstantiableClass)(classType)) {
4012
3996
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocMessage.finalReassigned().format({ name: memberName }));
4013
3997
  isDescriptorError = true;
4014
3998
  }
@@ -4392,8 +4376,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4392
4376
  argList.push({
4393
4377
  argumentCategory: 0 /* ArgumentCategory.Simple */,
4394
4378
  typeResult: {
4395
- type: strClassType && (0, types_1.isInstantiableClass)(strClassType)
4396
- ? 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)
4397
4381
  : types_1.AnyType.create(),
4398
4382
  },
4399
4383
  });
@@ -4901,17 +4885,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4901
4885
  types_1.ClassType.isPartiallyEvaluated(concreteSubtype);
4902
4886
  const isFinalAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'Final');
4903
4887
  const isClassVarAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'ClassVar');
4904
- // Inlined TypedDicts are supported only for 'dict' (and not for 'Dict').
4905
- // This feature is currently experimental.
4906
- const supportsTypedDictTypeArg = AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures &&
4907
- types_1.ClassType.isBuiltIn(concreteSubtype, 'dict') &&
4908
- !types_1.ClassType.isBuiltIn(concreteSubtype, 'Dict');
4909
4888
  let typeArgs = getTypeArgs(node, flags, {
4910
4889
  isAnnotatedClass,
4911
4890
  hasCustomClassGetItem: hasCustomClassGetItem || !isGenericClass,
4912
4891
  isFinalAnnotation,
4913
4892
  isClassVarAnnotation,
4914
- supportsTypedDictTypeArg,
4915
4893
  });
4916
4894
  if (!isAnnotatedClass) {
4917
4895
  typeArgs = adjustTypeArgumentsForVariadicTypeVar(typeArgs, concreteSubtype.details.typeParameters, node);
@@ -5059,8 +5037,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5059
5037
  });
5060
5038
  }
5061
5039
  function makeTupleObject(typeArgs, isUnpackedTuple = false) {
5062
- if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
5063
- 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));
5064
5042
  }
5065
5043
  return types_1.UnknownType.create();
5066
5044
  }
@@ -5371,7 +5349,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5371
5349
  };
5372
5350
  }
5373
5351
  else {
5374
- typeResult = getTypeArg(expr, adjFlags, !!(options === null || options === void 0 ? void 0 : options.supportsTypedDictTypeArg) && argIndex === 0);
5352
+ typeResult = getTypeArg(expr, adjFlags);
5375
5353
  }
5376
5354
  return typeResult;
5377
5355
  };
@@ -5415,7 +5393,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5415
5393
  }
5416
5394
  return typeArgs;
5417
5395
  }
5418
- function getTypeArg(node, flags, supportsDictExpression) {
5396
+ function getTypeArg(node, flags) {
5419
5397
  let typeResult;
5420
5398
  let adjustedFlags = flags |
5421
5399
  128 /* EvaluatorFlags.ExpectingInstantiableType */ |
@@ -5425,7 +5403,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5425
5403
  if (fileInfo.isStubFile) {
5426
5404
  adjustedFlags |= 4 /* EvaluatorFlags.AllowForwardReferences */;
5427
5405
  }
5428
- if (node.nodeType === 31 /* ParseNodeType.List */) {
5406
+ if (node.nodeType === 34 /* ParseNodeType.List */) {
5429
5407
  typeResult = {
5430
5408
  type: types_1.UnknownType.create(),
5431
5409
  typeList: node.entries.map((entry) => {
@@ -5436,20 +5414,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5436
5414
  // Set the node's type so it isn't reevaluated later.
5437
5415
  setTypeResultForNode(node, { type: types_1.UnknownType.create() });
5438
5416
  }
5439
- else if (node.nodeType === 15 /* ParseNodeType.Dictionary */ && supportsDictExpression) {
5440
- const inlinedTypeDict = typedDictClassType && (0, types_1.isInstantiableClass)(typedDictClassType)
5441
- ? (0, typedDicts_1.createTypedDictTypeInlined)(evaluatorInterface, node, typedDictClassType)
5442
- : undefined;
5443
- const keyTypeFallback = strClassType && (0, types_1.isInstantiableClass)(strClassType) ? strClassType : types_1.UnknownType.create();
5444
- typeResult = {
5445
- type: keyTypeFallback,
5446
- inlinedTypeDict,
5447
- node,
5448
- };
5449
- }
5450
5417
  else {
5451
5418
  typeResult = { ...getTypeOfExpression(node, adjustedFlags), node };
5452
- if (node.nodeType === 15 /* ParseNodeType.Dictionary */) {
5419
+ if (node.nodeType === 18 /* ParseNodeType.Dictionary */) {
5453
5420
  addError(localize_1.LocMessage.dictInAnnotation(), node);
5454
5421
  }
5455
5422
  if ((flags & 131072 /* EvaluatorFlags.DisallowClassVar */) !== 0) {
@@ -5525,7 +5492,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5525
5492
  if (!(0, types_1.isClassInstance)(inferenceContext.expectedType)) {
5526
5493
  return undefined;
5527
5494
  }
5528
- if (!tupleClassType || !(0, types_1.isInstantiableClass)(tupleClassType)) {
5495
+ if (!tupleClass || !(0, types_1.isInstantiableClass)(tupleClass)) {
5529
5496
  return undefined;
5530
5497
  }
5531
5498
  // Build an array of expected types.
@@ -5545,11 +5512,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5545
5512
  }
5546
5513
  }
5547
5514
  else {
5548
- const tupleTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(tupleClassType));
5549
- 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)) {
5550
5517
  return undefined;
5551
5518
  }
5552
- const specializedTuple = (0, typeUtils_1.applySolvedTypeVars)(tupleClassType, tupleTypeVarContext);
5519
+ const specializedTuple = (0, typeUtils_1.applySolvedTypeVars)(tupleClass, tupleTypeVarContext);
5553
5520
  if (!specializedTuple.typeArguments || specializedTuple.typeArguments.length !== 1) {
5554
5521
  return undefined;
5555
5522
  }
@@ -5641,7 +5608,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5641
5608
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeCallNotAllowed() + diag.getString(), node);
5642
5609
  }
5643
5610
  // Handle immediate calls of lambdas specially.
5644
- if (node.leftExpression.nodeType === 30 /* ParseNodeType.Lambda */) {
5611
+ if (node.leftExpression.nodeType === 33 /* ParseNodeType.Lambda */) {
5645
5612
  baseTypeResult = getTypeOfLambdaForCall(node, inferenceContext);
5646
5613
  }
5647
5614
  else {
@@ -5748,7 +5715,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5748
5715
  // to determine the lambda's type. It needs to be inferred from the argument
5749
5716
  // types instead.
5750
5717
  function getTypeOfLambdaForCall(node, inferenceContext) {
5751
- (0, debug_1.assert)(node.leftExpression.nodeType === 30 /* ParseNodeType.Lambda */);
5718
+ (0, debug_1.assert)(node.leftExpression.nodeType === 33 /* ParseNodeType.Lambda */);
5752
5719
  const expectedType = types_1.FunctionType.createSynthesizedInstance('');
5753
5720
  expectedType.details.declaredReturnType = inferenceContext
5754
5721
  ? inferenceContext.expectedType
@@ -5882,7 +5849,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5882
5849
  scope = ScopeUtils.getScopeForNode(curNode);
5883
5850
  // Stop when we get a valid scope that's not a list comprehension
5884
5851
  // scope. That includes lambdas, functions, classes, and modules.
5885
- if (scope && scope.type !== 1 /* ScopeType.ListComprehension */) {
5852
+ if (scope && scope.type !== 1 /* ScopeType.Comprehension */) {
5886
5853
  break;
5887
5854
  }
5888
5855
  curNode = curNode.parent;
@@ -6058,10 +6025,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6058
6025
  }
6059
6026
  else if (effectiveTargetClass &&
6060
6027
  !(0, types_1.isAnyOrUnknown)(effectiveTargetClass) &&
6061
- !(0, typeUtils_1.derivesFromAnyOrUnknown)(effectiveTargetClass) &&
6062
- objectType &&
6063
- (0, types_1.isClassInstance)(objectType)) {
6064
- resultType = types_1.ClassType.cloneAsInstantiable(objectType);
6028
+ !(0, typeUtils_1.derivesFromAnyOrUnknown)(effectiveTargetClass)) {
6029
+ resultType = objectClass !== null && objectClass !== void 0 ? objectClass : types_1.UnknownType.create();
6065
6030
  }
6066
6031
  else {
6067
6032
  resultType = types_1.UnknownType.create();
@@ -6102,9 +6067,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6102
6067
  return { type: resultIsInstance ? (0, typeUtils_1.convertToInstance)(nextBaseClassType) : nextBaseClassType };
6103
6068
  }
6104
6069
  // There's not much we can say about the type. Simply return object or type.
6105
- if (objectType && (0, types_1.isClassInstance)(objectType) && typeClassType && (0, types_1.isInstantiableClass)(typeClassType)) {
6070
+ if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
6106
6071
  return {
6107
- type: resultIsInstance ? objectType : (0, typeUtils_1.convertToInstance)(typeClassType),
6072
+ type: resultIsInstance ? getObjectType() : (0, typeUtils_1.convertToInstance)(typeClass),
6108
6073
  };
6109
6074
  }
6110
6075
  }
@@ -7063,7 +7028,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7063
7028
  // If this is a tuple with specified element types, use those
7064
7029
  // specified types rather than using the more generic iterator
7065
7030
  // type which will be a union of all element types.
7066
- const combinedArgType = (0, typeUtils_1.combineSameSizedTuples)(makeTopLevelTypeVarsConcrete(argType), tupleClassType);
7031
+ const combinedArgType = (0, typeUtils_1.combineSameSizedTuples)(makeTopLevelTypeVarsConcrete(argType), tupleClass);
7067
7032
  if ((0, types_1.isClassInstance)(combinedArgType) && (0, typeUtils_1.isTupleClass)(combinedArgType)) {
7068
7033
  const tupleTypeArgs = (_a = combinedArgType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [];
7069
7034
  if (tupleTypeArgs.length !== 1 || !tupleTypeArgs[0].isUnbounded) {
@@ -7592,20 +7557,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7592
7557
  }
7593
7558
  else {
7594
7559
  const strObjType = getBuiltInObject(errorNode, 'str');
7595
- if (supportsKeysAndGetItemProtocolType &&
7596
- (0, types_1.isInstantiableClass)(supportsKeysAndGetItemProtocolType) &&
7560
+ if (supportsKeysAndGetItemClass &&
7561
+ (0, types_1.isInstantiableClass)(supportsKeysAndGetItemClass) &&
7597
7562
  strObjType &&
7598
7563
  (0, types_1.isClassInstance)(strObjType)) {
7599
- const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(supportsKeysAndGetItemProtocolType));
7564
+ const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(supportsKeysAndGetItemClass));
7600
7565
  let isValidMappingType = false;
7601
7566
  // If this was a TypeVar (e.g. for pseudo-generic classes),
7602
7567
  // don't emit this error.
7603
7568
  if ((0, types_1.isTypeVar)(argType)) {
7604
7569
  isValidMappingType = true;
7605
7570
  }
7606
- else if (assignType(types_1.ClassType.cloneAsInstance(supportsKeysAndGetItemProtocolType), argType,
7571
+ else if (assignType(types_1.ClassType.cloneAsInstance(supportsKeysAndGetItemClass), argType,
7607
7572
  /* diag */ undefined, mappingTypeVarContext)) {
7608
- const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(supportsKeysAndGetItemProtocolType, mappingTypeVarContext);
7573
+ const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(supportsKeysAndGetItemClass, mappingTypeVarContext);
7609
7574
  const typeArgs = specializedMapping.typeArguments;
7610
7575
  if (typeArgs && typeArgs.length >= 2) {
7611
7576
  if (assignType(strObjType, typeArgs[0])) {
@@ -8252,7 +8217,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8252
8217
  types_1.ClassType.isBuiltIn(specializedReturnType, ['TypeGuard', 'TypeIs']) &&
8253
8218
  specializedReturnType.typeArguments &&
8254
8219
  specializedReturnType.typeArguments.length > 0) {
8255
- if (boolClassType && (0, types_1.isInstantiableClass)(boolClassType)) {
8220
+ if (boolClass && (0, types_1.isInstantiableClass)(boolClass)) {
8256
8221
  let typeGuardType = specializedReturnType.typeArguments[0];
8257
8222
  // If the first argument is a simple (non-constrained) TypeVar,
8258
8223
  // associate that TypeVar with the resulting TypeGuard type.
@@ -8267,7 +8232,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8267
8232
  }
8268
8233
  }
8269
8234
  const useTypeIsSemantics = types_1.ClassType.isBuiltIn(specializedReturnType, 'TypeIs');
8270
- 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));
8271
8236
  }
8272
8237
  }
8273
8238
  const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
@@ -8990,12 +8955,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8990
8955
  }
8991
8956
  function getParamSpecDefaultType(node, isPep695Syntax) {
8992
8957
  const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
8993
- if (node.nodeType === 18 /* ParseNodeType.Ellipsis */) {
8958
+ if (node.nodeType === 21 /* ParseNodeType.Ellipsis */) {
8994
8959
  types_1.FunctionType.addDefaultParameters(functionType);
8995
8960
  functionType.details.flags |= 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
8996
8961
  return functionType;
8997
8962
  }
8998
- if (node.nodeType === 31 /* ParseNodeType.List */) {
8963
+ if (node.nodeType === 34 /* ParseNodeType.List */) {
8999
8964
  node.entries.forEach((paramExpr, index) => {
9000
8965
  const typeResult = getTypeOfExpressionExpectingType(paramExpr, {
9001
8966
  allowTypeVarsWithoutScopeId: true,
@@ -9125,7 +9090,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9125
9090
  /* typeParamNodes */ undefined, () => typeParameters);
9126
9091
  }
9127
9092
  function getBooleanValue(node) {
9128
- if (node.nodeType === 11 /* ParseNodeType.Constant */) {
9093
+ if (node.nodeType === 14 /* ParseNodeType.Constant */) {
9129
9094
  if (node.constType === 15 /* KeywordType.False */) {
9130
9095
  return false;
9131
9096
  }
@@ -9179,9 +9144,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9179
9144
  let baseClass = getTypeOfArgumentExpectingType(argList[1]).type;
9180
9145
  let isBaseClassAny = false;
9181
9146
  if ((0, types_1.isAnyOrUnknown)(baseClass)) {
9182
- if (objectType && (0, types_1.isClassInstance)(objectType)) {
9183
- baseClass = types_1.ClassType.cloneAsInstantiable(objectType);
9184
- }
9147
+ baseClass = objectClass !== null && objectClass !== void 0 ? objectClass : types_1.UnknownType.create();
9185
9148
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeAnyOrUnknown(), (_c = argList[1].node) !== null && _c !== void 0 ? _c : errorNode);
9186
9149
  isBaseClassAny = true;
9187
9150
  }
@@ -9264,7 +9227,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9264
9227
  classType.details.baseClasses.push(specializedType);
9265
9228
  }
9266
9229
  else {
9267
- addExpectedClassDiagnostic(typeArg.type, argList[1].valueExpression || errorNode);
9230
+ classType.details.baseClasses.push(types_1.UnknownType.create());
9268
9231
  }
9269
9232
  });
9270
9233
  if (!(0, typeUtils_1.computeMroLinearization)(classType)) {
@@ -9275,7 +9238,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9275
9238
  function getTypeOfConstant(node, flags) {
9276
9239
  let type;
9277
9240
  if (node.constType === 26 /* KeywordType.None */) {
9278
- 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
+ }
9279
9247
  }
9280
9248
  else if (node.constType === 33 /* KeywordType.True */ ||
9281
9249
  node.constType === 15 /* KeywordType.False */ ||
@@ -9346,15 +9314,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9346
9314
  return handleSubtype(subtype);
9347
9315
  }
9348
9316
  if ((0, typeUtils_1.isNoneInstance)(subtype)) {
9349
- if (objectType && (0, types_1.isClassInstance)(objectType)) {
9317
+ if (objectClass && (0, types_1.isInstantiableClass)(objectClass)) {
9350
9318
  // Use 'object' for 'None'.
9351
- return handleSubtype(objectType);
9319
+ return handleSubtype((0, typeUtils_1.convertToInstance)(objectClass));
9352
9320
  }
9353
9321
  }
9354
9322
  if ((0, typeUtils_1.isNoneTypeClass)(subtype)) {
9355
- if (typeClassType && (0, types_1.isInstantiableClass)(typeClassType)) {
9323
+ if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
9356
9324
  // Use 'type' for 'type[None]'.
9357
- return handleSubtype(types_1.ClassType.cloneAsInstance(typeClassType));
9325
+ return handleSubtype(types_1.ClassType.cloneAsInstance(typeClass));
9358
9326
  }
9359
9327
  }
9360
9328
  magicMethodSupported = false;
@@ -9569,9 +9537,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9569
9537
  128 /* EvaluatorFlags.ExpectingInstantiableType */);
9570
9538
  // Infer the key and value types if possible.
9571
9539
  node.entries.forEach((entryNode, index) => {
9572
- var _a, _b, _c, _d;
9540
+ var _a, _b, _c;
9573
9541
  let addUnknown = true;
9574
- if (entryNode.nodeType === 17 /* ParseNodeType.DictionaryKeyEntry */) {
9542
+ if (entryNode.nodeType === 20 /* ParseNodeType.DictionaryKeyEntry */) {
9575
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)));
9576
9544
  if (keyTypeResult.isIncomplete) {
9577
9545
  isIncomplete = true;
@@ -9633,11 +9601,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9633
9601
  }
9634
9602
  addUnknown = false;
9635
9603
  }
9636
- else if (entryNode.nodeType === 16 /* ParseNodeType.DictionaryExpandEntry */) {
9604
+ else if (entryNode.nodeType === 19 /* ParseNodeType.DictionaryExpandEntry */) {
9637
9605
  let expectedType;
9638
9606
  if (expectedKeyType && expectedValueType) {
9639
- if (supportsKeysAndGetItemProtocolType && (0, types_1.isInstantiableClass)(supportsKeysAndGetItemProtocolType)) {
9640
- 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],
9641
9609
  /* isTypeArgumentExplicit */ true));
9642
9610
  }
9643
9611
  }
@@ -9661,8 +9629,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9661
9629
  }
9662
9630
  else if ((0, types_1.isClassInstance)(unexpandedType) && types_1.ClassType.isTypedDictClass(unexpandedType)) {
9663
9631
  // Handle dictionary expansion for a TypedDict.
9664
- if (strClassType && (0, types_1.isInstantiableClass)(strClassType)) {
9665
- const strObject = types_1.ClassType.cloneAsInstance(strClassType);
9632
+ if (strClass && (0, types_1.isInstantiableClass)(strClass)) {
9633
+ const strObject = types_1.ClassType.cloneAsInstance(strClass);
9666
9634
  const tdEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, unexpandedType,
9667
9635
  /* allowNarrowed */ true);
9668
9636
  tdEntries.knownItems.forEach((entry, name) => {
@@ -9678,20 +9646,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9678
9646
  keyTypes.push({ node: entryNode, type: types_1.ClassType.cloneAsInstance(strObject) });
9679
9647
  valueTypes.push({
9680
9648
  node: entryNode,
9681
- 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(),
9682
9650
  });
9683
9651
  }
9684
9652
  addUnknown = false;
9685
9653
  }
9686
9654
  }
9687
- else if (supportsKeysAndGetItemProtocolType &&
9688
- (0, types_1.isInstantiableClass)(supportsKeysAndGetItemProtocolType)) {
9689
- const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(supportsKeysAndGetItemProtocolType));
9690
- supportsKeysAndGetItemProtocolType = (0, typeUtils_1.selfSpecializeClass)(supportsKeysAndGetItemProtocolType);
9691
- 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,
9692
9659
  /* diag */ undefined, mappingTypeVarContext,
9693
9660
  /* srcTypeVarContext */ undefined, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */)) {
9694
- const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(supportsKeysAndGetItemProtocolType, mappingTypeVarContext);
9661
+ const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(supportsKeysAndGetItemClass, mappingTypeVarContext);
9695
9662
  const typeArgs = specializedMapping.typeArguments;
9696
9663
  if (typeArgs && typeArgs.length >= 2) {
9697
9664
  if (forceStrictInference || index < maxEntriesToUseForInference) {
@@ -9706,8 +9673,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9706
9673
  }
9707
9674
  }
9708
9675
  }
9709
- else if (entryNode.nodeType === 32 /* ParseNodeType.ListComprehension */) {
9710
- const dictEntryTypeResult = getElementTypeFromListComprehension(entryNode, flags, expectedValueType, expectedKeyType);
9676
+ else if (entryNode.nodeType === 11 /* ParseNodeType.Comprehension */) {
9677
+ const dictEntryTypeResult = getElementTypeFromComprehension(entryNode, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, expectedValueType, expectedKeyType);
9711
9678
  const dictEntryType = dictEntryTypeResult.type;
9712
9679
  if (dictEntryTypeResult.isIncomplete) {
9713
9680
  isIncomplete = true;
@@ -9717,7 +9684,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9717
9684
  }
9718
9685
  // The result should be a tuple.
9719
9686
  if ((0, types_1.isClassInstance)(dictEntryType) && (0, typeUtils_1.isTupleClass)(dictEntryType)) {
9720
- 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);
9721
9688
  if (typeArgs && typeArgs.length === 2) {
9722
9689
  if (forceStrictInference || index < maxEntriesToUseForInference) {
9723
9690
  keyTypes.push({ node: entryNode, type: typeArgs[0] });
@@ -9739,7 +9706,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9739
9706
  function getTypeOfListOrSet(node, flags, inferenceContext) {
9740
9707
  var _a;
9741
9708
  if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0 &&
9742
- node.nodeType === 31 /* ParseNodeType.List */ &&
9709
+ node.nodeType === 34 /* ParseNodeType.List */ &&
9743
9710
  ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
9744
9711
  const diag = new diagnostic_1.DiagnosticAddendum();
9745
9712
  diag.addMessage(localize_1.LocAddendum.useListInstead());
@@ -9789,7 +9756,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9789
9756
  // Attempts to determine the type of a list or set statement based on an expected type.
9790
9757
  // Returns undefined if that type cannot be honored.
9791
9758
  function getTypeOfListOrSetWithContext(node, flags, inferenceContext) {
9792
- const builtInClassName = node.nodeType === 31 /* ParseNodeType.List */ ? 'list' : 'set';
9759
+ const builtInClassName = node.nodeType === 34 /* ParseNodeType.List */ ? 'list' : 'set';
9793
9760
  inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
9794
9761
  let isIncomplete = false;
9795
9762
  let typeErrors = false;
@@ -9802,8 +9769,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9802
9769
  const expectedTypeDiagAddendum = new diagnostic_1.DiagnosticAddendum();
9803
9770
  node.entries.forEach((entry) => {
9804
9771
  let entryTypeResult;
9805
- if (entry.nodeType === 32 /* ParseNodeType.ListComprehension */) {
9806
- entryTypeResult = getElementTypeFromListComprehension(entry, flags, expectedEntryType);
9772
+ if (entry.nodeType === 11 /* ParseNodeType.Comprehension */) {
9773
+ entryTypeResult = getElementTypeFromComprehension(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, expectedEntryType);
9807
9774
  }
9808
9775
  else {
9809
9776
  entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedEntryType));
@@ -9861,7 +9828,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9861
9828
  }
9862
9829
  // Attempts to infer the type of a list or set statement with no "expected type".
9863
9830
  function getTypeOfListOrSetInferred(node, flags, hasExpectedType) {
9864
- const builtInClassName = node.nodeType === 31 /* ParseNodeType.List */ ? 'list' : 'set';
9831
+ const builtInClassName = node.nodeType === 34 /* ParseNodeType.List */ ? 'list' : 'set';
9865
9832
  const verifyHashable = node.nodeType === 45 /* ParseNodeType.Set */;
9866
9833
  let isEmptyContainer = false;
9867
9834
  let isIncomplete = false;
@@ -9869,8 +9836,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9869
9836
  let entryTypes = [];
9870
9837
  node.entries.forEach((entry, index) => {
9871
9838
  let entryTypeResult;
9872
- if (entry.nodeType === 32 /* ParseNodeType.ListComprehension */ && !entry.isGenerator) {
9873
- entryTypeResult = getElementTypeFromListComprehension(entry, flags);
9839
+ if (entry.nodeType === 11 /* ParseNodeType.Comprehension */ && !entry.isGenerator) {
9840
+ entryTypeResult = getElementTypeFromComprehension(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */);
9874
9841
  }
9875
9842
  else {
9876
9843
  entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */);
@@ -10189,14 +10156,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10189
10156
  }
10190
10157
  return { type: functionType, isIncomplete, typeErrors };
10191
10158
  }
10192
- function getTypeOfListComprehension(node, flags, inferenceContext) {
10159
+ function getTypeOfComprehension(node, flags, inferenceContext) {
10193
10160
  let isIncomplete = false;
10194
10161
  let typeErrors = false;
10195
10162
  // If any of the "for" clauses are marked async or any of the "if" clauses
10196
10163
  // or any clause other than the leftmost "for" contain an "await" operator,
10197
10164
  // it is treated as an async generator.
10198
10165
  let isAsync = node.forIfNodes.some((comp, index) => {
10199
- if (comp.nodeType === 33 /* ParseNodeType.ListComprehensionFor */ && comp.isAsync) {
10166
+ if (comp.nodeType === 12 /* ParseNodeType.ComprehensionFor */ && comp.isAsync) {
10200
10167
  return true;
10201
10168
  }
10202
10169
  return index > 0 && ParseTreeUtils.containsAwaitNode(comp);
@@ -10207,7 +10174,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10207
10174
  }
10208
10175
  const builtInIteratorType = getTypingType(node, isAsync ? 'AsyncGenerator' : 'Generator');
10209
10176
  const expectedEntryType = getExpectedEntryTypeForIterable(node, builtInIteratorType, inferenceContext);
10210
- const elementTypeResult = getElementTypeFromListComprehension(node, flags, expectedEntryType);
10177
+ const elementTypeResult = getElementTypeFromComprehension(node, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, expectedEntryType);
10211
10178
  if (elementTypeResult.isIncomplete) {
10212
10179
  isIncomplete = true;
10213
10180
  }
@@ -10251,10 +10218,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10251
10218
  }
10252
10219
  }
10253
10220
  }
10254
- function evaluateListComprehensionForIf(node) {
10221
+ function evaluateComprehensionForIf(node) {
10255
10222
  var _a;
10256
10223
  let isIncomplete = false;
10257
- if (node.nodeType === 33 /* ParseNodeType.ListComprehensionFor */) {
10224
+ if (node.nodeType === 12 /* ParseNodeType.ComprehensionFor */) {
10258
10225
  const iterableTypeResult = getTypeOfExpression(node.iterableExpression);
10259
10226
  if (iterableTypeResult.isIncomplete) {
10260
10227
  isIncomplete = true;
@@ -10265,7 +10232,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10265
10232
  assignTypeToExpression(targetExpr, itemTypeResult.type, !!itemTypeResult.isIncomplete, node.iterableExpression);
10266
10233
  }
10267
10234
  else {
10268
- (0, debug_1.assert)(node.nodeType === 34 /* ParseNodeType.ListComprehensionIf */);
10235
+ (0, debug_1.assert)(node.nodeType === 13 /* ParseNodeType.ComprehensionIf */);
10269
10236
  // Evaluate the test expression to validate it and mark symbols
10270
10237
  // as referenced. Don't bother doing this if we're in speculative
10271
10238
  // mode because it doesn't affect the element type.
@@ -10275,21 +10242,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10275
10242
  }
10276
10243
  return isIncomplete;
10277
10244
  }
10278
- // Returns the type of one entry returned by the list comprehension,
10279
- // as opposed to the entire list.
10280
- function getElementTypeFromListComprehension(node, flags, expectedValueOrElementType, expectedKeyType) {
10245
+ // Returns the type of one entry returned by the comprehension.
10246
+ function getElementTypeFromComprehension(node, flags, expectedValueOrElementType, expectedKeyType) {
10281
10247
  let isIncomplete = false;
10282
10248
  let typeErrors = false;
10283
10249
  // "Execute" the list comprehensions from start to finish.
10284
10250
  for (const forIfNode of node.forIfNodes) {
10285
- if (evaluateListComprehensionForIf(forIfNode)) {
10251
+ if (evaluateComprehensionForIf(forIfNode)) {
10286
10252
  isIncomplete = true;
10287
10253
  }
10288
10254
  }
10289
10255
  let type = types_1.UnknownType.create();
10290
- if (node.expression.nodeType === 17 /* ParseNodeType.DictionaryKeyEntry */) {
10256
+ if (node.expression.nodeType === 20 /* ParseNodeType.DictionaryKeyEntry */) {
10291
10257
  // Create a tuple with the key/value types.
10292
- const keyTypeResult = getTypeOfExpression(node.expression.keyExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedKeyType));
10258
+ const keyTypeResult = getTypeOfExpression(node.expression.keyExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedKeyType));
10293
10259
  if (keyTypeResult.isIncomplete) {
10294
10260
  isIncomplete = true;
10295
10261
  }
@@ -10300,7 +10266,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10300
10266
  if (!expectedKeyType || !(0, typeUtils_1.containsLiteralType)(expectedKeyType)) {
10301
10267
  keyType = stripLiteralValue(keyType);
10302
10268
  }
10303
- const valueTypeResult = getTypeOfExpression(node.expression.valueExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10269
+ const valueTypeResult = getTypeOfExpression(node.expression.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10304
10270
  if (valueTypeResult.isIncomplete) {
10305
10271
  isIncomplete = true;
10306
10272
  }
@@ -10316,12 +10282,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10316
10282
  { type: valueType, isUnbounded: false },
10317
10283
  ]);
10318
10284
  }
10319
- else if (node.expression.nodeType === 16 /* ParseNodeType.DictionaryExpandEntry */) {
10285
+ else if (node.expression.nodeType === 19 /* ParseNodeType.DictionaryExpandEntry */) {
10320
10286
  // The parser should have reported an error in this case because it's not allowed.
10321
- getTypeOfExpression(node.expression.expandExpression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10287
+ getTypeOfExpression(node.expression.expandExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10322
10288
  }
10323
10289
  else if ((0, parseNodes_1.isExpressionNode)(node)) {
10324
- const exprTypeResult = getTypeOfExpression(node.expression, flags | 268435456 /* EvaluatorFlags.StripLiteralTypeForTuple */, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10290
+ const exprTypeResult = getTypeOfExpression(node.expression, flags, (0, typeUtils_1.makeInferenceContext)(expectedValueOrElementType));
10325
10291
  if (exprTypeResult.isIncomplete) {
10326
10292
  isIncomplete = true;
10327
10293
  }
@@ -10539,9 +10505,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10539
10505
  addExpectedClassDiagnostic(typeArg0Type, typeArgs[0].node);
10540
10506
  typeArg0Type = types_1.UnknownType.create();
10541
10507
  }
10542
- let optionalType = (0, types_1.combineTypes)([typeArg0Type, noneClassType !== null && noneClassType !== void 0 ? noneClassType : types_1.UnknownType.create()]);
10543
- if (unionClassType && (0, types_1.isInstantiableClass)(unionClassType)) {
10544
- 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));
10545
10511
  }
10546
10512
  return optionalType;
10547
10513
  }
@@ -10601,7 +10567,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10601
10567
  type = cloneBuiltinClassWithLiteral(node, classType, 'int', itemExpr.value);
10602
10568
  }
10603
10569
  }
10604
- else if (itemExpr.nodeType === 11 /* ParseNodeType.Constant */) {
10570
+ else if (itemExpr.nodeType === 14 /* ParseNodeType.Constant */) {
10605
10571
  if (itemExpr.constType === 33 /* KeywordType.True */) {
10606
10572
  type = cloneBuiltinClassWithLiteral(node, classType, 'bool', true);
10607
10573
  }
@@ -10609,7 +10575,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10609
10575
  type = cloneBuiltinClassWithLiteral(node, classType, 'bool', false);
10610
10576
  }
10611
10577
  else if (itemExpr.constType === 26 /* KeywordType.None */) {
10612
- type = noneClassType !== null && noneClassType !== void 0 ? noneClassType : types_1.UnknownType.create();
10578
+ type = noneTypeClass !== null && noneTypeClass !== void 0 ? noneTypeClass : types_1.UnknownType.create();
10613
10579
  }
10614
10580
  }
10615
10581
  else if (itemExpr.nodeType === 55 /* ParseNodeType.UnaryOperation */) {
@@ -10653,8 +10619,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10653
10619
  literalTypes.push(type);
10654
10620
  }
10655
10621
  let result = (0, types_1.combineTypes)(literalTypes);
10656
- if ((0, types_1.isUnion)(result) && unionClassType && (0, types_1.isInstantiableClass)(unionClassType)) {
10657
- 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));
10658
10624
  }
10659
10625
  return result;
10660
10626
  }
@@ -11048,6 +11014,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11048
11014
  }
11049
11015
  for (const typeArg of typeArgs) {
11050
11016
  let typeArgType = typeArg.type;
11017
+ // This is an experimental feature because Unions of unpacked TypeVarTuples are not officially supported.
11051
11018
  if (!validateTypeArg(typeArg, {
11052
11019
  allowVariadicTypeVar: fileInfo.diagnosticRuleSet.enableExperimentalFeatures,
11053
11020
  })) {
@@ -11059,6 +11026,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11059
11026
  }
11060
11027
  // If this is an unpacked tuple, explode out the individual items.
11061
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.
11062
11030
  if (fileInfo.diagnosticRuleSet.enableExperimentalFeatures) {
11063
11031
  typeArg.type.tupleTypeArguments.forEach((tupleTypeArg) => {
11064
11032
  types.push((0, typeUtils_1.convertToInstantiable)(tupleTypeArg.type));
@@ -11072,6 +11040,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11072
11040
  }
11073
11041
  else {
11074
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.
11075
11044
  if (fileInfo.diagnosticRuleSet.enableExperimentalFeatures) {
11076
11045
  // If this is an unpacked TypeVar, note that it is in a union so we can
11077
11046
  // differentiate between Unpack[Vs] and Union[Unpack[Vs]].
@@ -11093,8 +11062,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11093
11062
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.unionTypeArgCount(), errorNode);
11094
11063
  }
11095
11064
  let unionType = (0, types_1.combineTypes)(types);
11096
- if (unionClassType && (0, types_1.isInstantiableClass)(unionClassType)) {
11097
- 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));
11098
11067
  }
11099
11068
  return unionType;
11100
11069
  }
@@ -11321,7 +11290,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11321
11290
  // Handle 'LiteralString' specially because we want it to act as
11322
11291
  // though it derives from 'str'.
11323
11292
  if (assignedName === 'LiteralString') {
11324
- 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());
11325
11294
  (0, typeUtils_1.computeMroLinearization)(specialType);
11326
11295
  }
11327
11296
  writeTypeCache(node, { type: specialType }, 0 /* EvaluatorFlags.None */);
@@ -11599,7 +11568,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11599
11568
  return `__type_of_${paramName}`;
11600
11569
  }
11601
11570
  function getTypeOfClass(node) {
11602
- initializedBasicTypes(node);
11571
+ initializePrefetchedTypes(node);
11603
11572
  // Is this type already cached?
11604
11573
  const cachedClassType = readTypeCache(node.name, 0 /* EvaluatorFlags.None */);
11605
11574
  if (cachedClassType) {
@@ -11861,6 +11830,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11861
11830
  classType.details.flags |= 1024 /* ClassTypeFlags.CanOmitDictValues */;
11862
11831
  }
11863
11832
  else if (arg.name.value === 'closed' && constArgValue) {
11833
+ // This is an experimental feature because PEP 728 hasn't been accepted yet.
11864
11834
  if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
11865
11835
  classType.details.flags |=
11866
11836
  256 /* ClassTypeFlags.TypedDictMarkedClosed */ | 512 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
@@ -12216,9 +12186,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12216
12186
  if (!classType.details.requiresVarianceInference) {
12217
12187
  return;
12218
12188
  }
12219
- if (!objectType || !(0, types_1.isClassInstance)(objectType)) {
12220
- return;
12221
- }
12222
12189
  // Presumptively mark the variance inference as complete. This
12223
12190
  // prevents potential recursion.
12224
12191
  classType.details.requiresVarianceInference = false;
@@ -12245,8 +12212,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12245
12212
  if (p.details.isVariadic) {
12246
12213
  return p;
12247
12214
  }
12248
- (0, debug_1.assert)(objectType !== undefined);
12249
- return i === paramIndex ? objectType : dummyTypeObject;
12215
+ return i === paramIndex ? getObjectType() : dummyTypeObject;
12250
12216
  });
12251
12217
  // Replace all type arguments with a dummy type except for the
12252
12218
  // TypeVar of interest, which is replaced with itself.
@@ -12303,7 +12269,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12303
12269
  if (!effectiveMetaclass || (0, types_1.isInstantiableClass)(effectiveMetaclass)) {
12304
12270
  for (const baseClass of classType.details.baseClasses) {
12305
12271
  if ((0, types_1.isInstantiableClass)(baseClass)) {
12306
- const baseClassMeta = baseClass.details.effectiveMetaclass || typeClassType;
12272
+ const baseClassMeta = baseClass.details.effectiveMetaclass || typeClass;
12307
12273
  if (baseClassMeta && (0, types_1.isInstantiableClass)(baseClassMeta)) {
12308
12274
  // Make sure there is no metaclass conflict.
12309
12275
  if (!effectiveMetaclass) {
@@ -12536,7 +12502,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12536
12502
  });
12537
12503
  }
12538
12504
  function getTypeOfFunction(node) {
12539
- initializedBasicTypes(node);
12505
+ initializePrefetchedTypes(node);
12540
12506
  // Is this predecorated function type cached?
12541
12507
  let functionType = readTypeCache(node.name, 0 /* EvaluatorFlags.None */);
12542
12508
  if (functionType) {
@@ -12963,7 +12929,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12963
12929
  // the type checker should assume that the type is optional (i.e. a union
12964
12930
  // of the specified type and 'None'). Skip this step if the type is already
12965
12931
  // optional to avoid losing alias names when combining the types.
12966
- 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 */ &&
12967
12933
  param.defaultValue.constType === 26 /* KeywordType.None */ &&
12968
12934
  !(0, typeUtils_1.isOptionalType)(type) &&
12969
12935
  !AnalyzerNodeInfo.getFileInfo(param).diagnosticRuleSet.strictParameterNoneValue) {
@@ -13529,7 +13495,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13529
13495
  let symbolType = getAliasedSymbolTypeForName(node, aliasNode.value);
13530
13496
  if (!symbolType) {
13531
13497
  const parentNode = node.parent;
13532
- (0, debug_1.assert)(parentNode && parentNode.nodeType === 22 /* ParseNodeType.ImportFrom */);
13498
+ (0, debug_1.assert)(parentNode && parentNode.nodeType === 25 /* ParseNodeType.ImportFrom */);
13533
13499
  (0, debug_1.assert)(!parentNode.isWildcardImport);
13534
13500
  const importInfo = AnalyzerNodeInfo.getImportInfo(parentNode.module);
13535
13501
  if (importInfo && importInfo.isImportFound && !importInfo.isNativeLib) {
@@ -13721,7 +13687,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13721
13687
  if (!resolvedAliasInfo.declaration) {
13722
13688
  return evaluatorOptions.evaluateUnknownImportsAsAny ? types_1.AnyType.create() : types_1.UnknownType.create();
13723
13689
  }
13724
- if (node.nodeType === 23 /* ParseNodeType.ImportFromAs */) {
13690
+ if (node.nodeType === 26 /* ParseNodeType.ImportFromAs */) {
13725
13691
  if (resolvedAliasInfo.isPrivate) {
13726
13692
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportPrivateUsage, localize_1.LocMessage.privateUsedOutsideOfModule().format({
13727
13693
  name: node.name.value,
@@ -13751,7 +13717,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13751
13717
  // is technically not part of an expression. We'll handle these here so
13752
13718
  // callers don't need to include special-case logic.
13753
13719
  if (node.nodeType === 38 /* ParseNodeType.Name */ && node.parent) {
13754
- if (node.parent.nodeType === 28 /* ParseNodeType.Function */ && node.parent.name === node) {
13720
+ if (node.parent.nodeType === 31 /* ParseNodeType.Function */ && node.parent.name === node) {
13755
13721
  getTypeOfFunction(node.parent);
13756
13722
  return;
13757
13723
  }
@@ -13759,11 +13725,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13759
13725
  getTypeOfClass(node.parent);
13760
13726
  return;
13761
13727
  }
13762
- if (node.parent.nodeType === 23 /* ParseNodeType.ImportFromAs */) {
13728
+ if (node.parent.nodeType === 26 /* ParseNodeType.ImportFromAs */) {
13763
13729
  evaluateTypesForImportFromAs(node.parent);
13764
13730
  return;
13765
13731
  }
13766
- if (node.parent.nodeType === 21 /* ParseNodeType.ImportAs */) {
13732
+ if (node.parent.nodeType === 24 /* ParseNodeType.ImportAs */) {
13767
13733
  evaluateTypesForImportAs(node.parent);
13768
13734
  return;
13769
13735
  }
@@ -13771,7 +13737,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13771
13737
  getTypeOfTypeAlias(node.parent);
13772
13738
  return;
13773
13739
  }
13774
- 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 */) {
13775
13741
  // For global and nonlocal statements, allow forward references so
13776
13742
  // we don't use code flow during symbol lookups.
13777
13743
  getTypeOfExpression(node, 4 /* EvaluatorFlags.AllowForwardReferences */);
@@ -13807,7 +13773,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13807
13773
  evaluateTypesForTypeAnnotationNode(annotationParent);
13808
13774
  return;
13809
13775
  }
13810
- if (annotationParent.nodeType === 28 /* ParseNodeType.Function */ &&
13776
+ if (annotationParent.nodeType === 31 /* ParseNodeType.Function */ &&
13811
13777
  annotationNode === annotationParent.returnTypeAnnotation) {
13812
13778
  getTypeOfAnnotation(annotationNode, {
13813
13779
  associateTypeVarsWithScope: true,
@@ -13843,7 +13809,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13843
13809
  if (argumentNode && argumentNode !== nodeToEvaluate) {
13844
13810
  (0, debug_1.assert)(argumentNode.parent !== undefined);
13845
13811
  if (argumentNode.parent.nodeType === 9 /* ParseNodeType.Call */ ||
13846
- argumentNode.parent.nodeType === 24 /* ParseNodeType.Index */) {
13812
+ argumentNode.parent.nodeType === 27 /* ParseNodeType.Index */) {
13847
13813
  nodeToEvaluate = argumentNode.parent;
13848
13814
  continue;
13849
13815
  }
@@ -13875,7 +13841,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13875
13841
  continue;
13876
13842
  }
13877
13843
  // Handle the special case where the LHS is a call to a lambda.
13878
- if (parent.nodeType === 9 /* ParseNodeType.Call */ && nodeToEvaluate.nodeType === 30 /* ParseNodeType.Lambda */) {
13844
+ if (parent.nodeType === 9 /* ParseNodeType.Call */ && nodeToEvaluate.nodeType === 33 /* ParseNodeType.Lambda */) {
13879
13845
  nodeToEvaluate = parent;
13880
13846
  continue;
13881
13847
  }
@@ -13883,7 +13849,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13883
13849
  break;
13884
13850
  }
13885
13851
  }
13886
- else if (parent.nodeType === 24 /* ParseNodeType.Index */) {
13852
+ else if (parent.nodeType === 27 /* ParseNodeType.Index */) {
13887
13853
  // The base expression of an index expression is not contextual.
13888
13854
  if (nodeToEvaluate === parent.baseExpression) {
13889
13855
  flags = 2 /* EvaluatorFlags.IndexBaseDefaults */;
@@ -13903,17 +13869,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13903
13869
  // stop. However, there are a few special "pass through"
13904
13870
  // node types that we can skip over to get to a known
13905
13871
  // expression node.
13906
- if (parent.nodeType === 17 /* ParseNodeType.DictionaryKeyEntry */ ||
13907
- parent.nodeType === 16 /* ParseNodeType.DictionaryExpandEntry */ ||
13908
- parent.nodeType === 33 /* ParseNodeType.ListComprehensionFor */ ||
13909
- 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 */) {
13910
13876
  (0, debug_1.assert)(parent.parent !== undefined && (0, parseNodes_1.isExpressionNode)(parent.parent));
13911
13877
  parent = parent.parent;
13912
13878
  }
13913
13879
  else if (parent.nodeType === 41 /* ParseNodeType.Parameter */) {
13914
13880
  (0, debug_1.assert)(parent.parent !== undefined);
13915
13881
  // Parameters are contextual for lambdas.
13916
- if (parent.parent.nodeType === 30 /* ParseNodeType.Lambda */) {
13882
+ if (parent.parent.nodeType === 33 /* ParseNodeType.Lambda */) {
13917
13883
  parent = parent.parent;
13918
13884
  }
13919
13885
  else {
@@ -13938,7 +13904,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13938
13904
  const parent = nodeToEvaluate.parent;
13939
13905
  (0, debug_1.assert)(parent !== undefined);
13940
13906
  switch (parent.nodeType) {
13941
- case 14 /* ParseNodeType.Del */: {
13907
+ case 17 /* ParseNodeType.Del */: {
13942
13908
  verifyDeleteExpression(nodeToEvaluate);
13943
13909
  return;
13944
13910
  }
@@ -13957,11 +13923,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13957
13923
  getTypeOfTypeAlias(parent);
13958
13924
  return;
13959
13925
  }
13960
- case 13 /* ParseNodeType.Decorator */: {
13926
+ case 16 /* ParseNodeType.Decorator */: {
13961
13927
  if (((_d = parent.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 10 /* ParseNodeType.Class */) {
13962
13928
  getTypeOfClass(parent.parent);
13963
13929
  }
13964
- 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 */) {
13965
13931
  getTypeOfFunction(parent.parent);
13966
13932
  }
13967
13933
  return;
@@ -14023,11 +13989,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14023
13989
  // be inferred, whereas the latter sometimes have type annotations
14024
13990
  // but cannot be inferred.
14025
13991
  const parent = node.parent;
14026
- if (parent.nodeType === 30 /* ParseNodeType.Lambda */) {
13992
+ if (parent.nodeType === 33 /* ParseNodeType.Lambda */) {
14027
13993
  evaluateTypesForExpressionInContext(parent);
14028
13994
  return;
14029
13995
  }
14030
- (0, debug_1.assert)(parent.nodeType === 28 /* ParseNodeType.Function */);
13996
+ (0, debug_1.assert)(parent.nodeType === 31 /* ParseNodeType.Function */);
14031
13997
  const functionNode = parent;
14032
13998
  const paramIndex = functionNode.parameters.findIndex((param) => param === node);
14033
13999
  const typeAnnotation = ParseTreeUtils.getTypeAnnotationForParameter(functionNode, paramIndex);
@@ -14063,7 +14029,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14063
14029
  // be evaluated to provide sufficient context for the type. Evaluated types
14064
14030
  // are written back to the type cache for later retrieval.
14065
14031
  function evaluateTypesForStatement(node) {
14066
- initializedBasicTypes(node);
14032
+ initializePrefetchedTypes(node);
14067
14033
  let curNode = node;
14068
14034
  while (curNode) {
14069
14035
  switch (curNode.nodeType) {
@@ -14101,19 +14067,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14101
14067
  evaluateTypeOfParameter(curNode);
14102
14068
  return;
14103
14069
  }
14104
- case 30 /* ParseNodeType.Lambda */: {
14070
+ case 33 /* ParseNodeType.Lambda */: {
14105
14071
  evaluateTypesForExpressionInContext(curNode);
14106
14072
  return;
14107
14073
  }
14108
- case 28 /* ParseNodeType.Function */: {
14074
+ case 31 /* ParseNodeType.Function */: {
14109
14075
  getTypeOfFunction(curNode);
14110
14076
  return;
14111
14077
  }
14112
- case 26 /* ParseNodeType.For */: {
14078
+ case 29 /* ParseNodeType.For */: {
14113
14079
  evaluateTypesForForStatement(curNode);
14114
14080
  return;
14115
14081
  }
14116
- case 25 /* ParseNodeType.Except */: {
14082
+ case 28 /* ParseNodeType.Except */: {
14117
14083
  evaluateTypesForExceptStatement(curNode);
14118
14084
  return;
14119
14085
  }
@@ -14121,17 +14087,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14121
14087
  evaluateTypesForWithStatement(curNode);
14122
14088
  return;
14123
14089
  }
14124
- case 33 /* ParseNodeType.ListComprehensionFor */: {
14125
- const listComprehension = curNode.parent;
14126
- (0, debug_1.assert)(listComprehension.nodeType === 32 /* ParseNodeType.ListComprehension */);
14127
- if (curNode === listComprehension.expression) {
14128
- 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);
14129
14095
  }
14130
14096
  else {
14131
14097
  // Evaluate the individual iterations starting with the first
14132
14098
  // up to the curNode.
14133
- for (const forIfNode of listComprehension.forIfNodes) {
14134
- evaluateListComprehensionForIf(forIfNode);
14099
+ for (const forIfNode of comprehension.forIfNodes) {
14100
+ evaluateComprehensionForIf(forIfNode);
14135
14101
  if (forIfNode === curNode) {
14136
14102
  break;
14137
14103
  }
@@ -14139,15 +14105,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14139
14105
  }
14140
14106
  return;
14141
14107
  }
14142
- case 21 /* ParseNodeType.ImportAs */: {
14108
+ case 24 /* ParseNodeType.ImportAs */: {
14143
14109
  evaluateTypesForImportAs(curNode);
14144
14110
  return;
14145
14111
  }
14146
- case 23 /* ParseNodeType.ImportFromAs */: {
14112
+ case 26 /* ParseNodeType.ImportFromAs */: {
14147
14113
  evaluateTypesForImportFromAs(curNode);
14148
14114
  return;
14149
14115
  }
14150
- case 22 /* ParseNodeType.ImportFrom */: {
14116
+ case 25 /* ParseNodeType.ImportFrom */: {
14151
14117
  evaluateTypesForImportFrom(curNode);
14152
14118
  return;
14153
14119
  }
@@ -14371,8 +14337,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14371
14337
  return { type: types_1.UnknownType.create() };
14372
14338
  }
14373
14339
  }
14374
- if (typeClassType && (0, types_1.isInstantiableClass)(typeClassType)) {
14375
- let typeType = createSpecialType(typeClassType, typeArgs, 1,
14340
+ if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
14341
+ let typeType = createSpecialType(typeClass, typeArgs, 1,
14376
14342
  /* allowParamSpec */ undefined,
14377
14343
  /* isSpecialForm */ false);
14378
14344
  if ((0, types_1.isInstantiableClass)(typeType)) {
@@ -14710,7 +14676,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14710
14676
  // Functions and list comprehensions don't allow access to implicitly
14711
14677
  // aliased symbols in outer scopes if they haven't yet been assigned
14712
14678
  // within the local scope.
14713
- let scopeTypeHonorsCodeFlow = scopeType !== 2 /* ScopeType.Function */ && scopeType !== 1 /* ScopeType.ListComprehension */;
14679
+ let scopeTypeHonorsCodeFlow = scopeType !== 2 /* ScopeType.Function */ && scopeType !== 1 /* ScopeType.Comprehension */;
14714
14680
  // TypeParameter scopes don't honor code flow, but if the symbol is resolved
14715
14681
  // using the proxy scope for the TypeParameter scope, we should use code flow.
14716
14682
  if (scopeType === 0 /* ScopeType.TypeParameter */ && symbolWithScope && symbolWithScope.scope === scope) {
@@ -14914,7 +14880,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14914
14880
  }
14915
14881
  function getAliasFromImport(node) {
14916
14882
  if (node.parent &&
14917
- node.parent.nodeType === 23 /* ParseNodeType.ImportFromAs */ &&
14883
+ node.parent.nodeType === 26 /* ParseNodeType.ImportFromAs */ &&
14918
14884
  node.parent.alias &&
14919
14885
  node === node.parent.name) {
14920
14886
  return node.parent.alias;
@@ -15145,7 +15111,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15145
15111
  // has a function-level annotation comment that provides
15146
15112
  // this parameter's annotation type.
15147
15113
  if (!typeAnnotationNode) {
15148
- 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 */) {
15149
15115
  const functionNode = declaration.node.parent;
15150
15116
  if (functionNode.functionAnnotationComment &&
15151
15117
  !functionNode.functionAnnotationComment.isParamListEllipsis) {
@@ -15313,7 +15279,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15313
15279
  // Set the variance to "auto" for class-scoped TypeVars.
15314
15280
  typeVar.details.declaredVariance = 0 /* Variance.Auto */;
15315
15281
  }
15316
- else if (scopeNode.nodeType === 28 /* ParseNodeType.Function */) {
15282
+ else if (scopeNode.nodeType === 31 /* ParseNodeType.Function */) {
15317
15283
  scopeType = 1 /* TypeVarScopeType.Function */;
15318
15284
  }
15319
15285
  else {
@@ -16158,7 +16124,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16158
16124
  function getTypeOfMember(member) {
16159
16125
  if ((0, types_1.isInstantiableClass)(member.classType)) {
16160
16126
  return (0, typeUtils_1.partiallySpecializeType)(getEffectiveTypeOfSymbol(member.symbol), member.classType,
16161
- /* 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());
16162
16128
  }
16163
16129
  return types_1.UnknownType.create();
16164
16130
  }
@@ -16235,22 +16201,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16235
16201
  if (types_1.ClassType.isBuiltIn(destType, 'Mapping')) {
16236
16202
  const mappingValueType = (0, typedDicts_1.getTypedDictMappingEquivalent)(evaluatorInterface, srcType);
16237
16203
  if (mappingValueType &&
16238
- mappingType &&
16239
- (0, types_1.isInstantiableClass)(mappingType) &&
16240
- strClassType &&
16241
- (0, types_1.isInstantiableClass)(strClassType)) {
16242
- 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],
16243
16209
  /* isTypeArgumentExplicit */ true);
16244
16210
  }
16245
16211
  }
16246
16212
  else if (types_1.ClassType.isBuiltIn(destType, ['dict', 'MutableMapping'])) {
16247
16213
  const dictValueType = (0, typedDicts_1.getTypedDictDictEquivalent)(evaluatorInterface, srcType, recursionCount);
16248
16214
  if (dictValueType &&
16249
- dictClassType &&
16250
- (0, types_1.isInstantiableClass)(dictClassType) &&
16251
- strClassType &&
16252
- (0, types_1.isInstantiableClass)(strClassType)) {
16253
- 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],
16254
16220
  /* isTypeArgumentExplicit */ true);
16255
16221
  }
16256
16222
  }
@@ -16477,7 +16443,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16477
16443
  // If the only removed arg from the dest type args is itself a variadic,
16478
16444
  // don't bother adjusting it.
16479
16445
  const skipAdjustment = destArgsToCapture === 1 && (0, types_1.isVariadicTypeVar)(destTypeArgs[srcVariadicIndex].type);
16480
- if (!skipAdjustment && tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
16446
+ if (!skipAdjustment && tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
16481
16447
  const removedArgs = destTypeArgs.splice(srcVariadicIndex, destArgsToCapture);
16482
16448
  // Package up the remaining type arguments into a tuple object.
16483
16449
  const variadicTuple = makeTupleObject(removedArgs.map((typeArg) => {
@@ -16501,7 +16467,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16501
16467
  // If the dest contains a variadic element, determine which source
16502
16468
  // args map to this element and package them up into an unpacked tuple.
16503
16469
  if ((0, types_1.isVariadicTypeVar)(destTypeArgs[destUnboundedOrVariadicIndex].type)) {
16504
- if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
16470
+ if (tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
16505
16471
  const removedArgs = srcTypeArgs.splice(destUnboundedOrVariadicIndex, srcArgsToCapture);
16506
16472
  let variadicTuple;
16507
16473
  // If we're left with a single unpacked variadic type var, there's no
@@ -16966,20 +16932,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16966
16932
  // rather than dest. If the type variable is not in the scope of the
16967
16933
  // provided TypeVarContext, simply verify that the concrete types are
16968
16934
  // compatible.
16969
- 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)))) {
16970
16937
  return assignType(makeTopLevelTypeVarsConcrete(destType), makeTopLevelTypeVarsConcrete(srcType), diag,
16971
16938
  /* destTypeVarContext */ undefined,
16972
16939
  /* srcTypeVarContext */ undefined, originalFlags, recursionCount);
16973
16940
  }
16974
16941
  else {
16975
- 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)) {
16976
16943
  return true;
16977
16944
  }
16978
16945
  // If the dest type is a union, only one of the subtypes needs to match.
16979
16946
  let isAssignable = false;
16980
16947
  if ((0, types_1.isUnion)(destType)) {
16981
16948
  (0, typeUtils_1.doForEachSubtype)(destType, (destSubtype) => {
16982
- 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)) {
16983
16950
  isAssignable = true;
16984
16951
  }
16985
16952
  });
@@ -17209,10 +17176,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17209
17176
  }
17210
17177
  }
17211
17178
  else if (types_1.ClassType.isBuiltIn(concreteSrcType, 'LiteralString') &&
17212
- strClassType &&
17213
- (0, types_1.isInstantiableClass)(strClassType) &&
17179
+ strClass &&
17180
+ (0, types_1.isInstantiableClass)(strClass) &&
17214
17181
  (flags & 1 /* AssignTypeFlags.EnforceInvariance */) === 0) {
17215
- concreteSrcType = types_1.ClassType.cloneAsInstance(strClassType);
17182
+ concreteSrcType = types_1.ClassType.cloneAsInstance(strClass);
17216
17183
  }
17217
17184
  if (!assignClass(types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstantiable(concreteSrcType), diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
17218
17185
  /* reportErrorsUsingObjType */ true)) {
@@ -17227,8 +17194,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17227
17194
  return assignType(destCallbackType, concreteSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
17228
17195
  }
17229
17196
  // All functions are considered instances of "builtins.function".
17230
- if (functionObj && (0, types_1.isClassInstance)(functionObj)) {
17231
- 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);
17232
17199
  }
17233
17200
  }
17234
17201
  else if ((0, types_1.isModule)(concreteSrcType)) {
@@ -17382,8 +17349,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17382
17349
  }
17383
17350
  // Are we trying to assign None to a protocol?
17384
17351
  if ((0, typeUtils_1.isNoneInstance)(srcType) && (0, types_1.isClassInstance)(destType) && types_1.ClassType.isProtocolClass(destType)) {
17385
- if (noneClassType && (0, types_1.isInstantiableClass)(noneClassType)) {
17386
- 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);
17387
17354
  }
17388
17355
  }
17389
17356
  if ((0, typeUtils_1.isNoneInstance)(destType)) {
@@ -17810,8 +17777,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17810
17777
  for (const field of types_1.ClassType.getSymbolTable(mroClass)) {
17811
17778
  if (field[0] !== '__call__' && !field[1].isIgnoredForProtocolMatch()) {
17812
17779
  let fieldIsPartOfFunction = false;
17813
- if (functionObj && (0, types_1.isClass)(functionObj)) {
17814
- 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])) {
17815
17782
  fieldIsPartOfFunction = true;
17816
17783
  }
17817
17784
  }
@@ -18417,9 +18384,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18417
18384
  // type at runtime.
18418
18385
  if ((0, types_1.isClassInstance)(srcReturnType) &&
18419
18386
  types_1.ClassType.isBuiltIn(srcReturnType, ['TypeGuard', 'TypeIs']) &&
18420
- boolClassType &&
18421
- (0, types_1.isInstantiableClass)(boolClassType)) {
18422
- 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)) {
18423
18390
  isReturnTypeCompatible = true;
18424
18391
  }
18425
18392
  }
@@ -18467,7 +18434,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18467
18434
  replacedTypeArg = true;
18468
18435
  return expectedTypeArgType;
18469
18436
  }
18470
- else if ((0, types_1.isClassInstance)(expectedTypeArgType) && (0, types_1.isClassInstance)(typeArg)) {
18437
+ if ((0, types_1.isClassInstance)(expectedTypeArgType) && (0, types_1.isClassInstance)(typeArg)) {
18471
18438
  // Recursively replace Any in the type argument.
18472
18439
  const recursiveReplacement = replaceTypeArgsWithAny(node, expectedTypeArgType, typeArg, recursionCount);
18473
18440
  if (recursiveReplacement) {
@@ -18507,6 +18474,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18507
18474
  // When a value is assigned to a variable with a declared type,
18508
18475
  // we may be able to narrow the type based on the assignment.
18509
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.
18510
18482
  const narrowedType = (0, typeUtils_1.mapSubtypes)(assignedType, (assignedSubtype) => {
18511
18483
  // Handle the special case where the assigned type is a literal type.
18512
18484
  // Some types include very large unions of literal types, and we don't
@@ -18541,8 +18513,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18541
18513
  return declaredSubtype;
18542
18514
  }
18543
18515
  // If the declared type doesn't contain any `Any` but the assigned
18544
- // type does, stick with the declared type.
18545
- 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)) {
18546
18525
  return declaredSubtype;
18547
18526
  }
18548
18527
  return assignedSubtype;
@@ -19215,21 +19194,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19215
19194
  case 56 /* ParseNodeType.Unpack */:
19216
19195
  case 52 /* ParseNodeType.Tuple */:
19217
19196
  case 9 /* ParseNodeType.Call */:
19218
- case 32 /* ParseNodeType.ListComprehension */:
19197
+ case 11 /* ParseNodeType.Comprehension */:
19219
19198
  case 46 /* ParseNodeType.Slice */:
19220
19199
  case 60 /* ParseNodeType.Yield */:
19221
19200
  case 61 /* ParseNodeType.YieldFrom */:
19222
- case 30 /* ParseNodeType.Lambda */:
19201
+ case 33 /* ParseNodeType.Lambda */:
19223
19202
  case 40 /* ParseNodeType.Number */:
19224
- case 15 /* ParseNodeType.Dictionary */:
19225
- case 31 /* ParseNodeType.List */:
19203
+ case 18 /* ParseNodeType.Dictionary */:
19204
+ case 34 /* ParseNodeType.List */:
19226
19205
  case 45 /* ParseNodeType.Set */:
19227
19206
  return false;
19228
19207
  case 7 /* ParseNodeType.BinaryOperation */:
19229
19208
  return (node.operator === 6 /* OperatorType.BitwiseOr */ &&
19230
19209
  isLegalTypeAliasExpressionForm(node.leftExpression) &&
19231
19210
  isLegalTypeAliasExpressionForm(node.rightExpression));
19232
- case 24 /* ParseNodeType.Index */:
19211
+ case 27 /* ParseNodeType.Index */:
19233
19212
  return isLegalTypeAliasExpressionForm(node.baseExpression);
19234
19213
  case 35 /* ParseNodeType.MemberAccess */:
19235
19214
  return isLegalTypeAliasExpressionForm(node.leftExpression);