Repository navigation
Simplify _match.py - #1432
Merged
Merged
Simplify _match.py#1432
Conversation
…ing set once, read _vocab's initialless test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pts in AGENTS.md and mechanisms.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…me through _pipeline/_vocab Co-Authored-By: Claude Opus 5.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.
Release checklist step 0: a /simplify pass over
nameparser/_match.py(new this cycle). It was reviewed as a whole file from four angles (reuse, simplification, efficiency, altitude). Every change is behavior-identical: no match result, key, repr, message text, exception type or public name moves.Simplifications
Matching.check: underother_readings, the right side's readings are built once. Before,self._readings(right)ran again for every left reading, which redid itsParser.revisesub-parses:Van Gogh/Van Morrisonmade 3revisecalls where 2 are needed.Matching._middle_left._pick_acrossranked candidates by removing the consumed middle word and comparing the rest;_resolvedthen did the same deletion and comparison again for the winner._pick_acrossnow returns the winner's remainder and outcome, and_resolveduses them._resolvedreturns early whenacross-rolesis not accepted. Before, both callers in_resultwrapped it in the same conditional._resolvedreads the middle words through_cross_texts(name, Role.MIDDLE), the same text it was building inline with_role_text(...).split()._familiarand_alternatewere one function with a different pair table. They are now_paired(sa, sb, pairs), which takes spelling sets already built._familiar_outcomebuilds each pair's two spelling sets once instead of three times (once each for listed, alternate and familiar)._keysbuilds the first given word's spelling set once instead of three times, and loops over one table (_pair_tables) for the familiar-form and alternate-spelling letters instead of repeating the same block for each._paired_formsnow requires itspairsargument._letters_of, which replaces four copies of{_letter(g) for g in ...} - {""}, and_row_more, which replaces two copies of a row'smoreon conflict._is_initialreads_pipeline._vocab.in_initialless_scriptinstead of a third local copy of the initialless-script matcher, and the_policyimports of_NO_INITIAL_RANGESand_ranges_matchergo. The two agree on every code point and its fold, checked exhaustively.tests/v2/test_script_properties.pyread the removed_match._initialless: its column test now asserts through_match._is_initial, and the matcher-agreement test reads_vocab.in_initialless_script._familiar_outcome: dropped a branch that the line after it already covers (if alt in accept and fam in accept: return fam)._first_half: dropped the redundant"-" not in w, whichparts[0] == walready implies._text_outcomes: dropped defaults that its only caller never uses._RUN_ROLESmoved beside the other role constants. Removed an extra blank line, and the quotes aroundLexiconin_Compare._family_outcomeno longer restates_text_outcomesand_aside_outcome, and its 130-column line is gone.in_initialless_script.AGENTS.md's layering bullet anddocs/design/mechanisms.md's script-properties entry now say_matchreads the initialless scripts through_vocab.in_initialless_script. AGENTS.md asks for a layering note to be updated in the same change. Intests/v2/test_layering.pyonly the comment on the_match.pyentry changes, to say the same. ItsALLOWEDtuple is unchanged:_matchalready imported_pipeline._vocab, and still imports_policy, forPolicy.Lines:
_match.pywent from 1,653 to 1,663. The new helpers' docstrings and the import block, which is now on several lines, outweigh the code removed. Code duplication fell; line count did not.Measurements
uv run pytest: 49,786 passed, 45 skipped, 3 xfailed.uv run pytest -n0 -m serial: 38 passed.uv run mypy: no issues.uv run ruff check: clean.match_diff.py --base <detached worktree of origin/master 90b15c84>, run with a privateNAMEPARSER_TOOLS_CACHEof symlinks:_first_halfalways false; the familiar and alternate given letters dropped from the keys) reported 38,146 rows moved, 18,898 of them keys.git diff --stat origin/master -- tools/differential/snapshot.jsonl: empty._calls_per_parse, py3.11): 285.8 before, 285.8 after. A parse never enters_match.Reviewed and not taken
_SpellingSetskeyed by group) through_text_outcomes,_part_agreesand_familiar_outcome. Measured,check('John Smith', 'Jon Smyth')builds_spellings16 times for about 4 distinct inputs. The change is wider than a cleanup and should be its own PR.ParsedName's role texts percheck._RoleRulefield for the word-by-word middle reading, and one encoding the family-versus-maiden mode in place ofbasespluschain. Both are mechanical but touch every comparator._capitals_word.Behavior-changing candidates
None found. Two splits that look like duplication are deliberate, and each carries its reason:
_same_lettersdrops empty words, while_initial_outcomekeeps them (Should a family name of initials alone match the same initials in another order, or fewer? (J. P., Ann/P. J., Annreads familypart-of-other, consistent) #1350).f[:1]mirrors the check'sfb[:1]. Switching it to_letterwould move keys for a family name opening with a hyphen without moving the check.🤖 Generated with Claude Code