Skip to content

Commit 7ad11e7

Browse files
[pre-commit.ci] pre-commit autoupdate (#97)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/charliermarsh/ruff-pre-commit: v0.0.269 → v0.0.272](astral-sh/ruff-pre-commit@v0.0.269...v0.0.272) * static code analysis fixes --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Nathan Patton <npatton@gmail.com>
1 parent a6425b0 commit 7ad11e7

13 files changed

Lines changed: 86 additions & 79 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
- id: name-tests-test
1010
- id: requirements-txt-fixer
1111
- repo: https://github.com/charliermarsh/ruff-pre-commit
12-
rev: 'v0.0.269'
12+
rev: 'v0.0.272'
1313
hooks:
1414
- id: ruff
1515
args: [ --fix, --exit-non-zero-on-fix ]

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Changed
1111

1212
- Updated README to more accurately describe current OSIS parser and Bible text formatting functionality
13+
- Minor code quality improvements based on static code analysis
1314

1415
## [0.10.0]
1516

docs/source/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# If extensions (or modules to document with autodoc) are in another directory,
1111
# add these directories to sys.path here. If the directory is relative to the
1212
# documentation root, use os.path.abspath to make it absolute, like shown here.
13-
#
1413
import pathlib
1514
import sys
1615

pythonbible/bible/bibles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ def get_bible(version: Version, bible_type: str) -> Bible:
5252
"""
5353
try:
5454
return BIBLES[version][bible_type]
55-
except KeyError as e:
56-
raise MissingVerseFileError from e
55+
except KeyError as error:
56+
raise MissingVerseFileError from error

pythonbible/books.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def abbreviations(self: Book) -> tuple[str, ...]:
195195
22,
196196
"Song of Songs",
197197
r"(Song(?: of (Solomon|Songs|Sol\.*))?)"
198-
r"|Canticles|(Canticle(?: of Canticles)?)|SOS|Cant",
198+
"|Canticles|(Canticle(?: of Canticles)?)|SOS|Cant",
199199
("Cant", "Canticle", "Canticles", "Song", "Song of Sol", "SOS"),
200200
)
201201
ISAIAH = 23, "Isaiah", r"Isa\.*(?:iah)?", ("Isa",)

pythonbible/formatter.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ def format_scripture_text(verse_ids: list[int], **kwargs: Any) -> str:
351351
text: str = ""
352352
current_book: Book | None = None
353353
current_chapter: int | None = None
354-
previous_verse_number: int | None = None
355354
current_start_verse: int | None = None
356355
current_end_verse: int | None = None
357356

@@ -360,10 +359,8 @@ def format_scripture_text(verse_ids: list[int], **kwargs: Any) -> str:
360359

361360
if (
362361
one_verse_per_paragraph
363-
or book != current_book
364-
or chapter_number != current_chapter
365-
or previous_verse_number is None
366-
or verse_number != previous_verse_number + 1
362+
or current_end_verse is None
363+
or verse_id - current_end_verse > 1
367364
):
368365
if current_start_verse and current_end_verse:
369366
verse_text = bible.get_scripture(current_start_verse, current_end_verse)
@@ -372,7 +369,6 @@ def format_scripture_text(verse_ids: list[int], **kwargs: Any) -> str:
372369
current_start_verse = verse_id
373370

374371
current_end_verse = verse_id
375-
previous_verse_number = verse_number
376372

377373
if book != current_book:
378374
current_book = book

pythonbible/normalized_reference.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
@dataclass
1111
class NormalizedReference:
12-
"""NormalizedReference is a dataclass that represents a single scripture reference
13-
that contains one or more consecutive verses.
12+
"""NormalizedReference is a dataclass that represents a single scripture reference.
13+
14+
The scripture reference contains one or more consecutive verses.
1415
1516
:param book: the first book of the Bible in the reference
1617
:type book: Book

pythonbible/parser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ def get_references(
2525
text: str,
2626
book_groups: dict[str, tuple[Book, ...]] = None,
2727
) -> list[NormalizedReference]:
28-
"""Search the text for scripture references and return any that are found in a list
29-
of normalized tuple references.
28+
"""Search the text for scripture references.
29+
30+
Return any scripture references that are found in a list of normalized references.
3031
3132
:param text: String that may contain zero or more scripture references
3233
:type text: str

pythonbible/regular_expressions.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
DIGIT: str = r"(\d{1,3})"
99
SPACE: str = r"\s*"
10-
COLON: str = rf"{SPACE}([:.]){SPACE}"
11-
DASH = rf"{SPACE}-{SPACE}"
12-
COMMA = rf"{SPACE},{SPACE}"
10+
COLON: str = f"{SPACE}([:.]){SPACE}"
11+
DASH = f"{SPACE}-{SPACE}"
12+
COMMA = f"{SPACE},{SPACE}"
1313

1414
BOOK: str = rf"\b({'|'.join(book.regular_expression for book in Book)})\b\.*"
1515
CHAPTER: str = DIGIT
1616
VERSE: str = DIGIT
1717

18-
CHAPTER_AND_VERSE: str = rf"({CHAPTER}(?:{COLON}{VERSE})?)"
18+
CHAPTER_AND_VERSE: str = f"({CHAPTER}(?:{COLON}{VERSE})?)"
1919

2020
# Possibly range regular expressions are:
2121
# 1. Book - Book (with optional chapter/verse)
@@ -27,15 +27,15 @@
2727

2828
# TODO - this regex may have some false positives for ranges given the above rules.
2929
RANGE: str = (
30-
rf"{DASH}(({BOOK}{SPACE}(?:{CHAPTER_AND_VERSE})?)|{CHAPTER_AND_VERSE}|{VERSE})"
30+
f"{DASH}(({BOOK}{SPACE}(?:{CHAPTER_AND_VERSE})?)|{CHAPTER_AND_VERSE}|{VERSE})"
3131
)
3232

33-
ADDITIONAL_REFERENCE: str = rf"({COMMA}({CHAPTER_AND_VERSE}(?:{RANGE})?|{VERSE}))"
33+
ADDITIONAL_REFERENCE: str = f"({COMMA}({CHAPTER_AND_VERSE}(?:{RANGE})?|{VERSE}))"
3434
FULL_CHAPTER_AND_VERSE: str = (
3535
f"({CHAPTER_AND_VERSE}(?:{RANGE})?({ADDITIONAL_REFERENCE})*)"
3636
)
37-
FULL_BOOK = rf"({BOOK}){SPACE}(?:{FULL_CHAPTER_AND_VERSE})?"
38-
CROSS_BOOK = rf"({FULL_BOOK}(?:{DASH}({FULL_BOOK}))?)"
37+
FULL_BOOK = f"({BOOK}){SPACE}(?:{FULL_CHAPTER_AND_VERSE})?"
38+
CROSS_BOOK = f"({FULL_BOOK}(?:{DASH}({FULL_BOOK}))?)"
3939

4040
SCRIPTURE_REFERENCE_REGULAR_EXPRESSION: Pattern[str] = re.compile(
4141
CROSS_BOOK,

pythonbible/verses.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,12 +1521,12 @@ def get_number_of_verses(book: Book, chapter: int) -> int:
15211521

15221522
try:
15231523
return chapter_list[chapter - 1]
1524-
except IndexError as e:
1524+
except IndexError as error:
15251525
error_message = (
15261526
f"{chapter} is not a valid chapter number for the book of {book.title}. "
15271527
f"Valid chapter numbers are 1-{len(chapter_list)}."
15281528
)
1529-
raise InvalidChapterError(error_message) from e
1529+
raise InvalidChapterError(error_message) from error
15301530

15311531

15321532
@lru_cache()

0 commit comments

Comments
 (0)