Unstructured-IO / Unstructured-IO/unstructured-inference
[Feature]: Add __iter__() method to LayoutElements and Elements for native iteration support
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 209
- Forks
- 73
- PR merge metrics
- No merged PRs in 30d
Description
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:
for el in elements:
...
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading LayoutElements in layoutelement.py and Elements in elements.py, focusing on their existing iter_elements() methods and array-like data. Add native iteration for both classes, then verify that direct loops over LayoutElements and Elements behave as described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100