Repository navigation
Add --order to python -m nameparser - #983
Merged
Merged
Conversation
The command line helper read every name in the default order. --order takes given-first, family-first or family-first-given-last, the three Policy.name_order values, and is applied after --locale so the explicit flag wins over an order a pack sets. Adds tests/v2/test_main.py, the CLI's first test module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of the first commit: dataclasses.replace on the built Parser ran Parser.__post_init__ a second time, so --locale ja --order printed the segmenterless warning twice, the copy attributed to dataclasses.py. The order now goes into the pack's own PolicyPatch (or a pack of its own), so parser_for builds once and re-emits from main's frame, and a pack's order is replaced without a two-pack conflict warning. The tests move into the existing tests/v2/test_cli.py, dropping two that repeated it, and gain rows for a pack's policy kept (cs), a pack's order replaced (a stand-in pack, since none ships one), a Han name keeping its script's order, one warning, and _ORDERS held to _locale's. The help, usage.rst and release log state the script and comma limits, and the bullet links the PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
derek73
added a commit
that referenced
this pull request
Oct 31, 2026
Review of #984: the fallback caught every ImportError, so an installed but broken namedivider (numpy failing to import) was reported as not installed, its cause dropped; and the parser's warning it fell back to offered remedies that are code a command line cannot pass, and showed nothing under PYTHONWARNINGS=ignore. The CLI now tests for the package with find_spec, lets any load failure propagate, and in its absence prints a note naming the install and filters the parser's warning by message. Tests: the segmenter survives every --order and an uppercase JA; the missing extra notes once and warns nothing; a broken install fails with its own ImportError or OSError; the zh check records calls rather than raising, since a broad catch would have swallowed the AssertionError. #983's warns-once test goes: the CLI no longer reaches that warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
derek73
added a commit
that referenced
this pull request
Oct 31, 2026
…locale ja (#984) * Attach the installed Japanese segmenter under python -m nameparser --locale ja The CLI took the ja pack but had no way to attach a segmenter, so --locale ja divided nothing and warned. It now calls locales.ja_segmenter() for the ja pack and passes it to parser_for, falling back to the segmenterless parser, and its warning, when the extra is not installed. parser_for(locales.JA) stays explicit: decisions/D1 records the library-wide form as declined, since the same code would parse differently with and without the extra. The #983 warning test assumed --locale ja always warns; it now makes the extra missing, so it holds in the ja-extra job too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Link #984 from its release-log bullet Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Fall back only on a missing namedivider, with a note in the CLI's terms Review of #984: the fallback caught every ImportError, so an installed but broken namedivider (numpy failing to import) was reported as not installed, its cause dropped; and the parser's warning it fell back to offered remedies that are code a command line cannot pass, and showed nothing under PYTHONWARNINGS=ignore. The CLI now tests for the package with find_spec, lets any load failure propagate, and in its absence prints a note naming the install and filters the parser's warning by message. Tests: the segmenter survives every --order and an uppercase JA; the missing extra notes once and warns nothing; a broken install fails with its own ImportError or OSError; the zh check records calls rather than raising, since a broad catch would have swallowed the AssertionError. #983's warns-once test goes: the CLI no longer reaches that warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Correct D1's pickle reason and cite #984; note the CLI's ja path in locales.rst Review of #984: a Parser holding ja_segmenter() cannot be pickled at all (its segmenter is a local closure), so the declined library-wide attach would stop parser_for(locales.JA) pickling wherever the extra is installed, not carry a callable. The entry gains its verdict headline and #984, the Standing line points at it, and both describe the note that now replaces the warning. locales.rst no longer reads as if the CLI were parser_for(locales.get(code)) for every code; usage.rst and the release log say note, not warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Test the CLI's namedivider check itself Every in-process test stands in for _ja_extra_installed, and the subprocess runs that reach it are not measured, so its line went uncovered (codecov/patch 94.73%). The new test calls it and holds it to the find_spec answer the subprocess tests' skips are keyed on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- 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.
Summary
python -m nameparserread every name in the default order. It now takes--order, one ofgiven-first,family-firstorfamily-first-given-last(the threePolicy.name_ordervalues, spelled as the vocabulary[rules]tables spell them):Without the flag the same name gives given
Kovács, familyPéter.--locale, the order is written into the pack's ownPolicyPatch, so it replaces any order the pack sets (none ships one today) withoutparser_for's two-pack conflict warning, and the parser is built once, soparser_forre-emits a construction warning (the--locale jasegmenterless one) frommain's frame, once.docs/usage.rstand the release log: a name wholly in Han, Hangul or kana keeps its script's order (Policy.script_orders), and a family comma fixes the order.choices).tests/v2/test_cli.py, in process: each order; a pack's vocabulary (es,Lic) and policy (cs, two family names) kept under--order; a stand-in pack's order replaced; a Han name keeping its order; exactly one warning, attributed to__main__.py; the CLI's_ORDERSheld equal to_locale._ORDERS, of which it is a copy because__main__imports only the public package.No parser behavior changes, so no rules or snapshot moves.
Test plan
uv run pytest(34,146 passed)uv run mypyuv run ruff check🤖 Generated with Claude Code