Allow adding nickname delimiter patterns at runtime#190
Conversation
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>
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>
|
Ran a multi-agent review pass (code, tests, comments) on the original commit and it caught a real regression before merge, now fixed in the second commit: Critical bug found: the original approach snapshotted Fix: Also addressed from review:
Full suite: 990 passed, 4 skipped, 22 xfailed. |
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>
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>
Summary
parse_nicknames()looped over a hardcoded tuple of three named regexes, so overriding an existing pattern inCONSTANTS.regexesand re-parsing already worked, but there was no way to add a new delimiter pattern.Constantsnow exposesnickname_delimiters, a namedTupleManagerof delimiter patterns (seeded with the existingquoted_word/double_quotes/parenthesisregexes), andparse_nicknames()iterates it instead of a literal tuple.hn.C.nickname_delimiters['curly_braces'] = re.compile(...)) and callparse_full_name()again to pick it up — no subclassing or monkeypatching required.docs/customize.rst) with a worked example.Test plan
test_add_custom_nickname_delimiterintests/test_nicknames.pyreproduces the runtime-add scenario from the issue thread982 passed, 4 skipped, 22 xfailedCloses #112 (the nickname-delimiter case discussed in the thread; further generalization to other config groups mentioned in the issue is left as future work if a concrete need comes up).
🤖 Generated with Claude Code