Skip to content

Commit 133a01c

Browse files
derek73claude
andcommitted
Guard against silent no-op deletion in join_on_conjunctions
PR review flagged that the del-slice replacement for the old pop()/try-except boundary check silently no-ops on an out-of-range index instead of raising, unlike the original. That state is currently unreachable, but add an assertion so a future regression in the index bookkeeping fails loudly instead of silently corrupting pieces. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent cb99c1d commit 133a01c

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

nameparser/parser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,10 @@ def shift_conj_index(past: int, by: int) -> None:
13061306
new_piece = " ".join(pieces[i-1:i+2])
13071307
register_joined_piece(new_piece, pieces[i-1])
13081308
pieces[i-1] = new_piece
1309+
# len(pieces) - i is always >= 1 here: pieces[i-1:i+2] above
1310+
# already accessed index i, so i is guaranteed in range.
13091311
rm_count = min(2, len(pieces) - i)
1312+
assert rm_count > 0, f"unexpected empty deletion at i={i}, pieces={pieces}"
13101313
del pieces[i:i+rm_count]
13111314
shift_conj_index(past=i, by=rm_count)
13121315

0 commit comments

Comments
 (0)