Skip to content

Commit b5bef9a

Browse files
derek73claude
andcommitted
Make CAPITALIZATION_EXCEPTIONS a dict instead of a tuple of tuples
Same rationale as REGEXES in the previous commit, minus the nondeterminism: it's key/value data consumed as dict(...), a duplicate key in the pair form is silently last-wins, and the docs already describe it as a dictionary. Anyone iterating it directly now gets keys instead of pairs; use .items(). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 36fd2ea commit b5bef9a

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

docs/release_log.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Release Log
4444
- Add German/Dutch last-name prefixes and title/degree suffixes; fix ``join_on_conjunctions()`` to register multi-word prefix chains (e.g. ``"von und zu"``) as prefixes, mirroring existing title handling (closes #18)
4545
- Change ``Constants.__repr__`` to report collection sizes and non-default scalar config, replacing the uninformative ``<Constants() instance>`` (#221)
4646
- Change ``REGEXES`` from a ``set`` of ``(name, pattern)`` tuples to a ``dict``, so a duplicate name is a visible overwrite in the source instead of a nondeterministic winner at import time; code iterating ``REGEXES`` directly now gets keys instead of pairs — use ``.items()`` (#227)
47+
- Change ``CAPITALIZATION_EXCEPTIONS`` from a tuple of ``(key, value)`` tuples to a ``dict``; code iterating it directly now gets keys instead of pairs — use ``.items()``
4748
* 1.2.1 - June 19, 2026
4849
- Fix ``initials()`` interpolating the literal ``None`` for empty name parts when ``empty_attribute_default = None`` (e.g. ``"J. None D."``); empty parts now render as an empty string and a fully-empty result returns ``empty_attribute_default``
4950
- Add ``python -m nameparser "Name String"`` command-line helper that prints a parsed name

nameparser/config/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,11 @@ class Constants:
273273
The subset of prefixes that are never a first name, so a *leading* one
274274
marks the whole name as a surname. Must stay disjoint from
275275
``bound_first_names``.
276-
:type capitalization_exceptions: tuple or dict
277-
:param capitalization_exceptions:
276+
:type capitalization_exceptions: dict or iterable of (key, value) tuples
277+
:param capitalization_exceptions:
278278
:py:attr:`~capitalization.CAPITALIZATION_EXCEPTIONS` wrapped with :py:class:`TupleManager`.
279-
:type regexes: tuple or dict
280-
:param regexes:
279+
:type regexes: dict or iterable of (key, value) tuples
280+
:param regexes:
281281
:py:attr:`regexes` wrapped with :py:class:`TupleManager`.
282282
283283
:py:attr:`nickname_delimiters` and :py:attr:`maiden_delimiters` are not
@@ -476,7 +476,7 @@ def __init__(self,
476476
conjunctions: Iterable[str] = CONJUNCTIONS,
477477
bound_first_names: Iterable[str] = BOUND_FIRST_NAMES,
478478
non_first_name_prefixes: Iterable[str] = NON_FIRST_NAME_PREFIXES,
479-
capitalization_exceptions: TupleManager[str] | Iterable[tuple[str, str]] = CAPITALIZATION_EXCEPTIONS,
479+
capitalization_exceptions: Mapping[str, str] | Iterable[tuple[str, str]] = CAPITALIZATION_EXCEPTIONS,
480480
regexes: Mapping[str, re.Pattern[str]] | Iterable[tuple[str, re.Pattern[str]]] = REGEXES,
481481
patronymic_name_order: bool = False,
482482
middle_name_as_last: bool = False,
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
CAPITALIZATION_EXCEPTIONS = (
2-
('ii', 'II'),
3-
('iii', 'III'),
4-
('iv', 'IV'),
5-
('md', 'M.D.'),
6-
('phd', 'Ph.D.'),
7-
)
1+
CAPITALIZATION_EXCEPTIONS = {
2+
'ii': 'II',
3+
'iii': 'III',
4+
'iv': 'IV',
5+
'md': 'M.D.',
6+
'phd': 'Ph.D.',
7+
}
88
"""
99
Any pieces that are not capitalized by capitalizing the first letter.
1010
"""

0 commit comments

Comments
 (0)