Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions nameparser/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,6 @@ def parser_for(*locales: Locale, base: Parser | None = None,
# segmenter it was asked to drop.
if segmenter is UNSET:
segmenter = base.segmenter if base is not None else None
# one choice for all the packs and the base's, so applying them is
# order-free; each pack's tags are checked on their own first, so a
# tag no file holds is reported with the pack that named it
# (rules/D2)
# strict's three states, as segmenter's: omitted keeps base's
# strictness; an explicit False on a strict base is refused, a
# strict choice not being undone by a later call, and an explicit
Expand All @@ -475,14 +471,18 @@ def parser_for(*locales: Locale, base: Parser | None = None,
"choice keeps it: leave strict out or pass strict=True, or "
"choose every language in one call from the default lexicon, "
"base's packs included, parser_for(*packs, strict=False)")
# one choice for all the packs and the base's, so applying them is
# order-free; each pack's tags are checked on their own first, so a
# tag no file holds is reported with the pack that named it
# (rules/D2)
languages = lexicon.languages
for loc in locales:
if loc.languages:
try:
_reading_index_selected(loc.languages, strict)
except ValueError as exc:
raise ValueError(
f"while applying locale {loc.code!r}: {exc}") from exc
raise _rewrapped(
exc, f"while applying locale {loc.code!r}") from exc
languages |= loc.languages
if strict and not languages:
raise ValueError(_no_strict_language(locales))
Expand All @@ -508,6 +508,9 @@ def parser_for(*locales: Locale, base: Parser | None = None,
scalars = [f.name for f in dataclasses.fields(PolicyPatch)
if f.metadata.get("compose") != "union"]
for loc in locales:
# rules/D2: "applying a locale pack wraps any such error with
# the locale's code, so a stacked configuration names which layer
# broke" (history: decisions/D2)
try:
policy = apply_patch(policy, loc.policy)
except (TypeError, ValueError) as exc:
Expand All @@ -528,9 +531,6 @@ def parser_for(*locales: Locale, base: Parser | None = None,
# scripts with no covering surnames and no segmenter warns at
# construction, naming the dead scripts and each way out"
# (history: decisions/D1)
# rules/D2: "applying a locale pack wraps any such error with
# the locale's code, so a stacked configuration names which layer
# broke" (history: decisions/D2)
# Construction warnings (the segmenterless-activation check in
# Parser.__post_init__) re-emit from THIS frame: its stacklevel is
# sized for direct Parser(...) construction, and through this
Expand All @@ -548,17 +548,17 @@ def parser_for(*locales: Locale, base: Parser | None = None,
def _no_strict_language(locales: tuple[Locale, ...]) -> str:
"""The refusal of a strict call that chooses no language, which
would keep only mul.toml's and native-script vocabulary, dropping
every language's own words in silence. The fix it offers is a pack choosing the first pack's
code where that is a language a strict choice accepts, else
``en``."""
every language's own words in silence. The fix it offers is a pack
choosing the first pack's code where that is a language a strict
choice accepts, else ``en``."""
tag = "en"
for loc in locales[:1]:
if locales:
try:
_reading_index_selected(frozenset({loc.code}), True)
_reading_index_selected(frozenset({locales[0].code}), True)
except ValueError:
pass
else:
tag = loc.code
tag = locales[0].code
codes = ", ".join(repr(loc.code) for loc in locales)
named = ("no pack was given" if not locales
else f"the pack {codes} chooses none" if len(locales) == 1
Expand Down
11 changes: 4 additions & 7 deletions nameparser/_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,14 +1008,11 @@ def __post_init__(self) -> None:
f"{f.name} must be an iterable, got {value!r}{hint}"
) from None
object.__setattr__(self, f.name, frozenset(value))
# middle_as_family, lenient_comma_suffixes,
# unlisted_dotted_suffixes, unlisted_caps_suffixes, strip_emoji,
# strip_bidi, two_family_names and two_given_names are scalar
# (compose="override")
# fields and DELIBERATELY get no type check here, unlike
# name_order and the union fields above: a
# Every other field (the scalars: the bools and
# unlisted_caps_suffixes) DELIBERATELY gets no type check here,
# unlike name_order and the union fields above: a
# PolicyPatch(strip_emoji="off") is constructible, and only raises
# once apply_patch runs Policy.__post_init__'s bool check. This is
# once apply_patch runs Policy.__post_init__'s checks. This is
# the one place the module's eager-validation ethos doesn't apply
# -- see the class docstring ("Values are validated when the patch
# is applied... not at patch construction").
Expand Down
7 changes: 2 additions & 5 deletions nameparser/locales/cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,5 @@
)


def DEVIATES(name: str) -> bool:
"""True when this pack's patch may parse `name` differently from the
default parser: rules/O6's declaration, shared with the es pack
(_locale.deviates_by_two_family_names)."""
return deviates_by_two_family_names(name)
# rules/O6's declaration, which every pack turning O6 on shares
DEVIATES = deviates_by_two_family_names
9 changes: 2 additions & 7 deletions nameparser/locales/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,5 @@
)


def DEVIATES(name: str) -> bool:
"""True when this pack's patch or fragment may parse `name`
differently from the default parser: rules/O6's declaration, which
the cs and sk packs share (_locale.deviates_by_two_family_names);
the given-name list acts only where O6 does, so it declares
nothing more."""
return deviates_by_two_family_names(name)
# rules/O6's declaration, which every pack turning O6 on shares
DEVIATES = deviates_by_two_family_names
9 changes: 2 additions & 7 deletions nameparser/locales/es_ar.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,5 @@
)


def DEVIATES(name: str) -> bool:
"""True when this pack's patch or fragment may parse `name`
differently from the default parser: rules/O6's declaration, which
every pack turning O6 on shares (_locale.deviates_by_two_family_names);
the given-name list acts only where O6 does, so it declares nothing
more."""
return deviates_by_two_family_names(name)
# rules/O6's declaration, which every pack turning O6 on shares
DEVIATES = deviates_by_two_family_names
7 changes: 2 additions & 5 deletions nameparser/locales/sk.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,5 @@
)


def DEVIATES(name: str) -> bool:
"""True when this pack's patch may parse `name` differently from the
default parser: rules/O6's declaration, shared with the es pack
(_locale.deviates_by_two_family_names)."""
return deviates_by_two_family_names(name)
# rules/O6's declaration, which every pack turning O6 on shares
DEVIATES = deviates_by_two_family_names
Loading