Skip to content

Simplify _comma.py, _pieces.py and _vocab.py - #1433

Merged
derek73 merged 2 commits into
masterfrom
simplify/comma-pieces-vocab
Nov 16, 2026
Merged

derek73 merged 2 commits into
masterfrom
simplify/comma-pieces-vocab

Conversation

@derek73

@derek73 derek73 commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Release checklist step 0: a /simplify pass over nameparser/_pipeline/_comma.py, _pieces.py and _vocab.py. It ran four review angles: reuse, simplification, efficiency, altitude. No reading moves.

Simplifications

  • _vocab: T8's "an unambiguous title or suffix word after the stop is no name" test was written out twice, word for word, in glued_cuts and glued_saint_cut. It is now one helper, _claimed_after_the_stop.

  • _vocab: _CYRILLIC_JOINERS (Should a Mongolian choice read the father's name first? (Ухнаагийн Хүрэлсүх gives given 'Ухнаагийн', family 'Хүрэлсүх') #1237) and _CAPITALS_JOINERS (O9) held the same six characters under two names. They are now one _NAME_JOINERS, whose comment names both readers.

  • _vocab: is_initial_chunk asks _is_cased_letter instead of restating it inline.

  • _vocab: is_capitals_word drops the capitals counter, since capitals >= longest always holds, and a dead while … else arm.

  • _vocab: glued_cuts and glued_saint_cut now run their C-level matches before the _normalize frame. For glued_cuts, a bare run of letters returns () up front, which is the walk's first answer anyway with titled false.

  • _vocab: the stray second from nameparser._lexicon import _HYPHEN_CHARS merged into the existing import, and the hyphen comment says the constant lives in _lexicon.

  • _comma: _credential_fork builds the SUFFIX_OR_NAME report that C13 (decide) and C16 (_run_read_as_initials) each built by hand. The message text is byte-identical.

  • _comma: C16's runs: set[int] never held more than one index. It becomes initials_at: int | None, and the at = -1, first and runs.clear() scaffolding goes with it. segment_suffix_reading's signature is unchanged.

  • _comma: the C13 block keeps the _whole_name answer it computes, where the later if not listing asked again. _whole_name reads only seg0, and nothing in between changes it.

  • _comma: C6's caps loop now writes the contrast into the contrast_box that _credentials_beside, _listed_credentials_behind and _capitals_in_contrast read, so _name_contrast is no longer computed twice. The box is empty whenever the local is None, so the two stay in step.

  • _comma's Reads: line now names generation_words and the two ambiguous suffix sets that _a_names_word reads directly (Should Jane Doe, BM PhD read BM as a credential, not the given name? #1323). The grep listed them and the line did not.

  • Comments trimmed to the citation form:

    No decisions file needed new text, so no doc under docs/design/ changed.

  • tests/v2/test_layering.py's _UNGUARDED_READS goes from 203 to 198, with its provenance line. The T8 fold removed direct _sets reads, and the recorded control counts them.

Lines: _comma.py 1166 → 1178 (the helper and a wider Reads: line), _pieces.py 2615 → 2603, _vocab.py 3367 → 3367.

Measurements

  • uv run pytest: 49786 passed, 45 skipped, 3 xfailed.
  • uv run pytest -n0 -m serial: 38 passed.
  • uv run mypy and uv run ruff check are clean.
  • git diff --stat origin/master -- tools/differential is empty, and tests/v2/test_snapshot.py passes.
  • uv run python tools/differential/cldr_agreement.py: all seven views match their record.

Frames, py3.11. Each name ran in a fresh process with one warm-up parse of the name itself, master vs this branch. _CALL_BASELINE is not edited.

name master branch
reference row (_calls_per_parse) 285.8 285.8
Smith, John 136 136
John Smith, MD, PhD 234 234
Jane Doe, BM PhD (C6 contrast reused) 330 310
John Smith, Md (C13 whole name kept) 192 182
J.R.R. Tolkien (letter run returns early) 216 213
Smith, J.P. (_credential_fork) 222 223
St.John Smith (_claimed_after_the_stop, asked twice) 149 151

Reads: headers

grep -oE '\b(policy|lexicon|lex)(\._sets)?\.[a-z][a-z_]*' was compared against each docstring. _comma now lists every set the grep finds; the policy fields it reads go through state.policy and its helpers and were already named. _pieces and _vocab are not stages and carry no Reads: line.

Branches called dead

The only branch removed is is_capitals_word's while … else: i = -1. It is dead by construction: the loop ends normally only at i == 0, where word[:0] is empty. The guard is now if i and not all(...), which also keeps the generator's frame off the common path.

Behavior-changing candidates

None found among the applied changes. One efficiency finding was not applied because it is not equivalent by construction.

  • decide's C16 block appends every dotted run of initials to maybe, even behind a full name, so John Smith, M.D. pays name_word_count and its helpers.
    • Cost: +22 frames against v3.0.1, measured by the reviewer.
    • Proposed gate: elif initials_at not in maybe and (maybe or _lone_word(state, seg0)).
    • Why it was held back: a head that is not one word but has fewer than two name words would then take the no-maybe path (the listing early return, head_named=True).
    • What was checked: the suite and the snapshot moved nothing, but local comma corpora (ctgov-officials with --base) were not read.
    • It belongs in its own PR with that measurement.

Follow-ups outside these files

🤖 Generated with Claude Code

The 3.1 release's simplify pass over three modules this cycle changed.
Readings unchanged: snapshot.jsonl byte-identical, every agreement view
matches its record.

- _vocab: T8's unambiguous title-or-suffix test after a glued stop,
  written twice (glued_cuts, glued_saint_cut), is one helper
- _vocab: one joiner constant for O9's capitals word and the Cyrillic
  order key, which held the same six characters under two names
- _vocab: is_initial_chunk asks _is_cased_letter; is_capitals_word
  drops a counter its chunk count implies and a dead while-else
- _vocab: glued_cuts and glued_saint_cut ask their C-level matches
  before the fold's frame
- _comma: one helper builds the credential fork C13 and C16 report;
  C16's one-element run set is an index; C13 keeps the whole-name
  answer it computes; C6's contrast fills the box its helpers read
- comments trimmed to the citation form, history left in decisions/;
  _comma's Reads: line names the sets it reads directly

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derek73 derek73 added commas Commas and name structure (rules/C) internals Refactors and parse cost with no behavior change labels Nov 16, 2026
@derek73 derek73 self-assigned this Nov 16, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derek73
derek73 merged commit d184d30 into master Nov 16, 2026
14 checks passed
@derek73
derek73 deleted the simplify/comma-pieces-vocab branch November 16, 2026 09:33
@derek73 derek73 added this to the 3.1 milestone Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commas Commas and name structure (rules/C) internals Refactors and parse cost with no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant