__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.
__iter__returnsselfwith a_countcursor that is reset onStopIteration(parser.py:148,180-187). Because the iterator state lives on the instance:breakmid-loop leaves the cursor set, so the next iteration starts mid-stream__len__iterates the object (parser.py:151), so callinglen(name)during a loop silently resets the cursorFix:
__iter__returns a fresh generator over non-empty members; delete_countand the recursiveor 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.