|
23 | 23 | "conjunctions", "bound_given_names", "maiden_markers", |
24 | 24 | ) |
25 | 25 |
|
| 26 | +#: (marker, base) pairs: each marker field narrows how entries of its |
| 27 | +#: base vocabulary are read, and carries no vocabulary of its own. An |
| 28 | +#: entry present in the marker but absent from the base is never |
| 29 | +#: consulted by any rule, so it is rejected rather than silently |
| 30 | +#: ignored -- a no-op configuration is the failure mode these fields |
| 31 | +#: are most likely to be misused into. |
| 32 | +_SUBSET_FIELDS = ( |
| 33 | + ("particles_ambiguous", "particles"), |
| 34 | + ("suffix_acronyms_ambiguous", "suffix_acronyms"), |
| 35 | + ("given_name_titles", "titles"), |
| 36 | +) |
| 37 | + |
26 | 38 |
|
27 | 39 | def _normalize(word: str) -> str: |
28 | 40 | """Lowercase, strip whitespace and EDGE periods -- v1's lc() |
@@ -215,19 +227,13 @@ def __post_init__(self) -> None: |
215 | 227 | canonical = _normpairs(self.capitalization_exceptions) |
216 | 228 | object.__setattr__(self, "capitalization_exceptions", canonical) |
217 | 229 | object.__setattr__(self, "_cap_map", MappingProxyType(dict(canonical))) |
218 | | - if not self.particles_ambiguous <= self.particles: |
219 | | - extra = ", ".join(sorted(self.particles_ambiguous - self.particles)) |
220 | | - raise ValueError( |
221 | | - f"particles_ambiguous must be a subset of particles; " |
222 | | - f"not in particles: {extra}" |
223 | | - ) |
224 | | - if not self.suffix_acronyms_ambiguous <= self.suffix_acronyms: |
225 | | - extra = ", ".join(sorted( |
226 | | - self.suffix_acronyms_ambiguous - self.suffix_acronyms)) |
227 | | - raise ValueError( |
228 | | - f"suffix_acronyms_ambiguous must be a subset of " |
229 | | - f"suffix_acronyms; not in suffix_acronyms: {extra}" |
230 | | - ) |
| 230 | + for marker, base in _SUBSET_FIELDS: |
| 231 | + orphans = getattr(self, marker) - getattr(self, base) |
| 232 | + if orphans: |
| 233 | + raise ValueError( |
| 234 | + f"{marker} must be a subset of {base}; " |
| 235 | + f"not in {base}: {', '.join(sorted(orphans))}" |
| 236 | + ) |
231 | 237 |
|
232 | 238 | # -- constructors ---------------------------------------------------- |
233 | 239 |
|
|
0 commit comments