@zzzen/pyright-internal 1.2.0-dev.20260726 → 1.2.0-dev.20260809

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.
@@ -3247,30 +3247,49 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
3247
3247
  }
3248
3248
  });
3249
3249
  }
3250
- // Verifies the rules specified in PEP 589 about TypedDict classes.
3251
- // They cannot have statements other than type annotations, doc
3252
- // strings, and "pass" statements or ellipses.
3250
+ // Verifies the rules specified for TypedDict class bodies.
3251
+ // They cannot have statements other than type annotations, doc strings,
3252
+ // "pass" statements, ellipses, and statically evaluable if statements.
3253
3253
  _validateTypedDictClassSuite(suiteNode) {
3254
3254
  const emitBadStatementError = (node) => {
3255
3255
  this._evaluator.addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictBadVar(), node);
3256
3256
  };
3257
- suiteNode.d.statements.forEach((statement) => {
3258
- if (!AnalyzerNodeInfo.isCodeUnreachable(statement)) {
3259
- if (statement.nodeType === 47 /* ParseNodeType.StatementList */) {
3260
- for (const substatement of statement.d.statements) {
3261
- if (substatement.nodeType !== 54 /* ParseNodeType.TypeAnnotation */ &&
3262
- substatement.nodeType !== 21 /* ParseNodeType.Ellipsis */ &&
3263
- substatement.nodeType !== 48 /* ParseNodeType.StringList */ &&
3264
- substatement.nodeType !== 42 /* ParseNodeType.Pass */) {
3265
- emitBadStatementError(substatement);
3266
- }
3257
+ function validateStatement(statement) {
3258
+ if (AnalyzerNodeInfo.isCodeUnreachable(statement)) {
3259
+ return;
3260
+ }
3261
+ if (statement.nodeType === 47 /* ParseNodeType.StatementList */) {
3262
+ for (const substatement of statement.d.statements) {
3263
+ if (substatement.nodeType !== 54 /* ParseNodeType.TypeAnnotation */ &&
3264
+ substatement.nodeType !== 21 /* ParseNodeType.Ellipsis */ &&
3265
+ substatement.nodeType !== 48 /* ParseNodeType.StringList */ &&
3266
+ substatement.nodeType !== 42 /* ParseNodeType.Pass */) {
3267
+ emitBadStatementError(substatement);
3267
3268
  }
3268
3269
  }
3269
- else {
3270
+ return;
3271
+ }
3272
+ if (statement.nodeType === 22 /* ParseNodeType.If */) {
3273
+ const conditionValue = AnalyzerNodeInfo.getStaticConditionValue(statement);
3274
+ if (conditionValue === undefined) {
3270
3275
  emitBadStatementError(statement);
3276
+ return;
3277
+ }
3278
+ const reachableSuite = conditionValue ? statement.d.ifSuite : statement.d.elseSuite;
3279
+ if (reachableSuite?.nodeType === 22 /* ParseNodeType.If */) {
3280
+ validateStatement(reachableSuite);
3271
3281
  }
3282
+ else if (reachableSuite) {
3283
+ validateSuite(reachableSuite);
3284
+ }
3285
+ return;
3272
3286
  }
3273
- });
3287
+ emitBadStatementError(statement);
3288
+ }
3289
+ function validateSuite(suite) {
3290
+ suite.d.statements.forEach((statement) => validateStatement(statement));
3291
+ }
3292
+ validateSuite(suiteNode);
3274
3293
  }
3275
3294
  _validateTypeGuardFunction(node, functionType, isMethod) {
3276
3295
  const returnType = functionType.shared.declaredReturnType;