Skip to content

Add __bool__, __iter__ and __len__ to TableFinder - #5153

Open
felipdsa21 wants to merge 3 commits into
pymupdf:mainfrom
felipdsa21:add-table-finder-methods
Open

felipdsa21 wants to merge 3 commits into
pymupdf:mainfrom
felipdsa21:add-table-finder-methods

Conversation

@felipdsa21

Copy link
Copy Markdown

The TableFinder class (returned by Page.find_tables()) is extended so it can be used like the list of tables it holds:

  • len(page.find_tables()) returns the number of tables found. Before, it raised TypeError.
  • bool(page.find_tables()) is False when no tables were found. Before, it was always True, so if page.find_tables(): never skipped pages without tables.
  • for tab in page.find_tables(): iterates over .tables.

.tables and indexing work as before.

Adds test_table_finder_len_bool_iter() to tests/test_tables.py. It checks all three methods on a page with three tables (test_3179.pdf) and on a page with none (battery-file-22.pdf).

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@felipdsa21

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@JorjMcKie
JorjMcKie requested a review from veget-able October 9, 2026 12:21
github-actions Bot added a commit that referenced this pull request Oct 12, 2026

@veget-able veget-able left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a handy addition. I pushed one small commit on top of your branch that adds a changelog line and documents the three methods in docs/page.rst, so the change is visible to users. Looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants