Skip to content

Simplify pass over the changes since v1.2.1#204

Merged
derek73 merged 2 commits into
masterfrom
simplify-1-3
Jul 4, 2026
Merged

Simplify pass over the changes since v1.2.1#204
derek73 merged 2 commits into
masterfrom
simplify-1-3

Conversation

@derek73

@derek73 derek73 commented Jul 4, 2026

Copy link
Copy Markdown
Owner

What changed

A /simplify review (four parallel angles: reuse, simplification, efficiency, altitude) over everything since the v1.2.1 tag, with the surviving findings applied. All changes are behavior-preserving — net −34 lines.

nameparser/parser.py

  • join_on_conjunctions: both join branches carried identical 5-line title/prefix registration blocks (including the pre-existing title duplication); they now share one local register_joined_piece helper.
  • The lenient "post-comma suffix_not_acronyms members bypass the is_an_initial veto" rule was encoded twice; it now lives in one new predicate, is_suffix_lenient(). are_suffixes_after_comma is a one-line all() over it, and the single-use 20-line is_suffix_at_lastname_comma_end method is deleted, with its positional guards (nxt is None and len(parts) == 2) inlined at the lastname-comma loop that owns that context.
  • cap_word: computes its exception-lookup key once instead of up to four lc()/.replace() string allocations per word (runs per word-match on every capitalize() pass).

nameparser/config/__init__.py

  • Constants.__setstate__: dropped the 10-line verification loop — its condition can never fire for any state __getstate__ produces, and removing it also eliminated the duplicated descriptor-scan between the two pickle hooks.
  • The dunder guard copy-pasted across four TupleManager/RegexTupleManager attribute hooks is now one _is_dunder() helper carrying the shared rationale; site-specific failure notes stay at each hook.

Tests

  • New FlaggedConstantsTestBase (with a constants_kwargs class attribute) replaces the identical setup_method/hn() pair copy-pasted into 7 classes across the patronymic-order and middle-name-as-last test files.
  • Deleted the two test_prefixes.py invariant tests that duplicate the import-time asserts in prefixes.py — a violated assert prevents import entirely, so the tests could never be the thing that fails.

AGENTS.md's note on the suffix/initial tension is updated to describe is_suffix_lenient().

Reviewer notes

  • Skipped as behavior-changing (not applied): the bound-first-name join is missing from the suffix-comma branch of parse_full_name"Abdul Salam Hassan, MD" parses differently from "Abdul Salam Hassan MD". Tracked separately rather than folded into this cleanup PR.
  • Also skipped: moving the suffix_delimiter split to suffix-classification time (design change), and extracting parse_nicknames' intentionally-inlined suffix normalization (the shared version came out clunkier than the commented inline form).

Verification

  • uv run pytest: 1236 passed, 22 xfailed (same xfail count as before)
  • uv run mypy nameparser/: clean; tests-included mypy error count identical to the pre-change baseline (41)

🤖 Generated with Claude Code

Behavior-preserving cleanups from a four-angle review (reuse,
simplification, efficiency, altitude) of everything since v1.2.1:

- join_on_conjunctions: share one register_joined_piece helper for the
  title/prefix registration duplicated across both join branches
- Consolidate the lenient post-comma suffix rule into is_suffix_lenient();
  are_suffixes_after_comma uses it, and the single-use
  is_suffix_at_lastname_comma_end method is inlined at its only call site
- cap_word: compute the exception-lookup key once instead of up to four
  lc()/replace() calls per word
- Constants.__setstate__: drop the verification loop that could never
  fire for state produced by __getstate__
- Extract _is_dunder() for the guard copy-pasted across four
  TupleManager/RegexTupleManager attribute hooks
- tests: add FlaggedConstantsTestBase replacing seven copy-pasted
  setup_method/hn() fixture pairs; drop the two invariant tests that
  duplicate prefixes.py's import-time asserts

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@derek73 derek73 self-assigned this Jul 4, 2026
@derek73 derek73 added this to the v1.3.0 milestone Jul 4, 2026
Review of #204 flagged the __setstate__ verification loop drop as an
undisclosed diagnostic regression (truncated/incompatible pickle state
would surface as a confusing AttributeError instead of a clear
ValueError), so it's restored. Also trims the two __getattr__ comments
that duplicated _is_dunder()'s rationale instead of stating only the
site-specific consequence.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@derek73 derek73 merged commit 9e11ca4 into master Jul 4, 2026
8 checks passed
@derek73 derek73 deleted the simplify-1-3 branch July 4, 2026 09:09
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.

1 participant