Repository navigation
Add try_get_chapters to scripture parsing - #407
claude[bot] wants to merge 1 commit into
Conversation
Co-authored-by: Eli C. Lowry <83078660+Enkidu93@users.noreply.github.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #407 +/- ##
=======================================
Coverage 92.07% 92.07%
=======================================
Files 394 394
Lines 24896 24911 +15
=======================================
+ Hits 22922 22937 +15
Misses 1974 1974 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| ) -> Tuple[bool, Optional[Dict[int, List[int]]]]: | ||
| try: | ||
| return True, get_chapters(selections, versification) | ||
| except ValueError: |
There was a problem hiding this comment.
Minor: F1. try_get_chapters raises on an empty segment instead of returning (False, None). For "MAT;;MRK", ";" or " ; ", parse_selection("") evaluates selection[-1] (line 62), which raises IndexError, and that error is not caught here. C# PR 497 added an Empty book range. guard to ParseSection and test cases that expect TryGetChapters to return false for these three inputs. Port the guard as a ValueError in parse_selection.
| assert try_get_chapters("MAT 500") == (False, None) | ||
| assert try_get_chapters("MAT3-1") == (False, None) | ||
| assert try_get_chapters("-MRK") == (False, None) | ||
| assert try_get_chapters("MRK 2-5;-MRK 6") == (False, None) |
There was a problem hiding this comment.
Minor: F2. The failure cases leave out the empty-segment inputs "MAT;;MRK", " ; " and ";". C# PR 497 added those three to the shared GetCases, and they are the inputs that break F1. Add them here, and to test_get_chapters with raises(ValueError).
|
|
||
| def try_get_chapters( | ||
| selections: Union[str, List[str]], versification: Versification = ORIGINAL_VERSIFICATION | ||
| ) -> Tuple[bool, Optional[Dict[int, List[int]]]]: |
There was a problem hiding this comment.
Minor: F3. The (bool, Optional[Dict]) return shape goes into the published wheel through __all__, and it differs from the existing try-API VerseRef.try_from_string (verse_ref.py:98), which returns Optional[...]. The bool tells pyright nothing about the dict, so ok, ch = ...; if ok: ch[40] still gets flagged as possibly None. Returning Optional[Dict[int, List[int]]] would match the existing convention, and {} stays distinct from failure. Once this is released, changing the shape is a breaking change.
|
Verdict: approve with fixes. The fix that matters most is F1 at Counts: Critical 0, Important 3, Low 0. What I ran: What I could not verify: executing the F1 inputs was blocked in this environment, so the Public API: Dropped as pre-existing or out of scope:
Reviewed at 59401fb |
Ports machine PR 497 (sillsdev/machine#497): adds try_get_chapters, a non-raising counterpart to get_chapters. It returns (True, chapters) on success and (False, None) when get_chapters raises ValueError, the Python form of the C# out parameter. Exported from machine.scripture. The C# namespace move and SIL.Scripture qualification fixes are C#-only and skipped. Added test_try_get_chapters. ./local_check.sh --agent-strict passed (864 passed, 3 skipped). Closes issue 380 - Closes #380. 🤖 Generated with Claude Code
This change is