Skip to content

Fix HumanName acting as its own iterator with a stored cursor#235

Merged
derek73 merged 2 commits into
masterfrom
fix/issue-225-iterator-cursor
Jul 5, 2026
Merged

Fix HumanName acting as its own iterator with a stored cursor#235
derek73 merged 2 commits into
masterfrom
fix/issue-225-iterator-cursor

Conversation

@derek73

@derek73 derek73 commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • HumanName.__iter__ returned self with a _count cursor stored on the instance, only reset when a loop ran to exhaustion — so a break mid-loop corrupted the next iteration, nested/concurrent loops over the same instance interfered with each other, and len(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 _count are deleted
  • Yielded values are unchanged, so this is behavior-compatible for documented use; next(name) directly on the instance (undocumented) now raises TypeError — noted in the release log with next(iter(name)) as the replacement

Test plan

  • New tests written first (TDD, all three verified failing against the old implementation): re-iteration after break, independent iter() calls, and len() mid-iteration
  • The break test intentionally consumes with a plain loop rather than list(), because list()'s __len__ length-hint accidentally reset the old cursor and masked the bug
  • Full suite: 1336 passed, 4 skipped, 22 xfailed

🤖 Generated with Claude Code

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-commenter

codecov-commenter commented Jul 5, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.25%. Comparing base (547e113) to head (a6cb4e0).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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>
@derek73 derek73 self-assigned this Jul 5, 2026
@derek73 derek73 added the bug label Jul 5, 2026
@derek73 derek73 added this to the v1.3.0 milestone Jul 5, 2026
@derek73 derek73 merged commit 7b4c5fe into master Jul 5, 2026
8 checks passed
@derek73 derek73 deleted the fix/issue-225-iterator-cursor branch July 5, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HumanName is its own iterator; stored cursor corrupts iteration

2 participants