fix: close file handles in readxml filecache and CLI patch loading#2711
fix: close file handles in readxml filecache and CLI patch loading#2711henryiii wants to merge 1 commit into
Conversation
- readxml.py: use .get("Activate", "False") on StatError to avoid
KeyError when the attribute is absent
- readxml.py: close cached uproot file handles in clear_filecache()
before resetting the dict, using contextlib.suppress for already-
closed handles
- cli/infer.py, cli/rootio.py: replace bare click.open_file().read()
(which leaks the handle) with proper with-statement context managers
Assisted-by: ClaudeCode:claude-sonnet-4.6
|
Warning Review limit reached
More reviews will be available in 29 minutes and 58 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ 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: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2711 +/- ##
==========================================
- Coverage 98.28% 96.40% -1.88%
==========================================
Files 65 65
Lines 4305 4316 +11
Branches 465 468 +3
==========================================
- Hits 4231 4161 -70
- Misses 46 121 +75
- Partials 28 34 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🤖 AI text below 🤖
Part of the code review in #2706.
Summary
src/pyhf/readxml.pyline 218:modtag.attrib["Activate"]raised a rawKeyErrorwhen a<StatError>element lacked the attribute. Changed tomodtag.attrib.get("Activate", "False") == "True", consistent with all sibling attribute accesses.src/pyhf/readxml.pyclear_filecache: the global__FILECACHE__stores open uproot file handles. Previously, clearing the dict abandoned them without closing. Now each handle is closed (usingcontextlib.suppress(Exception)to guard against already-closed handles) before the dict is reset.src/pyhf/cli/infer.py(two sites) andsrc/pyhf/cli/rootio.py(one site):json.loads(click.open_file(...).read())leaked file handles. Replaced with explicitwith click.open_file(...) as f: json.load(f)context managers, matching the style used everywhere else in those files.Test plan
pytest tests/test_import.py tests/test_scripts.py -q— 78 tests pass, no regressionsprek -a --quiet(pre-commit / ruff) — clean, no lint errors🤖 Generated with Claude Code