Skip to content

Commit 093a07e

Browse files
derek73claude
andcommitted
Address the fix review of #1533: every setting offered code it takes
- A setting no signal votes on (initials_as_family, capitals_as_family, any other Policy field) was still offered a name_order row by the fallback, which it refuses: it is now told no signal votes on it and offered `by_signal=()`, and its by_signal iterable `()`. - The two remaining "a {kind}" messages (attached on a reading, a phrase matching as a kind) take `_a`. - locales.VI's docstring: CS's fragment removes a reading too (#970). - Tests: the offered-row test runs both messages over the five settings suggest emits, the article test over every kind, the completed_by clause's text is pinned, and both signal helpers assert they yield rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 02071bc commit 093a07e

5 files changed

Lines changed: 56 additions & 24 deletions

File tree

‎nameparser/_lexicon.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ def _prop_value(kind: str, prop: str, value: object) -> object:
10331033
side = ("before" if _index_module().CATEGORY.get(kind) == "title"
10341034
else "after")
10351035
if value != side:
1036-
raise ValueError(f"attached on a {kind!r} reading must be "
1036+
raise ValueError(f"attached on {_a(kind)} {kind!r} reading must be "
10371037
f"{side!r} (a {'title peeled off the start' if side == 'before' else 'tail peeled off the end'} "
10381038
f"of a name token) or None, got {value!r}")
10391039
return value
@@ -1251,7 +1251,7 @@ def _make_edit(op: object, words: object, kind: object,
12511251
if " " in w and not (k == "birth_marker" or (
12521252
category == "title" and ("addresses", "given") in p)):
12531253
raise ValueError(
1254-
f"{w!r} is a phrase, which can never match as a {k}: only "
1254+
f"{w!r} is a phrase, which can never match as {_a(k)} {k}: only "
12551255
f"a birth_marker and a title with addresses='given' are "
12561256
f"matched as a whole run; add its words one by one")
12571257
# the build refuses attached on a title phrase: the glued-title

‎nameparser/_suggest.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,9 @@ def _checked_row(row: object, setting: str) -> tuple[Signal, Vote, int]:
681681
or len(row) != 3:
682682
raise TypeError(
683683
f"SettingEvidence by_signal rows must be (signal, vote, count) "
684-
f"triples, got {reprlib.repr(row)}; pass e.g. "
685-
f"{_ROW_EXAMPLE.get(setting, _ROW_EXAMPLE[_NAME_ORDER])}")
684+
f"triples, got {reprlib.repr(row)}; "
685+
+ (f"pass e.g. {_ROW_EXAMPLE[setting]}" if setting in _ROW_EXAMPLE
686+
else f"no signal votes on {setting}, so pass by_signal=()"))
686687
signal, vote, count = row
687688
pair = _checked_vote(signal, vote, "SettingEvidence by_signal")
688689
if _SETTING_OF[pair[0]] != setting:
@@ -874,8 +875,8 @@ def __post_init__(self) -> None:
874875
f"pass '' for no note")
875876
rows = _iterable(self.by_signal, "SettingEvidence by_signal",
876877
"an iterable of (signal, vote, count) rows",
877-
f"({_ROW_EXAMPLE.get(self.setting, _ROW_EXAMPLE[_NAME_ORDER])},)"
878-
" or ()")
878+
(f"({_ROW_EXAMPLE[self.setting]},) or ()"
879+
if self.setting in _ROW_EXAMPLE else "()"))
879880
object.__setattr__(
880881
self, "by_signal",
881882
tuple(_checked_row(row, self.setting) for row in rows))

‎nameparser/locales/vi.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
the English credential would take it (decisions/vocabulary-model, the
1515
2026-11-05 #1108 entry).
1616
17-
The fragment is the one pack content that removes: a choice prefers
17+
The fragment removes readings rather than adding them, as only
18+
locales.CS's does besides (``Ing``'s given reading): a choice prefers
1819
only by a vocabulary reading, and a name reading never settles a clash
1920
(decision 15 of decisions/vocabulary-model), so no reading vi.toml
2021
could write makes ``van`` a name word under a plain choice. The order

‎tests/v2/test_lexicon.py‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,6 +2242,10 @@ def test_completed_by_none_clears_the_list_the_message_offers_to_clear() -> None
22422242
Lexicon.default().add("عبد", kind="bound_given", completed_by=[])
22432243
offered = str(refused.value).split("write ", 1)[1].split(" to clear")[0]
22442244
assert offered == "completed_by=None"
2245+
# what it clears to: the word keeps P5's join, but no listed word
2246+
# completes it any more
2247+
assert str(refused.value).endswith(
2248+
"which leaves no listed word completing it")
22452249
shipped = [dict(r.properties) for r in
22462250
Lexicon.default().readings_of("عبد")
22472251
if r.kind == "bound_given"]
@@ -2254,10 +2258,15 @@ def test_completed_by_none_clears_the_list_the_message_offers_to_clear() -> None
22542258
assert Parser(lexicon=cleared).parse("سامر نور عبد الله").family == "الله"
22552259

22562260

2257-
@pytest.mark.parametrize("kind, article", [
2258-
("academic", "an"), ("alias_marker", "an"), ("article", "an"),
2259-
("honorific", "an"), ("occupation", "an"), ("title", "a"),
2260-
("nobility", "a"), ("given", "a")])
2261+
def _article_rows() -> list[tuple[str, str]]:
2262+
from nameparser._reading_index import CATEGORY
2263+
rows = [(kind, "an" if kind[:1] in "aeiou" or kind == "honorific"
2264+
else "a") for kind in sorted(CATEGORY)]
2265+
assert any(a == "an" for _, a in rows) and any(a == "a" for _, a in rows)
2266+
return rows
2267+
2268+
2269+
@pytest.mark.parametrize("kind, article", _article_rows())
22612270
def test_a_refused_property_names_the_kind_with_its_article(
22622271
kind: str, article: str) -> None:
22632272
# every kind beginning with a vowel, and honorific, whose h is

‎tests/v2/test_suggest.py‎

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,9 +3693,11 @@ def test_a_switch_not_weighed_says_why_and_casts_no_vote(
36933693
def _non_order_signals() -> list[tuple[Signal, object, str, object]]:
36943694
from nameparser._suggest import _SETTING_OF
36953695
bad = {"two_family_names": 1, "patronymic_rules": "east-slavic"}
3696-
return [(signal, bad[setting], setting, _SETTING_VALUES[setting])
3696+
rows = [(signal, bad[setting], setting, _SETTING_VALUES[setting])
36973697
for signal, setting in _SETTING_OF.items()
36983698
if setting != "name_order"]
3699+
assert rows
3700+
return rows
36993701

37003702

37013703
@pytest.mark.parametrize("signal, bad, setting, value", _non_order_signals())
@@ -3718,24 +3720,43 @@ def test_a_refused_vote_offers_its_owners_shape_and_the_code_runs(
37183720
(row,))
37193721

37203722

3721-
37223723
def _settings_voted_on() -> list[str]:
37233724
from nameparser._suggest import _SETTING_OF
3724-
return sorted(set(_SETTING_OF.values()))
3725+
settings = sorted(set(_SETTING_OF.values()))
3726+
assert settings
3727+
return settings
3728+
3729+
3730+
#: The settings ``Parser.suggest`` returns evidence for: the three a
3731+
#: signal votes on, and two it decides with no signal's row
3732+
_EMITTED = (*_settings_voted_on(), "initials_as_family", "capitals_as_family")
37253733

37263734

3727-
@pytest.mark.parametrize("setting", _settings_voted_on())
3728-
def test_a_row_that_is_no_triple_is_offered_a_row_of_its_own_setting(
3735+
@pytest.mark.parametrize("setting", _EMITTED)
3736+
def test_a_refused_by_signal_is_offered_code_its_own_setting_takes(
37293737
setting: str) -> None:
3730-
# every setting a signal votes on is offered a row whose signal
3731-
# votes on it (the name_order row was offered for every setting
3732-
# until the 3.2 prose sweep), and the offered row is accepted
3733-
value = _SETTING_VALUES[setting]
3738+
# a row that is no triple, and a by_signal that is no iterable, are
3739+
# each offered code the evidence's own setting accepts: a row whose
3740+
# signal votes on it, or no row where no signal does (the name_order
3741+
# row was offered for every setting until the 3.2 prose sweep)
3742+
from nameparser._suggest import _SETTING_OF
3743+
value = _SETTING_VALUES.get(setting, True)
37343744
names = {"Signal": Signal, "PatronymicRule": PatronymicRule,
37353745
"FAMILY_FIRST": FAMILY_FIRST}
3736-
with pytest.raises(TypeError) as refused:
3746+
voted_on = setting in set(_SETTING_OF.values())
3747+
with pytest.raises(TypeError) as refused_row:
37373748
SettingEvidence(setting, value, True, 2, 0, 0, 0, # type: ignore[arg-type]
37383749
("x",)) # type: ignore[arg-type]
3739-
row = eval(str(refused.value).rsplit("pass e.g. ", 1)[1], names)
3740-
SettingEvidence(setting, value, True, 2, 0, 0, 0, # type: ignore[arg-type]
3741-
(row,))
3750+
if voted_on:
3751+
row = eval(str(refused_row.value).rsplit("pass e.g. ", 1)[1], names)
3752+
SettingEvidence(setting, value, True, 2, 0, 0, 0, # type: ignore[arg-type]
3753+
(row,))
3754+
else:
3755+
assert str(refused_row.value).endswith("pass by_signal=()")
3756+
with pytest.raises(TypeError) as refused_rows:
3757+
SettingEvidence(setting, value, True, 2, 0, 0, 0, # type: ignore[arg-type]
3758+
5) # type: ignore[arg-type]
3759+
offered = str(refused_rows.value).rsplit("pass e.g. ", 1)[1]
3760+
for code in offered.split(" or "):
3761+
SettingEvidence(setting, value, True, 2, 0, 0, 0, # type: ignore[arg-type]
3762+
eval(code, names))

0 commit comments

Comments
 (0)