@zzzen/pyright-internal 1.2.0-dev.20220717 → 1.2.0-dev.20220724

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 (105) hide show
  1. package/dist/analyzer/analysis.js +1 -1
  2. package/dist/analyzer/analysis.js.map +1 -1
  3. package/dist/analyzer/checker.d.ts +1 -0
  4. package/dist/analyzer/checker.js +42 -1
  5. package/dist/analyzer/checker.js.map +1 -1
  6. package/dist/analyzer/constraintSolver.js +0 -1
  7. package/dist/analyzer/constraintSolver.js.map +1 -1
  8. package/dist/analyzer/dataClasses.js +13 -4
  9. package/dist/analyzer/dataClasses.js.map +1 -1
  10. package/dist/analyzer/importResolver.js +2 -2
  11. package/dist/analyzer/importResolver.js.map +1 -1
  12. package/dist/analyzer/importStatementUtils.d.ts +1 -1
  13. package/dist/analyzer/importStatementUtils.js +47 -18
  14. package/dist/analyzer/importStatementUtils.js.map +1 -1
  15. package/dist/analyzer/parseTreeUtils.d.ts +2 -0
  16. package/dist/analyzer/parseTreeUtils.js +71 -2
  17. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  18. package/dist/analyzer/patternMatching.js +1 -1
  19. package/dist/analyzer/patternMatching.js.map +1 -1
  20. package/dist/analyzer/service.d.ts +1 -1
  21. package/dist/analyzer/service.js +36 -37
  22. package/dist/analyzer/service.js.map +1 -1
  23. package/dist/analyzer/typeEvaluator.js +430 -410
  24. package/dist/analyzer/typeEvaluator.js.map +1 -1
  25. package/dist/analyzer/typeEvaluatorTypes.d.ts +11 -11
  26. package/dist/analyzer/typeGuards.d.ts +2 -0
  27. package/dist/analyzer/typeGuards.js +41 -13
  28. package/dist/analyzer/typeGuards.js.map +1 -1
  29. package/dist/analyzer/typeUtils.d.ts +2 -1
  30. package/dist/analyzer/typeUtils.js +21 -21
  31. package/dist/analyzer/typeUtils.js.map +1 -1
  32. package/dist/analyzer/typedDicts.js +2 -2
  33. package/dist/analyzer/typedDicts.js.map +1 -1
  34. package/dist/analyzer/types.d.ts +1 -0
  35. package/dist/analyzer/types.js +37 -0
  36. package/dist/analyzer/types.js.map +1 -1
  37. package/dist/backgroundAnalysisBase.d.ts +2 -1
  38. package/dist/backgroundAnalysisBase.js +7 -0
  39. package/dist/backgroundAnalysisBase.js.map +1 -1
  40. package/dist/backgroundThreadBase.js +1 -0
  41. package/dist/backgroundThreadBase.js.map +1 -1
  42. package/dist/common/chokidarFileWatcherProvider.d.ts +1 -2
  43. package/dist/common/chokidarFileWatcherProvider.js +0 -3
  44. package/dist/common/chokidarFileWatcherProvider.js.map +1 -1
  45. package/dist/common/configOptions.d.ts +1 -0
  46. package/dist/common/configOptions.js +4 -0
  47. package/dist/common/configOptions.js.map +1 -1
  48. package/dist/common/diagnosticRules.d.ts +1 -0
  49. package/dist/common/diagnosticRules.js +1 -0
  50. package/dist/common/diagnosticRules.js.map +1 -1
  51. package/dist/common/editAction.d.ts +6 -0
  52. package/dist/common/editAction.js +15 -0
  53. package/dist/common/editAction.js.map +1 -1
  54. package/dist/common/fileSystem.d.ts +4 -1
  55. package/dist/common/fileSystem.js +6 -4
  56. package/dist/common/fileSystem.js.map +1 -1
  57. package/dist/common/realFileSystem.d.ts +2 -2
  58. package/dist/common/realFileSystem.js.map +1 -1
  59. package/dist/common/textEditUtils.d.ts +22 -2
  60. package/dist/common/textEditUtils.js +138 -1
  61. package/dist/common/textEditUtils.js.map +1 -1
  62. package/dist/common/uriParser.d.ts +2 -0
  63. package/dist/common/uriParser.js +11 -0
  64. package/dist/common/uriParser.js.map +1 -1
  65. package/dist/languageServerBase.d.ts +14 -10
  66. package/dist/languageServerBase.js +45 -43
  67. package/dist/languageServerBase.js.map +1 -1
  68. package/dist/languageService/codeActionProvider.d.ts +2 -2
  69. package/dist/languageService/codeActionProvider.js +1 -1
  70. package/dist/languageService/codeActionProvider.js.map +1 -1
  71. package/dist/languageService/renameModuleProvider.d.ts +1 -4
  72. package/dist/languageService/renameModuleProvider.js +10 -46
  73. package/dist/languageService/renameModuleProvider.js.map +1 -1
  74. package/dist/localization/localize.d.ts +8 -0
  75. package/dist/localization/localize.js +2 -0
  76. package/dist/localization/localize.js.map +1 -1
  77. package/dist/localization/package.nls.en-us.json +2 -0
  78. package/dist/pyrightFileSystem.d.ts +19 -1
  79. package/dist/pyrightFileSystem.js +18 -1
  80. package/dist/pyrightFileSystem.js.map +1 -1
  81. package/dist/server.js +4 -4
  82. package/dist/server.js.map +1 -1
  83. package/dist/tests/checker.test.js +9 -0
  84. package/dist/tests/checker.test.js.map +1 -1
  85. package/dist/tests/harness/fourslash/testLanguageService.js +1 -1
  86. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  87. package/dist/tests/harness/fourslash/testState.js +1 -1
  88. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  89. package/dist/tests/renameModuleTestUtils.js +5 -87
  90. package/dist/tests/renameModuleTestUtils.js.map +1 -1
  91. package/dist/tests/testStateUtils.d.ts +8 -0
  92. package/dist/tests/testStateUtils.js +110 -0
  93. package/dist/tests/testStateUtils.js.map +1 -0
  94. package/dist/tests/testUtils.js +1 -1
  95. package/dist/tests/testUtils.js.map +1 -1
  96. package/dist/tests/typeEvaluator1.test.js +0 -4
  97. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  98. package/dist/tests/typeEvaluator2.test.js +4 -0
  99. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  100. package/dist/tests/typeEvaluator4.test.js +8 -0
  101. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  102. package/dist/workspaceMap.d.ts +1 -0
  103. package/dist/workspaceMap.js +10 -0
  104. package/dist/workspaceMap.js.map +1 -1
  105. package/package.json +2 -2
@@ -106,33 +106,31 @@ var MemberAccessFlags;
106
106
  MemberAccessFlags[MemberAccessFlags["SkipTypeBaseClass"] = 256] = "SkipTypeBaseClass";
107
107
  })(MemberAccessFlags || (MemberAccessFlags = {}));
108
108
  // Maps binary operators to the magic methods that implement them.
109
- // The boolean indicates whether the operators "chain" together.
110
109
  const binaryOperatorMap = {
111
- [0 /* Add */]: ['__add__', '__radd__', false],
112
- [33 /* Subtract */]: ['__sub__', '__rsub__', false],
113
- [26 /* Multiply */]: ['__mul__', '__rmul__', false],
114
- [13 /* FloorDivide */]: ['__floordiv__', '__rfloordiv__', false],
115
- [10 /* Divide */]: ['__truediv__', '__rtruediv__', false],
116
- [24 /* Mod */]: ['__mod__', '__rmod__', false],
117
- [29 /* Power */]: ['__pow__', '__rpow__', false],
118
- [22 /* MatrixMultiply */]: ['__matmul__', '__rmatmul__', false],
119
- [3 /* BitwiseAnd */]: ['__and__', '__rand__', false],
120
- [6 /* BitwiseOr */]: ['__or__', '__ror__', false],
121
- [8 /* BitwiseXor */]: ['__xor__', '__rxor__', false],
122
- [17 /* LeftShift */]: ['__lshift__', '__rlshift__', false],
123
- [31 /* RightShift */]: ['__rshift__', '__rrshift__', false],
124
- [12 /* Equals */]: ['__eq__', '__ne__', true],
125
- [28 /* NotEquals */]: ['__ne__', '__eq__', true],
126
- [20 /* LessThan */]: ['__lt__', '__ge__', true],
127
- [21 /* LessThanOrEqual */]: ['__le__', '__gt__', true],
128
- [15 /* GreaterThan */]: ['__gt__', '__le__', true],
129
- [16 /* GreaterThanOrEqual */]: ['__ge__', '__lt__', true],
110
+ [0 /* Add */]: ['__add__', '__radd__'],
111
+ [33 /* Subtract */]: ['__sub__', '__rsub__'],
112
+ [26 /* Multiply */]: ['__mul__', '__rmul__'],
113
+ [13 /* FloorDivide */]: ['__floordiv__', '__rfloordiv__'],
114
+ [10 /* Divide */]: ['__truediv__', '__rtruediv__'],
115
+ [24 /* Mod */]: ['__mod__', '__rmod__'],
116
+ [29 /* Power */]: ['__pow__', '__rpow__'],
117
+ [22 /* MatrixMultiply */]: ['__matmul__', '__rmatmul__'],
118
+ [3 /* BitwiseAnd */]: ['__and__', '__rand__'],
119
+ [6 /* BitwiseOr */]: ['__or__', '__ror__'],
120
+ [8 /* BitwiseXor */]: ['__xor__', '__rxor__'],
121
+ [17 /* LeftShift */]: ['__lshift__', '__rlshift__'],
122
+ [31 /* RightShift */]: ['__rshift__', '__rrshift__'],
123
+ [12 /* Equals */]: ['__eq__', '__ne__'],
124
+ [28 /* NotEquals */]: ['__ne__', '__eq__'],
125
+ [20 /* LessThan */]: ['__lt__', '__ge__'],
126
+ [21 /* LessThanOrEqual */]: ['__le__', '__gt__'],
127
+ [15 /* GreaterThan */]: ['__gt__', '__le__'],
128
+ [16 /* GreaterThanOrEqual */]: ['__ge__', '__lt__'],
130
129
  };
131
- // Maps boolean operators to a boolean value indicating whether
132
- // the operators "chain" together with other comparison operators.
130
+ // Map of operators that always return a bool result.
133
131
  const booleanOperatorMap = {
134
- [36 /* And */]: false,
135
- [37 /* Or */]: false,
132
+ [36 /* And */]: true,
133
+ [37 /* Or */]: true,
136
134
  [39 /* Is */]: true,
137
135
  [40 /* IsNot */]: true,
138
136
  [41 /* In */]: true,
@@ -283,6 +281,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
283
281
  return cachedType !== undefined;
284
282
  }
285
283
  function readTypeCache(node, flags) {
284
+ var _a, _b;
286
285
  let cachedType;
287
286
  // Should we use a temporary cache associated with a contextual
288
287
  // analysis of a function, contextualized based on call-site argument types?
@@ -299,8 +298,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
299
298
  if (flags !== undefined) {
300
299
  const expectedFlags = typeCacheFlags.get(node.id);
301
300
  if (expectedFlags !== undefined && flags !== expectedFlags) {
302
- (0, debug_1.fail)(`Type cache flag mismatch for node type ${node.nodeType}: ` +
303
- `cached flags = ${expectedFlags}, access flags = ${flags}`);
301
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
302
+ const position = (0, positionUtils_1.convertOffsetToPosition)(node.start, fileInfo.lines);
303
+ const message = `Type cache flag mismatch for node type ${node.nodeType} ` +
304
+ `(parent ${(_b = (_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== null && _b !== void 0 ? _b : 'none'}): ` +
305
+ `cached flags = ${expectedFlags}, access flags = ${flags}, ` +
306
+ `file = {${fileInfo.filePath} [${position.line + 1}:${position.character + 1}]}`;
307
+ if (evaluatorOptions.verifyTypeCacheEvaluatorFlags) {
308
+ (0, debug_1.fail)(message);
309
+ }
310
+ else {
311
+ console.log(message);
312
+ }
304
313
  }
305
314
  }
306
315
  }
@@ -428,9 +437,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
428
437
  // context. For example, if it's a subexpression of an argument expression,
429
438
  // the associated parameter type might inform the expected type.
430
439
  function getExpectedType(node) {
431
- evaluateTypesForExpressionInContext(node);
440
+ // Scan up the parse tree to find the top-most expression node
441
+ // so we can evaluate the entire expression.
442
+ let topExpression = node;
432
443
  let curNode = node;
433
- while (curNode !== undefined) {
444
+ while (curNode) {
445
+ if ((0, parseNodes_1.isExpressionNode)(curNode)) {
446
+ topExpression = curNode;
447
+ }
448
+ curNode = curNode.parent;
449
+ }
450
+ // Evaluate the expression. This will have the side effect of
451
+ // storing an expected type in the expected type cache.
452
+ evaluateTypesForExpressionInContext(topExpression);
453
+ // Look for the resulting expected type by scanning up the parse tree.
454
+ curNode = node;
455
+ while (curNode) {
434
456
  const expectedType = expectedTypeCache.get(curNode.id);
435
457
  if (expectedType) {
436
458
  return {
@@ -438,6 +460,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
438
460
  node: curNode,
439
461
  };
440
462
  }
463
+ if (curNode === topExpression) {
464
+ break;
465
+ }
441
466
  curNode = curNode.parent;
442
467
  }
443
468
  return undefined;
@@ -470,7 +495,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
470
495
  if (printExpressionTypes) {
471
496
  console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Cached ${printType(cachedType)}`);
472
497
  }
473
- return { type: cachedType, node };
498
+ return { type: cachedType };
474
499
  }
475
500
  else {
476
501
  // Is it cached in the speculative type cache?
@@ -479,7 +504,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
479
504
  if (printExpressionTypes) {
480
505
  console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Speculative ${printType(speculativeCachedType)}`);
481
506
  }
482
- return { type: speculativeCachedType, node };
507
+ return { type: speculativeCachedType };
483
508
  }
484
509
  }
485
510
  if (printExpressionTypes) {
@@ -631,7 +656,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
631
656
  getTypeOfExpression(node.child);
632
657
  }
633
658
  });
634
- typeResult = { type: types_1.UnknownType.create(), node };
659
+ typeResult = { type: types_1.UnknownType.create() };
635
660
  break;
636
661
  }
637
662
  default:
@@ -683,7 +708,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
683
708
  const exprTypeResult = getTypeOfExpression(node.expression, flags, effectiveExpectedType);
684
709
  const typeResult = {
685
710
  type: getTypeOfAwaitable(exprTypeResult.type, node.expression),
686
- node,
687
711
  };
688
712
  if (exprTypeResult.isIncomplete) {
689
713
  typeResult.isIncomplete = true;
@@ -692,26 +716,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
692
716
  }
693
717
  function getTypeOfEllipsis(flags, typeResult, node) {
694
718
  if ((flags & 1 /* ConvertEllipsisToAny */) !== 0) {
695
- typeResult = { type: types_1.AnyType.create(/* isEllipsis */ true), node };
719
+ typeResult = { type: types_1.AnyType.create(/* isEllipsis */ true) };
696
720
  }
697
721
  else if ((flags & 256 /* ConvertEllipsisToUnknown */) !== 0) {
698
- typeResult = { type: types_1.UnknownType.create(), node };
722
+ typeResult = { type: types_1.UnknownType.create() };
699
723
  }
700
724
  else {
701
725
  const ellipsisType = getBuiltInObject(node, 'ellipsis') || types_1.AnyType.create();
702
- typeResult = { type: ellipsisType, node };
726
+ typeResult = { type: ellipsisType };
703
727
  }
704
728
  return typeResult;
705
729
  }
706
730
  function getTypeOfNumber(node, typeResult) {
707
731
  if (node.isImaginary) {
708
- typeResult = { node, type: getBuiltInObject(node, 'complex') };
732
+ typeResult = { type: getBuiltInObject(node, 'complex') };
709
733
  }
710
734
  else if (node.isInteger) {
711
- typeResult = { node, type: cloneBuiltinObjectWithLiteral(node, 'int', node.value) };
735
+ typeResult = { type: cloneBuiltinObjectWithLiteral(node, 'int', node.value) };
712
736
  }
713
737
  else {
714
- typeResult = { node, type: getBuiltInObject(node, 'float') };
738
+ typeResult = { type: getBuiltInObject(node, 'float') };
715
739
  }
716
740
  return typeResult;
717
741
  }
@@ -730,17 +754,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
730
754
  if ((flags & 128 /* TypeVarTupleDisallowed */) === 0 &&
731
755
  (0, types_1.isVariadicTypeVar)(iterType) &&
732
756
  !iterType.isVariadicUnpacked) {
733
- typeResult = { type: types_1.TypeVarType.cloneForUnpacked(iterType), node };
757
+ typeResult = { type: types_1.TypeVarType.cloneForUnpacked(iterType) };
734
758
  }
735
759
  else {
736
760
  if ((flags & 2097152 /* AllowUnpackedTupleOrTypeVarTuple */) !== 0 &&
737
761
  (0, types_1.isInstantiableClass)(iterType) &&
738
762
  types_1.ClassType.isBuiltIn(iterType, 'tuple')) {
739
- typeResult = { type: types_1.ClassType.cloneForUnpacked(iterType), node };
763
+ typeResult = { type: types_1.ClassType.cloneForUnpacked(iterType) };
740
764
  }
741
765
  else {
742
766
  const type = (_a = getTypeOfIterator(iterType, /* isAsync */ false, node)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create(!!iterTypeResult.isIncomplete);
743
- typeResult = { type, unpackedType: iterType, node, isIncomplete: iterTypeResult.isIncomplete };
767
+ typeResult = { type, unpackedType: iterType, isIncomplete: iterTypeResult.isIncomplete };
744
768
  }
745
769
  }
746
770
  return typeResult;
@@ -769,7 +793,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
769
793
  if (!typeResult) {
770
794
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
771
795
  addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.expectedTypeNotString(), node);
772
- typeResult = { node, type: types_1.UnknownType.create() };
796
+ typeResult = { type: types_1.UnknownType.create() };
773
797
  }
774
798
  }
775
799
  else {
@@ -785,13 +809,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
785
809
  // Don't create a literal type if it's an f-string.
786
810
  if (node.strings.some((str) => str.nodeType === 27 /* FormatString */)) {
787
811
  typeResult = {
788
- node,
789
812
  type: getBuiltInObject(node, isBytes ? 'bytes' : 'str'),
790
813
  };
791
814
  }
792
815
  else {
793
816
  typeResult = {
794
- node,
795
817
  type: cloneBuiltinObjectWithLiteral(node, isBytes ? 'bytes' : 'str', node.strings.map((s) => s.value).join('')),
796
818
  };
797
819
  }
@@ -804,13 +826,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
804
826
  // Don't create a literal type if it's an f-string.
805
827
  if (node.nodeType === 27 /* FormatString */) {
806
828
  typeResult = {
807
- node,
808
829
  type: getBuiltInObject(node, isBytes ? 'bytes' : 'str'),
809
830
  };
810
831
  }
811
832
  else {
812
833
  typeResult = {
813
- node,
814
834
  type: cloneBuiltinObjectWithLiteral(node, isBytes ? 'bytes' : 'str', node.value),
815
835
  };
816
836
  }
@@ -1143,7 +1163,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1143
1163
  /* isAccessedThroughObject */ true, memberName, usage, diag, memberAccessFlags | 8 /* DisallowClassVarWrites */, bindToType);
1144
1164
  if (memberInfo) {
1145
1165
  return {
1146
- node: errorNode,
1147
1166
  type: memberInfo.type,
1148
1167
  isIncomplete: !!memberInfo.isTypeIncomplete,
1149
1168
  isAsymmetricDescriptor: memberInfo.isAsymmetricDescriptor,
@@ -1157,7 +1176,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1157
1176
  let memberInfo;
1158
1177
  if (types_1.ClassType.isPartiallyEvaluated(classType)) {
1159
1178
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classDefinitionCycle().format({ name: classType.details.name }), errorNode);
1160
- return { node: errorNode, type: types_1.UnknownType.create() };
1179
+ return { type: types_1.UnknownType.create() };
1161
1180
  }
1162
1181
  if ((memberAccessFlags & 32 /* ConsiderMetaclassOnly */) === 0) {
1163
1182
  memberInfo = getTypeOfClassMemberName(errorNode, classType,
@@ -1189,7 +1208,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1189
1208
  }
1190
1209
  if (memberInfo) {
1191
1210
  return {
1192
- node: errorNode,
1193
1211
  type: memberInfo.type,
1194
1212
  isIncomplete: !!memberInfo.isTypeIncomplete,
1195
1213
  isAsymmetricDescriptor: memberInfo.isAsymmetricDescriptor,
@@ -1509,6 +1527,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1509
1527
  const iterMethodName = isAsync ? '__aiter__' : '__iter__';
1510
1528
  const nextMethodName = isAsync ? '__anext__' : '__next__';
1511
1529
  let isValidIterator = true;
1530
+ type = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(type);
1512
1531
  type = makeTopLevelTypeVarsConcrete(type);
1513
1532
  if ((0, typeUtils_1.isOptionalType)(type)) {
1514
1533
  if (errorNode) {
@@ -1904,9 +1923,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1904
1923
  if (!isTypeIncomplete) {
1905
1924
  reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, nameNode, destType, nameNode, ignoreEmptyContainers);
1906
1925
  }
1907
- writeTypeCache(nameNode, destType, 0 /* None */, isTypeIncomplete,
1908
- /* expectedType */ undefined,
1909
- /* allowSpeculativeCaching */ false);
1926
+ writeTypeCache(nameNode, destType, 0 /* None */, isTypeIncomplete);
1910
1927
  }
1911
1928
  function assignTypeToMemberAccessNode(target, type, isTypeIncomplete, srcExpr, expectedTypeDiagAddendum) {
1912
1929
  const baseTypeResult = getTypeOfExpression(target.leftExpression, 2 /* DoNotSpecialize */);
@@ -1950,12 +1967,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1950
1967
  if (setTypeResult.isAsymmetricDescriptor) {
1951
1968
  setAsymmetricDescriptorAssignment(target);
1952
1969
  }
1953
- writeTypeCache(target.memberName, type, 0 /* None */, isTypeIncomplete,
1954
- /* expectedType */ undefined,
1955
- /* allowSpeculativeCaching */ false);
1956
- writeTypeCache(target, type, 0 /* None */, isTypeIncomplete,
1957
- /* expectedType */ undefined,
1958
- /* allowSpeculativeCaching */ false);
1970
+ writeTypeCache(target.memberName, type, 0 /* None */, isTypeIncomplete);
1971
+ writeTypeCache(target, type, 0 /* None */, isTypeIncomplete);
1959
1972
  }
1960
1973
  function assignTypeToMemberVariable(node, srcType, isTypeIncomplete, isInstanceMember, srcExprNode) {
1961
1974
  const memberName = node.memberName.value;
@@ -2164,7 +2177,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2164
2177
  if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
2165
2178
  return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [],
2166
2179
  /* isTypeArgumentExplicit */ true,
2167
- /* stripLiterals */ true,
2168
2180
  /* isUnpackedTuple */ true));
2169
2181
  }
2170
2182
  }
@@ -2476,7 +2488,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2476
2488
  break;
2477
2489
  }
2478
2490
  case 35 /* MemberAccess */: {
2479
- const baseTypeResult = getTypeOfExpression(node.leftExpression);
2491
+ const baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /* DoNotSpecialize */);
2480
2492
  const memberType = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* None */);
2481
2493
  writeTypeCache(node.memberName, memberType.type, 0 /* None */, /* isIncomplete */ false);
2482
2494
  writeTypeCache(node, memberType.type, 0 /* None */, /* isIncomplete */ false);
@@ -2574,7 +2586,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2574
2586
  const containingFunction = ParseTreeUtils.getEnclosingFunction(node);
2575
2587
  if (containingFunction && ParseTreeUtils.isUnannotatedFunction(containingFunction)) {
2576
2588
  return {
2577
- node,
2578
2589
  type: types_1.AnyType.create(),
2579
2590
  isIncomplete: false,
2580
2591
  };
@@ -2718,7 +2729,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2718
2729
  if ((0, types_1.isTypeVar)(type) && !type.details.isSynthesized) {
2719
2730
  type = validateTypeVarUsage(node, type, flags);
2720
2731
  }
2721
- return { type, node, isIncomplete };
2732
+ return { type, isIncomplete };
2722
2733
  }
2723
2734
  // Handles the case where a variable or parameter is defined in an outer
2724
2735
  // scope and captured by an inner scope (either a function or a lambda).
@@ -3016,7 +3027,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3016
3027
  const baseTypeResult = getTypeOfExpression(node.leftExpression, baseTypeFlags);
3017
3028
  if ((0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
3018
3029
  return {
3019
- node,
3020
3030
  type: types_1.UnknownType.create(/* isIncomplete */ true),
3021
3031
  isIncomplete: true,
3022
3032
  };
@@ -3076,7 +3086,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3076
3086
  // If the base type was incomplete and unbound, don't proceed
3077
3087
  // because false positive errors will be generated.
3078
3088
  if (baseTypeResult.isIncomplete && (0, types_1.isUnbound)(baseTypeResult.type)) {
3079
- return { type: types_1.UnknownType.create(/* isIncomplete */ true), node, isIncomplete: true };
3089
+ return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
3080
3090
  }
3081
3091
  // Handle the special case where the expression is an actual
3082
3092
  // UnionType special form.
@@ -3112,22 +3122,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3112
3122
  const paramNode = ParseTreeUtils.getEnclosingParameter(node);
3113
3123
  if (!paramNode || paramNode.category !== 1 /* VarArgList */) {
3114
3124
  addError(localize_1.Localizer.Diagnostic.paramSpecArgsUsage(), node);
3115
- return { type: types_1.UnknownType.create(isIncomplete), node, isIncomplete };
3125
+ return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
3116
3126
  }
3117
- return { type: types_1.TypeVarType.cloneForParamSpecAccess(baseType, 'args'), node, isIncomplete };
3127
+ return { type: types_1.TypeVarType.cloneForParamSpecAccess(baseType, 'args'), isIncomplete };
3118
3128
  }
3119
3129
  if (memberName === 'kwargs') {
3120
3130
  const paramNode = ParseTreeUtils.getEnclosingParameter(node);
3121
3131
  if (!paramNode || paramNode.category !== 2 /* VarArgDictionary */) {
3122
3132
  addError(localize_1.Localizer.Diagnostic.paramSpecKwargsUsage(), node);
3123
- return { type: types_1.UnknownType.create(isIncomplete), node, isIncomplete };
3133
+ return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
3124
3134
  }
3125
- return { type: types_1.TypeVarType.cloneForParamSpecAccess(baseType, 'kwargs'), node, isIncomplete };
3135
+ return { type: types_1.TypeVarType.cloneForParamSpecAccess(baseType, 'kwargs'), isIncomplete };
3126
3136
  }
3127
3137
  if (!isIncomplete) {
3128
3138
  addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecUnknownMember().format({ name: memberName }), node);
3129
3139
  }
3130
- return { type: types_1.UnknownType.create(isIncomplete), node, isIncomplete };
3140
+ return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
3131
3141
  }
3132
3142
  if (flags & 64 /* ExpectingType */) {
3133
3143
  if (!isIncomplete) {
@@ -3136,14 +3146,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3136
3146
  name: memberName,
3137
3147
  }), node.leftExpression);
3138
3148
  }
3139
- return { type: types_1.UnknownType.create(isIncomplete), node, isIncomplete };
3149
+ return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
3140
3150
  }
3141
3151
  if (baseType.details.recursiveTypeAliasName) {
3142
- return { type: types_1.UnknownType.create(/* isIncomplete */ true), node, isIncomplete: true };
3152
+ return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
3143
3153
  }
3144
3154
  return getTypeOfMemberAccessWithBaseType(node, {
3145
3155
  type: makeTopLevelTypeVarsConcrete(baseType),
3146
- node,
3147
3156
  bindToType: baseType,
3148
3157
  isIncomplete,
3149
3158
  }, usage, 0 /* None */);
@@ -3174,14 +3183,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3174
3183
  const strClass = getBuiltInType(node, 'str');
3175
3184
  if ((0, types_1.isInstantiableClass)(strClass)) {
3176
3185
  return {
3177
- node,
3178
3186
  type: types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneWithLiteral(strClass, literalValue.itemName)),
3179
3187
  isIncomplete,
3180
3188
  };
3181
3189
  }
3182
3190
  }
3183
3191
  else if (memberName === 'value' || memberName === '_value_') {
3184
- return { node, type: literalValue.itemType, isIncomplete };
3192
+ return { type: literalValue.itemType, isIncomplete };
3185
3193
  }
3186
3194
  }
3187
3195
  }
@@ -3285,7 +3293,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3285
3293
  else {
3286
3294
  const typeResult = getTypeOfMemberAccessWithBaseType(node, {
3287
3295
  type: subtype,
3288
- node,
3289
3296
  isIncomplete: baseTypeResult.isIncomplete,
3290
3297
  }, usage, 0 /* None */);
3291
3298
  if (typeResult.isIncomplete) {
@@ -3317,7 +3324,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3317
3324
  type = types_1.AnyType.create();
3318
3325
  }
3319
3326
  else {
3320
- type = getTypeOfMemberAccessWithBaseType(node, { type: functionObj, node }, usage, flags).type;
3327
+ type = getTypeOfMemberAccessWithBaseType(node, { type: functionObj }, usage, flags).type;
3321
3328
  }
3322
3329
  }
3323
3330
  break;
@@ -3387,7 +3394,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3387
3394
  /* ignoreEmptyContainers */ false);
3388
3395
  }
3389
3396
  }
3390
- return { type, node, isIncomplete, isAsymmetricDescriptor };
3397
+ return { type, isIncomplete, isAsymmetricDescriptor };
3391
3398
  }
3392
3399
  function getTypeOfClassMemberName(errorNode, classType, isAccessedThroughObject, memberName, usage, diag, flags, bindToType) {
3393
3400
  var _a, _b;
@@ -4026,7 +4033,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4026
4033
  }
4027
4034
  const tupleObject = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, variadicTypes,
4028
4035
  /* isTypeArgumentExplicit */ true,
4029
- /* stripLiterals */ true,
4030
4036
  /* isUnpackedTuple */ true));
4031
4037
  typeArgs = [
4032
4038
  ...typeArgs.slice(0, variadicIndex),
@@ -4041,7 +4047,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4041
4047
  node: errorNode,
4042
4048
  type: (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [],
4043
4049
  /* isTypeArgumentExplicit */ true,
4044
- /* stripLiterals */ true,
4045
4050
  /* isUnpackedTuple */ true)),
4046
4051
  });
4047
4052
  }
@@ -4202,9 +4207,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4202
4207
  if ((0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
4203
4208
  const typeArgTypes = getTypeArgs(node, flags).map((t) => (0, typeUtils_1.convertToInstance)(t.type));
4204
4209
  const type = types_1.TypeBase.cloneForTypeAlias(baseTypeResult.type, baseTypeResult.type.details.recursiveTypeAliasName, '', baseTypeResult.type.details.recursiveTypeAliasScopeId, baseTypeResult.type.details.recursiveTypeParameters, typeArgTypes);
4205
- return { type, node };
4210
+ return { type };
4206
4211
  }
4207
- let isIncomplete = false;
4212
+ let isIncomplete = baseTypeResult.isIncomplete;
4208
4213
  const type = mapSubtypesExpandTypeVars(baseTypeResult.type,
4209
4214
  /* conditionFilter */ undefined, (concreteSubtype, unexpandedSubtype) => {
4210
4215
  var _a;
@@ -4299,11 +4304,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4299
4304
  if ((0, types_1.isNever)(concreteSubtype)) {
4300
4305
  return types_1.UnknownType.create();
4301
4306
  }
4302
- if ((0, types_1.isNoneInstance)(concreteSubtype)) {
4307
+ if ((0, types_1.isNoneInstance)(concreteSubtype) && !isIncomplete) {
4303
4308
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportOptionalSubscript, diagnosticRules_1.DiagnosticRule.reportOptionalSubscript, localize_1.Localizer.Diagnostic.noneNotSubscriptable(), node.baseExpression);
4304
4309
  return types_1.UnknownType.create();
4305
4310
  }
4306
- if (!(0, types_1.isUnbound)(concreteSubtype)) {
4311
+ if (!(0, types_1.isUnbound)(concreteSubtype) && !isIncomplete) {
4307
4312
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
4308
4313
  addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotSubscriptable().format({ type: printType(concreteSubtype) }), node.baseExpression);
4309
4314
  }
@@ -4318,7 +4323,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4318
4323
  }
4319
4324
  });
4320
4325
  }
4321
- return { type, node, isIncomplete };
4326
+ return { type, isIncomplete };
4322
4327
  }
4323
4328
  function makeTupleObject(entryTypes, isUnspecifiedLength = false) {
4324
4329
  if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
@@ -4363,7 +4368,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4363
4368
  name: magicMethodName,
4364
4369
  type: printType(baseType),
4365
4370
  }), node.baseExpression);
4366
- return { node, type: types_1.UnknownType.create() };
4371
+ return { type: types_1.UnknownType.create() };
4367
4372
  }
4368
4373
  // Handle the special case where the object is a Tuple and
4369
4374
  // the index is a constant number (integer) or a slice with integer
@@ -4384,11 +4389,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4384
4389
  const tupleType = (0, typeUtils_1.getSpecializedTupleType)(baseType);
4385
4390
  if (tupleType && tupleType.tupleTypeArguments && !(0, typeUtils_1.isUnboundedTupleClass)(tupleType)) {
4386
4391
  if (indexValue >= 0 && indexValue < tupleType.tupleTypeArguments.length) {
4387
- return { node, type: tupleType.tupleTypeArguments[indexValue].type };
4392
+ return { type: tupleType.tupleTypeArguments[indexValue].type };
4388
4393
  }
4389
4394
  else if (indexValue < 0 && tupleType.tupleTypeArguments.length + indexValue >= 0) {
4390
4395
  return {
4391
- node,
4392
4396
  type: tupleType.tupleTypeArguments[tupleType.tupleTypeArguments.length + indexValue].type,
4393
4397
  };
4394
4398
  }
@@ -4426,7 +4430,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4426
4430
  tupleClassType &&
4427
4431
  (0, types_1.isInstantiableClass)(tupleClassType)) {
4428
4432
  return {
4429
- node,
4430
4433
  type: types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, tupleType.tupleTypeArguments.slice(startValue, endValue))),
4431
4434
  };
4432
4435
  }
@@ -4541,7 +4544,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4541
4544
  }
4542
4545
  callResult = validateCallArguments(node, argList, { type: itemMethodType });
4543
4546
  return {
4544
- node,
4545
4547
  type: (_c = callResult.returnType) !== null && _c !== void 0 ? _c : types_1.UnknownType.create(),
4546
4548
  isIncomplete: !!callResult.isTypeIncomplete,
4547
4549
  };
@@ -4569,10 +4571,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4569
4571
  // treated as types. If it's an Annotated[a, b, c], only the first index
4570
4572
  // should be treated as a type. The others can be regular (non-type) objects.
4571
4573
  if (hasCustomClassGetItem || (isAnnotatedClass && argIndex > 0)) {
4572
- typeResult = getTypeOfExpression(expr, 32 /* ParamSpecDisallowed */ |
4573
- 128 /* TypeVarTupleDisallowed */ |
4574
- 2 /* DoNotSpecialize */ |
4575
- 131072 /* ClassVarDisallowed */);
4574
+ typeResult = {
4575
+ ...getTypeOfExpression(expr, 32 /* ParamSpecDisallowed */ |
4576
+ 128 /* TypeVarTupleDisallowed */ |
4577
+ 2 /* DoNotSpecialize */ |
4578
+ 131072 /* ClassVarDisallowed */),
4579
+ node: expr,
4580
+ };
4576
4581
  }
4577
4582
  else {
4578
4583
  typeResult = getTypeArg(expr, adjFlags);
@@ -4618,7 +4623,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4618
4623
  let typeResult;
4619
4624
  let adjustedFlags = flags |
4620
4625
  64 /* ExpectingType */ |
4621
- 1024 /* ExpectingTypeAnnotation */ |
4622
4626
  1 /* ConvertEllipsisToAny */ |
4623
4627
  8 /* EvaluateStringLiteralAsType */;
4624
4628
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
@@ -4628,14 +4632,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4628
4632
  if (node.nodeType === 31 /* List */) {
4629
4633
  typeResult = {
4630
4634
  type: types_1.UnknownType.create(),
4631
- typeList: node.entries.map((entry) => getTypeOfExpression(entry, adjustedFlags)),
4635
+ typeList: node.entries.map((entry) => {
4636
+ return { ...getTypeOfExpression(entry, adjustedFlags), node: entry };
4637
+ }),
4632
4638
  node,
4633
4639
  };
4634
4640
  // Set the node's type so it isn't reevaluated later.
4635
4641
  setTypeForNode(node, types_1.UnknownType.create());
4636
4642
  }
4637
4643
  else {
4638
- typeResult = getTypeOfExpression(node, adjustedFlags);
4644
+ typeResult = { ...getTypeOfExpression(node, adjustedFlags), node };
4639
4645
  // "Protocol" is not allowed as a type argument.
4640
4646
  if ((0, types_1.isClass)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'Protocol')) {
4641
4647
  addError(localize_1.Localizer.Diagnostic.protocolNotAllowedInTypeArgument(), node);
@@ -4651,7 +4657,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4651
4657
  }
4652
4658
  function getTypeOfTuple(node, expectedType, flags) {
4653
4659
  if ((flags & 64 /* ExpectingType */) !== 0 && node.expressions.length === 0 && !expectedType) {
4654
- return { type: makeTupleObject([]), node, isEmptyTupleShorthand: true };
4660
+ return { type: makeTupleObject([]), isEmptyTupleShorthand: true };
4655
4661
  }
4656
4662
  // If the expected type is a union, recursively call for each of the subtypes
4657
4663
  // to find one that matches.
@@ -4728,20 +4734,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4728
4734
  }
4729
4735
  const entryTypeResults = node.expressions.map((expr, index) => getTypeOfExpression(expr,
4730
4736
  /* flags */ undefined, index < expectedTypes.length ? expectedTypes[index] : undefined));
4731
- const expectedTypesContainLiterals = expectedTypes.some((type) => (0, typeUtils_1.isLiteralTypeOrUnion)(type));
4732
4737
  const type = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, buildTupleTypesList(entryTypeResults),
4733
- /* isTypeArgumentExplicit */ true,
4734
- /* stripLiterals */ !expectedTypesContainLiterals));
4735
- return { type, node };
4738
+ /* isTypeArgumentExplicit */ true));
4739
+ return { type };
4736
4740
  }
4737
4741
  function getTypeOfTupleInferred(node) {
4738
4742
  const entryTypeResults = node.expressions.map((expr) => getTypeOfExpression(expr));
4739
4743
  const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
4740
4744
  if (!tupleClassType || !(0, types_1.isInstantiableClass)(tupleClassType)) {
4741
- return { type: types_1.UnknownType.create(), node };
4745
+ return { type: types_1.UnknownType.create() };
4742
4746
  }
4743
4747
  const type = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, buildTupleTypesList(entryTypeResults)));
4744
- return { type, node, isIncomplete };
4748
+ return { type, isIncomplete };
4745
4749
  }
4746
4750
  function buildTupleTypesList(entryTypeResults) {
4747
4751
  const entryTypes = [];
@@ -4797,7 +4801,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4797
4801
  };
4798
4802
  return functionArg;
4799
4803
  });
4800
- let typeResult = { node, type: types_1.UnknownType.create() };
4804
+ let typeResult = { type: types_1.UnknownType.create() };
4801
4805
  if (!(0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
4802
4806
  if (node.leftExpression.nodeType === 38 /* Name */ && node.leftExpression.value === 'super') {
4803
4807
  // Handle the built-in "super" call specially.
@@ -4871,7 +4875,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4871
4875
  }
4872
4876
  if ((flags & 1024 /* ExpectingTypeAnnotation */) !== 0) {
4873
4877
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAnnotationCall(), node);
4874
- typeResult = { node, type: types_1.UnknownType.create() };
4878
+ typeResult = { type: types_1.UnknownType.create() };
4875
4879
  }
4876
4880
  return typeResult;
4877
4881
  }
@@ -4882,12 +4886,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4882
4886
  node.arguments[0].argumentCategory !== 0 /* Simple */ ||
4883
4887
  node.arguments[1].name !== undefined) {
4884
4888
  addError(localize_1.Localizer.Diagnostic.assertTypeArgs(), node);
4885
- return { node, type: types_1.UnknownType.create() };
4889
+ return { type: types_1.UnknownType.create() };
4886
4890
  }
4887
4891
  const arg0TypeResult = getTypeOfExpression(node.arguments[0].valueExpression,
4888
4892
  /* flags */ undefined, expectedType);
4889
4893
  if (arg0TypeResult.isIncomplete) {
4890
- return { node, type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
4894
+ return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
4891
4895
  }
4892
4896
  const assertedType = (0, typeUtils_1.convertToInstance)(getTypeOfArgumentExpectingType(node.arguments[1]).type);
4893
4897
  if (!(0, types_1.isTypeSame)(assertedType, arg0TypeResult.type)) {
@@ -4896,7 +4900,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4896
4900
  received: printType(arg0TypeResult.type),
4897
4901
  }), node.arguments[0].valueExpression);
4898
4902
  }
4899
- return { node, type: arg0TypeResult.type };
4903
+ return { type: arg0TypeResult.type };
4900
4904
  }
4901
4905
  function getTypeOfRevealType(node, expectedType) {
4902
4906
  let arg0Value;
@@ -4933,7 +4937,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4933
4937
  });
4934
4938
  if (!arg0Value) {
4935
4939
  addError(localize_1.Localizer.Diagnostic.revealTypeArgs(), node);
4936
- return { node, type: types_1.UnknownType.create() };
4940
+ return { type: types_1.UnknownType.create() };
4937
4941
  }
4938
4942
  const typeResult = getTypeOfExpression(arg0Value, /* flags */ undefined, expectedType);
4939
4943
  const type = typeResult.type;
@@ -4957,11 +4961,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4957
4961
  }
4958
4962
  }
4959
4963
  addInformation(localize_1.Localizer.DiagnosticAddendum.typeOfSymbol().format({ name: exprString, type: typeString }), node.arguments[0]);
4960
- return {
4961
- node,
4962
- type,
4963
- isIncomplete: typeResult.isIncomplete,
4964
- };
4964
+ return { type, isIncomplete: typeResult.isIncomplete };
4965
4965
  }
4966
4966
  function getTypeOfRevealLocals(node) {
4967
4967
  let curNode = node;
@@ -5110,7 +5110,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5110
5110
  type: resultIsInstance
5111
5111
  ? types_1.ClassType.cloneAsInstance(lookupResults.classType)
5112
5112
  : lookupResults.classType,
5113
- node,
5114
5113
  bindToType: resultIsInstance && bindToType && (0, types_1.isInstantiableClass)(bindToType)
5115
5114
  ? types_1.ClassType.cloneAsInstance(bindToType)
5116
5115
  : bindToType,
@@ -5123,10 +5122,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5123
5122
  // If the class derives from one or more unknown classes,
5124
5123
  // return unknown here to prevent spurious errors.
5125
5124
  if (targetClassType.details.mro.some((mroBase) => (0, types_1.isAnyOrUnknown)(mroBase))) {
5126
- return {
5127
- type: types_1.UnknownType.create(),
5128
- node,
5129
- };
5125
+ return { type: types_1.UnknownType.create() };
5130
5126
  }
5131
5127
  const baseClasses = targetClassType.details.baseClasses;
5132
5128
  if (baseClasses.length > 0) {
@@ -5134,15 +5130,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5134
5130
  if ((0, types_1.isInstantiableClass)(baseClassType)) {
5135
5131
  return {
5136
5132
  type: resultIsInstance ? types_1.ClassType.cloneAsInstance(baseClassType) : baseClassType,
5137
- node,
5138
5133
  };
5139
5134
  }
5140
5135
  }
5141
5136
  }
5142
- return {
5143
- type: types_1.UnknownType.create(),
5144
- node,
5145
- };
5137
+ return { type: types_1.UnknownType.create() };
5146
5138
  }
5147
5139
  // Attempts to find an overloaded function for each set of argument
5148
5140
  // types in the expandedArgTypes list. If an argument type is undefined,
@@ -5152,6 +5144,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5152
5144
  // (one for each argument) will be undefined. On subsequent calls, this
5153
5145
  // list will grow to include union expansions.
5154
5146
  function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, expectedType) {
5147
+ var _a;
5155
5148
  const returnTypes = [];
5156
5149
  const matchedOverloads = [];
5157
5150
  let isTypeIncomplete = false;
@@ -5173,11 +5166,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5173
5166
  return argParamCopy;
5174
5167
  });
5175
5168
  }
5176
- // Clone the typeVarContext so we don't modify the original.
5177
- const effectiveTypeVarContext = typeVarContext
5178
- ? typeVarContext.clone()
5179
- : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overload));
5169
+ // Clone the typeVarContext so we don't modify the original. If this is
5170
+ // not the first time through the loop, clone the type var context
5171
+ // from the previous successful match.
5172
+ const typeVarContextToClone = matchedOverloads.length > 0
5173
+ ? matchedOverloads[matchedOverloads.length - 1].typeVarContext.clone()
5174
+ : typeVarContext;
5175
+ const effectiveTypeVarContext = (_a = typeVarContextToClone === null || typeVarContextToClone === void 0 ? void 0 : typeVarContextToClone.clone()) !== null && _a !== void 0 ? _a : new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overload));
5180
5176
  effectiveTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(overload));
5177
+ effectiveTypeVarContext.unlock();
5181
5178
  // Use speculative mode so we don't output any diagnostics or
5182
5179
  // record any final types in the type cache.
5183
5180
  const callResult = useSpeculativeMode(errorNode, () => {
@@ -5202,24 +5199,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5202
5199
  return { argumentErrors: true, isTypeIncomplete };
5203
5200
  }
5204
5201
  }
5205
- // We found a match for all of the expanded argument lists.
5206
- // Run through them again to populate the original typeVarContext.
5202
+ // We found a match for all of the expanded argument lists. Copy the
5203
+ // resulting type var context back into the caller's type var context.
5204
+ // Use the type var context from the last matched overload because it
5205
+ // includes the type var solutions for all earlier matched overloads.
5207
5206
  if (typeVarContext) {
5208
- for (let expandedTypesIndex = 0; expandedTypesIndex < expandedArgTypes.length; expandedTypesIndex++) {
5209
- const overload = matchedOverloads[expandedTypesIndex].overload;
5210
- const matchResults = matchedOverloads[expandedTypesIndex].matchResults;
5211
- useSpeculativeMode(errorNode, () => {
5212
- typeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(overload));
5213
- typeVarContext.unlock();
5214
- return validateFunctionArgumentTypesWithExpectedType(errorNode, matchResults, typeVarContext,
5215
- /* skipUnknownArgCheck */ true, expectedType);
5216
- });
5217
- }
5207
+ typeVarContext.copyFromClone(matchedOverloads[matchedOverloads.length - 1].typeVarContext);
5218
5208
  }
5219
5209
  // And run through the first expanded argument list one more time to
5220
5210
  // populate the type cache.
5221
- matchedOverloads[0].typeVarContext.unlock();
5222
- const finalCallResult = validateFunctionArgumentTypesWithExpectedType(errorNode, matchedOverloads[0].matchResults, matchedOverloads[0].typeVarContext, skipUnknownArgCheck, expectedType);
5211
+ const finalTypeVarContext = typeVarContext !== null && typeVarContext !== void 0 ? typeVarContext : matchedOverloads[0].typeVarContext;
5212
+ finalTypeVarContext.unlock();
5213
+ finalTypeVarContext.addSolveForScope((0, typeUtils_1.getTypeVarScopeId)(matchedOverloads[0].overload));
5214
+ const finalCallResult = validateFunctionArgumentTypesWithExpectedType(errorNode, matchedOverloads[0].matchResults, finalTypeVarContext, skipUnknownArgCheck, expectedType);
5223
5215
  if (finalCallResult.isTypeIncomplete) {
5224
5216
  isTypeIncomplete = true;
5225
5217
  }
@@ -6708,7 +6700,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6708
6700
  });
6709
6701
  const specializedTuple = types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, tupleTypeArgs,
6710
6702
  /* isTypeArgumentExplicit */ true,
6711
- /* stripLiterals */ true,
6712
6703
  /* isUnpackedTuple */ true));
6713
6704
  const combinedArg = {
6714
6705
  paramCategory: 1 /* VarArgList */,
@@ -7427,9 +7418,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7427
7418
  addError(localize_1.Localizer.Diagnostic.typeVarBoundAndConstrained(), argList[i].valueExpression || errorNode);
7428
7419
  }
7429
7420
  else {
7430
- const argType = (_b = (_a = argList[i].typeResult) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : getTypeOfExpressionExpectingType(argList[i].valueExpression,
7431
- /* allowFinal */ undefined,
7432
- /* allowRequired */ undefined).type;
7421
+ const argType = (_b = (_a = argList[i].typeResult) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : getTypeOfExpressionExpectingType(argList[i].valueExpression).type;
7433
7422
  if ((0, typeUtils_1.requiresSpecialization)(argType, /* ignorePseudoGeneric */ true)) {
7434
7423
  addError(localize_1.Localizer.Diagnostic.typeVarGeneric(), argList[i].valueExpression || errorNode);
7435
7424
  }
@@ -7466,9 +7455,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7466
7455
  addError(localize_1.Localizer.Diagnostic.typeVarBoundAndConstrained(), argList[i].valueExpression || errorNode);
7467
7456
  }
7468
7457
  else {
7469
- const argType = (_e = (_d = argList[i].typeResult) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : getTypeOfExpressionExpectingType(argList[i].valueExpression,
7470
- /* allowFinal */ undefined,
7471
- /* allowRequired */ undefined).type;
7458
+ const argType = (_e = (_d = argList[i].typeResult) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : getTypeOfExpressionExpectingType(argList[i].valueExpression).type;
7472
7459
  if ((0, typeUtils_1.requiresSpecialization)(argType, /* ignorePseudoGeneric */ true)) {
7473
7460
  addError(localize_1.Localizer.Diagnostic.typeVarGeneric(), argList[i].valueExpression || errorNode);
7474
7461
  }
@@ -7746,14 +7733,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7746
7733
  if (!type) {
7747
7734
  return undefined;
7748
7735
  }
7749
- return { type, node };
7736
+ return { type };
7750
7737
  }
7751
7738
  function getTypeOfUnaryOperation(node, expectedType) {
7752
7739
  const exprTypeResult = getTypeOfExpression(node.expression);
7753
7740
  let exprType = makeTopLevelTypeVarsConcrete(exprTypeResult.type);
7754
7741
  const isIncomplete = exprTypeResult.isIncomplete;
7755
7742
  if ((0, types_1.isNever)(exprType)) {
7756
- return { node, type: types_1.NeverType.createNever(), isIncomplete };
7743
+ return { type: types_1.NeverType.createNever(), isIncomplete };
7757
7744
  }
7758
7745
  // Map unary operators to magic functions. Note that the bitwise
7759
7746
  // invert has two magic functions that are aliases of each other.
@@ -7832,16 +7819,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7832
7819
  }
7833
7820
  }
7834
7821
  }
7835
- return { type, node, isIncomplete };
7836
- }
7837
- function operatorSupportsComparisonChaining(op) {
7838
- if (binaryOperatorMap[op] && binaryOperatorMap[op][2]) {
7839
- return true;
7840
- }
7841
- if (booleanOperatorMap[op]) {
7842
- return true;
7843
- }
7844
- return false;
7822
+ return { type, isIncomplete };
7845
7823
  }
7846
7824
  function getTypeOfBinaryOperation(node, expectedType, flags) {
7847
7825
  const leftExpression = node.leftExpression;
@@ -7850,10 +7828,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7850
7828
  // If this is a comparison and the left expression is also a comparison,
7851
7829
  // we need to change the behavior to accommodate python's "chained
7852
7830
  // comparisons" feature.
7853
- if (operatorSupportsComparisonChaining(node.operator)) {
7831
+ if (ParseTreeUtils.operatorSupportsChaining(node.operator)) {
7854
7832
  if (rightExpression.nodeType === 7 /* BinaryOperation */ &&
7855
7833
  !rightExpression.parenthesized &&
7856
- operatorSupportsComparisonChaining(rightExpression.operator)) {
7834
+ ParseTreeUtils.operatorSupportsChaining(rightExpression.operator)) {
7857
7835
  // Evaluate the right expression so it is type checked.
7858
7836
  getTypeOfBinaryOperation(rightExpression, expectedType, flags);
7859
7837
  // Use the left side of the right expression for comparison purposes.
@@ -7930,15 +7908,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7930
7908
  addError(localize_1.Localizer.Diagnostic.unionSyntaxIllegal(), node, node.operatorToken);
7931
7909
  }
7932
7910
  }
7933
- if (!validateTypeArg(leftTypeResult, { allowVariadicTypeVar: true, allowUnpackedTuples: true }) ||
7934
- !validateTypeArg(rightTypeResult, { allowVariadicTypeVar: true, allowUnpackedTuples: true })) {
7935
- return { type: types_1.UnknownType.create(), node };
7911
+ if (!validateTypeArg({ ...leftTypeResult, node: leftExpression }, { allowVariadicTypeVar: true, allowUnpackedTuples: true }) ||
7912
+ !validateTypeArg({ ...rightTypeResult, node: rightExpression }, { allowVariadicTypeVar: true, allowUnpackedTuples: true })) {
7913
+ return { type: types_1.UnknownType.create() };
7936
7914
  }
7937
7915
  const newUnion = (0, types_1.combineTypes)([adjustedLeftType, adjustedRightType]);
7938
7916
  if ((0, types_1.isUnion)(newUnion)) {
7939
7917
  types_1.TypeBase.setSpecialForm(newUnion);
7940
7918
  }
7941
- return { type: newUnion, node };
7919
+ return { type: newUnion };
7942
7920
  }
7943
7921
  }
7944
7922
  // Optional checks apply to all operations except for boolean operations.
@@ -7984,7 +7962,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7984
7962
  }
7985
7963
  type = types_1.UnknownType.create();
7986
7964
  }
7987
- return { type, node, isIncomplete };
7965
+ return { type, isIncomplete };
7988
7966
  }
7989
7967
  function customMetaclassSupportsMethod(type, methodName) {
7990
7968
  if (!(0, types_1.isInstantiableClass)(type)) {
@@ -8037,7 +8015,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8037
8015
  const rightType = rightTypeResult.type;
8038
8016
  const isIncomplete = !!rightTypeResult.isIncomplete || !!leftTypeResult.isIncomplete;
8039
8017
  if ((0, types_1.isNever)(leftType) || (0, types_1.isNever)(rightType)) {
8040
- typeResult = { node, type: types_1.NeverType.createNever(), isIncomplete };
8018
+ typeResult = { type: types_1.NeverType.createNever(), isIncomplete };
8041
8019
  }
8042
8020
  else {
8043
8021
  type = mapSubtypesExpandTypeVars(leftType,
@@ -8085,7 +8063,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8085
8063
  }
8086
8064
  type = types_1.UnknownType.create();
8087
8065
  }
8088
- typeResult = { node, type, isIncomplete };
8066
+ typeResult = { type, isIncomplete };
8089
8067
  }
8090
8068
  assignTypeToExpression(node.destExpression, typeResult.type, !!typeResult.isIncomplete, node.rightExpression);
8091
8069
  return typeResult;
@@ -8487,7 +8465,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8487
8465
  if (resultTypedDict) {
8488
8466
  return {
8489
8467
  type: resultTypedDict,
8490
- node,
8491
8468
  isIncomplete,
8492
8469
  };
8493
8470
  }
@@ -8525,7 +8502,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8525
8502
  return undefined;
8526
8503
  }
8527
8504
  const type = getBuiltInObject(node, 'dict', [specializedKeyType, specializedValueType]);
8528
- return { type, node, isIncomplete };
8505
+ return { type, isIncomplete };
8529
8506
  }
8530
8507
  // Attempts to infer the type of a dictionary statement. If hasExpectedType
8531
8508
  // is true, strict inference is used for the subexpressions.
@@ -8569,7 +8546,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8569
8546
  /* includeSubclasses */ undefined,
8570
8547
  /* TupleTypeArguments */ undefined, isEmptyContainer))
8571
8548
  : types_1.UnknownType.create();
8572
- return { type, node, isIncomplete };
8549
+ return { type, isIncomplete };
8573
8550
  }
8574
8551
  function getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes, forceStrictInference, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum) {
8575
8552
  let isIncomplete = false;
@@ -8747,7 +8724,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8747
8724
  return undefined;
8748
8725
  }
8749
8726
  const type = getBuiltInObject(node, builtInClassName, [specializedEntryType]);
8750
- return { type, node, isIncomplete };
8727
+ return { type, isIncomplete };
8751
8728
  }
8752
8729
  // Attempts to infer the type of a list or set statement with no "expected type".
8753
8730
  function getTypeOfListOrSetInferred(node, hasExpectedType) {
@@ -8799,7 +8776,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8799
8776
  /* includeSubclasses */ undefined,
8800
8777
  /* TupleTypeArguments */ undefined, isEmptyContainer))
8801
8778
  : types_1.UnknownType.create();
8802
- return { type, node, isIncomplete };
8779
+ return { type, isIncomplete };
8803
8780
  }
8804
8781
  function inferTypeArgFromExpectedType(expectedType, entryTypes, isNarrowable) {
8805
8782
  let targetTypeVar;
@@ -8861,7 +8838,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8861
8838
  isIncomplete = true;
8862
8839
  }
8863
8840
  }
8864
- return { type: (0, types_1.combineTypes)(typesToCombine), node, isIncomplete };
8841
+ return { type: (0, types_1.combineTypes)(typesToCombine), isIncomplete };
8865
8842
  }
8866
8843
  function getTypeOfYield(node) {
8867
8844
  let expectedYieldType;
@@ -8891,7 +8868,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8891
8868
  isIncomplete = true;
8892
8869
  }
8893
8870
  }
8894
- return { type: sentType || types_1.UnknownType.create(), node, isIncomplete };
8871
+ return { type: sentType || types_1.UnknownType.create(), isIncomplete };
8895
8872
  }
