fix(run_simScript): narrow Optional locals at use sites#1257
Conversation
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.
|
Warning Review limit reached
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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
PR #1247 pre-initialised
P8gen,theCouplingsandOpt_hightoNoneso theunbound-namewarnings would clear. That worked, but pyrefly then saw theNonebranches 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 asTObjectand rejects when we index orSetWritableon it.Approach
Tight narrowing at the use site, not blanket re-init:
:561theCouplings[…]in RPVSUSY branchassert theCouplings is not None(the sameoptions.thecouplingsguard set it):607P8gen.SetSmearBeam(...)and followingassert P8gen is not Noneinside theif HNL or RPVSUSY or DarkPhotonblock (each of those three arms assigns it):859Cosmicsgen.Init(Opt_high)assert Opt_high is not Noneinside theif options.cosmicsblock:1003/:1060t = fin["cbmsim"]/fin.SetWritablefinas `ROOT.TFileTest plan
pyrefly checkdrops 128 → 115 errors (13 fewer; the residual 2 in this file —SetMaxTheta,nrOfDP— are stub gaps already fixed in stubs(ROOT): add SetMaxTheta, nrOfDP, IsEqual, mnstat #1256)Companion to #1256 (stubs).