Skip to content

Commit b32b65c

Browse files
derek73claude
andcommitted
Explain why empty_attribute_default's type:ignores exist
Per code review: the AGENTS.md guidance added in this branch says to widen an annotation rather than ignore when runtime already supports the wider type, but empty_attribute_default is that exact case and was left un-widened. Document the deliberate scope decision (avoids cascading into ~8 public str-typed properties) at each ignore site instead of leaving it unexplained. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent b64691c commit b32b65c

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

tests/test_constants.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ def test_clear_removes_all_entries(self) -> None:
301301

302302
def test_empty_attribute_default(self) -> None:
303303
from nameparser.config import CONSTANTS
304+
# empty_attribute_default has no explicit annotation (mypy infers str
305+
# from the '' default), but None is documented/supported here -- see
306+
# the doctest on the attribute's docstring in config/__init__.py.
307+
# Not widened to str | None like string_format/suffix_delimiter
308+
# because it cascades into ~8 public str-typed properties (title,
309+
# first, middle, last, suffix, nickname, initials()).
304310
CONSTANTS.empty_attribute_default = None # type: ignore[assignment]
305311
hn = HumanName("")
306312
self.m(hn.title, None, hn)
@@ -312,7 +318,7 @@ def test_empty_attribute_default(self) -> None:
312318

313319
def test_empty_attribute_on_instance(self) -> None:
314320
hn = HumanName("", None)
315-
hn.C.empty_attribute_default = None # type: ignore[assignment]
321+
hn.C.empty_attribute_default = None # type: ignore[assignment] # see test_empty_attribute_default above
316322
self.m(hn.title, None, hn)
317323
self.m(hn.first, None, hn)
318324
self.m(hn.middle, None, hn)
@@ -322,7 +328,7 @@ def test_empty_attribute_on_instance(self) -> None:
322328

323329
def test_none_empty_attribute_string_formatting(self) -> None:
324330
hn = HumanName("", None)
325-
hn.C.empty_attribute_default = None # type: ignore[assignment]
331+
hn.C.empty_attribute_default = None # type: ignore[assignment] # see test_empty_attribute_default above
326332
self.assertEqual('', str(hn), hn)
327333

328334
def test_add_constant_with_explicit_encoding(self) -> None:
@@ -361,7 +367,7 @@ def test_pickle_roundtrip_preserves_customizations(self) -> None:
361367
def test_pickle_roundtrip_preserves_instance_scalar_override(self) -> None:
362368
"""An instance-level scalar override must survive a pickle round-trip."""
363369
c = Constants()
364-
c.empty_attribute_default = None # type: ignore[assignment]
370+
c.empty_attribute_default = None # type: ignore[assignment] # see test_empty_attribute_default above
365371

366372
# Safe: round-tripping a Constants the test just built, not untrusted data.
367373
restored = pickle.loads(pickle.dumps(c))

tests/test_initials.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ def test_initials_empty_part_with_none_default_not_literal_none(self) -> None:
2525
# used to be interpolated by str.format as the literal "None" (e.g.
2626
# "John Doe" -> "J. None D."). Empty parts must render as ''.
2727
hn = HumanName("John Doe", constants=None)
28+
# empty_attribute_default has no explicit annotation (mypy infers str
29+
# from the '' default), but None is documented/supported here -- see
30+
# the doctest on the attribute's docstring in config/__init__.py. Not
31+
# widened to str | None like string_format/suffix_delimiter because
32+
# it cascades into ~8 public str-typed properties (title, first,
33+
# middle, last, suffix, nickname, initials()).
2834
hn.C.empty_attribute_default = None # type: ignore[assignment]
2935
self.assertEqual(hn.initials(), "J. D.")
3036
self.assertTrue("None" not in hn.initials())
@@ -34,7 +40,7 @@ def test_initials_all_empty_returns_empty_attribute_default(self) -> None:
3440
# empty_attribute_default (here None), matching the first/last accessors,
3541
# rather than rendering the literal "None None None".
3642
hn = HumanName("", constants=None)
37-
hn.C.empty_attribute_default = None # type: ignore[assignment]
43+
hn.C.empty_attribute_default = None # type: ignore[assignment] # see test above
3844
self.assertEqual(hn.initials(), None)
3945

4046
def test_initials_middle_name_all_prefixes(self) -> None:

0 commit comments

Comments
 (0)