Repository navigation
Description
Lexicon.remove with a kind the word does not have returns a new lexicon and says nothing, and the parse is unchanged:
>>> from nameparser import Lexicon, Parser
>>> lex = Lexicon.default().remove("alhaj", kind="religious") # alhaj is a style
>>> Parser(lexicon=lex).parse("Alhaj Ahmed Khan").title
'Alhaj'The same holds for a word in no file at all (remove("zzyzx", kind="title")), a typo's usual shape. The only sign is the repr, Lexicon(default + edits: 1) where a remove that took a reading prints Lexicon(default + style: -1).
A recipe in docs/migrate.rst shipped this way: it removed alhaj under the wrong kind, and its doctest passed because the assertion shown was true with or without the call. The 3.2 docs sweep found it by review (#1534).
When a remove(*words, kind=...) names a word and a kind, or a word alone, and no vocabulary file holds a reading of that word in that kind (or any reading of the word, with no kind), counting readings a choice of languages would turn on (default = false).
Then the call emits a UserWarning naming the word, the kind asked for and the kinds the word does hold, and still returns the lexicon with the edit logged, as today. For the example: 'alhaj' has no 'religious' reading in any vocabulary file; its readings are: style. Did you mean remove("alhaj", kind="style")?
Because the edit can never take effect under any choice of languages, so it is indistinguishable from a working one, and the caller who wrote it meant something. A raise would be wrong by the project's own rule (an inert entry misparses nothing), and a caller who wants the inert edit can filter the warning.
Except
- A reading some file holds but the current lexicon has off stays silent:
remove("piedade", kind="given")on the default, which a Portuguese choice turns on. That is the case the docstring keeps the edit for. - A reading the same lexicon's own earlier
addsupplied is held, so it is silent, and removing it twice stays silent. remove(kind=..., every=True)names no word and is not in scope.- The
familiarandspellingpair removes are matched by folded forms through another index; whether a pair that matches nothing warns is a separate question, left out here.
Boundaries to check when building
- The category kinds (
kind="title",kind="name") match several kinds; warn only where none of them is held. - A locale pack's lexicon fragment that removes a reading (
locales.CS,locales.VI) must stay warning-free, and so must the default vocabulary build; both have tests of that form already. parser_forre-emits construction warnings from its own frame; a warning raised inremoveis raised at the caller's own line and needs no re-emission, but the stack level should be checked through chainedLexicon.default().remove(...)calls.- The message offers code, so a test must run the offered call.
Accepted A word spelled in a way the fold does not reach (a transliteration the files do not list) warns as an unknown word. That is the intended signal.
Open Whether add(..., kind=...) of a reading the word already holds, with the same properties, deserves the same treatment. It is also inert, but it is the natural result of copying a recipe, so probably not.
🤖 Generated with Claude Code
Activity
Address the first review round of the remove warning (#1535)
Narrow the remove warning's full-stop and list cases (#1535)
Offer the reading a dotted spelling is read by, and count the lexicon…
Name the bare spelling whenever a dotted word is an acronym or dotted…
Warn when Lexicon.remove names a reading no vocabulary file holds (#1536