@zzzen/pyright-internal 1.2.0-dev.20240929 → 1.2.0-dev.20241013

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 (77) hide show
  1. package/dist/analyzer/binder.js +1 -2
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.js +7 -7
  4. package/dist/analyzer/checker.js.map +1 -1
  5. package/dist/analyzer/codeFlowEngine.js +1 -1
  6. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  7. package/dist/analyzer/constraintSolver.js +14 -18
  8. package/dist/analyzer/constraintSolver.js.map +1 -1
  9. package/dist/analyzer/constraintTracker.js +1 -1
  10. package/dist/analyzer/constraintTracker.js.map +1 -1
  11. package/dist/analyzer/constructors.js +10 -8
  12. package/dist/analyzer/constructors.js.map +1 -1
  13. package/dist/analyzer/dataClasses.js +72 -22
  14. package/dist/analyzer/dataClasses.js.map +1 -1
  15. package/dist/analyzer/parameterUtils.d.ts +2 -1
  16. package/dist/analyzer/parameterUtils.js +2 -1
  17. package/dist/analyzer/parameterUtils.js.map +1 -1
  18. package/dist/analyzer/patternMatching.js +14 -3
  19. package/dist/analyzer/patternMatching.js.map +1 -1
  20. package/dist/analyzer/protocols.js +63 -32
  21. package/dist/analyzer/protocols.js.map +1 -1
  22. package/dist/analyzer/tuples.d.ts +8 -3
  23. package/dist/analyzer/tuples.js +157 -2
  24. package/dist/analyzer/tuples.js.map +1 -1
  25. package/dist/analyzer/typeEvaluator.js +283 -356
  26. package/dist/analyzer/typeEvaluator.js.map +1 -1
  27. package/dist/analyzer/typeEvaluatorTypes.d.ts +9 -14
  28. package/dist/analyzer/typeEvaluatorTypes.js +7 -1
  29. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  30. package/dist/analyzer/typePrinter.d.ts +2 -1
  31. package/dist/analyzer/typePrinter.js +17 -17
  32. package/dist/analyzer/typePrinter.js.map +1 -1
  33. package/dist/analyzer/typeStubWriter.js +1 -1
  34. package/dist/analyzer/typeStubWriter.js.map +1 -1
  35. package/dist/analyzer/typeUtils.d.ts +12 -3
  36. package/dist/analyzer/typeUtils.js +85 -21
  37. package/dist/analyzer/typeUtils.js.map +1 -1
  38. package/dist/analyzer/types.d.ts +10 -5
  39. package/dist/analyzer/types.js +49 -18
  40. package/dist/analyzer/types.js.map +1 -1
  41. package/dist/common/collectionUtils.d.ts +2 -0
  42. package/dist/common/collectionUtils.js +15 -0
  43. package/dist/common/collectionUtils.js.map +1 -1
  44. package/dist/common/pythonVersion.js +1 -1
  45. package/dist/languageService/completionProvider.d.ts +2 -2
  46. package/dist/languageService/completionProvider.js +11 -6
  47. package/dist/languageService/completionProvider.js.map +1 -1
  48. package/dist/localization/package.nls.cs.json +1 -0
  49. package/dist/localization/package.nls.de.json +1 -0
  50. package/dist/localization/package.nls.es.json +1 -0
  51. package/dist/localization/package.nls.fr.json +1 -0
  52. package/dist/localization/package.nls.it.json +1 -0
  53. package/dist/localization/package.nls.ja.json +1 -0
  54. package/dist/localization/package.nls.ko.json +1 -0
  55. package/dist/localization/package.nls.pl.json +1 -0
  56. package/dist/localization/package.nls.pt-br.json +1 -0
  57. package/dist/localization/package.nls.qps-ploc.json +1 -0
  58. package/dist/localization/package.nls.ru.json +1 -0
  59. package/dist/localization/package.nls.tr.json +1 -0
  60. package/dist/localization/package.nls.zh-cn.json +6 -5
  61. package/dist/localization/package.nls.zh-tw.json +6 -5
  62. package/dist/tests/fourslash/findDefinitions.dataclasses.converter.fourslash.d.ts +1 -0
  63. package/dist/tests/fourslash/findDefinitions.dataclasses.converter.fourslash.js +40 -0
  64. package/dist/tests/fourslash/findDefinitions.dataclasses.converter.fourslash.js.map +1 -0
  65. package/dist/tests/typeEvaluator1.test.js +1 -0
  66. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  67. package/dist/tests/typeEvaluator4.test.js +4 -3
  68. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  69. package/dist/tests/typeEvaluator5.test.js +3 -3
  70. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  71. package/dist/tests/typeEvaluator6.test.js +9 -3
  72. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  73. package/dist/tests/typeEvaluator7.test.js +11 -8
  74. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  75. package/dist/tests/typeEvaluator8.test.js +4 -0
  76. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  77. package/package.json +1 -1
@@ -152,15 +152,6 @@ const maxOverloadUnionExpansionCount = 64;
152
152
  // Maximum number of recursive function return type inference attempts
153
153
  // that can be concurrently pending before we give up.
154
154
  const maxInferFunctionReturnRecursionCount = 12;
155
- // In certain loops, it's possible to construct arbitrarily-deep containers
156
- // (tuples, lists, sets, or dicts) which can lead to infinite type analysis.
157
- // This limits the depth.
158
- const maxInferredContainerDepth = 8;
159
- // If a tuple expression with no declared type contains a large number
160
- // of elements, it can cause performance issues. This value limits the
161
- // number of elements that will be included in the tuple type before
162
- // we default to tuple[Unknown, ...].
163
- const maxInferredTupleEntryCount = 256;
164
155
  // Maximum recursion amount when comparing two recursive type aliases.
165
156
  // Increasing this can greatly increase the time required to evaluate
166
157
  // two recursive type aliases that have the same definition. Decreasing
@@ -639,7 +630,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
639
630
  break;
640
631
  }
641
632
  case 52 /* ParseNodeType.Tuple */: {
642
- typeResult = getTypeOfTuple(node, flags, inferenceContext);
633
+ typeResult = (0, tuples_1.getTypeOfTuple)(evaluatorInterface, node, flags, inferenceContext);
643
634
  break;
644
635
  }
645
636
  case 14 /* ParseNodeType.Constant */: {
@@ -863,8 +854,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
863
854
  typeResult = { type: types_1.AnyType.create(/* isEllipsis */ true) };
864
855
  }
865
856
  else {
866
- const ellipsisType = (_b = (_a = getBuiltInObject(node, 'EllipsisType')) !== null && _a !== void 0 ? _a : getBuiltInObject(node, 'ellipsis')) !== null && _b !== void 0 ? _b : types_1.AnyType.create();
867
- typeResult = { type: ellipsisType };
857
+ if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0 && (flags & 65536 /* EvalFlags.AllowEllipsis */) === 0) {
858
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.ellipsisContext(), node);
859
+ typeResult = { type: types_1.UnknownType.create() };
860
+ }
861
+ else {
862
+ const ellipsisType = (_b = (_a = getBuiltInObject(node, 'EllipsisType')) !== null && _a !== void 0 ? _a : getBuiltInObject(node, 'ellipsis')) !== null && _b !== void 0 ? _b : types_1.AnyType.create();
863
+ typeResult = { type: ellipsisType };
864
+ }
868
865
  }
869
866
  return typeResult;
870
867
  }
@@ -1112,7 +1109,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1112
1109
  }
1113
1110
  }
1114
1111
  return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
1115
- var _a;
1116
1112
  if ((0, types_1.isClass)(subtype)) {
1117
1113
  if (subtype.priv.literalValue !== undefined) {
1118
1114
  subtype = types_1.ClassType.cloneWithLiteral(subtype, /* value */ undefined);
@@ -1121,9 +1117,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1121
1117
  // Handle "LiteralString" specially.
1122
1118
  if (strClass && (0, types_1.isInstantiableClass)(strClass)) {
1123
1119
  let strInstance = types_1.ClassType.cloneAsInstance(strClass);
1124
- if ((_a = subtype.props) === null || _a === void 0 ? void 0 : _a.condition) {
1125
- strInstance = types_1.TypeBase.cloneForCondition(strInstance, (0, typeUtils_1.getTypeCondition)(subtype));
1126
- }
1120
+ strInstance = types_1.TypeBase.cloneForCondition(strInstance, (0, typeUtils_1.getTypeCondition)(subtype));
1127
1121
  return strInstance;
1128
1122
  }
1129
1123
  }
@@ -1557,10 +1551,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1557
1551
  return undefined;
1558
1552
  }
1559
1553
  function getBoundMagicMethod(classType, memberName, selfType, diag, recursionCount = 0) {
1560
- if (recursionCount > types_1.maxTypeRecursionCount) {
1561
- return undefined;
1562
- }
1563
- recursionCount++;
1564
1554
  const boundMethodResult = getTypeOfBoundMember(
1565
1555
  /* errorNode */ undefined, classType, memberName,
1566
1556
  /* usage */ undefined, diag, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */, selfType, recursionCount);
@@ -1571,6 +1561,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1571
1561
  return boundMethodResult.type;
1572
1562
  }
1573
1563
  if ((0, types_1.isClassInstance)(boundMethodResult.type)) {
1564
+ if (recursionCount > types_1.maxTypeRecursionCount) {
1565
+ return undefined;
1566
+ }
1567
+ recursionCount++;
1574
1568
  return getBoundMagicMethod(boundMethodResult.type, '__call__', selfType !== null && selfType !== void 0 ? selfType : types_1.ClassType.cloneAsInstance(classType), diag, recursionCount);
1575
1569
  }
