@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
@@ -8,9 +8,9 @@
8
8
  * Functions that operate on Type objects.
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.isTupleGradualForm = exports.isMaybeDescriptorInstance = exports.isDescriptorInstance = exports.isCallableType = exports.isProperty = exports.isEllipsisType = exports.getUnionSubtypeCount = exports.getLiteralTypeClassName = exports.containsLiteralType = exports.isLiteralTypeOrUnion = exports.isLiteralType = exports.getSpecializedTupleType = exports.selfSpecializeClass = exports.getUnknownTypeForCallable = exports.getUnknownTypeForVariadicTypeVar = exports.getUnknownTypeForParamSpec = exports.getUnknownTypeForTypeVar = exports.specializeWithUnknownTypeArgs = exports.specializeWithDefaultTypeArgs = exports.getTypeVarScopeIds = exports.getTypeVarScopeId = exports.transformPossibleRecursiveTypeAlias = exports.isTypeAliasRecursive = exports.isTypeAliasPlaceholder = exports.getTypeCondition = exports.addConditionToType = exports.getFullNameOfType = exports.derivesFromAnyOrUnknown = exports.isUnionableType = exports.preserveUnknown = exports.areTypesSame = exports.doForEachSignature = exports.allSubtypes = exports.someSubtypes = exports.doForEachSubtype = exports.sortTypes = exports.cleanIncompleteUnknown = exports.mapSignatures = exports.mapSubtypes = exports.makeInferenceContext = exports.isTypeVarSame = exports.isIncompleteUnknown = exports.removeNoneFromUnion = exports.isNoneTypeClass = exports.isNoneInstance = exports.isOptionalType = exports.UniqueSignatureTracker = exports.AssignTypeFlags = exports.ClassIteratorFlags = exports.MemberAccessFlags = void 0;
12
- exports.combineVariances = exports.requiresSpecialization = exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.specializeTupleClass = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsAnyOrUnknown = exports.containsAnyRecursive = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.isMetaclassInstance = exports.isInstantiableMetaclass = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.derivesFromStdlibClass = exports.specializeForBaseClass = exports.buildTypeVarContext = exports.buildTypeVarContextFromSpecializedClass = exports.setTypeArgumentsRecursive = exports.specializeClassType = exports.getTypeVarArgumentsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = exports.lookUpClassMember = exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbolsRecursive = exports.getProtocolSymbols = exports.transformExpectedType = exports.replaceTypeVarsWithAny = exports.validateTypeVarDefault = exports.applyInScopePlaceholders = exports.applySourceContextTypeVarsToSignature = exports.applySourceContextTypeVars = exports.applySolvedTypeVars = exports.ensureFunctionSignaturesAreUnique = exports.populateTypeVarContextForSelfType = exports.partiallySpecializeType = exports.isTupleIndexUnambiguous = exports.isUnboundedTupleClass = exports.isTupleClass = void 0;
13
- exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.convertArgumentNodeToFunctionArgument = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgumentCompatible = void 0;
11
+ exports.isTupleClass = exports.isTupleGradualForm = exports.isMaybeDescriptorInstance = exports.isDescriptorInstance = exports.isCallableType = exports.isProperty = exports.isEllipsisType = exports.getUnionSubtypeCount = exports.getLiteralTypeClassName = exports.containsLiteralType = exports.isLiteralTypeOrUnion = exports.isLiteralType = exports.getSpecializedTupleType = exports.selfSpecializeClass = exports.getUnknownTypeForCallable = exports.getUnknownForTypeVarTuple = exports.getUnknownForTypeVar = exports.specializeWithUnknownTypeArgs = exports.specializeWithDefaultTypeArgs = exports.getTypeVarScopeIds = exports.getTypeVarScopeId = exports.transformPossibleRecursiveTypeAlias = exports.isTypeAliasRecursive = exports.isTypeAliasPlaceholder = exports.getTypeCondition = exports.addConditionToType = exports.getFullNameOfType = exports.derivesFromAnyOrUnknown = exports.isUnionableType = exports.preserveUnknown = exports.areTypesSame = exports.doForEachSignature = exports.allSubtypes = exports.someSubtypes = exports.doForEachSubtype = exports.sortTypes = exports.cleanIncompleteUnknown = exports.mapSignatures = exports.mapSubtypes = exports.makeInferenceContext = exports.isTypeVarSame = exports.isIncompleteUnknown = exports.removeNoneFromUnion = exports.isNoneTypeClass = exports.isNoneInstance = exports.isOptionalType = exports.UniqueSignatureTracker = exports.AssignTypeFlags = exports.ClassIteratorFlags = exports.MemberAccessFlags = void 0;
12
+ exports.requiresTypeArgs = exports.getGeneratorTypeArgs = exports.specializeTupleClass = exports.combineTupleTypeArgs = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsAnyOrUnknown = exports.containsAnyRecursive = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.isMetaclassInstance = exports.isInstantiableMetaclass = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.derivesFromStdlibClass = exports.specializeForBaseClass = exports.buildTypeVarContext = exports.buildTypeVarContextFromSpecializedClass = exports.setTypeArgsRecursive = exports.specializeClassType = exports.getTypeVarArgsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = exports.lookUpClassMember = exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbolsRecursive = exports.getProtocolSymbols = exports.transformExpectedType = exports.replaceTypeVarsWithAny = exports.validateTypeVarDefault = exports.applyInScopePlaceholders = exports.applySourceContextTypeVarsToSignature = exports.applySourceContextTypeVars = exports.applySolvedTypeVars = exports.updateTypeWithExternalTypeVars = exports.updateTypeWithInternalTypeVars = exports.ensureFunctionSignaturesAreUnique = exports.populateTypeVarContextForSelfType = exports.partiallySpecializeType = exports.isTupleIndexUnambiguous = exports.isUnboundedTupleClass = void 0;
13
+ exports.convertParamSpecValueToType = exports.setTypeVarType = exports.convertTypeToParamSpecValue = exports.convertNodeToArg = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgCompatible = exports.combineVariances = exports.requiresSpecialization = void 0;
14
14
  const collectionUtils_1 = require("../common/collectionUtils");
15
15
  const debug_1 = require("../common/debug");
16
16
  const symbol_1 = require("./symbol");
@@ -96,15 +96,13 @@ var AssignTypeFlags;
96
96
  // as incompatible. Also, treat all source TypeVars as their
97
97
  // concrete counterparts. This option is used for validating
98
98
  // whether overload signatures overlap.
99
- AssignTypeFlags[AssignTypeFlags["OverloadOverlapCheck"] = 16] = "OverloadOverlapCheck";
99
+ AssignTypeFlags[AssignTypeFlags["OverloadOverlap"] = 16] = "OverloadOverlap";
100
100
  // When used in conjunction with OverloadOverlapCheck, look
101
101
  // for partial overlaps. For example, `int | list` overlaps
102
102
  // partially with `int | str`.
103
- AssignTypeFlags[AssignTypeFlags["PartialOverloadOverlapCheck"] = 32] = "PartialOverloadOverlapCheck";
103
+ AssignTypeFlags[AssignTypeFlags["PartialOverloadOverlap"] = 32] = "PartialOverloadOverlap";
104
104
  // For function types, skip the return type check.
105
- AssignTypeFlags[AssignTypeFlags["SkipFunctionReturnTypeCheck"] = 64] = "SkipFunctionReturnTypeCheck";
106
- // Allow bool values to be assigned to TypeGuard[x] types.
107
- AssignTypeFlags[AssignTypeFlags["AllowBoolTypeGuard"] = 128] = "AllowBoolTypeGuard";
105
+ AssignTypeFlags[AssignTypeFlags["SkipReturnTypeCheck"] = 64] = "SkipReturnTypeCheck";
108
106
  // In most cases, literals are stripped when assigning to a
109
107
  // type variable. This overrides the standard behavior.
110
108
  AssignTypeFlags[AssignTypeFlags["RetainLiteralsForTypeVar"] = 256] = "RetainLiteralsForTypeVar";
@@ -128,18 +126,14 @@ var AssignTypeFlags;
128
126
  // hasn't previously been specialized, it will be specialized with
129
127
  // default type arguments (typically "Unknown"). This flag skips
130
128
  // this step.
131
- AssignTypeFlags[AssignTypeFlags["AllowUnspecifiedTypeArguments"] = 8192] = "AllowUnspecifiedTypeArguments";
132
- // PEP 544 says that if the dest type is a type[Proto] class,
133
- // the source must be a "concrete" (non-protocol) class. This
134
- // flag skips this check.
135
- AssignTypeFlags[AssignTypeFlags["IgnoreProtocolAssignmentCheck"] = 16384] = "IgnoreProtocolAssignmentCheck";
129
+ AssignTypeFlags[AssignTypeFlags["AllowUnspecifiedTypeArgs"] = 8192] = "AllowUnspecifiedTypeArgs";
136
130
  // Normally all special form classes are incompatible with type[T],
137
131
  // but a few of them are allowed in the context of an isinstance
138
132
  // or issubclass call.
139
- AssignTypeFlags[AssignTypeFlags["AllowIsinstanceSpecialForms"] = 32768] = "AllowIsinstanceSpecialForms";
133
+ AssignTypeFlags[AssignTypeFlags["AllowIsinstanceSpecialForms"] = 16384] = "AllowIsinstanceSpecialForms";
140
134
  // When comparing two methods, skip the type check for the "self" or "cls"
141
135
  // parameters. This is used for variance inference and validation.
142
- AssignTypeFlags[AssignTypeFlags["IgnoreSelfClsParamCompatibility"] = 65536] = "IgnoreSelfClsParamCompatibility";
136
+ AssignTypeFlags[AssignTypeFlags["SkipSelfClsParamCheck"] = 32768] = "SkipSelfClsParamCheck";
143
137
  })(AssignTypeFlags || (exports.AssignTypeFlags = AssignTypeFlags = {}));
144
138
  // Tracks whether a function signature has been seen before within
145
139
  // an expression. For example, in the expression "foo(foo, foo)", the
@@ -220,7 +214,7 @@ function isTypeVarSame(type1, type2) {
220
214
  return true;
221
215
  }
222
216
  // If this isn't a bound TypeVar, return false.
223
- if (type1.shared.isParamSpec || type1.shared.isVariadic || !type1.shared.boundType) {
217
+ if ((0, types_1.isParamSpec)(type1) || (0, types_1.isTypeVarTuple)(type1) || !type1.shared.boundType) {
224
218
  return false;
225
219
  }
226
220
  // If the second type isn't a union, return false.
@@ -243,17 +237,18 @@ function isTypeVarSame(type1, type2) {
243
237
  return isCompatible;
244
238
  }
245
239
  exports.isTypeVarSame = isTypeVarSame;
246
- function makeInferenceContext(expectedType, isTypeIncomplete) {
240
+ function makeInferenceContext(expectedType, isTypeIncomplete, returnTypeOverride) {
247
241
  if (!expectedType) {
248
242
  return undefined;
249
243
  }
250
- return { expectedType, isTypeIncomplete };
244
+ return { expectedType, isTypeIncomplete, returnTypeOverride };
251
245
  }
252
246
  exports.makeInferenceContext = makeInferenceContext;
253
247
  // Calls a callback for each subtype and combines the results
254
248
  // into a final type. It performs no memory allocations if the
255
249
  // transformed type is the same as the original.
256
250
  function mapSubtypes(type, callback, options) {
251
+ var _a;
257
252
  if ((0, types_1.isUnion)(type)) {
258
253
  const subtypes = (options === null || options === void 0 ? void 0 : options.sortSubtypes) ? sortTypes(type.priv.subtypes) : type.priv.subtypes;
259
254
  for (let i = 0; i < subtypes.length; i++) {
@@ -275,9 +270,16 @@ function mapSubtypes(type, callback, options) {
275
270
  const newType = (0, types_1.combineTypes)(typesToCombine, {
276
271
  skipElideRedundantLiterals: options === null || options === void 0 ? void 0 : options.skipElideRedundantLiterals,
277
272
  });
278
- // Do our best to retain type aliases.
279
- if (newType.category === 8 /* TypeCategory.Union */) {
280
- types_1.UnionType.addTypeAliasSource(newType, type);
273
+ if (options === null || options === void 0 ? void 0 : options.retainTypeAlias) {
274
+ if ((_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo) {
275
+ types_1.TypeBase.setTypeAliasInfo(newType, type.props.typeAliasInfo);
276
+ }
277
+ }
278
+ else {
279
+ // Do our best to retain type aliases.
280
+ if (newType.category === 8 /* TypeCategory.Union */) {
281
+ types_1.UnionType.addTypeAliasSource(newType, type);
282
+ }
281
283
  }
282
284
  return newType;
283
285
  }
@@ -345,10 +347,10 @@ function cleanIncompleteUnknown(type, recursionCount = 0) {
345
347
  if ((0, types_1.isUnknown)(subtype) && subtype.priv.isIncomplete) {
346
348
  return undefined;
347
349
  }
348
- if ((0, types_1.isClass)(subtype) && subtype.priv.typeArguments) {
350
+ if ((0, types_1.isClass)(subtype) && subtype.priv.typeArgs) {
349
351
  let typeChanged = false;
350
- if (subtype.priv.tupleTypeArguments) {
351
- const updatedTupleTypeArgs = subtype.priv.tupleTypeArguments.map((tupleTypeArg) => {
352
+ if (subtype.priv.tupleTypeArgs) {
353
+ const updatedTupleTypeArgs = subtype.priv.tupleTypeArgs.map((tupleTypeArg) => {
352
354
  const newTypeArg = cleanIncompleteUnknown(tupleTypeArg.type, recursionCount);
353
355
  if (newTypeArg !== tupleTypeArg.type) {
354
356
  typeChanged = true;
@@ -360,11 +362,11 @@ function cleanIncompleteUnknown(type, recursionCount = 0) {
360
362
  };
361
363
  });
362
364
  if (typeChanged) {
363
- return specializeTupleClass(subtype, updatedTupleTypeArgs, !!subtype.priv.isTypeArgumentExplicit, !!subtype.priv.isUnpacked);
365
+ return specializeTupleClass(subtype, updatedTupleTypeArgs, !!subtype.priv.isTypeArgExplicit, !!subtype.priv.isUnpacked);
364
366
  }
365
367
  }
366
368
  else {
367
- const updatedTypeArgs = subtype.priv.typeArguments.map((typeArg) => {
369
+ const updatedTypeArgs = subtype.priv.typeArgs.map((typeArg) => {
368
370
  const newTypeArg = cleanIncompleteUnknown(typeArg, recursionCount);
369
371
  if (newTypeArg !== typeArg) {
370
372
  typeChanged = true;
@@ -372,7 +374,7 @@ function cleanIncompleteUnknown(type, recursionCount = 0) {
372
374
  return newTypeArg;
373
375
  });
374
376
  if (typeChanged) {
375
- return types_1.ClassType.cloneForSpecialization(subtype, updatedTypeArgs, !!subtype.priv.isTypeArgumentExplicit);
377
+ return types_1.ClassType.specialize(subtype, updatedTypeArgs, !!subtype.priv.isTypeArgExplicit);
376
378
  }
377
379
  }
378
380
  }
@@ -420,7 +422,7 @@ function compareTypes(a, b, recursionCount = 0) {
420
422
  if (aParam.category !== bParam.category) {
421
423
  return bParam.category - aParam.category;
422
424
  }
423
- const typeComparison = compareTypes(types_1.FunctionType.getEffectiveParameterType(a, i), types_1.FunctionType.getEffectiveParameterType(bFunc, i));
425
+ const typeComparison = compareTypes(types_1.FunctionType.getEffectiveParamType(a, i), types_1.FunctionType.getEffectiveParamType(bFunc, i));
424
426
  if (typeComparison !== 0) {
425
427
  return typeComparison;
426
428
  }
@@ -480,12 +482,12 @@ function compareTypes(a, b, recursionCount = 0) {
480
482
  return -1;
481
483
  }
482
484
  // Sort non-generics before generics.
483
- if (a.shared.typeParameters.length > 0 || isTupleClass(a)) {
484
- if (bClass.shared.typeParameters.length === 0) {
485
+ if (a.shared.typeParams.length > 0 || isTupleClass(a)) {
486
+ if (bClass.shared.typeParams.length === 0) {
485
487
  return 1;
486
488
  }
487
489
  }
488
- else if (bClass.shared.typeParameters.length > 0 || isTupleClass(bClass)) {
490
+ else if (bClass.shared.typeParams.length > 0 || isTupleClass(bClass)) {
489
491
  return -1;
490
492
  }
491
493
  // Sort by class name.
@@ -498,8 +500,8 @@ function compareTypes(a, b, recursionCount = 0) {
498
500
  return 1;
499
501
  }
500
502
  // Sort by type argument count.
501
- const aTypeArgCount = a.priv.typeArguments ? a.priv.typeArguments.length : 0;
502
- const bTypeArgCount = bClass.priv.typeArguments ? bClass.priv.typeArguments.length : 0;
503
+ const aTypeArgCount = a.priv.typeArgs ? a.priv.typeArgs.length : 0;
504
+ const bTypeArgCount = bClass.priv.typeArgs ? bClass.priv.typeArgs.length : 0;
503
505
  if (aTypeArgCount < bTypeArgCount) {
504
506
  return -1;
505
507
  }
@@ -508,7 +510,7 @@ function compareTypes(a, b, recursionCount = 0) {
508
510
  }
509
511
  // Sort by type argument.
510
512
  for (let i = 0; i < aTypeArgCount; i++) {
511
- const typeComparison = compareTypes(a.priv.typeArguments[i], bClass.priv.typeArguments[i], recursionCount);
513
+ const typeComparison = compareTypes(a.priv.typeArgs[i], bClass.priv.typeArgs[i], recursionCount);
512
514
  if (typeComparison !== 0) {
513
515
  return typeComparison;
514
516
  }
@@ -740,17 +742,17 @@ function transformPossibleRecursiveTypeAlias(type) {
740
742
  const unspecializedType = types_1.TypeBase.isInstance(type)
741
743
  ? convertToInstance(type.shared.boundType)
742
744
  : type.shared.boundType;
743
- if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments) || !type.shared.recursiveAlias.typeParameters) {
745
+ if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArgs) || !type.shared.recursiveAlias.typeParams) {
744
746
  return unspecializedType;
745
747
  }
746
- const typeVarContext = buildTypeVarContext(type.shared.recursiveAlias.typeParameters, aliasInfo.typeArguments, getTypeVarScopeId(type));
748
+ const typeVarContext = buildTypeVarContext(type.shared.recursiveAlias.typeParams, aliasInfo.typeArgs, getTypeVarScopeId(type));
747
749
  return applySolvedTypeVars(unspecializedType, typeVarContext);
748
750
  }
749
751
  if ((0, types_1.isUnion)(type) && type.priv.includesRecursiveTypeAlias) {
750
752
  let newType = mapSubtypes(type, (subtype) => transformPossibleRecursiveTypeAlias(subtype));
751
753
  if (newType !== type && aliasInfo) {
752
754
  // Copy the type alias information if present.
753
- newType = types_1.TypeBase.cloneForTypeAlias(newType, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParameters, aliasInfo.typeArguments);
755
+ newType = types_1.TypeBase.cloneForTypeAlias(newType, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParams, aliasInfo.typeArgs);
754
756
  }
755
757
  return newType;
756
758
  }
@@ -794,58 +796,51 @@ exports.getTypeVarScopeIds = getTypeVarScopeIds;
794
796
  // specified, specialize it with default type arguments (Unknown or the
795
797
  // default type if provided).
796
798
  function specializeWithDefaultTypeArgs(type) {
797
- if (type.shared.typeParameters.length === 0 || type.priv.typeArguments) {
799
+ if (type.shared.typeParams.length === 0 || type.priv.typeArgs) {
798
800
  return type;
799
801
  }
800
- return types_1.ClassType.cloneForSpecialization(type, type.shared.typeParameters.map((param) => param.shared.defaultType),
801
- /* isTypeArgumentExplicit */ false,
802
+ return types_1.ClassType.specialize(type, type.shared.typeParams.map((param) => param.shared.defaultType),
803
+ /* isTypeArgExplicit */ false,
802
804
  /* includeSubclasses */ type.priv.includeSubclasses);
803
805
  }
804
806
  exports.specializeWithDefaultTypeArgs = specializeWithDefaultTypeArgs;
805
807
  // Specializes the class with "Unknown" type args (or the equivalent for ParamSpecs
806
808
  // or TypeVarTuples).
807
809
  function specializeWithUnknownTypeArgs(type, tupleClassType) {
808
- if (type.shared.typeParameters.length === 0) {
810
+ if (type.shared.typeParams.length === 0) {
809
811
  return type;
810
812
  }
811
813
  if (isTupleClass(type)) {
812
814
  return types_1.ClassType.cloneIncludeSubclasses(specializeTupleClass(type, [{ type: types_1.UnknownType.create(), isUnbounded: true }],
813
- /* isTypeArgumentExplicit */ false), !!type.priv.includeSubclasses);
815
+ /* isTypeArgExplicit */ false), !!type.priv.includeSubclasses);
814
816
  }
815
- return types_1.ClassType.cloneForSpecialization(type, type.shared.typeParameters.map((param) => getUnknownTypeForTypeVar(param, tupleClassType)),
816
- /* isTypeArgumentExplicit */ false,
817
+ return types_1.ClassType.specialize(type, type.shared.typeParams.map((param) => getUnknownForTypeVar(param, tupleClassType)),
818
+ /* isTypeArgExplicit */ false,
817
819
  /* includeSubclasses */ type.priv.includeSubclasses);
818
820
  }
819
821
  exports.specializeWithUnknownTypeArgs = specializeWithUnknownTypeArgs;
820
822
  // Returns "Unknown" for simple TypeVars or the equivalent for a ParamSpec.
821
- function getUnknownTypeForTypeVar(typeVar, tupleClassType) {
822
- if (typeVar.shared.isParamSpec) {
823
- return getUnknownTypeForParamSpec();
823
+ function getUnknownForTypeVar(typeVar, tupleClassType) {
824
+ if ((0, types_1.isParamSpec)(typeVar)) {
825
+ return types_1.ParamSpecType.getUnknown();
824
826
  }
825
- if (typeVar.shared.isVariadic && tupleClassType) {
826
- return getUnknownTypeForVariadicTypeVar(tupleClassType);
827
+ if ((0, types_1.isTypeVarTuple)(typeVar) && tupleClassType) {
828
+ return getUnknownForTypeVarTuple(tupleClassType);
827
829
  }
828
830
  return types_1.UnknownType.create();
829
831
  }
830
- exports.getUnknownTypeForTypeVar = getUnknownTypeForTypeVar;
831
- // Returns the "Unknown" equivalent for a ParamSpec.
832
- function getUnknownTypeForParamSpec() {
833
- const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.GradualCallableForm */);
834
- types_1.FunctionType.addDefaultParameters(newFunction);
835
- return newFunction;
836
- }
837
- exports.getUnknownTypeForParamSpec = getUnknownTypeForParamSpec;
838
- function getUnknownTypeForVariadicTypeVar(tupleClassType) {
832
+ exports.getUnknownForTypeVar = getUnknownForTypeVar;
833
+ function getUnknownForTypeVarTuple(tupleClassType) {
839
834
  (0, debug_1.assert)((0, types_1.isInstantiableClass)(tupleClassType) && types_1.ClassType.isBuiltIn(tupleClassType, 'tuple'));
840
835
  return types_1.ClassType.cloneAsInstance(specializeTupleClass(tupleClassType, [{ type: types_1.UnknownType.create(), isUnbounded: true }],
841
- /* isTypeArgumentExplicit */ true,
836
+ /* isTypeArgExplicit */ true,
842
837
  /* isUnpackedTuple */ true));
843
838
  }
844
- exports.getUnknownTypeForVariadicTypeVar = getUnknownTypeForVariadicTypeVar;
839
+ exports.getUnknownForTypeVarTuple = getUnknownForTypeVarTuple;
845
840
  // Returns the equivalent of "Callable[..., Unknown]".
846
841
  function getUnknownTypeForCallable() {
847
842
  const newFunction = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.GradualCallableForm */);
848
- types_1.FunctionType.addDefaultParameters(newFunction);
843
+ types_1.FunctionType.addDefaultParams(newFunction);
849
844
  newFunction.shared.declaredReturnType = types_1.UnknownType.create();
850
845
  return newFunction;
851
846
  }
@@ -854,14 +849,16 @@ exports.getUnknownTypeForCallable = getUnknownTypeForCallable;
854
849
  // "self specializes" the class, filling in its own type parameters
855
850
  // as type arguments.
856
851
  function selfSpecializeClass(type, options) {
857
- if (type.shared.typeParameters.length === 0) {
852
+ if (type.shared.typeParams.length === 0) {
858
853
  return type;
859
854
  }
860
- if (type.priv.typeArguments && !(options === null || options === void 0 ? void 0 : options.overrideTypeArgs)) {
855
+ if (type.priv.typeArgs && !(options === null || options === void 0 ? void 0 : options.overrideTypeArgs)) {
861
856
  return type;
862
857
  }
863
- const typeParams = type.shared.typeParameters;
864
- return types_1.ClassType.cloneForSpecialization(type, typeParams, /* isTypeArgumentExplicit */ true);
858
+ const typeParams = type.shared.typeParams.map((typeParam) => {
859
+ return (options === null || options === void 0 ? void 0 : options.useInternalTypeVars) ? types_1.TypeVarType.cloneWithInternalScopeId(typeParam) : typeParam;
860
+ });
861
+ return types_1.ClassType.specialize(type, typeParams);
865
862
  }
866
863
  exports.selfSpecializeClass = selfSpecializeClass;
867
864
  // Determines whether the type derives from tuple. If so, it returns
@@ -1028,10 +1025,10 @@ exports.isMaybeDescriptorInstance = isMaybeDescriptorInstance;
1028
1025
  function isTupleGradualForm(type) {
1029
1026
  return ((0, types_1.isClassInstance)(type) &&
1030
1027
  isTupleClass(type) &&
1031
- type.priv.tupleTypeArguments &&
1032
- type.priv.tupleTypeArguments.length === 1 &&
1033
- (0, types_1.isAnyOrUnknown)(type.priv.tupleTypeArguments[0].type) &&
1034
- type.priv.tupleTypeArguments[0].isUnbounded);
1028
+ type.priv.tupleTypeArgs &&
1029
+ type.priv.tupleTypeArgs.length === 1 &&
1030
+ (0, types_1.isAnyOrUnknown)(type.priv.tupleTypeArgs[0].type) &&
1031
+ type.priv.tupleTypeArgs[0].isUnbounded);
1035
1032
  }
1036
1033
  exports.isTupleGradualForm = isTupleGradualForm;
1037
1034
  function isTupleClass(type) {
@@ -1042,32 +1039,30 @@ exports.isTupleClass = isTupleClass;
1042
1039
  // the form tuple[x, ...] where the number of elements
1043
1040
  // in the tuple is unknown.
1044
1041
  function isUnboundedTupleClass(type) {
1045
- return (type.priv.tupleTypeArguments &&
1046
- type.priv.tupleTypeArguments.some((t) => t.isUnbounded || (0, types_1.isUnpackedVariadicTypeVar)(t.type)));
1042
+ var _a;
1043
+ return (_a = type.priv.tupleTypeArgs) === null || _a === void 0 ? void 0 : _a.some((t) => t.isUnbounded || (0, types_1.isUnpackedTypeVarTuple)(t.type));
1047
1044
  }
1048
1045
  exports.isUnboundedTupleClass = isUnboundedTupleClass;
1049
1046
  // Indicates whether the specified index is within range and its type is unambiguous
1050
1047
  // in that it doesn't involve any element ranges that are of indeterminate length.
1051
1048
  function isTupleIndexUnambiguous(type, index) {
1052
- if (!type.priv.tupleTypeArguments) {
1049
+ if (!type.priv.tupleTypeArgs) {
1053
1050
  return false;
1054
1051
  }
1052
+ const unboundedIndex = type.priv.tupleTypeArgs.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedTypeVarTuple)(t.type));
1055
1053
  if (index < 0) {
1056
- if (isUnboundedTupleClass(type) || type.priv.tupleTypeArguments.length + index < 0) {
1057
- return false;
1058
- }
1059
- }
1060
- let unambiguousIndexLimit = type.priv.tupleTypeArguments.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedVariadicTypeVar)(t.type));
1061
- if (unambiguousIndexLimit < 0) {
1062
- unambiguousIndexLimit = type.priv.tupleTypeArguments.length;
1054
+ const lowerIndexLimit = unboundedIndex < 0 ? 0 : unboundedIndex;
1055
+ index += type.priv.tupleTypeArgs.length;
1056
+ return index >= lowerIndexLimit;
1063
1057
  }
1064
- return index < unambiguousIndexLimit;
1058
+ const upperIndexLimit = unboundedIndex < 0 ? type.priv.tupleTypeArgs.length : unboundedIndex;
1059
+ return index < upperIndexLimit;
1065
1060
  }
1066
1061
  exports.isTupleIndexUnambiguous = isTupleIndexUnambiguous;
1067
1062
  // Partially specializes a type within the context of a specified
1068
1063
  // (presumably specialized) class. Optionally specializes the `Self`
1069
1064
  // type variables, replacing them with selfClass.
1070
- function partiallySpecializeType(type, contextClassType, selfClass, typeClassType) {
1065
+ function partiallySpecializeType(type, contextClassType, typeClassType, selfClass) {
1071
1066
  // If the context class is not specialized (or doesn't need specialization),
1072
1067
  // then there's no need to do any more work.
1073
1068
  if (types_1.ClassType.isUnspecialized(contextClassType) && !selfClass) {
@@ -1088,7 +1083,7 @@ function partiallySpecializeType(type, contextClassType, selfClass, typeClassTyp
1088
1083
  return undefined;
1089
1084
  }
1090
1085
  return {
1091
- methodType: partiallySpecializeType(methodInfo.methodType, contextClassType, selfClass, typeClassType),
1086
+ methodType: partiallySpecializeType(methodInfo.methodType, contextClassType, typeClassType, selfClass),
1092
1087
  classType: methodInfo.classType,
1093
1088
  };
1094
1089
  }
@@ -1115,7 +1110,7 @@ function populateTypeVarContextForSelfType(typeVarContext, contextClassType, sel
1115
1110
  return subtype;
1116
1111
  });
1117
1112
  if (!(0, types_1.isTypeSame)(synthesizedSelfTypeVar, selfWithoutLiteral)) {
1118
- typeVarContext.setTypeVarType(synthesizedSelfTypeVar, selfInstance, selfWithoutLiteral);
1113
+ setTypeVarType(typeVarContext, synthesizedSelfTypeVar, selfInstance, selfWithoutLiteral);
1119
1114
  }
1120
1115
  }
1121
1116
  exports.populateTypeVarContextForSelfType = populateTypeVarContextForSelfType;
@@ -1126,6 +1121,16 @@ function ensureFunctionSignaturesAreUnique(type, signatureTracker, expressionOff
1126
1121
  return transformer.apply(type, 0);
1127
1122
  }
1128
1123
  exports.ensureFunctionSignaturesAreUnique = ensureFunctionSignaturesAreUnique;
1124
+ function updateTypeWithInternalTypeVars(type, scopeIds) {
1125
+ const transformer = new InternalScopeUpdateTransform(scopeIds);
1126
+ return transformer.apply(type, 0);
1127
+ }
1128
+ exports.updateTypeWithInternalTypeVars = updateTypeWithInternalTypeVars;
1129
+ function updateTypeWithExternalTypeVars(type, scopeIds) {
1130
+ const transformer = new ExternalScopeUpdateTransform(scopeIds);
1131
+ return transformer.apply(type, 0);
1132
+ }
1133
+ exports.updateTypeWithExternalTypeVars = updateTypeWithExternalTypeVars;
1129
1134
  // Specializes a (potentially generic) type by substituting
1130
1135
  // type variables from a type var map.
1131
1136
  function applySolvedTypeVars(type, typeVarContext, options = {}) {
@@ -1148,28 +1153,19 @@ function applySourceContextTypeVars(destContext, srcContext) {
1148
1153
  if (srcContext.isEmpty()) {
1149
1154
  return;
1150
1155
  }
1151
- destContext.doForEachSignatureContext((destSignature) => {
1152
- applySourceContextTypeVarsToSignature(destSignature, srcContext);
1156
+ destContext.doForEachSolutionSet((solutionSet) => {
1157
+ applySourceContextTypeVarsToSignature(solutionSet, srcContext);
1153
1158
  });
1154
1159
  }
1155
1160
  exports.applySourceContextTypeVars = applySourceContextTypeVars;
1156
- function applySourceContextTypeVarsToSignature(destSignature, srcContext) {
1157
- destSignature.getTypeVars().forEach((entry) => {
1158
- const newNarrowTypeBound = entry.narrowBound ? applySolvedTypeVars(entry.narrowBound, srcContext) : undefined;
1159
- const newNarrowTypeBoundNoLiterals = entry.narrowBoundNoLiterals
1160
- ? applySolvedTypeVars(entry.narrowBoundNoLiterals, srcContext)
1161
+ function applySourceContextTypeVarsToSignature(solutionSet, srcContext) {
1162
+ solutionSet.getTypeVars().forEach((entry) => {
1163
+ const newLowerBound = entry.lowerBound ? applySolvedTypeVars(entry.lowerBound, srcContext) : undefined;
1164
+ const newLowerBoundNoLiterals = entry.lowerBoundNoLiterals
1165
+ ? applySolvedTypeVars(entry.lowerBoundNoLiterals, srcContext)
1161
1166
  : undefined;
1162
- const newWideTypeBound = entry.wideBound ? applySolvedTypeVars(entry.wideBound, srcContext) : undefined;
1163
- destSignature.setTypeVarType(entry.typeVar, newNarrowTypeBound, newNarrowTypeBoundNoLiterals, newWideTypeBound);
1164
- if (entry.tupleTypes) {
1165
- destSignature.setTupleTypeVar(entry.typeVar, entry.tupleTypes.map((arg) => {
1166
- return {
1167
- type: applySolvedTypeVars(arg.type, srcContext),
1168
- isUnbounded: arg.isUnbounded,
1169
- isOptional: arg.isOptional,
1170
- };
1171
- }));
1172
- }
1167
+ const newUpperBound = entry.upperBound ? applySolvedTypeVars(entry.upperBound, srcContext) : undefined;
1168
+ solutionSet.setTypeVarType(entry.typeVar, newLowerBound, newLowerBoundNoLiterals, newUpperBound);
1173
1169
  });
1174
1170
  }
1175
1171
  exports.applySourceContextTypeVarsToSignature = applySourceContextTypeVarsToSignature;
@@ -1177,29 +1173,20 @@ exports.applySourceContextTypeVarsToSignature = applySourceContextTypeVarsToSign
1177
1173
  // in-scope placeholders used for bidirectional type inference, replace those
1178
1174
  // with the solved type associated with those in-scope placeholders.
1179
1175
  function applyInScopePlaceholders(typeVarContext) {
1180
- typeVarContext.doForEachSignatureContext((signature) => {
1181
- signature.getTypeVars().forEach((entry) => {
1176
+ typeVarContext.doForEachSolutionSet((solutionSet) => {
1177
+ solutionSet.getTypeVars().forEach((entry) => {
1182
1178
  const typeVar = entry.typeVar;
1183
1179
  if (!typeVar.priv.isInScopePlaceholder) {
1184
- const newNarrowTypeBound = entry.narrowBound
1185
- ? applyInScopePlaceholdersToType(entry.narrowBound, signature)
1180
+ const newLowerBound = entry.lowerBound
1181
+ ? applyInScopePlaceholdersToType(entry.lowerBound, solutionSet)
1186
1182
  : undefined;
1187
- const newNarrowTypeBoundNoLiterals = entry.narrowBoundNoLiterals
1188
- ? applyInScopePlaceholdersToType(entry.narrowBoundNoLiterals, signature)
1183
+ const newLowerBoundNoLiterals = entry.lowerBoundNoLiterals
1184
+ ? applyInScopePlaceholdersToType(entry.lowerBoundNoLiterals, solutionSet)
1189
1185
  : undefined;
1190
- const newWideTypeBound = entry.wideBound
1191
- ? applyInScopePlaceholdersToType(entry.wideBound, signature)
1186
+ const newUpperBound = entry.upperBound
1187
+ ? applyInScopePlaceholdersToType(entry.upperBound, solutionSet)
1192
1188
  : undefined;
1193
- signature.setTypeVarType(entry.typeVar, newNarrowTypeBound, newNarrowTypeBoundNoLiterals, newWideTypeBound);
1194
- if (entry.tupleTypes) {
1195
- signature.setTupleTypeVar(entry.typeVar, entry.tupleTypes.map((arg) => {
1196
- return {
1197
- type: applyInScopePlaceholdersToType(arg.type, signature),
1198
- isUnbounded: arg.isUnbounded,
1199
- isOptional: arg.isOptional,
1200
- };
1201
- }));
1202
- }
1189
+ solutionSet.setTypeVarType(entry.typeVar, newLowerBound, newLowerBoundNoLiterals, newUpperBound);
1203
1190
  }
1204
1191
  });
1205
1192
  });
@@ -1279,16 +1266,16 @@ function getContainerDepth(type, recursionCount = 0) {
1279
1266
  return 0;
1280
1267
  }
1281
1268
  let maxChildDepth = 0;
1282
- if (type.priv.tupleTypeArguments) {
1283
- type.priv.tupleTypeArguments.forEach((typeArgInfo) => {
1269
+ if (type.priv.tupleTypeArgs) {
1270
+ type.priv.tupleTypeArgs.forEach((typeArgInfo) => {
1284
1271
  doForEachSubtype(typeArgInfo.type, (subtype) => {
1285
1272
  const childDepth = getContainerDepth(subtype, recursionCount);
1286
1273
  maxChildDepth = Math.max(childDepth, maxChildDepth);
1287
1274
  });
1288
1275
  });
1289
1276
  }
1290
- else if (type.priv.typeArguments) {
1291
- type.priv.typeArguments.forEach((typeArg) => {
1277
+ else if (type.priv.typeArgs) {
1278
+ type.priv.typeArgs.forEach((typeArg) => {
1292
1279
  doForEachSubtype(typeArg, (subtype) => {
1293
1280
  const childDepth = getContainerDepth(subtype, recursionCount);
1294
1281
  maxChildDepth = Math.max(childDepth, maxChildDepth);
@@ -1487,7 +1474,7 @@ function* getClassIterator(classType, flags = 0 /* ClassIteratorFlags.Default */
1487
1474
  }
1488
1475
  // If mroClass is an ancestor of classType, partially specialize
1489
1476
  // it in the context of classType.
1490
- const specializedMroClass = partiallySpecializeType(mroClass, classType);
1477
+ const specializedMroClass = partiallySpecializeType(mroClass, classType, /* typeClassType */ undefined);
1491
1478
  // Should we ignore members on the 'object' base class?
1492
1479
  if (flags & 2 /* ClassIteratorFlags.SkipObjectBaseClass */) {
1493
1480
  if ((0, types_1.isInstantiableClass)(specializedMroClass)) {
@@ -1517,7 +1504,7 @@ function getClassFieldsRecursive(classType) {
1517
1504
  const memberMap = new Map();
1518
1505
  // Evaluate the types of members from the end of the MRO to the beginning.
1519
1506
  types_1.ClassType.getReverseMro(classType).forEach((mroClass) => {
1520
- const specializedMroClass = partiallySpecializeType(mroClass, classType);
1507
+ const specializedMroClass = partiallySpecializeType(mroClass, classType, /* typeClassType */ undefined);
1521
1508
  if ((0, types_1.isClass)(specializedMroClass)) {
1522
1509
  types_1.ClassType.getSymbolTable(specializedMroClass).forEach((symbol, name) => {
1523
1510
  if (!symbol.isIgnoredForProtocolMatch() && symbol.hasTypedDeclarations()) {
@@ -1561,17 +1548,17 @@ exports.addTypeVarsToListIfUnique = addTypeVarsToListIfUnique;
1561
1548
  // of unique type variables. For example, if the type is
1562
1549
  // Union[List[Dict[_T1, _T2]], _T1, _T3], the result would be
1563
1550
  // [_T1, _T2, _T3].
1564
- function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
1551
+ function getTypeVarArgsRecursive(type, recursionCount = 0) {
1565
1552
  var _a;
1566
1553
  if (recursionCount > types_1.maxTypeRecursionCount) {
1567
1554
  return [];
1568
1555
  }
1569
1556
  recursionCount++;
1570
1557
  const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
1571
- if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments) {
1558
+ if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArgs) {
1572
1559
  const combinedList = [];
1573
- aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments.forEach((typeArg) => {
1574
- addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(typeArg, recursionCount));
1560
+ aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArgs.forEach((typeArg) => {
1561
+ addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(typeArg, recursionCount));
1575
1562
  });
1576
1563
  return combinedList;
1577
1564
  }
@@ -1588,12 +1575,10 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
1588
1575
  }
1589
1576
  if ((0, types_1.isClass)(type)) {
1590
1577
  const combinedList = [];
1591
- const typeArgs = type.priv.tupleTypeArguments
1592
- ? type.priv.tupleTypeArguments.map((e) => e.type)
1593
- : type.priv.typeArguments;
1578
+ const typeArgs = type.priv.tupleTypeArgs ? type.priv.tupleTypeArgs.map((e) => e.type) : type.priv.typeArgs;
1594
1579
  if (typeArgs) {
1595
1580
  typeArgs.forEach((typeArg) => {
1596
- addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(typeArg, recursionCount));
1581
+ addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(typeArg, recursionCount));
1597
1582
  });
1598
1583
  }
1599
1584
  return combinedList;
@@ -1601,38 +1586,38 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
1601
1586
  if ((0, types_1.isUnion)(type)) {
1602
1587
  const combinedList = [];
1603
1588
  doForEachSubtype(type, (subtype) => {
1604
- addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(subtype, recursionCount));
1589
+ addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(subtype, recursionCount));
1605
1590
  });
1606
1591
  return combinedList;
1607
1592
  }
1608
1593
  if ((0, types_1.isFunction)(type)) {
1609
1594
  const combinedList = [];
1610
1595
  for (let i = 0; i < type.shared.parameters.length; i++) {
1611
- addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(types_1.FunctionType.getEffectiveParameterType(type, i), recursionCount));
1596
+ addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(types_1.FunctionType.getEffectiveParamType(type, i), recursionCount));
1612
1597
  }
1613
1598
  const returnType = types_1.FunctionType.getEffectiveReturnType(type);
1614
1599
  if (returnType) {
1615
- addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(returnType, recursionCount));
1600
+ addTypeVarsToListIfUnique(combinedList, getTypeVarArgsRecursive(returnType, recursionCount));
1616
1601
  }
1617
1602
  return combinedList;
1618
1603
  }
1619
1604
  return [];
1620
1605
  }
1621
- exports.getTypeVarArgumentsRecursive = getTypeVarArgumentsRecursive;
1606
+ exports.getTypeVarArgsRecursive = getTypeVarArgsRecursive;
1622
1607
  // Creates a specialized version of the class, filling in any unspecified
1623
1608
  // type arguments with Unknown.
1624
1609
  function specializeClassType(type) {
1625
1610
  const typeVarContext = new typeVarContext_1.TypeVarContext(getTypeVarScopeId(type));
1626
- const typeParams = types_1.ClassType.getTypeParameters(type);
1611
+ const typeParams = types_1.ClassType.getTypeParams(type);
1627
1612
  typeParams.forEach((typeParam) => {
1628
- typeVarContext.setTypeVarType(typeParam, applySolvedTypeVars(typeParam.shared.defaultType, typeVarContext));
1613
+ setTypeVarType(typeVarContext, typeParam, applySolvedTypeVars(typeParam.shared.defaultType, typeVarContext));
1629
1614
  });
1630
1615
  return applySolvedTypeVars(type, typeVarContext);
1631
1616
  }
1632
1617
  exports.specializeClassType = specializeClassType;
1633
1618
  // Recursively finds all of the type arguments and sets them
1634
1619
  // to the specified srcType.
1635
- function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionCount = 0) {
1620
+ function setTypeArgsRecursive(destType, srcType, typeVarContext, recursionCount = 0) {
1636
1621
  if (recursionCount > types_1.maxTypeRecursionCount) {
1637
1622
  return;
1638
1623
  }
@@ -1643,83 +1628,89 @@ function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionC
1643
1628
  switch (destType.category) {
1644
1629
  case 8 /* TypeCategory.Union */:
1645
1630
  doForEachSubtype(destType, (subtype) => {
1646
- setTypeArgumentsRecursive(subtype, srcType, typeVarContext, recursionCount);
1631
+ setTypeArgsRecursive(subtype, srcType, typeVarContext, recursionCount);
1647
1632
  });
1648
1633
  break;
1649
1634
  case 6 /* TypeCategory.Class */:
1650
- if (destType.priv.typeArguments) {
1651
- destType.priv.typeArguments.forEach((typeArg) => {
1652
- setTypeArgumentsRecursive(typeArg, srcType, typeVarContext, recursionCount);
1635
+ if (destType.priv.typeArgs) {
1636
+ destType.priv.typeArgs.forEach((typeArg) => {
1637
+ setTypeArgsRecursive(typeArg, srcType, typeVarContext, recursionCount);
1653
1638
  });
1654
1639
  }
1655
- if (destType.priv.tupleTypeArguments) {
1656
- destType.priv.tupleTypeArguments.forEach((typeArg) => {
1657
- setTypeArgumentsRecursive(typeArg.type, srcType, typeVarContext, recursionCount);
1640
+ if (destType.priv.tupleTypeArgs) {
1641
+ destType.priv.tupleTypeArgs.forEach((typeArg) => {
1642
+ setTypeArgsRecursive(typeArg.type, srcType, typeVarContext, recursionCount);
1658
1643
  });
1659
1644
  }
1660
1645
  break;
1661
1646
  case 4 /* TypeCategory.Function */:
1662
1647
  if (destType.priv.specializedTypes) {
1663
1648
  destType.priv.specializedTypes.parameterTypes.forEach((paramType) => {
1664
- setTypeArgumentsRecursive(paramType, srcType, typeVarContext, recursionCount);
1649
+ setTypeArgsRecursive(paramType, srcType, typeVarContext, recursionCount);
1665
1650
  });
1666
1651
  if (destType.priv.specializedTypes.returnType) {
1667
- setTypeArgumentsRecursive(destType.priv.specializedTypes.returnType, srcType, typeVarContext, recursionCount);
1652
+ setTypeArgsRecursive(destType.priv.specializedTypes.returnType, srcType, typeVarContext, recursionCount);
1668
1653
  }
1669
1654
  }
1670
1655
  else {
1671
1656
  destType.shared.parameters.forEach((param) => {
1672
- setTypeArgumentsRecursive(param.type, srcType, typeVarContext, recursionCount);
1657
+ setTypeArgsRecursive(param.type, srcType, typeVarContext, recursionCount);
1673
1658
  });
1674
1659
  if (destType.shared.declaredReturnType) {
1675
- setTypeArgumentsRecursive(destType.shared.declaredReturnType, srcType, typeVarContext, recursionCount);
1660
+ setTypeArgsRecursive(destType.shared.declaredReturnType, srcType, typeVarContext, recursionCount);
1676
1661
  }
1677
1662
  }
1678
1663
  break;
1679
1664
  case 5 /* TypeCategory.OverloadedFunction */:
1680
1665
  destType.priv.overloads.forEach((subtype) => {
1681
- setTypeArgumentsRecursive(subtype, srcType, typeVarContext, recursionCount);
1666
+ setTypeArgsRecursive(subtype, srcType, typeVarContext, recursionCount);
1682
1667
  });
1683
1668
  break;
1684
1669
  case 9 /* TypeCategory.TypeVar */:
1685
- if (!typeVarContext.getPrimarySignature().getTypeVar(destType)) {
1686
- typeVarContext.setTypeVarType(destType, srcType);
1670
+ if (!typeVarContext.getMainSolutionSet().getTypeVar(destType)) {
1671
+ setTypeVarType(typeVarContext, destType, srcType);
1687
1672
  }
1688
1673
  break;
1689
1674
  }
1690
1675
  }
1691
- exports.setTypeArgumentsRecursive = setTypeArgumentsRecursive;
1676
+ exports.setTypeArgsRecursive = setTypeArgsRecursive;
1692
1677
  // Builds a mapping between type parameters and their specialized
1693
1678
  // types. For example, if the generic type is Dict[_T1, _T2] and the
1694
1679
  // specialized type is Dict[str, int], it returns a map that associates
1695
1680
  // _T1 with str and _T2 with int.
1696
1681
  function buildTypeVarContextFromSpecializedClass(classType) {
1697
- const typeParameters = types_1.ClassType.getTypeParameters(classType);
1698
- const typeVarContext = buildTypeVarContext(typeParameters, classType.priv.typeArguments, getTypeVarScopeId(classType));
1699
- if (types_1.ClassType.isTupleClass(classType) && classType.priv.tupleTypeArguments) {
1700
- typeVarContext.setTupleTypeVar(typeParameters[0], classType.priv.tupleTypeArguments);
1682
+ const typeParams = types_1.ClassType.getTypeParams(classType);
1683
+ let typeArgs;
1684
+ if (classType.priv.tupleTypeArgs) {
1685
+ typeArgs = [
1686
+ convertToInstance(specializeTupleClass(classType, classType.priv.tupleTypeArgs, classType.priv.isTypeArgExplicit,
1687
+ /* isUnpackedTuple */ true)),
1688
+ ];
1701
1689
  }
1702
- return typeVarContext;
1690
+ else {
1691
+ typeArgs = classType.priv.typeArgs;
1692
+ }
1693
+ return buildTypeVarContext(typeParams, typeArgs, getTypeVarScopeId(classType));
1703
1694
  }
1704
1695
  exports.buildTypeVarContextFromSpecializedClass = buildTypeVarContextFromSpecializedClass;
1705
- function buildTypeVarContext(typeParameters, typeArgs, typeVarScopeId) {
1696
+ function buildTypeVarContext(typeParams, typeArgs, typeVarScopeId) {
1706
1697
  const typeVarContext = new typeVarContext_1.TypeVarContext(typeVarScopeId);
1707
- typeParameters.forEach((typeParam, index) => {
1698
+ typeParams.forEach((typeParam, index) => {
1708
1699
  let typeArgType;
1709
1700
  if (typeArgs) {
1710
- if (typeParam.shared.isParamSpec) {
1701
+ if ((0, types_1.isParamSpec)(typeParam)) {
1711
1702
  if (index < typeArgs.length) {
1712
1703
  typeArgType = typeArgs[index];
1713
1704
  if ((0, types_1.isFunction)(typeArgType) && types_1.FunctionType.isParamSpecValue(typeArgType)) {
1714
1705
  const parameters = [];
1715
1706
  const typeArgFunctionType = typeArgType;
1716
1707
  typeArgType.shared.parameters.forEach((param, paramIndex) => {
1717
- parameters.push(types_1.FunctionParam.create(param.category, types_1.FunctionType.getEffectiveParameterType(typeArgFunctionType, paramIndex), param.flags & types_1.FunctionParamFlags.NameSynthesized, param.name, param.defaultType));
1708
+ parameters.push(types_1.FunctionParam.create(param.category, types_1.FunctionType.getEffectiveParamType(typeArgFunctionType, paramIndex), param.flags & types_1.FunctionParamFlags.NameSynthesized, param.name, param.defaultType));
1718
1709
  });
1719
- typeVarContext.setTypeVarType(typeParam, convertTypeToParamSpecValue(typeArgType));
1710
+ setTypeVarType(typeVarContext, typeParam, typeArgType);
1720
1711
  }
1721
1712
  else if ((0, types_1.isParamSpec)(typeArgType) || (0, types_1.isAnyOrUnknown)(typeArgType)) {
1722
- typeVarContext.setTypeVarType(typeParam, convertTypeToParamSpecValue(typeArgType));
1713
+ setTypeVarType(typeVarContext, typeParam, typeArgType);
1723
1714
  }
1724
1715
  }
1725
1716
  }
@@ -1730,8 +1721,8 @@ function buildTypeVarContext(typeParameters, typeArgs, typeVarScopeId) {
1730
1721
  else {
1731
1722
  typeArgType = typeArgs[index];
1732
1723
  }
1733
- typeVarContext.setTypeVarType(typeParam, typeArgType,
1734
- /* narrowBoundNoLiterals */ undefined, typeArgType);
1724
+ setTypeVarType(typeVarContext, typeParam, typeArgType,
1725
+ /* lowerBoundNoLiterals */ undefined, typeArgType);
1735
1726
  }
1736
1727
  }
1737
1728
  });
@@ -1740,7 +1731,7 @@ function buildTypeVarContext(typeParameters, typeArgs, typeVarScopeId) {
1740
1731
  exports.buildTypeVarContext = buildTypeVarContext;
1741
1732
  // Determines the specialized base class type that srcType derives from.
1742
1733
  function specializeForBaseClass(srcType, baseClass) {
1743
- const typeParams = types_1.ClassType.getTypeParameters(baseClass);
1734
+ const typeParams = types_1.ClassType.getTypeParams(baseClass);
1744
1735
  // If there are no type parameters for the specified base class,
1745
1736
  // no specialization is required.
1746
1737
  if (typeParams.length === 0) {
@@ -1785,8 +1776,9 @@ function synthesizeTypeVarForSelfCls(classType, isClsParam) {
1785
1776
  selfType.shared.isSynthesizedSelf = true;
1786
1777
  selfType.priv.nameWithScope = types_1.TypeVarType.makeNameWithScope(selfType.shared.name, scopeId);
1787
1778
  selfType.priv.scopeId = scopeId;
1788
- const boundType = types_1.ClassType.cloneForSpecialization(classType, types_1.ClassType.getTypeParameters(classType),
1789
- /* isTypeArgumentExplicit */ false,
1779
+ const boundType = types_1.ClassType.specialize(classType,
1780
+ /* typeArgs */ undefined,
1781
+ /* isTypeArgExplicit */ false,
1790
1782
  /* includeSubclasses */ !!classType.priv.includeSubclasses);
1791
1783
  selfType.shared.boundType = types_1.ClassType.cloneAsInstance(boundType);
1792
1784
  return isClsParam ? types_1.TypeVarType.cloneAsInstantiable(selfType) : selfType;
@@ -1823,8 +1815,8 @@ function getGeneratorYieldType(declaredReturnType, isAsync) {
1823
1815
  ['', 'AwaitableGenerator'],
1824
1816
  ];
1825
1817
  if (expectedClasses.some((classes) => types_1.ClassType.isBuiltIn(subtype, isAsync ? classes[0] : classes[1]))) {
1826
- return subtype.priv.typeArguments && subtype.priv.typeArguments.length >= 1
1827
- ? subtype.priv.typeArguments[0]
1818
+ return subtype.priv.typeArgs && subtype.priv.typeArgs.length >= 1
1819
+ ? subtype.priv.typeArgs[0]
1828
1820
  : types_1.UnknownType.create();
1829
1821
  }
1830
1822
  }
@@ -1880,17 +1872,17 @@ function convertToInstance(type, includeSubclasses = true) {
1880
1872
  // Handle type[x] as a special case.
1881
1873
  if (types_1.ClassType.isBuiltIn(subtype, 'type')) {
1882
1874
  if (types_1.TypeBase.isInstance(subtype)) {
1883
- if (!subtype.priv.typeArguments || subtype.priv.typeArguments.length < 1) {
1875
+ if (!subtype.priv.typeArgs || subtype.priv.typeArgs.length < 1) {
1884
1876
  return types_1.UnknownType.create();
1885
1877
  }
1886
1878
  else {
1887
- return subtype.priv.typeArguments[0];
1879
+ return subtype.priv.typeArgs[0];
1888
1880
  }
1889
1881
  }
1890
1882
  else {
1891
- if (subtype.priv.typeArguments && subtype.priv.typeArguments.length > 0) {
1892
- if (!(0, types_1.isAnyOrUnknown)(subtype.priv.typeArguments[0])) {
1893
- return convertToInstantiable(subtype.priv.typeArguments[0]);
1883
+ if (subtype.priv.typeArgs && subtype.priv.typeArgs.length > 0) {
1884
+ if (!(0, types_1.isAnyOrUnknown)(subtype.priv.typeArgs[0])) {
1885
+ return convertToInstantiable(subtype.priv.typeArgs[0]);
1894
1886
  }
1895
1887
  }
1896
1888
  }
@@ -1929,7 +1921,7 @@ function convertToInstance(type, includeSubclasses = true) {
1929
1921
  // Copy over any type alias information.
1930
1922
  const aliasInfo = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo;
1931
1923
  if (aliasInfo && type !== result) {
1932
- result = types_1.TypeBase.cloneForTypeAlias(result, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParameters, aliasInfo.typeArguments);
1924
+ result = types_1.TypeBase.cloneForTypeAlias(result, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParams, aliasInfo.typeArgs);
1933
1925
  }
1934
1926
  if (type !== result && includeSubclasses) {
1935
1927
  // Cache the converted value for next time.
@@ -2116,8 +2108,8 @@ function isPartlyUnknown(type, recursionCount = 0) {
2116
2108
  // If this is a generic type alias, see if any of its type arguments
2117
2109
  // are either unspecified or are partially known.
2118
2110
  const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
2119
- if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments) {
2120
- if (aliasInfo.typeArguments.some((typeArg) => isPartlyUnknown(typeArg, recursionCount))) {
2111
+ if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArgs) {
2112
+ if (aliasInfo.typeArgs.some((typeArg) => isPartlyUnknown(typeArg, recursionCount))) {
2121
2113
  return true;
2122
2114
  }
2123
2115
  }
@@ -2134,7 +2126,7 @@ function isPartlyUnknown(type, recursionCount = 0) {
2134
2126
  return false;
2135
2127
  }
2136
2128
  if (!types_1.ClassType.isPseudoGenericClass(type)) {
2137
- const typeArgs = ((_b = type.priv.tupleTypeArguments) === null || _b === void 0 ? void 0 : _b.map((t) => t.type)) || type.priv.typeArguments;
2129
+ const typeArgs = ((_b = type.priv.tupleTypeArgs) === null || _b === void 0 ? void 0 : _b.map((t) => t.type)) || type.priv.typeArgs;
2138
2130
  if (typeArgs) {
2139
2131
  for (const argType of typeArgs) {
2140
2132
  if (isPartlyUnknown(argType, recursionCount)) {
@@ -2155,7 +2147,7 @@ function isPartlyUnknown(type, recursionCount = 0) {
2155
2147
  for (let i = 0; i < type.shared.parameters.length; i++) {
2156
2148
  // Ignore parameters such as "*" that have no name.
2157
2149
  if (type.shared.parameters[i].name) {
2158
- const paramType = types_1.FunctionType.getEffectiveParameterType(type, i);
2150
+ const paramType = types_1.FunctionType.getEffectiveParamType(type, i);
2159
2151
  if (isPartlyUnknown(paramType, recursionCount)) {
2160
2152
  return true;
2161
2153
  }
@@ -2175,13 +2167,11 @@ exports.isPartlyUnknown = isPartlyUnknown;
2175
2167
  // that is a union, it "explodes" the class into a union of classes with
2176
2168
  // each element of the union - e.g. Foo[A | B] becomes Foo[A] | Foo[B].
2177
2169
  function explodeGenericClass(classType) {
2178
- if (!classType.priv.typeArguments ||
2179
- classType.priv.typeArguments.length !== 1 ||
2180
- !(0, types_1.isUnion)(classType.priv.typeArguments[0])) {
2170
+ if (!classType.priv.typeArgs || classType.priv.typeArgs.length !== 1 || !(0, types_1.isUnion)(classType.priv.typeArgs[0])) {
2181
2171
  return classType;
2182
2172
  }
2183
- return (0, types_1.combineTypes)(classType.priv.typeArguments[0].priv.subtypes.map((subtype) => {
2184
- return types_1.ClassType.cloneForSpecialization(classType, [subtype], /* isTypeArgumentExplicit */ true);
2173
+ return (0, types_1.combineTypes)(classType.priv.typeArgs[0].priv.subtypes.map((subtype) => {
2174
+ return types_1.ClassType.specialize(classType, [subtype]);
2185
2175
  }));
2186
2176
  }
2187
2177
  exports.explodeGenericClass = explodeGenericClass;
@@ -2204,10 +2194,10 @@ function combineSameSizedTuples(type, tupleType) {
2204
2194
  // tuple with a known size. This includes named tuples.
2205
2195
  tupleClass = subtype.shared.mro.find((mroClass) => (0, types_1.isClass)(mroClass) && isTupleClass(mroClass) && !isUnboundedTupleClass(mroClass));
2206
2196
  }
2207
- if (tupleClass && (0, types_1.isClass)(tupleClass) && tupleClass.priv.tupleTypeArguments) {
2197
+ if (tupleClass && (0, types_1.isClass)(tupleClass) && tupleClass.priv.tupleTypeArgs) {
2208
2198
  if (tupleEntries) {
2209
- if (tupleEntries.length === tupleClass.priv.tupleTypeArguments.length) {
2210
- tupleClass.priv.tupleTypeArguments.forEach((entry, index) => {
2199
+ if (tupleEntries.length === tupleClass.priv.tupleTypeArgs.length) {
2200
+ tupleClass.priv.tupleTypeArgs.forEach((entry, index) => {
2211
2201
  tupleEntries[index].push(entry.type);
2212
2202
  });
2213
2203
  }
@@ -2216,7 +2206,7 @@ function combineSameSizedTuples(type, tupleType) {
2216
2206
  }
2217
2207
  }
2218
2208
  else {
2219
- tupleEntries = tupleClass.priv.tupleTypeArguments.map((entry) => [entry.type]);
2209
+ tupleEntries = tupleClass.priv.tupleTypeArgs.map((entry) => [entry.type]);
2220
2210
  }
2221
2211
  }
2222
2212
  else {
@@ -2235,18 +2225,21 @@ function combineSameSizedTuples(type, tupleType) {
2235
2225
  })));
2236
2226
  }
2237
2227
  exports.combineSameSizedTuples = combineSameSizedTuples;
2238
- // Tuples require special handling for specialization. This method computes
2239
- // the "effective" type argument, which is a union of the variadic type
2240
- // arguments.
2241
- function specializeTupleClass(classType, typeArgs, isTypeArgumentExplicit = true, isUnpackedTuple = false) {
2242
- const combinedTupleType = (0, types_1.combineTypes)(typeArgs.map((t) => {
2243
- if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedVariadicTypeVar)(t.type)) {
2228
+ function combineTupleTypeArgs(typeArgs) {
2229
+ return (0, types_1.combineTypes)(typeArgs.map((t) => {
2230
+ if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedTypeVarTuple)(t.type)) {
2244
2231
  // Treat the unpacked TypeVarTuple as a union.
2245
2232
  return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
2246
2233
  }
2247
2234
  return t.type;
2248
2235
  }));
2249
- const clonedClassType = types_1.ClassType.cloneForSpecialization(classType, [combinedTupleType], isTypeArgumentExplicit,
2236
+ }
2237
+ exports.combineTupleTypeArgs = combineTupleTypeArgs;
2238
+ // Tuples require special handling for specialization. This method computes
2239
+ // the "effective" type argument, which is a union of the variadic type
2240
+ // arguments.
2241
+ function specializeTupleClass(classType, typeArgs, isTypeArgExplicit = true, isUnpackedTuple = false) {
2242
+ const clonedClassType = types_1.ClassType.specialize(classType, [combineTupleTypeArgs(typeArgs)], isTypeArgExplicit,
2250
2243
  /* includeSubclasses */ undefined, typeArgs);
2251
2244
  if (isUnpackedTuple) {
2252
2245
  clonedClassType.priv.isUnpacked = true;
@@ -2255,8 +2248,8 @@ function specializeTupleClass(classType, typeArgs, isTypeArgumentExplicit = true
2255
2248
  }
2256
2249
  exports.specializeTupleClass = specializeTupleClass;
2257
2250
  function _expandVariadicUnpackedUnion(type) {
2258
- if ((0, types_1.isClassInstance)(type) && isTupleClass(type) && type.priv.tupleTypeArguments && type.priv.isUnpacked) {
2259
- return (0, types_1.combineTypes)(type.priv.tupleTypeArguments.map((t) => t.type));
2251
+ if ((0, types_1.isClassInstance)(type) && isTupleClass(type) && type.priv.tupleTypeArgs && type.priv.isUnpacked) {
2252
+ return (0, types_1.combineTypes)(type.priv.tupleTypeArgs.map((t) => t.type));
2260
2253
  }
2261
2254
  return type;
2262
2255
  }
@@ -2266,20 +2259,20 @@ function getGeneratorTypeArgs(returnType) {
2266
2259
  var _a;
2267
2260
  if ((0, types_1.isClassInstance)(returnType)) {
2268
2261
  if (types_1.ClassType.isBuiltIn(returnType, ['Generator', 'AsyncGenerator'])) {
2269
- return returnType.priv.typeArguments;
2262
+ return returnType.priv.typeArgs;
2270
2263
  }
2271
2264
  else if (types_1.ClassType.isBuiltIn(returnType, 'AwaitableGenerator')) {
2272
2265
  // AwaitableGenerator has four type arguments, and the first 3
2273
2266
  // correspond to the generator.
2274
- return (_a = returnType.priv.typeArguments) === null || _a === void 0 ? void 0 : _a.slice(0, 3);
2267
+ return (_a = returnType.priv.typeArgs) === null || _a === void 0 ? void 0 : _a.slice(0, 3);
2275
2268
  }
2276
2269
  }
2277
2270
  return undefined;
2278
2271
  }
2279
2272
  exports.getGeneratorTypeArgs = getGeneratorTypeArgs;
2280
- function requiresTypeArguments(classType) {
2281
- if (classType.shared.typeParameters.length > 0) {
2282
- const firstTypeParam = classType.shared.typeParameters[0];
2273
+ function requiresTypeArgs(classType) {
2274
+ if (classType.shared.typeParams.length > 0) {
2275
+ const firstTypeParam = classType.shared.typeParams[0];
2283
2276
  // If there are type parameters, type arguments are needed.
2284
2277
  // The exception is if type parameters have been synthesized
2285
2278
  // for classes that have untyped constructors.
@@ -2294,7 +2287,7 @@ function requiresTypeArguments(classType) {
2294
2287
  return true;
2295
2288
  }
2296
2289
  // There are a few built-in special classes that require
2297
- // type arguments even though typeParameters is empty.
2290
+ // type arguments even though typeParams is empty.
2298
2291
  if (types_1.ClassType.isSpecialBuiltIn(classType)) {
2299
2292
  const specialClasses = [
2300
2293
  'Tuple',
@@ -2314,7 +2307,7 @@ function requiresTypeArguments(classType) {
2314
2307
  }
2315
2308
  return false;
2316
2309
  }
2317
- exports.requiresTypeArguments = requiresTypeArguments;
2310
+ exports.requiresTypeArgs = requiresTypeArgs;
2318
2311
  function requiresSpecialization(type, options, recursionCount = 0) {
2319
2312
  var _a;
2320
2313
  if (recursionCount > types_1.maxTypeRecursionCount) {
@@ -2347,17 +2340,17 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
2347
2340
  if (types_1.ClassType.isPseudoGenericClass(type) && (options === null || options === void 0 ? void 0 : options.ignorePseudoGeneric)) {
2348
2341
  return false;
2349
2342
  }
2350
- if (!type.priv.isTypeArgumentExplicit && (options === null || options === void 0 ? void 0 : options.ignoreImplicitTypeArgs)) {
2343
+ if (!type.priv.isTypeArgExplicit && (options === null || options === void 0 ? void 0 : options.ignoreImplicitTypeArgs)) {
2351
2344
  return false;
2352
2345
  }
2353
- if (type.priv.typeArguments) {
2354
- return type.priv.typeArguments.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
2346
+ if (type.priv.typeArgs) {
2347
+ return type.priv.typeArgs.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
2355
2348
  }
2356
- return types_1.ClassType.getTypeParameters(type).length > 0;
2349
+ return types_1.ClassType.getTypeParams(type).length > 0;
2357
2350
  }
2358
2351
  case 4 /* TypeCategory.Function */: {
2359
2352
  for (let i = 0; i < type.shared.parameters.length; i++) {
2360
- if (requiresSpecialization(types_1.FunctionType.getEffectiveParameterType(type, i), options, recursionCount)) {
2353
+ if (requiresSpecialization(types_1.FunctionType.getEffectiveParamType(type, i), options, recursionCount)) {
2361
2354
  return true;
2362
2355
  }
2363
2356
  }
@@ -2393,8 +2386,8 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
2393
2386
  // If this is a recursive type alias, it may need to be specialized
2394
2387
  // if it has generic type arguments.
2395
2388
  const aliasInfo = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo;
2396
- if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments) {
2397
- return aliasInfo.typeArguments.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
2389
+ if (aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArgs) {
2390
+ return aliasInfo.typeArgs.some((typeArg) => requiresSpecialization(typeArg, options, recursionCount));
2398
2391
  }
2399
2392
  }
2400
2393
  }
@@ -2415,25 +2408,25 @@ function combineVariances(variance1, variance2) {
2415
2408
  exports.combineVariances = combineVariances;
2416
2409
  // Determines if the variance of the type argument for a generic class is compatible
2417
2410
  // With the declared variance of the corresponding type parameter.
2418
- function isVarianceOfTypeArgumentCompatible(type, typeParamVariance) {
2411
+ function isVarianceOfTypeArgCompatible(type, typeParamVariance) {
2419
2412
  if (typeParamVariance === 1 /* Variance.Unknown */ || typeParamVariance === 0 /* Variance.Auto */) {
2420
2413
  return true;
2421
2414
  }
2422
- if ((0, types_1.isTypeVar)(type) && !type.shared.isParamSpec && !type.shared.isVariadic) {
2415
+ if ((0, types_1.isTypeVar)(type) && !(0, types_1.isParamSpec)(type) && !(0, types_1.isTypeVarTuple)(type)) {
2423
2416
  const typeArgVariance = type.shared.declaredVariance;
2424
2417
  if (typeArgVariance === 4 /* Variance.Contravariant */ || typeArgVariance === 3 /* Variance.Covariant */) {
2425
2418
  return typeArgVariance === typeParamVariance;
2426
2419
  }
2427
2420
  }
2428
2421
  else if ((0, types_1.isClassInstance)(type)) {
2429
- if (type.shared.typeParameters && type.shared.typeParameters.length > 0) {
2430
- return type.shared.typeParameters.every((typeParam, index) => {
2422
+ if (type.shared.typeParams && type.shared.typeParams.length > 0) {
2423
+ return type.shared.typeParams.every((typeParam, index) => {
2431
2424
  let typeArgType;
2432
- if (typeParam.shared.isParamSpec || typeParam.shared.isVariadic) {
2425
+ if ((0, types_1.isParamSpec)(typeParam) || (0, types_1.isTypeVarTuple)(typeParam)) {
2433
2426
  return true;
2434
2427
  }
2435
- if (type.priv.typeArguments && index < type.priv.typeArguments.length) {
2436
- typeArgType = type.priv.typeArguments[index];
2428
+ if (type.priv.typeArgs && index < type.priv.typeArgs.length) {
2429
+ typeArgType = type.priv.typeArgs[index];
2437
2430
  }
2438
2431
  const declaredVariance = typeParam.shared.declaredVariance;
2439
2432
  if (declaredVariance === 0 /* Variance.Auto */) {
@@ -2455,13 +2448,13 @@ function isVarianceOfTypeArgumentCompatible(type, typeParamVariance) {
2455
2448
  effectiveVariance = 3 /* Variance.Covariant */;
2456
2449
  }
2457
2450
  }
2458
- return isVarianceOfTypeArgumentCompatible(typeArgType !== null && typeArgType !== void 0 ? typeArgType : types_1.UnknownType.create(), effectiveVariance);
2451
+ return isVarianceOfTypeArgCompatible(typeArgType !== null && typeArgType !== void 0 ? typeArgType : types_1.UnknownType.create(), effectiveVariance);
2459
2452
  });
2460
2453
  }
2461
2454
  }
2462
2455
  return true;
2463
2456
  }
2464
- exports.isVarianceOfTypeArgumentCompatible = isVarianceOfTypeArgumentCompatible;
2457
+ exports.isVarianceOfTypeArgCompatible = isVarianceOfTypeArgCompatible;
2465
2458
  // Computes the method resolution ordering for a class whose base classes
2466
2459
  // have already been filled in. The algorithm for computing MRO is described
2467
2460
  // here: https://www.python.org/download/releases/2.3/mro/. It returns true
@@ -2486,8 +2479,8 @@ function computeMroLinearization(classType) {
2486
2479
  if (classType.shared.baseClasses.some((innerBaseClass, innerIndex) => {
2487
2480
  return (innerIndex > index &&
2488
2481
  (0, types_1.isInstantiableClass)(innerBaseClass) &&
2489
- innerBaseClass.priv.typeArguments &&
2490
- innerBaseClass.priv.isTypeArgumentExplicit);
2482
+ innerBaseClass.priv.typeArgs &&
2483
+ innerBaseClass.priv.isTypeArgExplicit);
2491
2484
  })) {
2492
2485
  return false;
2493
2486
  }
@@ -2601,14 +2594,14 @@ function getDeclaringModulesForType(type) {
2601
2594
  return moduleList;
2602
2595
  }
2603
2596
  exports.getDeclaringModulesForType = getDeclaringModulesForType;
2604
- function convertArgumentNodeToFunctionArgument(node) {
2597
+ function convertNodeToArg(node) {
2605
2598
  return {
2606
- argumentCategory: node.d.argCategory,
2599
+ argCategory: node.d.argCategory,
2607
2600
  name: node.d.name,
2608
2601
  valueExpression: node.d.valueExpr,
2609
2602
  };
2610
2603
  }
2611
- exports.convertArgumentNodeToFunctionArgument = convertArgumentNodeToFunctionArgument;
2604
+ exports.convertNodeToArg = convertNodeToArg;
2612
2605
  function addDeclaringModuleNamesForType(type, moduleList, recursionCount = 0) {
2613
2606
  if (recursionCount > types_1.maxTypeRecursionCount) {
2614
2607
  return;
@@ -2660,7 +2653,7 @@ function convertTypeToParamSpecValue(type) {
2660
2653
  const newFunction = types_1.FunctionType.createInstance('', '', '', type.shared.flags | 65536 /* FunctionTypeFlags.ParamSpecValue */, type.shared.docString);
2661
2654
  newFunction.shared.deprecatedMessage = type.shared.deprecatedMessage;
2662
2655
  type.shared.parameters.forEach((param, index) => {
2663
- types_1.FunctionType.addParameter(newFunction, types_1.FunctionParam.create(param.category, types_1.FunctionType.getEffectiveParameterType(type, index), param.flags & types_1.FunctionParamFlags.NameSynthesized, param.name, param.defaultType));
2656
+ types_1.FunctionType.addParam(newFunction, types_1.FunctionParam.create(param.category, types_1.FunctionType.getEffectiveParamType(type, index), param.flags & types_1.FunctionParamFlags.NameSynthesized, param.name, param.defaultType));
2664
2657
  });
2665
2658
  if (type.priv.higherOrderTypeVarScopeIds) {
2666
2659
  newFunction.priv.higherOrderTypeVarScopeIds = [...type.priv.higherOrderTypeVarScopeIds];
@@ -2669,25 +2662,42 @@ function convertTypeToParamSpecValue(type) {
2669
2662
  newFunction.priv.constructorTypeVarScopeId = type.priv.constructorTypeVarScopeId;
2670
2663
  return newFunction;
2671
2664
  }
2672
- return getUnknownTypeForParamSpec();
2665
+ return types_1.ParamSpecType.getUnknown();
2673
2666
  }
2674
2667
  exports.convertTypeToParamSpecValue = convertTypeToParamSpecValue;
2668
+ // This function calls the setTypeVarType method on the TypeVarContext after
2669
+ // converting the parameters for use with a ParamSpec.
2670
+ function setTypeVarType(typeVarContext, typeVar, lowerBound, lowerBoundNoLiterals, upperBound) {
2671
+ if ((0, types_1.isParamSpec)(typeVar)) {
2672
+ if (lowerBound) {
2673
+ lowerBound = convertTypeToParamSpecValue(lowerBound);
2674
+ }
2675
+ if (lowerBoundNoLiterals) {
2676
+ lowerBoundNoLiterals = convertTypeToParamSpecValue(lowerBoundNoLiterals);
2677
+ }
2678
+ if (upperBound) {
2679
+ lowerBound = convertTypeToParamSpecValue(upperBound);
2680
+ }
2681
+ }
2682
+ typeVarContext.setTypeVarType(typeVar, lowerBound, lowerBoundNoLiterals, upperBound);
2683
+ }
2684
+ exports.setTypeVarType = setTypeVarType;
2675
2685
  // Converts a FunctionType into a ParamSpec if it consists only of
2676
2686
  // (* args: P.args, ** kwargs: P.kwargs). Otherwise returns the original type.
2677
2687
  function convertParamSpecValueToType(type) {
2678
2688
  const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
2679
2689
  const withoutParamSpec = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(type);
2680
- let hasParameters = withoutParamSpec.shared.parameters.length > 0;
2690
+ let hasParams = withoutParamSpec.shared.parameters.length > 0;
2681
2691
  if (withoutParamSpec.shared.parameters.length === 1) {
2682
2692
  // If the ParamSpec has a position-only separator as its only parameter,
2683
2693
  // treat it as though there are no parameters.
2684
2694
  const onlyParam = withoutParamSpec.shared.parameters[0];
2685
2695
  if ((0, types_1.isPositionOnlySeparator)(onlyParam)) {
2686
- hasParameters = false;
2696
+ hasParams = false;
2687
2697
  }
2688
2698
  }
2689
2699
  // Can we simplify it to just a paramSpec?
2690
- if (!hasParameters && paramSpec) {
2700
+ if (!hasParams && paramSpec) {
2691
2701
  return paramSpec;
2692
2702
  }
2693
2703
  // Create a function type from the param spec entries.
@@ -2696,7 +2706,7 @@ function convertParamSpecValueToType(type) {
2696
2706
  types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.priv.higherOrderTypeVarScopeIds);
2697
2707
  functionType.priv.constructorTypeVarScopeId = withoutParamSpec.priv.constructorTypeVarScopeId;
2698
2708
  withoutParamSpec.shared.parameters.forEach((entry, index) => {
2699
- types_1.FunctionType.addParameter(functionType, types_1.FunctionParam.create(entry.category, types_1.FunctionType.getEffectiveParameterType(withoutParamSpec, index), (entry.flags & types_1.FunctionParamFlags.NameSynthesized) | types_1.FunctionParamFlags.TypeDeclared, entry.name, entry.defaultType));
2709
+ types_1.FunctionType.addParam(functionType, types_1.FunctionParam.create(entry.category, types_1.FunctionType.getEffectiveParamType(withoutParamSpec, index), (entry.flags & types_1.FunctionParamFlags.NameSynthesized) | types_1.FunctionParamFlags.TypeDeclared, entry.name, entry.defaultType));
2700
2710
  });
2701
2711
  if (paramSpec) {
2702
2712
  types_1.FunctionType.addParamSpecVariadics(functionType, paramSpec);
@@ -2743,11 +2753,11 @@ class TypeVarTransformer {
2743
2753
  // type aliases.
2744
2754
  const aliasInfo = (_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo;
2745
2755
  if (type.shared.recursiveAlias) {
2746
- if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArguments)) {
2756
+ if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeArgs)) {
2747
2757
  return type;
2748
2758
  }
2749
2759
  let requiresUpdate = false;
2750
- const typeArgs = aliasInfo.typeArguments.map((typeArg) => {
2760
+ const typeArgs = aliasInfo.typeArgs.map((typeArg) => {
2751
2761
  const replacementType = this.apply(typeArg, recursionCount);
2752
2762
  if (replacementType !== typeArg) {
2753
2763
  requiresUpdate = true;
@@ -2755,7 +2765,7 @@ class TypeVarTransformer {
2755
2765
  return replacementType;
2756
2766
  });
2757
2767
  if (requiresUpdate) {
2758
- return types_1.TypeBase.cloneForTypeAlias(type, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParameters, typeArgs);
2768
+ return types_1.TypeBase.cloneForTypeAlias(type, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParams, typeArgs);
2759
2769
  }
2760
2770
  return type;
2761
2771
  }
@@ -2764,9 +2774,9 @@ class TypeVarTransformer {
2764
2774
  // type variables in the same scope recursively by setting it the scope in the
2765
2775
  // _pendingTypeVarTransformations set.
2766
2776
  if (!this._isTypeVarScopePending(type.priv.scopeId)) {
2767
- if (type.shared.isParamSpec) {
2777
+ if ((0, types_1.isParamSpec)(type)) {
2768
2778
  let paramSpecWithoutAccess = type;
2769
- if (type.priv.paramSpecAccess) {
2779
+ if ((0, types_1.isParamSpec)(type) && type.priv.paramSpecAccess) {
2770
2780
  paramSpecWithoutAccess = types_1.TypeVarType.cloneForParamSpecAccess(type, /* access */ undefined);
2771
2781
  }
2772
2782
  const paramSpecValue = this.transformParamSpec(paramSpecWithoutAccess, recursionCount);
@@ -2798,7 +2808,7 @@ class TypeVarTransformer {
2798
2808
  }
2799
2809
  // If we're transforming a variadic type variable that was in a union,
2800
2810
  // expand the union types.
2801
- if ((0, types_1.isVariadicTypeVar)(type) && type.priv.isVariadicInUnion) {
2811
+ if ((0, types_1.isTypeVarTuple)(type) && type.priv.isVariadicInUnion) {
2802
2812
  replacementType = _expandVariadicUnpackedUnion(replacementType);
2803
2813
  }
2804
2814
  }
@@ -2810,7 +2820,7 @@ class TypeVarTransformer {
2810
2820
  let transformedType = this.apply(subtype, recursionCount);
2811
2821
  // If we're transforming a variadic type variable within a union,
2812
2822
  // combine the individual types within the variadic type variable.
2813
- if ((0, types_1.isVariadicTypeVar)(subtype) && !(0, types_1.isVariadicTypeVar)(transformedType)) {
2823
+ if ((0, types_1.isTypeVarTuple)(subtype) && !(0, types_1.isTypeVarTuple)(transformedType)) {
2814
2824
  const subtypesToCombine = [];
2815
2825
  doForEachSubtype(transformedType, (transformedSubtype) => {
2816
2826
  subtypesToCombine.push(_expandVariadicUnpackedUnion(transformedSubtype));
@@ -2821,7 +2831,7 @@ class TypeVarTransformer {
2821
2831
  return this.transformUnionSubtype(subtype, transformedType, recursionCount);
2822
2832
  }
2823
2833
  return transformedType;
2824
- });
2834
+ }, { retainTypeAlias: true });
2825
2835
  return !(0, types_1.isNever)(newUnionType) ? newUnionType : types_1.UnknownType.create();
2826
2836
  }
2827
2837
  if ((0, types_1.isClass)(type)) {
@@ -2876,7 +2886,7 @@ class TypeVarTransformer {
2876
2886
  transformUnionSubtype(preTransform, postTransform, recursionCount) {
2877
2887
  return postTransform;
2878
2888
  }
2879
- doForEachSignatureContext(callback) {
2889
+ doForEachSolutionSet(callback) {
2880
2890
  // By default, simply return the result of the callback. Subclasses
2881
2891
  // can override this method as they see fit.
2882
2892
  return callback();
@@ -2884,11 +2894,11 @@ class TypeVarTransformer {
2884
2894
  transformGenericTypeAlias(type, recursionCount) {
2885
2895
  var _a;
2886
2896
  const aliasInfo = (_a = type.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
2887
- if (!aliasInfo || !aliasInfo.typeParameters || !aliasInfo.typeArguments) {
2897
+ if (!aliasInfo || !aliasInfo.typeParams || !aliasInfo.typeArgs) {
2888
2898
  return type;
2889
2899
  }
2890
2900
  let requiresUpdate = false;
2891
- const newTypeArgs = aliasInfo.typeArguments.map((typeArg) => {
2901
+ const newTypeArgs = aliasInfo.typeArgs.map((typeArg) => {
2892
2902
  const updatedType = this.apply(typeArg, recursionCount);
2893
2903
  if (type !== updatedType) {
2894
2904
  requiresUpdate = true;
@@ -2896,7 +2906,7 @@ class TypeVarTransformer {
2896
2906
  return updatedType;
2897
2907
  });
2898
2908
  return requiresUpdate
2899
- ? types_1.TypeBase.cloneForTypeAlias(type, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParameters, newTypeArgs)
2909
+ ? types_1.TypeBase.cloneForTypeAlias(type, aliasInfo.name, aliasInfo.fullName, aliasInfo.moduleName, aliasInfo.fileUri, aliasInfo.typeVarScopeId, aliasInfo.isPep695Syntax, aliasInfo.typeParams, newTypeArgs)
2900
2910
  : type;
2901
2911
  }
2902
2912
  transformConditionalType(type, recursionCount) {
@@ -2904,7 +2914,7 @@ class TypeVarTransformer {
2904
2914
  return type;
2905
2915
  }
2906
2916
  transformTypeVarsInClassType(classType, recursionCount) {
2907
- const typeParams = types_1.ClassType.getTypeParameters(classType);
2917
+ const typeParams = types_1.ClassType.getTypeParams(classType);
2908
2918
  // Handle the common case where the class has no type parameters.
2909
2919
  if (typeParams.length === 0 &&
2910
2920
  !types_1.ClassType.isSpecialBuiltIn(classType) &&
@@ -2929,18 +2939,18 @@ class TypeVarTransformer {
2929
2939
  // If type args were previously provided, specialize them.
2930
2940
  // Handle tuples specially.
2931
2941
  if (types_1.ClassType.isTupleClass(classType)) {
2932
- if (classType.priv.tupleTypeArguments) {
2942
+ if (classType.priv.tupleTypeArgs) {
2933
2943
  newTupleTypeArgs = [];
2934
- classType.priv.tupleTypeArguments.forEach((oldTypeArgType) => {
2944
+ classType.priv.tupleTypeArgs.forEach((oldTypeArgType) => {
2935
2945
  const newTypeArgType = this.apply(oldTypeArgType.type, recursionCount);
2936
2946
  if (newTypeArgType !== oldTypeArgType.type) {
2937
2947
  specializationNeeded = true;
2938
2948
  }
2939
- if ((0, types_1.isUnpackedVariadicTypeVar)(oldTypeArgType.type) &&
2949
+ if ((0, types_1.isUnpackedTypeVarTuple)(oldTypeArgType.type) &&
2940
2950
  (0, types_1.isClassInstance)(newTypeArgType) &&
2941
2951
  isTupleClass(newTypeArgType) &&
2942
- newTypeArgType.priv.tupleTypeArguments) {
2943
- (0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.priv.tupleTypeArguments);
2952
+ newTypeArgType.priv.tupleTypeArgs) {
2953
+ (0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.priv.tupleTypeArgs);
2944
2954
  }
2945
2955
  else {
2946
2956
  // Handle the special case where tuple[T, ...] is being specialized
@@ -2948,7 +2958,7 @@ class TypeVarTransformer {
2948
2958
  const isEmptyTuple = oldTypeArgType.isUnbounded &&
2949
2959
  (0, types_1.isTypeVar)(oldTypeArgType.type) &&
2950
2960
  (0, types_1.isNever)(newTypeArgType) &&
2951
- classType.priv.tupleTypeArguments.length === 1;
2961
+ classType.priv.tupleTypeArgs.length === 1;
2952
2962
  if (!isEmptyTuple) {
2953
2963
  newTupleTypeArgs.push({
2954
2964
  type: newTypeArgType,
@@ -2973,21 +2983,13 @@ class TypeVarTransformer {
2973
2983
  // If this is an empty tuple, don't recompute the non-tuple type argument.
2974
2984
  if (newTupleTypeArgs && newTupleTypeArgs.length > 0) {
2975
2985
  // Combine the tuple type args into a single non-tuple type argument.
2976
- newTypeArgs = [
2977
- (0, types_1.combineTypes)(newTupleTypeArgs.map((t) => {
2978
- if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedVariadicTypeVar)(t.type)) {
2979
- // Treat the unpacked TypeVarTuple as a union.
2980
- return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
2981
- }
2982
- return t.type;
2983
- })),
2984
- ];
2986
+ newTypeArgs = [combineTupleTypeArgs(newTupleTypeArgs)];
2985
2987
  }
2986
2988
  }
2987
2989
  if (!newTypeArgs) {
2988
- if (classType.priv.typeArguments) {
2989
- newTypeArgs = classType.priv.typeArguments.map((oldTypeArgType) => {
2990
- if ((0, types_1.isTypeVar)(oldTypeArgType) && oldTypeArgType.shared.isParamSpec) {
2990
+ if (classType.priv.typeArgs) {
2991
+ newTypeArgs = classType.priv.typeArgs.map((oldTypeArgType) => {
2992
+ if ((0, types_1.isParamSpec)(oldTypeArgType)) {
2991
2993
  return transformParamSpec(oldTypeArgType);
2992
2994
  }
2993
2995
  let newTypeArgType = this.apply(oldTypeArgType, recursionCount);
@@ -2996,7 +2998,7 @@ class TypeVarTransformer {
2996
2998
  // If this was a variadic type variable that was part of a union
2997
2999
  // (e.g. Union[Unpack[Vs]]), expand the subtypes into a union here.
2998
3000
  if ((0, types_1.isTypeVar)(oldTypeArgType) &&
2999
- (0, types_1.isVariadicTypeVar)(oldTypeArgType) &&
3001
+ (0, types_1.isTypeVarTuple)(oldTypeArgType) &&
3000
3002
  oldTypeArgType.priv.isVariadicInUnion) {
3001
3003
  newTypeArgType = _expandVariadicUnpackedUnion(newTypeArgType);
3002
3004
  }
@@ -3008,7 +3010,7 @@ class TypeVarTransformer {
3008
3010
  newTypeArgs = [];
3009
3011
  typeParams.forEach((typeParam) => {
3010
3012
  let replacementType = typeParam;
3011
- if (typeParam.shared.isParamSpec) {
3013
+ if ((0, types_1.isParamSpec)(typeParam)) {
3012
3014
  replacementType = transformParamSpec(typeParam);
3013
3015
  if (replacementType !== typeParam) {
3014
3016
  specializationNeeded = true;
@@ -3021,7 +3023,7 @@ class TypeVarTransformer {
3021
3023
  if (replacementType !== typeParam) {
3022
3024
  specializationNeeded = true;
3023
3025
  }
3024
- else if (transformedType !== undefined && !classType.priv.typeArguments) {
3026
+ else if (transformedType !== undefined && !classType.priv.typeArgs) {
3025
3027
  specializationNeeded = true;
3026
3028
  }
3027
3029
  }
@@ -3035,19 +3037,19 @@ class TypeVarTransformer {
3035
3037
  if (!specializationNeeded) {
3036
3038
  return classType;
3037
3039
  }
3038
- return types_1.ClassType.cloneForSpecialization(classType, newTypeArgs,
3039
- /* isTypeArgumentExplicit */ true,
3040
+ return types_1.ClassType.specialize(classType, newTypeArgs,
3041
+ /* isTypeArgExplicit */ true,
3040
3042
  /* includeSubclasses */ undefined, newTupleTypeArgs);
3041
3043
  }
3042
3044
  transformTypeVarsInFunctionType(sourceType, recursionCount) {
3043
- return this.doForEachSignatureContext(() => {
3045
+ return this.doForEachSolutionSet(() => {
3044
3046
  let functionType = sourceType;
3045
3047
  const declaredReturnType = types_1.FunctionType.getEffectiveReturnType(functionType);
3046
3048
  const specializedReturnType = declaredReturnType
3047
3049
  ? this.apply(declaredReturnType, recursionCount)
3048
3050
  : undefined;
3049
3051
  let typesRequiredSpecialization = declaredReturnType !== specializedReturnType;
3050
- const specializedParameters = {
3052
+ const specializedParams = {
3051
3053
  parameterTypes: [],
3052
3054
  parameterDefaultArgs: undefined,
3053
3055
  returnType: specializedReturnType,
@@ -3070,11 +3072,11 @@ class TypeVarTransformer {
3070
3072
  const wasTransformingTypeArg = this._isTransformingTypeArg;
3071
3073
  this._isTransformingTypeArg = true;
3072
3074
  for (let i = 0; i < functionType.shared.parameters.length; i++) {
3073
- const paramType = types_1.FunctionType.getEffectiveParameterType(functionType, i);
3075
+ const paramType = types_1.FunctionType.getEffectiveParamType(functionType, i);
3074
3076
  const specializedType = this.apply(paramType, recursionCount);
3075
- specializedParameters.parameterTypes.push(specializedType);
3077
+ specializedParams.parameterTypes.push(specializedType);
3076
3078
  // Do we need to specialize the default argument type for this parameter?
3077
- let defaultArgType = types_1.FunctionType.getEffectiveParameterDefaultArgType(functionType, i);
3079
+ let defaultArgType = types_1.FunctionType.getEffectiveParamDefaultArgType(functionType, i);
3078
3080
  if (defaultArgType) {
3079
3081
  const specializedArgType = this.apply(defaultArgType, recursionCount);
3080
3082
  if (specializedArgType !== defaultArgType) {
@@ -3084,13 +3086,13 @@ class TypeVarTransformer {
3084
3086
  }
3085
3087
  specializedDefaultArgs.push(defaultArgType);
3086
3088
  if (variadicParamIndex === undefined &&
3087
- (0, types_1.isVariadicTypeVar)(paramType) &&
3088
- functionType.shared.parameters[i].category === 1 /* ParameterCategory.ArgsList */) {
3089
+ (0, types_1.isTypeVarTuple)(paramType) &&
3090
+ functionType.shared.parameters[i].category === 1 /* ParamCategory.ArgsList */) {
3089
3091
  variadicParamIndex = i;
3090
3092
  if ((0, types_1.isClassInstance)(specializedType) &&
3091
3093
  isTupleClass(specializedType) &&
3092
3094
  specializedType.priv.isUnpacked) {
3093
- variadicTypesToUnpack = specializedType.priv.tupleTypeArguments;
3095
+ variadicTypesToUnpack = specializedType.priv.tupleTypeArgs;
3094
3096
  }
3095
3097
  }
3096
3098
  if (paramType !== specializedType) {
@@ -3124,11 +3126,11 @@ class TypeVarTransformer {
3124
3126
  return functionType;
3125
3127
  }
3126
3128
  if (specializedDefaultArgs.some((t) => t !== undefined)) {
3127
- specializedParameters.parameterDefaultArgs = specializedDefaultArgs;
3129
+ specializedParams.parameterDefaultArgs = specializedDefaultArgs;
3128
3130
  }
3129
3131
  // If there was no unpacked variadic type variable, we're done.
3130
3132
  if (!variadicTypesToUnpack) {
3131
- return types_1.FunctionType.cloneForSpecialization(functionType, specializedParameters, specializedInferredReturnType);
3133
+ return types_1.FunctionType.specialize(functionType, specializedParams, specializedInferredReturnType);
3132
3134
  }
3133
3135
  // Unpack the tuple and synthesize a new function in the process.
3134
3136
  const newFunctionType = types_1.TypeBase.isInstantiable(functionType)
@@ -3136,14 +3138,14 @@ class TypeVarTransformer {
3136
3138
  : types_1.FunctionType.createSynthesizedInstance('', functionType.shared.flags);
3137
3139
  let insertKeywordOnlySeparator = false;
3138
3140
  let swallowPositionOnlySeparator = false;
3139
- specializedParameters.parameterTypes.forEach((paramType, index) => {
3141
+ specializedParams.parameterTypes.forEach((paramType, index) => {
3140
3142
  if (index === variadicParamIndex) {
3141
3143
  let sawUnboundedEntry = false;
3142
3144
  // Unpack the tuple into individual parameters.
3143
3145
  variadicTypesToUnpack.forEach((unpackedType) => {
3144
- types_1.FunctionType.addParameter(newFunctionType, types_1.FunctionParam.create(unpackedType.isUnbounded || (0, types_1.isVariadicTypeVar)(unpackedType.type)
3145
- ? 1 /* ParameterCategory.ArgsList */
3146
- : 0 /* ParameterCategory.Simple */, unpackedType.type, types_1.FunctionParamFlags.NameSynthesized | types_1.FunctionParamFlags.TypeDeclared, `__p${newFunctionType.shared.parameters.length}`));
3146
+ types_1.FunctionType.addParam(newFunctionType, types_1.FunctionParam.create(unpackedType.isUnbounded || (0, types_1.isTypeVarTuple)(unpackedType.type)
3147
+ ? 1 /* ParamCategory.ArgsList */
3148
+ : 0 /* ParamCategory.Simple */, unpackedType.type, types_1.FunctionParamFlags.NameSynthesized | types_1.FunctionParamFlags.TypeDeclared, `__p${newFunctionType.shared.parameters.length}`));
3147
3149
  if (unpackedType.isUnbounded) {
3148
3150
  sawUnboundedEntry = true;
3149
3151
  }
@@ -3160,25 +3162,25 @@ class TypeVarTransformer {
3160
3162
  if ((0, types_1.isKeywordOnlySeparator)(param)) {
3161
3163
  insertKeywordOnlySeparator = false;
3162
3164
  }
3163
- else if (param.category === 2 /* ParameterCategory.KwargsDict */) {
3165
+ else if (param.category === 2 /* ParamCategory.KwargsDict */) {
3164
3166
  insertKeywordOnlySeparator = false;
3165
3167
  }
3166
3168
  // Insert a keyword-only separator parameter if we previously
3167
3169
  // unpacked a variadic TypeVar.
3168
- if (param.category === 0 /* ParameterCategory.Simple */ && param.name && insertKeywordOnlySeparator) {
3169
- types_1.FunctionType.addKeywordOnlyParameterSeparator(newFunctionType);
3170
+ if (param.category === 0 /* ParamCategory.Simple */ && param.name && insertKeywordOnlySeparator) {
3171
+ types_1.FunctionType.addKeywordOnlyParamSeparator(newFunctionType);
3170
3172
  insertKeywordOnlySeparator = false;
3171
3173
  }
3172
3174
  param.type = paramType;
3173
3175
  if (param.name && types_1.FunctionParam.isNameSynthesized(param)) {
3174
3176
  param.name = `__p${newFunctionType.shared.parameters.length}`;
3175
3177
  }
3176
- if (param.category !== 0 /* ParameterCategory.Simple */ || param.name || !swallowPositionOnlySeparator) {
3177
- types_1.FunctionType.addParameter(newFunctionType, param);
3178
+ if (param.category !== 0 /* ParamCategory.Simple */ || param.name || !swallowPositionOnlySeparator) {
3179
+ types_1.FunctionType.addParam(newFunctionType, param);
3178
3180
  }
3179
3181
  }
3180
3182
  });
3181
- newFunctionType.shared.declaredReturnType = specializedParameters.returnType;
3183
+ newFunctionType.shared.declaredReturnType = specializedParams.returnType;
3182
3184
  return newFunctionType;
3183
3185
  });
3184
3186
  }
@@ -3195,7 +3197,7 @@ class TypeVarAnyReplacer extends TypeVarTransformer {
3195
3197
  return types_1.AnyType.create();
3196
3198
  }
3197
3199
  transformParamSpec(paramSpec) {
3198
- return getUnknownTypeForParamSpec();
3200
+ return types_1.ParamSpecType.getUnknown();
3199
3201
  }
3200
3202
  }
3201
3203
  // For a TypeVar with a default type, validates whether the default type is using
@@ -3236,11 +3238,8 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
3236
3238
  return classType;
3237
3239
  }
3238
3240
  transformTypeVarsInFunctionType(sourceType, recursionCount) {
3239
- if (sourceType.priv.trackedSignatures) {
3240
- this._signatureTracker.addTrackedSignatures(sourceType.priv.trackedSignatures);
3241
- }
3242
3241
  // If this function is not generic, there's no need to check for uniqueness.
3243
- if (sourceType.shared.typeParameters.length === 0) {
3242
+ if (sourceType.shared.typeParams.length === 0) {
3244
3243
  return super.transformTypeVarsInFunctionType(sourceType, recursionCount);
3245
3244
  }
3246
3245
  let updatedSourceType = sourceType;
@@ -3254,13 +3253,10 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
3254
3253
  const typeVarContext = new typeVarContext_1.TypeVarContext(getTypeVarScopeIds(sourceType));
3255
3254
  // Create new type variables with the same scope but with
3256
3255
  // different (unique) names.
3257
- sourceType.shared.typeParameters.forEach((typeParam) => {
3256
+ sourceType.shared.typeParams.forEach((typeParam) => {
3258
3257
  if (typeParam.priv.scopeType === 1 /* TypeVarScopeType.Function */) {
3259
- let replacement = types_1.TypeVarType.cloneForNewName(typeParam, `${typeParam.shared.name}(${offsetIndex})`);
3260
- if (replacement.shared.isParamSpec) {
3261
- replacement = convertTypeToParamSpecValue(replacement);
3262
- }
3263
- typeVarContext.setTypeVarType(typeParam, replacement);
3258
+ const replacement = types_1.TypeVarType.cloneForNewName(typeParam, `${typeParam.shared.name}(${offsetIndex})`);
3259
+ setTypeVarType(typeVarContext, typeParam, replacement);
3264
3260
  }
3265
3261
  });
3266
3262
  updatedSourceType = applySolvedTypeVars(sourceType, typeVarContext);
@@ -3271,6 +3267,58 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
3271
3267
  return updatedSourceType;
3272
3268
  }
3273
3269
  }
3270
+ // Replaces the TypeVars within a type with their corresponding "internal"
3271
+ // types if they are in one of the specified scopes.
3272
+ class InternalScopeUpdateTransform extends TypeVarTransformer {
3273
+ constructor(_scopeIds) {
3274
+ super();
3275
+ this._scopeIds = _scopeIds;
3276
+ }
3277
+ transformTypeVar(typeVar) {
3278
+ if (this._isTypeVarInScope(typeVar)) {
3279
+ return this._replaceTypeVar(typeVar);
3280
+ }
3281
+ return undefined;
3282
+ }
3283
+ transformParamSpec(paramSpec) {
3284
+ if (this._isTypeVarInScope(paramSpec)) {
3285
+ return convertTypeToParamSpecValue(this._replaceTypeVar(paramSpec));
3286
+ }
3287
+ return undefined;
3288
+ }
3289
+ _isTypeVarInScope(typeVar) {
3290
+ return typeVar.priv.scopeId !== undefined && this._scopeIds.includes(typeVar.priv.scopeId);
3291
+ }
3292
+ _replaceTypeVar(typeVar) {
3293
+ return types_1.TypeVarType.cloneWithInternalScopeId(typeVar);
3294
+ }
3295
+ }
3296
+ // Replaces the internal TypeVars within a type with their corresponding
3297
+ // "external" types.
3298
+ class ExternalScopeUpdateTransform extends TypeVarTransformer {
3299
+ constructor(_scopeIds) {
3300
+ super();
3301
+ this._scopeIds = _scopeIds;
3302
+ }
3303
+ transformTypeVar(typeVar) {
3304
+ if (typeVar.priv.externalTypeVar && this._isTypeVarInScope(typeVar.priv.externalTypeVar)) {
3305
+ return typeVar.priv.externalTypeVar;
3306
+ }
3307
+ return undefined;
3308
+ }
3309
+ transformParamSpec(paramSpec) {
3310
+ if (paramSpec.priv.externalTypeVar && this._isTypeVarInScope(paramSpec.priv.externalTypeVar)) {
3311
+ return convertTypeToParamSpecValue(paramSpec.priv.externalTypeVar);
3312
+ }
3313
+ return undefined;
3314
+ }
3315
+ _isTypeVarInScope(typeVar) {
3316
+ if (!typeVar.priv.scopeId) {
3317
+ return false;
3318
+ }
3319
+ return this._scopeIds.includes(typeVar.priv.scopeId);
3320
+ }
3321
+ }
3274
3322
  // Specializes a (potentially generic) type by substituting
3275
3323
  // type variables from a type var map.
3276
3324
  class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
@@ -3282,16 +3330,16 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3282
3330
  }
3283
3331
  transformTypeVar(typeVar, recursionCount) {
3284
3332
  var _a, _b;
3285
- const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
3333
+ const solutionSet = this._typeVarContext.getSolutionSet((_a = this._activeSolutionSetIndex) !== null && _a !== void 0 ? _a : 0);
3286
3334
  // If the type variable is unrelated to the scopes we're solving,
3287
3335
  // don't transform that type variable.
3288
3336
  if (typeVar.priv.scopeId && this._typeVarContext.hasSolveForScope(typeVar.priv.scopeId)) {
3289
- let replacement = signatureContext.getTypeVarType(typeVar, !!this._options.useNarrowBoundOnly);
3290
- // If there was no narrow bound but there is a wide bound that
3291
- // contains literals or a TypeVar, we'll use the wide bound even if
3292
- // "useNarrowBoundOnly" is specified.
3293
- if (!replacement && this._options.useNarrowBoundOnly) {
3294
- const wideType = signatureContext.getTypeVarType(typeVar);
3337
+ let replacement = solutionSet.getTypeVarType(typeVar, !!this._options.useLowerBoundOnly);
3338
+ // If there was no lower bound but there is an upper bound that
3339
+ // contains literals or a TypeVar, we'll use the upper bound even if
3340
+ // "useLowerBoundOnly" is specified.
3341
+ if (!replacement && this._options.useLowerBoundOnly) {
3342
+ const wideType = solutionSet.getTypeVarType(typeVar);
3295
3343
  if (wideType) {
3296
3344
  if ((0, types_1.isTypeVar)(wideType) || containsLiteralType(wideType, /* includeTypeArgs */ true)) {
3297
3345
  replacement = wideType;
@@ -3303,8 +3351,9 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3303
3351
  if ((0, types_1.isAnyOrUnknown)(replacement) &&
3304
3352
  this._options.typeClassType &&
3305
3353
  (0, types_1.isInstantiableClass)(this._options.typeClassType)) {
3306
- replacement = types_1.ClassType.cloneForSpecialization(types_1.ClassType.cloneAsInstance(this._options.typeClassType), [replacement],
3307
- /* isTypeArgumentExplicit */ true);
3354
+ replacement = types_1.ClassType.specialize(types_1.ClassType.cloneAsInstance(this._options.typeClassType), [
3355
+ replacement,
3356
+ ]);
3308
3357
  }
3309
3358
  else {
3310
3359
  replacement = convertToInstantiable(replacement, /* includeSubclasses */ false);
@@ -3322,18 +3371,28 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3322
3371
  if (!subtype.priv.includeSubclasses) {
3323
3372
  subtype = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneAsInstantiable(subtype));
3324
3373
  }
3325
- if (this._options.unknownIfNotFound) {
3326
- return this._options.useUnknownOverDefault
3327
- ? specializeWithUnknownTypeArgs(subtype, this._options.tupleClassType)
3328
- : specializeWithDefaultTypeArgs(subtype);
3374
+ if (subtype.shared.typeParams && !subtype.priv.typeArgs) {
3375
+ if (this._options.unknownIfNotFound) {
3376
+ return this._options.useUnknownOverDefault
3377
+ ? specializeWithUnknownTypeArgs(subtype, this._options.tupleClassType)
3378
+ : specializeWithDefaultTypeArgs(subtype);
3379
+ }
3329
3380
  }
3330
3381
  }
3331
3382
  return subtype;
3332
3383
  });
3333
3384
  }
3334
- if ((0, types_1.isTypeVar)(replacement) && typeVar.priv.isVariadicUnpacked && replacement.shared.isVariadic) {
3385
+ if ((0, types_1.isTypeVarTuple)(replacement) && (0, types_1.isTypeVarTuple)(typeVar) && typeVar.priv.isVariadicUnpacked) {
3335
3386
  return types_1.TypeVarType.cloneForUnpacked(replacement, typeVar.priv.isVariadicInUnion);
3336
3387
  }
3388
+ // If this isn't a variadic typeVar, combine all of the tuple
3389
+ // type args into a common type.
3390
+ if (!(0, types_1.isTypeVarTuple)(typeVar) &&
3391
+ (0, types_1.isClassInstance)(replacement) &&
3392
+ replacement.priv.tupleTypeArgs &&
3393
+ replacement.priv.isUnpacked) {
3394
+ replacement = combineTupleTypeArgs(replacement.priv.tupleTypeArgs);
3395
+ }
3337
3396
  if (!(0, types_1.isTypeVar)(replacement) ||
3338
3397
  !replacement.priv.isInScopePlaceholder ||
3339
3398
  !this._options.unknownIfNotFound) {
@@ -3357,18 +3416,18 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3357
3416
  if (useDefaultOrUnknown) {
3358
3417
  // Use the default value if there is one.
3359
3418
  if (typeVar.shared.isDefaultExplicit && !this._options.useUnknownOverDefault) {
3360
- return this._solveDefaultType(typeVar.shared.defaultType, recursionCount);
3419
+ return this._solveDefaultType(typeVar, recursionCount);
3361
3420
  }
3362
- return getUnknownTypeForTypeVar(typeVar, this._options.tupleClassType);
3421
+ return getUnknownForTypeVar(typeVar, this._options.tupleClassType);
3363
3422
  }
3364
3423
  }
3365
3424
  // If we're solving a default type, handle type variables with no scope ID.
3366
3425
  if (this._isSolvingDefaultType && !typeVar.priv.scopeId) {
3367
- const replacementEntry = signatureContext
3426
+ const replacementEntry = solutionSet
3368
3427
  .getTypeVars()
3369
3428
  .find((entry) => entry.typeVar.shared.name === typeVar.shared.name);
3370
3429
  if (replacementEntry) {
3371
- return signatureContext.getTypeVarType(replacementEntry.typeVar);
3430
+ return solutionSet.getTypeVarType(replacementEntry.typeVar);
3372
3431
  }
3373
3432
  if (typeVar.shared.isDefaultExplicit) {
3374
3433
  return this.apply(typeVar.shared.defaultType, recursionCount);
@@ -3388,8 +3447,8 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3388
3447
  if ((0, types_1.isTypeVar)(preTransform) &&
3389
3448
  preTransform.priv.scopeId !== undefined &&
3390
3449
  this._typeVarContext.hasSolveForScope(preTransform.priv.scopeId)) {
3391
- const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
3392
- const typeVarType = signatureContext.getTypeVarType(preTransform);
3450
+ const solutionSet = this._typeVarContext.getSolutionSet((_a = this._activeSolutionSetIndex) !== null && _a !== void 0 ? _a : 0);
3451
+ const typeVarType = solutionSet.getTypeVarType(preTransform);
3393
3452
  // Did the TypeVar remain unsolved?
3394
3453
  if (!typeVarType || ((0, types_1.isTypeVar)(typeVarType) && typeVarType.priv.isInScopePlaceholder)) {
3395
3454
  // If the TypeVar was not transformed, then it was unsolved,
@@ -3411,36 +3470,38 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3411
3470
  var _a;
3412
3471
  if (!typeVar.priv.scopeId || !this._typeVarContext.hasSolveForScope(typeVar.priv.scopeId)) {
3413
3472
  const defaultType = typeVar.shared.defaultType;
3414
- if (typeVar.shared.isDefaultExplicit &&
3415
- (0, types_1.isClassInstance)(defaultType) &&
3416
- defaultType.priv.tupleTypeArguments) {
3417
- return defaultType.priv.tupleTypeArguments;
3473
+ if (typeVar.shared.isDefaultExplicit && (0, types_1.isClassInstance)(defaultType) && defaultType.priv.tupleTypeArgs) {
3474
+ return defaultType.priv.tupleTypeArgs;
3418
3475
  }
3419
3476
  return undefined;
3420
3477
  }
3421
- const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
3422
- return signatureContext.getTupleTypeVar(typeVar);
3478
+ const solutionSet = this._typeVarContext.getSolutionSet((_a = this._activeSolutionSetIndex) !== null && _a !== void 0 ? _a : 0);
3479
+ const value = solutionSet.getTypeVarType(typeVar);
3480
+ if (value && (0, types_1.isClassInstance)(value) && value.priv.tupleTypeArgs && (0, types_1.isUnpackedClass)(value)) {
3481
+ return value.priv.tupleTypeArgs;
3482
+ }
3483
+ return undefined;
3423
3484
  }
3424
3485
  transformParamSpec(paramSpec, recursionCount) {
3425
3486
  var _a, _b;
3426
- const signatureContext = this._typeVarContext.getSignatureContext((_a = this._activeTypeVarSignatureContextIndex) !== null && _a !== void 0 ? _a : 0);
3487
+ const solutionSet = this._typeVarContext.getSolutionSet((_a = this._activeSolutionSetIndex) !== null && _a !== void 0 ? _a : 0);
3427
3488
  // If we're solving a default type, handle param specs with no scope ID.
3428
3489
  if (this._isSolvingDefaultType && !paramSpec.priv.scopeId) {
3429
- const replacementEntry = signatureContext
3490
+ const replacementEntry = solutionSet
3430
3491
  .getTypeVars()
3431
3492
  .find((entry) => entry.typeVar.shared.name === paramSpec.shared.name);
3432
- if (replacementEntry) {
3433
- return signatureContext.getParamSpecType(replacementEntry.typeVar);
3493
+ if (replacementEntry && (0, types_1.isParamSpec)(replacementEntry.typeVar)) {
3494
+ return solutionSet.getTypeVarType(replacementEntry.typeVar);
3434
3495
  }
3435
3496
  if (paramSpec.shared.isDefaultExplicit) {
3436
3497
  return convertTypeToParamSpecValue(this.apply(paramSpec.shared.defaultType, recursionCount));
3437
3498
  }
3438
- return getUnknownTypeForParamSpec();
3499
+ return types_1.ParamSpecType.getUnknown();
3439
3500
  }
3440
3501
  if (!paramSpec.priv.scopeId || !this._typeVarContext.hasSolveForScope(paramSpec.priv.scopeId)) {
3441
3502
  return undefined;
3442
3503
  }
3443
- const transformedParamSpec = signatureContext.getParamSpecType(paramSpec);
3504
+ const transformedParamSpec = solutionSet.getTypeVarType(paramSpec);
3444
3505
  if (transformedParamSpec) {
3445
3506
  return transformedParamSpec;
3446
3507
  }
@@ -3457,29 +3518,30 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3457
3518
  if (useDefaultOrUnknown) {
3458
3519
  // Use the default value if there is one.
3459
3520
  if (paramSpec.shared.isDefaultExplicit && !this._options.useUnknownOverDefault) {
3460
- return convertTypeToParamSpecValue(this._solveDefaultType(paramSpec.shared.defaultType, recursionCount));
3521
+ return convertTypeToParamSpecValue(this._solveDefaultType(paramSpec, recursionCount));
3461
3522
  }
3462
3523
  // Convert to the ParamSpec equivalent of "Unknown".
3463
- return getUnknownTypeForParamSpec();
3524
+ return types_1.ParamSpecType.getUnknown();
3464
3525
  }
3465
3526
  return undefined;
3466
3527
  }
3467
3528
  transformConditionalType(type, recursionCount) {
3468
- var _a, _b;
3529
+ var _a, _b, _c, _d;
3469
3530
  if (!((_a = type.props) === null || _a === void 0 ? void 0 : _a.condition)) {
3470
3531
  return type;
3471
3532
  }
3472
- const signatureContext = this._typeVarContext.getSignatureContext((_b = this._activeTypeVarSignatureContextIndex) !== null && _b !== void 0 ? _b : 0);
3533
+ const solutionSet = this._typeVarContext.getSolutionSet((_b = this._activeSolutionSetIndex) !== null && _b !== void 0 ? _b : 0);
3473
3534
  for (const condition of type.props.condition) {
3474
3535
  // This doesn't apply to bound type variables.
3475
3536
  if (condition.typeVar.shared.constraints.length === 0) {
3476
3537
  continue;
3477
3538
  }
3478
- const typeVarEntry = signatureContext.getTypeVar(condition.typeVar);
3539
+ const conditionTypeVar = (_d = (_c = condition.typeVar.priv) === null || _c === void 0 ? void 0 : _c.externalTypeVar) !== null && _d !== void 0 ? _d : condition.typeVar;
3540
+ const typeVarEntry = solutionSet.getTypeVar(conditionTypeVar);
3479
3541
  if (!typeVarEntry || condition.constraintIndex >= typeVarEntry.typeVar.shared.constraints.length) {
3480
3542
  continue;
3481
3543
  }
3482
- const value = signatureContext.getTypeVarType(typeVarEntry.typeVar);
3544
+ const value = solutionSet.getTypeVarType(typeVarEntry.typeVar);
3483
3545
  if (!value) {
3484
3546
  continue;
3485
3547
  }
@@ -3491,19 +3553,19 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3491
3553
  }
3492
3554
  return type;
3493
3555
  }
3494
- doForEachSignatureContext(callback) {
3495
- const signatureContexts = this._typeVarContext.getSignatureContexts();
3556
+ doForEachSolutionSet(callback) {
3557
+ const solutionSet = this._typeVarContext.getSolutionSets();
3496
3558
  // Handle the common case where there are not multiple signature contexts.
3497
- if (signatureContexts.length <= 1) {
3559
+ if (solutionSet.length <= 1) {
3498
3560
  return callback();
3499
3561
  }
3500
3562
  // Loop through all of the signature contexts in the type var context
3501
3563
  // to create an overload type.
3502
- const overloadTypes = signatureContexts.map((_, index) => {
3503
- this._activeTypeVarSignatureContextIndex = index;
3564
+ const overloadTypes = solutionSet.map((_, index) => {
3565
+ this._activeSolutionSetIndex = index;
3504
3566
  return callback();
3505
3567
  });
3506
- this._activeTypeVarSignatureContextIndex = undefined;
3568
+ this._activeSolutionSetIndex = undefined;
3507
3569
  const filteredOverloads = [];
3508
3570
  doForEachSubtype((0, types_1.combineTypes)(overloadTypes), (subtype) => {
3509
3571
  (0, debug_1.assert)((0, types_1.isFunction)(subtype));
@@ -3515,7 +3577,8 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3515
3577
  }
3516
3578
  return types_1.OverloadedFunctionType.create(filteredOverloads);
3517
3579
  }
3518
- _solveDefaultType(defaultType, recursionCount) {
3580
+ _solveDefaultType(typeVar, recursionCount) {
3581
+ const defaultType = typeVar.shared.defaultType;
3519
3582
  const wasSolvingDefaultType = this._isSolvingDefaultType;
3520
3583
  this._isSolvingDefaultType = true;
3521
3584
  const result = this.apply(defaultType, recursionCount);
@@ -3533,7 +3596,7 @@ class ExpectedTypeTransformer extends TypeVarTransformer {
3533
3596
  if (!this._isTypeVarLive(typeVar)) {
3534
3597
  return types_1.TypeVarType.cloneAsInScopePlaceholder(typeVar, this._usageOffset);
3535
3598
  }
3536
- return typeVar;
3599
+ return undefined;
3537
3600
  }
3538
3601
  transformParamSpec(paramSpec) {
3539
3602
  if (!this._isTypeVarLive(paramSpec)) {
@@ -3542,35 +3605,35 @@ class ExpectedTypeTransformer extends TypeVarTransformer {
3542
3605
  return undefined;
3543
3606
  }
3544
3607
  _isTypeVarLive(typeVar) {
3545
- return this._liveTypeVarScopes.some((scopeId) => typeVar.priv.scopeId === scopeId);
3608
+ return this._liveTypeVarScopes.some((scopeId) => { var _a; return typeVar.priv.scopeId === scopeId || ((_a = typeVar.priv.externalTypeVar) === null || _a === void 0 ? void 0 : _a.priv.scopeId) === scopeId; });
3546
3609
  }
3547
3610
  }
3548
3611
  class InScopePlaceholderTransformer extends TypeVarTransformer {
3549
- constructor(_signatureContext) {
3612
+ constructor(_solutionSet) {
3550
3613
  super();
3551
- this._signatureContext = _signatureContext;
3614
+ this._solutionSet = _solutionSet;
3552
3615
  }
3553
3616
  transformTypeVar(typeVar) {
3554
3617
  var _a;
3555
3618
  if (typeVar.priv.isInScopePlaceholder) {
3556
- return (_a = this._signatureContext.getTypeVarType(typeVar)) !== null && _a !== void 0 ? _a : typeVar;
3619
+ return (_a = this._solutionSet.getTypeVarType(typeVar)) !== null && _a !== void 0 ? _a : typeVar;
3557
3620
  }
3558
- return typeVar;
3621
+ return undefined;
3559
3622
  }
3560
3623
  transformParamSpec(paramSpec) {
3561
3624
  if (paramSpec.priv.isInScopePlaceholder) {
3562
- return this._signatureContext.getParamSpecType(paramSpec);
3625
+ return this._solutionSet.getTypeVarType(paramSpec);
3563
3626
  }
3564
3627
  return undefined;
3565
3628
  }
3566
3629
  }
3567
- function applyInScopePlaceholdersToType(type, signatureContext) {
3630
+ function applyInScopePlaceholdersToType(type, solutionSet) {
3568
3631
  // Handle the common case where there are no in-scope placeholders.
3569
3632
  // No more work is required in this case.
3570
- if (!signatureContext.getTypeVars().some((entry) => entry.typeVar.priv.isInScopePlaceholder)) {
3633
+ if (!solutionSet.getTypeVars().some((entry) => entry.typeVar.priv.isInScopePlaceholder)) {
3571
3634
  return type;
3572
3635
  }
3573
- const transformer = new InScopePlaceholderTransformer(signatureContext);
3636
+ const transformer = new InScopePlaceholderTransformer(solutionSet);
3574
3637
  return transformer.apply(type, 0);
3575
3638
  }
3576
3639
  //# sourceMappingURL=typeUtils.js.map