Skip to content

fix(run_simScript): narrow Optional locals at use sites#1257

Open
olantwin wants to merge 1 commit into
masterfrom
pyrefly/run-simscript-narrowing
Open

fix(run_simScript): narrow Optional locals at use sites#1257
olantwin wants to merge 1 commit into
masterfrom
pyrefly/run-simscript-narrowing

Conversation

@olantwin

Copy link
Copy Markdown
Contributor

Summary

PR #1247 pre-initialised P8gen, theCouplings and Opt_high to None so the unbound-name warnings would clear. That worked, but pyrefly then saw the None branches propagate into the conditional blocks below and complained at every member access. Plus the recent feat commit (ada8e92) added a write/read cycle around the FairRoot output file that pyrefly types as TObject and rejects when we index or SetWritable on it.

Approach

Tight narrowing at the use site, not blanket re-init:

Site Fix
:561 theCouplings[…] in RPVSUSY branch assert theCouplings is not None (the same options.thecouplings guard set it)
:607 P8gen.SetSmearBeam(...) and following assert P8gen is not None inside the if HNL or RPVSUSY or DarkPhoton block (each of those three arms assigns it)
:859 Cosmicsgen.Init(Opt_high) assert Opt_high is not None inside the if options.cosmics block
:1003/:1060 t = fin["cbmsim"] / fin.SetWritable type fin as `ROOT.TFile

Test plan

Companion to #1256 (stubs).

PR #1247 pre-initialised P8gen, theCouplings and Opt_high to None so
the unbound-name warnings would clear. That worked, but pyrefly then
saw the None branches propagate through the conditional blocks below
and warned at every member access (P8gen.SetSmearBeam, theCouplings[0],
Cosmicsgen.Init(Opt_high), …). Plus the recent feat commit
(ada8e92) added a write/read cycle around the FairRoot output file
that pyrefly types as TObject and complains about indexing /
SetWritable on.

Apply tight narrowing rather than re-introducing the unbound-name
risk:

* Add 'assert theCouplings is not None' at the top of the RPVSUSY
  branch (the same options.thecouplings guard sets it).
* Add 'assert P8gen is not None' inside the
  'if HNL or options.RPVSUSY or options.DarkPhoton' block (each of
  the three branches above assigns P8gen).
* Add 'assert Opt_high is not None' at the top of the
  'if options.cosmics' block (the same flag guarded the assignment).
* Type the FairRoot output-file handle as 'ROOT.TFile | None', cast
  the lookup from ROOT.gROOT.GetListOfFiles() to TFile, and assert
  TFile.Open's return before indexing — yields a TFile-typed handle
  that t = fin['cbmsim'] and fin.SetWritable(False) accept.

Pyrefly errors drop from 128 → 115 (13 fewer). The remaining 2 in
this file (SetMaxTheta, nrOfDP) are stub gaps resolved by the
companion PR adding those entries.
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@olantwin, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 13 minutes and 40 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f1aaffcf-806c-4f0e-b771-80cb224c33a9

📥 Commits

Reviewing files that changed from the base of the PR and between 7be7505 and c308705.

📒 Files selected for processing (1)
  • macro/run_simScript.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pyrefly/run-simscript-narrowing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant