fix: add initials_separator; fix or-defaulting for format/delimiter kwargs#171
Merged
Conversation
…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>
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #152.
initials_separatortoConstants(default" ") and as aHumanNamekwarg. Controls the joiner between consecutive initials within a name group (e.g. two middle names), distinct frominitials_delimiterwhich is the trailing character after each initial.string_format,initials_format, andinitials_delimiter: these usedor-defaulting which silently discarded falsy values like"". Now useis not None.initials_separatorin__process_initial__andinitials()in place of a hardcoded" ".docs/usage.rstwith examples showing how all three settings compose.Behavior changes
HumanName(..., initials_delimiter='')silently used"."initials_delimiteris""as passedHumanName(..., initials_format='')silently used default formatinitials_formatis""as passedinitials_separator=""removes theminitials_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 passuv run pytest— full suite passes (728 passed, 20 xfailed)HumanName("Doe, John A. Kenneth", initials_separator="", initials_format="{first}{middle}{last}").initials()returns"J.A.K.D."HumanName("Doe, John A. Kenneth", initials_delimiter="", initials_separator="", initials_format="{first}{middle}{last}").initials()returns"JAKD"🤖 Generated with Claude Code