8896
8873
  function getTypeOfYieldFrom(node) {
8897
8874
  var _a;
@@ -8914,7 +8891,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8914
8891
  returnedType = generatorTypeArgs.length >= 2 ? generatorTypeArgs[2] : types_1.UnknownType.create();
8915
8892
  }
8916
8893
  }
8917
- return { type: returnedType || types_1.UnknownType.create(), node };
8894
+ return { type: returnedType || types_1.UnknownType.create() };
8918
8895
  }
8919
8896
  function getTypeOfLambda(node, expectedType) {
8920
8897
  let isIncomplete = false;
@@ -9033,7 +9010,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9033
9010
  }
9034
9011
  // Mark the function type as no longer being evaluated.
9035
9012
  functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
9036
- return { type: functionType, node, isIncomplete };
9013
+ return { type: functionType, isIncomplete };
9037
9014
  }
9038
9015
  function getTypeOfListComprehension(node, expectedType) {
9039
9016
  let isIncomplete = false;
@@ -9066,7 +9043,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9066
9043
  : [elementType, types_1.NoneType.createInstance(), types_1.NoneType.createInstance()],
9067
9044
  /* isTypeArgumentExplicit */ true));
9068
9045
  }
9069
- return { type, node, isIncomplete };
9046
+ return { type, isIncomplete };
9070
9047
  }
9071
9048
  function reportPossibleUnknownAssignment(diagLevel, rule, target, type, errorNode, ignoreEmptyContainers) {
9072
9049
  // Don't bother if the feature is disabled.
@@ -9164,7 +9141,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9164
9141
  }
9165
9142
  type = exprTypeResult.type;
9166
9143
  }
9167
- return { type, node, isIncomplete };
9144
+ return { type, isIncomplete };
9168
9145
  }
9169
9146
  function getTypeOfSlice(node) {
9170
9147
  // Evaluate the expressions to report errors and record symbol
@@ -9180,7 +9157,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9180
9157
  getTypeOfExpression(node.stepValue);
9181
9158
  }
9182
9159
  }
9183
- return { type: getBuiltInObject(node, 'slice'), node };
9160
+ return { type: getBuiltInObject(node, 'slice') };
9184
9161
  }
9185
9162
  // Verifies that a type argument's type is not disallowed.
9186
9163
  function validateTypeArg(argResult, options) {
@@ -9785,8 +9762,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9785
9762
  }
9786
9763
  });
9787
9764
  }
9788
- returnType = (0, typeUtils_1.specializeTupleClass)(classType, tupleTypeArgTypes, typeArgs !== undefined,
9789
- /* stripLiterals */ false);
9765
+ returnType = (0, typeUtils_1.specializeTupleClass)(classType, tupleTypeArgTypes, typeArgs !== undefined);
9790
9766
  }
9791
9767
  else {
9792
9768
  returnType = types_1.ClassType.cloneForSpecialization(classType, typeArgTypes, typeArgs !== undefined);
@@ -11573,8 +11549,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11573
11549
  }
11574
11550
  if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
11575
11551
  return types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type, isUnbounded: !(0, types_1.isVariadicTypeVar)(type) }],
11576
- /* isTypeArgumentExplicit */ true,
11577
- /* stripLiterals */ true));
11552
+ /* isTypeArgumentExplicit */ true));
11578
11553
  }
11579
11554
  return types_1.UnknownType.create();
11580
11555
  }
@@ -12328,6 +12303,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12328
12303
  assignTypeToNameNode(symbolNameNode, symbolType, /* isIncomplete */ false, /* ignoreEmptyContainers */ false);
12329
12304
  writeTypeCache(node, symbolType, 0 /* None */, /* isIncomplete */ false);
12330
12305
  }
