@zzzen/pyright-internal 1.2.0-dev.20240721 → 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 (211) 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 +115 -122
  9. package/dist/analyzer/checker.js.map +1 -1
  10. package/dist/analyzer/codeFlowEngine.d.ts +2 -2
  11. package/dist/analyzer/codeFlowEngine.js +49 -42
  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 +164 -204
  17. package/dist/analyzer/constraintSolver.js.map +1 -1
  18. package/dist/analyzer/constructorTransform.d.ts +2 -2
  19. package/dist/analyzer/constructorTransform.js +15 -15
  20. package/dist/analyzer/constructorTransform.js.map +1 -1
  21. package/dist/analyzer/constructors.d.ts +2 -2
  22. package/dist/analyzer/constructors.js +28 -33
  23. package/dist/analyzer/constructors.js.map +1 -1
  24. package/dist/analyzer/dataClasses.d.ts +2 -2
  25. package/dist/analyzer/dataClasses.js +59 -36
  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 +4 -4
  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 +10 -10
  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 +58 -58
  54. package/dist/analyzer/parameterUtils.js.map +1 -1
  55. package/dist/analyzer/parseTreeUtils.d.ts +6 -6
  56. package/dist/analyzer/parseTreeUtils.js +22 -22
  57. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  58. package/dist/analyzer/patternMatching.js +108 -89
  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 +19 -19
  63. package/dist/analyzer/properties.js.map +1 -1
  64. package/dist/analyzer/protocols.js +14 -15
  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/tracePrinter.js +4 -4
  82. package/dist/analyzer/tracePrinter.js.map +1 -1
  83. package/dist/analyzer/tuples.d.ts +9 -0
  84. package/dist/analyzer/tuples.js +252 -0
  85. package/dist/analyzer/tuples.js.map +1 -0
  86. package/dist/analyzer/typeComplexity.d.ts +2 -0
  87. package/dist/analyzer/typeComplexity.js +86 -0
  88. package/dist/analyzer/typeComplexity.js.map +1 -0
  89. package/dist/analyzer/typeEvaluator.js +1062 -1311
  90. package/dist/analyzer/typeEvaluator.js.map +1 -1
  91. package/dist/analyzer/typeEvaluatorTypes.d.ts +44 -40
  92. package/dist/analyzer/typeEvaluatorTypes.js +7 -1
  93. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  94. package/dist/analyzer/typeGuards.js +114 -85
  95. package/dist/analyzer/typeGuards.js.map +1 -1
  96. package/dist/analyzer/typePrinter.d.ts +1 -1
  97. package/dist/analyzer/typePrinter.js +54 -53
  98. package/dist/analyzer/typePrinter.js.map +1 -1
  99. package/dist/analyzer/typeStubWriter.d.ts +3 -3
  100. package/dist/analyzer/typeStubWriter.js +15 -15
  101. package/dist/analyzer/typeStubWriter.js.map +1 -1
  102. package/dist/analyzer/typeUtils.d.ts +20 -18
  103. package/dist/analyzer/typeUtils.js +316 -321
  104. package/dist/analyzer/typeUtils.js.map +1 -1
  105. package/dist/analyzer/typeVarContext.d.ts +24 -36
  106. package/dist/analyzer/typeVarContext.js +89 -193
  107. package/dist/analyzer/typeVarContext.js.map +1 -1
  108. package/dist/analyzer/typeWalker.js +4 -4
  109. package/dist/analyzer/typeWalker.js.map +1 -1
  110. package/dist/analyzer/typedDicts.d.ts +2 -2
  111. package/dist/analyzer/typedDicts.js +48 -52
  112. package/dist/analyzer/typedDicts.js.map +1 -1
  113. package/dist/analyzer/types.d.ts +79 -57
  114. package/dist/analyzer/types.js +125 -113
  115. package/dist/analyzer/types.js.map +1 -1
  116. package/dist/commands/dumpFileDebugInfoCommand.js +11 -11
  117. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  118. package/dist/common/configOptions.d.ts +1 -0
  119. package/dist/common/configOptions.js +5 -0
  120. package/dist/common/configOptions.js.map +1 -1
  121. package/dist/common/diagnosticRules.d.ts +1 -0
  122. package/dist/common/diagnosticRules.js +1 -0
  123. package/dist/common/diagnosticRules.js.map +1 -1
  124. package/dist/common/fileSystem.d.ts +0 -1
  125. package/dist/common/fileSystem.js.map +1 -1
  126. package/dist/common/languageServerInterface.d.ts +13 -0
  127. package/dist/common/languageServerInterface.js +15 -1
  128. package/dist/common/languageServerInterface.js.map +1 -1
  129. package/dist/common/lspUtils.js +2 -2
  130. package/dist/common/memUtils.d.ts +4 -0
  131. package/dist/common/memUtils.js +33 -2
  132. package/dist/common/memUtils.js.map +1 -1
  133. package/dist/common/serviceKeys.d.ts +3 -0
  134. package/dist/common/serviceKeys.js +2 -0
  135. package/dist/common/serviceKeys.js.map +1 -1
  136. package/dist/common/serviceProviderExtensions.js +7 -0
  137. package/dist/common/serviceProviderExtensions.js.map +1 -1
  138. package/dist/languageServerBase.d.ts +4 -3
  139. package/dist/languageServerBase.js +14 -10
  140. package/dist/languageServerBase.js.map +1 -1
  141. package/dist/languageService/autoImporter.d.ts +3 -2
  142. package/dist/languageService/autoImporter.js +5 -1
  143. package/dist/languageService/autoImporter.js.map +1 -1
  144. package/dist/languageService/completionProvider.d.ts +5 -3
  145. package/dist/languageService/completionProvider.js +38 -37
  146. package/dist/languageService/completionProvider.js.map +1 -1
  147. package/dist/languageService/completionProviderUtils.d.ts +1 -1
  148. package/dist/languageService/completionProviderUtils.js +3 -3
  149. package/dist/languageService/completionProviderUtils.js.map +1 -1
  150. package/dist/languageService/fileWatcherDynamicFeature.js +2 -2
  151. package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
  152. package/dist/languageService/hoverProvider.js +3 -3
  153. package/dist/languageService/hoverProvider.js.map +1 -1
  154. package/dist/languageService/referencesProvider.js +2 -2
  155. package/dist/languageService/signatureHelpProvider.js +1 -1
  156. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  157. package/dist/languageService/tooltipUtils.js +3 -3
  158. package/dist/languageService/tooltipUtils.js.map +1 -1
  159. package/dist/localization/localize.d.ts +5 -0
  160. package/dist/localization/localize.js +6 -0
  161. package/dist/localization/localize.js.map +1 -1
  162. package/dist/localization/package.nls.cs.json +5 -1
  163. package/dist/localization/package.nls.de.json +5 -1
  164. package/dist/localization/package.nls.en-us.json +5 -0
  165. package/dist/localization/package.nls.es.json +5 -1
  166. package/dist/localization/package.nls.fr.json +5 -1
  167. package/dist/localization/package.nls.it.json +5 -1
  168. package/dist/localization/package.nls.ja.json +5 -1
  169. package/dist/localization/package.nls.ko.json +5 -1
  170. package/dist/localization/package.nls.pl.json +5 -1
  171. package/dist/localization/package.nls.pt-br.json +5 -1
  172. package/dist/localization/package.nls.qps-ploc.json +5 -1
  173. package/dist/localization/package.nls.ru.json +5 -1
  174. package/dist/localization/package.nls.tr.json +5 -1
  175. package/dist/localization/package.nls.zh-cn.json +5 -1
  176. package/dist/localization/package.nls.zh-tw.json +5 -1
  177. package/dist/parser/parseNodes.d.ts +9 -9
  178. package/dist/parser/parseNodes.js +20 -20
  179. package/dist/parser/parseNodes.js.map +1 -1
  180. package/dist/parser/parser.js +30 -30
  181. package/dist/parser/parser.js.map +1 -1
  182. package/dist/tests/checker.test.js +2 -2
  183. package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js +4 -21
  184. package/dist/tests/fourslash/signature.builtinDocstrings.fourslash.js.map +1 -1
  185. package/dist/tests/fourslash/signature.complicated.fourslash.js +1 -1
  186. package/dist/tests/fourslash/signature.complicated.fourslash.js.map +1 -1
  187. package/dist/tests/harness/fourslash/fourSlashParser.js +1 -1
  188. package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
  189. package/dist/tests/harness/fourslash/testStateUtils.js +2 -2
  190. package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
  191. package/dist/tests/harness/vfs/filesystem.d.ts +0 -1
  192. package/dist/tests/harness/vfs/filesystem.js +0 -4
  193. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  194. package/dist/tests/importResolver.test.js +62 -15
  195. package/dist/tests/importResolver.test.js.map +1 -1
  196. package/dist/tests/lsp/languageServerTestUtils.js +1 -1
  197. package/dist/tests/lsp/languageServerTestUtils.js.map +1 -1
  198. package/dist/tests/typeEvaluator3.test.js +1 -1
  199. package/dist/tests/typeEvaluator4.test.js +9 -1
  200. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  201. package/dist/tests/typeEvaluator5.test.js +8 -2
  202. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  203. package/dist/tests/typeEvaluator6.test.js +72 -60
  204. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  205. package/dist/tests/typeEvaluator7.test.js +2 -2
  206. package/dist/tests/typePrinter.test.js +13 -18
  207. package/dist/tests/typePrinter.test.js.map +1 -1
  208. package/dist/workspaceFactory.d.ts +3 -2
  209. package/dist/workspaceFactory.js +15 -2
  210. package/dist/workspaceFactory.js.map +1 -1
  211. package/package.json +1 -1
@@ -110,6 +110,7 @@ function narrowTypeBasedOnSequencePattern(evaluator, type, pattern, isPositiveTe
110
110
  let isPlausibleMatch = true;
111
111
  let isDefiniteMatch = true;
112
112
  const narrowedEntryTypes = [];
113
+ const unnarrowedEntryTypes = [];
113
114
  let canNarrowTuple = entry.isTuple;
114
115
  // Don't attempt to narrow tuples in the negative case if the subject
115
116
  // contains indeterminate-length entries or the tuple is of indeterminate
@@ -118,8 +119,8 @@ function narrowTypeBasedOnSequencePattern(evaluator, type, pattern, isPositiveTe
118
119
  if (entry.isIndeterminateLength) {
119
120
  canNarrowTuple = false;
120
121
  }
121
- if ((0, types_1.isClassInstance)(entry.subtype) && entry.subtype.priv.tupleTypeArguments) {
122
- const unboundedIndex = entry.subtype.priv.tupleTypeArguments.findIndex((typeArg) => typeArg.isUnbounded);
122
+ if ((0, types_1.isClassInstance)(entry.subtype) && entry.subtype.priv.tupleTypeArgs) {
123
+ const unboundedIndex = entry.subtype.priv.tupleTypeArgs.findIndex((typeArg) => typeArg.isUnbounded);
123
124
  if (unboundedIndex >= 0) {
124
125
  // If the pattern includes a "star" entry that aligns exactly with
125
126
  // the corresponding unbounded entry in the tuple, we can narrow
@@ -138,18 +139,19 @@ function narrowTypeBasedOnSequencePattern(evaluator, type, pattern, isPositiveTe
138
139
  isDefiniteMatch = false;
139
140
  }
140
141
  }
141
- let negativeEntriesNarrowed = 0;
142
+ const negativeNarrowedDims = [];
142
143
  pattern.d.entries.forEach((sequenceEntry, index) => {
143
144
  const entryType = getTypeOfPatternSequenceEntry(evaluator, pattern, entry, index, pattern.d.entries.length, pattern.d.starEntryIndex,
144
145
  /* unpackStarEntry */ true);
146
+ unnarrowedEntryTypes.push(entryType);
145
147
  const narrowedEntryType = narrowTypeBasedOnPattern(evaluator, entryType, sequenceEntry, isPositiveTest);
146
148
  if (isPositiveTest) {
147
149
  if (index === pattern.d.starEntryIndex) {
148
150
  if ((0, types_1.isClassInstance)(narrowedEntryType) &&
149
- narrowedEntryType.priv.tupleTypeArguments &&
151
+ narrowedEntryType.priv.tupleTypeArgs &&
150
152
  !(0, typeUtils_1.isUnboundedTupleClass)(narrowedEntryType) &&
151
- narrowedEntryType.priv.tupleTypeArguments) {
152
- (0, collectionUtils_1.appendArray)(narrowedEntryTypes, narrowedEntryType.priv.tupleTypeArguments.map((t) => t.type));
153
+ narrowedEntryType.priv.tupleTypeArgs) {
154
+ (0, collectionUtils_1.appendArray)(narrowedEntryTypes, narrowedEntryType.priv.tupleTypeArgs.map((t) => t.type));
153
155
  }
154
156
  else {
155
157
  narrowedEntryTypes.push(narrowedEntryType);
@@ -169,10 +171,11 @@ function narrowTypeBasedOnSequencePattern(evaluator, type, pattern, isPositiveTe
169
171
  }
170
172
  if (!(0, types_1.isNever)(narrowedEntryType)) {
171
173
  isDefiniteMatch = false;
172
- // Record the number of entries that were narrowed in the negative
173
- // case. We can apply the tuple narrowing only if exactly one entry
174
- // is narrowed.
175
- negativeEntriesNarrowed++;
174
+ // Record which entries were narrowed in the negative case
175
+ // by storing their indexes. If more than one is narrowed,
176
+ // we need to perform tuple expansion to represent the
177
+ // resulting narrowed type.
178
+ negativeNarrowedDims.push(index);
176
179
  narrowedEntryTypes.push(narrowedEntryType);
177
180
  }
178
181
  else {
@@ -199,12 +202,22 @@ function narrowTypeBasedOnSequencePattern(evaluator, type, pattern, isPositiveTe
199
202
  return false;
200
203
  }
201
204
  // Can we narrow a tuple?
202
- if (canNarrowTuple && negativeEntriesNarrowed === 1) {
205
+ if (canNarrowTuple && negativeNarrowedDims.length > 0) {
203
206
  const tupleClassType = evaluator.getBuiltInType(pattern, 'tuple');
204
207
  if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
205
- entry.subtype = types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, narrowedEntryTypes.map((t) => {
206
- return { type: t, isUnbounded: false };
207
- })));
208
+ // Expand the tuple in the dimensions that were narrowed.
209
+ // Start with the fully-narrowed set of entries.
210
+ const expandedEntryTypes = [];
211
+ for (const dim of negativeNarrowedDims) {
212
+ const newEntryTypes = [...unnarrowedEntryTypes];
213
+ newEntryTypes[dim] = narrowedEntryTypes[dim];
214
+ expandedEntryTypes.push(newEntryTypes);
215
+ }
216
+ entry.subtype = (0, types_1.combineTypes)(expandedEntryTypes.map((entryTypes) => {
217
+ return types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, entryTypes.map((t) => {
218
+ return { type: t, isUnbounded: false };
219
+ })));
220
+ }));
208
221
  }
209
222
  }
210
223
  return true;
@@ -229,7 +242,7 @@ function narrowTypeBasedOnSequencePattern(evaluator, type, pattern, isPositiveTe
229
242
  // If the type is a union that contains Any or Unknown, remove the other types
230
243
  // before wrapping it in a Sequence.
231
244
  typeArgType = (_a = (0, typeUtils_1.containsAnyOrUnknown)(typeArgType, /* recurse */ false)) !== null && _a !== void 0 ? _a : typeArgType;
232
- entry.subtype = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(sequenceType, [typeArgType], /* isTypeArgumentExplicit */ true));
245
+ entry.subtype = types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(sequenceType, [typeArgType]));
233
246
  }
234
247
  }
235
248
  }
@@ -380,8 +393,8 @@ function getPositionalMatchArgNames(evaluator, type) {
380
393
  if ((0, types_1.isClassInstance)(matchArgsType) &&
381
394
  (0, typeUtils_1.isTupleClass)(matchArgsType) &&
382
395
  !(0, typeUtils_1.isUnboundedTupleClass)(matchArgsType) &&
383
- matchArgsType.priv.tupleTypeArguments) {
384
- const tupleArgs = matchArgsType.priv.tupleTypeArguments;
396
+ matchArgsType.priv.tupleTypeArgs) {
397
+ const tupleArgs = matchArgsType.priv.tupleTypeArgs;
385
398
  // Are all the args string literals?
386
399
  if (tupleArgs.every((arg) => (0, types_1.isClassInstance)(arg.type) && types_1.ClassType.isBuiltIn(arg.type, 'str') && (0, typeUtils_1.isLiteralType)(arg.type))) {
387
400
  return tupleArgs.map((arg) => arg.type.priv.literalValue);
@@ -455,10 +468,8 @@ function narrowTypeBasedOnClassPattern(evaluator, type, pattern, isPositiveTest)
455
468
  return type;
456
469
  }
457
470
  let classType = exprType;
458
- if (classType.shared.typeParameters.length > 0) {
459
- classType = types_1.ClassType.cloneForSpecialization(classType,
460
- /* typeArguments */ undefined,
461
- /* isTypeArgumentExplicit */ false);
471
+ if (classType.shared.typeParams.length > 0) {
472
+ classType = types_1.ClassType.specialize(classType, /* typeArgs */ undefined);
462
473
  }
463
474
  const classInstance = (0, typeUtils_1.convertToInstance)(classType);
464
475
  const isPatternMetaclass = (0, typeUtils_1.isMetaclassInstance)(classInstance);
@@ -515,7 +526,7 @@ function narrowTypeBasedOnClassPattern(evaluator, type, pattern, isPositiveTest)
515
526
  }
516
527
  }
517
528
  for (let index = 0; index < pattern.d.args.length; index++) {
518
- const narrowedArgType = narrowTypeOfClassPatternArgument(evaluator, pattern.d.args[index], index, positionalArgNames, subjectSubtypeExpanded, isPositiveTest);
529
+ const narrowedArgType = narrowTypeOfClassPatternArg(evaluator, pattern.d.args[index], index, positionalArgNames, subjectSubtypeExpanded, isPositiveTest);
519
530
  if (!(0, types_1.isNever)(narrowedArgType)) {
520
531
  return subjectSubtypeUnexpanded;
521
532
  }
@@ -547,7 +558,7 @@ function narrowTypeBasedOnClassPattern(evaluator, type, pattern, isPositiveTest)
547
558
  if ((0, types_1.isInstantiableClass)(expandedSubtype) && types_1.ClassType.isBuiltIn(expandedSubtype, 'Callable')) {
548
559
  // Convert to an unknown callable type.
549
560
  const unknownCallable = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.GradualCallableForm */);
550
- types_1.FunctionType.addDefaultParameters(unknownCallable,
561
+ types_1.FunctionType.addDefaultParams(unknownCallable,
551
562
  /* useUnknown */ (0, types_1.isUnknown)(subjectSubtypeExpanded));
552
563
  unknownCallable.shared.declaredReturnType = subjectSubtypeExpanded;
553
564
  return unknownCallable;
@@ -592,11 +603,10 @@ function narrowTypeBasedOnClassPattern(evaluator, type, pattern, isPositiveTest)
592
603
  // Try to retain the type arguments for the pattern class type.
593
604
  if ((0, types_1.isInstantiableClass)(unexpandedSubtype) && (0, types_1.isClassInstance)(subjectSubtypeExpanded)) {
594
605
  if (types_1.ClassType.isSpecialBuiltIn(unexpandedSubtype) ||
595
- unexpandedSubtype.shared.typeParameters.length > 0) {
606
+ unexpandedSubtype.shared.typeParams.length > 0) {
596
607
  const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(unexpandedSubtype));
597
- const unspecializedMatchType = types_1.ClassType.cloneForSpecialization(unexpandedSubtype,
598
- /* typeArguments */ undefined,
599
- /* isTypeArgumentExplicit */ false);
608
+ const unspecializedMatchType = types_1.ClassType.specialize(unexpandedSubtype,
609
+ /* typeArgs */ undefined);
600
610
  const matchTypeInstance = types_1.ClassType.cloneAsInstance(unspecializedMatchType);
601
611
  if ((0, constraintSolver_1.addConstraintsForExpectedType)(evaluator, matchTypeInstance, subjectSubtypeExpanded, typeVarContext,
602
612
  /* liveTypeVarScopes */ undefined,
@@ -623,7 +633,7 @@ function narrowTypeBasedOnClassPattern(evaluator, type, pattern, isPositiveTest)
623
633
  // Narrow the arg pattern. It's possible that the actual type of the object
624
634
  // being matched is a subtype of the resultType, so it might contain additional
625
635
  // attributes that we don't know about.
626
- const narrowedArgType = narrowTypeOfClassPatternArgument(evaluator, arg, index, positionalArgNames, resultType, isPositiveTest);
636
+ const narrowedArgType = narrowTypeOfClassPatternArg(evaluator, arg, index, positionalArgNames, resultType, isPositiveTest);
627
637
  if ((0, types_1.isNever)(narrowedArgType)) {
628
638
  isMatchValid = false;
629
639
  }
@@ -658,7 +668,7 @@ function isClassSpecialCaseForClassPattern(classType) {
658
668
  return false;
659
669
  }
660
670
  // Narrows the pattern provided for a class pattern argument.
661
- function narrowTypeOfClassPatternArgument(evaluator, arg, argIndex, positionalArgNames, matchType, isPositiveTest) {
671
+ function narrowTypeOfClassPatternArg(evaluator, arg, argIndex, positionalArgNames, matchType, isPositiveTest) {
662
672
  var _a;
663
673
  let argName;
664
674
  if (arg.d.name) {
@@ -802,44 +812,40 @@ function getMappingPatternInfo(evaluator, type, node) {
802
812
  });
803
813
  return;
804
814
  }
805
- // Is it a subclass of Mapping?
806
- let mroClassToSpecialize;
807
- for (const mroClass of concreteSubtype.shared.mro) {
808
- if ((0, types_1.isInstantiableClass)(mroClass) && types_1.ClassType.isBuiltIn(mroClass, 'Mapping')) {
809
- mroClassToSpecialize = mroClass;
810
- break;
811
- }
815
+ const mappingType = evaluator.getTypingType(node, 'Mapping');
816
+ if (!mappingType || !(0, types_1.isInstantiableClass)(mappingType)) {
817
+ return;
812
818
  }
813
- if (mroClassToSpecialize) {
814
- const specializedMapping = (0, typeUtils_1.partiallySpecializeType)(mroClassToSpecialize, concreteSubtype, evaluator.getTypeClassType());
815
- if (specializedMapping.priv.typeArguments && specializedMapping.priv.typeArguments.length >= 2) {
819
+ const mappingObject = types_1.ClassType.cloneAsInstance(mappingType);
820
+ // Is it a subtype of Mapping?
821
+ const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(mappingObject));
822
+ if (evaluator.assignType(mappingObject, subtype, /* diag */ undefined, typeVarContext)) {
823
+ const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(mappingObject, typeVarContext);
824
+ if (specializedMapping.priv.typeArgs && specializedMapping.priv.typeArgs.length >= 2) {
816
825
  mappingInfo.push({
817
826
  subtype,
818
827
  isDefinitelyMapping: true,
819
828
  isDefinitelyNotMapping: false,
820
829
  dictTypeArgs: {
821
- key: specializedMapping.priv.typeArguments[0],
822
- value: specializedMapping.priv.typeArguments[1],
830
+ key: specializedMapping.priv.typeArgs[0],
831
+ value: specializedMapping.priv.typeArgs[1],
823
832
  },
824
833
  });
825
834
  }
826
835
  return;
827
836
  }
828
837
  // Is it a superclass of Mapping?
829
- const mappingType = evaluator.getTypingType(node, 'Mapping');
830
- if (mappingType && (0, types_1.isInstantiableClass)(mappingType)) {
831
- const mappingObject = types_1.ClassType.cloneAsInstance(mappingType);
832
- if (evaluator.assignType(subtype, mappingObject)) {
833
- mappingInfo.push({
834
- subtype,
835
- isDefinitelyMapping: false,
836
- isDefinitelyNotMapping: false,
837
- dictTypeArgs: {
838
- key: types_1.UnknownType.create(),
839
- value: types_1.UnknownType.create(),
840
- },
841
- });
842
- }
838
+ if (evaluator.assignType(subtype, mappingObject)) {
839
+ mappingInfo.push({
840
+ subtype,
841
+ isDefinitelyMapping: false,
842
+ isDefinitelyNotMapping: false,
843
+ dictTypeArgs: {
844
+ key: types_1.UnknownType.create(),
845
+ value: types_1.UnknownType.create(),
846
+ },
847
+ });
848
+ return;
843
849
  }
844
850
  mappingInfo.push({
845
851
  subtype,
@@ -861,7 +867,6 @@ function getSequencePatternInfo(evaluator, pattern, type) {
861
867
  var _a;
862
868
  const concreteSubtype = evaluator.makeTopLevelTypeVarsConcrete(subtype);
863
869
  let mroClassToSpecialize;
864
- let pushedEntry = false;
865
870
  if ((0, types_1.isClassInstance)(concreteSubtype)) {
866
871
  for (const mroClass of concreteSubtype.shared.mro) {
867
872
  if (!(0, types_1.isInstantiableClass)(mroClass)) {
@@ -892,10 +897,10 @@ function getSequencePatternInfo(evaluator, pattern, type) {
892
897
  if (mroClassToSpecialize) {
893
898
  const specializedSequence = (0, typeUtils_1.partiallySpecializeType)(mroClassToSpecialize, concreteSubtype, evaluator.getTypeClassType());
894
899
  if ((0, typeUtils_1.isTupleClass)(specializedSequence)) {
895
- const typeArgs = (_a = specializedSequence.priv.tupleTypeArguments) !== null && _a !== void 0 ? _a : [
900
+ const typeArgs = (_a = specializedSequence.priv.tupleTypeArgs) !== null && _a !== void 0 ? _a : [
896
901
  { type: types_1.UnknownType.create(), isUnbounded: true },
897
902
  ];
898
- const tupleIndeterminateIndex = typeArgs.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedVariadicTypeVar)(t.type));
903
+ const tupleIndeterminateIndex = typeArgs.findIndex((t) => t.isUnbounded || (0, types_1.isUnpackedTypeVarTuple)(t.type));
899
904
  let tupleDeterminateEntryCount = typeArgs.length;
900
905
  // If the tuple contains an indeterminate entry, expand or remove that
901
906
  // entry to match the length of the pattern if possible.
@@ -917,7 +922,7 @@ function getSequencePatternInfo(evaluator, pattern, type) {
917
922
  const removedEntries = typeArgs.splice(patternStarEntryIndex, entriesToCombine);
918
923
  typeArgs.splice(patternStarEntryIndex, 0, {
919
924
  type: (0, types_1.combineTypes)(removedEntries.map((t) => t.type)),
920
- isUnbounded: removedEntries.every((t) => t.isUnbounded || (0, types_1.isUnpackedVariadicTypeVar)(t.type)),
925
+ isUnbounded: removedEntries.every((t) => t.isUnbounded || (0, types_1.isUnpackedTypeVarTuple)(t.type)),
921
926
  });
922
927
  }
923
928
  if (typeArgs.length === patternEntryCount) {
@@ -949,7 +954,7 @@ function getSequencePatternInfo(evaluator, pattern, type) {
949
954
  isDefiniteNoMatch,
950
955
  isPotentialNoMatch,
951
956
  });
952
- pushedEntry = true;
957
+ return;
953
958
  }
954
959
  // If the pattern contains a star entry and the pattern associated with
955
960
  // the star entry is unbounded, we can remove it completely under the
@@ -988,7 +993,7 @@ function getSequencePatternInfo(evaluator, pattern, type) {
988
993
  isTuple: true,
989
994
  isDefiniteNoMatch,
990
995
  });
991
- pushedEntry = true;
996
+ return;
992
997
  }
993
998
  }
994
999
  }
@@ -996,28 +1001,44 @@ function getSequencePatternInfo(evaluator, pattern, type) {
996
1001
  sequenceInfo.push({
997
1002
  subtype,
998
1003
  entryTypes: [
999
- specializedSequence.priv.typeArguments && specializedSequence.priv.typeArguments.length > 0
1000
- ? specializedSequence.priv.typeArguments[0]
1004
+ specializedSequence.priv.typeArgs && specializedSequence.priv.typeArgs.length > 0
1005
+ ? specializedSequence.priv.typeArgs[0]
1001
1006
  : types_1.UnknownType.create(),
1002
1007
  ],
1003
1008
  isIndeterminateLength: true,
1004
1009
  isDefiniteNoMatch: false,
1005
1010
  });
1006
- pushedEntry = true;
1011
+ return;
1007
1012
  }
1008
1013
  }
1009
1014
  }
1010
- if (!pushedEntry) {
1011
- // If it wasn't a subtype of Sequence, see if it's a supertype.
1015
+ if (!mroClassToSpecialize) {
1012
1016
  const sequenceType = evaluator.getTypingType(pattern, 'Sequence');
1013
1017
  if (sequenceType && (0, types_1.isInstantiableClass)(sequenceType)) {
1018
+ const sequenceObject = types_1.ClassType.cloneAsInstance(sequenceType);
1019
+ // Is it a subtype of Sequence?
1020
+ const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(sequenceType));
1021
+ if (evaluator.assignType(sequenceObject, subtype, /* diag */ undefined, typeVarContext)) {
1022
+ const specializedSequence = (0, typeUtils_1.applySolvedTypeVars)(sequenceObject, typeVarContext);
1023
+ if (specializedSequence.priv.typeArgs && specializedSequence.priv.typeArgs.length > 0) {
1024
+ sequenceInfo.push({
1025
+ subtype,
1026
+ entryTypes: [specializedSequence.priv.typeArgs[0]],
1027
+ isIndeterminateLength: true,
1028
+ isDefiniteNoMatch: false,
1029
+ isPotentialNoMatch: false,
1030
+ });
1031
+ return;
1032
+ }
1033
+ }
1034
+ // If it wasn't a subtype of Sequence, see if it's a supertype.
1014
1035
  const sequenceTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(sequenceType));
1015
1036
  if ((0, constraintSolver_1.addConstraintsForExpectedType)(evaluator, types_1.ClassType.cloneAsInstance(sequenceType), subtype, sequenceTypeVarContext, (0, parseTreeUtils_1.getTypeVarScopesForNode)(pattern), pattern.start)) {
1016
1037
  const specializedSequence = (0, typeUtils_1.applySolvedTypeVars)(types_1.ClassType.cloneAsInstantiable(sequenceType), sequenceTypeVarContext);
1017
- if (specializedSequence.priv.typeArguments && specializedSequence.priv.typeArguments.length > 0) {
1038
+ if (specializedSequence.priv.typeArgs && specializedSequence.priv.typeArgs.length > 0) {
1018
1039
  sequenceInfo.push({
1019
1040
  subtype,
1020
- entryTypes: [specializedSequence.priv.typeArguments[0]],
1041
+ entryTypes: [specializedSequence.priv.typeArgs[0]],
1021
1042
  isIndeterminateLength: true,
1022
1043
  isDefiniteNoMatch: false,
1023
1044
  isPotentialNoMatch: true,
@@ -1025,8 +1046,7 @@ function getSequencePatternInfo(evaluator, pattern, type) {
1025
1046
  return;
1026
1047
  }
1027
1048
  }
1028
- if (evaluator.assignType(subtype, types_1.ClassType.cloneForSpecialization(types_1.ClassType.cloneAsInstance(sequenceType), [types_1.UnknownType.create()],
1029
- /* isTypeArgumentExplicit */ true))) {
1049
+ if (evaluator.assignType(subtype, types_1.ClassType.specialize(types_1.ClassType.cloneAsInstance(sequenceType), [types_1.UnknownType.create()]))) {
1030
1050
  sequenceInfo.push({
1031
1051
  subtype,
1032
1052
  entryTypes: [types_1.UnknownType.create()],
@@ -1037,14 +1057,14 @@ function getSequencePatternInfo(evaluator, pattern, type) {
1037
1057
  return;
1038
1058
  }
1039
1059
  }
1040
- // Push an entry that indicates that this is definitely not a match.
1041
- sequenceInfo.push({
1042
- subtype,
1043
- entryTypes: [],
1044
- isIndeterminateLength: true,
1045
- isDefiniteNoMatch: true,
1046
- });
1047
1060
  }
1061
+ // Push an entry that indicates that this is definitely not a match.
1062
+ sequenceInfo.push({
1063
+ subtype,
1064
+ entryTypes: [],
1065
+ isIndeterminateLength: true,
1066
+ isDefiniteNoMatch: true,
1067
+ });
1048
1068
  });
1049
1069
  return sequenceInfo;
1050
1070
  }
@@ -1069,7 +1089,7 @@ function getTypeOfPatternSequenceEntry(evaluator, node, sequenceInfo, entryIndex
1069
1089
  // its type other than it's "Unknown". We could evaluate it as an
1070
1090
  // "object", but that will cause problems given that this type will
1071
1091
  // be wrapped in a "list" below, and lists are invariant.
1072
- if ((0, types_1.isVariadicTypeVar)(type) && !type.priv.isVariadicInUnion) {
1092
+ if ((0, types_1.isTypeVarTuple)(type) && !type.priv.isVariadicInUnion) {
1073
1093
  return types_1.UnknownType.create();
1074
1094
  }
1075
1095
  return evaluator.stripLiteralValue(type);
@@ -1189,8 +1209,7 @@ function assignTypeToPatternTargets(evaluator, type, isTypeIncomplete, pattern)
1189
1209
  const dictClass = evaluator.getBuiltInType(pattern, 'dict');
1190
1210
  const strType = evaluator.getBuiltInObject(pattern, 'str');
1191
1211
  const dictType = dictClass && (0, types_1.isInstantiableClass)(dictClass) && (0, types_1.isClassInstance)(strType)
1192
- ? types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(dictClass, [keyType, valueType],
1193
- /* isTypeArgumentExplicit */ true))
1212
+ ? types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(dictClass, [keyType, valueType]))
1194
1213
  : types_1.UnknownType.create();
1195
1214
  evaluator.assignTypeToExpression(mappingEntry.d.target, { type: dictType, isIncomplete: isTypeIncomplete }, mappingEntry.d.target);
1196
1215
  }
@@ -1216,7 +1235,7 @@ function assignTypeToPatternTargets(evaluator, type, isTypeIncomplete, pattern)
1216
1235
  positionalArgNames = getPositionalMatchArgNames(evaluator, types_1.ClassType.cloneAsInstantiable(expandedSubtype));
1217
1236
  }
1218
1237
  pattern.d.args.forEach((arg, index) => {
1219
- const narrowedArgType = narrowTypeOfClassPatternArgument(evaluator, arg, index, positionalArgNames, types_1.ClassType.cloneAsInstantiable(expandedSubtype),
1238
+ const narrowedArgType = narrowTypeOfClassPatternArg(evaluator, arg, index, positionalArgNames, types_1.ClassType.cloneAsInstantiable(expandedSubtype),
1220
1239
  /* isPositiveTest */ true);
1221
1240
  argTypes[index].push(narrowedArgType);
1222
1241
  });
@@ -1255,7 +1274,7 @@ function wrapTypeInList(evaluator, node, type) {
1255
1274
  // If the type is a union that contains an Any or Unknown, eliminate the other
1256
1275
  // types before wrapping it in a list.
1257
1276
  type = (_a = (0, typeUtils_1.containsAnyOrUnknown)(type, /* recurse */ false)) !== null && _a !== void 0 ? _a : type;
1258
- return types_1.ClassType.cloneForSpecialization(listObjectType, [type], /* isTypeArgumentExplicit */ true);
1277
+ return types_1.ClassType.specialize(listObjectType, [type]);
1259
1278
  }
1260
1279
  return types_1.UnknownType.create();
1261
1280
  }
@@ -1273,8 +1292,8 @@ function validateClassPattern(evaluator, pattern) {
1273
1292
  // Check for certain uses of type aliases that generate runtime exceptions.
1274
1293
  if (((_b = exprType.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo) &&
1275
1294
  (0, types_1.isInstantiableClass)(exprType) &&
1276
- exprType.priv.typeArguments &&
1277
- exprType.priv.isTypeArgumentExplicit) {
1295
+ exprType.priv.typeArgs &&
1296
+ exprType.priv.isTypeArgExplicit) {
1278
1297
  evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.classPatternTypeAlias().format({ type: evaluator.printType(exprType) }), pattern.d.className);
1279
1298
  }
1280
1299
  else if (!(0, types_1.isInstantiableClass)(exprType)) {
@@ -1324,7 +1343,7 @@ function getPatternSubtypeNarrowingCallback(evaluator, reference, subjectExpress
1324
1343
  if (subjectExpression.nodeType === 27 /* ParseNodeType.Index */ &&
1325
1344
  subjectExpression.d.items.length === 1 &&
1326
1345
  !subjectExpression.d.trailingComma &&
1327
- subjectExpression.d.items[0].d.argCategory === 0 /* ArgumentCategory.Simple */ &&
1346
+ subjectExpression.d.items[0].d.argCategory === 0 /* ArgCategory.Simple */ &&
1328
1347
  (0, parseTreeUtils_1.isMatchingExpression)(reference, subjectExpression.d.leftExpr)) {
1329
1348
  const indexTypeResult = evaluator.getTypeOfExpression(subjectExpression.d.items[0].d.valueExpr);
1330
1349
  const indexType = indexTypeResult.type;
@@ -1375,10 +1394,10 @@ function getPatternSubtypeNarrowingCallback(evaluator, reference, subjectExpress
1375
1394
  (0, typeUtils_1.doForEachSubtype)(narrowedSubjectType, (subtype) => {
1376
1395
  if ((0, types_1.isClassInstance)(subtype) &&
1377
1396
  types_1.ClassType.isBuiltIn(subtype, 'tuple') &&
1378
- subtype.priv.tupleTypeArguments &&
1379
- matchingEntryIndex < subtype.priv.tupleTypeArguments.length &&
1380
- subtype.priv.tupleTypeArguments.every((e) => !e.isUnbounded)) {
1381
- narrowedSubtypes.push(subtype.priv.tupleTypeArguments[matchingEntryIndex].type);
1397
+ subtype.priv.tupleTypeArgs &&
1398
+ matchingEntryIndex < subtype.priv.tupleTypeArgs.length &&
1399
+ subtype.priv.tupleTypeArgs.every((e) => !e.isUnbounded)) {
1400
+ narrowedSubtypes.push(subtype.priv.tupleTypeArgs[matchingEntryIndex].type);
1382
1401
  }
1383
1402
  else if ((0, types_1.isNever)(narrowedSubjectType)) {
1384
1403
  narrowedSubtypes.push(narrowedSubjectType);