Repository navigation
Attach the installed Japanese segmenter under python -m nameparser --locale ja - #984
Merged
Merged
Conversation
…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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
…ocales.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>
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>
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 nameparser --locale jatook the pack but had no way to attach a segmenter, so it divided nothing and warned (rules/D1, the segmenterless-activation warning). It now attacheslocales.ja_segmenter()when namedivider is installed:importlib.util.find_spec; any failure to load an installed one (numpy'sImportError, anOSError) propagates with its own message rather than being reported as "not installed".nameparser: --locale ja divides unspaced names only with namedivider-python installed: pip install 'nameparser[ja]'in place of the parser's warning, which it filters by message: that warning's other remedies are code a command line cannot pass, and a print still shows underPYTHONWARNINGS=ignore.parser_for(locales.JA)still needssegmenter=locales.ja_segmenter()and still warns without one. decisions/D1's new entry records the library-wide form as declined: the same code would parse高橋一郎differently with and without the extra, aParserholdingja_segmenter()cannot be pickled (local closure), soparser_for(locales.JA)would stop pickling wherever the extra is installed, and the pack-and-segmenter pairing is explicit by design.japack consults the factory.Tests (
tests/v2/test_cli.py)In process, with the install stood in for so every branch runs in every environment: the segmenter attaches under
jaandJAand survives each--order, with no warning; the missing extra prints the note once and warns nothing, with and without--order; a broken install fails with its ownImportErrororOSError;zhnever calls the factory. Plus one subprocess run per environment, each skipping where it cannot apply (the extra one runs only in theja-extrajob). Mutations checked against them: a broadexcept ImportError(3 fail), the segmenter dropped under--order(6), the warning not filtered (3), the factory called for every pack (1). #983's warns-once test is gone: the CLI no longer reaches that warning.Docs:
usage.rst's "has no way to attach one" paragraph rewritten,locales.rst's "equivalent toparser_for(locales.get(...))" qualified forja, release-log bullet.No parser behavior changes, so no rules or snapshot moves.
Test plan
uv run pytestwithout the extra (34,158 passed)uv run --with 'namedivider-python>=0.4' pytest(34,181 passed)uv run mypy,uv run ruff check,sphinx-build -b htmlclean for the edited pages🤖 Generated with Claude Code