Skip to content

Modernize config constant data structures#233

Merged
derek73 merged 4 commits into
masterfrom
fix/issue-227-regexes-dict
Jul 5, 2026
Merged

Modernize config constant data structures#233
derek73 merged 4 commits into
masterfrom
fix/issue-227-regexes-dict

Conversation

@derek73

@derek73 derek73 commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Closes #227, expanded to cover all the Python 2-era data structures in nameparser/config. Three commits, ordered from behavior-relevant to purely cosmetic:

1. REGEXES: set of (name, pattern) tuples → dict (#227)

REGEXES was a set of tuples consumed as dict(...) by RegexTupleManager. If two entries ever shared a name, which one won was nondeterministic per process (set iteration order varies with hash randomization). A dict literal makes a duplicate key a visible overwrite at write time.

2. CAPITALIZATION_EXCEPTIONS: tuple of tuples → dict

Same rationale minus the nondeterminism (tuples are ordered, so last-wins was at least deterministic — just silent). The docs already described it as a dictionary; now the code agrees.

3. set([...]) → set literals

CONJUNCTIONS, FIRST_NAME_TITLES, TITLES, NON_FIRST_NAME_PREFIXES, PREFIXES, and the three SUFFIX_* constants used the pre-2.7 set([...])-around-a-list form. Purely cosmetic; contents verified element-for-element identical against master for all eight.

Supporting changes

  • Constants.__init__ annotations for regexes and capitalization_exceptions collapse to Mapping[...] | Iterable[tuple[...]] — the old TupleManager union arms were dict subclasses already covered by Mapping, and the plain-dict defaults require it
  • Release log entries for the two observable changes, each with the compat note: code iterating REGEXES or CAPITALIZATION_EXCEPTIONS directly now gets keys instead of pairs — use .items()

Verification

  • uv run pytest: 1344 passed, 22 xfailed (after each commit)
  • uv run mypy: no issues in 13 source files
  • Set-literal sweep additionally verified by importing each config module from master and from the branch and asserting all eight constants compare equal

4. Documentation accuracy pass

A multi-agent review of the diff surfaced prose made stale by the conversions (plus a few adjacent pre-existing imprecisions): the TupleManager docstring's reference to "the tuple constants", the :param regexes: line naming the wrong wrapper class, AGENTS.md's description of the config modules, a missing release-log issue reference, and customize.rst promising add()/remove() on the dict-valued constants. All fixed in the final commit; Sphinx builds warning-free.

🤖 Generated with Claude Code

A set of tuples consumed as dict(...) means a duplicate name resolves
nondeterministically per process (set iteration order varies with hash
randomization). A dict literal makes a duplicate key a visible overwrite
at write time and is the honest structure for key/value data.

The regexes parameter annotation on Constants.__init__ collapses to
Mapping: both TupleManager arms were dict subclasses already covered by
it, and the new plain-dict default requires it (iterating a dict yields
keys, not pairs, so it never satisfied the Iterable[tuple] arm).

Closes #227

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented Jul 5, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.29%. Comparing base (2358c77) to head (df720b1).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #233   +/-   ##
=======================================
  Coverage   97.29%   97.29%           
=======================================
  Files          13       13           
  Lines         813      813           
=======================================
  Hits          791      791           
  Misses         22       22           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

derek73 and others added 2 commits July 5, 2026 14:43
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>
Set literals arrived in Python 2.7/3.0; the set([...])-around-a-list
form predates them. Purely cosmetic: contents verified identical
against master for all eight constants.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@derek73 derek73 changed the title Make REGEXES a dict instead of a set of (name, pattern) tuples Modernize config constant data structures Jul 5, 2026
@derek73 derek73 self-assigned this Jul 5, 2026
@derek73 derek73 added this to the v1.3.0 milestone Jul 5, 2026
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>
@derek73 derek73 merged commit adbb772 into master Jul 5, 2026
8 checks passed
@derek73 derek73 deleted the fix/issue-227-regexes-dict branch July 5, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

REGEXES is a set of (name, pattern) tuples; make it a dict

2 participants