Skip to content

HumanName is its own iterator; stored cursor corrupts iteration #225

Description

@derek73

__iter__ returns self with a _count cursor that is reset on StopIteration (parser.py:148, 180-187). Because the iterator state lives on the instance:

  • a break mid-loop leaves the cursor set, so the next iteration starts mid-stream
  • nested or concurrent loops over the same instance interfere with each other
  • __len__ iterates the object (parser.py:151), so calling len(name) during a loop silently resets the cursor

Fix: __iter__ returns a fresh generator over non-empty members; delete _count and the recursive or next(self) in __next__; __len__ becomes a direct count of non-empty members. The yielded values are unchanged, so this is behavior-compatible for documented use.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions