Simplify join_on_conjunctions bookkeeping#207
Merged
Conversation
Dedup the conjunction-index shift loop into a shift_conj_index helper, replace the pop()/try-except-IndexError boundary check with an equivalent slice delete, and replace slice-and-rebuild list reconstruction (pieces = pieces[:i] + [x] + pieces[j:]) with in-place slice assignment. No behavior change; full test suite still passes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
shift_conj_indexhelper.pop()+try/except IndexErrorboundary check with an equivalentdel pieces[i:i+rm_count]slice delete.pieces = pieces[:i] + [new_piece] + pieces[j:]slice-and-rebuild patterns with in-place slice assignment (pieces[i:j] = [new_piece]).No behavior change intended — purely mechanical cleanup from a
/simplifypass onjoin_on_conjunctionsinnameparser/parser.py. Riskier suggestions (merging thei == 0/elsebranches, restructuring the value-based prefix.index()lookup, introducing a token-classification abstraction) were deliberately skipped since that logic was the root cause of a prior parsing bug (#100) and warrants separate, careful investigation rather than opportunistic refactoring.Test plan
python -m pytest -q— 1248 passed, 4 skipped, 22 xfailed (same as before the change)