Skip to content

Add the Policy switches to python -m nameparser - #1114

Merged
derek73 merged 5 commits into
masterfrom
feat/cli-policy-flags
Nov 6, 2026
Merged

derek73 merged 5 commits into
masterfrom
feat/cli-policy-flags

Conversation

@derek73

@derek73 derek73 commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Summary

Lets the command line try a rule on one name, to see whether a Policy switch already resolves a parse problem.

  • --two-given-names, --two-family-names, --middle-as-family, --lenient-comma-suffixes, --unlisted-dotted-suffixes, each with a --no- form (argparse.BooleanOptionalAction), and --unlisted-caps-suffixes {off,after-comma,everywhere}, its choices read from CapsSuffixes.
  • Flags are spelled as the field they set. Like --order, each is written into the --locale pack's own PolicyPatch, so it replaces the pack's setting (--locale es --no-two-family-names) and a flag left out keeps the pack's value.
  • The other Policy fields stay off the command line on purpose, listed in _NOT_ON_THE_COMMAND_LINE: script_orders, segment_scripts, patronymic_rules and the three delimiter sets need real setup, and strip_emoji/strip_bidi are input clean-up. test_cli_sorts_every_policy_field_into_a_flag_or_a_reason holds the tables to dataclasses.fields(Policy), so a new field fails until someone decides.
$ python -m nameparser --two-given-names --json "Juan Carlos García"
{"title": "", "given": "Juan Carlos", "middle": "", "family": "García", ...}
$ python -m nameparser --locale es --no-two-family-names --json "Gabriel García Márquez"
{"title": "", "given": "Gabriel", "middle": "García", "family": "Márquez", ...}

No parser behavior changes, so no rules docs move; docs/usage.rst's command-line section and the release log gain a paragraph and a bullet.

Test plan

  • Each switch in both directions, with a row-coverage check against _SWITCHES
  • Each --unlisted-caps-suffixes value on a comma name and a trailing-capitals name, with a row-coverage check against CapsSuffixes
  • A flag overriding a pack's setting, a flag left out keeping it, a flag combined with --order
  • A stand-in pack per flag setting its field against the default: left out, the pack's value holds; given the other way, the flag wins. Forcing an omitted flag to the Policy default fails it for every field that mutation reaches
  • uv run pytest (38,961 passed), uv run mypy, uv run ruff check

🤖 Generated with Claude Code

--two-given-names, --two-family-names, --middle-as-family,
--lenient-comma-suffixes and --unlisted-dotted-suffixes (each with a
--no- form) and --unlisted-caps-suffixes {off,after-comma,everywhere}
set the Policy field of their name, written into the --locale pack's
own patch as --order is, so each replaces a pack's setting and one
left out keeps it. A test sorts every Policy field into a flag or a
named reason it has none, so a new field must be decided.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
derek73 and others added 4 commits November 6, 2026 12:13
…er flag

The argparse quoting differs only on 3.12 (bare) against 3.11 and 3.13
on (quoted), so AGENTS.md's sentence and the test comment say so and
point at matching a message in a form every interpreter writes.
--unlisted-caps-suffixes gains a one-line help, the two_family_names
help and the delimiter comment say what the fields hold, and the
examples contrast the pack (Lic) with the flag. A stand-in pack per
flag proves a flag left out keeps the pack's setting and one given
wins, for every flag rather than only two_family_names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@derek73 derek73 added this to the 3.0 milestone Nov 6, 2026
@derek73
derek73 merged commit 0a4233f into master Nov 6, 2026
13 checks passed
@derek73
derek73 deleted the feat/cli-policy-flags branch November 6, 2026 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant