Skip to content

Simplify _suggest.py with no suggestion moved - #1530

Merged
derek73 merged 3 commits into
masterfrom
refactor/simplify-suggest
Nov 22, 2026
Merged

derek73 merged 3 commits into
masterfrom
refactor/simplify-suggest

Conversation

@derek73

@derek73 derek73 commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

The 3.2 release checklist's step 0: a /simplify pass over nameparser/_suggest.py, the group suggester, covering the code changed since v3.1.0 (git diff v3.1.0 -- nameparser/_suggest.py, 293 lines). It is quality only: no suggestion, printed evidence, message, repr or pickle moves. No other library file is touched. The test file only gains a test and moves a helper; no expectation is edited.

Changes

  • _quiet(parser, policy) builds a parser under a policy with its construction warnings silenced. It replaces four copies of that block (_letter_readers, _capitals_reader, _two_family_votes, suggest).
  • _two_family_note(base, rest) says why two_family_names is not weighed. The reasons used to be inline in suggest. The reader parser is now built only where the switch is weighed.
  • _decide_two_family_names tallies the switch with _Tally, as the other settings are tallied. Before, it held a hand copy of _Tally's counting and its row sort.
  • _keeps_family_first counts the PATRONYMIC_POSITION votes already cast, instead of working the position out again from the words.
  • _patronymic_end asks rules/O1's own east_slavic_rotates, the pipeline predicate, as root AGENTS.md asks of a signal. It is equivalent under the East Slavic vote it is asked beside.
  • _decide_order states its FAMILY_FIRST_GIVEN_LAST case as the rule it is: a decided East Slavic rule takes the end's own spelling.
  • Removed:
    • the _setting_of wrapper of _SETTING_OF
    • a name_votes filter that dropped nothing, since _read casts no switch vote
    • a second dict(name._votes) in _disagrees
    • a hand-rolled suffix slice, now removesuffix
  • Comments. Two comments lost a measurement and a history that decisions/group-suggestion's 2026-11-19 entries already hold; each keeps its pointer. The Standing line that named _setting_of among _SETTING_OF's readers now names the real readers. The dated log bullets that mention it are left as history.

Proof that no suggestion moved

tools/differential/suggest_measure.py was run in both trees: master af58ca09 in a separate checkout and this branch.

Run Result
default sizes (2 to 200) identical: all 674 lines but the one naming the tree
--sizes 2,3,4,5,10,20,50,100,200,500,1000,2000 identical: all 688 lines but the one naming the tree
--checks (per-name checks) byte-identical (7 lines, 1,784,012 names written both ways)

Other checks:

  • Differential. The code review compared 19,096 (base, group) suggestions in both trees: 41 bases (every order × the switches × the rules, and five packs) and groups built for each changed branch (East Slavic, Spanish two-family names, Nepali letter runs, capitals lists, comma and empty names). For each it hashed str(s), repr(s.patch), the evidence, repr(s), a pickle round-trip and every name's name_votes. The digests are identical.
  • tools/differential/snapshot.jsonl is byte-identical, not re-recorded.
  • The full suite passes, 57,962 passed (and the serial tests). uv run sphinx-build -b doctest docs <tmp> gives 0 failures across 1,527 tests, which covers the suggester's printed evidence in docs/suggest.rst and getting-started.rst.
  • uv run ruff check and uv run mypy are clean.

Behavior-changing candidates

None of these is applied. Each would move a suggestion, its printed evidence, or a hand-built Suggestion's reading.

  1. Read the word the switch takes by tokens, not by family strings. Today _two_family_votes slices on.family by off.family. Reading on.tokens_for(Role.FAMILY) minus the off parse's, or ParsedName.surname1, is sturdier. But it changes the taken word wherever the family string and its units differ: surname1 treats a connective-joined or bound pair as one unit (Juan y Garcia takes y Garcia, Tariq Abdul Aziz Abdul Aziz). The reuse review measured that on 46 of 1,746 moved names, which would move FIRST_SURNAME votes and the evidence.
  2. One shared decider for the three switches (_decide_letters, _decide_capitals, _decide_two_family_names). The letters decider counts its against votes as carrying when undecided, unlike the other two, so a shared helper would move initials_as_family's printed for and against counts. Only the capitals and two-family pair could merge without moving anything.
  3. A generic switch disagreement in _disagrees: "a bool vote on setting S that differs from decided[S]", in place of the capitals and FIRST_SURNAME special cases. It would make a hand-built Suggestion with two_family_names decided False list True voters as disagreeing. suggest never decides the switch False, so no returned suggestion moves.
  4. Skip the switch's parses for names that can cast no vote (no comma and fewer than three words, or too few possible voters). This changes the printed moved, vetoed and fathers counts. It is also not exact: 30 of 3,177 such names in the committed corpora are still moved by the switch.

Found and left, needing another module or more than this pass

  • suggest got 8 to 20 times slower this cycle, measured by the efficiency review (a 2,000-name group took about 40 ms before and 0.3 to 0.8 s now). The cause is the two_family_names vote: _two_family_votes parses each name with the switch off, and again with it on where the name has a middle. No exact cheaper form exists inside this file. Working out the switched-on family from the off parse would copy rules/O6's predicate. The fix needs a pipeline or Parser entry point that names the word O6 would take in one parse (_pipeline/_post_rules, outside this pass).
  • A per-call memo of parses keyed by (policy, text) would be exact. _letter_run, _capitals_family and _two_family_votes often parse the same text under equal policies: 19% of a Nepali list's parses repeat, and 33% of a capitals list's. It needs threading through three helpers, so it is left for a change of its own rather than added as new machinery in a simplify pass.

Reviews

  1. The pass itself used the simplify skill: four cleanup reviewers (reuse, simplification, efficiency, altitude) over the cycle's diff. Their behavior-preserving findings are the changes above. Their behavior-changing ones are the candidates.
  2. The PR review toolkit on d8f19952:
    • Code (pr-review-toolkit:code-reviewer): every change confirmed equivalent, with the differential above.
    • Comments (pr-review-toolkit:comment-analyzer): five docstrings and comments stated less than the code does. Fixed in e5e2c27d.
    • Tests (pr-review-toolkit:pr-test-analyzer): 16 mutations, 11 killed. The survivors showed the unweighed switch pinned only by its notes' openings, so e5e2c27d adds test_a_switch_not_weighed_says_why_and_casts_no_vote. It holds each note in full, asks the base's own switch before the rule and the order, and checks that no vote is cast. A note asked out of order and a vote cast where the switch is not weighed each fail it.
  3. The fix commit e5e2c27d was reviewed again (pr-review-toolkit:code-reviewer): comment-only in the library, the test real. Its two findings are fixed in a3731a66: _quiet's docstring now names what the construction warning reads, and the test says that only its East Slavic row can show a vote cast. The measured code is d8f19952; both fix commits change only comments and tests.

🤖 Generated with Claude Code

derek73 and others added 2 commits November 22, 2026 01:18
The 3.2 release checklist's step 0 pass over the suggester's changes
since v3.1.0, behavior-preserving:

- _quiet builds a parser under a policy with its construction warnings
  silenced, replacing four copies of the block.
- _two_family_note gives why two_family_names is not weighed, and the
  reader parser is built only where it is.
- _decide_two_family_names tallies the switch with _Tally, as the other
  settings are, instead of a hand copy of its counting and row sort.
- _keeps_family_first counts the PATRONYMIC_POSITION votes already
  cast, and _patronymic_end asks rules/O1's own east_slavic_rotates.
- _decide_order states its FAMILY_FIRST_GIVEN_LAST case as the rule it
  is: a decided East Slavic rule takes the end's own spelling.
- _setting_of, a wrapper of _SETTING_OF, is gone; name_votes loses a
  filter that dropped nothing; _disagrees reads the votes once.
- Two comments lose a measurement and a history the decisions entries
  hold; the Standing line naming _setting_of names its readers now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…itch

The comment review found five docstrings and comments stating less than
the code does: _quiet's reason for silencing a policy other than the
base's, _two_family_note leaving out the base's own switch, a comment
calling a policy a parser, _decide_two_family_names' note, and
_decide_order's opening sentence, which now names the East Slavic case.

The test review found the unweighed switch pinned only by its notes'
openings: test_a_switch_not_weighed_says_why_and_casts_no_vote holds
each note in full, the base's own switch asked before the rule and the
order, and the evidence and every name holding no switch vote. A note
asked out of order and a vote cast where the switch is not weighed
each fail it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derek73 derek73 added this to the 3.2 milestone Nov 22, 2026
@derek73 derek73 added internals Refactors and parse cost with no behavior change suggester The group suggester: Parser.suggest() and its signals labels Nov 22, 2026
@derek73 derek73 self-assigned this Nov 22, 2026
The fix commit's review: _quiet's docstring now names what the
construction warning reads, which no policy it is given changes, and the
unweighed-switch test says only its East Slavic row can show a vote
cast, the other rows pinning the note and the evidence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derek73
derek73 merged commit b339036 into master Nov 22, 2026
14 checks passed
@derek73
derek73 deleted the refactor/simplify-suggest branch November 22, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internals Refactors and parse cost with no behavior change suggester The group suggester: Parser.suggest() and its signals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant