Skip to content

Add __bool__, __iter__ and __len__ to TableFinder - #5153

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

felipdsa21 wants to merge 2 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


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


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


You can retrigger this bot by commenting recheck in this Pull Request. 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

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.

1 participant