Skip to content

Add try_get_chapters to scripture parsing - #407

Merged
Enkidu93 merged 2 commits into
mainfrom
claude/issue-380-20261007-1927
Oct 13, 2026
Merged

Enkidu93 merged 2 commits into
mainfrom
claude/issue-380-20261007-1927

Conversation

@claude

@claude claude Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

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 Reviewable

@codecov-commenter

codecov-commenter commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.17%. Comparing base (e276d06) to head (039e269).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #407   +/-   ##
=======================================
  Coverage   92.16%   92.17%           
=======================================
  Files         396      396           
  Lines       25199    25225   +26     
=======================================
+ Hits        23225    23251   +26     
  Misses       1974     1974           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread machine/scripture/parse.py
Comment thread tests/scripture/test_parse.py Outdated
Comment thread machine/scripture/parse.py Outdated
@claude

This comment has been minimized.

@Enkidu93 Enkidu93 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claude Please address the comments on this PR.

@Enkidu93 reviewed 1 file and all commit messages, and made 1 comment.
Reviewable status: 1 of 3 files reviewed, 3 unresolved discussions.

@Enkidu93

Copy link
Copy Markdown
Collaborator

@claude Please address the comments on this PR.

@claude

claude Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Claude finished @Enkidu93's task in 3m 54s —— View job


Addressed the review comments

  • F1: parse_selection now raises ValueError("Empty book range.") for an empty segment, as C# PR 497 does. "MAT;;MRK", " ; " and ";" now fail with ValueError, not IndexError.
  • F2: added those three inputs to test_get_chapters (with raises(ValueError)) and to test_try_get_chapters.
  • F3: try_get_chapters now returns Optional[Dict[int, List[int]]] (None on failure), matching VerseRef.try_from_string. {} stays distinct from failure. The tests are updated to match.

./local_check.sh --agent-strict passed (864 passed, 3 skipped). Pushed as 3a4f240.

F3 departs from the C# out-parameter shape on purpose. Say so if you'd rather keep the (bool, dict) tuple.
· branch claude/issue-380-20261007-1927

@claude

This comment has been minimized.

github-actions Bot and others added 2 commits October 13, 2026 10:08
Co-authored-by: Eli C. Lowry <83078660+Enkidu93@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Eli C. Lowry <83078660+Enkidu93@users.noreply.github.com>
@Enkidu93
Enkidu93 force-pushed the claude/issue-380-20261007-1927 branch from 3a4f240 to 039e269 Compare October 13, 2026 14:08
with raises(ValueError):
get_chapters("OT,MAT-LUK")

# empty segments

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: F4. The empty-segment guard is tested only through string input with a doubled or lone ;. The list path (get_chapters(["MAT", ""]), ["-"], [""]) and a trailing delimiter ("MAT;") used to raise IndexError and now raise ValueError, which I confirmed by running them. No test pins this, so if it regresses, try_get_chapters raises again. Add one or two of these.

@claude

claude Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Verdict: approve.

What matters most: the PR description still says try_get_chapters returns (True, chapters) / (False, None). Since F3 it returns Optional[Dict[int, List[int]]] (machine/scripture/parse.py:186). The description is the record of a new export in machine.scripture.__all__, so update it before merge. On the code itself, F4 at tests/scripture/test_parse.py:181 is optional.

Counts: Critical 0, Important 0, Low 1 new.

What I ran: the branch was rebased (compare 3a4f240...039e269 reports diverged), so I re-reviewed the whole PR. pytest tests/scripture/test_parse.py passed (3 tests). pyright on the two changed files reported 0 errors. I called get_chapters/try_get_chapters on "", [], [""], [" "], ["MAT", ""], ["-"], "MAT;" and "-": the two empty inputs return {}, and the rest raise ValueError/return None. I compared the result with C# PR 497: the Empty book range. guard and the ArgumentException-only catch match. CI: the macOS builds are green, and the Ubuntu and Windows builds had not finished when I checked.

What I could not verify: ./local_check.sh --agent-strict was blocked by this environment's permissions.

Public API: machine.scripture.__all__ gains try_get_chapters. Parity with sillsdev/machine: returning Optional instead of the C# out parameter is a deliberate divergence. The list overload is Python-only, so get_chapters([""]) raising has no C# counterpart. Before this PR it raised IndexError.

Dropped: the unsorted merge in get_chapters (parse.py:177) and the missing spaces in its error messages are pre-existing and untouched. {} vs None both being falsy is ordinary Optional usage. The "Empty book range." text matches C#. Catching only ValueError matches C#.

Reviewed at 039e269

@Enkidu93 Enkidu93 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@Enkidu93 reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion.

@Enkidu93
Enkidu93 merged commit 4a1ff2c into main Oct 13, 2026
22 of 23 checks passed
@Enkidu93
Enkidu93 deleted the claude/issue-380-20261007-1927 branch October 13, 2026 14:17
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.

Port 'Add TryGetChapters to ScriptureRangeParser'

2 participants