Description
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' object is not iterable
or similarly for Elements.
Suggested Fix
Add the following to both classes:
def __iter__(self):
return self.iter_elements()
This will enable intuitive usage like:
for el in layout_elements:
...
or:
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:
- ✅ Enhances clarity and developer-friendliness
- 🚫 No breaking changes (backward-compatible)
Description
Both
LayoutElements(inlayoutelement.py) andElements(inelements.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:or similarly for
Elements.Suggested Fix
Add the following to both classes:
This will enable intuitive usage like:
or:
Motivation
This change improves the developer experience and aligns both
LayoutElementsandElementswith Python's collection protocol. It supports clean and readable code, especially when using list comprehensions or loops.Benefits
for el in elements: