Skip to content

Commit cac4231

Browse files
derek73claude
andcommitted
Drop the whitespace check the charset pin subsumed
The [a-z0-9_]+ fullmatch landed after the whitespace check and fully absorbs it: all-whitespace input already fails the strip() check, and interior whitespace fails the charset with an accurate message. The empty and lowercase pre-checks stay -- they guard the common mistakes with materially friendlier messages. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent eaba92f commit cac4231

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

nameparser/_locale.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ def __post_init__(self) -> None:
3636
raise ValueError(
3737
f"Locale.code must be lowercase, got {self.code!r}"
3838
)
39-
if any(c.isspace() for c in self.code):
40-
raise ValueError(
41-
f"Locale.code must not contain whitespace, got {self.code!r}"
42-
)
4339
# Codes are registry keys (parser_for, third-party packs): every
4440
# accepted character is supported forever, so pin the charset
4541
# while relaxing later is still compatible. One separator only --

tests/v2/test_locale.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ def test_locale_code_must_be_nonempty_lowercase() -> None:
2929

3030

3131
def test_locale_code_rejects_whitespace() -> None:
32+
# caught by the [a-z0-9_]+ charset pin (a dedicated whitespace check
33+
# would be pure redundancy; the charset message is accurate)
3234
for bad in ("ru ", " ru", "ru\n", "r u"):
33-
with pytest.raises(ValueError, match="whitespace"):
35+
with pytest.raises(ValueError, match="a-z0-9_"):
3436
Locale(code=bad, lexicon=Lexicon.empty())
3537

3638

0 commit comments

Comments
 (0)