Skip to content

Commit ceb605c

Browse files
committed
Assert NON_FIRST_NAME_PREFIXES invariants at import time (#121)
Enforces the subset/disjointness invariants documented on the set so a future bad edit fails the import instead of silently drifting until a test happens to catch it.
1 parent 64faab7 commit ceb605c

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

nameparser/config/prefixes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from nameparser.config.first_name_prefixes import FIRST_NAME_PREFIXES
2+
13
#: The sub-set of :py:data:`PREFIXES` that are *never* a standalone first name.
24
#: A name that *starts* with one of these has no first name -- the whole thing
35
#: is a surname (e.g. "de Mesnil" -> last name "de Mesnil"). Curated to exclude
@@ -85,3 +87,11 @@
8587
'vel',
8688
'von',
8789
])
90+
91+
# Guard the two invariants the docstring above promises, so a future edit that
92+
# breaks them fails at import time instead of silently drifting until a test
93+
# happens to catch it.
94+
assert NON_FIRST_NAME_PREFIXES <= PREFIXES, \
95+
"NON_FIRST_NAME_PREFIXES must stay a subset of PREFIXES"
96+
assert not (NON_FIRST_NAME_PREFIXES & FIRST_NAME_PREFIXES), \
97+
"NON_FIRST_NAME_PREFIXES must stay disjoint from FIRST_NAME_PREFIXES"

0 commit comments

Comments
 (0)