@zzzen/pyright-internal 1.2.0-dev.20240714 → 1.2.0-dev.20240728

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 (225) 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 +8 -8
  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 +3 -2
  8. package/dist/analyzer/checker.js +137 -142
  9. package/dist/analyzer/checker.js.map +1 -1
  10. package/dist/analyzer/codeFlowEngine.d.ts +2 -2
  11. package/dist/analyzer/codeFlowEngine.js +74 -44
  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/constraintSolver.d.ts +2 -2
  16. package/dist/analyzer/constraintSolver.js +166 -206
  17. package/dist/analyzer/constraintSolver.js.map +1 -1
  18. package/dist/analyzer/constructorTransform.d.ts +2 -3
  19. package/dist/analyzer/constructorTransform.js +18 -19
  20. package/dist/analyzer/constructorTransform.js.map +1 -1
  21. package/dist/analyzer/constructors.d.ts +3 -3
  22. package/dist/analyzer/constructors.js +72 -175
  23. package/dist/analyzer/constructors.js.map +1 -1
  24. package/dist/analyzer/dataClasses.d.ts +2 -2
  25. package/dist/analyzer/dataClasses.js +60 -40
  26. package/dist/analyzer/dataClasses.js.map +1 -1
  27. package/dist/analyzer/declaration.d.ts +9 -9
  28. package/dist/analyzer/declaration.js +9 -9
  29. package/dist/analyzer/declaration.js.map +1 -1
  30. package/dist/analyzer/declarationUtils.d.ts +1 -1
  31. package/dist/analyzer/declarationUtils.js +6 -6
  32. package/dist/analyzer/declarationUtils.js.map +1 -1
  33. package/dist/analyzer/decorators.js +5 -6
  34. package/dist/analyzer/decorators.js.map +1 -1
  35. package/dist/analyzer/docStringConversion.js +2 -2
  36. package/dist/analyzer/docStringConversion.js.map +1 -1
  37. package/dist/analyzer/enums.d.ts +2 -2
  38. package/dist/analyzer/enums.js +6 -6
  39. package/dist/analyzer/enums.js.map +1 -1
  40. package/dist/analyzer/functionTransform.d.ts +2 -2
  41. package/dist/analyzer/functionTransform.js +4 -4
  42. package/dist/analyzer/functionTransform.js.map +1 -1
  43. package/dist/analyzer/importResolver.js +5 -3
  44. package/dist/analyzer/importResolver.js.map +1 -1
  45. package/dist/analyzer/namedTuples.d.ts +3 -3
  46. package/dist/analyzer/namedTuples.js +21 -22
  47. package/dist/analyzer/namedTuples.js.map +1 -1
  48. package/dist/analyzer/operations.js +145 -96
  49. package/dist/analyzer/operations.js.map +1 -1
  50. package/dist/analyzer/packageTypeVerifier.js +8 -8
  51. package/dist/analyzer/packageTypeVerifier.js.map +1 -1
  52. package/dist/analyzer/parameterUtils.d.ts +10 -10
  53. package/dist/analyzer/parameterUtils.js +60 -59
  54. package/dist/analyzer/parameterUtils.js.map +1 -1
  55. package/dist/analyzer/parseTreeUtils.d.ts +7 -6
  56. package/dist/analyzer/parseTreeUtils.js +47 -24
  57. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  58. package/dist/analyzer/patternMatching.js +109 -90
  59. package/dist/analyzer/patternMatching.js.map +1 -1
  60. package/dist/analyzer/program.js +11 -4
  61. package/dist/analyzer/program.js.map +1 -1
  62. package/dist/analyzer/properties.js +23 -19
  63. package/dist/analyzer/properties.js.map +1 -1
  64. package/dist/analyzer/protocols.js +23 -20
  65. package/dist/analyzer/protocols.js.map +1 -1
  66. package/dist/analyzer/pythonPathUtils.js +1 -1
  67. package/dist/analyzer/pythonPathUtils.js.map +1 -1
  68. package/dist/analyzer/service.d.ts +3 -7
  69. package/dist/analyzer/service.js +28 -30
  70. package/dist/analyzer/service.js.map +1 -1
  71. package/dist/analyzer/serviceUtils.d.ts +8 -0
  72. package/dist/analyzer/serviceUtils.js +31 -0
  73. package/dist/analyzer/serviceUtils.js.map +1 -0
  74. package/dist/analyzer/sourceFile.js +5 -19
  75. package/dist/analyzer/sourceFile.js.map +1 -1
  76. package/dist/analyzer/sourceMapper.d.ts +1 -1
  77. package/dist/analyzer/sourceMapper.js +4 -4
  78. package/dist/analyzer/sourceMapper.js.map +1 -1
  79. package/dist/analyzer/staticExpressions.js +1 -1
  80. package/dist/analyzer/staticExpressions.js.map +1 -1
  81. package/dist/analyzer/testWalker.js +13 -1
  82. package/dist/analyzer/testWalker.js.map +1 -1
  83. package/dist/analyzer/tracePrinter.js +4 -4
  84. package/dist/analyzer/tracePrinter.js.map +1 -1
  85. package/dist/analyzer/tuples.d.ts +9 -0
  86. package/dist/analyzer/tuples.js +252 -0
  87. package/dist/analyzer/tuples.js.map +1 -0
  88. package/dist/analyzer/typeComplexity.d.ts +2 -0
  89. package/dist/analyzer/typeComplexity.js +86 -0
  90. package/dist/analyzer/typeComplexity.js.map +1 -0
  91. package/dist/analyzer/typeEvaluator.js +1721 -1824
  92. package/dist/analyzer/typeEvaluator.js.map +1 -1
  93. package/dist/analyzer/typeEvaluatorTypes.d.ts +47 -40
  94. package/dist/analyzer/typeEvaluatorTypes.js +10 -1
  95. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  96. package/dist/analyzer/typeGuards.js +116 -90
  97. package/dist/analyzer/typeGuards.js.map +1 -1
  98. package/dist/analyzer/typePrinter.d.ts +1 -1
  99. package/dist/analyzer/typePrinter.js +54 -53
  100. package/dist/analyzer/typePrinter.js.map +1 -1
  101. package/dist/analyzer/typeStubWriter.d.ts +3 -3
  102. package/dist/analyzer/typeStubWriter.js +15 -15
  103. package/dist/analyzer/typeStubWriter.js.map +1 -1
  104. package/dist/analyzer/typeUtils.d.ts +35 -29
  105. package/dist/analyzer/typeUtils.js +420 -357
  106. package/dist/analyzer/typeUtils.js.map +1 -1
  107. package/dist/analyzer/typeVarContext.d.ts +24 -36
  108. package/dist/analyzer/typeVarContext.js +89 -193
  109. package/dist/analyzer/typeVarContext.js.map +1 -1
  110. package/dist/analyzer/typeWalker.js +4 -4
  111. package/dist/analyzer/typeWalker.js.map +1 -1
  112. package/dist/analyzer/typedDicts.d.ts +2 -2
  113. package/dist/analyzer/typedDicts.js +49 -53
  114. package/dist/analyzer/typedDicts.js.map +1 -1
  115. package/dist/analyzer/types.d.ts +89 -63
  116. package/dist/analyzer/types.js +163 -120
  117. package/dist/analyzer/types.js.map +1 -1
  118. package/dist/commands/dumpFileDebugInfoCommand.js +12 -12
  119. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  120. package/dist/common/configOptions.d.ts +1 -0
  121. package/dist/common/configOptions.js +5 -0
  122. package/dist/common/configOptions.js.map +1 -1
  123. package/dist/common/diagnosticRules.d.ts +1 -0
  124. package/dist/common/diagnosticRules.js +1 -0
  125. package/dist/common/diagnosticRules.js.map +1 -1
  126. package/dist/common/fileSystem.d.ts +0 -1
  127. package/dist/common/fileSystem.js.map +1 -1
  128. package/dist/common/languageServerInterface.d.ts +13 -0
  129. package/dist/common/languageServerInterface.js +15 -1
  130. package/dist/common/languageServerInterface.js.map +1 -1
  131. package/dist/common/lspUtils.js +2 -2
  132. package/dist/common/memUtils.d.ts +4 -0
  133. package/dist/common/memUtils.js +33 -2
  134. package/dist/common/memUtils.js.map +1 -1
  135. package/dist/common/serviceKeys.d.ts +3 -0
  136. package/dist/common/serviceKeys.js +2 -0
  137. package/dist/common/serviceKeys.js.map +1 -1
  138. package/dist/common/serviceProviderExtensions.js +7 -0
  139. package/dist/common/serviceProviderExtensions.js.map +1 -1
  140. package/dist/languageServerBase.d.ts +4 -3
  141. package/dist/languageServerBase.js +14 -10
  142. package/dist/languageServerBase.js.map +1 -1
  143. package/dist/languageService/autoImporter.d.ts +3 -2
  144. package/dist/languageService/autoImporter.js +5 -1
  145. package/dist/languageService/autoImporter.js.map +1 -1
  146. package/dist/languageService/completionProvider.d.ts +5 -3
  147. package/dist/languageService/completionProvider.js +38 -37
  148. package/dist/languageService/completionProvider.js.map +1 -1
  149. package/dist/languageService/completionProviderUtils.d.ts +1 -1
  150. package/dist/languageService/completionProviderUtils.js +3 -3
  151. package/dist/languageService/completionProviderUtils.js.map +1 -1
  152. package/dist/languageService/fileWatcherDynamicFeature.js +2 -2
  153. package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
  154. package/dist/languageService/hoverProvider.js +14 -6
  155. package/dist/languageService/hoverProvider.js.map +1 -1
  156. package/dist/languageService/referencesProvider.d.ts +10 -4
  157. package/dist/languageService/referencesProvider.js +24 -12
  158. package/dist/languageService/referencesProvider.js.map +1 -1
  159. package/dist/languageService/renameProvider.js +21 -4
  160. package/dist/languageService/renameProvider.js.map +1 -1
  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 +9 -3
  166. package/dist/localization/localize.js +8 -1
  167. package/dist/localization/localize.js.map +1 -1
  168. package/dist/localization/package.nls.cs.json +5 -2
  169. package/dist/localization/package.nls.de.json +5 -2
  170. package/dist/localization/package.nls.en-us.json +7 -1
  171. package/dist/localization/package.nls.es.json +5 -2
  172. package/dist/localization/package.nls.fr.json +5 -2
  173. package/dist/localization/package.nls.it.json +5 -2
  174. package/dist/localization/package.nls.ja.json +5 -2
  175. package/dist/localization/package.nls.ko.json +5 -2
  176. package/dist/localization/package.nls.pl.json +5 -2
  177. package/dist/localization/package.nls.pt-br.json +5 -2
  178. package/dist/localization/package.nls.qps-ploc.json +5 -2
  179. package/dist/localization/package.nls.ru.json +5 -2
  180. package/dist/localization/package.nls.tr.json +5 -2
  181. package/dist/localization/package.nls.zh-cn.json +5 -2
  182. package/dist/localization/package.nls.zh-tw.json +5 -2
  183. package/dist/parser/parseNodes.d.ts +12 -10
  184. package/dist/parser/parseNodes.js +23 -21
  185. package/dist/parser/parseNodes.js.map +1 -1
  186. package/dist/parser/parser.js +66 -43
  187. package/dist/parser/parser.js.map +1 -1
  188. package/dist/tests/checker.test.js +2 -2
  189. package/dist/tests/fourslash/rename.args.fourslash.d.ts +1 -0
  190. package/dist/tests/fourslash/rename.args.fourslash.js +71 -0
  191. package/dist/tests/fourslash/rename.args.fourslash.js.map +1 -0
  192. package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js +4 -21
  193. package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js.map +1 -1
  194. package/dist/tests/fourslash/signature.complicated.fourslash.js +1 -1
  195. package/dist/tests/fourslash/signature.complicated.fourslash.js.map +1 -1
  196. package/dist/tests/harness/fourslash/fourSlashParser.js +1 -1
  197. package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
  198. package/dist/tests/harness/fourslash/testStateUtils.js +2 -2
  199. package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
  200. package/dist/tests/harness/vfs/filesystem.d.ts +0 -1
  201. package/dist/tests/harness/vfs/filesystem.js +0 -4
  202. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  203. package/dist/tests/importResolver.test.js +62 -15
  204. package/dist/tests/importResolver.test.js.map +1 -1
  205. package/dist/tests/lsp/languageServerTestUtils.js +1 -1
  206. package/dist/tests/lsp/languageServerTestUtils.js.map +1 -1
  207. package/dist/tests/typeEvaluator1.test.js +17 -0
  208. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  209. package/dist/tests/typeEvaluator2.test.js +4 -0
  210. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  211. package/dist/tests/typeEvaluator3.test.js +1 -1
  212. package/dist/tests/typeEvaluator4.test.js +19 -7
  213. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  214. package/dist/tests/typeEvaluator5.test.js +8 -2
  215. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  216. package/dist/tests/typeEvaluator6.test.js +76 -60
  217. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  218. package/dist/tests/typeEvaluator7.test.js +5 -1
  219. package/dist/tests/typeEvaluator7.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
@@ -17,10 +17,10 @@ const typeEvaluatorTypes_1 = require("./typeEvaluatorTypes");
17
17
  const types_1 = require("./types");
18
18
  const typeUtils_1 = require("./typeUtils");
19
19
  const typeVarContext_1 = require("./typeVarContext");
20
- // As we widen the narrow bound of a type variable, we may end up with
20
+ // As we widen the lower bound of a type variable, we may end up with
21
21
  // many subtypes. For performance reasons, we need to cap this at some
22
22
  // point. This constant determines the cap.
23
- const maxSubtypeCountForTypeVarNarrowBound = 64;
23
+ const maxSubtypeCountForTypeVarLowerBound = 64;
24
24
  // This debugging switch enables logging of the TypeVarContext before and
25
25
  // after it is updated by the constraint solver.
26
26
  const logTypeVarContextUpdates = false;
@@ -39,7 +39,6 @@ function assignTypeToTypeVar(evaluator, destType, srcType, diag, typeVarContext,
39
39
  console.log(`${indent}srcType: ${evaluator.printType(srcType)}`);
40
40
  console.log(`${indent}flags: ${flags}`);
41
41
  console.log(`${indent}scopes: ${(typeVarContext.getSolveForScopes() || []).join(', ')}`);
42
- console.log(`${indent}pre-call context #${typeVarContext.getId()}: `);
43
42
  logTypeVarContext(evaluator, typeVarContext, indent);
44
43
  }
45
44
  let isTypeVarInScope = true;
@@ -66,16 +65,16 @@ function assignTypeToTypeVar(evaluator, destType, srcType, diag, typeVarContext,
66
65
  }
67
66
  // Handle a type[Any] as a source.
68
67
  if ((0, types_1.isClassInstance)(srcType) && types_1.ClassType.isBuiltIn(srcType, 'type')) {
69
- if (!srcType.priv.typeArguments ||
70
- srcType.priv.typeArguments.length < 1 ||
71
- (0, types_1.isAnyOrUnknown)(srcType.priv.typeArguments[0])) {
68
+ if (!srcType.priv.typeArgs ||
69
+ srcType.priv.typeArgs.length < 1 ||
70
+ (0, types_1.isAnyOrUnknown)(srcType.priv.typeArgs[0])) {
72
71
  if (types_1.TypeBase.isInstantiable(destType)) {
73
72
  return true;
74
73
  }
75
74
  }
76
75
  }
77
76
  // Is this the equivalent of an "Unknown" for a ParamSpec?
78
- if (destType.shared.isParamSpec &&
77
+ if ((0, types_1.isParamSpec)(destType) &&
79
78
  (0, types_1.isFunction)(srcType) &&
80
79
  types_1.FunctionType.isParamSpecValue(srcType) &&
81
80
  types_1.FunctionType.isGradualCallableForm(srcType)) {
@@ -109,16 +108,16 @@ function assignTypeToTypeVar(evaluator, destType, srcType, diag, typeVarContext,
109
108
  /* destTypeVarContext */ undefined,
110
109
  /* srcTypeVarContext */ undefined, flags, recursionCount);
111
110
  }
112
- if (destType.shared.isParamSpec) {
111
+ if ((0, types_1.isParamSpec)(destType)) {
113
112
  return assignTypeToParamSpec(evaluator, destType, srcType, diag, typeVarContext, recursionCount);
114
113
  }
115
- if (destType.shared.isVariadic && !destType.priv.isVariadicInUnion) {
114
+ if ((0, types_1.isTypeVarTuple)(destType) && !destType.priv.isVariadicInUnion) {
116
115
  if (!(0, types_1.isUnpacked)(srcType)) {
117
116
  const tupleClassType = evaluator.getTupleClassType();
118
117
  if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
119
118
  // Package up the type into a tuple.
120
119
  srcType = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type: srcType, isUnbounded: false }],
121
- /* isTypeArgumentExplicit */ true,
120
+ /* isTypeArgExplicit */ true,
122
121
  /* isUnpackedTuple */ true));
123
122
  }
124
123
  else {
@@ -128,11 +127,10 @@ function assignTypeToTypeVar(evaluator, destType, srcType, diag, typeVarContext,
128
127
  }
129
128
  // If we're assigning an unpacked TypeVarTuple to a regular TypeVar,
130
129
  // we need to treat it as a union of the unpacked TypeVarTuple.
131
- if ((0, types_1.isTypeVar)(srcType) &&
132
- srcType.shared.isVariadic &&
130
+ if ((0, types_1.isTypeVarTuple)(srcType) &&
133
131
  srcType.priv.isVariadicUnpacked &&
134
132
  !srcType.priv.isVariadicInUnion &&
135
- !destType.shared.isVariadic) {
133
+ !(0, types_1.isTypeVarTuple)(destType)) {
136
134
  srcType = types_1.TypeVarType.cloneForUnpacked(srcType, /* isInUnion */ true);
137
135
  }
138
136
  // Handle the constrained case. This case needs to be handled specially
@@ -143,19 +141,19 @@ function assignTypeToTypeVar(evaluator, destType, srcType, diag, typeVarContext,
143
141
  return assignTypeToConstrainedTypeVar(evaluator, destType, srcType, diag, typeVarContext, flags, isTypeVarInScope, recursionCount);
144
142
  }
145
143
  // Handle the unconstrained (but possibly bound) case.
146
- const curEntry = typeVarContext.getPrimarySignature().getTypeVar(destType);
147
- let curWideTypeBound = curEntry === null || curEntry === void 0 ? void 0 : curEntry.wideBound;
148
- if (!curWideTypeBound && !destType.shared.isSynthesizedSelf) {
149
- curWideTypeBound = destType.shared.boundType;
150
- }
151
- let curNarrowTypeBound = curEntry === null || curEntry === void 0 ? void 0 : curEntry.narrowBound;
152
- let newNarrowTypeBound = curNarrowTypeBound;
153
- let newWideTypeBound = curWideTypeBound;
144
+ const curEntry = typeVarContext.getMainSolutionSet().getTypeVar(destType);
145
+ let curUpperBound = curEntry === null || curEntry === void 0 ? void 0 : curEntry.upperBound;
146
+ if (!curUpperBound && !destType.shared.isSynthesizedSelf) {
147
+ curUpperBound = destType.shared.boundType;
148
+ }
149
+ let curLowerBound = curEntry === null || curEntry === void 0 ? void 0 : curEntry.lowerBound;
150
+ let newLowerBound = curLowerBound;
151
+ let newUpperTypeBound = curUpperBound;
154
152
  const diagAddendum = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
155
153
  let adjSrcType = srcType;
156
154
  // If the source is a class that is missing type arguments, fill
157
155
  // in missing type arguments with Unknown.
158
- if ((flags & 8192 /* AssignTypeFlags.AllowUnspecifiedTypeArguments */) === 0) {
156
+ if ((flags & 8192 /* AssignTypeFlags.AllowUnspecifiedTypeArgs */) === 0) {
159
157
  if ((0, types_1.isClass)(adjSrcType) && adjSrcType.priv.includeSubclasses) {
160
158
  adjSrcType = (0, typeUtils_1.specializeWithDefaultTypeArgs)(adjSrcType);
161
159
  }
@@ -187,51 +185,51 @@ function assignTypeToTypeVar(evaluator, destType, srcType, diag, typeVarContext,
187
185
  return true;
188
186
  }
189
187
  // If we're populating the expected type, constrain either the
190
- // narrow type bound, wide type bound or both. Don't overwrite
188
+ // lower type bound, upper type bound or both. Don't overwrite
191
189
  // an existing entry.
192
190
  if (!curEntry) {
193
191
  if (isInvariant) {
194
- newNarrowTypeBound = adjSrcType;
195
- newWideTypeBound = adjSrcType;
192
+ newLowerBound = adjSrcType;
193
+ newUpperTypeBound = adjSrcType;
196
194
  }
197
195
  else if (isContravariant) {
198
- newNarrowTypeBound = adjSrcType;
196
+ newLowerBound = adjSrcType;
199
197
  }
200
198
  else {
201
- newWideTypeBound = adjSrcType;
199
+ newUpperTypeBound = adjSrcType;
202
200
  }
203
201
  }
204
202
  }
205
203
  else if (isContravariant) {
206
- // Update the wide type bound.
207
- if (!curWideTypeBound || (0, types_1.isTypeSame)(destType, curWideTypeBound)) {
208
- newWideTypeBound = adjSrcType;
204
+ // Update the upper bound.
205
+ if (!curUpperBound || (0, types_1.isTypeSame)(destType, curUpperBound)) {
206
+ newUpperTypeBound = adjSrcType;
209
207
  }
210
- else if (!(0, types_1.isTypeSame)(curWideTypeBound, adjSrcType, {}, recursionCount)) {
211
- if (evaluator.assignType(curWideTypeBound, evaluator.makeTopLevelTypeVarsConcrete(adjSrcType), diagAddendum,
208
+ else if (!(0, types_1.isTypeSame)(curUpperBound, adjSrcType, {}, recursionCount)) {
209
+ if (evaluator.assignType(curUpperBound, evaluator.makeTopLevelTypeVarsConcrete(adjSrcType), diagAddendum,
212
210
  /* destTypeVarContext */ undefined,
213
211
  /* srcTypeVarContext */ undefined, flags & 1024 /* AssignTypeFlags.IgnoreTypeVarScope */, recursionCount)) {
214
- // The srcType is narrower than the current wideTypeBound, so replace it.
215
- newWideTypeBound = adjSrcType;
212
+ // The srcType is narrower than the current upper bound, so replace it.
213
+ newUpperTypeBound = adjSrcType;
216
214
  }
217
- else if (!evaluator.assignType(adjSrcType, curWideTypeBound, diagAddendum,
215
+ else if (!evaluator.assignType(adjSrcType, curUpperBound, diagAddendum,
218
216
  /* destTypeVarContext */ undefined,
219
217
  /* srcTypeVarContext */ undefined, flags & 1024 /* AssignTypeFlags.IgnoreTypeVarScope */, recursionCount)) {
220
218
  if (diag && diagAddendum) {
221
- diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(evaluator.printSrcDestTypes(curWideTypeBound, adjSrcType)));
219
+ diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(evaluator.printSrcDestTypes(curUpperBound, adjSrcType)));
222
220
  diag.addAddendum(diagAddendum);
223
221
  }
224
222
  return false;
225
223
  }
226
224
  }
227
- // Make sure we haven't narrowed it beyond the current narrow bound.
228
- if (curNarrowTypeBound) {
229
- if (!evaluator.assignType(newWideTypeBound, curNarrowTypeBound,
225
+ // Make sure we haven't narrowed it beyond the current lower bound.
226
+ if (curLowerBound) {
227
+ if (!evaluator.assignType(newUpperTypeBound, curLowerBound,
230
228
  /* diag */ undefined,
231
229
  /* destTypeVarContext */ undefined,
232
230
  /* srcTypeVarContext */ undefined, flags & 1024 /* AssignTypeFlags.IgnoreTypeVarScope */, recursionCount)) {
233
231
  if (diag && diagAddendum) {
234
- diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(evaluator.printSrcDestTypes(curNarrowTypeBound, newWideTypeBound)));
232
+ diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(evaluator.printSrcDestTypes(curLowerBound, newUpperTypeBound)));
235
233
  diag.addAddendum(diagAddendum);
236
234
  }
237
235
  return false;
@@ -239,138 +237,132 @@ function assignTypeToTypeVar(evaluator, destType, srcType, diag, typeVarContext,
239
237
  }
240
238
  }
241
239
  else {
242
- if (!curNarrowTypeBound || (0, types_1.isTypeSame)(destType, curNarrowTypeBound)) {
243
- // There was previously no narrow bound. We've now established one.
244
- newNarrowTypeBound = adjSrcType;
240
+ if (!curLowerBound || (0, types_1.isTypeSame)(destType, curLowerBound)) {
241
+ // There was previously no lower bound. We've now established one.
242
+ newLowerBound = adjSrcType;
245
243
  }
246
- else if ((0, types_1.isTypeSame)(curNarrowTypeBound, adjSrcType, {}, recursionCount)) {
247
- // If this is an invariant context and there is currently no wide type bound
248
- // established, use the "no literals" version of the narrow type bounds rather
244
+ else if ((0, types_1.isTypeSame)(curLowerBound, adjSrcType, {}, recursionCount)) {
245
+ // If this is an invariant context and there is currently no upper bound
246
+ // established, use the "no literals" version of the lower bound rather
249
247
  // than a version that has literals.
250
- if (!newWideTypeBound && isInvariant && (curEntry === null || curEntry === void 0 ? void 0 : curEntry.narrowBoundNoLiterals)) {
251
- newNarrowTypeBound = curEntry.narrowBoundNoLiterals;
248
+ if (!newUpperTypeBound && isInvariant && (curEntry === null || curEntry === void 0 ? void 0 : curEntry.lowerBoundNoLiterals)) {
249
+ newLowerBound = curEntry.lowerBoundNoLiterals;
252
250
  }
253
251
  }
254
252
  else {
255
- if ((0, types_1.isAnyOrUnknown)(adjSrcType) && (curEntry === null || curEntry === void 0 ? void 0 : curEntry.tupleTypes)) {
256
- // Handle the tuple case specially. If Any or Unknown is assigned
257
- // during the construction of a tuple, the resulting tuple type must
258
- // be tuple[Any, ...], which is compatible with any tuple.
259
- newNarrowTypeBound = adjSrcType;
260
- }
261
- else if (evaluator.assignType(curNarrowTypeBound, adjSrcType, diagAddendum, typeVarContext,
253
+ if (evaluator.assignType(curLowerBound, adjSrcType, diagAddendum, typeVarContext,
262
254
  /* srcTypeVarContext */ undefined, flags, recursionCount)) {
263
255
  // No need to widen. Stick with the existing type unless it's unknown
264
256
  // or partly unknown, in which case we'll replace it with a known type
265
- // as long as it doesn't violate the current narrow bound.
266
- if ((0, typeUtils_1.isPartlyUnknown)(curNarrowTypeBound) &&
257
+ // as long as it doesn't violate the current lower bound.
258
+ if ((0, typeUtils_1.isPartlyUnknown)(curLowerBound) &&
267
259
  !(0, types_1.isUnknown)(adjSrcType) &&
268
- evaluator.assignType(adjSrcType, curNarrowTypeBound,
260
+ evaluator.assignType(adjSrcType, curLowerBound,
269
261
  /* diag */ undefined, typeVarContext,
270
262
  /* srcTypeVarContext */ undefined, flags & 1024 /* AssignTypeFlags.IgnoreTypeVarScope */, recursionCount)) {
271
- newNarrowTypeBound = adjSrcType;
263
+ newLowerBound = adjSrcType;
272
264
  }
273
265
  else {
274
- newNarrowTypeBound = (0, typeUtils_1.applySolvedTypeVars)(curNarrowTypeBound, typeVarContext);
266
+ newLowerBound = (0, typeUtils_1.applySolvedTypeVars)(curLowerBound, typeVarContext);
275
267
  }
276
268
  }
277
- else if ((0, types_1.isTypeVar)(curNarrowTypeBound) &&
269
+ else if ((0, types_1.isTypeVar)(curLowerBound) &&
278
270
  !(0, types_1.isTypeVar)(adjSrcType) &&
279
- evaluator.assignType(evaluator.makeTopLevelTypeVarsConcrete(curNarrowTypeBound), adjSrcType, diagAddendum, typeVarContext,
271
+ evaluator.assignType(evaluator.makeTopLevelTypeVarsConcrete(curLowerBound), adjSrcType, diagAddendum, typeVarContext,
280
272
  /* srcTypeVarContext */ undefined, flags, recursionCount)) {
281
- // If the existing narrow type bound was a TypeVar that is not
273
+ // If the existing lower bound was a TypeVar that is not
282
274
  // part of the current context we can replace it with the new
283
275
  // source type.
284
- newNarrowTypeBound = adjSrcType;
276
+ newLowerBound = adjSrcType;
285
277
  }
286
278
  else {
287
279
  // We need to widen the type.
288
280
  if (typeVarContext.isLocked()) {
289
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(evaluator.printSrcDestTypes(adjSrcType, curNarrowTypeBound)));
281
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(evaluator.printSrcDestTypes(adjSrcType, curLowerBound)));
290
282
  return false;
291
283
  }
292
- if (evaluator.assignType(adjSrcType, curNarrowTypeBound,
284
+ if (evaluator.assignType(adjSrcType, curLowerBound,
293
285
  /* diag */ undefined, typeVarContext,
294
286
  /* srcTypeVarContext */ undefined, flags & 1024 /* AssignTypeFlags.IgnoreTypeVarScope */, recursionCount)) {
295
- newNarrowTypeBound = adjSrcType;
287
+ newLowerBound = adjSrcType;
296
288
  }
297
- else if ((0, types_1.isVariadicTypeVar)(destType)) {
298
- const widenedType = widenTypeForVariadicTypeVar(evaluator, curNarrowTypeBound, adjSrcType);
289
+ else if ((0, types_1.isTypeVarTuple)(destType)) {
290
+ const widenedType = widenTypeForTypeVarTuple(evaluator, curLowerBound, adjSrcType);
299
291
  if (!widenedType) {
300
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(evaluator.printSrcDestTypes(curNarrowTypeBound, adjSrcType)));
292
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(evaluator.printSrcDestTypes(curLowerBound, adjSrcType)));
301
293
  return false;
302
294
  }
303
- newNarrowTypeBound = widenedType;
295
+ newLowerBound = widenedType;
304
296
  }
305
297
  else {
306
298
  const objectType = evaluator.getObjectType();
307
- // If this is an invariant context and there is currently no wide type bound
308
- // established, use the "no literals" version of the narrow type bounds rather
299
+ // If this is an invariant context and there is currently no upper bound
300
+ // established, use the "no literals" version of the lower bound rather
309
301
  // than a version that has literals.
310
- if (!newWideTypeBound && isInvariant && (curEntry === null || curEntry === void 0 ? void 0 : curEntry.narrowBoundNoLiterals)) {
311
- curNarrowTypeBound = curEntry.narrowBoundNoLiterals;
302
+ if (!newUpperTypeBound && isInvariant && (curEntry === null || curEntry === void 0 ? void 0 : curEntry.lowerBoundNoLiterals)) {
303
+ curLowerBound = curEntry.lowerBoundNoLiterals;
312
304
  }
313
- const curSolvedNarrowTypeBound = (0, typeUtils_1.applySolvedTypeVars)(curNarrowTypeBound, typeVarContext);
314
- // In some extreme edge cases, the narrow type bound can become
305
+ const curSolvedLowerBound = (0, typeUtils_1.applySolvedTypeVars)(curLowerBound, typeVarContext);
306
+ // In some extreme edge cases, the lower bound can become
315
307
  // a union with so many subtypes that performance grinds to a
316
308
  // halt. We'll detect this case and widen the resulting type
317
309
  // to an 'object' instead of making the union even bigger. This
318
310
  // is still a valid solution to the TypeVar.
319
- if ((0, types_1.isUnion)(curSolvedNarrowTypeBound) &&
320
- curSolvedNarrowTypeBound.priv.subtypes.length > typeEvaluatorTypes_1.maxSubtypesForInferredType &&
311
+ if ((0, types_1.isUnion)(curSolvedLowerBound) &&
312
+ curSolvedLowerBound.priv.subtypes.length > typeEvaluatorTypes_1.maxSubtypesForInferredType &&
321
313
  destType.shared.boundType !== undefined &&
322
314
  (0, types_1.isClassInstance)(objectType)) {
323
- newNarrowTypeBound = (0, types_1.combineTypes)([curSolvedNarrowTypeBound, objectType], {
324
- maxSubtypeCount: maxSubtypeCountForTypeVarNarrowBound,
315
+ newLowerBound = (0, types_1.combineTypes)([curSolvedLowerBound, objectType], {
316
+ maxSubtypeCount: maxSubtypeCountForTypeVarLowerBound,
325
317
  });
326
318
  }
327
319
  else {
328
- newNarrowTypeBound = (0, types_1.combineTypes)([curSolvedNarrowTypeBound, adjSrcType], {
329
- maxSubtypeCount: maxSubtypeCountForTypeVarNarrowBound,
320
+ newLowerBound = (0, types_1.combineTypes)([curSolvedLowerBound, adjSrcType], {
321
+ maxSubtypeCount: maxSubtypeCountForTypeVarLowerBound,
330
322
  });
331
323
  }
332
324
  }
333
325
  }
334
326
  }
335
- // If this is an invariant context, make sure the narrow type bound
327
+ // If this is an invariant context, make sure the lower bound
336
328
  // isn't too wide.
337
- if (isInvariant && newNarrowTypeBound) {
338
- if (!evaluator.assignType(adjSrcType, newNarrowTypeBound, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
329
+ if (isInvariant && newLowerBound) {
330
+ if (!evaluator.assignType(adjSrcType, newLowerBound, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
339
331
  /* destTypeVarContext */ undefined,
340
332
  /* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */, recursionCount)) {
341
333
  if (diag && diagAddendum) {
342
- diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(evaluator.printSrcDestTypes(newNarrowTypeBound, adjSrcType)));
334
+ diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(evaluator.printSrcDestTypes(newLowerBound, adjSrcType)));
343
335
  }
344
336
  return false;
345
337
  }
346
338
  }
347
- // Make sure we don't exceed the wide type bound.
348
- if (curWideTypeBound && newNarrowTypeBound) {
349
- if (!(0, types_1.isTypeSame)(curWideTypeBound, newNarrowTypeBound, {}, recursionCount)) {
350
- let adjWideTypeBound = evaluator.makeTopLevelTypeVarsConcrete(curWideTypeBound,
339
+ // Make sure we don't exceed the upper bound.
340
+ if (curUpperBound && newLowerBound) {
341
+ if (!(0, types_1.isTypeSame)(curUpperBound, newLowerBound, {}, recursionCount)) {
342
+ let adjUpperBound = evaluator.makeTopLevelTypeVarsConcrete(curUpperBound,
351
343
  /* makeParamSpecsConcrete */ true);
352
- // Convert any remaining (non-top-level) TypeVars in the wide type
344
+ // Convert any remaining (non-top-level) TypeVars in the upper
353
345
  // bound to in-scope placeholders.
354
- adjWideTypeBound = (0, typeUtils_1.transformExpectedType)(adjWideTypeBound,
346
+ adjUpperBound = (0, typeUtils_1.transformExpectedType)(adjUpperBound,
355
347
  /* liveTypeVarScopes */ [],
356
348
  /* usageOffset */ undefined);
357
- if (!evaluator.assignType(adjWideTypeBound, newNarrowTypeBound, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
349
+ if (!evaluator.assignType(adjUpperBound, newLowerBound, diag === null || diag === void 0 ? void 0 : diag.createAddendum(),
358
350
  /* destTypeVarContext */ undefined,
359
351
  /* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */, recursionCount)) {
360
352
  if (diag && diagAddendum) {
361
- diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(evaluator.printSrcDestTypes(newNarrowTypeBound, adjWideTypeBound)));
353
+ diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(evaluator.printSrcDestTypes(newLowerBound, adjUpperBound)));
362
354
  }
363
355
  return false;
364
356
  }
365
357
  }
366
358
  }
367
359
  }
368
- if (!newWideTypeBound && isInvariant) {
369
- newWideTypeBound = newNarrowTypeBound;
360
+ if (!newUpperTypeBound && isInvariant) {
361
+ newUpperTypeBound = newLowerBound;
370
362
  }
371
363
  // If there's a bound type, make sure the source is assignable to it.
372
364
  if (destType.shared.boundType) {
373
- const updatedType = (newNarrowTypeBound || newWideTypeBound);
365
+ const updatedType = (newLowerBound || newUpperTypeBound);
374
366
  // If the dest is a Type[T] but the source is not a valid Type,
375
367
  // skip the assignType check and the diagnostic addendum, which will
376
368
  // be confusing and inaccurate.
@@ -397,56 +389,45 @@ function assignTypeToTypeVar(evaluator, destType, srcType, diag, typeVarContext,
397
389
  return false;
398
390
  }
399
391
  }
400
- // Update the tuple types based on the new type bounds. We need to
401
- // switch to an unbounded tuple type since the length of the resulting
402
- // tuple is indeterminate.
403
- let newTupleTypes = curEntry === null || curEntry === void 0 ? void 0 : curEntry.tupleTypes;
404
- if (newTupleTypes) {
405
- const updatedType = newNarrowTypeBound !== null && newNarrowTypeBound !== void 0 ? newNarrowTypeBound : newWideTypeBound;
406
- if (updatedType) {
407
- newTupleTypes = [{ type: updatedType, isUnbounded: true }];
408
- }
409
- }
410
392
  if (!typeVarContext.isLocked() && isTypeVarInScope) {
411
- updateTypeVarType(evaluator, typeVarContext, destType, newNarrowTypeBound, newWideTypeBound, newTupleTypes, (flags & (2048 /* AssignTypeFlags.PopulatingExpectedType */ | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */)) !== 0);
393
+ updateTypeVarType(evaluator, typeVarContext, destType, newLowerBound, newUpperTypeBound, (flags & (2048 /* AssignTypeFlags.PopulatingExpectedType */ | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */)) !== 0);
412
394
  }
413
395
  if (logTypeVarContextUpdates) {
414
396
  const indent = ' '.repeat(recursionCount * 2);
415
397
  console.log(`${indent}`);
416
- console.log(`${indent}post-call context #${typeVarContext.getId()}: `);
417
398
  logTypeVarContext(evaluator, typeVarContext, indent);
418
399
  }
419
400
  return true;
420
401
  }
421
402
  exports.assignTypeToTypeVar = assignTypeToTypeVar;
422
- // Updates the narrow and wide type bounds for a type variable. It also calculates the
423
- // narrowTypeBoundNoLiterals, which is a variant of the narrow type bound that has
403
+ // Updates the lower and upper bounds for a type variable. It also calculates the
404
+ // lowerBoundNoLiterals, which is a variant of the lower bound that has
424
405
  // literals stripped. By default, the constraint solver always uses the "no literals"
425
406
  // type in its solutions unless the version with literals is required to satisfy
426
- // the wide type bound.
427
- function updateTypeVarType(evaluator, typeVarContext, destType, narrowTypeBound, wideTypeBound, tupleTypes = undefined, forceRetainLiterals = false) {
428
- let narrowTypeBoundNoLiterals;
429
- if (narrowTypeBound && !forceRetainLiterals) {
430
- const strippedLiteral = (0, types_1.isVariadicTypeVar)(destType)
431
- ? stripLiteralValueForUnpackedTuple(evaluator, narrowTypeBound)
432
- : evaluator.stripLiteralValue(narrowTypeBound);
433
- // Strip the literals from the narrow type bound and see if it is still
434
- // narrower than the wide bound.
435
- if (strippedLiteral !== narrowTypeBound) {
436
- if (!wideTypeBound || evaluator.assignType(wideTypeBound, strippedLiteral)) {
437
- narrowTypeBoundNoLiterals = strippedLiteral;
438
- }
439
- }
440
- }
441
- typeVarContext.setTypeVarType(destType, narrowTypeBound, narrowTypeBoundNoLiterals, wideTypeBound, tupleTypes);
407
+ // the upper bound.
408
+ function updateTypeVarType(evaluator, typeVarContext, destType, lowerBound, upperBound, forceRetainLiterals = false) {
409
+ let lowerBoundNoLiterals;
410
+ if (lowerBound && !forceRetainLiterals) {
411
+ const strippedLiteral = (0, types_1.isTypeVarTuple)(destType)
412
+ ? stripLiteralValueForUnpackedTuple(evaluator, lowerBound)
413
+ : evaluator.stripLiteralValue(lowerBound);
414
+ // Strip the literals from the lower bound and see if it is still
415
+ // narrower than the upper bound.
416
+ if (strippedLiteral !== lowerBound) {
417
+ if (!upperBound || evaluator.assignType(upperBound, strippedLiteral)) {
418
+ lowerBoundNoLiterals = strippedLiteral;
419
+ }
420
+ }
421
+ }
422
+ typeVarContext.setTypeVarType(destType, lowerBound, lowerBoundNoLiterals, upperBound); //, tupleTypes);
442
423
  }
443
424
  exports.updateTypeVarType = updateTypeVarType;
444
425
  function assignTypeToConstrainedTypeVar(evaluator, destType, srcType, diag, typeVarContext, flags, isTypeVarInScope, recursionCount) {
445
426
  let constrainedType;
446
427
  const concreteSrcType = evaluator.makeTopLevelTypeVarsConcrete(srcType);
447
- const curEntry = typeVarContext.getPrimarySignature().getTypeVar(destType);
448
- const curWideTypeBound = curEntry === null || curEntry === void 0 ? void 0 : curEntry.wideBound;
449
- const curNarrowTypeBound = curEntry === null || curEntry === void 0 ? void 0 : curEntry.narrowBound;
428
+ const curEntry = typeVarContext.getMainSolutionSet().getTypeVar(destType);
429
+ const curUpperBound = curEntry === null || curEntry === void 0 ? void 0 : curEntry.upperBound;
430
+ const curLowerBound = curEntry === null || curEntry === void 0 ? void 0 : curEntry.lowerBound;
450
431
  let forceRetainLiterals = false;
451
432
  if ((0, types_1.isTypeVar)(srcType)) {
452
433
  if (evaluator.assignType(destType, concreteSrcType,
@@ -542,26 +523,26 @@ function assignTypeToConstrainedTypeVar(evaluator, destType, srcType, diag, type
542
523
  else if ((0, typeUtils_1.isLiteralTypeOrUnion)(constrainedType)) {
543
524
  forceRetainLiterals = true;
544
525
  }
545
- if (curNarrowTypeBound && !(0, types_1.isAnyOrUnknown)(curNarrowTypeBound)) {
546
- if (!evaluator.assignType(curNarrowTypeBound, constrainedType,
526
+ if (curLowerBound && !(0, types_1.isAnyOrUnknown)(curLowerBound)) {
527
+ if (!evaluator.assignType(curLowerBound, constrainedType,
547
528
  /* diag */ undefined,
548
529
  /* destTypeVarContext */ undefined,
549
530
  /* srcTypeVarContext */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount)) {
550
531
  // Handle the case where one of the constrained types is a wider
551
532
  // version of another constrained type that was previously assigned
552
533
  // to the type variable.
553
- if (evaluator.assignType(constrainedType, curNarrowTypeBound,
534
+ if (evaluator.assignType(constrainedType, curLowerBound,
554
535
  /* diag */ undefined,
555
536
  /* destTypeVarContext */ undefined,
556
537
  /* srcTypeVarContext */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount)) {
557
538
  if (!typeVarContext.isLocked() && isTypeVarInScope) {
558
- updateTypeVarType(evaluator, typeVarContext, destType, constrainedType, curWideTypeBound);
539
+ updateTypeVarType(evaluator, typeVarContext, destType, constrainedType, curUpperBound);
559
540
  }
560
541
  }
561
542
  else {
562
543
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeConstrainedTypeVar().format({
563
544
  type: evaluator.printType(constrainedType),
564
- name: evaluator.printType(curNarrowTypeBound),
545
+ name: evaluator.printType(curLowerBound),
565
546
  }));
566
547
  return false;
567
548
  }
@@ -570,8 +551,7 @@ function assignTypeToConstrainedTypeVar(evaluator, destType, srcType, diag, type
570
551
  else {
571
552
  // Assign the type to the type var.
572
553
  if (!typeVarContext.isLocked() && isTypeVarInScope) {
573
- updateTypeVarType(evaluator, typeVarContext, destType, constrainedType, curWideTypeBound,
574
- /* tupleTypes */ undefined, forceRetainLiterals);
554
+ updateTypeVarType(evaluator, typeVarContext, destType, constrainedType, curUpperBound, forceRetainLiterals);
575
555
  }
576
556
  }
577
557
  return true;
@@ -579,9 +559,9 @@ function assignTypeToConstrainedTypeVar(evaluator, destType, srcType, diag, type
579
559
  function assignTypeToParamSpec(evaluator, destType, srcType, diag, typeVarContext, recursionCount = 0) {
580
560
  let isAssignable = true;
581
561
  const adjSrcType = (0, types_1.isFunction)(srcType) ? (0, typeUtils_1.convertParamSpecValueToType)(srcType) : srcType;
582
- typeVarContext.doForEachSignature((signatureContext) => {
583
- if ((0, types_1.isTypeVar)(adjSrcType) && adjSrcType.shared.isParamSpec) {
584
- const existingType = signatureContext.getParamSpecType(destType);
562
+ typeVarContext.doForEachSolutionSet((solutionSet) => {
563
+ if ((0, types_1.isParamSpec)(adjSrcType)) {
564
+ const existingType = solutionSet.getTypeVarType(destType);
585
565
  if (existingType) {
586
566
  const existingTypeParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(existingType);
587
567
  const existingTypeWithoutArgsKwargs = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(existingType);
@@ -594,7 +574,7 @@ function assignTypeToParamSpec(evaluator, destType, srcType, diag, typeVarContex
594
574
  }
595
575
  else {
596
576
  if (!typeVarContext.isLocked() && typeVarContext.hasSolveForScope(destType.priv.scopeId)) {
597
- signatureContext.setTypeVarType(destType, (0, typeUtils_1.convertTypeToParamSpecValue)(adjSrcType));
577
+ solutionSet.setTypeVarType(destType, (0, typeUtils_1.convertTypeToParamSpecValue)(adjSrcType));
598
578
  }
599
579
  return;
600
580
  }
@@ -602,7 +582,7 @@ function assignTypeToParamSpec(evaluator, destType, srcType, diag, typeVarContex
602
582
  else if ((0, types_1.isFunction)(adjSrcType)) {
603
583
  const newFunction = adjSrcType;
604
584
  let updateContextWithNewFunction = false;
605
- const existingType = signatureContext.getParamSpecType(destType);
585
+ const existingType = solutionSet.getTypeVarType(destType);
606
586
  if (existingType) {
607
587
  // Convert the remaining portion of the signature to a function
608
588
  // for comparison purposes.
@@ -610,11 +590,11 @@ function assignTypeToParamSpec(evaluator, destType, srcType, diag, typeVarContex
610
590
  const isNewNarrower = evaluator.assignType(existingFunction, newFunction,
611
591
  /* diag */ undefined,
612
592
  /* destTypeVarContext */ undefined,
613
- /* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */, recursionCount);
593
+ /* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.SkipReturnTypeCheck */, recursionCount);
614
594
  const isNewWider = evaluator.assignType(newFunction, existingFunction,
615
595
  /* diag */ undefined,
616
596
  /* destTypeVarContext */ undefined,
617
- /* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */, recursionCount);
597
+ /* srcTypeVarContext */ undefined, 64 /* AssignTypeFlags.SkipReturnTypeCheck */, recursionCount);
618
598
  // Should we widen the type?
619
599
  if (isNewNarrower && isNewWider) {
620
600
  // The new type is both a supertype and a subtype of the existing type.
@@ -643,7 +623,7 @@ function assignTypeToParamSpec(evaluator, destType, srcType, diag, typeVarContex
643
623
  }
644
624
  if (updateContextWithNewFunction) {
645
625
  if (!typeVarContext.isLocked() && typeVarContext.hasSolveForScope(destType.priv.scopeId)) {
646
- signatureContext.setTypeVarType(destType, newFunction);
626
+ solutionSet.setTypeVarType(destType, newFunction);
647
627
  }
648
628
  return;
649
629
  }
@@ -673,7 +653,7 @@ function assignTypeToParamSpec(evaluator, destType, srcType, diag, typeVarContex
673
653
  // it returns false.
674
654
  function addConstraintsForExpectedType(evaluator, type, expectedType, typeVarContext, liveTypeVarScopes, usageOffset = undefined) {
675
655
  if ((0, types_1.isAny)(expectedType)) {
676
- type.shared.typeParameters.forEach((typeParam) => {
656
+ type.shared.typeParams.forEach((typeParam) => {
677
657
  updateTypeVarType(evaluator, typeVarContext, typeParam, expectedType, expectedType);
678
658
  });
679
659
  return true;
@@ -685,84 +665,64 @@ function addConstraintsForExpectedType(evaluator, type, expectedType, typeVarCon
685
665
  return false;
686
666
  }
687
667
  // If the expected type is generic (but not specialized), we can't proceed.
688
- const expectedTypeArgs = expectedType.priv.typeArguments;
668
+ const expectedTypeArgs = expectedType.priv.typeArgs;
689
669
  if (!expectedTypeArgs) {
690
670
  return evaluator.assignType(type, expectedType,
691
671
  /* diag */ undefined, typeVarContext,
692
672
  /* srcTypeVarContext */ undefined, 2048 /* AssignTypeFlags.PopulatingExpectedType */);
693
673
  }
694
- evaluator.inferTypeParameterVarianceForClass(type);
674
+ evaluator.inferVarianceForClass(type);
695
675
  // If the expected type is the same as the target type (commonly the case),
696
676
  // we can use a faster method.
697
677
  if (types_1.ClassType.isSameGenericClass(expectedType, type)) {
698
678
  const sameClassTypeVarContext = (0, typeUtils_1.buildTypeVarContextFromSpecializedClass)(expectedType);
699
679
  sameClassTypeVarContext
700
- .getPrimarySignature()
680
+ .getMainSolutionSet()
701
681
  .getTypeVars()
702
682
  .forEach((entry) => {
703
- let typeArgValue = sameClassTypeVarContext.getPrimarySignature().getTypeVarType(entry.typeVar);
683
+ let typeArgValue = sameClassTypeVarContext.getMainSolutionSet().getTypeVarType(entry.typeVar);
704
684
  if (typeArgValue && liveTypeVarScopes) {
705
685
  typeArgValue = (0, typeUtils_1.transformExpectedType)(typeArgValue, liveTypeVarScopes, usageOffset);
706
686
  }
707
687
  if (typeArgValue) {
708
688
  const variance = types_1.TypeVarType.getVariance(entry.typeVar);
709
689
  updateTypeVarType(evaluator, typeVarContext, entry.typeVar, variance === 3 /* Variance.Covariant */ ? undefined : typeArgValue, variance === 4 /* Variance.Contravariant */ ? undefined : typeArgValue);
710
- if (entry.tupleTypes) {
711
- typeVarContext.setTupleTypeVar(entry.typeVar, entry.tupleTypes.map((tupleEntry) => {
712
- let tupleType = tupleEntry.type;
713
- if (liveTypeVarScopes) {
714
- tupleType = (0, typeUtils_1.transformExpectedType)(tupleEntry.type, liveTypeVarScopes, usageOffset);
715
- }
716
- return {
717
- type: tupleType,
718
- isUnbounded: tupleEntry.isUnbounded,
719
- isOptional: tupleEntry.isOptional,
720
- };
721
- }));
722
- }
723
690
  }
724
691
  });
725
692
  return true;
726
693
  }
727
694
  // Create a generic version of the expected type.
728
695
  const expectedTypeScopeId = (0, typeUtils_1.getTypeVarScopeId)(expectedType);
729
- const synthExpectedTypeArgs = types_1.ClassType.getTypeParameters(expectedType).map((typeParam, index) => {
730
- const typeVar = types_1.TypeVarType.createInstance(`__dest${index}`);
696
+ const synthExpectedTypeArgs = types_1.ClassType.getTypeParams(expectedType).map((typeParam, index) => {
697
+ const typeVar = types_1.TypeVarType.createInstance(`__dest${index}`, (0, types_1.isParamSpec)(typeParam) ? types_1.TypeVarKind.ParamSpec : types_1.TypeVarKind.TypeVar);
731
698
  typeVar.shared.isSynthesized = true;
732
- if (typeParam.shared.isParamSpec) {
733
- typeVar.shared.isParamSpec = true;
734
- }
735
- // Use invariance here so we set the narrow and wide values on the TypeVar.
699
+ // Use invariance here so we set the lower and upper bound on the TypeVar.
736
700
  typeVar.shared.declaredVariance = 2 /* Variance.Invariant */;
737
701
  typeVar.priv.scopeId = expectedTypeScopeId;
738
702
  return typeVar;
739
703
  });
740
- const genericExpectedType = types_1.ClassType.cloneForSpecialization(expectedType, synthExpectedTypeArgs,
741
- /* isTypeArgumentExplicit */ true);
704
+ const genericExpectedType = types_1.ClassType.specialize(expectedType, synthExpectedTypeArgs);
742
705
  // For each type param in the target type, create a placeholder type variable.
743
- const typeArgs = types_1.ClassType.getTypeParameters(type).map((typeParam, index) => {
744
- const typeVar = types_1.TypeVarType.createInstance(`__source${index}`);
706
+ const typeArgs = types_1.ClassType.getTypeParams(type).map((typeParam, index) => {
707
+ const typeVar = types_1.TypeVarType.createInstance(`__source${index}`, (0, types_1.isParamSpec)(typeParam) ? types_1.TypeVarKind.ParamSpec : types_1.TypeVarKind.TypeVar);
745
708
  typeVar.shared.isSynthesized = true;
746
709
  typeVar.shared.synthesizedIndex = index;
747
710
  typeVar.shared.isExemptFromBoundCheck = true;
748
- if (typeParam.shared.isParamSpec) {
749
- typeVar.shared.isParamSpec = true;
750
- }
751
711
  return types_1.TypeVarType.cloneAsInScopePlaceholder(typeVar);
752
712
  });
753
- const specializedType = types_1.ClassType.cloneForSpecialization(type, typeArgs, /* isTypeArgumentExplicit */ true);
713
+ const specializedType = types_1.ClassType.specialize(type, typeArgs);
754
714
  const syntheticTypeVarContext = new typeVarContext_1.TypeVarContext(expectedTypeScopeId);
755
715
  if (evaluator.assignType(genericExpectedType, specializedType,
756
716
  /* diag */ undefined, syntheticTypeVarContext,
757
717
  /* srcTypeVarContext */ undefined, 2048 /* AssignTypeFlags.PopulatingExpectedType */)) {
758
718
  let isResultValid = true;
759
719
  synthExpectedTypeArgs.forEach((typeVar, index) => {
760
- let synthTypeVar = syntheticTypeVarContext.getPrimarySignature().getTypeVarType(typeVar);
720
+ let synthTypeVar = syntheticTypeVarContext.getMainSolutionSet().getTypeVarType(typeVar);
761
721
  const otherSubtypes = [];
762
722
  // If the resulting type is a union, try to find a matching type var and move
763
723
  // the remaining subtypes to the "otherSubtypes" array.
764
724
  if (synthTypeVar) {
765
- if (typeVar.shared.isParamSpec && (0, types_1.isFunction)(synthTypeVar)) {
725
+ if ((0, types_1.isParamSpec)(typeVar) && (0, types_1.isFunction)(synthTypeVar)) {
766
726
  synthTypeVar = (0, typeUtils_1.convertParamSpecValueToType)(synthTypeVar);
767
727
  }
768
728
  if ((0, types_1.isUnion)(synthTypeVar)) {
@@ -789,7 +749,7 @@ function addConstraintsForExpectedType(evaluator, type, expectedType, typeVarCon
789
749
  (0, types_1.isTypeVar)(synthTypeVar) &&
790
750
  synthTypeVar.shared.isSynthesized &&
791
751
  synthTypeVar.shared.synthesizedIndex !== undefined) {
792
- const targetTypeVar = types_1.ClassType.getTypeParameters(specializedType)[synthTypeVar.shared.synthesizedIndex];
752
+ const targetTypeVar = types_1.ClassType.getTypeParams(specializedType)[synthTypeVar.shared.synthesizedIndex];
793
753
  if (index < expectedTypeArgs.length) {
794
754
  let typeArgValue = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expectedTypeArgs[index]);
795
755
  if (otherSubtypes.length > 0) {
@@ -803,7 +763,7 @@ function addConstraintsForExpectedType(evaluator, type, expectedType, typeVarCon
803
763
  // If this type variable already has a type, don't overwrite it. This can
804
764
  // happen if a single type variable in the derived class is used multiple times
805
765
  // in the specialized base class type (e.g. Mapping[T, T]).
806
- if (typeVarContext.getPrimarySignature().getTypeVarType(targetTypeVar)) {
766
+ if (typeVarContext.getMainSolutionSet().getTypeVarType(targetTypeVar)) {
807
767
  isResultValid = false;
808
768
  typeArgValue = types_1.UnknownType.create();
809
769
  }
@@ -823,7 +783,7 @@ exports.addConstraintsForExpectedType = addConstraintsForExpectedType;
823
783
  // For normal TypeVars, the constraint solver can widen a type by combining
824
784
  // two otherwise incompatible types into a union. For TypeVarTuples, we need
825
785
  // to do the equivalent operation for unpacked tuples.
826
- function widenTypeForVariadicTypeVar(evaluator, type1, type2) {
786
+ function widenTypeForTypeVarTuple(evaluator, type1, type2) {
827
787
  // The typing spec indicates that the type should always be "exactly
828
788
  // the same type" if a TypeVarTuple is used in multiple locations.
829
789
  // This is problematic for a number of reasons, but in the interest
@@ -833,9 +793,9 @@ function widenTypeForVariadicTypeVar(evaluator, type1, type2) {
833
793
  return undefined;
834
794
  }
835
795
  // If the two unpacked tuples are not the same length, we can't combine them.
836
- if (!type1.priv.tupleTypeArguments ||
837
- !type2.priv.tupleTypeArguments ||
838
- type1.priv.tupleTypeArguments.length !== type2.priv.tupleTypeArguments.length) {
796
+ if (!type1.priv.tupleTypeArgs ||
797
+ !type2.priv.tupleTypeArgs ||
798
+ type1.priv.tupleTypeArgs.length !== type2.priv.tupleTypeArgs.length) {
839
799
  return undefined;
840
800
  }
841
801
  const strippedType1 = stripLiteralValueForUnpackedTuple(evaluator, type1);
@@ -848,11 +808,11 @@ function widenTypeForVariadicTypeVar(evaluator, type1, type2) {
848
808
  // If the provided type is an unpacked tuple, this function strips the
849
809
  // literals from types of the corresponding elements.
850
810
  function stripLiteralValueForUnpackedTuple(evaluator, type) {
851
- if (!(0, types_1.isUnpackedClass)(type) || !type.priv.tupleTypeArguments) {
811
+ if (!(0, types_1.isUnpackedClass)(type) || !type.priv.tupleTypeArgs) {
852
812
  return type;
853
813
  }
854
814
  let strippedLiteral = false;
855
- const tupleTypeArgs = type.priv.tupleTypeArguments.map((arg) => {
815
+ const tupleTypeArgs = type.priv.tupleTypeArgs.map((arg) => {
856
816
  const strippedType = evaluator.stripLiteralValue(arg.type);
857
817
  if (strippedType !== arg.type) {
858
818
  strippedLiteral = true;
@@ -866,44 +826,44 @@ function stripLiteralValueForUnpackedTuple(evaluator, type) {
866
826
  if (!strippedLiteral) {
867
827
  return type;
868
828
  }
869
- return (0, typeUtils_1.specializeTupleClass)(type, tupleTypeArgs, /* isTypeArgumentExplicit */ true, /* isUnpackedTuple */ true);
829
+ return (0, typeUtils_1.specializeTupleClass)(type, tupleTypeArgs, /* isTypeArgExplicit */ true, /* isUnpackedTuple */ true);
870
830
  }
871
831
  // This function is used for debugging only. It dumps the current contents of
872
832
  // the TypeVarContext to the console.
873
833
  function logTypeVarContext(evaluator, typeVarContext, indent) {
874
- const signatureContextCount = typeVarContext.getSignatureContexts().length;
875
- if (signatureContextCount === 0) {
834
+ const solutionSetCount = typeVarContext.getSolutionSets().length;
835
+ if (solutionSetCount === 0) {
876
836
  console.log(`${indent} no signatures`);
877
837
  }
878
- else if (signatureContextCount === 1) {
879
- logTypeVarSignatureContext(evaluator, typeVarContext.getSignatureContexts()[0], `${indent} `);
838
+ else if (solutionSetCount === 1) {
839
+ logTypeVarSolutionSet(evaluator, typeVarContext.getSolutionSets()[0], `${indent} `);
880
840
  }
881
841
  else {
882
- typeVarContext.doForEachSignatureContext((context, signatureIndex) => {
883
- console.log(`${indent} signature ${signatureIndex}`);
884
- logTypeVarSignatureContext(evaluator, context, `${indent} `);
842
+ typeVarContext.doForEachSolutionSet((solutionSet, index) => {
843
+ console.log(`${indent} signature ${index}`);
844
+ logTypeVarSolutionSet(evaluator, solutionSet, `${indent} `);
885
845
  });
886
846
  }
887
847
  }
888
- function logTypeVarSignatureContext(evaluator, context, indent) {
848
+ function logTypeVarSolutionSet(evaluator, context, indent) {
889
849
  let loggedConstraint = false;
890
850
  context.getTypeVars().forEach((entry) => {
891
851
  var _a;
892
852
  const typeVarName = `${indent}${entry.typeVar.shared.name}`;
893
- const narrowBound = (_a = entry.narrowBoundNoLiterals) !== null && _a !== void 0 ? _a : entry.narrowBound;
894
- const wideBound = entry.wideBound;
895
- // Log the narrow and wide bounds.
896
- if (narrowBound && wideBound && (0, types_1.isTypeSame)(narrowBound, wideBound)) {
897
- console.log(`${typeVarName} = ${evaluator.printType(narrowBound)}`);
853
+ const lowerBound = (_a = entry.lowerBoundNoLiterals) !== null && _a !== void 0 ? _a : entry.lowerBound;
854
+ const upperBound = entry.upperBound;
855
+ // Log the lower and upper bounds.
856
+ if (lowerBound && upperBound && (0, types_1.isTypeSame)(lowerBound, upperBound)) {
857
+ console.log(`${typeVarName} = ${evaluator.printType(lowerBound)}`);
898
858
  loggedConstraint = true;
899
859
  }
900
860
  else {
901
- if (narrowBound) {
902
- console.log(`${typeVarName} ≤ ${evaluator.printType(narrowBound)}`);
861
+ if (lowerBound) {
862
+ console.log(`${typeVarName} ≤ ${evaluator.printType(lowerBound)}`);
903
863
  loggedConstraint = true;
904
864
  }
905
- if (wideBound) {
906
- console.log(`${typeVarName} ≥ ${evaluator.printType(wideBound)}`);
865
+ if (upperBound) {
866
+ console.log(`${typeVarName} ≥ ${evaluator.printType(upperBound)}`);
907
867
  loggedConstraint = true;
908
868
  }
909
869
  }