Fix HumanName acting as its own iterator with a stored cursor#235
Merged
Conversation
HumanName.__iter__ returned self, with iteration state in a _count cursor on the instance that was only reset when a loop ran to exhaustion. Breaking out of a loop left the cursor mid-stream so the next loop started there; nested or concurrent loops over the same instance shared one cursor and interfered; and len(name) during a loop consumed and reset the cursor out from under the live iteration. __iter__ now returns a fresh generator over the non-empty members, so every iteration is independent, and __len__ counts the non-empty members directly instead of iterating the object. The instance-level __next__ and the _count cursor are deleted; next(name) on the instance itself (undocumented) now raises TypeError — use next(iter(name)). Closes #225 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #235 +/- ##
==========================================
- Coverage 97.29% 97.25% -0.04%
==========================================
Files 13 13
Lines 813 802 -11
==========================================
- Hits 791 780 -11
Misses 22 22 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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>
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
HumanName.__iter__returnedselfwith a_countcursor stored on the instance, only reset when a loop ran to exhaustion — so abreakmid-loop corrupted the next iteration, nested/concurrent loops over the same instance interfered with each other, andlen(name)during a loop consumed and reset the live cursor (closes HumanName is its own iterator; stored cursor corrupts iteration #225)__iter__now returns a fresh generator over non-empty members on every call;__len__counts non-empty members directly;__next__and_countare deletednext(name)directly on the instance (undocumented) now raisesTypeError— noted in the release log withnext(iter(name))as the replacementTest plan
break, independentiter()calls, andlen()mid-iterationlist(), becauselist()'s__len__length-hint accidentally reset the old cursor and masked the bug🤖 Generated with Claude Code