1576
1570
  if ((0, types_1.isAnyOrUnknown)(boundMethodResult.type)) {
@@ -2311,7 +2305,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2311
2305
  const isTypeAlias = !!declaredType && (0, types_1.isClassInstance)(declaredType) && types_1.ClassType.isBuiltIn(declaredType, 'TypeAlias');
2312
2306
  if (declaredType && !isTypeAlias) {
2313
2307
  let diagAddendum = new diagnostic_1.DiagnosticAddendum();
2314
- if (!assignType(declaredType, typeResult.type, diagAddendum)) {
2308
+ const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(nameNode);
2309
+ const boundDeclaredType = (0, typeUtils_1.makeTypeVarsBound)(declaredType, liveScopeIds);
2310
+ const srcType = (0, typeUtils_1.makeTypeVarsBound)(typeResult.type, liveScopeIds);
2311
+ if (!assignType(boundDeclaredType, srcType, diagAddendum)) {
2315
2312
  // If there was an expected type mismatch, use that diagnostic
2316
2313
  // addendum because it will be more informative.
2317
2314
  if (expectedTypeDiagAddendum) {
@@ -2645,7 +2642,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2645
2642
  var _a;
2646
2643
  if ((0, types_1.isParamSpec)(subtype)) {
2647
2644
  if (subtype.priv.paramSpecAccess === 'args') {
2648
- return makeTupleObject([{ type: getObjectType(), isUnbounded: true }]);
2645
+ return (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type: getObjectType(), isUnbounded: true }]);
2649
2646
  }
2650
2647
  else if (subtype.priv.paramSpecAccess === 'kwargs') {
2651
2648
  if (dictClass && (0, types_1.isInstantiableClass)(dictClass) && strClass && (0, types_1.isInstantiableClass)(strClass)) {
@@ -2676,7 +2673,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2676
2673
  return types_1.AnyType.create();
2677
2674
  }
2678
2675
  // Fall back to "*tuple[object, ...]".
2679
- return makeTupleObject([{ type: getObjectType(), isUnbounded: true }], /* isUnpacked */ true);
2676
+ return (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type: getObjectType(), isUnbounded: true }],
2677
+ /* isUnpacked */ true);
2680
2678
  }
2681
2679
  if ((0, types_1.isTypeVar)(subtype)) {
2682
2680
  // If this is a recursive type alias placeholder
@@ -2716,6 +2714,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2716
2714
  useBoundTypeVars: types_1.TypeVarType.isBound(subtype),
2717
2715
  });
2718
2716
  }
2717
+ if (subtype.priv.isUnpacked && (0, types_1.isClass)(boundType)) {
2718
+ boundType = types_1.ClassType.cloneForUnpacked(boundType);
2719
+ }
2719
2720
  boundType = types_1.TypeBase.isInstantiable(subtype) ? (0, typeUtils_1.convertToInstantiable)(boundType) : boundType;
2720
2721
  return (0, typeUtils_1.addConditionToType)(boundType, [{ typeVar: subtype, constraintIndex: 0 }]);
2721
2722
  }
@@ -2892,11 +2893,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2892
2893
  break;
2893
2894
  }
2894
2895
  case 54 /* ParseNodeType.TypeAnnotation */: {
2895
- const annotationType = getTypeOfAnnotation(target.d.annotation, {
2896
+ let annotationType = getTypeOfAnnotation(target.d.annotation, {
2896
2897
  varTypeAnnotation: true,
2897
2898
  allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(target.d.valueExpr),
2898
2899
  allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(target.d.valueExpr),
2899
2900
  });
2901
+ if (annotationType) {
2902
+ const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(target);
2903
+ annotationType = (0, typeUtils_1.makeTypeVarsBound)(annotationType, liveScopeIds);
2904
+ }
2900
2905
  // Handle a bare "Final" or "ClassVar" in a special manner.
2901
2906
  const isBareFinalOrClassVar = (0, types_1.isClassInstance)(annotationType) &&
2902
2907
  (types_1.ClassType.isBuiltIn(annotationType, 'Final') || types_1.ClassType.isBuiltIn(annotationType, 'ClassVar'));
@@ -3145,6 +3150,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3145
3150
  if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
3146
3151
  type = validateSymbolIsTypeExpression(node, type, !!effectiveTypeInfo.includesVariableDecl);
3147
3152
  }
3153
+ if ((0, types_1.isTypeVar)(type) && !type.shared.isSynthesized) {
3154
+ type = validateTypeVarUsage(node, type, flags);
3155
+ }
3148
3156
  // Add TypeForm details if appropriate.
3149
3157
  type = addTypeFormForSymbol(node, type, flags, !!effectiveTypeInfo.includesVariableDecl);
3150
3158
  }
@@ -3158,7 +3166,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3158
3166
  type = types_1.UnknownType.create();
3159
3167
  }
3160
3168
  }
3161
- if ((0, types_1.isParamSpec)(type)) {
3169
+ if ((0, types_1.isParamSpec)(type) && type.priv.scopeId) {
3162
3170
  if (flags & 32 /* EvalFlags.NoParamSpec */) {
3163
3171
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.paramSpecContext(), node);
3164
3172
  type = types_1.UnknownType.create();
@@ -3175,9 +3183,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3175
3183
  }
3176
3184
  }
3177
3185
  }
3178
- if ((0, types_1.isTypeVar)(type) && !type.shared.isSynthesized) {
3179
- type = validateTypeVarUsage(node, type, flags);
3180
- }
3181
3186
  return { type, isIncomplete };
3182
3187
  }
3183
3188
  function addTypeFormForSymbol(node, type, flags, includesVarDecl) {
@@ -3233,7 +3238,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3233
3238
  if ((0, typeUtils_1.isTypeAliasPlaceholder)(type)) {
3234
3239
  return true;
3235
3240
  }
3236
- if ((0, types_1.isTypeVar)(type) && !type.priv.scopeId) {
3241
+ if ((0, types_1.isTypeVar)(type)) {
3237
3242
  return true;
3238
3243
  }
3239
3244
  // Exempts class types that are created by calling NewType, NamedTuple, etc.
@@ -3472,7 +3477,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3472
3477
  if (type.priv.scopeId && !scopedTypeVarInfo.foundInterveningClass) {
3473
3478
  return type;
3474
3479
  }
3475
- if (!type.shared.isSynthesized) {
3480
+ if (!type.shared.isSynthesized && (flags & 128 /* EvalFlags.InstantiableType */) !== 0) {
3476
3481
  const message = (0, types_1.isParamSpec)(type)
3477
3482
  ? localize_1.LocMessage.paramSpecNotUsedByOuterScope()
3478
3483
  : localize_1.LocMessage.typeVarNotUsedByOuterScope();
@@ -4793,7 +4798,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4793
4798
  }
4794
4799
  });
4795
4800
  }
4796
- const tupleObject = makeTupleObject(variadicTypes, /* isUnpacked */ true);
4801
+ const tupleObject = (0, tuples_1.makeTupleObject)(evaluatorInterface, variadicTypes, /* isUnpacked */ true);
4797
4802
  typeArgs = [
4798
4803
  ...typeArgs.slice(0, variadicIndex),
4799
4804
  { node: typeArgs[variadicIndex].node, type: tupleObject },
@@ -4805,7 +4810,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4805
4810
  // Add an empty tuple that maps to the TypeVarTuple type parameter.
4806
4811
  typeArgs.push({
4807
4812
  node: errorNode,
4808
- type: makeTupleObject([], /* isUnpacked */ true),
4813
+ type: (0, tuples_1.makeTupleObject)(evaluatorInterface, [], /* isUnpacked */ true),
4809
4814
  });
4810
4815
  }
4811
4816
  }
@@ -4853,7 +4858,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4853
4858
  });
4854
4859
  }
4855
4860
  else if ((0, types_1.isTypeVarTuple)(param) && tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
4856
- defaultType = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }],
4861
+ defaultType = (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type: types_1.UnknownType.create(), isUnbounded: true }],
4857
4862
  /* isUnpacked */ true);
4858
4863
  }
4859
4864
  else {
@@ -4898,22 +4903,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4898
4903
  }
4899
4904
  inferVarianceForTypeAlias(baseType);
4900
4905
  const typeParams = aliasInfo.shared.typeParams;
4901
- let typeArgs = adjustTypeArgsForTypeVarTuple(getTypeArgs(node, flags), typeParams, node);
4906
+ let typeArgs;
4907
+ typeArgs = adjustTypeArgsForTypeVarTuple(getTypeArgs(node, flags), typeParams, node);
4902
4908
  let reportedError = false;
4903
- // PEP 612 says that if the class has only one type parameter consisting
4904
- // of a ParamSpec, the list of arguments does not need to be enclosed in
4905
- // a list. We'll handle that case specially here. Presumably this applies to
4906
- // type aliases as well.
4907
- if (typeParams.length === 1 && (0, types_1.isParamSpec)(typeParams[0]) && typeArgs) {
4908
- if (typeArgs.every((typeArg) => !(0, typeUtils_1.isEllipsisType)(typeArg.type) && !typeArg.typeList && !(0, types_1.isParamSpec)(typeArg.type))) {
4909
- typeArgs = [
4910
- {
4911
- type: types_1.UnknownType.create(),
4912
- node: typeArgs.length > 0 ? typeArgs[0].node : node,
4913
- typeList: typeArgs,
4914
- },
4915
- ];
4916
- }
4909
+ typeArgs = transformTypeArgsForParamSpec(typeParams, typeArgs, node);
4910
+ if (!typeArgs) {
4911
+ typeArgs = [];
4912
+ reportedError = true;
4917
4913
  }
4918
4914
  let minTypeArgCount = typeParams.length;
4919
4915
  const firstDefaultParamIndex = typeParams.findIndex((param) => !!param.shared.isDefaultExplicit);
@@ -4950,8 +4946,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4950
4946
  const typeList = typeArgs[index].typeList;
4951
4947
  if (typeList) {
4952
4948
  const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
4953
- typeList.forEach((paramType, paramIndex) => {
4954
- types_1.FunctionType.addParam(functionType, types_1.FunctionParam.create(0 /* ParamCategory.Simple */, (0, typeUtils_1.convertToInstance)(paramType.type), types_1.FunctionParamFlags.NameSynthesized | types_1.FunctionParamFlags.TypeDeclared, `__p${paramIndex}`));
4949
+ typeList.forEach((paramTypeResult, paramIndex) => {
4950
+ let paramType = paramTypeResult.type;
4951
+ if (!validateTypeArg(paramTypeResult)) {
4952
+ paramType = types_1.UnknownType.create();
4953
+ }
4954
+ types_1.FunctionType.addParam(functionType, types_1.FunctionParam.create(0 /* ParamCategory.Simple */, (0, typeUtils_1.convertToInstance)(paramType), types_1.FunctionParamFlags.NameSynthesized | types_1.FunctionParamFlags.TypeDeclared, `__p${paramIndex}`));
4955
4955
  });
4956
4956
  if (typeList.length > 0) {
4957
4957
  types_1.FunctionType.addPositionOnlyParamSeparator(functionType);
@@ -5283,14 +5283,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5283
5283
  // Looks at uses of the type parameters within the type and adjusts the
5284
5284
  // variances accordingly. For example, if the type is `Mapping[T1, T2]`,
5285
5285
  // then T1 will be set to invariant and T2 will be set to covariant.
5286
- function updateUsageVariancesRecursive(type, typeAliasTypeParams, usageVariances, varianceContext, recursionCount = 0) {
5286
+ function updateUsageVariancesRecursive(type, typeAliasTypeParams, usageVariances, varianceContext, pendingTypes = [], recursionCount = 0) {
5287
5287
  if (recursionCount > types_1.maxTypeRecursionCount) {
5288
5288
  return;
5289
5289
  }
5290
5290
  const transformedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(type);
5291
- // If this is a recursive type alias, use a lower recursion limit.
5291
+ // If this is a recursive type alias, see if we've already recursed
5292
+ // seen it once before in the recursion stack. If so, don't recurse
5293
+ // further.
5292
5294
  if (transformedType !== type) {
5293
- if (recursionCount > maxRecursiveTypeAliasRecursionCount) {
5295
+ const pendingOverlaps = pendingTypes.filter((pendingType) => (0, types_1.isTypeSame)(pendingType, type));
5296
+ if (pendingOverlaps.length > 1) {
5294
5297
  return;
5295
5298
  }
5296
5299
  }
@@ -5303,7 +5306,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5303
5306
  usageVariances[typeParamIndex] = (0, typeUtils_1.combineVariances)(usageVariances[typeParamIndex], variance);
5304
5307
  }
5305
5308
  else {
5306
- updateUsageVariancesRecursive(subtype, typeAliasTypeParams, usageVariances, variance, recursionCount);
5309
+ pendingTypes.push(type);
5310
+ updateUsageVariancesRecursive(subtype, typeAliasTypeParams, usageVariances, variance, pendingTypes, recursionCount);
5311
+ pendingTypes.pop();
5307
5312
  }
5308
5313
  });
5309
5314
  }
@@ -5349,12 +5354,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5349
5354
  }
5350
5355
  });
5351
5356
  }
5352
- function makeTupleObject(typeArgs, isUnpacked = false) {
5353
- if (tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
5354
- return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClass, typeArgs, /* isTypeArgExplicit */ true, isUnpacked));
5355
- }
5356
- return types_1.UnknownType.create();
5357
- }
5358
5357
  function getIndexAccessMagicMethodName(usage) {
5359
5358
  if (usage.method === 'get') {
5360
5359
  return '__getitem__';
@@ -5443,7 +5442,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5443
5442
  }
5444
5443
  else if (positionalArgs.length === 0 && unpackedListArgs.length === 0) {
5445
5444
  // Handle the case where there are no positionals provided but there are keywords.
5446
- positionalIndexType = makeTupleObject([]);
5445
+ positionalIndexType = (0, tuples_1.makeTupleObject)(evaluatorInterface, []);
5447
5446
  }
5448
5447
  else {
5449
5448
  // Package up all of the positionals into a tuple.
@@ -5464,7 +5463,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5464
5463
  const iterableType = (_b = (_a = getTypeOfIterator(typeResult, /* isAsync */ false, arg.d.valueExpr)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
5465
5464
  tupleTypeArgs.push({ type: iterableType, isUnbounded: true });
5466
5465
  });
5467
- positionalIndexType = makeTupleObject(tupleTypeArgs);
5466
+ positionalIndexType = (0, tuples_1.makeTupleObject)(evaluatorInterface, tupleTypeArgs);
5468
5467
  }
5469
5468
  const argList = [
5470
5469
  {
@@ -5567,7 +5566,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5567
5566
  }
5568
5567
  else if ((options === null || options === void 0 ? void 0 : options.isAnnotatedClass) && argIndex > 0) {
5569
5568
  // If it's an Annotated[a, b, c], only the first index should be
5570
- // treated as a type.The others can be regular(non - type) objects.
5569
+ // treated as a type. The others can be regular (non-type) objects.
5571
5570
  adjFlags =
5572
5571
  32 /* EvalFlags.NoParamSpec */ | 64 /* EvalFlags.NoTypeVarTuple */ | 2 /* EvalFlags.NoSpecialize */ | 131072 /* EvalFlags.NoClassVar */;
5573
5572
  if ((0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(AnalyzerNodeInfo.getFileInfo(node))) {
@@ -5593,38 +5592,70 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5593
5592
  });
5594
5593
  // Set the node's type so it isn't reevaluated later.
5595
5594
  setTypeResultForNode(node.d.items[0].d.valueExpr, { type: types_1.UnknownType.create() });
5596
- }
5597
- else {
5598
- node.d.items.forEach((arg, index) => {
5599
- const typeResult = getTypeArgTypeResult(arg.d.valueExpr, index);
5600
- if (arg.d.argCategory !== 0 /* ArgCategory.Simple */) {
5601
- if (arg.d.argCategory === 1 /* ArgCategory.UnpackedList */) {
5602
- if (!(options === null || options === void 0 ? void 0 : options.isAnnotatedClass) || index === 0) {
5603
- if ((0, types_1.isTypeVarTuple)(typeResult.type) && !typeResult.type.priv.isUnpacked) {
5604
- typeResult.type = types_1.TypeVarType.cloneForUnpacked(typeResult.type);
5605
- }
5606
- else if ((0, types_1.isInstantiableClass)(typeResult.type) &&
5607
- !typeResult.type.priv.includeSubclasses &&
5608
- (0, typeUtils_1.isTupleClass)(typeResult.type)) {
5609
- typeResult.type = types_1.ClassType.cloneForUnpacked(typeResult.type);
5595
+ return typeArgs;
5596
+ }
5597
+ node.d.items.forEach((arg, index) => {
5598
+ const typeResult = getTypeArgTypeResult(arg.d.valueExpr, index);
5599
+ if (arg.d.argCategory !== 0 /* ArgCategory.Simple */) {
5600
+ if (arg.d.argCategory === 1 /* ArgCategory.UnpackedList */) {
5601
+ if (!(options === null || options === void 0 ? void 0 : options.isAnnotatedClass) || index === 0) {
5602
+ const unpackedType = applyUnpackToTupleLike(typeResult.type);
5603
+ if (unpackedType) {
5604
+ typeResult.type = unpackedType;
5605
+ }
5606
+ else {
5607
+ if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
5608
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.unpackNotAllowed(), arg.d.valueExpr);
5609
+ typeResult.typeErrors = true;
5610
5610
  }
5611
5611
  else {
5612
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.unpackNotAllowed(), arg.d.valueExpr);
5612
+ typeResult.type = types_1.UnknownType.create();
5613
5613
  }
5614
5614
  }
5615
5615
  }
5616
5616
  }
5617
- if (arg.d.name) {
5617
+ }
5618
+ if (arg.d.name) {
5619
+ if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
5618
5620
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.keywordArgInTypeArgument(), arg.d.valueExpr);
5621
+ typeResult.typeErrors = true;
5619
5622
  }
5620
- if (arg.d.valueExpr.nodeType !== 0 /* ParseNodeType.Error */ ||
5621
- arg.d.valueExpr.d.category !== 3 /* ErrorExpressionCategory.MissingIndexOrSlice */) {
5622
- typeArgs.push(typeResult);
5623
+ else {
5624
+ typeResult.type = types_1.UnknownType.create();
5623
5625
  }
5624
- });
5625
- }
5626
+ }
5627
+ if (arg.d.valueExpr.nodeType !== 0 /* ParseNodeType.Error */ ||
5628
+ arg.d.valueExpr.d.category !== 3 /* ErrorExpressionCategory.MissingIndexOrSlice */) {
5629
+ typeArgs.push(typeResult);
5630
+ }
5631
+ });
5626
5632
  return typeArgs;
5627
5633
  }
5634
+ function applyUnpackToTupleLike(type) {
5635
+ if ((0, types_1.isTypeVarTuple)(type)) {
5636
+ if (!type.priv.isUnpacked) {
5637
+ return types_1.TypeVarType.cloneForUnpacked(type);
5638
+ }
5639
+ return undefined;
5640
+ }
5641
+ if ((0, types_1.isParamSpec)(type)) {
5642
+ return undefined;
5643
+ }
5644
+ // Is this a TypeVar that has a tuple upper bound?
5645
+ if ((0, types_1.isTypeVar)(type)) {
5646
+ const upperBound = type.shared.boundType;
5647
+ if (upperBound && (0, types_1.isClassInstance)(upperBound) && (0, typeUtils_1.isTupleClass)(upperBound)) {
5648
+ return types_1.TypeVarType.cloneForUnpacked(type);
5649
+ }
5650
+ return undefined;
5651
+ }
5652
+ if ((0, types_1.isInstantiableClass)(type) && !type.priv.includeSubclasses) {
5653
+ if ((0, typeUtils_1.isTupleClass)(type)) {
5654
+ return types_1.ClassType.cloneForUnpacked(type);
5655
+ }
5656
+ }
5657
+ return undefined;
5658
+ }
5628
5659
  function getTypeArg(node, flags) {
5629
5660
  let typeResult;
5630
5661
  let adjustedFlags = flags | 128 /* EvalFlags.InstantiableType */ | 1 /* EvalFlags.ConvertEllipsisToAny */ | 8 /* EvalFlags.StrLiteralAsType */;
@@ -5657,138 +5688,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5657
5688
  }
5658
5689
  return typeResult;
5659
5690
  }
5660
- function getTypeOfTuple(node, flags, inferenceContext) {
5661
- var _a;
5662
- if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0 && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) !== 1 /* ParseNodeType.Argument */) {
5663
- // This is allowed inside of an index trailer, specifically
5664
- // to support Tuple[()], which is the documented way to annotate
5665
- // a zero-length tuple.
5666
- const diag = new diagnostic_1.DiagnosticAddendum();
5667
- diag.addMessage(localize_1.LocAddendum.useTupleInstead());
5668
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.tupleInAnnotation() + diag.getString(), node);
5669
- return { type: types_1.UnknownType.create() };
5670
- }
5671
- if ((flags & 128 /* EvalFlags.InstantiableType */) !== 0 && node.d.items.length === 0 && !inferenceContext) {
5672
- return { type: makeTupleObject([]), isEmptyTupleShorthand: true };
5673
- }
5674
- flags &= ~(256 /* EvalFlags.TypeExpression */ | 8 /* EvalFlags.StrLiteralAsType */ | 128 /* EvalFlags.InstantiableType */);
5675
- // If the expected type is a union, recursively call for each of the subtypes
5676
- // to find one that matches.
5677
- let expectedType = inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType;
5678
- let expectedTypeContainsAny = inferenceContext && (0, types_1.isAny)(inferenceContext.expectedType);
5679
- if (inferenceContext && (0, types_1.isUnion)(inferenceContext.expectedType)) {
5680
- let matchingSubtype;
5681
- (0, typeUtils_1.doForEachSubtype)(inferenceContext.expectedType, (subtype) => {
5682
- if ((0, types_1.isAny)(subtype)) {
5683
- expectedTypeContainsAny = true;
5684
- }
5685
- if (!matchingSubtype) {
5686
- const subtypeResult = useSpeculativeMode(node, () => {
5687
- return getTypeOfTupleWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(subtype));
5688
- });
5689
- if (subtypeResult && assignType(subtype, subtypeResult.type)) {
5690
- matchingSubtype = subtype;
5691
- }
5692
- }
5693
- },
5694
- /* sortSubtypes */ true);
5695
- expectedType = matchingSubtype;
5696
- }
5697
- let expectedTypeDiagAddendum;
5698
- if (expectedType) {
5699
- const result = getTypeOfTupleWithContext(node, flags, (0, typeUtils_1.makeInferenceContext)(expectedType));
5700
- if (result && !result.typeErrors) {
5701
- return result;
5702
- }
5703
- expectedTypeDiagAddendum = result === null || result === void 0 ? void 0 : result.expectedTypeDiagAddendum;
5704
- }
5705
- const typeResult = getTypeOfTupleInferred(node, flags);
5706
- // If there was an expected type of Any, replace the resulting type
5707
- // with Any rather than return a type with unknowns.
5708
- if (expectedTypeContainsAny) {
5709
- typeResult.type = types_1.AnyType.create();
5710
- }
5711
- return { ...typeResult, expectedTypeDiagAddendum };
5712
- }
5713
- function getTypeOfTupleWithContext(node, flags, inferenceContext) {
5714
- inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
5715
- if (!(0, types_1.isClassInstance)(inferenceContext.expectedType)) {
5716
- return undefined;
5717
- }
5718
- if (!tupleClass || !(0, types_1.isInstantiableClass)(tupleClass)) {
5719
- return undefined;
5720
- }
5721
- // Build an array of expected types.
5722
- let expectedTypes = [];
5723
- if ((0, typeUtils_1.isTupleClass)(inferenceContext.expectedType) && inferenceContext.expectedType.priv.tupleTypeArgs) {
5724
- expectedTypes = inferenceContext.expectedType.priv.tupleTypeArgs.map((t) => (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(t.type));
5725
- const unboundedIndex = inferenceContext.expectedType.priv.tupleTypeArgs.findIndex((t) => t.isUnbounded);
5726
- if (unboundedIndex >= 0) {
5727
- if (expectedTypes.length > node.d.items.length) {
5728
- expectedTypes.splice(unboundedIndex, 1);
5729
- }
5730
- else {
5731
- while (expectedTypes.length < node.d.items.length) {
5732
- expectedTypes.splice(unboundedIndex, 0, expectedTypes[unboundedIndex]);
5733
- }
5734
- }
5735
- }
5736
- }
5737
- else {
5738
- const tupleConstraints = new constraintTracker_1.ConstraintTracker();
5739
- if (!(0, constraintSolver_1.addConstraintsForExpectedType)(evaluatorInterface, types_1.ClassType.cloneAsInstance(tupleClass), inferenceContext.expectedType, tupleConstraints, ParseTreeUtils.getTypeVarScopesForNode(node), node.start)) {
5740
- return undefined;
5741
- }
5742
- const specializedTuple = solveAndApplyConstraints(tupleClass, tupleConstraints);
5743
- if (!specializedTuple.priv.typeArgs || specializedTuple.priv.typeArgs.length !== 1) {
5744
- return undefined;
5745
- }
5746
- const homogenousType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(specializedTuple.priv.typeArgs[0]);
5747
- for (let i = 0; i < node.d.items.length; i++) {
5748
- expectedTypes.push(homogenousType);
5749
- }
5750
- }
5751
- const entryTypeResults = node.d.items.map((expr, index) => getTypeOfExpression(expr, flags | 268435456 /* EvalFlags.StripTupleLiterals */, (0, typeUtils_1.makeInferenceContext)(index < expectedTypes.length ? expectedTypes[index] : undefined, inferenceContext.isTypeIncomplete)));
5752
- const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
5753
- // Copy any expected type diag addenda for precision error reporting.
5754
- let expectedTypeDiagAddendum;
5755
- if (entryTypeResults.some((result) => result.expectedTypeDiagAddendum)) {
5756
- expectedTypeDiagAddendum = new diagnostic_1.DiagnosticAddendum();
5757
- entryTypeResults.forEach((result) => {
5758
- if (result.expectedTypeDiagAddendum) {
5759
- expectedTypeDiagAddendum.addAddendum(result.expectedTypeDiagAddendum);
5760
- }
5761
- });
5762
- }
5763
- // If the tuple contains a very large number of entries, it's probably
5764
- // generated code. If we encounter type errors, don't bother building
5765
- // the full tuple type.
5766
- let type;
5767
- if (node.d.items.length > maxInferredTupleEntryCount && entryTypeResults.some((result) => result.typeErrors)) {
5768
- type = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }]);
5769
- }
5770
- else {
5771
- type = makeTupleObject(buildTupleTypesList(entryTypeResults, /* stripLiterals */ false));
5772
- }
5773
- return { type, expectedTypeDiagAddendum, isIncomplete };
5774
- }
5775
- function getTypeOfTupleInferred(node, flags) {
5776
- const entryTypeResults = node.d.items.map((expr) => getTypeOfExpression(expr, flags | 268435456 /* EvalFlags.StripTupleLiterals */));
5777
- const isIncomplete = entryTypeResults.some((result) => result.isIncomplete);
5778
- // If the tuple contains a very large number of entries, it's probably
5779
- // generated code. Rather than taking the time to evaluate every entry,
5780
- // simply return an unknown type in this case.
5781
- if (node.d.items.length > maxInferredTupleEntryCount) {
5782
- return { type: makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }]) };
5783
- }
5784
- const type = makeTupleObject(buildTupleTypesList(entryTypeResults, (flags & 268435456 /* EvalFlags.StripTupleLiterals */) !== 0));
5785
- if (isIncomplete) {
5786
- if ((0, typeUtils_1.getContainerDepth)(type) > maxInferredContainerDepth) {
5787
- return { type: types_1.UnknownType.create() };
5788
- }
5789
- }
5790
- return { type, isIncomplete };
5791
- }
5792
5691
  function buildTupleTypesList(entryTypeResults, stripLiterals) {
5793
5692
  const entryTypes = [];
5794
5693
  for (const typeResult of entryTypeResults) {
@@ -5999,7 +5898,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5999
5898
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.typeFormArgs(), node);
6000
5899
  return { type: types_1.UnknownType.create() };
6001
5900
  }
6002
- const typeFormResult = getTypeOfArgExpectingType((0, typeUtils_1.convertNodeToArg)(node.d.args[0]), {
5901
+ const typeFormResult = getTypeOfArgExpectingType(convertNodeToArg(node.d.args[0]), {
6003
5902
  typeFormArg: isTypeFormSupported(node),
6004
5903
  noNonTypeSpecialForms: true,
6005
5904
  typeExpression: true,
@@ -6022,7 +5921,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6022
5921
  if (arg0TypeResult.isIncomplete) {
6023
5922
  return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
6024
5923
  }
6025
- const assertedType = (0, typeUtils_1.convertToInstance)(getTypeOfArgExpectingType((0, typeUtils_1.convertNodeToArg)(node.d.args[1]), {
5924
+ const assertedType = (0, typeUtils_1.convertToInstance)(getTypeOfArgExpectingType(convertNodeToArg(node.d.args[1]), {
6026
5925
  typeExpression: true,
6027
5926
  }).type);
6028
5927
  // We'll replace TypeGuard and TypeIs with bool for purposes of assert_type testing.
@@ -6041,6 +5940,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6041
5940
  }
6042
5941
  return { type: arg0TypeResult.type };
6043
5942
  }
5943
+ function convertNodeToArg(node) {
5944
+ return {
5945
+ argCategory: node.d.argCategory,
5946
+ name: node.d.name,
5947
+ valueExpression: node.d.valueExpr,
5948
+ };
5949
+ }
6044
5950
  function getTypeOfRevealType(node, inferenceContext) {
6045
5951
  let arg0Value;
6046
5952
  let expectedRevealTypeNode;
@@ -6071,7 +5977,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6071
5977
  }
6072
5978
  else if (arg.d.name.d.value === 'expected_type') {
6073
5979
  expectedRevealTypeNode = arg.d.valueExpr;
6074
- expectedRevealType = (0, typeUtils_1.convertToInstance)(getTypeOfArgExpectingType((0, typeUtils_1.convertNodeToArg)(arg), {
5980
+ expectedRevealType = (0, typeUtils_1.convertToInstance)(getTypeOfArgExpectingType(convertNodeToArg(arg), {
6075
5981
  typeExpression: true,
6076
5982
  }).type);
6077
5983
  }
@@ -7314,7 +7220,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7314
7220
  function evaluateCastCall(argList, errorNode) {
7315
7221
  var _a;
7316
7222
  // Verify that the cast is necessary.
7317
- const castToType = getTypeOfArgExpectingType(argList[0], { typeExpression: true }).type;
7223
+ let castToType = getTypeOfArgExpectingType(argList[0], { typeExpression: true }).type;
7224
+ const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
7225
+ castToType = (0, typeUtils_1.makeTypeVarsBound)(castToType, liveScopeIds);
7318
7226
  let castFromType = getTypeOfArg(argList[1], /* inferenceContext */ undefined).type;
7319
7227
  if ((_a = castFromType.props) === null || _a === void 0 ? void 0 : _a.specialForm) {
7320
7228
  castFromType = castFromType.props.specialForm;
@@ -7351,7 +7259,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7351
7259
  argCategory: 1 /* ArgCategory.UnpackedList */,
7352
7260
  valueExpression: undefined,
7353
7261
  typeResult: {
7354
- type: makeTupleObject([tupleTypeArg]),
7262
+ type: (0, tuples_1.makeTupleObject)(evaluatorInterface, [tupleTypeArg]),
7355
7263
  },
7356
7264
  });
7357
7265
  }
@@ -7547,7 +7455,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7547
7455
  const paramInfo = paramDetails.params[paramIndex];
7548
7456
  const paramType = paramInfo.type;
7549
7457
  const paramName = paramInfo.param.name;
7550
- const isParamVariadic = paramInfo.param.category === 1 /* ParamCategory.ArgsList */ && (0, types_1.isTypeVarTuple)(paramType);
7458
+ const isParamVariadic = paramInfo.param.category === 1 /* ParamCategory.ArgsList */ && (0, types_1.isUnpacked)(paramType);
7551
7459
  if (argList[argIndex].argCategory === 1 /* ArgCategory.UnpackedList */) {
7552
7460
  let isArgCompatibleWithVariadic = false;
7553
7461
  const argTypeResult = getTypeOfArg(argList[argIndex], /* inferenceContext */ undefined);
@@ -7679,7 +7587,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7679
7587
  paramType.priv.tupleTypeArgs.length > 0) {
7680
7588
  effectiveParamType = paramType.priv.tupleTypeArgs[0].type;
7681
7589
  }
7682
- paramCategory = (0, types_1.isTypeVarTuple)(effectiveParamType) ? 1 /* ParamCategory.ArgsList */ : 0 /* ParamCategory.Simple */;
7590
+ paramCategory = (0, types_1.isUnpacked)(effectiveParamType) ? 1 /* ParamCategory.ArgsList */ : 0 /* ParamCategory.Simple */;
7683
7591
  if (remainingArgCount <= remainingParamCount) {
7684
7592
  if (remainingArgCount < remainingParamCount) {
7685
7593
  if (!canSkipDiagnosticForNode(errorNode) && !isTypeIncomplete) {
@@ -8158,7 +8066,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8158
8066
  !isTypeVarTupleFullyMatched) {
8159
8067
  const paramType = paramDetails.params[paramDetails.argsIndex].type;
8160
8068
  const variadicArgs = validateArgTypeParams.filter((argParam) => argParam.mapsToVarArgList);
8161
- if ((0, types_1.isTypeVarTuple)(paramType) && !paramType.priv.isInUnion) {
8069
+ if ((0, types_1.isUnpacked)(paramType) && (!(0, types_1.isTypeVarTuple)(paramType) || !paramType.priv.isInUnion)) {
8162
8070
  const tupleTypeArgs = variadicArgs.map((argParam) => {
8163
8071
  var _a;
8164
8072
  const argType = getTypeOfArg(argParam.argument, /* inferenceContext */ undefined).type;
@@ -8182,20 +8090,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8182
8090
  };
8183
8091
  });
8184
8092
  let specializedTuple;
8185
- if (tupleTypeArgs.length === 1 &&
8186
- !tupleTypeArgs[0].isUnbounded &&
8187
- ((0, types_1.isUnpackedClass)(tupleTypeArgs[0].type) || (0, types_1.isTypeVarTuple)(tupleTypeArgs[0].type))) {
8188
- // If there is a single unpacked tuple or unpacked variadic type variable
8189
- // (including an unpacked TypeVarTuple union) within this tuple,
8190
- // simplify the type.
8191
- specializedTuple = tupleTypeArgs[0].type;
8093
+ if (tupleTypeArgs.length === 1 && !tupleTypeArgs[0].isUnbounded) {
8094
+ const entryType = tupleTypeArgs[0].type;
8095
+ if ((0, types_1.isUnpacked)(entryType)) {
8096
+ specializedTuple = (0, typeUtils_1.makePacked)(entryType);
8097
+ }
8192
8098
  }
8193
- else {
8194
- specializedTuple = makeTupleObject(tupleTypeArgs, /* isUnpacked */ true);
8099
+ if (!specializedTuple) {
8100
+ specializedTuple = (0, tuples_1.makeTupleObject)(evaluatorInterface, tupleTypeArgs, /* isUnpacked */ false);
8195
8101
  }
8196
8102
  const combinedArg = {
8197
- paramCategory: 1 /* ParamCategory.ArgsList */,
8198
- paramType,
8103
+ paramCategory: 0 /* ParamCategory.Simple */,
8104
+ paramType: (0, typeUtils_1.makePacked)(paramType),
8199
8105
  requiresTypeVarMatching: true,
8200
8106
  argument: {
8201
8107
  argCategory: 0 /* ArgCategory.Simple */,
@@ -8521,7 +8427,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8521
8427
  }
8522
8428
  // If the final return type is an unpacked tuple, turn it into a normal (unpacked) tuple.
8523
8429
  if ((0, types_1.isUnpackedClass)(specializedReturnType)) {
8524
- specializedReturnType = types_1.ClassType.cloneForUnpacked(specializedReturnType, /* isUnpacked */ false);
8430
+ specializedReturnType = types_1.ClassType.cloneForPacked(specializedReturnType);
8525
8431
  }
8526
8432
  const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
8527
8433
  specializedReturnType = adjustCallableReturnType(errorNode, specializedReturnType, liveTypeVarScopes);
@@ -9100,7 +9006,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9100
9006
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarFirstArg(), firstArg.valueExpression || errorNode);
9101
9007
  }
9102
9008
  const typeVar = types_1.TypeBase.cloneAsSpecialForm(types_1.TypeVarType.createInstantiable(typeVarName, types_1.TypeVarKind.TypeVarTuple), types_1.ClassType.cloneAsInstance(classType));
9103
- typeVar.shared.defaultType = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }]);
9009
+ typeVar.shared.defaultType = (0, tuples_1.makeTupleObject)(evaluatorInterface, [
9010
+ { type: types_1.UnknownType.create(), isUnbounded: true },
9011
+ ]);
9104
9012
  // Parse the remaining parameters.
9105
9013
  for (let i = 1; i < argList.length; i++) {
9106
9014
  const paramNameNode = argList[i].name;
@@ -9222,6 +9130,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9222
9130
  const typeResult = getTypeOfExpressionExpectingType(node, {
9223
9131
  allowParamSpec: true,
9224
9132
  allowTypeVarsWithoutScopeId: true,
9133
+ allowEllipsis: true,
9225
9134
  typeExpression: true,
9226
9135
  });
9227
9136
  if (typeResult.typeErrors) {
@@ -9752,7 +9661,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9752
9661
  /* tupleTypeArgs */ undefined, isEmptyContainer))
9753
9662
  : types_1.UnknownType.create();
9754
9663
  if (isIncomplete) {
9755
- if ((0, typeUtils_1.getContainerDepth)(type) > maxInferredContainerDepth) {
9664
+ if ((0, typeUtils_1.getContainerDepth)(type) > typeEvaluatorTypes_1.maxInferredContainerDepth) {
9756
9665
  return { type: types_1.UnknownType.create() };
9757
9666
  }
9758
9667
  }
@@ -10119,7 +10028,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10119
10028
  /* tupleTypeArgs */ undefined, isEmptyContainer))
10120
10029
  : types_1.UnknownType.create();
10121
10030
  if (isIncomplete) {
10122
- if ((0, typeUtils_1.getContainerDepth)(type) > maxInferredContainerDepth) {
10031
+ if ((0, typeUtils_1.getContainerDepth)(type) > typeEvaluatorTypes_1.maxInferredContainerDepth) {
10123
10032
  return { type: types_1.UnknownType.create() };
10124
10033
  }
10125
10034
  }
@@ -10519,7 +10428,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10519
10428
  if (!expectedValueOrElementType || !(0, typeUtils_1.containsLiteralType)(expectedValueOrElementType)) {
10520
10429
  valueType = stripLiteralValue(valueType);
10521
10430
  }
10522
- type = makeTupleObject([
10431
+ type = (0, tuples_1.makeTupleObject)(evaluatorInterface, [
10523
10432
  { type: keyType, isUnbounded: false },
10524
10433
  { type: valueType, isUnbounded: false },
10525
10434
  ]);
@@ -10785,16 +10694,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10785
10694
  // As per the specification, we support None, int, bool, str, bytes literals
10786
10695
  // plus enum values.
10787
10696
  const literalTypes = [];
10697
+ let isValidTypeForm = true;
10788
10698
  for (const item of node.d.items) {
10789
10699
  let type;
10790
10700
  const itemExpr = item.d.valueExpr;
10791
10701
  if (item.d.argCategory !== 0 /* ArgCategory.Simple */) {
10792
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.unpackedArgInTypeArgument(), itemExpr);
10793
- type = types_1.UnknownType.create();
10702
+ if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
10703
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.unpackedArgInTypeArgument(), itemExpr);
10704
+ type = types_1.UnknownType.create();
10705
+ isValidTypeForm = false;
10706
+ }
10794
10707
  }
10795
10708
  else if (item.d.name) {
10796
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.keywordArgInTypeArgument(), itemExpr);
10797
- type = types_1.UnknownType.create();
10709
+ if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
10710
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.keywordArgInTypeArgument(), itemExpr);
10711
+ type = types_1.UnknownType.create();
10712
+ isValidTypeForm = false;
10713
+ }
10798
10714
  }
10799
10715
  else if (itemExpr.nodeType === 48 /* ParseNodeType.StringList */) {
10800
10716
  const isBytes = (itemExpr.d.strings[0].d.token.flags & 32 /* StringTokenFlags.Bytes */) !== 0;
@@ -10805,11 +10721,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10805
10721
  else {
10806
10722
  type = cloneBuiltinClassWithLiteral(node, classType, 'str', value);
10807
10723
  }
10808
- itemExpr.d.strings.forEach((stringNode) => {
10809
- if ((stringNode.d.token.flags & 512 /* StringTokenFlags.NamedUnicodeEscape */) !== 0) {
10810
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.literalNamedUnicodeEscape(), stringNode);
10811
- }
10812
- });
10724
+ if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
10725
+ itemExpr.d.strings.forEach((stringNode) => {
10726
+ if ((stringNode.d.token.flags & 512 /* StringTokenFlags.NamedUnicodeEscape */) !== 0) {
10727
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.literalNamedUnicodeEscape(), stringNode);
10728
+ isValidTypeForm = false;
10729
+ }
10730
+ });
10731
+ }
10813
10732
  }
10814
10733
  else if (itemExpr.nodeType === 40 /* ParseNodeType.Number */) {
10815
10734
  if (!itemExpr.d.isImaginary && itemExpr.d.isInteger) {
@@ -10865,6 +10784,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10865
10784
  if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
10866
10785
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.literalUnsupportedType(), item);
10867
10786
  type = types_1.UnknownType.create();
10787
+ isValidTypeForm = false;
10868
10788
  }
10869
10789
  else {
10870
10790
  return types_1.ClassType.cloneAsInstance(classType);
@@ -10876,7 +10796,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10876
10796
  if ((0, types_1.isUnion)(result) && unionTypeClass && (0, types_1.isInstantiableClass)(unionTypeClass)) {
10877
10797
  result = types_1.TypeBase.cloneAsSpecialForm(result, types_1.ClassType.cloneAsInstance(unionTypeClass));
10878
10798
  }
10879
- if (isTypeFormSupported(node)) {
10799
+ if (isTypeFormSupported(node) && isValidTypeForm) {
10880
10800
  result = types_1.TypeBase.cloneWithTypeForm(result, (0, typeUtils_1.convertToInstance)(result));
10881
10801
  }
10882
10802
  return result;
@@ -11087,16 +11007,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11087
11007
  }
11088
11008
  return classType;
11089
11009
  }
11090
- let typeArgType = typeArgs[0].type;
11091
- if ((0, types_1.isUnion)(typeArgType) && typeArgType.priv.subtypes.length === 1) {
11092
- typeArgType = typeArgType.priv.subtypes[0];
11093
- }
11010
+ const typeArgType = typeArgs[0].type;
11094
11011
  if ((flags & 2097152 /* EvalFlags.AllowUnpackedTuple */) !== 0) {
11095
- if ((0, types_1.isInstantiableClass)(typeArgType) && !typeArgType.priv.includeSubclasses && (0, typeUtils_1.isTupleClass)(typeArgType)) {
11096
- return types_1.ClassType.cloneForUnpacked(typeArgType);
11097
- }
11098
- if ((0, types_1.isTypeVarTuple)(typeArgType) && !typeArgType.priv.isUnpacked) {
11099
- return types_1.TypeVarType.cloneForUnpacked(typeArgType);
11012
+ const unpackedType = applyUnpackToTupleLike(typeArgType);
11013
+ if (unpackedType) {
11014
+ return unpackedType;
11100
11015
  }
11101
11016
  if ((flags & 256 /* EvalFlags.TypeExpression */) === 0) {
11102
11017
  return classType;
@@ -11210,44 +11125,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11210
11125
  }
11211
11126
  // Determines whether the metadata object is compatible with the base type.
11212
11127
  function validateTypeMetadata(errorNode, baseType, metaArg) {
11213
- var _a;
11214
- // This is an experimental feature because PEP 746 hasn't been accepted.
11215
- if (!AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.enableExperimentalFeatures) {
11216
- return true;
11217
- }
11218
- if (!(0, types_1.isClass)(metaArg.type)) {
11219
- return true;
11220
- }
11221
- const supportsTypeMethod = (_a = getTypeOfBoundMember(
11222
- /* errorNode */ undefined, metaArg.type, '__supports_type__')) === null || _a === void 0 ? void 0 : _a.type;
11223
- if (!supportsTypeMethod) {
11224
- return true;
11225
- }
11226
- // "Call" the __supports_type__ method to determine if the type is supported.
11227
- const callResult = useSpeculativeMode(errorNode, () => validateCallArgs(errorNode, [
11228
- {
11229
- argCategory: 0 /* ArgCategory.Simple */,
11230
- typeResult: { type: (0, typeUtils_1.convertToInstance)(baseType) },
11231
- },
11232
- ], { type: supportsTypeMethod },
11233
- /* constraints */ undefined,
11234
- /* skipUnknownArgCheck */ true,
11235
- /* inferenceContext */ undefined));
11236
- if (!callResult.returnType) {
11237
- return true;
11238
- }
11239
- // If there are no errors and the return type is potentially truthy,
11240
- // we know that the type is supported by this metadata object.
11241
- if (!callResult.argumentErrors && canBeTruthy(callResult.returnType)) {
11242
- return true;
11243
- }
11244
- if (!callResult.isTypeIncomplete) {
11245
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.annotatedMetadataInconsistent().format({
11246
- metadataType: printType(metaArg.type),
11247
- type: printType((0, typeUtils_1.convertToInstance)(baseType)),
11248
- }), metaArg.node);
11249
- }
11250
- return false;
11128
+ // This function was added for draft PEP 746, but the functionality
11129
+ // has been removed for now while the PEP is being revised.
11130
+ return true;
11251
11131
  }
11252
11132
  // Creates one of several "special" types that are defined in typing.pyi
11253
11133
  // but not declared in their entirety. This includes the likes of "Tuple",
@@ -11409,7 +11289,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11409
11289
  // is allowed if it's an unpacked TypeVarTuple or tuple. None is also allowed
11410
11290
  // since it is used to define NoReturn in typeshed stubs).
11411
11291
  if (types.length === 1 && !allowSingleTypeArg && !(0, typeUtils_1.isNoneInstance)(types[0])) {
11412
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.unionTypeArgCount(), errorNode);
11292
+ if ((flags & 256 /* EvalFlags.TypeExpression */) !== 0) {
11293
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.unionTypeArgCount(), errorNode);
11294
+ }
11413
11295
  isValidTypeForm = false;
11414
11296
  }
11415
11297
  let unionType = (0, types_1.combineTypes)(types, { skipElideRedundantLiterals: true });
@@ -11462,9 +11344,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11462
11344
  }
11463
11345
  function transformTypeForTypeAlias(type, errorNode, typeAliasPlaceholder, isPep695TypeVarType, typeParamNodes) {
11464
11346
  var _a;
11465
- if (!types_1.TypeBase.isInstantiable(type)) {
11466
- return type;
11467
- }
11468
11347
  // If this is a recursive type alias that hasn't yet been fully resolved
11469
11348
  // (i.e. there is no boundType associated with it), don't apply the transform.
11470
11349
  if ((0, typeUtils_1.isTypeAliasPlaceholder)(type)) {
@@ -11526,6 +11405,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11526
11405
  }), errorNode);
11527
11406
  }
11528
11407
  }
11408
+ if (!types_1.TypeBase.isInstantiable(type)) {
11409
+ return type;
11410
+ }
11529
11411
  sharedInfo.typeParams = typeParams.length > 0 ? typeParams : undefined;
11530
11412
  let typeAlias = types_1.TypeBase.cloneForTypeAlias(type, {
11531
11413
  shared: sharedInfo,
@@ -11774,8 +11656,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11774
11656
  }
11775
11657
  }
11776
11658
  if (!rightHandType) {
11777
- // Determine whether there is a declared type.
11778
- const declaredType = getDeclaredTypeForExpression(node.d.leftExpr, { method: 'set' });
11779
11659
  let typeAliasNameNode;
11780
11660
  let typeAliasPlaceholder;
11781
11661
  let isSpeculativeTypeAlias = false;
@@ -11819,6 +11699,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11819
11699
  writeTypeCache(node.d.leftExpr.d.valueExpr, { type: typeAliasPlaceholder }, /* flags */ undefined);
11820
11700
  }
11821
11701
  }
11702
+ let declaredType = getDeclaredTypeForExpression(node.d.leftExpr, { method: 'set' });
11703
+ if (declaredType) {
11704
+ const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(node);
11705
+ declaredType = (0, typeUtils_1.makeTypeVarsBound)(declaredType, liveTypeVarScopes);
11706
+ }
11822
11707
  const srcTypeResult = getTypeOfExpression(node.d.rightExpr, flags, (0, typeUtils_1.makeInferenceContext)(declaredType));
11823
11708
  rightHandType = srcTypeResult.type;
11824
11709
  expectedTypeDiagAddendum = srcTypeResult.expectedTypeDiagAddendum;
@@ -13461,9 +13346,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13461
13346
  return type;
13462
13347
  }
13463
13348
  if ((0, types_1.isUnpackedClass)(type)) {
13464
- return types_1.ClassType.cloneForUnpacked(type, /* isUnpacked */ false);
13349
+ return types_1.ClassType.cloneForPacked(type);
13465
13350
  }
13466
- return makeTupleObject([{ type, isUnbounded: !(0, types_1.isTypeVarTuple)(type) }]);
13351
+ return (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type, isUnbounded: !(0, types_1.isTypeVarTuple)(type) }]);
13467
13352
  }
13468
13353
  case 2 /* ParamCategory.KwargsDict */: {
13469
13354
  // Leave a ParamSpec alone.
@@ -13493,7 +13378,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13493
13378
  awaitableFunctionType.shared.declaredReturnType = createAwaitableReturnType(node, functionType.shared.declaredReturnType, types_1.FunctionType.isGenerator(functionType));
13494
13379
  }
13495
13380
  else {
13496
- awaitableFunctionType.priv.inferredReturnType = createAwaitableReturnType(node, getFunctionInferredReturnType(functionType), types_1.FunctionType.isGenerator(functionType));
13381
+ awaitableFunctionType.priv.inferredReturnType = createAwaitableReturnType(node, getInferredReturnType(functionType), types_1.FunctionType.isGenerator(functionType));
13497
13382
  }
13498
13383
  return awaitableFunctionType;
13499
13384
  }
@@ -14883,39 +14768,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14883
14768
  // Handle ParamSpec arguments and fill in any missing type arguments with Unknown.
14884
14769
  let typeArgTypes = [];
14885
14770
  const fullTypeParams = types_1.ClassType.getTypeParams(classType);
14886
- // PEP 612 says that if the class has only one type parameter consisting
14887
- // of a ParamSpec, the list of arguments does not need to be enclosed in
14888
- // a list. We'll handle that case specially here.
14889
- if (fullTypeParams.length === 1 && (0, types_1.isParamSpec)(fullTypeParams[0]) && typeArgs) {
14890
- if (typeArgs.every((typeArg) => !(0, typeUtils_1.isEllipsisType)(typeArg.type) && !typeArg.typeList && !(0, types_1.isParamSpec)(typeArg.type))) {
14891
- if (typeArgs.length !== 1 ||
14892
- !(0, types_1.isInstantiableClass)(typeArgs[0].type) ||
14893
- !types_1.ClassType.isBuiltIn(typeArgs[0].type, 'Concatenate')) {
14894
- // Package up the type arguments into a typeList.
14895
- typeArgs =
14896
- typeArgs.length > 0
14897
- ? [
14898
- {
14899
- type: types_1.UnknownType.create(),
14900
- node: typeArgs[0].node,
14901
- typeList: typeArgs,
14902
- },
14903
- ]
14904
- : [];
14905
- }
14906
- }
14907
- else if (typeArgs.length > 1) {
14908
- const paramSpecTypeArg = typeArgs.find((typeArg) => (0, types_1.isParamSpec)(typeArg.type));
14909
- if (paramSpecTypeArg) {
14910
- isValidTypeForm = false;
14911
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.paramSpecContext(), paramSpecTypeArg.node);
14912
- }
14913
- const listTypeArg = typeArgs.find((typeArg) => !!typeArg.typeList);
14914
- if (listTypeArg) {
14915
- isValidTypeForm = false;
14916
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeArgListNotAllowed(), listTypeArg.node);
14917
- }
14918
- }
14771
+ typeArgs = transformTypeArgsForParamSpec(fullTypeParams, typeArgs, errorNode);
14772
+ if (!typeArgs) {
14773
+ isValidTypeForm = false;
14919
14774
  }
14920
14775
  const constraints = new constraintTracker_1.ConstraintTracker();
14921
14776
  fullTypeParams.forEach((typeParam, index) => {
@@ -15022,6 +14877,57 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15022
14877
  }
15023
14878
  return { type: specializedClass };
15024
14879
  }
14880
+ // PEP 612 says that if the class has only one type parameter consisting
14881
+ // of a ParamSpec, the list of arguments does not need to be enclosed in
14882
+ // a list. We'll handle that case specially here.
14883
+ function transformTypeArgsForParamSpec(typeParams, typeArgs, errorNode) {
14884
+ if (typeParams.length !== 1 || !(0, types_1.isParamSpec)(typeParams[0]) || !typeArgs) {
14885
+ return typeArgs;
14886
+ }
14887
+ if (typeArgs.length > 1) {
14888
+ for (const typeArg of typeArgs) {
14889
+ if ((0, types_1.isParamSpec)(typeArg.type)) {
14890
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.paramSpecContext(), typeArg.node);
14891
+ return undefined;
14892
+ }
14893
+ if ((0, typeUtils_1.isEllipsisType)(typeArg.type)) {
14894
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.ellipsisContext(), typeArg.node);
14895
+ return undefined;
14896
+ }
14897
+ if ((0, types_1.isInstantiableClass)(typeArg.type) && types_1.ClassType.isBuiltIn(typeArg.type, 'Concatenate')) {
14898
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.concatenateContext(), typeArg.node);
14899
+ return undefined;
14900
+ }
14901
+ if (typeArg.typeList) {
14902
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeArgListNotAllowed(), typeArg.node);
14903
+ return undefined;
14904
+ }
14905
+ }
14906
+ }
14907
+ if (typeArgs.length === 1) {
14908
+ // Don't transform a type list.
14909
+ if (typeArgs[0].typeList) {
14910
+ return typeArgs;
14911
+ }
14912
+ const typeArgType = typeArgs[0].type;
14913
+ // Don't transform a single ParamSpec or ellipsis.
14914
+ if ((0, types_1.isParamSpec)(typeArgType) || (0, typeUtils_1.isEllipsisType)(typeArgType)) {
14915
+ return typeArgs;
14916
+ }
14917
+ // Don't transform a Concatenate.
14918
+ if ((0, types_1.isInstantiableClass)(typeArgType) && types_1.ClassType.isBuiltIn(typeArgType, 'Concatenate')) {
14919
+ return typeArgs;
14920
+ }
14921
+ }
14922
+ // Package up the type arguments into a type list.
14923
+ return [
14924
+ {
14925
+ type: types_1.UnknownType.create(),
14926
+ node: typeArgs.length > 0 ? typeArgs[0].node : errorNode,
14927
+ typeList: typeArgs,
14928
+ },
14929
+ ];
14930
+ }
15025
14931
  function getTypeOfArg(arg, inferenceContext) {
15026
14932
  var _a, _b;
15027
14933
  if (arg.typeResult) {
@@ -15091,6 +14997,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15091
14997
  if (options === null || options === void 0 ? void 0 : options.convertEllipsisToAny) {
15092
14998
  flags |= 1 /* EvalFlags.ConvertEllipsisToAny */;
15093
14999
  }
15000
+ if (options === null || options === void 0 ? void 0 : options.allowEllipsis) {
15001
+ flags |= 65536 /* EvalFlags.AllowEllipsis */;
15002
+ }
15094
15003
  if (options === null || options === void 0 ? void 0 : options.noNonTypeSpecialForms) {
15095
15004
  flags |= 67108864 /* EvalFlags.NoNonTypeSpecialForms */;
15096
15005
  }
@@ -15528,7 +15437,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15528
15437
  if (paramDecl) {
15529
15438
  declarations.push(paramDecl);
15530
15439
  }
15531
- else if (types_1.ClassType.isDataClass(baseType) || types_1.ClassType.isTypedDictClass(baseType)) {
15440
+ else if (types_1.ClassType.isDataClass(baseType) ||
15441
+ types_1.ClassType.isTypedDictClass(baseType) ||
15442
+ types_1.ClassType.hasNamedTupleEntry(baseType, paramName)) {
15532
15443
  const lookupResults = (0, typeUtils_1.lookUpClassMember)(baseType, paramName);
15533
15444
  if (lookupResults) {
15534
15445
  (0, collectionUtils_1.appendArray)(declarations, lookupResults.symbol.getDeclarations());
@@ -15783,7 +15694,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15783
15694
  typeVar.shared.isDefaultExplicit = true;
15784
15695
  }
15785
15696
  else {
15786
- typeVar.shared.defaultType = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }]);
15697
+ typeVar.shared.defaultType = (0, tuples_1.makeTupleObject)(evaluatorInterface, [
15698
+ { type: types_1.UnknownType.create(), isUnbounded: true },
15699
+ ]);
15787
15700
  }
15788
15701
  }
15789
15702
  else {
@@ -15813,7 +15726,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15813
15726
  if (scopeNode.nodeType === 10 /* ParseNodeType.Class */) {
15814
15727
  scopeType = 0 /* TypeVarScopeType.Class */;
15815
15728
  // Set the variance to "auto" for class-scoped TypeVars.
15816
- typeVar.shared.declaredVariance = 0 /* Variance.Auto */;
15729
+ typeVar.shared.declaredVariance =
15730
+ (0, types_1.isParamSpec)(typeVar) || (0, types_1.isTypeVarTuple)(typeVar) ? 2 /* Variance.Invariant */ : 0 /* Variance.Auto */;
15817
15731
  }
15818
15732
  else if (scopeNode.nodeType === 31 /* ParseNodeType.Function */) {
15819
15733
  scopeType = 1 /* TypeVarScopeType.Function */;
@@ -15821,7 +15735,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15821
15735
  else {
15822
15736
  (0, debug_1.assert)(scopeNode.nodeType === 77 /* ParseNodeType.TypeAlias */);
15823
15737
  scopeType = 2 /* TypeVarScopeType.TypeAlias */;
15824
- typeVar.shared.declaredVariance = 0 /* Variance.Auto */;
15738
+ typeVar.shared.declaredVariance =
15739
+ (0, types_1.isParamSpec)(typeVar) || (0, types_1.isTypeVarTuple)(typeVar) ? 2 /* Variance.Invariant */ : 0 /* Variance.Auto */;
15825
15740
  }
15826
15741
  typeVar = types_1.TypeVarType.cloneForScopeId(typeVar, ParseTreeUtils.getScopeIdForNode(scopeNode.nodeType === 77 /* ParseNodeType.TypeAlias */ ? scopeNode.d.name : scopeNode), scopeNode.d.name.d.value, scopeType);
15827
15742
  }
@@ -16426,7 +16341,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16426
16341
  return specializedReturnType;
16427
16342
  }
16428
16343
  if (!(options === null || options === void 0 ? void 0 : options.skipInferReturnType)) {
16429
- return getFunctionInferredReturnType(type, options === null || options === void 0 ? void 0 : options.callSiteInfo);
16344
+ return getInferredReturnType(type, options === null || options === void 0 ? void 0 : options.callSiteInfo);
16430
16345
  }
16431
16346
  return types_1.UnknownType.create();
16432
16347
  }
@@ -17043,7 +16958,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17043
16958
  const typeParam = destType.shared.typeParams[i];
17044
16959
  const variance = types_1.TypeVarType.getVariance(typeParam);
17045
16960
  if (curSrcType.priv.tupleTypeArgs) {
17046
- typeArgType = (0, typeUtils_1.convertToInstance)(makeTupleObject(curSrcType.priv.tupleTypeArgs, /* isUnpacked */ true));
16961
+ typeArgType = (0, typeUtils_1.convertToInstance)((0, tuples_1.makeTupleObject)(evaluatorInterface, curSrcType.priv.tupleTypeArgs, /* isUnpacked */ true));
17047
16962
  }
17048
16963
  else {
17049
16964
  typeArgType = i < srcTypeArgs.length ? srcTypeArgs[i] : types_1.UnknownType.create();
@@ -17509,6 +17424,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17509
17424
  }
17510
17425
  let concreteSrcType = makeTopLevelTypeVarsConcrete(srcType);
17511
17426
  if ((0, types_1.isClass)(concreteSrcType) && types_1.TypeBase.isInstance(concreteSrcType)) {
17427
+ // Handle the case where the source is an unpacked tuple.
17428
+ if (!destType.priv.isUnpacked &&
17429
+ concreteSrcType.priv.isUnpacked &&
17430
+ concreteSrcType.priv.tupleTypeArgs) {
17431
+ return assignType(destType, (0, typeUtils_1.combineTupleTypeArgs)(concreteSrcType.priv.tupleTypeArgs), diag, constraints, flags, recursionCount);
17432
+ }
17512
17433
  // Handle enum literals that are assignable to another (non-Enum) literal.
17513
17434
  // This can happen for IntEnum and StrEnum members.
17514
17435
  if (types_1.ClassType.isEnumClass(concreteSrcType) &&
@@ -18360,7 +18281,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18360
18281
  }
18361
18282
  });
18362
18283
  if (srcTupleTypes.length !== 1 || !(0, types_1.isTypeVarTuple)(srcTupleTypes[0].type)) {
18363
- const srcPositionalsType = makeTupleObject(srcTupleTypes, /* isUnpacked */ true);
18284
+ const srcPositionalsType = (0, tuples_1.makeTupleObject)(evaluatorInterface, srcTupleTypes, /* isUnpacked */ true);
18364
18285
  // Snip out the portion of the source positionals that map to the variadic
18365
18286
  // dest parameter and replace it with a single parameter that is typed as a
18366
18287
  // tuple containing the individual types of the replaced parameters.
@@ -18427,11 +18348,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18427
18348
  const destParamName = (_c = destParam.param.name) !== null && _c !== void 0 ? _c : '';
18428
18349
  const srcParamName = (_d = srcParam.param.name) !== null && _d !== void 0 ? _d : '';
18429
18350
  if (destParamName) {
18430
- const isDestPositionalOnly = destParam.kind === parameterUtils_1.ParamKind.Positional;
18351
+ const isDestPositionalOnly = destParam.kind === parameterUtils_1.ParamKind.Positional || destParam.kind === parameterUtils_1.ParamKind.ExpandedArgs;
18431
18352
  if (!isDestPositionalOnly &&
18432
18353
  destParam.param.category !== 1 /* ParamCategory.ArgsList */ &&
18433
18354
  srcParam.param.category !== 1 /* ParamCategory.ArgsList */) {
18434
- if (srcParam.kind === parameterUtils_1.ParamKind.Positional) {
18355
+ if (srcParam.kind === parameterUtils_1.ParamKind.Positional || srcParam.kind === parameterUtils_1.ParamKind.ExpandedArgs) {
18435
18356
  diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.LocAddendum.functionParamPositionOnly().format({
18436
18357
  name: destParamName,
18437
18358
  }));
@@ -18616,10 +18537,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18616
18537
  let destArgsType = destParamDetails.params[destParamDetails.argsIndex].type;
18617
18538
  let srcArgsType = srcParamDetails.params[srcParamDetails.argsIndex].type;
18618
18539
  if (!(0, types_1.isUnpacked)(destArgsType)) {
18619
- destArgsType = makeTupleObject([{ type: destArgsType, isUnbounded: true }], /* isUnpacked */ true);
18540
+ destArgsType = (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type: destArgsType, isUnbounded: true }],
18541
+ /* isUnpacked */ true);
18620
18542
  }
18621
18543
  if (!(0, types_1.isUnpacked)(srcArgsType)) {
18622
- srcArgsType = makeTupleObject([{ type: srcArgsType, isUnbounded: true }], /* isUnpacked */ true);
18544
+ srcArgsType = (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type: srcArgsType, isUnbounded: true }],
18545
+ /* isUnpacked */ true);
18623
18546
  }
18624
18547
  if (!assignParam(destArgsType, srcArgsType, destParamDetails.params[destParamDetails.argsIndex].index, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints, flags, recursionCount)) {
18625
18548
  canAssign = false;
@@ -18973,7 +18896,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18973
18896
  }
18974
18897
  return assignedSubtype;
18975
18898
  }
18976
- if (!(0, types_1.isTypeVar)(declaredSubtype) && (0, types_1.isTypeVar)(assignedSubtype)) {
18899
+ if (!(0, types_1.isTypeVar)(declaredSubtype) &&
18900
+ (0, types_1.isTypeVar)(assignedSubtype) &&
18901
+ !types_1.TypeVarType.isBound(assignedSubtype)) {
18977
18902
  // If the source is an unsolved TypeVar but the declared type is concrete,
18978
18903
  // use the concrete type.
18979
18904
  return declaredSubtype;
@@ -19868,7 +19793,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19868
19793
  return codeFlowEngine.printControlFlowGraph(flowNode, reference, callName, logger);
19869
19794
  }
19870
19795
  // Track these apis internal usages when logging is on. otherwise, it should be noop.
19871
- const getFunctionInferredReturnType = wrapWithLogger(_getInferredReturnType);
19796
+ const getInferredReturnType = wrapWithLogger(_getInferredReturnType);
19872
19797
  const evaluatorInterface = {
19873
19798
  runWithCancellationToken,
19874
19799
  getType,
@@ -19886,7 +19811,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19886
19811
  evaluateTypesForStatement,
19887
19812
  evaluateTypesForMatchStatement,
19888
19813
  evaluateTypesForCaseStatement,
19889
- evaluateTypeOfParam: evaluateTypeOfParam,
19814
+ evaluateTypeOfParam,
19890
19815
  canBeTruthy,
19891
19816
  canBeFalsy,
19892
19817
  stripLiteralValue,
@@ -19913,7 +19838,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19913
19838
  getTypeOfIterable,
19914
19839
  getTypeOfIterator,
19915
19840
  getGetterTypeFromProperty,
19916
- getTypeOfArg: getTypeOfArg,
19841
+ getTypeOfArg,
19842
+ convertNodeToArg,
19843
+ buildTupleTypesList,
19917
19844
  markNamesAccessed,
19918
19845
  expandPromotionTypes,
19919
19846
  makeTopLevelTypeVarsConcrete,
@@ -19925,8 +19852,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19925
19852
  getEffectiveTypeOfSymbolForUsage,
19926
19853
  getInferredTypeOfDeclaration,
19927
19854
  getDeclaredTypeForExpression,
19928
- getFunctionDeclaredReturnType: getDeclaredReturnType,
19929
- getFunctionInferredReturnType,
19855
+ getDeclaredReturnType,
19856
+ getInferredReturnType,
19930
19857
  getBestOverloadForArgs,
19931
19858
  getBuiltInType,
19932
19859
  getTypeOfMember,