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

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 (101) hide show
  1. package/dist/analyzer/binder.js +22 -18
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/codeFlowEngine.js +25 -13
  4. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  5. package/dist/analyzer/codeFlowTypes.d.ts +0 -1
  6. package/dist/analyzer/codeFlowTypes.js.map +1 -1
  7. package/dist/analyzer/decorators.js +14 -43
  8. package/dist/analyzer/decorators.js.map +1 -1
  9. package/dist/analyzer/importResolver.js +1 -1
  10. package/dist/analyzer/importResolver.js.map +1 -1
  11. package/dist/analyzer/operations.d.ts +1 -1
  12. package/dist/analyzer/operations.js +16 -1
  13. package/dist/analyzer/operations.js.map +1 -1
  14. package/dist/analyzer/packageTypeVerifier.d.ts +5 -1
  15. package/dist/analyzer/packageTypeVerifier.js +59 -41
  16. package/dist/analyzer/packageTypeVerifier.js.map +1 -1
  17. package/dist/analyzer/parameterUtils.js +1 -1
  18. package/dist/analyzer/parameterUtils.js.map +1 -1
  19. package/dist/analyzer/parseTreeUtils.js +1 -1
  20. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  21. package/dist/analyzer/patternMatching.js +23 -0
  22. package/dist/analyzer/patternMatching.js.map +1 -1
  23. package/dist/analyzer/properties.js +3 -0
  24. package/dist/analyzer/properties.js.map +1 -1
  25. package/dist/analyzer/protocols.js +18 -6
  26. package/dist/analyzer/protocols.js.map +1 -1
  27. package/dist/analyzer/service.js +12 -10
  28. package/dist/analyzer/service.js.map +1 -1
  29. package/dist/analyzer/sourceMapper.js +3 -2
  30. package/dist/analyzer/sourceMapper.js.map +1 -1
  31. package/dist/analyzer/typeEvaluator.js +144 -120
  32. package/dist/analyzer/typeEvaluator.js.map +1 -1
  33. package/dist/analyzer/typeEvaluatorTypes.d.ts +4 -4
  34. package/dist/analyzer/typeGuards.d.ts +1 -0
  35. package/dist/analyzer/typeGuards.js +9 -7
  36. package/dist/analyzer/typeGuards.js.map +1 -1
  37. package/dist/analyzer/typeUtils.d.ts +2 -1
  38. package/dist/analyzer/typeUtils.js +35 -12
  39. package/dist/analyzer/typeUtils.js.map +1 -1
  40. package/dist/analyzer/typeVarContext.d.ts +0 -1
  41. package/dist/analyzer/typeVarContext.js +4 -5
  42. package/dist/analyzer/typeVarContext.js.map +1 -1
  43. package/dist/analyzer/types.d.ts +7 -4
  44. package/dist/analyzer/types.js +10 -7
  45. package/dist/analyzer/types.js.map +1 -1
  46. package/dist/common/fileWatcher.d.ts +1 -1
  47. package/dist/common/realFileSystem.js +1 -1
  48. package/dist/common/realFileSystem.js.map +1 -1
  49. package/dist/common/uri/emptyUri.js +1 -25
  50. package/dist/common/uri/emptyUri.js.map +1 -1
  51. package/dist/common/uri/webUri.js +1 -25
  52. package/dist/common/uri/webUri.js.map +1 -1
  53. package/dist/common/workspaceEditUtils.js +3 -3
  54. package/dist/common/workspaceEditUtils.js.map +1 -1
  55. package/dist/languageService/documentSymbolCollector.js +1 -1
  56. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  57. package/dist/languageService/symbolIndexer.js +10 -2
  58. package/dist/languageService/symbolIndexer.js.map +1 -1
  59. package/dist/localization/localize.d.ts +4 -0
  60. package/dist/localization/localize.js +4 -0
  61. package/dist/localization/localize.js.map +1 -1
  62. package/dist/localization/package.nls.en-us.json +4 -0
  63. package/dist/parser/parseNodes.d.ts +1 -0
  64. package/dist/parser/parseNodes.js +1 -0
  65. package/dist/parser/parseNodes.js.map +1 -1
  66. package/dist/parser/parser.js +18 -15
  67. package/dist/parser/parser.js.map +1 -1
  68. package/dist/pyright.js +10 -7
  69. package/dist/pyright.js.map +1 -1
  70. package/dist/tests/classDeclaration.test.d.ts +1 -0
  71. package/dist/tests/classDeclaration.test.js +166 -0
  72. package/dist/tests/classDeclaration.test.js.map +1 -0
  73. package/dist/tests/fourslash/fourslash.d.ts +1 -0
  74. package/dist/tests/fourslash/fourslash.js +2 -2
  75. package/dist/tests/fourslash/rename.parens.fourslash.d.ts +1 -0
  76. package/dist/tests/fourslash/rename.parens.fourslash.js +20 -0
  77. package/dist/tests/fourslash/rename.parens.fourslash.js.map +1 -0
  78. package/dist/tests/fourslash/typeVerifier.fourslash.d.ts +1 -0
  79. package/dist/tests/fourslash/typeVerifier.fourslash.js +47 -0
  80. package/dist/tests/fourslash/typeVerifier.fourslash.js.map +1 -0
  81. package/dist/tests/harness/fourslash/testState.d.ts +2 -0
  82. package/dist/tests/harness/fourslash/testState.js +16 -0
  83. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  84. package/dist/tests/harness/fourslash/workspaceEditTestUtils.js +4 -0
  85. package/dist/tests/harness/fourslash/workspaceEditTestUtils.js.map +1 -1
  86. package/dist/tests/harness/vfs/filesystem.js +1 -1
  87. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  88. package/dist/tests/importResolver.test.js +25 -0
  89. package/dist/tests/importResolver.test.js.map +1 -1
  90. package/dist/tests/sourceMapperUtils.test.js +60 -29
  91. package/dist/tests/sourceMapperUtils.test.js.map +1 -1
  92. package/dist/tests/typeEvaluator1.test.js +1 -1
  93. package/dist/tests/typeEvaluator2.test.js +8 -0
  94. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  95. package/dist/tests/typeEvaluator3.test.js +17 -1
  96. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  97. package/dist/tests/typeEvaluator4.test.js +13 -1
  98. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  99. package/dist/tests/uri.test.js +4 -0
  100. package/dist/tests/uri.test.js.map +1 -1
  101. package/package.json +1 -1
@@ -568,7 +568,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
568
568
  break;
569
569
  }
570
570
  case 55 /* ParseNodeType.UnaryOperation */: {
571
- typeResult = (0, operations_1.getTypeOfUnaryOperation)(evaluatorInterface, node, inferenceContext);
571
+ typeResult = (0, operations_1.getTypeOfUnaryOperation)(evaluatorInterface, node, flags, inferenceContext);
572
572
  break;
573
573
  }
574
574
  case 7 /* ParseNodeType.BinaryOperation */: {
@@ -622,6 +622,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
622
622
  break;
623
623
  }
624
624
  case 4 /* ParseNodeType.AssignmentExpression */: {
625
+ if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
626
+ addError(localize_1.Localizer.Diagnostic.walrusNotAllowed(), node);
627
+ }
625
628
  typeResult = getTypeOfExpression(node.rightExpression, flags, inferenceContext);
626
629
  assignTypeToExpression(node.name, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
627
630
  /* ignoreEmptyContainers */ true);
@@ -761,6 +764,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
761
764
  }
762
765
  }
763
766
  function getTypeOfAwaitOperator(node, flags, inferenceContext) {
767
+ if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
768
+ addError(localize_1.Localizer.Diagnostic.awaitNotAllowed(), node);
769
+ return { type: types_1.UnknownType.create() };
770
+ }
764
771
  const effectiveExpectedType = inferenceContext
765
772
  ? createAwaitableReturnType(node, inferenceContext.expectedType,
766
773
  /* isGenerator */ false,
@@ -815,24 +822,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
815
822
  !iterType.isVariadicUnpacked) {
816
823
  typeResult = { type: types_1.TypeVarType.cloneForUnpacked(iterType) };
817
824
  }
825
+ else if ((flags & 2097152 /* EvaluatorFlags.AllowUnpackedTupleOrTypeVarTuple */) !== 0 &&
826
+ (0, types_1.isInstantiableClass)(iterType) &&
827
+ types_1.ClassType.isBuiltIn(iterType, 'tuple')) {
828
+ typeResult = { type: types_1.ClassType.cloneForUnpacked(iterType) };
829
+ }
830
+ else if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
831
+ addError(localize_1.Localizer.Diagnostic.unpackInAnnotation(), node, node.starToken);
832
+ typeResult = { type: types_1.UnknownType.create() };
833
+ }
818
834
  else {
819
- if ((flags & 2097152 /* EvaluatorFlags.AllowUnpackedTupleOrTypeVarTuple */) !== 0 &&
820
- (0, types_1.isInstantiableClass)(iterType) &&
821
- types_1.ClassType.isBuiltIn(iterType, 'tuple')) {
822
- typeResult = { type: types_1.ClassType.cloneForUnpacked(iterType) };
823
- }
824
- else {
825
- const iteratorTypeResult = (_a = getTypeOfIterator(iterTypeResult, /* isAsync */ false, node)) !== null && _a !== void 0 ? _a : {
826
- type: types_1.UnknownType.create(!!iterTypeResult.isIncomplete),
827
- isIncomplete: iterTypeResult.isIncomplete,
828
- };
829
- typeResult = {
830
- type: iteratorTypeResult.type,
831
- typeErrors: iterTypeResult.typeErrors,
832
- unpackedType: iterType,
833
- isIncomplete: iteratorTypeResult.isIncomplete,
834
- };
835
- }
835
+ const iteratorTypeResult = (_a = getTypeOfIterator(iterTypeResult, /* isAsync */ false, node)) !== null && _a !== void 0 ? _a : {
836
+ type: types_1.UnknownType.create(!!iterTypeResult.isIncomplete),
837
+ isIncomplete: iterTypeResult.isIncomplete,
838
+ };
839
+ typeResult = {
840
+ type: iteratorTypeResult.type,
841
+ typeErrors: iterTypeResult.typeErrors,
842
+ unpackedType: iterType,
843
+ isIncomplete: iteratorTypeResult.isIncomplete,
844
+ };
836
845
  }
837
846
  return typeResult;
838
847
  }
@@ -1324,7 +1333,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1324
1333
  !types_1.ClassType.isBuiltIn(metaclass, 'type') &&
1325
1334
  !types_1.ClassType.isSameGenericClass(metaclass, objectType)) {
1326
1335
  const descMemberInfo = getTypeOfClassMemberName(errorNode, metaclass, memberName, usage,
1327
- /* diag */ undefined, flags | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */, objectType);
1336
+ /* diag */ undefined, flags | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */, objectType, recursionCount);
1328
1337
  if (descMemberInfo) {
1329
1338
  const isProperty = (0, types_1.isClassInstance)(descMemberInfo.type) && types_1.ClassType.isPropertyClass(descMemberInfo.type);
1330
1339
  if ((0, typeUtils_1.isDescriptorInstance)(descMemberInfo.type, /* requireSetter */ true) || isProperty) {
@@ -1344,7 +1353,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1344
1353
  }
1345
1354
  subDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
1346
1355
  // See if the member is present in the object itself.
1347
- memberInfo = getTypeOfClassMemberName(errorNode, objectType, memberName, usage, subDiag, effectiveFlags, selfType);
1356
+ memberInfo = getTypeOfClassMemberName(errorNode, objectType, memberName, usage, subDiag, effectiveFlags, selfType, recursionCount);
1348
1357
  }
1349
1358
  // If it wasn't found on the object, see if it's part of the metaclass.
1350
1359
  if (!memberInfo && metaclass && (0, types_1.isInstantiableClass)(metaclass)) {
@@ -1491,8 +1500,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1491
1500
  // type information than `__new__`.
1492
1501
  const initMethodResult = (0, constructors_1.getBoundInitMethod)(evaluatorInterface, callNode, types_1.ClassType.cloneAsInstance(subtype),
1493
1502
  /* skipObjectBase */ false);
1494
- if (initMethodResult && !initMethodResult.typeErrors && (0, types_1.isFunction)(initMethodResult.type)) {
1495
- constructorType = initMethodResult.type;
1503
+ if (initMethodResult && !initMethodResult.typeErrors) {
1504
+ if ((0, types_1.isFunction)(initMethodResult.type) || (0, types_1.isOverloadedFunction)(initMethodResult.type)) {
1505
+ constructorType = initMethodResult.type;
1506
+ }
1496
1507
  }
1497
1508
  const isObjectInit = constructorType &&
1498
1509
  (0, types_1.isFunction)(constructorType) &&
@@ -1506,11 +1517,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1506
1517
  if (!constructorType || isObjectInit || isDefaultParams) {
1507
1518
  const newMethodResult = (0, constructors_1.getBoundNewMethod)(evaluatorInterface, callNode, subtype,
1508
1519
  /* skipObjectBase */ false);
1509
- if (newMethodResult &&
1510
- !newMethodResult.typeErrors &&
1511
- (0, types_1.isFunction)(newMethodResult.type) &&
1512
- newMethodResult.type.details.fullName !== 'builtins.object.__new__') {
1513
- constructorType = newMethodResult.type;
1520
+ if (newMethodResult && !newMethodResult.typeErrors && (0, types_1.isFunction)(newMethodResult.type)) {
1521
+ if ((0, types_1.isFunction)(newMethodResult.type) &&
1522
+ newMethodResult.type.details.fullName !== 'builtins.object.__new__') {
1523
+ constructorType = newMethodResult.type;
1524
+ }
1525
+ else if ((0, types_1.isOverloadedFunction)(newMethodResult.type)) {
1526
+ constructorType = newMethodResult.type;
1527
+ }
1514
1528
  }
1515
1529
  }
1516
1530
  if (constructorType) {
@@ -2336,7 +2350,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2336
2350
  // Is this subtype a tuple?
2337
2351
  const tupleType = (0, typeUtils_1.getSpecializedTupleType)(subtype);
2338
2352
  if (tupleType && tupleType.tupleTypeArguments) {
2339
- const sourceEntryTypes = tupleType.tupleTypeArguments.map((t) => (0, typeUtils_1.addConditionToType)(t.type, (0, typeUtils_1.getTypeCondition)(subtype)));
2353
+ const sourceEntryTypes = tupleType.tupleTypeArguments.map((t) => (0, typeUtils_1.addConditionToType)(t.type, (0, typeUtils_1.getTypeCondition)(subtype), /* skipSelfCondition */ true));
2340
2354
  const unboundedIndex = tupleType.tupleTypeArguments.findIndex((t) => t.isUnbounded);
2341
2355
  if (unboundedIndex >= 0) {
2342
2356
  if (sourceEntryTypes.length < targetTypes.length) {
@@ -2489,7 +2503,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2489
2503
  }
2490
2504
  return subtype;
2491
2505
  }
2492
- if ((0, types_1.isTypeVar)(subtype) && !subtype.details.recursiveTypeAliasName) {
2506
+ if ((0, types_1.isTypeVar)(subtype)) {
2493
2507
  // If this is a recursive type alias placeholder
2494
2508
  // that hasn't yet been resolved, return it as is.
2495
2509
  if (subtype.details.recursiveTypeAliasName) {
@@ -2502,7 +2516,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2502
2516
  subtype.details.constraints.forEach((constraintType, constraintIndex) => {
2503
2517
  if (conditionFilter) {
2504
2518
  const typeVarName = types_1.TypeVarType.getNameWithScope(subtype);
2505
- const applicableConstraint = conditionFilter.find((filter) => filter.typeVarName === typeVarName);
2519
+ const applicableConstraint = conditionFilter.find((filter) => filter.typeVar.nameWithScope === typeVarName);
2506
2520
  // If this type variable is being constrained to a single index,
2507
2521
  // don't include the other indices.
2508
2522
  if (applicableConstraint && applicableConstraint.constraintIndex !== constraintIndex) {
@@ -2512,13 +2526,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2512
2526
  if (types_1.TypeBase.isInstantiable(subtype)) {
2513
2527
  constraintType = (0, typeUtils_1.convertToInstantiable)(constraintType);
2514
2528
  }
2515
- typesToCombine.push((0, typeUtils_1.addConditionToType)(constraintType, [
2516
- {
2517
- typeVarName: types_1.TypeVarType.getNameWithScope(subtype),
2518
- constraintIndex,
2519
- isConstrainedTypeVar: true,
2520
- },
2521
- ]));
2529
+ typesToCombine.push((0, typeUtils_1.addConditionToType)(constraintType, [{ typeVar: subtype, constraintIndex }]));
2522
2530
  });
2523
2531
  return (0, types_1.combineTypes)(typesToCombine);
2524
2532
  }
@@ -2528,17 +2536,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2528
2536
  // Fall back to a bound of "object" if no bound is provided.
2529
2537
  let boundType = (_b = (_a = subtype.details.boundType) !== null && _a !== void 0 ? _a : objectType) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
2530
2538
  boundType = types_1.TypeBase.isInstantiable(subtype) ? (0, typeUtils_1.convertToInstantiable)(boundType) : boundType;
2531
- // Handle Self and type[Self] specially.
2532
- if (subtype.details.isSynthesizedSelf && (0, types_1.isClass)(boundType)) {
2533
- return types_1.ClassType.cloneIncludeSubclasses(boundType);
2534
- }
2535
- return (0, typeUtils_1.addConditionToType)(boundType, [
2536
- {
2537
- typeVarName: types_1.TypeVarType.getNameWithScope(subtype),
2538
- constraintIndex: 0,
2539
- isConstrainedTypeVar: false,
2540
- },
2541
- ]);
2539
+ return (0, typeUtils_1.addConditionToType)(boundType, [{ typeVar: subtype, constraintIndex: 0 }]);
2542
2540
  }
2543
2541
  return subtype;
2544
2542
  });
@@ -2570,7 +2568,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2570
2568
  }
2571
2569
  if (transformedType) {
2572
2570
  // Apply the type condition if it's associated with a constrained TypeVar.
2573
- const typeCondition = (_a = (0, typeUtils_1.getTypeCondition)(subtype)) === null || _a === void 0 ? void 0 : _a.filter((condition) => condition.isConstrainedTypeVar);
2571
+ const typeCondition = (_a = (0, typeUtils_1.getTypeCondition)(subtype)) === null || _a === void 0 ? void 0 : _a.filter((condition) => condition.typeVar.details.constraints.length > 0);
2574
2572
  if (typeCondition && typeCondition.length > 0) {
2575
2573
  transformedType = (0, typeUtils_1.addConditionToType)(transformedType, typeCondition);
2576
2574
  }
@@ -3282,7 +3280,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3282
3280
  name: type.typeAliasInfo.name,
3283
3281
  }), node);
3284
3282
  }
3285
- type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(type, typeVarContext, { unknownIfNotFound: true }), type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.isPep695Syntax, type.typeAliasInfo.typeParameters, defaultTypeArgs);
3283
+ type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(type, typeVarContext, { unknownIfNotFound: true }), type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.moduleName, type.typeAliasInfo.fileUri, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.isPep695Syntax, type.typeAliasInfo.typeParameters, defaultTypeArgs);
3286
3284
  }
3287
3285
  return type;
3288
3286
  }
@@ -3568,7 +3566,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3568
3566
  const typeResult = (_a = (0, enums_1.getTypeOfEnumMember)(evaluatorInterface, node, baseType, memberName, isIncomplete)) !== null && _a !== void 0 ? _a : getTypeOfBoundMember(node.memberName, baseType, memberName, usage, diag,
3569
3567
  /* memberAccessFlags */ undefined, baseTypeResult.bindToSelfType);
3570
3568
  if (typeResult) {
3571
- type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType));
3569
+ type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType),
3570
+ /* skipSelfCondition */ true);
3572
3571
  }
3573
3572
  if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete) {
3574
3573
  isIncomplete = true;
@@ -4634,7 +4633,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4634
4633
  }
4635
4634
  aliasTypeArgs.push(typeVarType);
4636
4635
  });
4637
- const type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(baseType, typeVarContext), baseType.typeAliasInfo.name, baseType.typeAliasInfo.fullName, baseType.typeAliasInfo.typeVarScopeId, baseType.typeAliasInfo.isPep695Syntax, baseType.typeAliasInfo.typeParameters, aliasTypeArgs);
4636
+ const type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(baseType, typeVarContext), baseType.typeAliasInfo.name, baseType.typeAliasInfo.fullName, baseType.typeAliasInfo.moduleName, baseType.typeAliasInfo.fileUri, baseType.typeAliasInfo.typeVarScopeId, baseType.typeAliasInfo.isPep695Syntax, baseType.typeAliasInfo.typeParameters, aliasTypeArgs);
4638
4637
  return { type, node };
4639
4638
  }
4640
4639
  function getTypeOfIndexWithBaseType(node, baseTypeResult, usage, flags) {
@@ -4645,7 +4644,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4645
4644
  }
4646
4645
  if ((0, types_1.isTypeVar)(baseTypeResult.type) && (0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
4647
4646
  const typeArgTypes = getTypeArgs(node, flags).map((t) => (0, typeUtils_1.convertToInstance)(t.type));
4648
- const type = types_1.TypeBase.cloneForTypeAlias(baseTypeResult.type, baseTypeResult.type.details.recursiveTypeAliasName, '', baseTypeResult.type.details.recursiveTypeAliasScopeId, !!baseTypeResult.type.details.recursiveTypeAliasIsPep695Syntax, baseTypeResult.type.details.recursiveTypeParameters, typeArgTypes);
4647
+ const type = types_1.TypeBase.cloneForTypeAlias(baseTypeResult.type, baseTypeResult.type.details.recursiveTypeAliasName, '', '', uri_1.Uri.empty(), baseTypeResult.type.details.recursiveTypeAliasScopeId, !!baseTypeResult.type.details.recursiveTypeAliasIsPep695Syntax, baseTypeResult.type.details.recursiveTypeParameters, typeArgTypes);
4649
4648
  return { type };
4650
4649
  }
4651
4650
  let isIncomplete = baseTypeResult.isIncomplete;
@@ -6700,6 +6699,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6700
6699
  const newClassType = types_1.ClassType.createInstantiable(newClassName, '', '', AnalyzerNodeInfo.getFileInfo(errorNode).fileUri, 0 /* ClassTypeFlags.None */, ParseTreeUtils.getTypeSourceId(errorNode), types_1.ClassType.cloneAsInstantiable(returnType), types_1.ClassType.cloneAsInstantiable(returnType));
6701
6700
  newClassType.details.baseClasses.push(getBuiltInType(errorNode, 'object'));
6702
6701
  newClassType.details.effectiveMetaclass = expandedCallType;
6702
+ newClassType.details.declaration = returnType.details.declaration;
6703
6703
  (0, typeUtils_1.computeMroLinearization)(newClassType);
6704
6704
  returnType = newClassType;
6705
6705
  }
@@ -6858,7 +6858,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6858
6858
  }
6859
6859
  else if (typeResult.type.details.paramSpec) {
6860
6860
  const paramSpecScopeId = typeResult.type.details.paramSpec.scopeId;
6861
- if (paramSpecScopeId === typeResult.type.details.typeVarScopeId ||
6861
+ if (typeResult.type.details.typeVarScopeId === types_1.WildcardTypeVarScopeId ||
6862
+ paramSpecScopeId === typeResult.type.details.typeVarScopeId ||
6862
6863
  paramSpecScopeId === typeResult.type.details.constructorTypeVarScopeId) {
6863
6864
  hasParamSpecArgsKwargs = true;
6864
6865
  paramSpecArgList = [];
@@ -7963,11 +7964,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7963
7964
  !arg0Type.details.isParamSpec &&
7964
7965
  arg0Type.details.constraints.length === 0) {
7965
7966
  typeGuardType = (0, typeUtils_1.addConditionToType)(typeGuardType, [
7966
- {
7967
- typeVarName: types_1.TypeVarType.getNameWithScope(arg0Type),
7968
- constraintIndex: 0,
7969
- isConstrainedTypeVar: false,
7970
- },
7967
+ { typeVar: arg0Type, constraintIndex: 0 },
7971
7968
  ]);
7972
7969
  }
7973
7970
  }
@@ -8136,7 +8133,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8136
8133
  let argErrorNode;
8137
8134
  for (const arg of argList) {
8138
8135
  const argType = (_a = getTypeOfArgument(arg)) === null || _a === void 0 ? void 0 : _a.type;
8139
- const isArgTypeCompatible = argType && ((0, types_1.isTypeSame)(argType, paramSpec) || (0, types_1.isAnyOrUnknown)(argType));
8136
+ const isArgTypeCompatible = argType && ((0, types_1.isTypeSame)(argType, paramSpec, { ignoreTypeFlags: true }) || (0, types_1.isAnyOrUnknown)(argType));
8140
8137
  if (arg.argumentCategory === 1 /* ArgumentCategory.UnpackedList */ && !sawArgs && isArgTypeCompatible) {
8141
8138
  sawArgs = true;
8142
8139
  }
@@ -10745,7 +10742,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10745
10742
  }
10746
10743
  }
10747
10744
  const fileInfo = AnalyzerNodeInfo.getFileInfo(name);
10748
- const typeAlias = types_1.TypeBase.cloneForTypeAlias(type, name.value, ParseTreeUtils.getClassFullName(name, fileInfo.moduleName, name.value), typeAliasScopeId, isPep695Syntax, typeParameters.length > 0 ? typeParameters : undefined);
10745
+ const typeAlias = types_1.TypeBase.cloneForTypeAlias(type, name.value, ParseTreeUtils.getClassFullName(name, fileInfo.moduleName, name.value), fileInfo.moduleName, fileInfo.fileUri, typeAliasScopeId, isPep695Syntax, typeParameters.length > 0 ? typeParameters : undefined);
10749
10746
  // All PEP 695 type aliases are special forms because they are
10750
10747
  // TypeAliasType objects at runtime.
10751
10748
  if (isPep695Syntax || isPep695TypeVarType) {
@@ -10754,11 +10751,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10754
10751
  return typeAlias;
10755
10752
  }
10756
10753
  function createSpecialBuiltInClass(node, assignedName, aliasMapEntry) {
10754
+ var _a;
10757
10755
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
10758
10756
  let specialClassType = types_1.ClassType.createInstantiable(assignedName, ParseTreeUtils.getClassFullName(node, fileInfo.moduleName, assignedName), fileInfo.moduleName, fileInfo.fileUri, 1 /* ClassTypeFlags.BuiltInClass */ | 2 /* ClassTypeFlags.SpecialBuiltIn */,
10759
10757
  /* typeSourceId */ 0,
10760
10758
  /* declaredMetaclass */ undefined,
10761
10759
  /* effectiveMetaclass */ undefined);
10760
+ const specialBuiltInClassDeclaration = ((_a = AnalyzerNodeInfo.getDeclaration(node)) !== null && _a !== void 0 ? _a : (node.parent ? AnalyzerNodeInfo.getDeclaration(node.parent) : undefined));
10761
+ specialClassType.details.declaration = specialBuiltInClassDeclaration;
10762
10762
  if (fileInfo.isTypingExtensionsStubFile) {
10763
10763
  specialClassType.details.flags |= 65536 /* ClassTypeFlags.TypingExtensionClass */;
10764
10764
  }
@@ -11188,6 +11188,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11188
11188
  setSymbolResolutionPartialType(classSymbol, classDecl, classType);
11189
11189
  }
11190
11190
  classType.details.flags |= 131072 /* ClassTypeFlags.PartiallyEvaluated */;
11191
+ classType.details.declaration = classDecl;
11191
11192
  try {
11192
11193
  writeTypeCache(node, { type: classType }, /* flags */ undefined);
11193
11194
  writeTypeCache(node.name, { type: classType }, /* flags */ undefined);
@@ -12785,7 +12786,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12785
12786
  // This eliminates any "partially unknown" errors in strict mode
12786
12787
  // in the common case.
12787
12788
  const sendType = isYieldResultUsed ? types_1.UnknownType.create() : types_1.AnyType.create();
12788
- typeArgs.push(inferredYieldType, sendType, (0, types_1.isNever)(inferredReturnType) ? getNoneType() : inferredReturnType);
12789
+ typeArgs.push(inferredYieldType, sendType, inferredReturnType);
12789
12790
  if (useAwaitableGenerator) {
12790
12791
  typeArgs.push(types_1.AnyType.create());
12791
12792
  }
@@ -14989,30 +14990,32 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14989
14990
  }
14990
14991
  // Returns the type of the symbol. If the type is explicitly declared, that type
14991
14992
  // is returned. If not, the type is inferred from assignments to the symbol. All
14992
- // assigned types are evaluated and combined into a union. If a "usageNode"
14993
- // node is specified, only declarations that are outside of the current execution
14994
- // scope or that are reachable (as determined by code flow analysis) are considered.
14995
- // This helps in cases where there are cyclical dependencies between symbols.
14993
+ // assigned types are evaluated and combined into a union.
14996
14994
  function getEffectiveTypeOfSymbol(symbol) {
14997
14995
  return getEffectiveTypeOfSymbolForUsage(symbol).type;
14998
14996
  }
14997
+ // If a "usageNode" node is specified, only declarations that are outside
14998
+ // of the current execution scope or that are reachable (as determined by
14999
+ // code flow analysis) are considered. This helps in cases where there
15000
+ // are cyclical dependencies between symbols.
14999
15001
  function getEffectiveTypeOfSymbolForUsage(symbol, usageNode, useLastDecl = false) {
15000
15002
  let declaredTypeInfo;
15001
15003
  // If there's a declared type, it takes precedence over inferred types.
15002
15004
  if (symbol.hasTypedDeclarations()) {
15003
15005
  declaredTypeInfo = getDeclaredTypeOfSymbol(symbol, usageNode);
15004
15006
  const declaredType = declaredTypeInfo === null || declaredTypeInfo === void 0 ? void 0 : declaredTypeInfo.type;
15005
- const hasMetadata = !!declaredTypeInfo.isTypeAlias;
15006
- if (declaredType || !hasMetadata) {
15007
- let isIncomplete = false;
15008
- if (declaredType) {
15009
- if ((0, types_1.isFunction)(declaredType) && types_1.FunctionType.isPartiallyEvaluated(declaredType)) {
15010
- isIncomplete = true;
15011
- }
15012
- else if ((0, types_1.isClass)(declaredType) && types_1.ClassType.isPartiallyEvaluated(declaredType)) {
15013
- isIncomplete = true;
15014
- }
15007
+ let isIncomplete = false;
15008
+ if (declaredType) {
15009
+ if ((0, types_1.isFunction)(declaredType) && types_1.FunctionType.isPartiallyEvaluated(declaredType)) {
15010
+ isIncomplete = true;
15011
+ }
15012
+ else if ((0, types_1.isClass)(declaredType) && types_1.ClassType.isPartiallyEvaluated(declaredType)) {
15013
+ isIncomplete = true;
15015
15014
  }
15015
+ }
15016
+ // If the "declared" type uses a "TypeAlias" type annotation, then
15017
+ // we need to use the inferred type path to evaluate its type.
15018
+ if (declaredType || !declaredTypeInfo.isTypeAlias) {
15016
15019
  const typedDecls = symbol.getTypedDeclarations();
15017
15020
  const result = {
15018
15021
  type: declaredType !== null && declaredType !== void 0 ? declaredType : types_1.UnknownType.create(),
@@ -15025,6 +15028,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15025
15028
  return result;
15026
15029
  }
15027
15030
  }
15031
+ return inferTypeOfSymbolForUsage(symbol, usageNode, useLastDecl);
15032
+ }
15033
+ function inferTypeOfSymbolForUsage(symbol, usageNode, useLastDecl = false) {
15028
15034
  // Look in the inferred type cache to see if we've computed this already.
15029
15035
  let cacheEntries = effectiveTypeCache.get(symbol.id);
15030
15036
  const usageNodeId = usageNode ? usageNode.id : undefined;
@@ -15072,9 +15078,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15072
15078
  }
15073
15079
  // Determine which declarations to use for inference.
15074
15080
  const declsToConsider = [];
15081
+ let includesVariableDecl = false;
15082
+ let includesIllegalTypeAliasDecl = false;
15075
15083
  let sawExplicitTypeAlias = false;
15076
15084
  decls.forEach((decl, index) => {
15077
15085
  var _a, _b, _c;
15086
+ const resolvedDecl = (_a = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
15087
+ allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
15088
+ })) !== null && _a !== void 0 ? _a : decl;
15089
+ if (!isPossibleTypeAliasDeclaration(resolvedDecl)) {
15090
+ includesIllegalTypeAliasDecl = true;
15091
+ }
15092
+ if (resolvedDecl.type === 1 /* DeclarationType.Variable */) {
15093
+ // Exempt typing.pyi, which uses variables to define some
15094
+ // special forms like Any.
15095
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(resolvedDecl.node);
15096
+ if (!fileInfo.isTypingStubFile) {
15097
+ includesVariableDecl = true;
15098
+ }
15099
+ }
15078
15100
  if (declIndexToConsider !== undefined && declIndexToConsider !== index) {
15079
15101
  return;
15080
15102
  }
@@ -15094,18 +15116,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15094
15116
  if (usageNode !== undefined) {
15095
15117
  if (decl.type !== 8 /* DeclarationType.Alias */) {
15096
15118
  // Is the declaration in the same execution scope as the "usageNode" node?
15119
+ // If so, we can skip it because code flow analysis will allow us
15120
+ // to determine the type in this context.
15097
15121
  const usageScope = ParseTreeUtils.getExecutionScopeNode(usageNode);
15098
15122
  const declScope = ParseTreeUtils.getExecutionScopeNode(decl.node);
15099
15123
  if (usageScope === declScope) {
15100
- if (!isFlowPathBetweenNodes(decl.node, usageNode)) {
15101
- return;
15102
- }
15124
+ return;
15103
15125
  }
15104
15126
  }
15105
15127
  }
15106
- const resolvedDecl = (_a = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
15107
- allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
15108
- })) !== null && _a !== void 0 ? _a : decl;
15109
15128
  const isExplicitTypeAlias = isExplicitTypeAliasDeclaration(resolvedDecl);
15110
15129
  const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasOrTypedDict(resolvedDecl);
15111
15130
  if (isExplicitTypeAlias) {
@@ -15121,6 +15140,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15121
15140
  declsToConsider.push(resolvedDecl);
15122
15141
  });
15123
15142
  const result = getTypeOfSymbolForDecls(symbol, declsToConsider, effectiveTypeCacheKey);
15143
+ result.includesVariableDecl = includesVariableDecl;
15144
+ result.includesIllegalTypeAliasDecl = includesIllegalTypeAliasDecl;
15124
15145
  // Add the result to the effective type cache if it doesn't include speculative results.