12306
+ function evaluateTypesForTypeAnnotationNode(node) {
12307
+ var _a;
12308
+ // If this node is part of an assignment statement, use specialized
12309
+ // logic that performs bidirectional inference and assignment
12310
+ // type narrowing.
12311
+ if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 3 /* Assignment */) {
12312
+ evaluateTypesForAssignmentStatement(node.parent);
12313
+ }
12314
+ else {
12315
+ const annotationType = getTypeOfAnnotation(node.typeAnnotation, {
12316
+ isVariableAnnotation: true,
12317
+ allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(node.valueExpression),
12318
+ allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(node.valueExpression),
12319
+ });
12320
+ writeTypeCache(node.valueExpression, annotationType, 0 /* None */, /* isIncomplete */ false);
12321
+ }
12322
+ }
12331
12323
  function getAliasedSymbolTypeForName(node, name) {
12332
12324
  const symbolWithScope = lookUpSymbolRecursive(node, name, /* honorCodeFlow */ true);
12333
12325
  if (!symbolWithScope) {
@@ -12388,62 +12380,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12388
12380
  // allows for bidirectional type evaluation.
12389
12381
  function evaluateTypesForExpressionInContext(node) {
12390
12382
  var _a, _b, _c, _d, _e;
12391
- let lastContextualExpression = node;
12392
- let curNode = node;
12393
- function isContextual(node) {
12394
- var _a, _b, _c, _d, _e;
12395
- // Parameters are contextual only for lambdas.
12396
- if (node.nodeType === 41 /* Parameter */ && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 30 /* Lambda */) {
12397
- return true;
12398
- }
12399
- // Arguments are contextual only for call and index nodes.
12400
- if (node.nodeType === 1 /* Argument */ &&
12401
- (((_b = node.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 9 /* Call */ || ((_c = node.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 24 /* Index */)) {
12402
- return true;
12403
- }
12404
- // All nodes within a type annotation need to be evaluated
12405
- // contextually so we pass the "type expected" flag to
12406
- // the evaluator.
12407
- if (((_d = node.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 54 /* TypeAnnotation */) {
12408
- return true;
12409
- }
12410
- if (((_e = node.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 41 /* Parameter */ &&
12411
- (node === node.parent.typeAnnotation || node === node.parent.typeAnnotationComment)) {
12412
- return true;
12413
- }
12414
- // The | operator is contextual in cases where it is used to describe a
12415
- // union in type annotations.
12416
- if (node.nodeType === 7 /* BinaryOperation */ && node.operator === 6 /* BitwiseOr */) {
12417
- return true;
12418
- }
12419
- return (node.nodeType === 9 /* Call */ ||
12420
- node.nodeType === 24 /* Index */ ||
12421
- node.nodeType === 15 /* Dictionary */ ||
12422
- node.nodeType === 27 /* FormatString */ ||
12423
- node.nodeType === 31 /* List */ ||
12424
- node.nodeType === 30 /* Lambda */ ||
12425
- node.nodeType === 35 /* MemberAccess */ ||
12426
- node.nodeType === 45 /* Set */ ||
12427
- node.nodeType === 49 /* String */ ||
12428
- node.nodeType === 48 /* StringList */ ||
12429
- node.nodeType === 52 /* Tuple */ ||
12430
- node.nodeType === 56 /* Unpack */ ||
12431
- node.nodeType === 17 /* DictionaryKeyEntry */ ||
12432
- node.nodeType === 16 /* DictionaryExpandEntry */ ||
12433
- node.nodeType === 32 /* ListComprehension */ ||
12434
- node.nodeType === 33 /* ListComprehensionFor */ ||
12435
- node.nodeType === 34 /* ListComprehensionIf */ ||
12436
- node.nodeType === 65 /* PatternSequence */ ||
12437
- node.nodeType === 67 /* PatternLiteral */ ||
12438
- node.nodeType === 68 /* PatternClass */ ||
12439
- node.nodeType === 74 /* PatternClassArgument */ ||
12440
- node.nodeType === 66 /* PatternAs */ ||
12441
- node.nodeType === 69 /* PatternCapture */ ||
12442
- node.nodeType === 70 /* PatternMapping */ ||
12443
- node.nodeType === 73 /* PatternValue */ ||
12444
- node.nodeType === 71 /* PatternMappingKeyEntry */ ||
12445
- node.nodeType === 72 /* PatternMappingExpandEntry */);
12446
- }
12447
12383
  // Check for a couple of special cases where the node is a NameNode but
12448
12384
  // is technically not part of an expression. We'll handle these here so
12449
12385
  // callers don't need to include special-case logic.
@@ -12452,154 +12388,228 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12452
12388
  getTypeOfFunction(node.parent);
12453
12389
  return;
12454
12390
  }
12455
- else if (node.parent.nodeType === 10 /* Class */ && node.parent.name === node) {
12391
+ if (node.parent.nodeType === 10 /* Class */ && node.parent.name === node) {
12456
12392
  getTypeOfClass(node.parent);
12457
12393
  return;
12458
12394
  }
12459
- else if (node.parent.nodeType === 77 /* TypeAlias */ && node.parent.name === node) {
12395
+ if (node.parent.nodeType === 77 /* TypeAlias */ && node.parent.name === node) {
12460
12396
  getTypeOfTypeAlias(node.parent);
12461
12397
  return;
12462
12398
  }
12463
- else if (node.parent.nodeType === 29 /* Global */ ||
12464
- node.parent.nodeType === 39 /* Nonlocal */) {
12399
+ if (node.parent.nodeType === 29 /* Global */ || node.parent.nodeType === 39 /* Nonlocal */) {
12465
12400
  // For global and nonlocal statements, allow forward references so
12466
12401
  // we don't use code flow during symbol lookups.
12467
12402
  getTypeOfExpression(node, 4 /* AllowForwardReferences */);
12468
12403
  return;
12469
12404
  }
12405
+ if (node.parent.nodeType === 37 /* ModuleName */) {
12406
+ // A name within a module name isn't an expression,
12407
+ // so there's nothing we can evaluate here.
12408
+ return;
12409
+ }
12470
12410
  }
12471
- // Scan up the parse tree until we find a non-expression (while
12472
- // looking for contextual expressions in the process).
12473
- while (curNode) {
12474
- const isNodeContextual = isContextual(curNode);
12475
- if (!isNodeContextual && !(0, parseNodes_1.isExpressionNode)(curNode)) {
12476
- break;
12411
+ // If the expression is part of a type annotation, we need to evaluate
12412
+ // it with special evaluation flags.
12413
+ const annotationNode = ParseTreeUtils.getParentAnnotationNode(node);
12414
+ if (annotationNode) {
12415
+ // Annotations need to be evaluated with specialized evaluation flags.
12416
+ const annotationParent = annotationNode.parent;
12417
+ (0, debug_1.assert)(annotationParent !== undefined);
12418
+ if (annotationParent.nodeType === 3 /* Assignment */) {
12419
+ if (annotationNode === annotationParent.typeAnnotationComment) {
12420
+ getTypeOfAnnotation(annotationNode, {
12421
+ isVariableAnnotation: true,
12422
+ allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(annotationParent.leftExpression),
12423
+ allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(annotationParent.leftExpression),
12424
+ });
12425
+ }
12426
+ else {
12427
+ evaluateTypesForAssignmentStatement(annotationParent);
12428
+ }
12429
+ return;
12477
12430
  }
12478
- if (isNodeContextual) {
12479
- lastContextualExpression = curNode;
12431
+ if (annotationParent.nodeType === 54 /* TypeAnnotation */) {
12432
+ evaluateTypesForTypeAnnotationNode(annotationParent);
12433
+ return;
12480
12434
  }
12481
- curNode = curNode.parent;
12482
- }
12483
- const parent = lastContextualExpression.parent;
12484
- if (parent.nodeType === 3 /* Assignment */) {
12485
- if (lastContextualExpression === parent.typeAnnotationComment) {
12486
- getTypeOfAnnotation(lastContextualExpression, {
12487
- isVariableAnnotation: true,
12488
- allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(parent.leftExpression),
12489
- allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(parent.leftExpression),
12435
+ if (annotationParent.nodeType === 28 /* Function */ &&
12436
+ annotationNode === annotationParent.returnTypeAnnotation) {
12437
+ getTypeOfAnnotation(annotationNode, {
12438
+ associateTypeVarsWithScope: true,
12439
+ disallowRecursiveTypeAlias: true,
12490
12440
  });
12441
+ return;
12491
12442
  }
12492
- else {
12493
- evaluateTypesForAssignmentStatement(parent);
12494
- }
12495
- return;
12496
- }
12497
- else if (parent.nodeType === 14 /* Del */) {
12498
- verifyDeleteExpression(lastContextualExpression);
12443
+ getTypeOfAnnotation(annotationNode);
12499
12444
  return;
12500
12445
  }
12501
- // If this is the name node within a type parameter list, see if it's a type alias
12502
- // definition. If so, we need to evaluate the type alias contextually.
12503
- if (parent.nodeType === 75 /* TypeParameter */ && lastContextualExpression === parent.name) {
12504
- if (((_a = parent.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 76 /* TypeParameterList */ &&
12505
- ((_b = parent.parent.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 77 /* TypeAlias */) {
12506
- getTypeOfTypeAlias(parent.parent.parent);
12446
+ // See if the expression is part of a pattern used in a case statement.
12447
+ const possibleCaseNode = ParseTreeUtils.getParentNodeOfType(node, 64 /* Case */);
12448
+ if (possibleCaseNode) {
12449
+ const caseNode = possibleCaseNode;
12450
+ if (ParseTreeUtils.isNodeContainedWithin(node, caseNode.pattern)) {
12451
+ evaluateTypesForCaseStatement(caseNode);
12507
12452
  return;
12508
12453
  }
12509
12454
  }
12510
- if (parent.nodeType === 75 /* TypeParameter */) {
12511
- getTypeOfExpression(parent.name);
12512
- return;
12513
- }
12514
- if (parent.nodeType === 77 /* TypeAlias */) {
12515
- getTypeOfTypeAlias(parent);
12516
- return;
12517
- }
12518
- if (parent.nodeType === 5 /* AugmentedAssignment */) {
12519
- evaluateTypesForAugmentedAssignment(parent);
12520
- return;
12521
- }
12522
- if (parent.nodeType === 13 /* Decorator */) {
12523
- if (((_c = parent.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 10 /* Class */) {
12524
- getTypeOfClass(parent.parent);
12455
+ // Scan up the parse tree until we find a node that doesn't
12456
+ // require any context to be evaluated.
12457
+ let nodeToEvaluate = node;
12458
+ let flags = 0 /* None */;
12459
+ while (true) {
12460
+ // If we're within an argument node in a call or index expression, skip
12461
+ // all of the nodes between because the entire argument expression
12462
+ // needs to be evaluated contextually.
12463
+ const argumentNode = ParseTreeUtils.getParentNodeOfType(nodeToEvaluate, 1 /* Argument */);
12464
+ if (argumentNode && argumentNode !== nodeToEvaluate) {
12465
+ (0, debug_1.assert)(argumentNode.parent !== undefined);
12466
+ if (argumentNode.parent.nodeType === 9 /* Call */ ||
12467
+ argumentNode.parent.nodeType === 24 /* Index */) {
12468
+ nodeToEvaluate = argumentNode.parent;
12469
+ continue;
12470
+ }
12525
12471
  }
12526
- else if (((_d = parent.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 28 /* Function */) {
12527
- getTypeOfFunction(parent.parent);
12472
+ let parent = nodeToEvaluate.parent;
12473
+ if (!parent) {
12474
+ break;
12528
12475
  }
12529
- return;
12530
- }
12531
- const evaluateTypeAnnotationExpression = (node) => {
12532
- const annotationParent = node.parent;
12533
- if ((annotationParent === null || annotationParent === void 0 ? void 0 : annotationParent.nodeType) === 3 /* Assignment */ && annotationParent.leftExpression === parent) {
12534
- evaluateTypesForAssignmentStatement(annotationParent);
12476
+ // If this is the target of an assignment expression, evaluate the
12477
+ // assignment expression node instead.
12478
+ if (parent.nodeType === 4 /* AssignmentExpression */ && nodeToEvaluate === parent.name) {
12479
+ nodeToEvaluate = parent;
12480
+ continue;
12481
+ }
12482
+ // The left expression of a call or member access expression is not contextual.
12483
+ if (parent.nodeType === 9 /* Call */ || parent.nodeType === 35 /* MemberAccess */) {
12484
+ if (nodeToEvaluate === parent.leftExpression) {
12485
+ flags = 2 /* DoNotSpecialize */;
12486
+ break;
12487
+ }
12488
+ }
12489
+ else if (parent.nodeType === 24 /* Index */) {
12490
+ // The base expression of an index expression is not contextual.
12491
+ if (nodeToEvaluate === parent.baseExpression) {
12492
+ flags = 2 /* DoNotSpecialize */;
12493
+ break;
12494
+ }
12535
12495
  }
12536
12496
  else {
12537
- const annotationType = getTypeOfAnnotation(node.typeAnnotation, {
12538
- isVariableAnnotation: true,
12539
- allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(node.valueExpression),
12540
- allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(node.valueExpression),
12541
- });
12542
- writeTypeCache(node.valueExpression, annotationType, 0 /* None */, /* isIncomplete */ false);
12497
+ // Check for expression types that are always contextual.
12498
+ if (nodeToEvaluate.nodeType !== 15 /* Dictionary */ &&
12499
+ nodeToEvaluate.nodeType !== 31 /* List */ &&
12500
+ nodeToEvaluate.nodeType !== 30 /* Lambda */ &&
12501
+ nodeToEvaluate.nodeType !== 45 /* Set */ &&
12502
+ nodeToEvaluate.nodeType !== 52 /* Tuple */ &&
12503
+ nodeToEvaluate.nodeType !== 56 /* Unpack */ &&
12504
+ nodeToEvaluate.nodeType !== 32 /* ListComprehension */) {
12505
+ break;
12506
+ }
12543
12507
  }
12544
- };
12545
- if (parent.nodeType === 64 /* Case */ && lastContextualExpression !== parent.guardExpression) {
12546
- evaluateTypesForCaseStatement(parent);
12547
- return;
12548
- }
12549
- if (parent.nodeType === 54 /* TypeAnnotation */) {
12550
- evaluateTypeAnnotationExpression(parent);
12551
- return;
12552
- }
12553
- if (parent.nodeType === 41 /* Parameter */ && lastContextualExpression !== parent.defaultValue) {
12554
- evaluateTypeOfParameter(parent);
12555
- return;
12508
+ if (!(0, parseNodes_1.isExpressionNode)(parent)) {
12509
+ // If we've hit a non-expression node, we generally want to
12510
+ // stop. However, there are a few special "pass through"
12511
+ // node types that we can skip over to get to a known
12512
+ // expression node.
12513
+ if (parent.nodeType === 17 /* DictionaryKeyEntry */ ||
12514
+ parent.nodeType === 16 /* DictionaryExpandEntry */ ||
12515
+ parent.nodeType === 33 /* ListComprehensionFor */ ||
12516
+ parent.nodeType === 34 /* ListComprehensionIf */) {
12517
+ (0, debug_1.assert)(parent.parent !== undefined && (0, parseNodes_1.isExpressionNode)(parent.parent));
12518
+ parent = parent.parent;
12519
+ }
12520
+ else if (parent.nodeType === 41 /* Parameter */) {
12521
+ (0, debug_1.assert)(parent.parent !== undefined);
12522
+ // Parameters are contextual for lambdas.
12523
+ if (parent.parent.nodeType === 30 /* Lambda */) {
12524
+ parent = parent.parent;
12525
+ }
12526
+ else {
12527
+ break;
12528
+ }
12529
+ }
12530
+ else {
12531
+ break;
12532
+ }
12533
+ }
12534
+ nodeToEvaluate = parent;
12556
12535
  }
12557
- if (parent.nodeType === 28 /* Function */) {
12558
- if (lastContextualExpression === parent.returnTypeAnnotation) {
12559
- getTypeOfAnnotation(lastContextualExpression, {
12560
- associateTypeVarsWithScope: true,
12561
- disallowRecursiveTypeAlias: true,
12562
- });
12536
+ const parent = nodeToEvaluate.parent;
12537
+ (0, debug_1.assert)(parent !== undefined);
12538
+ switch (parent.nodeType) {
12539
+ case 14 /* Del */: {
12540
+ verifyDeleteExpression(nodeToEvaluate);
12541
+ return;
12542
+ }
12543
+ case 75 /* TypeParameter */: {
12544
+ // If this is the name node within a type parameter list, see if it's a type alias
12545
+ // definition. If so, we need to evaluate the type alias contextually.
12546
+ if (nodeToEvaluate === parent.name &&
12547
+ ((_a = parent.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 76 /* TypeParameterList */ &&
12548
+ ((_b = parent.parent.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 77 /* TypeAlias */) {
12549
+ getTypeOfTypeAlias(parent.parent.parent);
12550
+ return;
12551
+ }
12552
+ break;
12553
+ }
12554
+ case 77 /* TypeAlias */: {
12555
+ getTypeOfTypeAlias(parent);
12556
+ return;
12557
+ }
12558
+ case 13 /* Decorator */: {
12559
+ if (((_c = parent.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 10 /* Class */) {
12560
+ getTypeOfClass(parent.parent);
12561
+ }
12562
+ else if (((_d = parent.parent) === null || _d === void 0 ? void 0 : _d.nodeType) === 28 /* Function */) {
12563
+ getTypeOfFunction(parent.parent);
12564
+ }
12565
+ return;
12566
+ }
12567
+ case 41 /* Parameter */: {
12568
+ if (nodeToEvaluate !== parent.defaultValue) {
12569
+ evaluateTypeOfParameter(parent);
12570
+ return;
12571
+ }
12572
+ break;
12573
+ }
12574
+ case 1 /* Argument */: {
12575
+ if (nodeToEvaluate === parent.name) {
12576
+ // A name used to specify a named parameter in an argument isn't an
12577
+ // expression, so there's nothing we can evaluate here.
12578
+ return;
12579
+ }
12580
+ if (((_e = parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 10 /* Class */) {
12581
+ // A class argument must be evaluated in the context of the class declaration.
12582
+ getTypeOfClass(parent.parent);
12583
+ return;
12584
+ }
12585
+ break;
12586
+ }
12587
+ case 44 /* Return */: {
12588
+ // Return expressions must be evaluated in the context of the expected return type.
12589
+ if (parent.returnExpression) {
12590
+ const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(node);
12591
+ const declaredReturnType = enclosingFunctionNode
12592
+ ? getFunctionDeclaredReturnType(enclosingFunctionNode)
12593
+ : undefined;
12594
+ getTypeOfExpression(parent.returnExpression, 0 /* None */, declaredReturnType);
12595
+ return;
12596
+ }
12597
+ break;
12598
+ }
12599
+ case 54 /* TypeAnnotation */: {
12600
+ evaluateTypesForTypeAnnotationNode(parent);
12601
+ return;
12602
+ }
12603
+ case 3 /* Assignment */: {
12604
+ evaluateTypesForAssignmentStatement(parent);
12563
12605
  return;
12564
12606
  }
12565
12607
  }
12566
- if (parent.nodeType === 37 /* ModuleName */) {
12567
- // A name within a module name isn't an expression,
12568
- // so there's nothing we can evaluate here.
12569
- return;
12570
- }
12571
- if (parent.nodeType === 1 /* Argument */ && lastContextualExpression === parent.name) {
12572
- // A name used to specify a named parameter in an argument isn't an
12573
- // expression, so there's nothing we can evaluate here.
12574
- return;
12575
- }
12576
- // A class argument must be evaluated in the context of the class declaration.
12577
- if (parent.nodeType === 1 /* Argument */ && ((_e = parent.parent) === null || _e === void 0 ? void 0 : _e.nodeType) === 10 /* Class */) {
12578
- getTypeOfClass(parent.parent);
12579
- return;
12580
- }
12581
- if (parent.nodeType === 44 /* Return */ && parent.returnExpression) {
12582
- const enclosingFunctionNode = ParseTreeUtils.getEnclosingFunction(node);
12583
- const declaredReturnType = enclosingFunctionNode
12584
- ? getFunctionDeclaredReturnType(enclosingFunctionNode)
12585
- : undefined;
12586
- getTypeOfExpression(parent.returnExpression, 0 /* None */, declaredReturnType);
12587
- return;
12588
- }
12589
- // If the parent is an expression, we'll evaluate it to provide
12590
- // the context for its child. If it's not, we'll evaluate the
12591
- // child directly without any context.
12592
- const nodeToEvaluate = (0, parseNodes_1.isExpressionNode)(parent) && parent.nodeType !== 0 /* Error */
12593
- ? parent
12594
- : lastContextualExpression;
12595
12608
  if (nodeToEvaluate.nodeType === 54 /* TypeAnnotation */) {
12596
- evaluateTypeAnnotationExpression(nodeToEvaluate);
12597
- }
12598
- else {
12599
- const fileInfo = AnalyzerNodeInfo.getFileInfo(nodeToEvaluate);
12600
- const flags = fileInfo.isStubFile ? 4 /* AllowForwardReferences */ : 0 /* None */;
12601
- getTypeOfExpression(nodeToEvaluate, flags);
12609
+ evaluateTypesForTypeAnnotationNode(nodeToEvaluate);
12610
+ return;
12602
12611
  }
12612
+ getTypeOfExpression(nodeToEvaluate, flags);
12603
12613
  }
12604
12614
  function evaluateTypeOfParameter(node) {
12605
12615
  // If this parameter has no name, we have nothing to do.
@@ -12759,7 +12769,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12759
12769
  // doing additional work.
12760
12770
  let subnodeType = readTypeCache(subnode, /* flags */ undefined);
12761
12771
  if (subnodeType) {
12762
- return { node: subnode, type: subnodeType };
12772
+ return { type: subnodeType };
12763
12773
  }
12764
12774
  const oldIncompleteCache = incompleteTypeCache;
12765
12775
  try {
@@ -12772,11 +12782,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12772
12782
  callback();
12773
12783
  subnodeType = readTypeCache(subnode, /* flags */ undefined);
12774
12784
  if (subnodeType) {
12775
- return { node: subnode, type: subnodeType };
12785
+ return { type: subnodeType };
12776
12786
  }
12777
12787
  subnodeType = incompleteTypeCache.get(subnode.id);
12778
12788
  if (subnodeType) {
12779
- return { node: subnode, type: subnodeType, isIncomplete: true };
12789
+ return { type: subnodeType, isIncomplete: true };
12780
12790
  }
12781
12791
  incompleteTypeCache = oldIncompleteCache;
12782
12792
  }
@@ -14442,7 +14452,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14442
14452
  // prior to specializing.
14443
14453
  inferReturnTypeIfNecessary(typeResult.type);
14444
14454
  return {
14445
- node,
14446
14455
  type: (0, typeUtils_1.partiallySpecializeType)(typeResult.type, member.classType, selfClass),
14447
14456
  isIncomplete: !!typeResult.isIncomplete,
14448
14457
  };
@@ -14625,7 +14634,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14625
14634
  return { type: (0, typeUtils_1.stripLiteralValue)(typeArg.type), isUnbounded: false };
14626
14635
  }),
14627
14636
  /* isTypeArgumentExplicit */ true,
14628
- /* stripLiterals */ true,
14629
14637
  /* isUnpackedTuple */ true));
14630
14638
  srcTypeArgs.splice(destVariadicIndex, 0, {
14631
14639
  type: variadicTuple,
@@ -15549,54 +15557,69 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15549
15557
  // For union destinations, we just need to match one of the types.
15550
15558
  const diagAddendum = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
15551
15559
  let foundMatch = false;
15552
- // Run through all subtypes in the union. Don't stop at the first
15553
- // match we find because we may need to match TypeVars in other
15554
- // subtypes. We special-case "None" so we can handle Optional[T]
15555
- // without matching the None to the type var.
15556
- if ((0, types_1.isNoneInstance)(srcType) && (0, typeUtils_1.isOptionalType)(destType)) {
15557
- foundMatch = true;
15560
+ // Does the union contain any type variables that need to be solved?
15561
+ // If so, we need to use a slower path.
15562
+ if (!(0, typeUtils_1.requiresSpecialization)(destType)) {
15563
+ for (const subtype of destType.subtypes) {
15564
+ if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(),
15565
+ /* destTypeVarContextClone */ undefined,
15566
+ /* srcTypeVarContextClone */ undefined, flags, recursionCount)) {
15567
+ foundMatch = true;
15568
+ break;
15569
+ }
15570
+ }
15558
15571
  }
15559
15572
  else {
15560
- let bestDestTypeVarContext;
15561
- let bestSrcTypeVarContext;
15562
- let bestTypeVarContextScore;
15563
- // If the srcType is a literal, try to use the fast-path lookup
15564
- // in case the destType is a union with hundreds of literals.
15565
- if ((0, types_1.isClassInstance)(srcType) &&
15566
- (0, typeUtils_1.isLiteralType)(srcType) &&
15567
- types_1.UnionType.containsType(destType, srcType, recursionCount)) {
15568
- return true;
15573
+ // Run through all subtypes in the union. Don't stop at the first
15574
+ // match we find because we may need to match TypeVars in other
15575
+ // subtypes. We special-case "None" so we can handle Optional[T]
15576
+ // without matching the None to the type var.
15577
+ if ((0, types_1.isNoneInstance)(srcType) && (0, typeUtils_1.isOptionalType)(destType)) {
15578
+ foundMatch = true;
15569
15579
  }
15570
- (0, typeUtils_1.doForEachSubtype)(destType, (subtype) => {
15571
- // Make a temporary clone of the typeVarContext. We don't want to modify
15572
- // the original typeVarContext until we find the "optimal" typeVar mapping.
15573
- const destTypeVarContextClone = destTypeVarContext === null || destTypeVarContext === void 0 ? void 0 : destTypeVarContext.clone();
15574
- const srcTypeVarContextClone = srcTypeVarContext === null || srcTypeVarContext === void 0 ? void 0 : srcTypeVarContext.clone();
15575
- if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(), destTypeVarContextClone, srcTypeVarContextClone, flags, recursionCount)) {
15576
- foundMatch = true;
15577
- if (destTypeVarContextClone) {
15578
- // Ask the typeVarContext to compute a "score" for the current
15579
- // contents of the table.
15580
- let typeVarContextScore = destTypeVarContextClone.getScore();
15581
- // If the type matches exactly, prefer it over other types.
15582
- if ((0, types_1.isTypeSame)(subtype, (0, typeUtils_1.stripLiteralValue)(srcType))) {
15583
- typeVarContextScore = Number.POSITIVE_INFINITY;
15584
- }
15585
- if (bestTypeVarContextScore === undefined || bestTypeVarContextScore <= typeVarContextScore) {
15586
- // We found a typeVar mapping with a higher score than before.
15587
- bestTypeVarContextScore = typeVarContextScore;
15588
- bestDestTypeVarContext = destTypeVarContextClone;
15589
- bestSrcTypeVarContext = srcTypeVarContextClone;
15580
+ else {
15581
+ let bestDestTypeVarContext;
15582
+ let bestSrcTypeVarContext;
15583
+ let bestTypeVarContextScore;
15584
+ // If the srcType is a literal, try to use the fast-path lookup
15585
+ // in case the destType is a union with hundreds of literals.
15586
+ if ((0, types_1.isClassInstance)(srcType) &&
15587
+ (0, typeUtils_1.isLiteralType)(srcType) &&
15588
+ types_1.UnionType.containsType(destType, srcType, recursionCount)) {
15589
+ return true;
15590
+ }
15591
+ (0, typeUtils_1.doForEachSubtype)(destType, (subtype) => {
15592
+ // Make a temporary clone of the typeVarContext. We don't want to modify
15593
+ // the original typeVarContext until we find the "optimal" typeVar mapping.
15594
+ const destTypeVarContextClone = destTypeVarContext === null || destTypeVarContext === void 0 ? void 0 : destTypeVarContext.clone();
15595
+ const srcTypeVarContextClone = srcTypeVarContext === null || srcTypeVarContext === void 0 ? void 0 : srcTypeVarContext.clone();
15596
+ if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(), destTypeVarContextClone, srcTypeVarContextClone, flags, recursionCount)) {
15597
+ foundMatch = true;
15598
+ if (destTypeVarContextClone) {
15599
+ // Ask the typeVarContext to compute a "score" for the current
15600
+ // contents of the table.
15601
+ let typeVarContextScore = destTypeVarContextClone.getScore();
15602
+ // If the type matches exactly, prefer it over other types.
15603
+ if ((0, types_1.isTypeSame)(subtype, (0, typeUtils_1.stripLiteralValue)(srcType))) {
15604
+ typeVarContextScore = Number.POSITIVE_INFINITY;
15605
+ }
15606
+ if (bestTypeVarContextScore === undefined ||
15607
+ bestTypeVarContextScore <= typeVarContextScore) {
15608
+ // We found a typeVar mapping with a higher score than before.
15609
+ bestTypeVarContextScore = typeVarContextScore;
15610
+ bestDestTypeVarContext = destTypeVarContextClone;
15611
+ bestSrcTypeVarContext = srcTypeVarContextClone;
15612
+ }
15590
15613
  }
15591
15614
  }
15615
+ });
15616
+ // If we found a winning type var mapping, copy it back to typeVarContext.
15617
+ if (destTypeVarContext && bestDestTypeVarContext) {
15618
+ destTypeVarContext.copyFromClone(bestDestTypeVarContext);
15619
+ }
15620
+ if (srcTypeVarContext && bestSrcTypeVarContext) {
15621
+ srcTypeVarContext.copyFromClone(bestSrcTypeVarContext);
15592
15622
  }
15593
- });
15594
- // If we found a winning type var mapping, copy it back to typeVarContext.
15595
- if (destTypeVarContext && bestDestTypeVarContext) {
15596
- destTypeVarContext.copyFromClone(bestDestTypeVarContext);
15597
- }
15598
- if (srcTypeVarContext && bestSrcTypeVarContext) {
15599
- srcTypeVarContext.copyFromClone(bestSrcTypeVarContext);
15600
15623
  }
15601
15624
  }
15602
15625
  // If the source is a constrained TypeVar, see if we can assign all of the
@@ -15884,7 +15907,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15884
15907
  if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
15885
15908
  srcPositionalsType = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, srcTupleTypes,
15886
15909
  /* isTypeArgumentExplicit */ true,
15887
- /* stripLiterals */ true,
15888
15910
  /* isUnpackedTuple */ true));
15889
15911
  }
15890
15912
  else {
@@ -16070,13 +16092,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16070
16092
  if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
16071
16093
  if (!(0, types_1.isUnpacked)(destArgsType)) {
16072
16094
  destArgsType = types_1.ClassType.cloneForUnpacked(types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type: destArgsType, isUnbounded: true }],
16073
- /* isTypeArgumentExplicit */ true,
16074
- /* stripLiterals */ true)));
16095
+ /* isTypeArgumentExplicit */ true)));
16075
16096
  }
16076
16097
  if (!(0, types_1.isUnpacked)(srcArgsType)) {
16077
16098
  srcArgsType = types_1.ClassType.cloneForUnpacked(types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type: srcArgsType, isUnbounded: true }],
16078
- /* isTypeArgumentExplicit */ true,
16079
- /* stripLiterals */ true)));
16099
+ /* isTypeArgumentExplicit */ true)));
16080
16100
  }
16081
16101
  }
16082
16102
  if (!assignFunctionParameter(destArgsType, srcArgsType, destParamDetails.params[destParamDetails.argsIndex].index, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {