@zzzen/pyright-internal 1.2.0-dev.20241201 → 1.2.0-dev.20241215

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.
@@ -2914,7 +2914,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2914
2914
  let annotationType = getTypeOfAnnotation(target.d.annotation, {
2915
2915
  varTypeAnnotation: true,
2916
2916
  allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(target.d.valueExpr),
2917
- allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(target.d.valueExpr),
2917
+ allowClassVar: isClassVarAllowedForAssignmentTarget(target.d.valueExpr),
2918
2918
  });
2919
2919
  if (annotationType) {
2920
2920
  const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(target);
@@ -2964,6 +2964,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2964
2964
  }
2965
2965
  }
2966
2966
  }
2967
+ function isClassVarAllowedForAssignmentTarget(targetNode) {
2968
+ var _a;
2969
+ const classNode = ParseTreeUtils.getEnclosingClass(targetNode, /* stopAtFunction */ true);
2970
+ if (!classNode) {
2971
+ return false;
2972
+ }
2973
+ // ClassVar is not allowed in a TypedDict or a NamedTuple class.
2974
+ const classType = (_a = getTypeOfClass(classNode)) === null || _a === void 0 ? void 0 : _a.classType;
2975
+ if (!classType) {
2976
+ return false;
2977
+ }
2978
+ return !types_1.ClassType.isTypedDictClass(classType) && !classType.shared.namedTupleEntries;
2979
+ }
2967
2980
  function verifyRaiseExceptionType(node, allowNone) {
2968
2981
  const baseExceptionType = getBuiltInType(node, 'BaseException');
2969
2982
  const exceptionType = getTypeOfExpression(node).type;
@@ -10538,20 +10551,39 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10538
10551
  return { type, isIncomplete, typeErrors };
10539
10552
  }
10540
10553
  function getTypeOfSlice(node) {
10554
+ const noneType = getNoneType();
10555
+ let startType = noneType;
10556
+ let endType = noneType;
10557
+ let stepType = noneType;
10558
+ let isIncomplete = false;
10541
10559
  // Evaluate the expressions to report errors and record symbol
10542
- // references. We can skip this if we're executing speculatively.
10543
- if (!isSpeculativeModeInUse(node)) {
10544
- if (node.d.startValue) {
10545
- getTypeOfExpression(node.d.startValue);
10560
+ // references.
10561
+ if (node.d.startValue) {
10562
+ const startTypeResult = getTypeOfExpression(node.d.startValue);
10563
+ startType = startTypeResult.type;
10564
+ if (startTypeResult.isIncomplete) {
10565
+ isIncomplete = true;
10546
10566
  }
10547
- if (node.d.endValue) {
10548
- getTypeOfExpression(node.d.endValue);
10567
+ }
10568
+ if (node.d.endValue) {
10569
+ const endTypeResult = getTypeOfExpression(node.d.endValue);
10570
+ endType = endTypeResult.type;
10571
+ if (endTypeResult.isIncomplete) {
10572
+ isIncomplete = true;
10549
10573
  }
10550
- if (node.d.stepValue) {
10551
- getTypeOfExpression(node.d.stepValue);
10574
+ }
10575
+ if (node.d.stepValue) {
10576
+ const stepTypeResult = getTypeOfExpression(node.d.stepValue);
10577
+ stepType = stepTypeResult.type;
10578
+ if (stepTypeResult.isIncomplete) {
10579
+ isIncomplete = true;
10552
10580
  }
10553
10581
  }
10554
- return { type: getBuiltInObject(node, 'slice') };
10582
+ const sliceType = getBuiltInObject(node, 'slice');
10583
+ if (!(0, types_1.isClassInstance)(sliceType)) {
10584
+ return { type: sliceType };
10585
+ }
10586
+ return { type: types_1.ClassType.specialize(sliceType, [startType, endType, stepType]), isIncomplete };
10555
10587
  }
10556
10588
  // Verifies that a type argument's type is not disallowed.
10557
10589
  function validateTypeArg(argResult, options) {
@@ -10964,7 +10996,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10964
10996
  function createSelfType(classType, errorNode, typeArgs, flags) {
10965
10997
  var _a;
10966
10998
  // Self doesn't support any type arguments.
10967
- if (typeArgs) {
10999
+ if (typeArgs && typeArgs.length > 0) {
10968
11000
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeArguments, localize_1.LocMessage.typeArgsExpectingNone().format({
10969
11001
  name: classType.shared.name,
10970
11002
  }), (_a = typeArgs[0].node) !== null && _a !== void 0 ? _a : errorNode);
@@ -13805,7 +13837,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13805
13837
  }
13806
13838
  if ((0, types_1.isClassInstance)(exceptionType)) {
13807
13839
  const iterableType = (_b = (_a = getTypeOfIterator({ type: exceptionType, isIncomplete: exceptionTypeResult.isIncomplete },
13808
- /* isAsync */ false, errorNode)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
13840
+ /* isAsync */ false, errorNode,
13841
+ /* emitNotIterableError */ false)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
13809
13842
  return (0, typeUtils_1.mapSubtypes)(iterableType, (subtype) => {
13810
13843
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
13811
13844
  return subtype;
@@ -14113,7 +14146,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14113
14146
  const annotationType = getTypeOfAnnotation(node.d.annotation, {
14114
14147
  varTypeAnnotation: true,
14115
14148
  allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(node.d.valueExpr),
14116
- allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(node.d.valueExpr),
14149
+ allowClassVar: isClassVarAllowedForAssignmentTarget(node.d.valueExpr),
14117
14150
  });
14118
14151
  writeTypeCache(node.d.valueExpr, { type: annotationType }, 0 /* EvalFlags.None */);
14119
14152
  }
@@ -14226,7 +14259,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14226
14259
  getTypeOfAnnotation(annotationNode, {
14227
14260
  varTypeAnnotation: true,
14228
14261
  allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(annotationParent.d.leftExpr),
14229
- allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(annotationParent.d.leftExpr),
14262
+ allowClassVar: isClassVarAllowedForAssignmentTarget(annotationParent.d.leftExpr),
14230
14263
  });
14231
14264
  }
14232
14265
  else {
@@ -15774,7 +15807,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15774
15807
  ((_c = declaration.node.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 35 /* ParseNodeType.MemberAccess */
15775
15808
  ? declaration.node.parent
15776
15809
  : declaration.node;
15777
- const allowClassVar = ParseTreeUtils.isClassVarAllowedForAssignmentTarget(declNode);
15810
+ const allowClassVar = isClassVarAllowedForAssignmentTarget(declNode);
15778
15811
  const allowFinal = ParseTreeUtils.isFinalAllowedForAssignmentTarget(declNode);
15779
15812
  const allowRequired = ParseTreeUtils.isRequiredAllowedForAssignmentTarget(declNode) ||
15780
15813
  !!declaration.isInInlinedTypedDict;