15125
15146
  if (!result.includesSpeculativeResult) {
15126
15147
  addToEffectiveTypeCache(result);
@@ -15141,7 +15162,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15141
15162
  const typesToCombine = [];
15142
15163
  let isIncomplete = false;
15143
15164
  let sawPendingEvaluation = false;
15144
- let includesVariableDecl = false;
15145
15165
  let includesSpeculativeResult = false;
15146
15166
  decls.forEach((decl) => {
15147
15167
  if (pushSymbolResolution(symbol, decl)) {
@@ -15152,12 +15172,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15152
15172
  }
15153
15173
  if (type) {
15154
15174
  if (decl.type === 1 /* DeclarationType.Variable */) {
15155
- // Exempt typing.pyi, which uses variables to define some
15156
- // special forms like Any.
15157
- const fileInfo = AnalyzerNodeInfo.getFileInfo(decl.node);
15158
- if (!fileInfo.isTypingStubFile) {
15159
- includesVariableDecl = true;
15160
- }
15161
15175
  let isConstant = false;
15162
15176
  if (decl.type === 1 /* DeclarationType.Variable */) {
15163
15177
  if (decl.isConstant || isFinalVariableDeclaration(decl)) {
@@ -15219,15 +15233,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15219
15233
  else {
15220
15234
  type = types_1.UnboundType.create();
15221
15235
  }
15222
- return {
15223
- type,
15224
- isIncomplete,
15225
- includesVariableDecl,
15226
- includesIllegalTypeAliasDecl: !decls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
15227
- includesSpeculativeResult,
15228
- isRecursiveDefinition: false,
15229
- evaluationAttempts,
15230
- };
15236
+ return { type, isIncomplete, includesSpeculativeResult, evaluationAttempts };
15231
15237
  }
15232
15238
  // If a declaration has an explicit type (e.g. a variable with an annotation),
15233
15239
  // this function evaluates the type and returns it. If the symbol has no
@@ -15343,7 +15349,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15343
15349
  var _a;
15344
15350
  let returnType;
15345
15351
  let isIncomplete = false;
15346
- let analyzeUnannotatedFunctions = true;
15352
+ const analyzeUnannotatedFunctions = true;
15347
15353
  // Don't attempt to infer the return type for a stub file.
15348
15354
  if (types_1.FunctionType.isStubDefinition(type)) {
15349
15355
  return types_1.UnknownType.create();
@@ -15366,10 +15372,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15366
15372
  }
15367
15373
  else if (type.details.declaration) {
15368
15374
  const functionNode = type.details.declaration.node;
15369
- analyzeUnannotatedFunctions =
15370
- AnalyzerNodeInfo.getFileInfo(functionNode).diagnosticRuleSet.analyzeUnannotatedFunctions;
15375
+ const skipUnannotatedFunction = !AnalyzerNodeInfo.getFileInfo(functionNode).diagnosticRuleSet.analyzeUnannotatedFunctions &&
15376
+ ParseTreeUtils.isUnannotatedFunction(functionNode);
15371
15377
  // Skip return type inference if we are in "skip unannotated function" mode.
15372
- if (analyzeUnannotatedFunctions && !checkCodeFlowTooComplex(functionNode.suite)) {
15378
+ if (!skipUnannotatedFunction && !checkCodeFlowTooComplex(functionNode.suite)) {
15373
15379
  const codeFlowComplexity = AnalyzerNodeInfo.getCodeFlowComplexity(functionNode);
15374
15380
  // For very complex functions that have no annotated parameter types,
15375
15381
  // don't attempt to infer the return type because it can be extremely
@@ -16208,7 +16214,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16208
16214
  if (types_1.TypeBase.isInstantiable(destType) === types_1.TypeBase.isInstantiable(srcType) &&
16209
16215
  srcType.condition &&
16210
16216
  srcType.condition.some((cond) => {
16211
- return !cond.isConstrainedTypeVar && cond.typeVarName === destTypeVar.nameWithScope;
16217
+ return (cond.typeVar.details.constraints.length === 0 &&
16218
+ cond.typeVar.nameWithScope === destTypeVar.nameWithScope);
16212
16219
  })) {
16213
16220
  return true;
16214
16221
  }
@@ -16691,7 +16698,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16691
16698
  let canUseFastPath = true;
16692
16699
  // First attempt to match all of the non-generic types in the dest
16693
16700
  // to non-generic types in the source.
16694
- destType.subtypes.forEach((destSubtype) => {
16701
+ (0, typeUtils_1.sortTypes)(destType.subtypes).forEach((destSubtype) => {
16695
16702
  if ((0, typeUtils_1.requiresSpecialization)(destSubtype)) {
16696
16703
  remainingDestSubtypes.push(destSubtype);
16697
16704
  }
@@ -16999,13 +17006,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16999
17006
  const destTypeVarName = types_1.TypeVarType.getNameWithScope(destType);
17000
17007
  // Determine which conditions on this type apply to this type variable.
17001
17008
  // There might be more than one of them.
17002
- const applicableConditions = ((_a = (0, typeUtils_1.getTypeCondition)(srcSubtype)) !== null && _a !== void 0 ? _a : []).filter((constraint) => constraint.typeVarName === destTypeVarName);
17009
+ const applicableConditions = ((_a = (0, typeUtils_1.getTypeCondition)(srcSubtype)) !== null && _a !== void 0 ? _a : []).filter((constraint) => constraint.typeVar.nameWithScope === destTypeVarName);
17003
17010
  // If there are no applicable conditions, it's not assignable.
17004
17011
  if (applicableConditions.length === 0) {
17005
17012
  return true;
17006
17013
  }
17007
17014
  return !applicableConditions.some((condition) => {
17008
- if (condition.typeVarName === types_1.TypeVarType.getNameWithScope(destType)) {
17015
+ if (condition.typeVar.nameWithScope === types_1.TypeVarType.getNameWithScope(destType)) {
17009
17016
  if (destType.details.boundType) {
17010
17017
  (0, debug_1.assert)(condition.constraintIndex === 0, 'Expected constraint for bound TypeVar to have index of 0');
17011
17018
  return assignType(destType.details.boundType, srcSubtype,
@@ -17199,7 +17206,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17199
17206
  }
17200
17207
  }
17201
17208
  function assignFunction(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
17202
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
17209
+ var _a, _b, _c, _d, _e, _f, _g, _h;
17203
17210
  let canAssign = true;
17204
17211
  const checkReturnType = (flags & 32 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */) === 0;
17205
17212
  const reverseMatching = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) !== 0;
@@ -17210,19 +17217,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17210
17217
  const srcParamDetails = (0, parameterUtils_1.getParameterListDetails)(srcType);
17211
17218
  adjustSourceParamDetailsForDestVariadic(reverseMatching ? destParamDetails : srcParamDetails, reverseMatching ? srcParamDetails : destParamDetails);
17212
17219
  const targetIncludesParamSpec = reverseMatching ? !!srcType.details.paramSpec : !!destType.details.paramSpec;
17213
- const destPositionalCount = (_b = (_a = destParamDetails.argsIndex) !== null && _a !== void 0 ? _a : destParamDetails.firstKeywordOnlyIndex) !== null && _b !== void 0 ? _b : destParamDetails.params.length;
17214
- const srcPositionalCount = (_d = (_c = srcParamDetails.argsIndex) !== null && _c !== void 0 ? _c : srcParamDetails.firstKeywordOnlyIndex) !== null && _d !== void 0 ? _d : srcParamDetails.params.length;
17220
+ const destPositionalCount = (_a = destParamDetails.firstKeywordOnlyIndex) !== null && _a !== void 0 ? _a : destParamDetails.params.length;
17221
+ const srcPositionalCount = (_b = srcParamDetails.firstKeywordOnlyIndex) !== null && _b !== void 0 ? _b : srcParamDetails.params.length;
17215
17222
  const positionalsToMatch = Math.min(destPositionalCount, srcPositionalCount);
17216
17223
  // Match positional parameters.
17217
17224
  for (let paramIndex = 0; paramIndex < positionalsToMatch; paramIndex++) {
17225
+ // Skip over the *args parameter since it's handled separately below.
17226
+ if (paramIndex === destParamDetails.argsIndex) {
17227
+ continue;
17228
+ }
17218
17229
  const destParam = destParamDetails.params[paramIndex];
17219
17230
  const srcParam = srcParamDetails.params[paramIndex];
17220
17231
  // Find the original index of this source param. If we synthesized it above (for
17221
17232
  // a variadic parameter), it may not be found.
17222
17233
  const srcParamType = srcParam.type;
17223
17234
  const destParamType = destParam.type;
17224
- const destParamName = (_e = destParam.param.name) !== null && _e !== void 0 ? _e : '';
17225
- const srcParamName = (_f = srcParam.param.name) !== null && _f !== void 0 ? _f : '';
17235
+ const destParamName = (_c = destParam.param.name) !== null && _c !== void 0 ? _c : '';
17236
+ const srcParamName = (_d = srcParam.param.name) !== null && _d !== void 0 ? _d : '';
17226
17237
  if (destParamName && !(0, symbolNameUtils_1.isPrivateOrProtectedName)(destParamName) && !(0, symbolNameUtils_1.isPrivateOrProtectedName)(srcParamName)) {
17227
17238
  const isDestPositionalOnly = destParam.source === parameterUtils_1.ParameterSource.PositionOnly;
17228
17239
  if (!isDestPositionalOnly &&
@@ -17236,7 +17247,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17236
17247
  canAssign = false;
17237
17248
  }
17238
17249
  }
17239
- if (!!destParam.param.hasDefault && !srcParam.param.hasDefault) {
17250
+ if (!!destParam.param.hasDefault &&
17251
+ !srcParam.param.hasDefault &&
17252
+ paramIndex !== srcParamDetails.argsIndex) {
17240
17253
  diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.Localizer.DiagnosticAddendum.functionParamDefaultMissing().format({
17241
17254
  name: srcParamName,
17242
17255
  }));
@@ -17310,6 +17323,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17310
17323
  // *args parameter type.
17311
17324
  const srcArgsType = srcParamDetails.params[srcParamDetails.argsIndex].type;
17312
17325
  for (let paramIndex = srcPositionalCount; paramIndex < destPositionalCount; paramIndex++) {
17326
+ if (paramIndex === srcParamDetails.argsIndex) {
17327
+ continue;
17328
+ }
17313
17329
  const destParamType = destParamDetails.params[paramIndex].type;
17314
17330
  if ((0, types_1.isVariadicTypeVar)(destParamType) && !(0, types_1.isVariadicTypeVar)(srcArgsType)) {
17315
17331
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeVarTupleRequiresKnownLength());
@@ -17322,7 +17338,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17322
17338
  if (destParamDetails.params[paramIndex].source !== parameterUtils_1.ParameterSource.PositionOnly &&
17323
17339
  srcParamDetails.kwargsIndex === undefined) {
17324
17340
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.namedParamMissingInSource().format({
17325
- name: (_g = destParamDetails.params[paramIndex].param.name) !== null && _g !== void 0 ? _g : '',
17341
+ name: (_e = destParamDetails.params[paramIndex].param.name) !== null && _e !== void 0 ? _e : '',
17326
17342
  }));
17327
17343
  canAssign = false;
17328
17344
  }
@@ -17330,11 +17346,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17330
17346
  }
17331
17347
  }
17332
17348
  else if (!srcParamDetails.paramSpec) {
17333
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.functionTooManyParams().format({
17334
- expected: srcPositionalCount,
17335
- received: destPositionalCount,
17336
- }));
17337
- canAssign = false;
17349
+ // If the dest contains a *args, remove it from the positional count
17350
+ // because it's OK for zero source args to match it.
17351
+ let adjDestPositionalCount = destPositionalCount;
17352
+ if (destParamDetails.argsIndex !== undefined && destParamDetails.argsIndex < destPositionalCount) {
17353
+ adjDestPositionalCount--;
17354
+ }
17355
+ if (srcPositionalCount < adjDestPositionalCount) {
17356
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.functionTooManyParams().format({
17357
+ expected: srcPositionalCount,
17358
+ received: destPositionalCount,
17359
+ }));
17360
+ canAssign = false;
17361
+ }
17338
17362
  }
17339
17363
  }
17340
17364
  // If both src and dest have an "*args" parameter, make sure
@@ -17366,7 +17390,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17366
17390
  destParamDetails.argsIndex !== undefined &&
17367
17391
  !destParamDetails.hasUnpackedVariadicTypeVar) {
17368
17392
  diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.Localizer.DiagnosticAddendum.argsParamMissing().format({
17369
- paramName: (_h = destParamDetails.params[destParamDetails.argsIndex].param.name) !== null && _h !== void 0 ? _h : '',
17393
+ paramName: (_f = destParamDetails.params[destParamDetails.argsIndex].param.name) !== null && _f !== void 0 ? _f : '',
17370
17394
  }));
17371
17395
  canAssign = false;
17372
17396
  }
@@ -17477,7 +17501,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17477
17501
  // If the source and the dest are using the same ParamSpec, any additional
17478
17502
  // concatenated parameters must match.
17479
17503
  if (targetIncludesParamSpec &&
17480
- ((_j = srcType.details.paramSpec) === null || _j === void 0 ? void 0 : _j.nameWithScope) === ((_k = destType.details.paramSpec) === null || _k === void 0 ? void 0 : _k.nameWithScope)) {
17504
+ ((_g = srcType.details.paramSpec) === null || _g === void 0 ? void 0 : _g.nameWithScope) === ((_h = destType.details.paramSpec) === null || _h === void 0 ? void 0 : _h.nameWithScope)) {
17481
17505
  if (srcParamDetails.params.length !== destParamDetails.params.length) {
17482
17506
  canAssign = false;
17483
17507
  }