@zzzen/pyright-internal 1.2.0-dev.20240721 → 1.2.0-dev.20240804

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 (228) hide show
  1. package/dist/analyzer/analyzerNodeInfo.js +2 -2
  2. package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
  3. package/dist/analyzer/binder.js +15 -12
  4. package/dist/analyzer/binder.js.map +1 -1
  5. package/dist/analyzer/cacheManager.js +3 -0
  6. package/dist/analyzer/cacheManager.js.map +1 -1
  7. package/dist/analyzer/checker.d.ts +5 -3
  8. package/dist/analyzer/checker.js +238 -193
  9. package/dist/analyzer/checker.js.map +1 -1
  10. package/dist/analyzer/codeFlowEngine.d.ts +2 -2
  11. package/dist/analyzer/codeFlowEngine.js +53 -46
  12. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  13. package/dist/analyzer/codeFlowTypes.js +1 -1
  14. package/dist/analyzer/codeFlowTypes.js.map +1 -1
  15. package/dist/analyzer/constraintSolution.d.ts +21 -0
  16. package/dist/analyzer/constraintSolution.js +71 -0
  17. package/dist/analyzer/constraintSolution.js.map +1 -0
  18. package/dist/analyzer/constraintSolver.d.ts +10 -6
  19. package/dist/analyzer/constraintSolver.js +520 -462
  20. package/dist/analyzer/constraintSolver.js.map +1 -1
  21. package/dist/analyzer/constraintTracker.d.ts +44 -0
  22. package/dist/analyzer/constraintTracker.js +230 -0
  23. package/dist/analyzer/constraintTracker.js.map +1 -0
  24. package/dist/analyzer/constructorTransform.d.ts +2 -2
  25. package/dist/analyzer/constructorTransform.js +25 -25
  26. package/dist/analyzer/constructorTransform.js.map +1 -1
  27. package/dist/analyzer/constructors.d.ts +3 -3
  28. package/dist/analyzer/constructors.js +80 -64
  29. package/dist/analyzer/constructors.js.map +1 -1
  30. package/dist/analyzer/dataClasses.d.ts +2 -2
  31. package/dist/analyzer/dataClasses.js +87 -61
  32. package/dist/analyzer/dataClasses.js.map +1 -1
  33. package/dist/analyzer/declaration.d.ts +9 -9
  34. package/dist/analyzer/declaration.js +9 -9
  35. package/dist/analyzer/declaration.js.map +1 -1
  36. package/dist/analyzer/declarationUtils.d.ts +1 -1
  37. package/dist/analyzer/declarationUtils.js +6 -6
  38. package/dist/analyzer/declarationUtils.js.map +1 -1
  39. package/dist/analyzer/decorators.js +5 -5
  40. package/dist/analyzer/decorators.js.map +1 -1
  41. package/dist/analyzer/docStringConversion.js +2 -2
  42. package/dist/analyzer/docStringConversion.js.map +1 -1
  43. package/dist/analyzer/enums.d.ts +2 -2
  44. package/dist/analyzer/enums.js +6 -6
  45. package/dist/analyzer/enums.js.map +1 -1
  46. package/dist/analyzer/functionTransform.d.ts +2 -2
  47. package/dist/analyzer/functionTransform.js +5 -5
  48. package/dist/analyzer/functionTransform.js.map +1 -1
  49. package/dist/analyzer/importResolver.js +5 -3
  50. package/dist/analyzer/importResolver.js.map +1 -1
  51. package/dist/analyzer/namedTuples.d.ts +3 -3
  52. package/dist/analyzer/namedTuples.js +21 -22
  53. package/dist/analyzer/namedTuples.js.map +1 -1
  54. package/dist/analyzer/operations.d.ts +1 -2
  55. package/dist/analyzer/operations.js +105 -82
  56. package/dist/analyzer/operations.js.map +1 -1
  57. package/dist/analyzer/packageTypeVerifier.js +16 -12
  58. package/dist/analyzer/packageTypeVerifier.js.map +1 -1
  59. package/dist/analyzer/parameterUtils.d.ts +12 -12
  60. package/dist/analyzer/parameterUtils.js +67 -69
  61. package/dist/analyzer/parameterUtils.js.map +1 -1
  62. package/dist/analyzer/parseTreeUtils.d.ts +6 -6
  63. package/dist/analyzer/parseTreeUtils.js +22 -22
  64. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  65. package/dist/analyzer/patternMatching.js +122 -101
  66. package/dist/analyzer/patternMatching.js.map +1 -1
  67. package/dist/analyzer/program.js +11 -4
  68. package/dist/analyzer/program.js.map +1 -1
  69. package/dist/analyzer/properties.d.ts +3 -2
  70. package/dist/analyzer/properties.js +27 -27
  71. package/dist/analyzer/properties.js.map +1 -1
  72. package/dist/analyzer/protocols.d.ts +3 -3
  73. package/dist/analyzer/protocols.js +58 -57
  74. package/dist/analyzer/protocols.js.map +1 -1
  75. package/dist/analyzer/pythonPathUtils.js +1 -1
  76. package/dist/analyzer/pythonPathUtils.js.map +1 -1
  77. package/dist/analyzer/service.d.ts +3 -7
  78. package/dist/analyzer/service.js +28 -30
  79. package/dist/analyzer/service.js.map +1 -1
  80. package/dist/analyzer/serviceUtils.d.ts +8 -0
  81. package/dist/analyzer/serviceUtils.js +31 -0
  82. package/dist/analyzer/serviceUtils.js.map +1 -0
  83. package/dist/analyzer/sourceFile.js +5 -19
  84. package/dist/analyzer/sourceFile.js.map +1 -1
  85. package/dist/analyzer/sourceMapper.d.ts +1 -1
  86. package/dist/analyzer/sourceMapper.js +4 -4
  87. package/dist/analyzer/sourceMapper.js.map +1 -1
  88. package/dist/analyzer/staticExpressions.js +1 -1
  89. package/dist/analyzer/staticExpressions.js.map +1 -1
  90. package/dist/analyzer/tracePrinter.js +4 -4
  91. package/dist/analyzer/tracePrinter.js.map +1 -1
  92. package/dist/analyzer/tuples.d.ts +9 -0
  93. package/dist/analyzer/tuples.js +253 -0
  94. package/dist/analyzer/tuples.js.map +1 -0
  95. package/dist/analyzer/typeComplexity.d.ts +2 -0
  96. package/dist/analyzer/typeComplexity.js +94 -0
  97. package/dist/analyzer/typeComplexity.js.map +1 -0
  98. package/dist/analyzer/typeEvaluator.js +1758 -1979
  99. package/dist/analyzer/typeEvaluator.js.map +1 -1
  100. package/dist/analyzer/typeEvaluatorTypes.d.ts +69 -45
  101. package/dist/analyzer/typeEvaluatorTypes.js +7 -1
  102. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  103. package/dist/analyzer/typeGuards.js +157 -121
  104. package/dist/analyzer/typeGuards.js.map +1 -1
  105. package/dist/analyzer/typePrinter.d.ts +1 -1
  106. package/dist/analyzer/typePrinter.js +64 -61
  107. package/dist/analyzer/typePrinter.js.map +1 -1
  108. package/dist/analyzer/typeStubWriter.d.ts +3 -3
  109. package/dist/analyzer/typeStubWriter.js +15 -15
  110. package/dist/analyzer/typeStubWriter.js.map +1 -1
  111. package/dist/analyzer/typeUtils.d.ts +45 -41
  112. package/dist/analyzer/typeUtils.js +511 -748
  113. package/dist/analyzer/typeUtils.js.map +1 -1
  114. package/dist/analyzer/typeWalker.js +4 -4
  115. package/dist/analyzer/typeWalker.js.map +1 -1
  116. package/dist/analyzer/typedDicts.d.ts +4 -4
  117. package/dist/analyzer/typedDicts.js +73 -77
  118. package/dist/analyzer/typedDicts.js.map +1 -1
  119. package/dist/analyzer/types.d.ts +97 -72
  120. package/dist/analyzer/types.js +217 -208
  121. package/dist/analyzer/types.js.map +1 -1
  122. package/dist/commands/dumpFileDebugInfoCommand.js +11 -11
  123. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  124. package/dist/common/configOptions.d.ts +1 -0
  125. package/dist/common/configOptions.js +5 -0
  126. package/dist/common/configOptions.js.map +1 -1
  127. package/dist/common/diagnosticRules.d.ts +1 -0
  128. package/dist/common/diagnosticRules.js +1 -0
  129. package/dist/common/diagnosticRules.js.map +1 -1
  130. package/dist/common/fileSystem.d.ts +0 -1
  131. package/dist/common/fileSystem.js.map +1 -1
  132. package/dist/common/languageServerInterface.d.ts +13 -0
  133. package/dist/common/languageServerInterface.js +15 -1
  134. package/dist/common/languageServerInterface.js.map +1 -1
  135. package/dist/common/lspUtils.js +2 -2
  136. package/dist/common/memUtils.d.ts +4 -0
  137. package/dist/common/memUtils.js +33 -2
  138. package/dist/common/memUtils.js.map +1 -1
  139. package/dist/common/serviceKeys.d.ts +3 -0
  140. package/dist/common/serviceKeys.js +2 -0
  141. package/dist/common/serviceKeys.js.map +1 -1
  142. package/dist/common/serviceProviderExtensions.js +7 -0
  143. package/dist/common/serviceProviderExtensions.js.map +1 -1
  144. package/dist/languageServerBase.d.ts +5 -4
  145. package/dist/languageServerBase.js +19 -12
  146. package/dist/languageServerBase.js.map +1 -1
  147. package/dist/languageService/autoImporter.d.ts +3 -2
  148. package/dist/languageService/autoImporter.js +5 -1
  149. package/dist/languageService/autoImporter.js.map +1 -1
  150. package/dist/languageService/completionProvider.d.ts +5 -3
  151. package/dist/languageService/completionProvider.js +39 -38
  152. package/dist/languageService/completionProvider.js.map +1 -1
  153. package/dist/languageService/completionProviderUtils.d.ts +1 -1
  154. package/dist/languageService/completionProviderUtils.js +3 -3
  155. package/dist/languageService/completionProviderUtils.js.map +1 -1
  156. package/dist/languageService/fileWatcherDynamicFeature.js +2 -2
  157. package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
  158. package/dist/languageService/hoverProvider.js +3 -3
  159. package/dist/languageService/hoverProvider.js.map +1 -1
  160. package/dist/languageService/referencesProvider.js +2 -2
  161. package/dist/languageService/signatureHelpProvider.js +1 -1
  162. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  163. package/dist/languageService/tooltipUtils.js +3 -3
  164. package/dist/languageService/tooltipUtils.js.map +1 -1
  165. package/dist/localization/localize.d.ts +5 -0
  166. package/dist/localization/localize.js +6 -0
  167. package/dist/localization/localize.js.map +1 -1
  168. package/dist/localization/package.nls.cs.json +5 -1
  169. package/dist/localization/package.nls.de.json +5 -1
  170. package/dist/localization/package.nls.en-us.json +5 -0
  171. package/dist/localization/package.nls.es.json +5 -1
  172. package/dist/localization/package.nls.fr.json +5 -1
  173. package/dist/localization/package.nls.it.json +5 -1
  174. package/dist/localization/package.nls.ja.json +5 -1
  175. package/dist/localization/package.nls.ko.json +5 -1
  176. package/dist/localization/package.nls.pl.json +5 -1
  177. package/dist/localization/package.nls.pt-br.json +5 -1
  178. package/dist/localization/package.nls.qps-ploc.json +5 -1
  179. package/dist/localization/package.nls.ru.json +5 -1
  180. package/dist/localization/package.nls.tr.json +5 -1
  181. package/dist/localization/package.nls.zh-cn.json +5 -1
  182. package/dist/localization/package.nls.zh-tw.json +5 -1
  183. package/dist/parser/parseNodes.d.ts +9 -9
  184. package/dist/parser/parseNodes.js +20 -20
  185. package/dist/parser/parseNodes.js.map +1 -1
  186. package/dist/parser/parser.js +30 -30
  187. package/dist/parser/parser.js.map +1 -1
  188. package/dist/tests/checker.test.js +12 -4
  189. package/dist/tests/checker.test.js.map +1 -1
  190. package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js +4 -21
  191. package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js.map +1 -1
  192. package/dist/tests/fourslash/signature.complicated.fourslash.js +1 -1
  193. package/dist/tests/fourslash/signature.complicated.fourslash.js.map +1 -1
  194. package/dist/tests/harness/fourslash/fourSlashParser.js +1 -1
  195. package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
  196. package/dist/tests/harness/fourslash/testStateUtils.js +2 -2
  197. package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
  198. package/dist/tests/harness/vfs/filesystem.d.ts +0 -1
  199. package/dist/tests/harness/vfs/filesystem.js +0 -4
  200. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  201. package/dist/tests/importResolver.test.js +62 -15
  202. package/dist/tests/importResolver.test.js.map +1 -1
  203. package/dist/tests/lsp/languageServerTestUtils.js +1 -1
  204. package/dist/tests/lsp/languageServerTestUtils.js.map +1 -1
  205. package/dist/tests/typeEvaluator1.test.js +1 -1
  206. package/dist/tests/typeEvaluator2.test.js +12 -0
  207. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  208. package/dist/tests/typeEvaluator3.test.js +5 -1
  209. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  210. package/dist/tests/typeEvaluator4.test.js +10 -2
  211. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  212. package/dist/tests/typeEvaluator5.test.js +9 -3
  213. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  214. package/dist/tests/typeEvaluator6.test.js +72 -60
  215. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  216. package/dist/tests/typeEvaluator7.test.js +6 -2
  217. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  218. package/dist/tests/typeEvaluator8.test.js +4 -0
  219. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  220. package/dist/tests/typePrinter.test.js +13 -18
  221. package/dist/tests/typePrinter.test.js.map +1 -1
  222. package/dist/workspaceFactory.d.ts +3 -2
  223. package/dist/workspaceFactory.js +15 -2
  224. package/dist/workspaceFactory.js.map +1 -1
  225. package/package.json +1 -1
  226. package/dist/analyzer/typeVarContext.d.ts +0 -60
  227. package/dist/analyzer/typeVarContext.js +0 -392
  228. package/dist/analyzer/typeVarContext.js.map +0 -1
@@ -38,6 +38,7 @@ const debug_1 = require("../common/debug");
38
38
  const parseNodes_1 = require("../parser/parseNodes");
39
39
  const analyzerNodeInfo_1 = require("./analyzerNodeInfo");
40
40
  const constraintSolver_1 = require("./constraintSolver");
41
+ const constraintTracker_1 = require("./constraintTracker");
41
42
  const enums_1 = require("./enums");
42
43
  const ParseTreeUtils = __importStar(require("./parseTreeUtils"));
43
44
  const scopeUtils_1 = require("./scopeUtils");
@@ -45,7 +46,6 @@ const symbol_1 = require("./symbol");
45
46
  const typedDicts_1 = require("./typedDicts");
46
47
  const types_1 = require("./types");
47
48
  const typeUtils_1 = require("./typeUtils");
48
- const typeVarContext_1 = require("./typeVarContext");
49
49
  // Given a reference expression and a test expression, returns a callback that
50
50
  // can be used to narrow the type described by the reference expression.
51
51
  // If the specified flow node is not associated with the test expression,
@@ -90,7 +90,7 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
90
90
  ParseTreeUtils.isMatchingExpression(reference, leftExpression.d.leftExpr) &&
91
91
  leftExpression.d.items.length === 1 &&
92
92
  !leftExpression.d.trailingComma &&
93
- leftExpression.d.items[0].d.argCategory === 0 /* ArgumentCategory.Simple */ &&
93
+ leftExpression.d.items[0].d.argCategory === 0 /* ArgCategory.Simple */ &&
94
94
  !leftExpression.d.items[0].d.name &&
95
95
  leftExpression.d.items[0].d.valueExpr.nodeType === 40 /* ParseNodeType.Number */ &&
96
96
  leftExpression.d.items[0].d.valueExpr.d.isInteger &&
@@ -126,7 +126,7 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
126
126
  // Look for "type(X) is Y", "type(X) is not Y", "type(X) == Y" or "type(X) != Y".
127
127
  if (testExpression.d.leftExpr.nodeType === 9 /* ParseNodeType.Call */) {
128
128
  if (testExpression.d.leftExpr.d.args.length === 1 &&
129
- testExpression.d.leftExpr.d.args[0].d.argCategory === 0 /* ArgumentCategory.Simple */) {
129
+ testExpression.d.leftExpr.d.args[0].d.argCategory === 0 /* ArgCategory.Simple */) {
130
130
  const arg0Expr = testExpression.d.leftExpr.d.args[0].d.valueExpr;
131
131
  if (ParseTreeUtils.isMatchingExpression(reference, arg0Expr)) {
132
132
  const callType = evaluator.getTypeOfExpression(testExpression.d.leftExpr.d.leftExpr, 2 /* EvalFlags.CallBaseDefaults */).type;
@@ -175,7 +175,7 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
175
175
  if (testExpression.d.leftExpr.nodeType === 27 /* ParseNodeType.Index */ &&
176
176
  testExpression.d.leftExpr.d.items.length === 1 &&
177
177
  !testExpression.d.leftExpr.d.trailingComma &&
178
- testExpression.d.leftExpr.d.items[0].d.argCategory === 0 /* ArgumentCategory.Simple */ &&
178
+ testExpression.d.leftExpr.d.items[0].d.argCategory === 0 /* ArgCategory.Simple */ &&
179
179
  ParseTreeUtils.isMatchingExpression(reference, testExpression.d.leftExpr.d.leftExpr)) {
180
180
  const indexTypeResult = evaluator.getTypeOfExpression(testExpression.d.leftExpr.d.items[0].d.valueExpr);
181
181
  const indexType = indexTypeResult.type;
@@ -241,7 +241,7 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
241
241
  if (testExpression.d.leftExpr.nodeType === 27 /* ParseNodeType.Index */ &&
242
242
  testExpression.d.leftExpr.d.items.length === 1 &&
243
243
  !testExpression.d.leftExpr.d.trailingComma &&
244
- testExpression.d.leftExpr.d.items[0].d.argCategory === 0 /* ArgumentCategory.Simple */ &&
244
+ testExpression.d.leftExpr.d.items[0].d.argCategory === 0 /* ArgCategory.Simple */ &&
245
245
  ParseTreeUtils.isMatchingExpression(reference, testExpression.d.leftExpr.d.leftExpr)) {
246
246
  const indexTypeResult = evaluator.getTypeOfExpression(testExpression.d.leftExpr.d.items[0].d.valueExpr);
247
247
  const indexType = indexTypeResult.type;
@@ -489,10 +489,11 @@ function getTypeNarrowingCallback(evaluator, reference, testExpression, isPositi
489
489
  const functionReturnTypeResult = evaluator.getTypeOfExpression(testExpression);
490
490
  const functionReturnType = functionReturnTypeResult.type;
491
491
  if ((0, types_1.isClassInstance)(functionReturnType) &&
492
- types_1.ClassType.isBuiltIn(functionReturnType, 'bool') &&
493
- functionReturnType.priv.typeGuardType) {
494
- const isStrictTypeGuard = !!functionReturnType.priv.isStrictTypeGuard;
495
- const typeGuardType = functionReturnType.priv.typeGuardType;
492
+ types_1.ClassType.isBuiltIn(functionReturnType, ['TypeGuard', 'TypeIs']) &&
493
+ functionReturnType.priv.typeArgs &&
494
+ functionReturnType.priv.typeArgs.length > 0) {
495
+ const isStrictTypeGuard = types_1.ClassType.isBuiltIn(functionReturnType, 'TypeIs');
496
+ const typeGuardType = functionReturnType.priv.typeArgs[0];
496
497
  const isIncomplete = !!callTypeResult.isIncomplete || !!functionReturnTypeResult.isIncomplete;
497
498
  return (type) => {
498
499
  return {
@@ -596,14 +597,14 @@ function getDeclsForLocalVar(evaluator, name, reachableFrom, requireUnique) {
596
597
  return undefined;
597
598
  }
598
599
  if (decls.length === 0 ||
599
- decls.some((decl) => decl.type !== 1 /* DeclarationType.Variable */ && decl.type !== 2 /* DeclarationType.Parameter */)) {
600
+ decls.some((decl) => decl.type !== 1 /* DeclarationType.Variable */ && decl.type !== 2 /* DeclarationType.Param */)) {
600
601
  return undefined;
601
602
  }
602
603
  // If there are any assignments within different scopes (e.g. via a "global" or
603
604
  // "nonlocal" reference), don't consider it a local variable.
604
605
  let prevDeclScope;
605
606
  if (decls.some((decl) => {
606
- const nodeToConsider = decl.type === 2 /* DeclarationType.Parameter */ ? decl.node.d.name : decl.node;
607
+ const nodeToConsider = decl.type === 2 /* DeclarationType.Param */ ? decl.node.d.name : decl.node;
607
608
  const declScopeNode = ParseTreeUtils.getExecutionScopeNode(nodeToConsider);
608
609
  if (prevDeclScope && declScopeNode !== prevDeclScope) {
609
610
  return true;
@@ -624,7 +625,17 @@ function narrowTypeForUserDefinedTypeGuard(evaluator, type, typeGuardType, isPos
624
625
  // For non-strict type guards, always narrow to the typeGuardType
625
626
  // in the positive case and don't narrow in the negative case.
626
627
  if (!isStrictTypeGuard) {
627
- return isPositiveTest ? typeGuardType : type;
628
+ let result = type;
629
+ if (isPositiveTest) {
630
+ result = typeGuardType;
631
+ // If the type guard is a non-constrained TypeVar, add a
632
+ // condition to the resulting type.
633
+ if ((0, types_1.isTypeVar)(type) && !(0, types_1.isParamSpec)(type) && !types_1.TypeVarType.hasConstraints(type)) {
634
+ result = (0, typeUtils_1.addConditionToType)(result, [{ typeVar: type, constraintIndex: 0 }]);
635
+ }
636
+ return result;
637
+ }
638
+ return result;
628
639
  }
629
640
  const filterTypes = [];
630
641
  (0, typeUtils_1.doForEachSubtype)(typeGuardType, (typeGuardSubtype) => {
@@ -655,14 +666,14 @@ function narrowTypeForTruthiness(evaluator, type, isPositiveTest) {
655
666
  function narrowTupleTypeForIsNone(evaluator, type, isPositiveTest, indexValue) {
656
667
  return evaluator.mapSubtypesExpandTypeVars(type, /* options */ undefined, (subtype) => {
657
668
  const tupleType = (0, typeUtils_1.getSpecializedTupleType)(subtype);
658
- if (!tupleType || (0, typeUtils_1.isUnboundedTupleClass)(tupleType) || !tupleType.priv.tupleTypeArguments) {
669
+ if (!tupleType || (0, typeUtils_1.isUnboundedTupleClass)(tupleType) || !tupleType.priv.tupleTypeArgs) {
659
670
  return subtype;
660
671
  }
661
- const tupleLength = tupleType.priv.tupleTypeArguments.length;
672
+ const tupleLength = tupleType.priv.tupleTypeArgs.length;
662
673
  if (indexValue < 0 || indexValue >= tupleLength) {
663
674
  return subtype;
664
675
  }
665
- const typeOfEntry = evaluator.makeTopLevelTypeVarsConcrete(tupleType.priv.tupleTypeArguments[indexValue].type);
676
+ const typeOfEntry = evaluator.makeTopLevelTypeVarsConcrete(tupleType.priv.tupleTypeArgs[indexValue].type);
666
677
  if (isPositiveTest) {
667
678
  if (!evaluator.assignType(typeOfEntry, evaluator.getNoneType())) {
668
679
  return undefined;
@@ -686,32 +697,40 @@ function narrowTypeForIsNone(evaluator, type, isPositiveTest) {
686
697
  /* options */ undefined, (subtype, unexpandedSubtype) => {
687
698
  var _a;
688
699
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
689
- // We need to assume that "Any" is always both None and not None,
690
- // so it matches regardless of whether the test is positive or negative.
700
+ // Assume that "Any" is always both None and not None, so it matches
701
+ // regardless of whether the test is positive or negative.
691
702
  return subtype;
692
703
  }
693
- // If this is a TypeVar that isn't constrained, use the unexpanded
694
- // TypeVar. For all other cases (including constrained TypeVars),
695
- // use the expanded subtype.
696
- const adjustedSubtype = (0, types_1.isTypeVar)(unexpandedSubtype) && unexpandedSubtype.shared.constraints.length === 0
697
- ? unexpandedSubtype
698
- : subtype;
699
- // See if it's a match for object.
700
- if ((0, types_1.isClassInstance)(subtype) && types_1.ClassType.isBuiltIn(subtype, 'object')) {
704
+ let useExpandedSubtype = false;
705
+ if ((0, types_1.isTypeVar)(unexpandedSubtype) && !types_1.TypeVarType.isSelf(unexpandedSubtype)) {
706
+ // If the TypeVar has value constraints and one or more of them
707
+ // are possibly compatible with None, use the expanded subtypes.
708
+ if (unexpandedSubtype.shared.constraints.some((constraint) => {
709
+ return evaluator.assignType(constraint, evaluator.getNoneType());
710
+ })) {
711
+ useExpandedSubtype = true;
712
+ }
713
+ // If the TypeVar han an explicit bound that is possibly compatible
714
+ // with None (e.g. "T: int | None"), use the expanded subtypes.
715
+ if (unexpandedSubtype.shared.boundType &&
716
+ evaluator.assignType(unexpandedSubtype.shared.boundType, evaluator.getNoneType())) {
717
+ useExpandedSubtype = true;
718
+ }
719
+ }
720
+ const adjustedSubtype = useExpandedSubtype ? subtype : unexpandedSubtype;
721
+ // Is it an exact match for None?
722
+ if ((0, typeUtils_1.isNoneInstance)(subtype)) {
723
+ resultIncludesNoneSubtype = true;
724
+ return isPositiveTest ? adjustedSubtype : undefined;
725
+ }
726
+ // Is it potentially None?
727
+ if (evaluator.assignType(subtype, evaluator.getNoneType())) {
701
728
  resultIncludesNoneSubtype = true;
702
729
  return isPositiveTest
703
730
  ? (0, typeUtils_1.addConditionToType)(evaluator.getNoneType(), (_a = subtype.props) === null || _a === void 0 ? void 0 : _a.condition)
704
731
  : adjustedSubtype;
705
732
  }
706
- // See if it's a match for None.
707
- if ((0, typeUtils_1.isNoneInstance)(subtype) === isPositiveTest) {
708
- resultIncludesNoneSubtype = true;
709
- if ((0, types_1.isTypeVar)(adjustedSubtype) && adjustedSubtype.shared.isSynthesizedSelf) {
710
- return adjustedSubtype;
711
- }
712
- return subtype;
713
- }
714
- return undefined;
733
+ return isPositiveTest ? undefined : adjustedSubtype;
715
734
  });
716
735
  // If this is a positive test and the result is a union that includes None,
717
736
  // we can eliminate all the non-None subtypes include Any or Unknown. If some
@@ -738,7 +757,7 @@ function narrowTypeForIsEllipsis(evaluator, type, isPositiveTest) {
738
757
  // If this is a TypeVar that isn't constrained, use the unexpanded
739
758
  // TypeVar. For all other cases (including constrained TypeVars),
740
759
  // use the expanded subtype.
741
- const adjustedSubtype = (0, types_1.isTypeVar)(unexpandedSubtype) && unexpandedSubtype.shared.constraints.length === 0
760
+ const adjustedSubtype = (0, types_1.isTypeVar)(unexpandedSubtype) && !types_1.TypeVarType.hasConstraints(unexpandedSubtype)
742
761
  ? unexpandedSubtype
743
762
  : subtype;
744
763
  // See if it's a match for object.
@@ -781,8 +800,8 @@ function getIsInstanceClassTypes(evaluator, argType) {
781
800
  }
782
801
  else if ((0, types_1.isFunction)(subtype) &&
783
802
  subtype.shared.parameters.length === 2 &&
784
- subtype.shared.parameters[0].category === 1 /* ParameterCategory.ArgsList */ &&
785
- subtype.shared.parameters[1].category === 2 /* ParameterCategory.KwargsDict */) {
803
+ subtype.shared.parameters[0].category === 1 /* ParamCategory.ArgsList */ &&
804
+ subtype.shared.parameters[1].category === 2 /* ParamCategory.KwargsDict */) {
786
805
  classTypeList.push(subtype);
787
806
  }
788
807
  else {
@@ -795,8 +814,8 @@ function getIsInstanceClassTypes(evaluator, argType) {
795
814
  return;
796
815
  }
797
816
  if ((0, types_1.isClass)(type) && types_1.TypeBase.isInstance(type) && (0, typeUtils_1.isTupleClass)(type)) {
798
- if (type.priv.tupleTypeArguments) {
799
- type.priv.tupleTypeArguments.forEach((tupleEntry) => {
817
+ if (type.priv.tupleTypeArgs) {
818
+ type.priv.tupleTypeArgs.forEach((tupleEntry) => {
800
819
  addClassTypesRecursive(tupleEntry.type, recursionCount + 1);
801
820
  });
802
821
  }
@@ -826,8 +845,11 @@ function isIsinstanceFilterSuperclass(evaluator, varType, concreteVarType, filte
826
845
  return true;
827
846
  }
828
847
  if (isInstanceCheck) {
848
+ // We convert both types to instances in case they are protocol
849
+ // classes. A protocol class isn't allowed to be assigned to
850
+ // type[T], so this would otherwise fail.
829
851
  if (types_1.ClassType.isProtocolClass(concreteFilterType) &&
830
- evaluator.assignType(concreteFilterType, concreteVarType)) {
852
+ evaluator.assignType(types_1.ClassType.cloneAsInstance(concreteFilterType), types_1.ClassType.cloneAsInstance(concreteVarType))) {
831
853
  return true;
832
854
  }
833
855
  }
@@ -845,7 +867,11 @@ function isIsinstanceFilterSubclass(evaluator, varType, concreteFilterType, isIn
845
867
  return true;
846
868
  }
847
869
  if (isInstanceCheck) {
848
- if (types_1.ClassType.isProtocolClass(varType) && evaluator.assignType(varType, concreteFilterType)) {
870
+ // We convert both types to instances in case they are protocol
871
+ // classes. A protocol class isn't allowed to be assigned to
872
+ // type[T], so this would otherwise fail.
873
+ if (types_1.ClassType.isProtocolClass(varType) &&
874
+ evaluator.assignType(types_1.ClassType.cloneAsInstance(varType), types_1.ClassType.cloneAsInstance(concreteFilterType))) {
849
875
  return true;
850
876
  }
851
877
  }
@@ -894,10 +920,8 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
894
920
  // If the class was implicitly specialized (e.g. because its type
895
921
  // parameters have default values), replace the default type arguments
896
922
  // with Unknown.
897
- if (concreteFilterType.priv.typeArguments && !concreteFilterType.priv.isTypeArgumentExplicit) {
898
- concreteFilterType = (0, typeUtils_1.specializeWithUnknownTypeArgs)(types_1.ClassType.cloneForSpecialization(concreteFilterType,
899
- /* typeArguments */ undefined,
900
- /* isTypeArgumentExplicit */ false), evaluator.getTupleClassType());
923
+ if (concreteFilterType.priv.typeArgs && !concreteFilterType.priv.isTypeArgExplicit) {
924
+ concreteFilterType = (0, typeUtils_1.specializeWithUnknownTypeArgs)(types_1.ClassType.specialize(concreteFilterType, /* typeArgs */ undefined), evaluator.getTupleClassType());
901
925
  }
902
926
  filterIsSuperclass = isIsinstanceFilterSuperclass(evaluator, varType, concreteVarType, filterType, concreteFilterType, isInstanceCheck);
903
927
  filterIsSubclass = isIsinstanceFilterSubclass(evaluator, concreteVarType, concreteFilterType, isInstanceCheck);
@@ -925,7 +949,7 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
925
949
  // If the variable type is a subclass of the isinstance filter,
926
950
  // we haven't learned anything new about the variable type.
927
951
  // If the varType is a Self or type[Self], retain the unnarrowedType.
928
- if ((0, types_1.isTypeVar)(varType) && varType.shared.isSynthesizedSelf) {
952
+ if ((0, types_1.isTypeVar)(varType) && types_1.TypeVarType.isSelf(varType)) {
929
953
  filteredTypes.push((0, typeUtils_1.addConditionToType)(varType, conditions));
930
954
  }
931
955
  else {
@@ -933,10 +957,10 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
933
957
  }
934
958
  }
935
959
  else if (filterIsSubclass) {
936
- if (evaluator.assignType(concreteVarType, concreteFilterType,
960
+ if (evaluator.assignType((0, typeUtils_1.convertToInstance)(concreteVarType), (0, typeUtils_1.convertToInstance)(concreteFilterType),
937
961
  /* diag */ undefined,
938
- /* destTypeVarContext */ undefined,
939
- /* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */ | 16384 /* AssignTypeFlags.AllowIsinstanceSpecialForms */)) {
962
+ /* destConstraints */ undefined,
963
+ /* srcConstraints */ undefined, 16384 /* AssignTypeFlags.AllowIsinstanceSpecialForms */)) {
940
964
  // If the variable type is a superclass of the isinstance
941
965
  // filter, we can narrow the type to the subclass.
942
966
  let specializedFilterType = filterType;
@@ -944,20 +968,20 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
944
968
  // important because a specialized version of the filter cannot
945
969
  // be passed to isinstance or issubclass.
946
970
  if ((0, types_1.isClass)(filterType)) {
947
- if (types_1.ClassType.isSpecialBuiltIn(filterType) ||
948
- filterType.shared.typeParameters.length > 0) {
949
- if (!filterType.priv.isTypeArgumentExplicit &&
971
+ if (types_1.ClassType.isSpecialBuiltIn(filterType) || filterType.shared.typeParams.length > 0) {
972
+ if (!filterType.priv.isTypeArgExplicit &&
950
973
  !types_1.ClassType.isSameGenericClass(concreteVarType, filterType)) {
951
- const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(filterType));
952
- const unspecializedFilterType = types_1.ClassType.cloneForSpecialization(filterType,
953
- /* typeArguments */ undefined,
954
- /* isTypeArgumentExplicit */ false);
955
- if ((0, constraintSolver_1.addConstraintsForExpectedType)(evaluator, unspecializedFilterType, concreteVarType, typeVarContext,
974
+ const constraints = new constraintTracker_1.ConstraintTracker();
975
+ const unspecializedFilterType = types_1.ClassType.specialize(filterType,
976
+ /* typeArg */ undefined);
977
+ if ((0, constraintSolver_1.addConstraintsForExpectedType)(evaluator, (0, typeUtils_1.convertToInstance)(unspecializedFilterType), (0, typeUtils_1.convertToInstance)(concreteVarType), constraints,
956
978
  /* liveTypeVarScopes */ undefined, errorNode.start)) {
957
- specializedFilterType = (0, typeUtils_1.applySolvedTypeVars)(unspecializedFilterType, typeVarContext, {
958
- unknownIfNotFound: true,
959
- useUnknownOverDefault: true,
960
- tupleClassType: evaluator.getTupleClassType(),
979
+ specializedFilterType = evaluator.solveAndApplyConstraints(unspecializedFilterType, constraints, {
980
+ replaceUnsolved: {
981
+ scopeIds: (0, typeUtils_1.getTypeVarScopeIds)(filterType),
982
+ useUnknown: true,
983
+ tupleClassType: evaluator.getTupleClassType(),
984
+ },
961
985
  });
962
986
  }
963
987
  }
@@ -966,6 +990,16 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
966
990
  filteredTypes.push((0, typeUtils_1.addConditionToType)(specializedFilterType, conditions));
967
991
  }
968
992
  }
993
+ else if (types_1.ClassType.isSameGenericClass(concreteVarType, concreteFilterType)) {
994
+ // Don't attempt to narrow in this case.
995
+ if (((_a = concreteVarType.priv) === null || _a === void 0 ? void 0 : _a.literalValue) === undefined &&
996
+ ((_b = concreteFilterType.priv) === null || _b === void 0 ? void 0 : _b.literalValue) === undefined) {
997
+ const intersection = intersectSameClassType(evaluator, concreteVarType, concreteFilterType);
998
+ filteredTypes.push(intersection !== null && intersection !== void 0 ? intersection : varType);
999
+ // Don't attempt to narrow in the negative direction.
1000
+ isClassRelationshipIndeterminate = true;
1001
+ }
1002
+ }
969
1003
  else if (allowIntersections &&
970
1004
  !types_1.ClassType.isFinal(concreteVarType) &&
971
1005
  !types_1.ClassType.isFinal(concreteFilterType)) {
@@ -974,39 +1008,16 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
974
1008
  // be a mix-in class used with the other. In this case, we'll
975
1009
  // synthesize a new class type that represents an intersection of
976
1010
  // the two types.
977
- const className = `<subclass of ${concreteVarType.shared.name} and ${concreteFilterType.shared.name}>`;
978
- const fileInfo = (0, analyzerNodeInfo_1.getFileInfo)(errorNode);
979
- // The effective metaclass of the intersection is the narrower of the two metaclasses.
980
- let effectiveMetaclass = concreteVarType.shared.effectiveMetaclass;
981
- if (concreteFilterType.shared.effectiveMetaclass) {
982
- if (!effectiveMetaclass ||
983
- evaluator.assignType(effectiveMetaclass, concreteFilterType.shared.effectiveMetaclass)) {
984
- effectiveMetaclass = concreteFilterType.shared.effectiveMetaclass;
985
- }
986
- }
987
- let newClassType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 0 /* ClassTypeFlags.None */, ParseTreeUtils.getTypeSourceId(errorNode),
988
- /* declaredMetaclass */ undefined, effectiveMetaclass, concreteVarType.shared.docString);
989
- newClassType.shared.baseClasses = [
990
- types_1.ClassType.cloneAsInstantiable(concreteVarType),
991
- concreteFilterType,
992
- ];
993
- (0, typeUtils_1.computeMroLinearization)(newClassType);
994
- newClassType = (0, typeUtils_1.addConditionToType)(newClassType, (_a = concreteFilterType.props) === null || _a === void 0 ? void 0 : _a.condition);
995
- if ((0, types_1.isTypeVar)(varType) &&
996
- !varType.shared.isParamSpec &&
997
- varType.shared.constraints.length === 0) {
998
- newClassType = (0, typeUtils_1.addConditionToType)(newClassType, [
999
- { typeVar: varType, constraintIndex: 0 },
1000
- ]);
1001
- }
1002
- let newClassInstanceType = types_1.ClassType.cloneAsInstance(newClassType);
1003
- if ((_b = concreteVarType.props) === null || _b === void 0 ? void 0 : _b.condition) {
1004
- newClassInstanceType = (0, typeUtils_1.addConditionToType)(newClassInstanceType, (_c = concreteVarType.props) === null || _c === void 0 ? void 0 : _c.condition);
1011
+ let newClassType = evaluator.createSubclass(errorNode, concreteVarType, concreteFilterType);
1012
+ if ((0, types_1.isTypeVar)(varType) && !(0, types_1.isParamSpec)(varType) && !types_1.TypeVarType.hasConstraints(varType)) {
1013
+ newClassType = (0, typeUtils_1.addConditionToType)(newClassType, [{ typeVar: varType, constraintIndex: 0 }]);
1005
1014
  }
1015
+ let newClassObjType = types_1.ClassType.cloneAsInstance(newClassType);
1016
+ newClassObjType = (0, typeUtils_1.addConditionToType)(newClassObjType, (_c = concreteVarType.props) === null || _c === void 0 ? void 0 : _c.condition);
1006
1017
  // If this is a issubclass check, we do a double conversion from instantiable
1007
1018
  // to instance back to instantiable to make sure that the includeSubclasses flag
1008
1019
  // gets cleared.
1009
- filteredTypes.push(isInstanceCheck ? newClassInstanceType : types_1.ClassType.cloneAsInstantiable(newClassInstanceType));
1020
+ filteredTypes.push(isInstanceCheck ? newClassObjType : types_1.ClassType.cloneAsInstantiable(newClassObjType));
1010
1021
  }
1011
1022
  }
1012
1023
  }
@@ -1075,8 +1086,8 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
1075
1086
  }
1076
1087
  else if (evaluator.assignType(concreteVarType, filterType,
1077
1088
  /* diag */ undefined,
1078
- /* destTypeVarContext */ undefined,
1079
- /* srcTypeVarContext */ undefined, 16384 /* AssignTypeFlags.AllowIsinstanceSpecialForms */)) {
1089
+ /* destConstraints */ undefined,
1090
+ /* srcConstraints */ undefined, 16384 /* AssignTypeFlags.AllowIsinstanceSpecialForms */)) {
1080
1091
  if (isPositiveTest) {
1081
1092
  filteredTypes.push(filterType);
1082
1093
  }
@@ -1119,7 +1130,7 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
1119
1130
  // This will normally be treated as type[Any], which is compatible with
1120
1131
  // any metaclass, but we specifically want to treat type as the class
1121
1132
  // type[object] in this case.
1122
- if (types_1.ClassType.isBuiltIn(filterMetaclass, 'type') && !filterMetaclass.priv.isTypeArgumentExplicit) {
1133
+ if (types_1.ClassType.isBuiltIn(filterMetaclass, 'type') && !filterMetaclass.priv.isTypeArgExplicit) {
1123
1134
  if (!types_1.ClassType.isBuiltIn(metaclassType, 'type')) {
1124
1135
  isMetaclassOverlap = false;
1125
1136
  }
@@ -1164,10 +1175,7 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
1164
1175
  if (isPositiveTest) {
1165
1176
  for (const filterType of filterTypes) {
1166
1177
  const concreteFilterType = evaluator.makeTopLevelTypeVarsConcrete(filterType);
1167
- if (evaluator.assignType(varType, (0, typeUtils_1.convertToInstance)(concreteFilterType),
1168
- /* diag */ undefined,
1169
- /* destTypeVarContext */ undefined,
1170
- /* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */)) {
1178
+ if (evaluator.assignType(varType, (0, typeUtils_1.convertToInstance)(concreteFilterType))) {
1171
1179
  // If the filter type is a Callable, use the original type. If the
1172
1180
  // filter type is a callback protocol, use the filter type.
1173
1181
  if ((0, types_1.isFunction)(filterType)) {
@@ -1254,8 +1262,9 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
1254
1262
  if ((0, types_1.isInstantiableClass)(subtype) || isSubtypeMetaclass) {
1255
1263
  // Handle the special case of isinstance(x, metaclass).
1256
1264
  const includesMetaclassType = filterTypes.some((classType) => (0, typeUtils_1.isInstantiableMetaclass)(classType));
1265
+ const includesObject = filterTypes.some((classType) => (0, types_1.isInstantiableClass)(classType) && types_1.ClassType.isBuiltIn(classType, 'object'));
1257
1266
  if (isPositiveTest) {
1258
- return includesMetaclassType ? negativeFallback : undefined;
1267
+ return includesMetaclassType || includesObject ? negativeFallback : undefined;
1259
1268
  }
1260
1269
  else {
1261
1270
  return includesMetaclassType ? undefined : negativeFallback;
@@ -1297,6 +1306,35 @@ function narrowTypeForIsInstanceInternal(evaluator, type, filterTypes, isInstanc
1297
1306
  }
1298
1307
  return filteredType;
1299
1308
  }
1309
+ // This function assumes that the caller has already verified that the two
1310
+ // types are the same class and are not literals. It also assumes that the
1311
+ // caller has verified that type1 is not assignable to type2 or vice versa.
1312
+ // Returns undefined if there is no intersection between the two types.
1313
+ function intersectSameClassType(evaluator, type1, type2) {
1314
+ var _a, _b;
1315
+ (0, debug_1.assert)((0, types_1.isInstantiableClass)(type1) && (0, types_1.isInstantiableClass)(type2));
1316
+ (0, debug_1.assert)(types_1.ClassType.isSameGenericClass(type1, type2));
1317
+ (0, debug_1.assert)(((_a = type1.priv) === null || _a === void 0 ? void 0 : _a.literalValue) === undefined);
1318
+ (0, debug_1.assert)(((_b = type2.priv) === null || _b === void 0 ? void 0 : _b.literalValue) === undefined);
1319
+ // Handle tuples specially.
1320
+ if (types_1.ClassType.isBuiltIn(type1, 'tuple')) {
1321
+ return intersectTupleTypes(type1, type1);
1322
+ }
1323
+ // Indicate that there is no intersection.
1324
+ return undefined;
1325
+ }
1326
+ function intersectTupleTypes(type1, type2) {
1327
+ var _a, _b;
1328
+ if (!type2.priv.tupleTypeArgs || (0, typeUtils_1.isTupleGradualForm)(type2)) {
1329
+ return (0, typeUtils_1.addConditionToType)(type1, (_a = type2.props) === null || _a === void 0 ? void 0 : _a.condition);
1330
+ }
1331
+ if (!type1.priv.tupleTypeArgs || (0, typeUtils_1.isTupleGradualForm)(type1)) {
1332
+ return (0, typeUtils_1.addConditionToType)(type2, (_b = type1.props) === null || _b === void 0 ? void 0 : _b.condition);
1333
+ }
1334
+ // For now, don't attempt to narrow in this case.
1335
+ // TODO - add more sophisticated logic here.
1336
+ return undefined;
1337
+ }
1300
1338
  // Attempts to narrow a union of tuples based on their known length.
1301
1339
  function narrowTypeForTupleLength(evaluator, referenceType, lengthValue, isPositiveTest, isLessThanCheck) {
1302
1340
  return (0, typeUtils_1.mapSubtypes)(referenceType, (subtype) => {
@@ -1304,23 +1342,23 @@ function narrowTypeForTupleLength(evaluator, referenceType, lengthValue, isPosit
1304
1342
  // If it's not a tuple, we can't narrow it.
1305
1343
  if (!(0, types_1.isClassInstance)(concreteSubtype) ||
1306
1344
  !(0, typeUtils_1.isTupleClass)(concreteSubtype) ||
1307
- !concreteSubtype.priv.tupleTypeArguments) {
1345
+ !concreteSubtype.priv.tupleTypeArgs) {
1308
1346
  return subtype;
1309
1347
  }
1310
- // If the tuple contains a variadic TypeVar, we can't narrow it.
1311
- if (concreteSubtype.priv.tupleTypeArguments.some((typeArg) => (0, types_1.isUnpackedVariadicTypeVar)(typeArg.type))) {
1348
+ // If the tuple contains a TypeVarTuple, we can't narrow it.
1349
+ if (concreteSubtype.priv.tupleTypeArgs.some((typeArg) => (0, types_1.isUnpackedTypeVarTuple)(typeArg.type))) {
1312
1350
  return subtype;
1313
1351
  }
1314
1352
  // If the tuple contains no unbounded elements, then we know its length exactly.
1315
- if (!concreteSubtype.priv.tupleTypeArguments.some((typeArg) => typeArg.isUnbounded)) {
1353
+ if (!concreteSubtype.priv.tupleTypeArgs.some((typeArg) => typeArg.isUnbounded)) {
1316
1354
  const tupleLengthMatches = isLessThanCheck
1317
- ? concreteSubtype.priv.tupleTypeArguments.length < lengthValue
1318
- : concreteSubtype.priv.tupleTypeArguments.length === lengthValue;
1355
+ ? concreteSubtype.priv.tupleTypeArgs.length < lengthValue
1356
+ : concreteSubtype.priv.tupleTypeArgs.length === lengthValue;
1319
1357
  return tupleLengthMatches === isPositiveTest ? subtype : undefined;
1320
1358
  }
1321
1359
  // The tuple contains a "...". We'll expand this into as many elements as
1322
1360
  // necessary to match the lengthValue.
1323
- const elementsToAdd = lengthValue - concreteSubtype.priv.tupleTypeArguments.length + 1;
1361
+ const elementsToAdd = lengthValue - concreteSubtype.priv.tupleTypeArgs.length + 1;
1324
1362
  if (!isLessThanCheck) {
1325
1363
  // If the specified length is smaller than the minimum length of this tuple,
1326
1364
  // we can rule it out for a positive test and rule it in for a negative test.
@@ -1360,7 +1398,7 @@ function narrowTypeForTupleLength(evaluator, referenceType, lengthValue, isPosit
1360
1398
  // to) the unbounded element.
1361
1399
  function expandUnboundedTupleElement(tupleType, elementsToAdd, keepUnbounded) {
1362
1400
  const tupleTypeArgs = [];
1363
- tupleType.priv.tupleTypeArguments.forEach((typeArg) => {
1401
+ tupleType.priv.tupleTypeArgs.forEach((typeArg) => {
1364
1402
  if (!typeArg.isUnbounded) {
1365
1403
  tupleTypeArgs.push(typeArg);
1366
1404
  }
@@ -1388,13 +1426,13 @@ function narrowTypeForContainerType(evaluator, referenceType, containerType, isP
1388
1426
  // with a known length.
1389
1427
  if (!(0, types_1.isClassInstance)(containerType) ||
1390
1428
  !types_1.ClassType.isBuiltIn(containerType, 'tuple') ||
1391
- !containerType.priv.tupleTypeArguments) {
1429
+ !containerType.priv.tupleTypeArgs) {
1392
1430
  return referenceType;
1393
1431
  }
1394
1432
  // Determine which tuple types can be eliminated. Only "None" and
1395
1433
  // literal types can be handled here.
1396
1434
  const typesToEliminate = [];
1397
- containerType.priv.tupleTypeArguments.forEach((tupleEntry) => {
1435
+ containerType.priv.tupleTypeArgs.forEach((tupleEntry) => {
1398
1436
  if (!tupleEntry.isUnbounded) {
1399
1437
  if ((0, typeUtils_1.isNoneInstance)(tupleEntry.type)) {
1400
1438
  typesToEliminate.push(tupleEntry.type);
@@ -1429,12 +1467,12 @@ function getElementTypeForContainerNarrowing(containerType) {
1429
1467
  if (!(0, types_1.isClassInstance)(containerType) || !types_1.ClassType.isBuiltIn(containerType, supportedContainers)) {
1430
1468
  return undefined;
1431
1469
  }
1432
- if (!containerType.priv.typeArguments || containerType.priv.typeArguments.length < 1) {
1470
+ if (!containerType.priv.typeArgs || containerType.priv.typeArgs.length < 1) {
1433
1471
  return undefined;
1434
1472
  }
1435
- let elementType = containerType.priv.typeArguments[0];
1436
- if ((0, typeUtils_1.isTupleClass)(containerType) && containerType.priv.tupleTypeArguments) {
1437
- elementType = (0, types_1.combineTypes)(containerType.priv.tupleTypeArguments.map((t) => t.type));
1473
+ let elementType = containerType.priv.typeArgs[0];
1474
+ if ((0, typeUtils_1.isTupleClass)(containerType) && containerType.priv.tupleTypeArgs) {
1475
+ elementType = (0, types_1.combineTypes)(containerType.priv.tupleTypeArgs.map((t) => t.type));
1438
1476
  }
1439
1477
  return elementType;
1440
1478
  }
@@ -1584,10 +1622,8 @@ function narrowTypeForDiscriminatedTupleComparison(evaluator, referenceType, ind
1584
1622
  typeof indexLiteralType.priv.literalValue === 'number' &&
1585
1623
  (0, types_1.isClassInstance)(literalType)) {
1586
1624
  const indexValue = indexLiteralType.priv.literalValue;
1587
- if (subtype.priv.tupleTypeArguments &&
1588
- indexValue >= 0 &&
1589
- indexValue < subtype.priv.tupleTypeArguments.length) {
1590
- const tupleEntryType = (_a = subtype.priv.tupleTypeArguments[indexValue]) === null || _a === void 0 ? void 0 : _a.type;
1625
+ if (subtype.priv.tupleTypeArgs && indexValue >= 0 && indexValue < subtype.priv.tupleTypeArgs.length) {
1626
+ const tupleEntryType = (_a = subtype.priv.tupleTypeArgs[indexValue]) === null || _a === void 0 ? void 0 : _a.type;
1591
1627
  if (tupleEntryType && (0, typeUtils_1.isLiteralTypeOrUnion)(tupleEntryType)) {
1592
1628
  if (isPositiveTest) {
1593
1629
  return evaluator.assignType(tupleEntryType, literalType) ? subtype : undefined;
@@ -1733,8 +1769,8 @@ function narrowTypeForClassComparison(evaluator, referenceType, classType, isPos
1733
1769
  types_1.TypeBase.isInstance(subtype) &&
1734
1770
  types_1.ClassType.isBuiltIn(concreteSubtype, 'type')) {
1735
1771
  concreteSubtype =
1736
- concreteSubtype.priv.typeArguments && concreteSubtype.priv.typeArguments.length > 0
1737
- ? (0, typeUtils_1.convertToInstantiable)(concreteSubtype.priv.typeArguments[0])
1772
+ concreteSubtype.priv.typeArgs && concreteSubtype.priv.typeArgs.length > 0
1773
+ ? (0, typeUtils_1.convertToInstantiable)(concreteSubtype.priv.typeArgs[0])
1738
1774
  : types_1.UnknownType.create();
1739
1775
  }
1740
1776
  if ((0, types_1.isAnyOrUnknown)(concreteSubtype)) {
@@ -1894,9 +1930,9 @@ function narrowTypeForCallable(evaluator, type, isPositiveTest, errorNode, allow
1894
1930
  newClassType = (0, typeUtils_1.addConditionToType)(newClassType, (_a = subtype.props) === null || _a === void 0 ? void 0 : _a.condition);
1895
1931
  // Add a __call__ method to the new class.
1896
1932
  const callMethod = types_1.FunctionType.createSynthesizedInstance('__call__');
1897
- const selfParam = types_1.FunctionParam.create(0 /* ParameterCategory.Simple */, types_1.ClassType.cloneAsInstance(newClassType), types_1.FunctionParamFlags.TypeDeclared, 'self');
1898
- types_1.FunctionType.addParameter(callMethod, selfParam);
1899
- types_1.FunctionType.addDefaultParameters(callMethod);
1933
+ const selfParam = types_1.FunctionParam.create(0 /* ParamCategory.Simple */, types_1.ClassType.cloneAsInstance(newClassType), types_1.FunctionParamFlags.TypeDeclared, 'self');
1934
+ types_1.FunctionType.addParam(callMethod, selfParam);
1935
+ types_1.FunctionType.addDefaultParams(callMethod);
1900
1936
  callMethod.shared.declaredReturnType = types_1.UnknownType.create();
1901
1937
  types_1.ClassType.getSymbolTable(newClassType).set('__call__', symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, callMethod));
1902
1938
  return types_1.ClassType.cloneAsInstance(newClassType);