@zzzen/pyright-internal 1.2.0-dev.20250330 → 1.2.0-dev.20250406

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.
@@ -2393,7 +2393,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2393
2393
  }
2394
2394
  }
2395
2395
  if (!typeResult.isIncomplete) {
2396
- reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, nameNode, destType, nameNode, ignoreEmptyContainers);
2396
+ reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, nameNode, typeResult.type, nameNode, ignoreEmptyContainers);
2397
2397
  }
2398
2398
  writeTypeCache(nameNode, { type: destType, isIncomplete: typeResult.isIncomplete }, 0 /* EvalFlags.None */);
2399
2399
  }
@@ -2934,31 +2934,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2934
2934
  break;
2935
2935
  }
2936
2936
  case 54 /* ParseNodeType.TypeAnnotation */: {
2937
- let annotationType = getTypeOfAnnotation(target.d.annotation, {
2937
+ getTypeOfAnnotation(target.d.annotation, {
2938
2938
  varTypeAnnotation: true,
2939
2939
  allowFinal: isFinalAllowedForAssignmentTarget(target.d.valueExpr),
2940
2940
  allowClassVar: isClassVarAllowedForAssignmentTarget(target.d.valueExpr),
2941
2941
  });
2942
- if (annotationType) {
2943
- const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(target);
2944
- annotationType = (0, typeUtils_1.makeTypeVarsBound)(annotationType, liveScopeIds);
2945
- }
2946
- // Handle a bare "Final" or "ClassVar" in a special manner.
2947
- const isBareFinalOrClassVar = (0, types_1.isClassInstance)(annotationType) &&
2948
- (types_1.ClassType.isBuiltIn(annotationType, 'Final') || types_1.ClassType.isBuiltIn(annotationType, 'ClassVar'));
2949
- if (!isBareFinalOrClassVar) {
2950
- const isTypeAliasAnnotation = (0, types_1.isClassInstance)(annotationType) && types_1.ClassType.isBuiltIn(annotationType, 'TypeAlias');
2951
- if (!isTypeAliasAnnotation) {
2952
- if (assignType(annotationType, typeResult.type)) {
2953
- // Don't attempt to narrow based on the annotated type if the type
2954
- // is a enum because the annotated type in an enum doesn't reflect
2955
- // the type of the symbol.
2956
- if (!(0, types_1.isClassInstance)(typeResult.type) || !types_1.ClassType.isEnumClass(typeResult.type)) {
2957
- typeResult = narrowTypeBasedOnAssignment(annotationType, typeResult);
2958
- }
2959
- }
2960
- }
2961
- }
2962
2942
  assignTypeToExpression(target.d.valueExpr, typeResult, srcExpr, ignoreEmptyContainers, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
2963
2943
  break;
2964
2944
  }
@@ -4796,16 +4776,29 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4796
4776
  const variadicIndex = typeParams.findIndex((param) => (0, types_1.isTypeVarTuple)(param));
4797
4777
  // Is there a *tuple[T, ...] somewhere in the type arguments that we can expand if needed?
4798
4778
  let srcUnboundedTupleType;
4799
- let srcUnboundedTupleIndex = typeArgs.findIndex((arg) => {
4800
- if ((0, types_1.isUnpackedClass)(arg.type) &&
4801
- arg.type.priv.tupleTypeArgs &&
4802
- arg.type.priv.tupleTypeArgs.length === 1 &&
4803
- arg.type.priv.tupleTypeArgs[0].isUnbounded) {
4804
- srcUnboundedTupleType = arg.type.priv.tupleTypeArgs[0].type;
4805
- return true;
4779
+ const findUnboundedTupleIndex = (startArgIndex) => {
4780
+ return typeArgs.findIndex((arg, index) => {
4781
+ if (index < startArgIndex) {
4782
+ return false;
4783
+ }
4784
+ if ((0, types_1.isUnpackedClass)(arg.type) &&
4785
+ arg.type.priv.tupleTypeArgs &&
4786
+ arg.type.priv.tupleTypeArgs.length === 1 &&
4787
+ arg.type.priv.tupleTypeArgs[0].isUnbounded) {
4788
+ srcUnboundedTupleType = arg.type.priv.tupleTypeArgs[0].type;
4789
+ return true;
4790
+ }
4791
+ return false;
4792
+ });
4793
+ };
4794
+ let srcUnboundedTupleIndex = findUnboundedTupleIndex(0);
4795
+ // Allow only one unpacked tuple that maps to a TypeVarTuple.
4796
+ if (srcUnboundedTupleIndex >= 0) {
4797
+ const secondUnboundedTupleIndex = findUnboundedTupleIndex(srcUnboundedTupleIndex + 1);
4798
+ if (secondUnboundedTupleIndex >= 0) {
4799
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.variadicTypeArgsTooMany(), typeArgs[secondUnboundedTupleIndex].node);
4806
4800
  }
4807
- return false;
4808
- });
4801
+ }
4809
4802
  if (srcUnboundedTupleType &&
4810
4803
  srcUnboundedTupleIndex >= 0 &&
4811
4804
  variadicIndex >= 0 &&
@@ -11334,7 +11327,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11334
11327
  validateTypeVarTupleIsUnpacked(typeArg.type, typeArg.node);
11335
11328
  }
11336
11329
  else if (paramLimit === undefined && (0, types_1.isUnpackedClass)(typeArg.type)) {
11337
- if (typeArg.type.priv.tupleTypeArgs?.some((typeArg) => (0, types_1.isTypeVarTuple)(typeArg.type) || typeArg.isUnbounded)) {
11330
+ if ((0, typeUtils_1.isUnboundedTupleClass)(typeArg.type)) {
11338
11331
  noteSawUnpacked(typeArg);
11339
11332
  }
11340
11333
  validateTypeArg(typeArg, { allowUnpackedTuples: true });
@@ -17805,13 +17798,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17805
17798
  // Determine if the metaclass can be assigned to the object.
17806
17799
  const metaclass = concreteSrcType.shared.effectiveMetaclass;
17807
17800
  if (metaclass) {
17808
- if ((0, types_1.isAnyOrUnknown)(metaclass)) {
17809
- return true;
17810
- }
17811
- if (assignClass(types_1.ClassType.cloneAsInstantiable(destType), metaclass,
17812
- /* diag */ undefined, constraints, flags, recursionCount,
17813
- /* reportErrorsUsingObjType */ true)) {
17814
- return true;
17801
+ if (!(0, types_1.isAnyOrUnknown)(metaclass)) {
17802
+ if (assignClass(types_1.ClassType.cloneAsInstantiable(destType), metaclass,
17803
+ /* diag */ undefined, constraints, flags, recursionCount,
17804
+ /* reportErrorsUsingObjType */ true)) {
17805
+ return true;
17806
+ }
17815
17807
  }
17816
17808
  }
17817
17809
  }