Skip to content

fix: add initials_separator; fix or-defaulting for format/delimiter kwargs#171

Merged
derek73 merged 3 commits into
masterfrom
fix/issue-152-initials-separator
Jun 29, 2026
Merged

fix: add initials_separator; fix or-defaulting for format/delimiter kwargs#171
derek73 merged 3 commits into
masterfrom
fix/issue-152-initials-separator

Conversation

@derek73

@derek73 derek73 commented Jun 29, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #152.

  • Add initials_separator to Constants (default " ") and as a HumanName kwarg. Controls the joiner between consecutive initials within a name group (e.g. two middle names), distinct from initials_delimiter which is the trailing character after each initial.
  • Fix silent kwarg ignoring for string_format, initials_format, and initials_delimiter: these used or-defaulting which silently discarded falsy values like "". Now use is not None.
  • Use initials_separator in __process_initial__ and initials() in place of a hardcoded " ".
  • Document the new setting in docs/usage.rst with examples showing how all three settings compose.

Behavior changes

Before After
HumanName(..., initials_delimiter='') silently used "." initials_delimiter is "" as passed
HumanName(..., initials_format='') silently used default format initials_format is "" as passed
No way to remove spaces between initials within a group initials_separator="" removes them
initials_format="{first}{middle}{last}", initials_delimiter=".""J.A. K.D." + initials_separator="""J.A.K.D."

Test plan

  • uv run pytest tests/test_initials.py -v — all initials tests pass
  • uv run pytest — full suite passes (728 passed, 20 xfailed)
  • Verify HumanName("Doe, John A. Kenneth", initials_separator="", initials_format="{first}{middle}{last}").initials() returns "J.A.K.D."
  • Verify HumanName("Doe, John A. Kenneth", initials_delimiter="", initials_separator="", initials_format="{first}{middle}{last}").initials() returns "JAKD"

🤖 Generated with Claude Code

…wargs (closes #152)

- Add initials_separator = " " to Constants: controls the joiner between
  consecutive initials within a name group, distinct from initials_delimiter
  which is the trailing character after each individual initial
- Add initials_separator kwarg to HumanName.__init__
- Fix or-defaulting to is-not-None for string_format, initials_format, and
  initials_delimiter kwargs so empty string '' is accepted as a valid value
- Use initials_separator in __process_initial__ and initials() in place of
  hardcoded " "
- Document initials_separator in usage.rst with examples

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@derek73 derek73 self-assigned this Jun 29, 2026
derek73 and others added 2 commits June 28, 2026 18:36
…g_format='' in __str__

- `__process_initial__` was reading `self.C.initials_separator` (Constants)
  instead of `self.initials_separator` (per-instance), so the constructor kwarg
  was silently ignored for multi-word name parts
- `__str__` used `if self.string_format:` (truthiness) so `string_format=""`
  fell through to the default format despite the assignment fix in the PR
- Add regression tests for both kwarg paths through the affected code
- Fix `test_initials_separator_multiword_name_part` to set instance attr instead
  of Constants attr, so it tests the now-correct code path
- Correct `Constants.initials_separator` docstring example (requires
  initials_format="{first}{middle}{last}" to produce "J.A.D.")
- Clarify usage.rst: initials_separator only removes intra-group spaces;
  inter-group spacing is still governed by initials_format

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add assertNotEqual shim to HumanNameTestBase
- Tighten test_initials_format_empty_string_kwarg: use assertNotEqual +
  assertFalse instead of vacuous or-equality check
- Add test_initials_separator_custom_value: non-empty separator on a
  multi-word token via __process_initial__
- Add test_str_default_behavior_unchanged: regression guard for the
  or→is-not-None __str__ fix
- Remove duplicate test_initials_separator_multiword_name_part
- Wrap CONSTANTS mutation tests in try/finally to ensure state is
  restored even when an assertion fails

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@derek73 derek73 added this to the v1.2.2 milestone Jun 29, 2026
@derek73 derek73 merged commit ba164e1 into master Jun 29, 2026
8 checks passed
@derek73 derek73 deleted the fix/issue-152-initials-separator branch June 29, 2026 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Initials Formatting

1 participant