Repository navigation
Warn when Lexicon.remove names a reading no vocabulary file holds - #1536
Merged
Merged
Conversation
) remove(word, kind=...) of a kind the word does not hold, or of a word in no file, took nothing and said nothing: docs/migrate.rst's alhaj recipe shipped that way, its doctest passing without the edit. remove() now emits a UserWarning for each such word, naming the kinds it does hold and offering the remove that would take one. A reading counts if any file holds it, on by default or not (a choice may turn it on), or if an earlier add() of the same lexicon gave it; a category counts where any of its kinds is held. The warning is raised at the caller's own line through _warn_at_caller, in remove() alone, so a lexicon replaying its log (dataclasses.replace, a pickle load) never warns again. remove of every word's readings and the familiar and spelling pair removes are not judged. Three tests removed a reading on purpose that the warning now names, and assert it: a remove before the add it would undo, a no-kind remove of a name held only as another word's pair, and a pack fragment removing a reading another fragment adds, which remove() cannot see. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ecisions, AGENTS.md (#1535) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ove-inert-warning
…ame held only in pairs (#1535) The message now tells three cases apart: a word in the vocabulary without that kind (its kinds and the call that takes one), a word in no file and no earlier add, and, with no kind, a word holding no reading of its own, only the other name of another word's familiar or spelling pair, for which it offers remove(word, kind="familiar") or "spelling", the call that reaches pairs; a test runs that call and checks the pair goes. The docstring, docs/customize.rst and the decisions entry state the accepted case in the issue's terms: a fragment meant to remove a word another lexicon adds warns, since remove cannot see the lexicon it will be joined with, and its caller filters that warning by its message, never by category, or removes on the joined lexicon; customize.rst's recipe shows the filter, with a title example whose output moves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ove-inert-warning # Conflicts: # tests/v2/test_lexicon.py
The messages: - open with the call and "changes nothing" in every case, so the by-message filter covers them all; - offer a call only where one kind is plainly meant, the single held kind of the asked category or else the single held kind, and never a familiar or spelling kind (dean/particle offered the family reading, don/title a pair remove); - say "in any vocabulary file or earlier add()", the add counting; - find a pair's other name through the reading index as well as the compiled pairs, so robert with a kind and abigail on Lexicon.empty() read as pair names, not as words to check the spelling of; - tell a word held only in the surnames or given_names list how to drop it, with code a test runs; - tell Ph.D., which remove stores as ph.d and the vocabulary as phd, to remove phd: a real no-op the cased and dotted rows turned up; - name the joined-lexicon remedy beside the spelling one; - warn once for a word named twice. Docs: remove's docstring states the cases and that a joined lexicon's adds count; customize.rst's lead names the two common cases, its quoted message updated; the release-log bullet says 3.0.0 through 3.1.0 and keeps one limit sentence; the decisions entry states the five cases and the offer rule, declines an add-repeat warning, which leaves the reading the caller wanted, replaces the Open line, and gains its Standing line; the recipe-doctest lesson moves from root AGENTS.md's validation bullet into docs/AGENTS.md's non-vacuous paragraph, where a docs writer meets it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of the fix commit found the full-stop case offering another
word: remove("j.r.") was offered remove("jr"), though the parse never
reads J.R. as jr, and that remove changes how Jr. reads; and it ignored
the kind asked, so remove("m.d.", kind="title") offered a remove that
takes nothing either. It now fires only where the bare word is a suffix
acronym or a dotted title, the spellings the parse reads with their
stops dropped, and holds the kind asked; else the word is reported as
in no file. The list case offers dropping the entry only where the kind
asked is the list's (family or name for the surnames, given or name for
the given names). Test rows hold j.r. and m.d. as a title in case (v).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'s adds there (#1535) Review of the narrowing found remove("M.D.") offering remove("md"), which also takes md's given reading (Muhammad written short) and moves "Md. Ali Khan"; with no kind asked the full-stop case now names the kind the dotted spelling is read by, the suffix acronym's suffix reading or the dotted title's title one, offering remove("md", kind="credential"). The bare word's kinds now count the lexicon's own earlier adds, as the word's do, so an acronym a caller added (xq) is offered and not reported as in no file. The list case's third test, which could never hold, is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… title (#1535) Review of 612d7ec found a dotted acronym or title falling to "in no vocabulary file" where no call was plainly meant (us read by two title kinds after a caller's add; M.D. asked as given, Ph.D. as title); the message now always names the bare word, offers the call where one kind is plainly meant, and otherwise lists the kinds the dotted spelling is read by. Tests now run the full-stop offers: remove('md', kind='credential') takes M.D.'s suffix and leaves "Md. Ali Khan" given, and an added acronym's offer takes it. The decisions entry states case (iv)'s condition as the code reads it, and records as accepted that rules/S3's dotted shape still reads Ph.D. as a suffix after the offered remove takes the vocabulary's reading. 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.
Closes #1535
Lexicon.removewarns where no vocabulary file holds the reading it names and no earlieradd()of the lexicon gave it, so the edit can take effect under no choice of languages. It still returns the lexicon with the edit logged, as before.The rule
What counts as held: for each word, every kind the reading index gives it (
_reading_index.readings_of, every file's row whether on by default or not, the word looked up asremovestores it), plus every kind an earlieraddin the same lexicon's log gave it. A category (kind="title",kind="name") counts where any of its kinds is held.The message. Every message opens with the call and "changes nothing", so a caller can filter one by message. It then names one of five cases:
remove("alhaj", kind="religious")remove('alhaj', kind='style')only where one kind is plainly meant, never a pair kind (dean/particleoffers nothing,don/titlelistsfamiliarand offers nothing)surnamesorgiven_nameslistremove("김", kind="family")remove()does not edit the list; offers thedataclasses.replacethat drops itremove("robert", kind="given"),Lexicon.empty().remove("abigail")remove('robert', kind='familiar'); pair names are found through the reading index as well as the compiled pairsremove("Ph.D.", kind="credential"), storedph.dremove('phd', kind='credential'); with no kind it names the kind the spelling is read by (M.D.getsmd's credential reading, not its given reading);J.R.is no such spelling and offers nothingremove("zzyzx", kind="title")A test runs each offered call and checks it takes what the inert one missed. A word named twice in one call warns once.
Case (iv) caught a real silent no-op:
remove("Ph.D.", kind="credential"), the spelling a caller plausibly writes, took nothing, becauseremovestoresph.dwhile the vocabulary storesphd.Silent, as the issue's Except lists:
remove("piedade", kind="given"));remove("dean", kind="title"));every=True;familiarandspellingpair removes.Where it is raised: in
remove()alone, through_warn_at_caller. A test checks the warning's filename and line through a plain call, a chainedLexicon.default().remove(...).remove(...)andParser(lexicon=...). Replaying the log (dataclasses.replace, a pickle load, a parse) warns nothing again, and a test covers that too.Accepted: a fragment meant to remove a word another lexicon adds warns, since
removecannot see the lexicon it will be joined with. Its caller filters that warning by its message, never by category, or does the remove on the joined lexicon; docs/customize.rst gives the recipe. A fragment removing a file's reading, which is how a pack is written, stays silent. Every shipped pack, plain and strict, builds warning-free, and a test holds that.Where it fired in the repository
With pytest's warnings-as-errors, the full suite,
sphinx-build -b doctest docs,python -m doctest README.rstand the packs were run. It fired in three tests and nowhere else (no docs page, README example, tool or pack). Each is a test that removes an inert reading on purpose. Each now takespytest.warnswith a match on the message and still asserts what it asserted before. These are the only expectation changes:tests/v2/test_parser.py::test_a_packs_fragment_joins_under_the_callers_lexicon: packbb'sLexicon.empty().remove("zzq", kind="title")takes out packaa's added word when joined. This is case (ii), the accepted case above.tests/v2/test_lexicon.py::test_a_later_edit_reads_after_an_earlier_one:Lexicon.empty().remove("x")before theaddit precedes, case (ii).tests/v2/test_match.py::test_a_remove_of_every_reading_of_a_word_keeps_the_pairs_other_words_hold:remove("zzrobert")with no kind, a name held only in another word's pair, case (iii).The second silent no-op the issue grew from, docs/migrate.rst's
alhajrecipe, was fixed by #1534 before this branch. On this tree it does not warn.No parse moves
tools/differential/snapshot.jsonlis byte-identical.tools/perf/call_count.py --against origin/master: 195.72 frames per parse on both, py3.11.removeis not on the parse path, and_pair_names, which scans the reading index, is cached and reached only on the warning path.Negative control
The new and changed tests were run against master's
nameparser/_lexicon.pyin a scratch copy. Every warning test fails there (11), and the silent cases pass either way.Docs
Lexicon.remove's docstring: the rule, the three cases and the accepted fragment case.Lexicon.removenames a reading no vocabulary file holds (remove("alhaj", kind="religious")) #1535 entry with the rule, where it is raised, why a warning, what is accepted, what was measured, and the issue's open question onadd.addof a reading the word already holds, with the same properties, warn too?) is settled as Declined, recorded in the decisions entry with the reason. An inert remove leaves a reading the caller wanted gone, so the parse is not what they asked for. A redundant add leaves the reading the caller wanted present, so the parse is what they asked for. Its usual cause is a recipe a later release made unnecessary, so a warning would fire on working code after every upgrade that ships a word a caller had added.Closes #1535therefore closes it whole._a) is not used: no message here writes "a/an {kind}"; each quotes the kind ('religious').Reviews
code-reviewer,pr-test-analyzer(10 mutations, 8 killed; the two survivors gained rows: cased and dotted words, a multi-kind offer),comment-analyzer,silent-failure-hunter,design-docs-reviewer. Fixed in b76658c:dean/particleofferedfamily), so it is now offered only where one kind is plainly meant, and never a pair kind;Lexicon.empty(), was told to check its spelling;surnameslist was told the same;Ph.D.no-op (case iv).j.r.offeredjr, though the parse never readsJ.R.asjr) and ignored the kind asked; the list case ignored the kind. Fixed in 1836fb0.M.D.offeredremove('md'), which also takes Muhammad's given reading; the bare word's kinds missed the lexicon's own adds; a dead clause. Fixed in 612d7ec.remove("m.d.", kind="title")) gets case (v)'s spelling advice. Nothing wrong is offered there.uswith two title kinds after an add;M.D.asked asgiven); the decisions entry's case (iv) condition was looser than the code; and no test ran the full-stop offers. Fixed in the head commit:M.D.offer, which takes the suffix and leavesMd. Ali Khangiven, and an added acronym's offer.Ph.D.as a suffix after the offered remove takes the vocabulary's reading.Not applicable:
type-design-analyzer(no type added) andcode-simplifier.🤖 Generated with Claude Code