@zzzen/pyright-internal 1.2.0-dev.20231224 → 1.2.0-dev.20240107

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 (71) hide show
  1. package/dist/analyzer/binder.js +13 -6
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.d.ts +3 -0
  4. package/dist/analyzer/checker.js +167 -42
  5. package/dist/analyzer/checker.js.map +1 -1
  6. package/dist/analyzer/codeFlowEngine.js +7 -4
  7. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  8. package/dist/analyzer/constraintSolver.js +21 -17
  9. package/dist/analyzer/constraintSolver.js.map +1 -1
  10. package/dist/analyzer/dataClasses.js +2 -9
  11. package/dist/analyzer/dataClasses.js.map +1 -1
  12. package/dist/analyzer/enums.js +1 -1
  13. package/dist/analyzer/enums.js.map +1 -1
  14. package/dist/analyzer/namedTuples.js +14 -6
  15. package/dist/analyzer/namedTuples.js.map +1 -1
  16. package/dist/analyzer/protocols.d.ts +2 -0
  17. package/dist/analyzer/protocols.js +75 -6
  18. package/dist/analyzer/protocols.js.map +1 -1
  19. package/dist/analyzer/scopeUtils.d.ts +1 -0
  20. package/dist/analyzer/scopeUtils.js +12 -1
  21. package/dist/analyzer/scopeUtils.js.map +1 -1
  22. package/dist/analyzer/typeEvaluator.js +339 -219
  23. package/dist/analyzer/typeEvaluator.js.map +1 -1
  24. package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -1
  25. package/dist/analyzer/typeEvaluatorTypes.js +2 -0
  26. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  27. package/dist/analyzer/typeGuards.js +10 -6
  28. package/dist/analyzer/typeGuards.js.map +1 -1
  29. package/dist/analyzer/typePrinter.js +4 -2
  30. package/dist/analyzer/typePrinter.js.map +1 -1
  31. package/dist/analyzer/typeUtils.d.ts +10 -9
  32. package/dist/analyzer/typeUtils.js +20 -14
  33. package/dist/analyzer/typeUtils.js.map +1 -1
  34. package/dist/analyzer/typedDicts.js +24 -36
  35. package/dist/analyzer/typedDicts.js.map +1 -1
  36. package/dist/analyzer/types.d.ts +8 -2
  37. package/dist/analyzer/types.js +58 -8
  38. package/dist/analyzer/types.js.map +1 -1
  39. package/dist/backgroundAnalysisBase.js +4 -3
  40. package/dist/backgroundAnalysisBase.js.map +1 -1
  41. package/dist/backgroundThreadBase.d.ts +1 -0
  42. package/dist/backgroundThreadBase.js +8 -1
  43. package/dist/backgroundThreadBase.js.map +1 -1
  44. package/dist/common/diagnostic.d.ts +1 -0
  45. package/dist/common/diagnostic.js +18 -1
  46. package/dist/common/diagnostic.js.map +1 -1
  47. package/dist/common/realFileSystem.js +44 -12
  48. package/dist/common/realFileSystem.js.map +1 -1
  49. package/dist/localization/localize.d.ts +45 -0
  50. package/dist/localization/localize.js +22 -0
  51. package/dist/localization/localize.js.map +1 -1
  52. package/dist/localization/package.nls.en-us.json +24 -2
  53. package/dist/parser/parser.js +1 -1
  54. package/dist/parser/parser.js.map +1 -1
  55. package/dist/pyright.js +6 -3
  56. package/dist/pyright.js.map +1 -1
  57. package/dist/tests/localizer.test.js +1 -1
  58. package/dist/tests/localizer.test.js.map +1 -1
  59. package/dist/tests/typeEvaluator1.test.js +2 -2
  60. package/dist/tests/typeEvaluator2.test.js +22 -10
  61. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  62. package/dist/tests/typeEvaluator3.test.js +3 -3
  63. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  64. package/dist/tests/typeEvaluator4.test.js +7 -3
  65. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  66. package/dist/tests/typeEvaluator5.test.js +1 -1
  67. package/dist/tests/typePrinter.test.js +2 -10
  68. package/dist/tests/typePrinter.test.js.map +1 -1
  69. package/dist/tests/uri.test.js +7 -0
  70. package/dist/tests/uri.test.js.map +1 -1
  71. package/package.json +1 -1
@@ -706,7 +706,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
706
706
  // Make sure the resulting type is assignable to the expected type.
707
707
  if (!assignType(inferenceContext.expectedType, typeResult.type, diag,
708
708
  /* destTypeVarContext */ undefined,
709
- /* srcTypeVarContext */ undefined, 512 /* AssignTypeFlags.IgnoreTypeVarScope */)) {
709
+ /* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */)) {
710
710
  typeResult.typeErrors = true;
711
711
  typeResult.expectedTypeDiagAddendum = diag;
712
712
  diag.addTextRange(node);
@@ -1398,15 +1398,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1398
1398
  }
1399
1399
  return undefined;
1400
1400
  }
1401
- function getBoundMagicMethod(classType, memberName, selfType, recursionCount = 0) {
1401
+ function getBoundMagicMethod(classType, memberName, selfType, diag, recursionCount = 0) {
1402
1402
  if (recursionCount > types_1.maxTypeRecursionCount) {
1403
1403
  return undefined;
1404
1404
  }
1405
1405
  recursionCount++;
1406
1406
  const boundMethodResult = getTypeOfBoundMember(
1407
1407
  /* errorNode */ undefined, classType, memberName,
1408
- /* usage */ undefined,
1409
- /* diag */ undefined, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */, selfType, recursionCount);
1408
+ /* usage */ undefined, diag, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */, selfType, recursionCount);
1410
1409
  if (!boundMethodResult || boundMethodResult.typeErrors) {
1411
1410
  return undefined;
1412
1411
  }
@@ -1414,7 +1413,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1414
1413
  return boundMethodResult.type;
1415
1414
  }
1416
1415
  if ((0, types_1.isClassInstance)(boundMethodResult.type)) {
1417
- return getBoundMagicMethod(boundMethodResult.type, '__call__', selfType !== null && selfType !== void 0 ? selfType : types_1.ClassType.cloneAsInstance(classType), recursionCount);
1416
+ return getBoundMagicMethod(boundMethodResult.type, '__call__', selfType !== null && selfType !== void 0 ? selfType : types_1.ClassType.cloneAsInstance(classType), diag, recursionCount);
1418
1417
  }
1419
1418
  if ((0, types_1.isAnyOrUnknown)(boundMethodResult.type)) {
1420
1419
  return (0, typeUtils_1.getUnknownTypeForCallable)();
@@ -1574,10 +1573,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1574
1573
  const kwSeparatorIndex = functionType.details.parameters.findIndex((param) => param.category === 1 /* ParameterCategory.ArgsList */);
1575
1574
  // Add a keyword separator if necessary.
1576
1575
  if (kwSeparatorIndex < 0) {
1577
- types_1.FunctionType.addParameter(newFunction, {
1578
- category: 1 /* ParameterCategory.ArgsList */,
1579
- type: types_1.AnyType.create(),
1580
- });
1576
+ types_1.FunctionType.addKeywordOnlyParameterSeparator(newFunction);
1581
1577
  }
1582
1578
  tdEntries.forEach((tdEntry, name) => {
1583
1579
  types_1.FunctionType.addParameter(newFunction, {
@@ -1738,6 +1734,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1738
1734
  specializedType.typeArguments.length > 0) {
1739
1735
  return specializedType.typeArguments[0];
1740
1736
  }
1737
+ return types_1.UnknownType.create();
1741
1738
  }
1742
1739
  }
1743
1740
  if (errorNode) {
@@ -2970,9 +2967,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2970
2967
  // Verify that the name does not refer to a (non type alias) variable.
2971
2968
  if (effectiveTypeInfo.includesVariableDecl && !type.typeAliasInfo) {
2972
2969
  let isAllowedTypeForVariable = (0, types_1.isTypeVar)(type) || (0, typeUtils_1.isTypeAliasPlaceholder)(type);
2973
- if ((0, types_1.isClass)(type) && !type.includeSubclasses && !symbol.hasTypedDeclarations()) {
2970
+ if ((0, types_1.isClass)(type) &&
2971
+ !type.includeSubclasses &&
2972
+ !symbol.hasTypedDeclarations() &&
2973
+ types_1.ClassType.isValidTypeAliasClass(type)) {
2974
2974
  // This check exempts class types that are created by calling
2975
- // NewType, NamedTuple, and by invoking a metaclass directly.
2975
+ // NewType, NamedTuple, etc.
2976
2976
  isAllowedTypeForVariable = true;
2977
2977
  }
2978
2978
  // Disable for assignments in the typings.pyi file, since it defines special forms.
@@ -4383,6 +4383,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4383
4383
  }
4384
4384
  return indexTypeResult;
4385
4385
  }
4386
+ // If the list of type parameters includes a TypeVarTuple, we may need to adjust
4387
+ // the supplied type arguments to map to the type parameter list.
4386
4388
  function adjustTypeArgumentsForVariadicTypeVar(typeArgs, typeParameters, errorNode) {
4387
4389
  const variadicIndex = typeParameters.findIndex((param) => (0, types_1.isVariadicTypeVar)(param));
4388
4390
  // Do we need to adjust the type arguments to map to a variadic type
@@ -4485,26 +4487,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4485
4487
  ];
4486
4488
  }
4487
4489
  }
4488
- if (!typeParameters.some((typeVar) => typeVar.details.isVariadic && !typeVar.isVariadicInUnion)) {
4489
- let minTypeArgCount = typeParameters.length;
4490
- const firstNonDefaultParam = typeParameters.findIndex((param) => !!param.details.defaultType);
4491
- if (firstNonDefaultParam >= 0) {
4492
- minTypeArgCount = firstNonDefaultParam;
4493
- }
4494
- if (typeArgs.length > typeParameters.length) {
4495
- addError(localize_1.Localizer.Diagnostic.typeArgsTooMany().format({
4496
- name: printType(baseType),
4497
- expected: typeParameters.length,
4498
- received: typeArgs.length,
4499
- }), typeArgs[typeParameters.length].node);
4500
- }
4501
- else if (typeArgs.length < minTypeArgCount) {
4502
- addError(localize_1.Localizer.Diagnostic.typeArgsTooFew().format({
4503
- name: printType(baseType),
4504
- expected: typeParameters.length,
4505
- received: typeArgs.length,
4506
- }), node.items[node.items.length - 1]);
4507
- }
4490
+ let minTypeArgCount = typeParameters.length;
4491
+ const firstDefaultParamIndex = typeParameters.findIndex((param) => !!param.details.defaultType);
4492
+ if (firstDefaultParamIndex >= 0) {
4493
+ minTypeArgCount = firstDefaultParamIndex;
4494
+ }
4495
+ if (typeArgs.length > typeParameters.length) {
4496
+ addError(localize_1.Localizer.Diagnostic.typeArgsTooMany().format({
4497
+ name: printType(baseType),
4498
+ expected: typeParameters.length,
4499
+ received: typeArgs.length,
4500
+ }), typeArgs[typeParameters.length].node);
4501
+ }
4502
+ else if (typeArgs.length < minTypeArgCount) {
4503
+ addError(localize_1.Localizer.Diagnostic.typeArgsTooFew().format({
4504
+ name: printType(baseType),
4505
+ expected: typeParameters.length,
4506
+ received: typeArgs.length,
4507
+ }), node.items[node.items.length - 1]);
4508
4508
  }
4509
4509
  // Handle the mypy_extensions.FlexibleAlias type specially.
4510
4510
  if ((0, types_1.isInstantiableClass)(baseType) &&
@@ -4520,7 +4520,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4520
4520
  const typeList = typeArgs[index].typeList;
4521
4521
  if (typeList) {
4522
4522
  const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
4523
- types_1.TypeBase.setSpecialForm(functionType);
4524
4523
  typeList.forEach((paramType, paramIndex) => {
4525
4524
  types_1.FunctionType.addParameter(functionType, {
4526
4525
  category: 0 /* ParameterCategory.Simple */,
@@ -4530,10 +4529,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4530
4529
  hasDeclaredType: true,
4531
4530
  });
4532
4531
  });
4533
- (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext, 128 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4532
+ if (typeList.length > 0) {
4533
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
4534
+ }
4535
+ (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4534
4536
  }
4535
4537
  else if ((0, types_1.isParamSpec)(typeArgType)) {
4536
- (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, (0, typeUtils_1.convertToInstance)(typeArgType), diag, typeVarContext, 128 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4538
+ (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, (0, typeUtils_1.convertToInstance)(typeArgType), diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4537
4539
  }
4538
4540
  else if ((0, types_1.isInstantiableClass)(typeArgType) && types_1.ClassType.isBuiltIn(typeArgType, 'Concatenate')) {
4539
4541
  const concatTypeArgs = typeArgType.typeArguments;
@@ -4541,12 +4543,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4541
4543
  if (concatTypeArgs && concatTypeArgs.length > 0) {
4542
4544
  concatTypeArgs.forEach((typeArg, index) => {
4543
4545
  if (index === concatTypeArgs.length - 1) {
4544
- // Add a position-only separator
4545
- types_1.FunctionType.addParameter(functionType, {
4546
- category: 0 /* ParameterCategory.Simple */,
4547
- isNameSynthesized: false,
4548
- type: types_1.UnknownType.create(),
4549
- });
4546
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
4550
4547
  if ((0, types_1.isParamSpec)(typeArg)) {
4551
4548
  functionType.details.paramSpec = typeArg;
4552
4549
  }
@@ -4566,11 +4563,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4566
4563
  }
4567
4564
  });
4568
4565
  }
4569
- (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext, 128 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4566
+ (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4570
4567
  }
4571
4568
  else if ((0, typeUtils_1.isEllipsisType)(typeArgType)) {
4572
4569
  const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */);
4573
- types_1.TypeBase.setSpecialForm(functionType);
4574
4570
  types_1.FunctionType.addDefaultParameters(functionType);
4575
4571
  (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext);
4576
4572
  }
@@ -4606,7 +4602,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4606
4602
  }
4607
4603
  }
4608
4604
  }
4609
- (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, typeArgType, diag, typeVarContext, 128 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4605
+ if ((0, types_1.isUnpacked)(typeArgType) && !(0, types_1.isVariadicTypeVar)(param)) {
4606
+ const messageDiag = diag.createAddendum();
4607
+ messageDiag.addMessage(localize_1.Localizer.Diagnostic.unpackedArgInTypeArgument());
4608
+ messageDiag.addTextRange(typeArgs[index].node);
4609
+ typeArgType = types_1.UnknownType.create();
4610
+ }
4611
+ (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, typeArgType, diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
4610
4612
  }
4611
4613
  });
4612
4614
  if (!diag.isEmpty()) {
@@ -4921,7 +4923,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4921
4923
  }), node.baseExpression);
4922
4924
  return { type: types_1.UnknownType.create() };
4923
4925
  }
4924
- // Handle the special case where the object is a Tuple and
4926
+ // Handle the special case where the object is a tuple and
4925
4927
  // the index is a constant number (integer) or a slice with integer
4926
4928
  // start and end values. In these cases, we can determine
4927
4929
  // the exact type by indexing into the tuple type array.
@@ -4954,39 +4956,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4954
4956
  }
4955
4957
  else if ((0, types_1.isClassInstance)(valueType) && types_1.ClassType.isBuiltIn(valueType, 'slice')) {
4956
4958
  const tupleType = (0, typeUtils_1.getSpecializedTupleType)(baseType);
4957
- if (tupleType && tupleType.tupleTypeArguments && !(0, typeUtils_1.isUnboundedTupleClass)(tupleType)) {
4958
- if (index0Expr.nodeType === 46 /* ParseNodeType.Slice */ && !index0Expr.stepValue) {
4959
- // Create a local helper function to evaluate the slice parameters.
4960
- const getSliceParameter = (expression, defaultValue) => {
4961
- let value = defaultValue;
4962
- if (expression) {
4963
- const valType = getTypeOfExpression(expression).type;
4964
- if ((0, types_1.isClassInstance)(valType) &&
4965
- types_1.ClassType.isBuiltIn(valType, 'int') &&
4966
- (0, typeUtils_1.isLiteralType)(valType) &&
4967
- typeof valType.literalValue === 'number') {
4968
- value = valType.literalValue;
4969
- if (value < 0) {
4970
- value = tupleType.tupleTypeArguments.length + value;
4971
- }
4972
- }
4973
- else {
4974
- value = -1;
4975
- }
4976
- }
4977
- return value;
4978
- };
4979
- const startValue = getSliceParameter(index0Expr.startValue, 0);
4980
- const endValue = getSliceParameter(index0Expr.endValue, tupleType.tupleTypeArguments.length);
4981
- if (startValue >= 0 &&
4982
- endValue > 0 &&
4983
- endValue <= tupleType.tupleTypeArguments.length &&
4984
- tupleClassType &&
4985
- (0, types_1.isInstantiableClass)(tupleClassType)) {
4986
- return {
4987
- type: types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, tupleType.tupleTypeArguments.slice(startValue, endValue))),
4988
- };
4989
- }
4959
+ if (tupleType && index0Expr.nodeType === 46 /* ParseNodeType.Slice */) {
4960
+ const slicedTupleType = getSlicedTupleType(tupleType, index0Expr);
4961
+ if (slicedTupleType) {
4962
+ return { type: slicedTupleType };
4990
4963
  }
4991
4964
  }
4992
4965
  }
@@ -5106,6 +5079,51 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5106
5079
  isIncomplete: !!callResult.isTypeIncomplete,
5107
5080
  };
5108
5081
  }
5082
+ // Given a tuple type and a slice expression, determines the resulting
5083
+ // type if it can be determined. If not, it returns undefined.
5084
+ function getSlicedTupleType(tupleType, sliceNode) {
5085
+ // We don't handle step values.
5086
+ if (sliceNode.stepValue || !tupleType.tupleTypeArguments) {
5087
+ return undefined;
5088
+ }
5089
+ const tupleTypeArgs = tupleType.tupleTypeArguments;
5090
+ const startValue = getTupleSliceParameter(sliceNode.startValue, 0, tupleTypeArgs);
5091
+ const endValue = getTupleSliceParameter(sliceNode.endValue, tupleTypeArgs.length, tupleTypeArgs);
5092
+ if (startValue === undefined || endValue === undefined || endValue < startValue) {
5093
+ return undefined;
5094
+ }
5095
+ const slicedTypeArgs = tupleTypeArgs.slice(startValue, endValue);
5096
+ return types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleType, slicedTypeArgs));
5097
+ }
5098
+ function getTupleSliceParameter(expression, defaultValue, tupleTypeArgs) {
5099
+ let value = defaultValue;
5100
+ if (expression) {
5101
+ const valType = getTypeOfExpression(expression).type;
5102
+ if (!(0, types_1.isClassInstance)(valType) || !types_1.ClassType.isBuiltIn(valType, 'int') || !(0, typeUtils_1.isLiteralType)(valType)) {
5103
+ return undefined;
5104
+ }
5105
+ value = valType.literalValue;
5106
+ const unboundedIndex = tupleTypeArgs.findIndex((typeArg) => typeArg.isUnbounded || (0, types_1.isVariadicTypeVar)(typeArg.type));
5107
+ if (value < 0) {
5108
+ value = tupleTypeArgs.length + value;
5109
+ if (value < 0) {
5110
+ return undefined;
5111
+ }
5112
+ else if (unboundedIndex >= 0 && value <= unboundedIndex) {
5113
+ return undefined;
5114
+ }
5115
+ }
5116
+ else {
5117
+ if (value >= tupleTypeArgs.length) {
5118
+ return undefined;
5119
+ }
5120
+ else if (unboundedIndex >= 0 && value > unboundedIndex) {
5121
+ return undefined;
5122
+ }
5123
+ }
5124
+ }
5125
+ return value;
5126
+ }
5109
5127
  function getTypeArgs(node, flags, options) {
5110
5128
  const typeArgs = [];
5111
5129
  let adjFlags = flags;
@@ -5121,7 +5139,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5121
5139
  if (!(options === null || options === void 0 ? void 0 : options.isAnnotatedClass)) {
5122
5140
  adjFlags |= 131072 /* EvaluatorFlags.DisallowClassVar */ | 16 /* EvaluatorFlags.DisallowFinal */;
5123
5141
  }
5124
- adjFlags |= 2097152 /* EvaluatorFlags.AllowUnpackedTupleOrTypeVarTuple */;
5142
+ adjFlags |= 2097152 /* EvaluatorFlags.AllowUnpackedTupleOrTypeVarTuple */ | 134217728 /* EvaluatorFlags.AllowConcatenate */;
5125
5143
  }
5126
5144
  // Create a local function that validates a single type argument.
5127
5145
  const getTypeArgTypeResult = (expr, argIndex) => {
@@ -5185,6 +5203,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5185
5203
  (0, typeUtils_1.isTupleClass)(typeResult.type)) {
5186
5204
  typeResult.type = types_1.ClassType.cloneForUnpacked(typeResult.type);
5187
5205
  }
5206
+ else {
5207
+ addError(localize_1.Localizer.Diagnostic.unpackNotAllowed(), arg.valueExpression);
5208
+ }
5188
5209
  }
5189
5210
  }
5190
5211
  if (arg.name) {
@@ -5251,6 +5272,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5251
5272
  const diag = new diagnostic_1.DiagnosticAddendum();
5252
5273
  diag.addMessage(localize_1.Localizer.DiagnosticAddendum.useTupleInstead());
5253
5274
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.tupleInAnnotation() + diag.getString(), node);
5275
+ return { type: types_1.UnknownType.create() };
5254
5276
  }
5255
5277
  if ((flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) !== 0 &&
5256
5278
  node.expressions.length === 0 &&
@@ -5552,11 +5574,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5552
5574
  if (lambdaParams.length > 0) {
5553
5575
  const lastParam = lambdaParams[lambdaParams.length - 1];
5554
5576
  if (lastParam.category === 0 /* ParameterCategory.Simple */ && !lastParam.name) {
5555
- types_1.FunctionType.addParameter(expectedType, {
5556
- category: 0 /* ParameterCategory.Simple */,
5557
- name: '',
5558
- type: types_1.UnknownType.create(),
5559
- });
5577
+ types_1.FunctionType.addPositionOnlyParameterSeparator(expectedType);
5560
5578
  }
5561
5579
  }
5562
5580
  function getLambdaType() {
@@ -5843,9 +5861,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5843
5861
  resultType = types_1.UnknownType.create();
5844
5862
  }
5845
5863
  return {
5846
- type: resultIsInstance ? (0, typeUtils_1.convertToInstance)(resultType) : resultType,
5864
+ type: resultIsInstance ? (0, typeUtils_1.convertToInstance)(resultType, /* includeSubclasses */ false) : resultType,
5847
5865
  bindToSelfType: bindToType
5848
- ? types_1.TypeBase.cloneForCondition((0, typeUtils_1.synthesizeTypeVarForSelfCls)(bindToType, /* isClsParam */ false), bindToType.condition)
5866
+ ? types_1.TypeBase.cloneForCondition((0, typeUtils_1.synthesizeTypeVarForSelfCls)(types_1.ClassType.cloneIncludeSubclasses(bindToType, /* includeSubclasses */ false),
5867
+ /* isClsParam */ false), bindToType.condition)
5849
5868
  : undefined,
5850
5869
  };
5851
5870
  }
@@ -6437,18 +6456,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6437
6456
  }), errorNode);
6438
6457
  return { returnType: undefined, argumentErrors: true };
6439
6458
  }
6440
- // Check for an attempt to invoke an abstract static or class method.
6441
- if (expandedCallType.boundToType &&
6442
- (0, types_1.isInstantiableClass)(expandedCallType.boundToType) &&
6443
- !expandedCallType.boundToType.includeSubclasses) {
6444
- if (types_1.FunctionType.isAbstractMethod(expandedCallType)) {
6445
- if (types_1.FunctionType.isStaticMethod(expandedCallType) || types_1.FunctionType.isClassMethod(expandedCallType)) {
6446
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.abstractMethodInvocation().format({
6447
- method: expandedCallType.details.name,
6448
- }), errorNode.nodeType === 9 /* ParseNodeType.Call */ ? errorNode.leftExpression : errorNode);
6449
- }
6450
- }
6451
- }
6452
6459
  let effectiveTypeVarContext = typeVarContext;
6453
6460
  if (!effectiveTypeVarContext) {
6454
6461
  // If a typeVarContext wasn't provided by the caller, allocate one here.
@@ -6501,6 +6508,41 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6501
6508
  specializedInitSelfType: functionResult.specializedInitSelfType,
6502
6509
  };
6503
6510
  }
6511
+ function isMethodUnimplementedAbstract(functionType) {
6512
+ let isAbstract = false;
6513
+ // If the function is part of a protocol, it's automatically considered abstract
6514
+ // unless it's located in a stub, in which case it must be explicitly marked as
6515
+ // abstract.
6516
+ if (types_1.FunctionType.isAbstractMethod(functionType)) {
6517
+ isAbstract = true;
6518
+ }
6519
+ else if (functionType.details.methodClass &&
6520
+ types_1.ClassType.isProtocolClass(functionType.details.methodClass) &&
6521
+ functionType.details.declaration &&
6522
+ !AnalyzerNodeInfo.getFileInfo(functionType.details.declaration.node).isStubFile) {
6523
+ isAbstract = true;
6524
+ }
6525
+ if (!isAbstract) {
6526
+ return false;
6527
+ }
6528
+ // Determine if the method is unimplemented by looking at whether its
6529
+ // body contains a "trivial" implementation.
6530
+ let implementation = functionType;
6531
+ // If this is an overloaded method, consider the implementation.
6532
+ if (functionType.overloaded) {
6533
+ implementation = types_1.OverloadedFunctionType.getImplementation(functionType.overloaded);
6534
+ // If there is no implementation and it's in a stub file, assume it's not abstract.
6535
+ if (!implementation) {
6536
+ return (functionType.details.declaration !== undefined &&
6537
+ !AnalyzerNodeInfo.getFileInfo(functionType.details.declaration.node).isStubFile);
6538
+ }
6539
+ }
6540
+ if (!implementation.details.declaration) {
6541
+ return false;
6542
+ }
6543
+ const decl = implementation.details.declaration;
6544
+ return ParseTreeUtils.isSuiteEmpty(decl.node.suite) || methodAlwaysRaisesNotImplemented(decl);
6545
+ }
6504
6546
  function validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext) {
6505
6547
  var _a, _b;
6506
6548
  // Handle the 'cast' call as a special case.
@@ -6542,8 +6584,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6542
6584
  }
6543
6585
  if (types_1.ClassType.isBuiltIn(expandedCallType)) {
6544
6586
  const className = (_a = expandedCallType.aliasName) !== null && _a !== void 0 ? _a : expandedCallType.details.name;
6545
- // Handle the 'type' call specially.
6546
- if (expandedCallType.details.name === 'type') {
6587
+ // Handle a call to a metaclass explicitly.
6588
+ if ((0, typeUtils_1.isInstantiableMetaclass)(expandedCallType)) {
6547
6589
  if (expandedCallType.typeArguments && expandedCallType.isTypeArgumentExplicit) {
6548
6590
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.objectNotCallable().format({
6549
6591
  type: printType(expandedCallType),
@@ -6552,9 +6594,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6552
6594
  }
6553
6595
  // Validate the constructor arguments.
6554
6596
  (0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedCallType, skipUnknownArgCheck, inferenceContext);
6555
- if (argList.length === 1) {
6556
- // The one-parameter form of "type" returns the class
6557
- // for the specified object.
6597
+ // The one-parameter form of "type" returns the class
6598
+ // for the specified object.
6599
+ if (expandedCallType.details.name === 'type' && argList.length === 1) {
6558
6600
  const argType = getTypeOfArgument(argList[0]).type;
6559
6601
  const returnType = (0, typeUtils_1.mapSubtypes)(argType, (subtype) => {
6560
6602
  if ((0, types_1.isClassInstance)(subtype) ||
@@ -6570,9 +6612,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6570
6612
  return { returnType };
6571
6613
  }
6572
6614
  if (argList.length >= 2) {
6573
- // The two-parameter form of "type" returns a new class type
6615
+ // The two-parameter form of a call to a metaclass returns a new class
6574
6616
  // built from the specified base types.
6575
- return { returnType: createType(errorNode, argList) || types_1.AnyType.create() };
6617
+ return {
6618
+ returnType: createClassFromMetaclass(errorNode, argList, expandedCallType) || types_1.AnyType.create(),
6619
+ };
6576
6620
  }
6577
6621
  // If the parameter to type() is not statically known,
6578
6622
  // fall back to Any.
@@ -7646,9 +7690,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7646
7690
  }
7647
7691
  const effectiveReturnType = getFunctionEffectiveReturnType(type);
7648
7692
  let effectiveExpectedType = inferenceContext.expectedType;
7649
- let effectiveFlags = 1024 /* AssignTypeFlags.PopulatingExpectedType */;
7693
+ let effectiveFlags = 2048 /* AssignTypeFlags.PopulatingExpectedType */;
7650
7694
  if ((0, typeUtils_1.containsLiteralType)(effectiveExpectedType, /* includeTypeArgs */ true)) {
7651
- effectiveFlags |= 128 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
7695
+ effectiveFlags |= 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
7652
7696
  }
7653
7697
  // If the expected type is a union, we don't know which type is expected.
7654
7698
  // We may or may not be able to make use of the expected type. We'll evaluate
@@ -7704,7 +7748,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7704
7748
  effectiveExpectedType = (0, typeUtils_1.applySolvedTypeVars)(genericReturnType, tempTypeVarContext, {
7705
7749
  unknownIfNotFound: true,
7706
7750
  });
7707
- effectiveFlags |= 2048 /* AssignTypeFlags.SkipPopulateUnknownExpectedType */;
7751
+ effectiveFlags |= 4096 /* AssignTypeFlags.SkipPopulateUnknownExpectedType */;
7708
7752
  }
7709
7753
  }
7710
7754
  }
@@ -7732,6 +7776,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7732
7776
  let specializedInitSelfType;
7733
7777
  let anyOrUnknownArgument;
7734
7778
  const typeCondition = (0, typeUtils_1.getTypeCondition)(type);
7779
+ // Check for an attempt to invoke an unimplemented abstract method.
7780
+ if (type.boundToType && !type.boundToType.includeSubclasses && isMethodUnimplementedAbstract(type)) {
7781
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.abstractMethodInvocation().format({
7782
+ method: type.details.name,
7783
+ }), errorNode.nodeType === 9 /* ParseNodeType.Call */ ? errorNode.leftExpression : errorNode);
7784
+ }
7735
7785
  if (type.boundTypeVarScopeId) {
7736
7786
  // If the function was bound to a class or object and was a constructor, a
7737
7787
  // static method or a class method, it's possible that some of that class's
@@ -8598,6 +8648,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8598
8648
  addError(localize_1.Localizer.Diagnostic.typeVarTupleUnknownParam().format({ name: ((_a = argList[i].name) === null || _a === void 0 ? void 0 : _a.value) || '?' }), ((_b = argList[i].node) === null || _b === void 0 ? void 0 : _b.name) || argList[i].valueExpression || errorNode);
8599
8649
  }
8600
8650
  }
8651
+ else {
8652
+ addError(localize_1.Localizer.Diagnostic.typeVarTupleConstraints(), argList[i].valueExpression || errorNode);
8653
+ }
8601
8654
  }
8602
8655
  return typeVar;
8603
8656
  }
@@ -8658,7 +8711,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8658
8711
  }
8659
8712
  function getParamSpecDefaultType(node) {
8660
8713
  const functionType = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */ | 65536 /* FunctionTypeFlags.ParamSpecValue */);
8661
- types_1.TypeBase.setSpecialForm(functionType);
8662
8714
  if (node.nodeType === 18 /* ParseNodeType.Ellipsis */) {
8663
8715
  types_1.FunctionType.addDefaultParameters(functionType);
8664
8716
  return functionType;
@@ -8674,6 +8726,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8674
8726
  type: (0, typeUtils_1.convertToInstance)(typeResult.type),
8675
8727
  });
8676
8728
  });
8729
+ if (node.entries.length > 0) {
8730
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
8731
+ }
8677
8732
  // Update the type cache so we don't attempt to re-evaluate this node.
8678
8733
  // The type doesn't matter, so use Any.
8679
8734
  writeTypeCache(node, { type: types_1.AnyType.create() }, /* flags */ undefined);
@@ -8710,7 +8765,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8710
8765
  if (errorNode.parent.nodeType !== 3 /* ParseNodeType.Assignment */ ||
8711
8766
  errorNode.parent.rightExpression !== errorNode ||
8712
8767
  errorNode.parent.leftExpression.nodeType !== 38 /* ParseNodeType.Name */) {
8713
- addError(localize_1.Localizer.Diagnostic.typeAliasTypeMustBeAssigned(), errorNode);
8768
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasTypeMustBeAssigned(), errorNode);
8714
8769
  return undefined;
8715
8770
  }
8716
8771
  const nameNode = errorNode.parent.leftExpression;
@@ -8718,11 +8773,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8718
8773
  if (firstArg.valueExpression && firstArg.valueExpression.nodeType === 48 /* ParseNodeType.StringList */) {
8719
8774
  const typeAliasName = firstArg.valueExpression.strings.map((s) => s.value).join('');
8720
8775
  if (typeAliasName !== nameNode.value) {
8721
- addError(localize_1.Localizer.Diagnostic.typeAliasTypeNameMismatch(), firstArg.valueExpression);
8776
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasTypeNameMismatch(), firstArg.valueExpression);
8722
8777
  }
8723
8778
  }
8724
8779
  else {
8725
- addError(localize_1.Localizer.Diagnostic.typeAliasTypeNameArg(), firstArg.valueExpression || errorNode);
8780
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasTypeNameArg(), firstArg.valueExpression || errorNode);
8726
8781
  return undefined;
8727
8782
  }
8728
8783
  let valueExpr;
@@ -8777,12 +8832,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8777
8832
  }
8778
8833
  });
8779
8834
  if (!isTypeParamListValid) {
8780
- addError(localize_1.Localizer.Diagnostic.typeAliasTypeParamInvalid(), typeParamsExpr);
8835
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasTypeParamInvalid(), typeParamsExpr);
8781
8836
  return undefined;
8782
8837
  }
8783
8838
  }
8784
8839
  return getTypeOfTypeAliasCommon(nameNode, nameNode, valueExpr,
8785
- /* isPep695Syntax */ false,
8840
+ /* isPep695Syntax */ true,
8786
8841
  /* typeParamNodes */ undefined, () => typeParameters);
8787
8842
  }
8788
8843
  function getBooleanValue(node) {
@@ -8794,7 +8849,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8794
8849
  return true;
8795
8850
  }
8796
8851
  }
8797
- addError(localize_1.Localizer.Diagnostic.expectedBoolLiteral(), node);
8852
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.expectedBoolLiteral(), node);
8798
8853
  return false;
8799
8854
  }
8800
8855
  function getFunctionFullName(functionNode, moduleName, functionName) {
@@ -8814,7 +8869,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8814
8869
  // in the Python specification: The static type checker will treat
8815
8870
  // the new type as if it were a subclass of the original type.
8816
8871
  function createNewType(errorNode, argList) {
8817
- var _a;
8872
+ var _a, _b, _c;
8818
8873
  const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
8819
8874
  let className = '';
8820
8875
  if (argList.length !== 2) {
@@ -8831,26 +8886,36 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8831
8886
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.newTypeBadName(), (_a = argList[0].node) !== null && _a !== void 0 ? _a : errorNode);
8832
8887
  return undefined;
8833
8888
  }
8889
+ if (((_b = errorNode.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 3 /* ParseNodeType.Assignment */ &&
8890
+ errorNode.parent.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
8891
+ errorNode.parent.leftExpression.value !== className) {
8892
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.newTypeNameMismatch(), errorNode.parent.leftExpression);
8893
+ return undefined;
8894
+ }
8834
8895
  let baseClass = getTypeOfArgumentExpectingType(argList[1]).type;
8835
8896
  let isBaseClassAny = false;
8836
8897
  if ((0, types_1.isAnyOrUnknown)(baseClass)) {
8837
8898
  if (objectType && (0, types_1.isClassInstance)(objectType)) {
8838
8899
  baseClass = types_1.ClassType.cloneAsInstantiable(objectType);
8839
8900
  }
8901
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.newTypeAnyOrUnknown(), (_c = argList[1].node) !== null && _c !== void 0 ? _c : errorNode);
8840
8902
  isBaseClassAny = true;
8841
8903
  }
8842
8904
  if (!(0, types_1.isInstantiableClass)(baseClass)) {
8843
8905
  addError(localize_1.Localizer.Diagnostic.newTypeNotAClass(), argList[1].node || errorNode);
8844
8906
  return undefined;
8845
8907
  }
8846
- if (types_1.ClassType.isProtocolClass(baseClass)) {
8908
+ if (types_1.ClassType.isProtocolClass(baseClass) || types_1.ClassType.isTypedDictClass(baseClass)) {
8847
8909
  addError(localize_1.Localizer.Diagnostic.newTypeProtocolClass(), argList[1].node || errorNode);
8848
8910
  }
8849
8911
  else if (baseClass.literalValue !== undefined) {
8850
8912
  addError(localize_1.Localizer.Diagnostic.newTypeLiteral(), argList[1].node || errorNode);
8851
8913
  }
8914
+ else if (types_1.ClassType.isNewTypeClass(baseClass)) {
8915
+ addError(localize_1.Localizer.Diagnostic.newTypeNewTypeClass(), argList[1].node || errorNode);
8916
+ }
8852
8917
  let classFlags = baseClass.details.flags & ~(1 /* ClassTypeFlags.BuiltInClass */ | 2 /* ClassTypeFlags.SpecialBuiltIn */);
8853
- classFlags |= 4096 /* ClassTypeFlags.Final */;
8918
+ classFlags |= 4096 /* ClassTypeFlags.Final */ | 268435456 /* ClassTypeFlags.NewTypeClass */ | 536870912 /* ClassTypeFlags.ValidTypeAliasClass */;
8854
8919
  const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, classFlags, ParseTreeUtils.getTypeSourceId(errorNode),
8855
8920
  /* declaredMetaclass */ undefined, baseClass.details.effectiveMetaclass);
8856
8921
  classType.details.baseClasses.push(isBaseClassAny ? types_1.AnyType.create() : baseClass);
@@ -8887,7 +8952,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8887
8952
  return classType;
8888
8953
  }
8889
8954
  // Implements the semantics of the multi-parameter variant of the "type" call.
8890
- function createType(errorNode, argList) {
8955
+ function createClassFromMetaclass(errorNode, argList, metaclass) {
8891
8956
  const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
8892
8957
  const arg0Type = getTypeOfArgument(argList[0]).type;
8893
8958
  if (!(0, types_1.isClassInstance)(arg0Type) || !types_1.ClassType.isBuiltIn(arg0Type, 'str')) {
@@ -8895,10 +8960,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8895
8960
  }
8896
8961
  const className = arg0Type.literalValue || '_';
8897
8962
  const arg1Type = getTypeOfArgument(argList[1]).type;
8963
+ // TODO - properly handle case where tuple of base classes is provided.
8898
8964
  if (!(0, types_1.isClassInstance)(arg1Type) || !(0, typeUtils_1.isTupleClass)(arg1Type) || arg1Type.tupleTypeArguments === undefined) {
8899
8965
  return undefined;
8900
8966
  }
8901
- const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 0 /* ClassTypeFlags.None */, ParseTreeUtils.getTypeSourceId(errorNode),
8967
+ const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 536870912 /* ClassTypeFlags.ValidTypeAliasClass */, ParseTreeUtils.getTypeSourceId(errorNode),
8902
8968
  /* declaredMetaclass */ undefined, arg1Type.details.effectiveMetaclass);
8903
8969
  arg1Type.tupleTypeArguments.forEach((typeArg) => {
8904
8970
  const specializedType = makeTopLevelTypeVarsConcrete(typeArg.type);
@@ -8936,14 +9002,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8936
9002
  }
8937
9003
  return { type: type !== null && type !== void 0 ? type : types_1.UnknownType.create() };
8938
9004
  }
8939
- function getTypeOfMagicMethodCall(objType, methodName, argList, errorNode, inferenceContext) {
9005
+ function getTypeOfMagicMethodCall(objType, methodName, argList, errorNode, inferenceContext, diag) {
8940
9006
  let magicMethodSupported = true;
8941
9007
  // Create a helper lambda for object subtypes.
8942
9008
  const handleSubtype = (subtype) => {
8943
9009
  let magicMethodType;
8944
9010
  const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
8945
9011
  if ((0, types_1.isClass)(concreteSubtype)) {
8946
- magicMethodType = getBoundMagicMethod(concreteSubtype, methodName, subtype);
9012
+ magicMethodType = getBoundMagicMethod(concreteSubtype, methodName, subtype, diag);
8947
9013
  }
8948
9014
  if (magicMethodType) {
8949
9015
  const functionArgs = argList.map((arg) => {
@@ -9283,7 +9349,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9283
9349
  mappingType = (0, typeUtils_1.selfSpecializeClass)(mappingType);
9284
9350
  if (assignType(types_1.ClassType.cloneAsInstance(mappingType), unexpandedType,
9285
9351
  /* diag */ undefined, mappingTypeVarContext,
9286
- /* srcTypeVarContext */ undefined, 128 /* AssignTypeFlags.RetainLiteralsForTypeVar */)) {
9352
+ /* srcTypeVarContext */ undefined, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */)) {
9287
9353
  const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(mappingType, mappingTypeVarContext);
9288
9354
  const typeArgs = specializedMapping.typeArguments;
9289
9355
  if (typeArgs && typeArgs.length >= 2) {
@@ -9711,11 +9777,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9711
9777
  if (paramsArePositionOnly &&
9712
9778
  !isImplicitPositionOnlyParam &&
9713
9779
  functionType.details.parameters.length > 0) {
9714
- // Insert an implicit "position-only parameter" separator.
9715
- types_1.FunctionType.addParameter(functionType, {
9716
- category: 0 /* ParameterCategory.Simple */,
9717
- type: types_1.UnknownType.create(),
9718
- });
9780
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
9719
9781
  }
9720
9782
  if (!isImplicitPositionOnlyParam) {
9721
9783
  paramsArePositionOnly = false;
@@ -9732,11 +9794,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9732
9794
  types_1.FunctionType.addParameter(functionType, functionParam);
9733
9795
  });
9734
9796
  if (paramsArePositionOnly && functionType.details.parameters.length > 0) {
9735
- // Insert an implicit "position-only parameter" separator.
9736
- types_1.FunctionType.addParameter(functionType, {
9737
- category: 0 /* ParameterCategory.Simple */,
9738
- type: types_1.UnknownType.create(),
9739
- });
9797
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
9740
9798
  }
9741
9799
  let typeErrors = false;
9742
9800
  // If we're speculatively evaluating the lambda, create another speculative
@@ -10047,12 +10105,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10047
10105
  });
10048
10106
  });
10049
10107
  if (typeList.length > 0) {
10050
- // Add a positional-only separator to the end of the parameter list.
10051
- types_1.FunctionType.addParameter(functionType, {
10052
- category: 0 /* ParameterCategory.Simple */,
10053
- isNameSynthesized: false,
10054
- type: types_1.UnknownType.create(),
10055
- });
10108
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
10056
10109
  }
10057
10110
  }
10058
10111
  else if ((0, typeUtils_1.isEllipsisType)(typeArgs[0].type)) {
@@ -10068,12 +10121,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10068
10121
  if (concatTypeArgs && concatTypeArgs.length > 0) {
10069
10122
  concatTypeArgs.forEach((typeArg, index) => {
10070
10123
  if (index === concatTypeArgs.length - 1) {
10071
- // Add a position-only separator
10072
- types_1.FunctionType.addParameter(functionType, {
10073
- category: 0 /* ParameterCategory.Simple */,
10074
- isNameSynthesized: false,
10075
- type: types_1.UnknownType.create(),
10076
- });
10124
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
10077
10125
  if ((0, types_1.isParamSpec)(typeArg)) {
10078
10126
  functionType.details.paramSpec = typeArg;
10079
10127
  }
@@ -10308,14 +10356,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10308
10356
  name: classType.details.name,
10309
10357
  }), (_a = typeArgs[0].node) !== null && _a !== void 0 ? _a : errorNode);
10310
10358
  }
10311
- const enclosingClass = ParseTreeUtils.getEnclosingClass(errorNode);
10359
+ let enclosingClass = ParseTreeUtils.getEnclosingClass(errorNode);
10360
+ // If `Self` appears anywhere outside of the class body (e.g. a decorator,
10361
+ // base class list, metaclass argument, type parameter list), it is
10362
+ // considered illegal.
10363
+ if (enclosingClass && !ParseTreeUtils.isNodeContainedWithin(errorNode, enclosingClass.suite)) {
10364
+ enclosingClass = undefined;
10365
+ }
10312
10366
  const enclosingClassTypeResult = enclosingClass ? getTypeOfClass(enclosingClass) : undefined;
10313
10367
  if (!enclosingClassTypeResult) {
10314
- if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
10368
+ if ((flags & (256 /* EvaluatorFlags.ExpectingTypeAnnotation */ | 128 /* EvaluatorFlags.ExpectingInstantiableType */)) !== 0) {
10315
10369
  addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.selfTypeContext(), errorNode);
10316
10370
  }
10317
10371
  return types_1.UnknownType.create();
10318
10372
  }
10373
+ else if ((0, typeUtils_1.isInstantiableMetaclass)(enclosingClassTypeResult.classType)) {
10374
+ // If `Self` appears within a metaclass, it is considered illegal.
10375
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.selfTypeMetaclass(), errorNode);
10376
+ return types_1.UnknownType.create();
10377
+ }
10319
10378
  const enclosingFunction = ParseTreeUtils.getEnclosingFunction(errorNode);
10320
10379
  if (enclosingFunction) {
10321
10380
  const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, enclosingFunction,
@@ -10452,7 +10511,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10452
10511
  }
10453
10512
  return typeArgs[0].type;
10454
10513
  }
10455
- function createConcatenateType(errorNode, classType, typeArgs) {
10514
+ function createConcatenateType(errorNode, classType, typeArgs, flags) {
10515
+ if ((flags & 134217728 /* EvaluatorFlags.AllowConcatenate */) === 0) {
10516
+ addError(localize_1.Localizer.Diagnostic.concatenateContext(), errorNode);
10517
+ return types_1.AnyType.create();
10518
+ }
10456
10519
  if (!typeArgs || typeArgs.length === 0) {
10457
10520
  addError(localize_1.Localizer.Diagnostic.concatenateTypeArgsMissing(), errorNode);
10458
10521
  }
@@ -10485,6 +10548,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10485
10548
  if (!typeArgs || typeArgs.length === 0) {
10486
10549
  return { type: types_1.AnyType.create() };
10487
10550
  }
10551
+ if (typeArgs[0].typeList) {
10552
+ addError(localize_1.Localizer.Diagnostic.typeArgListNotAllowed(), typeArgs[0].node);
10553
+ }
10488
10554
  return {
10489
10555
  type: types_1.TypeBase.cloneForAnnotated(typeArgs[0].type),
10490
10556
  isReadOnly: typeArgs[0].isReadOnly,
@@ -10606,7 +10672,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10606
10672
  }
10607
10673
  // Unpacks the index expression for a "Union[X, Y, Z]" type annotation.
10608
10674
  function createUnionType(classType, errorNode, typeArgs, flags) {
10675
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
10609
10676
  const types = [];
10677
+ let allowSingleTypeArg = false;
10610
10678
  if (!typeArgs) {
10611
10679
  // If no type arguments are provided, the resulting type
10612
10680
  // depends on whether we're evaluating a type annotation or
@@ -10628,15 +10696,29 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10628
10696
  }
10629
10697
  // If this is an unpacked tuple, explode out the individual items.
10630
10698
  if ((0, types_1.isUnpackedClass)(typeArg.type) && typeArg.type.tupleTypeArguments) {
10631
- typeArg.type.tupleTypeArguments.forEach((tupleTypeArg) => {
10632
- types.push((0, typeUtils_1.convertToInstantiable)(tupleTypeArg.type));
10633
- });
10699
+ if (fileInfo.diagnosticRuleSet.enableExperimentalFeatures) {
10700
+ typeArg.type.tupleTypeArguments.forEach((tupleTypeArg) => {
10701
+ types.push((0, typeUtils_1.convertToInstantiable)(tupleTypeArg.type));
10702
+ });
10703
+ allowSingleTypeArg = true;
10704
+ }
10705
+ else {
10706
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.unionUnpackedTuple(), errorNode);
10707
+ types.push(types_1.UnknownType.create());
10708
+ }
10634
10709
  }
10635
10710
  else {
10636
- // If this is an unpacked TypeVar, note that it is in a union so we can differentiate
10637
- // between Unpack[Vs] and Union[Unpack[Vs]].
10638
10711
  if ((0, types_1.isTypeVar)(typeArgType) && (0, types_1.isUnpackedVariadicTypeVar)(typeArgType)) {
10639
- typeArgType = types_1.TypeVarType.cloneForUnpacked(typeArgType, /* isInUnion */ true);
10712
+ if (fileInfo.diagnosticRuleSet.enableExperimentalFeatures) {
10713
+ // If this is an unpacked TypeVar, note that it is in a union so we can
10714
+ // differentiate between Unpack[Vs] and Union[Unpack[Vs]].
10715
+ typeArgType = types_1.TypeVarType.cloneForUnpacked(typeArgType, /* isInUnion */ true);
10716
+ allowSingleTypeArg = true;
10717
+ }
10718
+ else {
10719
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.unionUnpackedTypeVarTuple(), errorNode);
10720
+ typeArgType = types_1.UnknownType.create();
10721
+ }
10640
10722
  }
10641
10723
  types.push(typeArgType);
10642
10724
  }
@@ -10644,10 +10726,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10644
10726
  // Validate that we received at least two type arguments. One type argument
10645
10727
  // is allowed if it's an unpacked variadic type var or tuple. None is also allowed
10646
10728
  // since it is used to define NoReturn in typeshed stubs).
10647
- if (types.length === 1) {
10648
- if (!(0, types_1.isVariadicTypeVar)(types[0]) && !(0, types_1.isUnpacked)(types[0]) && !(0, typeUtils_1.isNoneInstance)(types[0])) {
10649
- addError(localize_1.Localizer.Diagnostic.unionTypeArgCount(), errorNode);
10650
- }
10729
+ if (types.length === 1 && !allowSingleTypeArg && !(0, typeUtils_1.isNoneInstance)(types[0])) {
10730
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.unionTypeArgCount(), errorNode);
10651
10731
  }
10652
10732
  const unionType = (0, types_1.combineTypes)(types);
10653
10733
  if ((0, types_1.isUnion)(unionType)) {
@@ -11003,7 +11083,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11003
11083
  // only if the evaluated type is an instantiable type.
11004
11084
  if (!isSpeculativeTypeAlias || isLegalImplicitTypeAliasType(rightHandType)) {
11005
11085
  // If this is a type alias, record its name based on the assignment target.
11006
- rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode, node.rightExpression,
11086
+ rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode, typeAliasNameNode,
11007
11087
  /* isPep695Syntax */ false,
11008
11088
  /* isPep695TypeVarType */ false);
11009
11089
  (0, debug_1.assert)(typeAliasTypeVar !== undefined);
@@ -11094,17 +11174,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11094
11174
  setSymbolResolutionPartialType(typeAliasSymbol.symbol, typeAliasDecl, typeAliasTypeVar);
11095
11175
  }
11096
11176
  const typeParameters = getTypeParamCallback();
11097
- typeAliasTypeVar.details.recursiveTypeParameters = typeParameters;
11098
- if (!isLegalTypeAliasExpressionForm(valueNode)) {
11099
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(valueNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIllegalExpressionForm(), valueNode);
11100
- }
11101
- const aliasTypeResult = getTypeOfExpressionExpectingType(valueNode, { allowForwardReference: true });
11177
+ typeAliasTypeVar.details.recursiveTypeParameters = typeParameters || [];
11178
+ const aliasTypeResult = getTypeOfExpressionExpectingType(valueNode, {
11179
+ allowForwardReference: true,
11180
+ enforceTypeAnnotationRules: true,
11181
+ });
11102
11182
  let isIncomplete = false;
11103
11183
  let aliasType = aliasTypeResult.type;
11104
11184
  if (aliasTypeResult.isIncomplete) {
11105
11185
  isIncomplete = true;
11106
11186
  }
11107
- aliasType = transformTypeForTypeAlias(aliasType, nameNode, valueNode, isPep695Syntax,
11187
+ aliasType = transformTypeForTypeAlias(aliasType, nameNode, nameNode, isPep695Syntax,
11108
11188
  /* isPep695TypeVarType */ true, typeParameters, typeParamNodes);
11109
11189
  if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, aliasType)) {
11110
11190
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(valueNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIsRecursiveDirect().format({
@@ -11363,6 +11443,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11363
11443
  }
11364
11444
  }
11365
11445
  }
11446
+ else if (types_1.ClassType.isTypedDictClass(classType)) {
11447
+ if (arg.name.value === 'total') {
11448
+ // The "total" and "readonly" parameters apply only for TypedDict classes.
11449
+ // PEP 589 specifies that the parameter must be either True or False.
11450
+ const constArgValue = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.valueExpression, fileInfo.executionEnvironment, fileInfo.definedConstants);
11451
+ if (constArgValue === undefined) {
11452
+ addError(localize_1.Localizer.Diagnostic.typedDictBoolParam().format({ name: arg.name.value }), arg.valueExpression);
11453
+ }
11454
+ else if (arg.name.value === 'total' && !constArgValue) {
11455
+ classType.details.flags |= 256 /* ClassTypeFlags.CanOmitDictValues */;
11456
+ }
11457
+ }
11458
+ else {
11459
+ addError(localize_1.Localizer.Diagnostic.typedDictInitsubclassParameter().format({ name: arg.name.value }), arg);
11460
+ }
11461
+ }
11366
11462
  else if (arg.name.value === 'metaclass') {
11367
11463
  if (metaclassNode) {
11368
11464
  addError(localize_1.Localizer.Diagnostic.metaclassDuplicate(), arg);
@@ -11371,17 +11467,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11371
11467
  metaclassNode = arg.valueExpression;
11372
11468
  }
11373
11469
  }
11374
- else if (types_1.ClassType.isTypedDictClass(classType) && arg.name.value === 'total') {
11375
- // The "total" and "readonly" parameters apply only for TypedDict classes.
11376
- // PEP 589 specifies that the parameter must be either True or False.
11377
- const constArgValue = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.valueExpression, fileInfo.executionEnvironment, fileInfo.definedConstants);
11378
- if (constArgValue === undefined) {
11379
- addError(localize_1.Localizer.Diagnostic.typedDictBoolParam().format({ name: arg.name.value }), arg.valueExpression);
11380
- }
11381
- else if (arg.name.value === 'total' && !constArgValue) {
11382
- classType.details.flags |= 256 /* ClassTypeFlags.CanOmitDictValues */;
11383
- }
11384
- }
11385
11470
  else {
11386
11471
  // Collect arguments that will be passed to the `__init_subclass__`
11387
11472
  // method described in PEP 487.
@@ -12272,11 +12357,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12272
12357
  if (paramsArePositionOnly &&
12273
12358
  !isImplicitPositionOnlyParam &&
12274
12359
  functionType.details.parameters.length > firstNonClsSelfParamIndex) {
12275
- // Insert an implicit "position-only parameter" separator.
12276
- types_1.FunctionType.addParameter(functionType, {
12277
- category: 0 /* ParameterCategory.Simple */,
12278
- type: types_1.UnknownType.create(),
12279
- });
12360
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
12280
12361
  }
12281
12362
  if (!isImplicitPositionOnlyParam) {
12282
12363
  paramsArePositionOnly = false;
@@ -12315,11 +12396,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12315
12396
  }
12316
12397
  });
12317
12398
  if (paramsArePositionOnly && functionType.details.parameters.length > firstNonClsSelfParamIndex) {
12318
- // Insert an implicit "position-only parameter" separator.
12319
- types_1.FunctionType.addParameter(functionType, {
12320
- category: 0 /* ParameterCategory.Simple */,
12321
- type: types_1.UnknownType.create(),
12322
- });
12399
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
12323
12400
  }
12324
12401
  // Update the types for the nodes associated with the parameters.
12325
12402
  paramTypes.forEach((paramType, index) => {
@@ -12915,7 +12992,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12915
12992
  const additionalHelp = new diagnostic_1.DiagnosticAddendum();
12916
12993
  if ((0, types_1.isClass)(subtype)) {
12917
12994
  let enterType = getTypeOfMagicMethodCall(subtype, enterMethodName, [], node.expression,
12918
- /* inferenceContext */ undefined);
12995
+ /* inferenceContext */ undefined, additionalHelp.createAddendum());
12919
12996
  if (enterType) {
12920
12997
  // For "async while", an implicit "await" is performed.
12921
12998
  if (isAsync) {
@@ -13785,7 +13862,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13785
13862
  return createAnnotatedType(errorNode, typeArgs);
13786
13863
  }
13787
13864
  case 'Concatenate': {
13788
- return { type: createConcatenateType(errorNode, classType, typeArgs) };
13865
+ return { type: createConcatenateType(errorNode, classType, typeArgs, flags) };
13789
13866
  }
13790
13867
  case 'TypeGuard': {
13791
13868
  return { type: createTypeGuardType(errorNode, classType, typeArgs, flags) };
@@ -13858,9 +13935,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13858
13935
  const variadicTypeParamIndex = typeParameters.findIndex((param) => (0, types_1.isVariadicTypeVar)(param));
13859
13936
  if (typeArgs) {
13860
13937
  let minTypeArgCount = typeParameters.length;
13861
- const firstNonDefaultParam = typeParameters.findIndex((param) => !!param.details.defaultType);
13862
- if (firstNonDefaultParam >= 0) {
13863
- minTypeArgCount = firstNonDefaultParam;
13938
+ const firstDefaultParamIndex = typeParameters.findIndex((param) => !!param.details.defaultType);
13939
+ if (firstDefaultParamIndex >= 0) {
13940
+ minTypeArgCount = firstDefaultParamIndex;
13864
13941
  }
13865
13942
  // Classes that accept inlined type dict type args allow only one.
13866
13943
  if (typeArgs[0].inlinedTypeDict) {
@@ -13958,7 +14035,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13958
14035
  if (typeParam.details.isParamSpec) {
13959
14036
  const typeArg = typeArgs[index];
13960
14037
  const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
13961
- types_1.TypeBase.setSpecialForm(functionType);
13962
14038
  if ((0, typeUtils_1.isEllipsisType)(typeArg.type)) {
13963
14039
  types_1.FunctionType.addDefaultParameters(functionType);
13964
14040
  functionType.details.flags |= 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
@@ -13976,6 +14052,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13976
14052
  hasDeclaredType: true,
13977
14053
  });
13978
14054
  });
14055
+ if (typeArg.typeList.length > 0) {
14056
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
14057
+ }
13979
14058
  typeArgTypes.push(functionType);
13980
14059
  typeVarContext.setTypeVarType(typeParam, (0, typeUtils_1.convertTypeToParamSpecValue)(functionType));
13981
14060
  return;
@@ -14505,7 +14584,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14505
14584
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
14506
14585
  // Determine if this node is within a quoted type annotation.
14507
14586
  const isWithinTypeAnnotation = ParseTreeUtils.isWithinTypeAnnotation(node, !(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(AnalyzerNodeInfo.getFileInfo(node)));
14508
- const allowForwardReferences = isWithinTypeAnnotation || fileInfo.isStubFile;
14587
+ // Determine if this is part of a "type" statement.
14588
+ const isWithinTypeAliasStatement = !!ParseTreeUtils.getParentNodeOfType(node, 77 /* ParseNodeType.TypeAlias */);
14589
+ const allowForwardReferences = isWithinTypeAnnotation || isWithinTypeAliasStatement || fileInfo.isStubFile;
14509
14590
  let symbol;
14510
14591
  const typeParamSymbol = AnalyzerNodeInfo.getTypeParameterSymbol(node);
14511
14592
  if (typeParamSymbol) {
@@ -15712,7 +15793,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15712
15793
  function assignClassToSelf(destType, srcType, ignoreBaseClassVariance = true, recursionCount = 0) {
15713
15794
  (0, debug_1.assert)(types_1.ClassType.isSameGenericClass(destType, srcType));
15714
15795
  (0, debug_1.assert)(destType.details.typeParameters.length > 0);
15715
- const diag = new diagnostic_1.DiagnosticAddendum();
15716
15796
  const typeVarContext = new typeVarContext_1.TypeVarContext();
15717
15797
  let isAssignable = true;
15718
15798
  destType.details.fields.forEach((symbol, name) => {
@@ -15733,7 +15813,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15733
15813
  types_1.ClassType.isPropertyClass(destMemberType) &&
15734
15814
  (0, types_1.isClassInstance)(srcMemberType) &&
15735
15815
  types_1.ClassType.isPropertyClass(srcMemberType)) {
15736
- if (!(0, properties_1.assignProperty)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destMemberType), types_1.ClassType.cloneAsInstantiable(srcMemberType), destType, srcType, diag, typeVarContext,
15816
+ if (!(0, properties_1.assignProperty)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destMemberType), types_1.ClassType.cloneAsInstantiable(srcMemberType), destType, srcType,
15817
+ /* diag */ undefined, typeVarContext,
15737
15818
  /* selfTypeVarContext */ undefined, recursionCount)) {
15738
15819
  isAssignable = false;
15739
15820
  }
@@ -15752,7 +15833,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15752
15833
  flags |= 1 /* AssignTypeFlags.EnforceInvariance */;
15753
15834
  }
15754
15835
  }
15755
- if (!assignType(destMemberType, srcMemberType, diag, typeVarContext,
15836
+ if (!assignType(destMemberType, srcMemberType,
15837
+ /* diag */ undefined, typeVarContext,
15756
15838
  /* srcTypeVarContext */ undefined, flags, recursionCount)) {
15757
15839
  isAssignable = false;
15758
15840
  }
@@ -16057,16 +16139,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16057
16139
  let errorSource;
16058
16140
  let includeDiagAddendum = true;
16059
16141
  if (variance === 3 /* Variance.Covariant */) {
16060
- effectiveFlags = flags | 128 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
16142
+ effectiveFlags = flags | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
16061
16143
  errorSource = localize_1.Localizer.DiagnosticAddendum.typeVarIsCovariant;
16062
16144
  }
16063
16145
  else if (variance === 4 /* Variance.Contravariant */) {
16064
16146
  effectiveFlags =
16065
- (flags ^ 2 /* AssignTypeFlags.ReverseTypeVarMatching */) | 128 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
16147
+ (flags ^ 2 /* AssignTypeFlags.ReverseTypeVarMatching */) | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
16066
16148
  errorSource = localize_1.Localizer.DiagnosticAddendum.typeVarIsContravariant;
16067
16149
  }
16068
16150
  else {
16069
- effectiveFlags = flags | 1 /* AssignTypeFlags.EnforceInvariance */ | 128 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
16151
+ effectiveFlags = flags | 1 /* AssignTypeFlags.EnforceInvariance */ | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
16070
16152
  errorSource = localize_1.Localizer.DiagnosticAddendum.typeVarIsInvariant;
16071
16153
  // Omit the diagnostic addendum for the invariant case because it's obvious
16072
16154
  // why two types are not the same.
@@ -16189,7 +16271,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16189
16271
  }
16190
16272
  // Strip flags we don't want to propagate to other calls.
16191
16273
  const originalFlags = flags;
16192
- flags &= ~64 /* AssignTypeFlags.AllowBoolTypeGuard */;
16274
+ flags &= ~128 /* AssignTypeFlags.AllowBoolTypeGuard */;
16193
16275
  // Before performing any other checks, see if the dest type is a
16194
16276
  // TypeVar that we are attempting to match.
16195
16277
  if ((0, types_1.isTypeVar)(destType)) {
@@ -16414,7 +16496,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16414
16496
  // PEP 544 says that if the dest type is a type[Proto] class,
16415
16497
  // the source must be a "concrete" (non-protocol) class.
16416
16498
  if (types_1.ClassType.isProtocolClass(destType) &&
16417
- (flags & 8192 /* AssignTypeFlags.IgnoreProtocolAssignmentCheck */) === 0) {
16499
+ (flags & 16384 /* AssignTypeFlags.IgnoreProtocolAssignmentCheck */) === 0) {
16418
16500
  if (types_1.ClassType.isProtocolClass(expandedSrcType) &&
16419
16501
  (0, types_1.isInstantiableClass)(srcType) &&
16420
16502
  !srcType.includeSubclasses) {
@@ -16466,7 +16548,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16466
16548
  }
16467
16549
  else if (types_1.ClassType.isBuiltIn(destType, 'TypeGuard')) {
16468
16550
  // All the source to be a "bool".
16469
- if ((originalFlags & 64 /* AssignTypeFlags.AllowBoolTypeGuard */) !== 0) {
16551
+ if ((originalFlags & 128 /* AssignTypeFlags.AllowBoolTypeGuard */) !== 0) {
16470
16552
  if ((0, types_1.isClassInstance)(srcType) && types_1.ClassType.isBuiltIn(srcType, 'bool')) {
16471
16553
  return true;
16472
16554
  }
@@ -16560,7 +16642,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16560
16642
  let concreteSrcType = makeTopLevelTypeVarsConcrete(srcType);
16561
16643
  if ((0, types_1.isClassInstance)(concreteSrcType)) {
16562
16644
  const boundMethod = getBoundMagicMethod(concreteSrcType, '__call__',
16563
- /* selfType */ undefined, recursionCount);
16645
+ /* selfType */ undefined,
16646
+ /* diag */ undefined, recursionCount);
16564
16647
  if (boundMethod) {
16565
16648
  concreteSrcType = (0, typeUtils_1.removeParamSpecVariadicsFromSignature)(boundMethod);
16566
16649
  }
@@ -16680,6 +16763,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16680
16763
  }
16681
16764
  // Sort the subtypes so we have a deterministic order for unions.
16682
16765
  let sortedSrcTypes = (0, typeUtils_1.sortTypes)(srcType.subtypes);
16766
+ let matchedSomeSubtypes = false;
16683
16767
  // Handle the case where the source and dest are both unions. Try
16684
16768
  // to eliminate as many exact type matches between the src and dest.
16685
16769
  if ((0, types_1.isUnion)(destType)) {
@@ -16706,6 +16790,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16706
16790
  const srcTypeIndex = remainingSrcSubtypes.findIndex((srcSubtype) => (0, types_1.isTypeSame)(srcSubtype, destSubtype, {}, recursionCount));
16707
16791
  if (srcTypeIndex >= 0) {
16708
16792
  remainingSrcSubtypes.splice(srcTypeIndex, 1);
16793
+ matchedSomeSubtypes = true;
16709
16794
  }
16710
16795
  else {
16711
16796
  remainingDestSubtypes.push(destSubtype);
@@ -16743,7 +16828,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16743
16828
  return false;
16744
16829
  });
16745
16830
  if (destTypeIndex >= 0) {
16746
- if (!assignType(remainingDestSubtypes[destTypeIndex], srcSubtype, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
16831
+ if (assignType(remainingDestSubtypes[destTypeIndex], srcSubtype, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
16832
+ // Note that we have matched at least one subtype indicating
16833
+ // there is at least some overlap.
16834
+ matchedSomeSubtypes = true;
16835
+ }
16836
+ else {
16747
16837
  canUseFastPath = false;
16748
16838
  }
16749
16839
  remainingDestSubtypes.splice(destTypeIndex, 1);
@@ -16781,7 +16871,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16781
16871
  sortedSrcTypes = remainingSrcSubtypes;
16782
16872
  }
16783
16873
  else if (remainingSrcSubtypes.length === 0) {
16784
- if ((flags & 1024 /* AssignTypeFlags.PopulatingExpectedType */) !== 0) {
16874
+ if ((flags & 2048 /* AssignTypeFlags.PopulatingExpectedType */) !== 0) {
16785
16875
  // If we're populating an expected type, try not to leave
16786
16876
  // any TypeVars unsolved. Assign the full type to the remaining
16787
16877
  // dest TypeVars.
@@ -16804,6 +16894,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16804
16894
  if (canUseFastPath) {
16805
16895
  return true;
16806
16896
  }
16897
+ // If we're looking for type overlaps and at least one type was matched,
16898
+ // consider it as assignable.
16899
+ if ((flags & 32 /* AssignTypeFlags.PartialOverloadOverlapCheck */) !== 0 && matchedSomeSubtypes) {
16900
+ return true;
16901
+ }
16807
16902
  }
16808
16903
  let isIncompatible = false;
16809
16904
  sortedSrcTypes.forEach((subtype) => {
@@ -16822,8 +16917,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16822
16917
  isIncompatible = true;
16823
16918
  }
16824
16919
  }
16920
+ else {
16921
+ matchedSomeSubtypes = true;
16922
+ }
16825
16923
  }, /* sortSubtypes */ true);
16826
16924
  if (isIncompatible) {
16925
+ // If we're looking for type overlaps and at least one type was matched,
16926
+ // consider it as assignable.
16927
+ if ((flags & 32 /* AssignTypeFlags.PartialOverloadOverlapCheck */) !== 0 && matchedSomeSubtypes) {
16928
+ return true;
16929
+ }
16827
16930
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
16828
16931
  return false;
16829
16932
  }
@@ -17061,7 +17164,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17061
17164
  }
17062
17165
  }
17063
17166
  }
17064
- const boundMethod = getBoundMagicMethod(objType, '__call__', /* selfType */ undefined, recursionCount);
17167
+ const boundMethod = getBoundMagicMethod(objType, '__call__',
17168
+ /* selfType */ undefined,
17169
+ /* diag */ undefined, recursionCount);
17065
17170
  if (boundMethod) {
17066
17171
  return (0, typeUtils_1.removeParamSpecVariadicsFromSignature)(boundMethod);
17067
17172
  }
@@ -17094,7 +17199,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17094
17199
  // Is an additional specialization step required?
17095
17200
  if (doSpecializationStep) {
17096
17201
  assignType(specializedSrcType, specializedDestType,
17097
- /* diag */ undefined, srcTypeVarContext, destTypeVarContext, (flags ^ 2 /* AssignTypeFlags.ReverseTypeVarMatching */) | 128 /* AssignTypeFlags.RetainLiteralsForTypeVar */, recursionCount);
17202
+ /* diag */ undefined, srcTypeVarContext, destTypeVarContext, (flags ^ 2 /* AssignTypeFlags.ReverseTypeVarMatching */) | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */, recursionCount);
17098
17203
  if ((flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) === 0) {
17099
17204
  specializedDestType = (0, typeUtils_1.applySolvedTypeVars)(destType, destTypeVarContext);
17100
17205
  }
@@ -17208,9 +17313,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17208
17313
  function assignFunction(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
17209
17314
  var _a, _b, _c, _d, _e, _f, _g, _h;
17210
17315
  let canAssign = true;
17211
- const checkReturnType = (flags & 32 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */) === 0;
17316
+ const checkReturnType = (flags & 64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */) === 0;
17212
17317
  const reverseMatching = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) !== 0;
17213
- flags &= ~32 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */;
17318
+ flags &= ~64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */;
17214
17319
  destType = (0, typeUtils_1.removeParamSpecVariadicsFromFunction)(destType);
17215
17320
  srcType = (0, typeUtils_1.removeParamSpecVariadicsFromFunction)(srcType);
17216
17321
  const destParamDetails = (0, parameterUtils_1.getParameterListDetails)(destType);
@@ -17234,17 +17339,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17234
17339
  const destParamType = destParam.type;
17235
17340
  const destParamName = (_c = destParam.param.name) !== null && _c !== void 0 ? _c : '';
17236
17341
  const srcParamName = (_d = srcParam.param.name) !== null && _d !== void 0 ? _d : '';
17237
- if (destParamName && !(0, symbolNameUtils_1.isPrivateOrProtectedName)(destParamName) && !(0, symbolNameUtils_1.isPrivateOrProtectedName)(srcParamName)) {
17342
+ if (destParamName) {
17238
17343
  const isDestPositionalOnly = destParam.source === parameterUtils_1.ParameterSource.PositionOnly;
17239
17344
  if (!isDestPositionalOnly &&
17240
17345
  destParam.param.category !== 1 /* ParameterCategory.ArgsList */ &&
17241
- srcParam.param.category !== 1 /* ParameterCategory.ArgsList */ &&
17242
- destParamName !== srcParamName) {
17243
- diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.Localizer.DiagnosticAddendum.functionParamName().format({
17244
- srcName: srcParamName,
17245
- destName: destParamName,
17246
- }));
17247
- canAssign = false;
17346
+ srcParam.param.category !== 1 /* ParameterCategory.ArgsList */) {
17347
+ if (srcParam.source === parameterUtils_1.ParameterSource.PositionOnly) {
17348
+ diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.Localizer.DiagnosticAddendum.functionParamPositionOnly().format({
17349
+ name: destParamName,
17350
+ }));
17351
+ canAssign = false;
17352
+ }
17353
+ else if (destParamName !== srcParamName) {
17354
+ diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.Localizer.DiagnosticAddendum.functionParamName().format({
17355
+ srcName: srcParamName,
17356
+ destName: destParamName,
17357
+ }));
17358
+ canAssign = false;
17359
+ }
17248
17360
  }
17249
17361
  }
17250
17362
  if (!!destParam.param.hasDefault &&
@@ -17269,7 +17381,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17269
17381
  if (!assignFunctionParameter(destParamType, srcParamType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
17270
17382
  // Handle the special case where the source parameter is a synthesized
17271
17383
  // TypeVar for "self" or "cls".
17272
- if ((flags & 256 /* AssignTypeFlags.SkipSelfClsTypeCheck */) === 0 ||
17384
+ if ((flags & 512 /* AssignTypeFlags.SkipSelfClsTypeCheck */) === 0 ||
17273
17385
  !(0, types_1.isTypeVar)(srcParamType) ||
17274
17386
  !srcParamType.details.isSynthesized) {
17275
17387
  canAssign = false;
@@ -17599,7 +17711,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17599
17711
  // solver to retain literals.
17600
17712
  if (srcType.details.declaredReturnType &&
17601
17713
  (0, typeUtils_1.containsLiteralType)(srcType.details.declaredReturnType, /* includeTypeArgs */ true)) {
17602
- effectiveFlags |= 128 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
17714
+ effectiveFlags |= 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
17603
17715
  }
17604
17716
  if ((0, types_1.isNever)(srcReturnType)) {
17605
17717
  // We'll allow any function that returns NoReturn to match any
@@ -18343,7 +18455,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18343
18455
  }
18344
18456
  }
18345
18457
  else if (!assignType(memberTypeFirstParamType, firstParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), typeVarContext,
18346
- /* srcTypeVarContext */ undefined, 4096 /* AssignTypeFlags.AllowUnspecifiedTypeArguments */, recursionCount)) {
18458
+ /* srcTypeVarContext */ undefined, 8192 /* AssignTypeFlags.AllowUnspecifiedTypeArguments */, recursionCount)) {
18347
18459
  if (memberTypeFirstParam.name &&
18348
18460
  !memberTypeFirstParam.isNameSynthesized &&
18349
18461
  memberTypeFirstParam.hasDeclaredType) {
@@ -18415,6 +18527,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18415
18527
  case 31 /* ParseNodeType.List */:
18416
18528
  case 45 /* ParseNodeType.Set */:
18417
18529
  return false;
18530
+ case 7 /* ParseNodeType.BinaryOperation */:
18531
+ return (node.operator === 6 /* OperatorType.BitwiseOr */ &&
18532
+ isLegalTypeAliasExpressionForm(node.leftExpression) &&
18533
+ isLegalTypeAliasExpressionForm(node.rightExpression));
18534
+ case 24 /* ParseNodeType.Index */:
18535
+ return isLegalTypeAliasExpressionForm(node.baseExpression);
18536
+ case 35 /* ParseNodeType.MemberAccess */:
18537
+ return isLegalTypeAliasExpressionForm(node.leftExpression);
18418
18538
  }
18419
18539
  return true;
18420
18540
  }