You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Both LayoutElements (in layoutelement.py) and Elements (in elements.py )are structured to behave like containers or array-like objects. They expose methods like .slice() and hold list/array-like data (texts, element_coords, etc.).
However, neither class implements the __iter__() method. Attempting to loop over them directly results in:
TypeError: 'LayoutElements'objectisnotiterable
or similarly for Elements.
Suggested Fix
Add the following to both classes:
def__iter__(self):
returnself.iter_elements()
This will enable intuitive usage like:
forelinlayout_elements:
...
or:
forelinelements:
...
Motivation
This change improves the developer experience and aligns both LayoutElements and Elements with Python's collection protocol. It supports clean and readable code, especially when using list comprehensions or loops.
Benefits
✅ Enables native iteration with for el in elements: