Skip to content

Commit a6cb4e0

Browse files
derek73claude
andcommitted
Add regression tests pinning the iterator-protocol contract
Review follow-ups on #235: pin that next(name) on the instance raises TypeError (the documented behavior change — without this, re-adding a __next__ would pass the existing tests while contradicting the release log), and that iterating an all-empty name yields nothing now that __iter__ and __len__ are independent code paths. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 75e5ed3 commit a6cb4e0

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

tests/test_python_api.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ def test_len_during_iteration(self) -> None:
6969
self.assertEqual(len(hn), 2)
7070
self.assertEqual(next(it), "Doe")
7171

72+
def test_instance_is_not_its_own_iterator(self) -> None:
73+
# iterator state must never live on the instance; see release log
74+
# for the next(name) -> next(iter(name)) migration
75+
hn = HumanName("John Doe")
76+
with pytest.raises(TypeError):
77+
next(hn) # type: ignore[call-overload]
78+
79+
def test_iterating_empty_name_yields_nothing(self) -> None:
80+
collected = []
81+
for part in HumanName(""):
82+
collected.append(part)
83+
self.assertEqual(collected, [])
84+
7285
@pytest.mark.skipif(not dill, reason="requires python-dill module to test pickling")
7386
def test_config_pickle(self) -> None:
7487
constants = Constants()

0 commit comments

Comments
 (0)