Skip to content

Commit 173e951

Browse files
committed
Address review feedback on Constants.__repr__
- Add a release_log.rst bullet for the __repr__ change (#221) - Fix the scalar-override test to exercise direct assignment, since 8 of the 10 tracked scalars aren't __init__ kwargs at all -- only patronymic_name_order and middle_name_as_last are - Add tests for multiple simultaneous scalar overrides and an empty collection
1 parent 1a1d1c8 commit 173e951

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

docs/release_log.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Release Log
4141
- Add international honorifics to ``TITLES`` (#187)
4242
- Add German/Austrian nobility and ecclesiastical titles to ``TITLES`` (closes #101)
4343
- Add German/Dutch last-name prefixes and title/degree suffixes; fix ``join_on_conjunctions()`` to register multi-word prefix chains (e.g. ``"von und zu"``) as prefixes, mirroring existing title handling (closes #18)
44+
- Change ``Constants.__repr__`` to report collection sizes and non-default scalar config, replacing the uninformative ``<Constants() instance>`` (#221)
4445
* 1.2.1 - June 19, 2026
4546
- Fix ``initials()`` interpolating the literal ``None`` for empty name parts when ``empty_attribute_default = None`` (e.g. ``"J. None D."``); empty parts now render as an empty string and a fully-empty result returns ``empty_attribute_default``
4647
- Add ``python -m nameparser "Name String"`` command-line helper that prints a parsed name

tests/test_constants.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,16 +538,34 @@ def test_repr_omits_scalars_at_default_value(self) -> None:
538538
for name in Constants._repr_scalar_attrs:
539539
self.assertNotIn(name, repr_str)
540540

541-
def test_repr_shows_scalar_override(self) -> None:
541+
def test_repr_shows_scalar_override_via_constructor(self) -> None:
542542
c = Constants(middle_name_as_last=True)
543543
self.assertIn("middle_name_as_last: True", repr(c))
544544

545+
def test_repr_shows_scalar_override_via_assignment(self) -> None:
546+
# Most _repr_scalar_attrs (e.g. capitalize_name) aren't __init__ kwargs
547+
# at all -- they're only ever overridden by direct assignment.
548+
c = Constants()
549+
c.capitalize_name = True
550+
self.assertIn("capitalize_name: True", repr(c))
551+
552+
def test_repr_shows_multiple_simultaneous_scalar_overrides(self) -> None:
553+
c = Constants(patronymic_name_order=True)
554+
c.capitalize_name = True
555+
repr_str = repr(c)
556+
self.assertIn("patronymic_name_order: True", repr_str)
557+
self.assertIn("capitalize_name: True", repr_str)
558+
545559
def test_repr_reflects_mutated_collection_size(self) -> None:
546560
c = Constants()
547561
before = len(c.titles)
548562
c.titles.add('a-brand-new-title-for-repr-test')
549563
self.assertIn(f"titles: {before + 1}", repr(c))
550564

565+
def test_repr_reports_empty_collection(self) -> None:
566+
c = Constants(titles=[])
567+
self.assertIn("titles: 0", repr(c))
568+
551569
def test_repr_is_bracketed_multiline(self) -> None:
552570
repr_str = repr(Constants())
553571
self.assertTrue(repr_str.startswith("<Constants : [\n"))

0 commit comments

Comments
 (0)