Repository navigation
Simplify _suggest.py with no suggestion moved - #1530
Merged
Merged
Conversation
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>
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>
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.
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 whytwo_family_namesis not weighed. The reasons used to be inline insuggest. The reader parser is now built only where the switch is weighed._decide_two_family_namestallies 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_firstcounts thePATRONYMIC_POSITIONvotes already cast, instead of working the position out again from the words._patronymic_endasks rules/O1's owneast_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_orderstates itsFAMILY_FIRST_GIVEN_LASTcase as the rule it is: a decided East Slavic rule takes the end's own spelling._setting_ofwrapper of_SETTING_OFname_votesfilter that dropped nothing, since_readcasts no switch votedict(name._votes)in_disagreesremovesuffix_setting_ofamong_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.pywas run in both trees: masteraf58ca09in a separate checkout and this branch.--sizes 2,3,4,5,10,20,50,100,200,500,1000,2000--checks(per-name checks)Other checks:
str(s),repr(s.patch), the evidence,repr(s), a pickle round-trip and every name'sname_votes. The digests are identical.tools/differential/snapshot.jsonlis byte-identical, not re-recorded.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 checkanduv run mypyare clean.Behavior-changing candidates
None of these is applied. Each would move a suggestion, its printed evidence, or a hand-built
Suggestion's reading._two_family_votessliceson.familybyoff.family. Readingon.tokens_for(Role.FAMILY)minus the off parse's, orParsedName.surname1, is sturdier. But it changes the taken word wherever the family string and its units differ:surname1treats a connective-joined or bound pair as one unit (Juan y Garciatakesy Garcia,Tariq Abdul AzizAbdul Aziz). The reuse review measured that on 46 of 1,746 moved names, which would move FIRST_SURNAME votes and the evidence._decide_letters,_decide_capitals,_decide_two_family_names). The letters decider counts its against votes ascarryingwhen undecided, unlike the other two, so a shared helper would moveinitials_as_family's printed for and against counts. Only the capitals and two-family pair could merge without moving anything._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-builtSuggestionwithtwo_family_namesdecided False list True voters as disagreeing.suggestnever decides the switch False, so no returned suggestion moves.Found and left, needing another module or more than this pass
suggestgot 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 thetwo_family_namesvote:_two_family_votesparses 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 orParserentry point that names the word O6 would take in one parse (_pipeline/_post_rules, outside this pass)._letter_run,_capitals_familyand_two_family_votesoften 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
simplifyskill: 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.d8f19952:pr-review-toolkit:code-reviewer): every change confirmed equivalent, with the differential above.pr-review-toolkit:comment-analyzer): five docstrings and comments stated less than the code does. Fixed ine5e2c27d.pr-review-toolkit:pr-test-analyzer): 16 mutations, 11 killed. The survivors showed the unweighed switch pinned only by its notes' openings, soe5e2c27daddstest_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.e5e2c27dwas reviewed again (pr-review-toolkit:code-reviewer): comment-only in the library, the test real. Its two findings are fixed ina3731a66:_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 isd8f19952; both fix commits change only comments and tests.🤖 Generated with Claude Code