You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow adding nickname delimiter patterns at runtime (#190)
* Allow adding nickname delimiter patterns at runtime (#112)
parse_nicknames() looped over a hardcoded tuple of three named regexes,
so overriding an existing pattern in CONSTANTS.regexes and re-parsing
worked, but adding a brand new delimiter had no effect since nothing
iterated a variable set of patterns.
Constants now exposes nickname_delimiters, a named TupleManager of
delimiter patterns (seeded with the existing quoted_word/double_quotes/
parenthesis regexes) that parse_nicknames() iterates. Adding an entry
and calling parse_full_name() again picks it up.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* Fix regression: keep built-in nickname delimiters live, isolate extras
Multi-agent review of PR #190 caught a critical regression: snapshotting
quoted_word/double_quotes/parenthesis into nickname_delimiters at
Constants.__init__ time silently broke the pre-existing, documented
customization path of overriding CONSTANTS.regexes.parenthesis (etc.)
and re-parsing, since the snapshot never saw later changes to regexes.
parse_nicknames() now reads the three built-ins live from self.C.regexes
(restoring that override path) and additionally iterates a renamed,
initially-empty extra_nickname_delimiters collection for new patterns,
matching what issue #112 actually asked for (add, not replace).
Also: added extra_nickname_delimiters to conftest.py's autouse
snapshot/restore list (it was missing, so mutating the global CONSTANTS
copy in a test would have leaked into later tests), added regression/
removal/pickle-roundtrip/suffix-interaction tests, and fixed the stale
parse_nicknames() docstring.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* Document conftest registration for new Constants collections
Extension Patterns had guidance for adding a scalar Constants attribute
but nothing for a mutable/collection one, which is how extra_nickname_delimiters
almost shipped without being added to conftest.py's autouse snapshot/restore list.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* Close post-review test gaps for extra_nickname_delimiters
Multi-agent review of PR #190 flagged two coverage gaps: no test for
registering multiple extra delimiters together, and no dedicated
deepcopy round-trip test for extra_nickname_delimiters itself (only
incidental coverage via conftest's autouse snapshot/restore). Also add
assertIsNone/assertIsNotNone to HumanNameTestBase, needed by the new
deepcopy test, and a note in AGENTS.md to add a deepcopy test whenever
a new mutable Constants collection is introduced.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: AGENTS.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -110,6 +110,10 @@ Each named attribute (`title`, `first`, etc.) is a `@property` that joins its co
110
110
3. Add `self.x = x if x is not None else self.C.x` in body — use `is not None`, not `or`, to allow falsy values like `""`
111
111
4. conftest auto-restores scalar CONSTANTS between tests, but tests that *set* CONSTANTS mid-run still need their own try/finally
112
112
113
+
**Adding a new mutable/collection `Constants` attribute** (a `SetManager`/`TupleManager`-backed group, e.g. `extra_nickname_delimiters`): add it to `_COLLECTION_CONFIG_ATTRS` in `tests/conftest.py`, or tests that mutate the global `CONSTANTS` copy will leak state into later tests. Contents must be deep-copyable (the snapshot uses `copy.deepcopy`) — already true for the existing manager types.
114
+
115
+
Add a dedicated `copy.deepcopy()` round-trip test for it too (see `test_regexes_deepcopy_roundtrip`/`test_extra_nickname_delimiters_deepcopy_roundtrip` in `tests/test_constants.py`), not just reliance on conftest's autouse snapshot/restore exercising it incidentally. `TupleManager`/`RegexTupleManager.__getattr__` answer *any* unknown attribute lookup — including dunder probes like `__deepcopy__` — so a new manager subtype or a `__getattr__` tweak can silently break `copy.deepcopy` (this bit `RegexTupleManager` before the dunder-lookup guard was added). A direct test on the new attribute's own manager instance catches that where the conftest fixture, which never asserts on the copy, would not.
116
+
113
117
**Adding a word to a config set** — first check the *other* sets for the same word (grep `nameparser/config/` or intersect the sets in a `python3 -c`). Real overlaps exist: `do`/`st`/`mc` ∈ `PREFIXES` ∩ `TITLES`/`SUFFIX_ACRONYMS`; `abd` = "ABD" ∈ `SUFFIX_ACRONYMS`; `abu` ∈ `PREFIXES` ∩ `first_name_prefixes` (position-dependent: leading token → first-name join, mid-name → last-name join). Usually position-dependent and harmless, but can force a guard or an exclusion (the `last_base` all-particles guard; dropping `abd` from `first_name_prefixes`).
114
118
115
119
**Adding a flag-gated post-parse transform** (reorder/adjust, e.g. `patronymic_name_order`) — add a `Constants` boolean (default `False`), implement a `handle_*()` method, and call it in `post_process()` after `handle_firstnames()` and before `handle_capitalization()`, gated on the flag. Default-off keeps existing parses byte-for-byte unchanged. (#85; extension point for #185 Turkic.)
0 commit comments