Skip to content

Issue 168 - Fix parsing references with trailing periods after book n… - #258

Open
mmatchyn2 wants to merge 4 commits into
avendesora:mainfrom
mmatchyn2:fix-issue-168
Open

mmatchyn2 wants to merge 4 commits into
avendesora:mainfrom
mmatchyn2:fix-issue-168

Conversation

@mmatchyn2

@mmatchyn2 mmatchyn2 commented Sep 8, 2026

Copy link
Copy Markdown

…ames (#168)

Fixes examples reported in #168 such as 'Micah. 2Ch. 34:20', 'Psalm. 46', 'Psalms. 74', and '1Peter. 1:22'. The parser now strips punctuation after the matched book name before interpreting chapter and verse values, avoiding empty-string int conversion errors.

Description

Fixes #168
I wanted to test out AI and it's ability to fix bugs.

Checklist:

  • [X ] I have read the CONTRIBUTING document.
  • I have added tests that prove my fix is effective or that my feature works.
  • [X ] I have run pre-commit locally prior to submission and fixed any errors/warnings.
  • [X ] I have run tests locally prior to submission and they are passing.
  • [NA ] I have added necessary documentation (if appropriate).
  • [NA] I have updated the README (if appropriate).
  • [X ] I have updated the CHANGELOG (if appropriate).
  • [NA] I have updated the version number (if appropriate).
  • [NA] I have updated the requirements (if appropriate).

Summary by Sourcery

Handle punctuation after Bible book names so affected references parse correctly.

Bug Fixes:

  • Fix parsing of Bible references when book names are followed by periods, preserving chapter and verse values without errors.

Tests:

  • Add coverage for references with trailing periods after several book-name formats.

…ames (avendesora#168)

Fixes examples reported in avendesora#168 such as 'Micah. 2Ch. 34:20', 'Psalm. 46', 'Psalms. 74', and '1Peter. 1:22'. The parser now strips punctuation after the matched book name before interpreting chapter and verse values, avoiding empty-string int conversion errors.
@sourcery-ai

sourcery-ai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

The parser now strips leading whitespace and punctuation from reference segments before interpreting chapter/verse values, preventing empty-string conversion failures for book names followed by periods while retaining existing range handling. Parameterized regression tests cover the reported forms, and the fix is documented in the changelog.

Flow diagram for parsing references with trailing periods

flowchart LR
    A["Reference segment"] --> B["strip and lstrip punctuation"]
    B --> C["remove trailing DASH"]
    C --> D["replace PERIOD with COLON"]
    D --> E["split chapter and verse"]
    E --> F["parse normalized reference"]
Loading

File-Level Changes

Change Details Files
Normalize leading punctuation around sub-references before parsing chapter and verse components.
  • Strip whitespace and common punctuation, including periods, before handling empty references and dash ranges.
  • Apply the same normalization inside sub-reference parsing before converting periods to chapter/verse separators.
  • Preserve existing handling for book-only references and trailing dash syntax after normalization.
pythonbible/pythonbible/parser.py
Add regression coverage for book names followed immediately by periods.
  • Cover singular and plural Psalm forms, Micah, and 1 Peter.
  • Verify chapter-only and chapter-and-verse references normalize to the expected book and numeric ranges.
pythonbible/tests/parser/parser_test.py
Document the bug fix in the unreleased changelog. CHANGELOG.md

Assessment against linked issues

Issue Objective Addressed Explanation
#168 Parse Bible references when a recognized book name is immediately followed by a period, including references such as "Micah. 2", "Psalm. 46", "Psalms. 74", and "1Peter. 1:22".
#168 Prevent punctuation following book names from causing parsing errors or causing the chapter and verse information to be discarded in the reported compound reference strings.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codacy-production

codacy-production Bot commented Sep 8, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Sep 8, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="pythonbible/pythonbible/parser.py" line_range="163-166" />
<code_context>
-        if (not sub_reference or sub_reference in {DASH, PERIOD}) and not references:
+        normalized_sub_reference = sub_reference.strip().lstrip(" .,:;-")
+
+        if (
+            not normalized_sub_reference
+            or normalized_sub_reference in {DASH, PERIOD}
+        ) and not references:
             references.append(NormalizedReference(book, None, None, None, None, book))
             continue
</code_context>
<issue_to_address>
**nitpick:** The `normalized_sub_reference in {DASH, PERIOD}` check can never match `PERIOD`: `lstrip(" .,:;-")` converts a period-only value to an empty string before the condition is evaluated. The unreachable `PERIOD` branch leaves contradictory punctuation handling in this control flow and can mislead future changes to the parser.

**Suggested fix:** Remove `PERIOD` from the set or check the punctuation-only value before stripping it.

```suggestion
        if (
            not normalized_sub_reference
            or normalized_sub_reference in {DASH}
        ) and not references:
```
</issue_to_address>

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread pythonbible/pythonbible/parser.py
sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Sep 8, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Sep 9, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

This branch has not been deployed

No deployments
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.

A few potential test fails?

1 participant