Skip to content

Commit df720b1

Browse files
derek73claude
andcommitted
Fix documentation prose made stale by the dict conversions
Review findings from PR #233: - TupleManager's docstring referred to "the tuple constants", which no longer exist; note the name is historical instead - The :param regexes: docstring named the wrong wrapper (TupleManager instead of RegexTupleManager, whose EMPTY_REGEX fallback is behaviorally significant) and used a self-referential xref; point it at ~regexes.REGEXES like the sibling capitalization entry - :type regexes: now says (name, compiled pattern) so readers know the values must be re.Pattern objects - AGENTS.md said every config module defines a set and described regexes.py as wrapped in a TupleManager; two modules now define dicts and the wrapping happens in Constants, with RegexTupleManager - The CAPITALIZATION_EXCEPTIONS release-log entry was missing its reference (#233), violating the documented release-log convention - customize.rst promised add()/remove() on every constant; scope that to the set-valued ones and note dicts use normal dict operations Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 3f1c206 commit df720b1

4 files changed

Lines changed: 13 additions & 9 deletions

File tree

AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ The library has two layers: `nameparser/config/` (data) and `nameparser/parser.p
7373

7474
### Configuration layer (`nameparser/config/`)
7575

76-
Each module defines a plain Python set of known name pieces:
76+
Most modules define a plain Python set of known name pieces; `capitalization.py` and `regexes.py` define dicts:
7777

7878
- `titles.py``TITLES` (prenominals) and `FIRST_NAME_TITLES` (e.g. "Sir", which treat the following name as first, not last)
7979
- `suffixes.py``SUFFIX_ACRONYMS` (with periods, e.g. "M.D.") and `SUFFIX_NOT_ACRONYMS` (e.g. "Jr.")
8080
- `prefixes.py``PREFIXES` (lastname particles, e.g. "de", "van")
8181
- `bound_first_names.py``BOUND_FIRST_NAMES` (bound given-name prefixes, e.g. "abdul", "abu"); `_join_bound_first_name` joins the first non-title piece to its following piece before the main assignment loop
8282
- `conjunctions.py``CONJUNCTIONS` (e.g. "and", "of") used to chain multi-word titles
8383
- `capitalization.py``CAPITALIZATION_EXCEPTIONS` mapping (e.g. `{'phd': 'Ph.D.'}`)
84-
- `regexes.py` — compiled regular expressions wrapped in a `TupleManager`
84+
- `regexes.py`dict of compiled regular expressions (wrapped in `RegexTupleManager` by `Constants`)
8585

8686
`config/__init__.py` wraps everything into `SetManager` and `TupleManager` instances inside a `Constants` class. A module-level singleton `CONSTANTS` is shared across all `HumanName` instances by default.
8787

docs/customize.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ Editable attributes of nameparser.config.CONSTANTS
5353
* :py:data:`~nameparser.config.CAPITALIZATION_EXCEPTIONS` - Dictionary of pieces that do not capitalize the first letter, e.g. "Ph.D".
5454
* :py:data:`~nameparser.config.REGEXES` - Regular expressions used to find words, initials, nicknames, etc.
5555

56-
Each set of constants comes with :py:func:`~nameparser.config.SetManager.add` and :py:func:`~nameparser.config.SetManager.remove` methods for tuning
56+
Each set-valued constant comes with :py:func:`~nameparser.config.SetManager.add` and :py:func:`~nameparser.config.SetManager.remove` methods for tuning
5757
the constants for your project. These methods automatically lower case and
58-
remove punctuation to normalize them for comparison.
58+
remove punctuation to normalize them for comparison. The two dict-valued
59+
constants (``CAPITALIZATION_EXCEPTIONS`` and ``REGEXES``) are edited with
60+
normal dict operations.
5961

6062
Adding Custom Nickname Delimiters
6163
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

docs/release_log.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +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()``
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()`` (#233)
4848
* 1.2.1 - June 19, 2026
4949
- 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``
5050
- Add ``python -m nameparser "Name String"`` command-line helper that prints a parsed name

nameparser/config/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ def _is_dunder(attr: str) -> bool:
154154

155155
class TupleManager(dict[str, T]):
156156
'''
157-
A dictionary with dot.notation access. Subclass of ``dict``. Makes the tuple constants
158-
more friendly.
157+
A dictionary with dot.notation access. Subclass of ``dict``. Wraps the
158+
mapping config constants (``capitalization_exceptions``, ``regexes``, and
159+
the nickname/maiden delimiter buckets). The name is historical: before
160+
1.3.0 these constants were tuples of pairs.
159161
'''
160162

161163
def __getattr__(self, attr: str) -> T | None:
@@ -276,9 +278,9 @@ class Constants:
276278
:type capitalization_exceptions: dict or iterable of (key, value) tuples
277279
:param capitalization_exceptions:
278280
:py:attr:`~capitalization.CAPITALIZATION_EXCEPTIONS` wrapped with :py:class:`TupleManager`.
279-
:type regexes: dict or iterable of (key, value) tuples
281+
:type regexes: dict or iterable of (name, compiled pattern) tuples
280282
:param regexes:
281-
:py:attr:`regexes` wrapped with :py:class:`TupleManager`.
283+
:py:attr:`~regexes.REGEXES` wrapped with :py:class:`RegexTupleManager`.
282284
283285
:py:attr:`nickname_delimiters` and :py:attr:`maiden_delimiters` are not
284286
constructor arguments -- they're always set in ``__init__`` (see the

0 commit comments

Comments
 (0)