Skip to content

Convert deeply nested documents without recursion (#276) - #277

Open
HardMax71 wants to merge 1 commit into
matthewwithanm:developfrom
HardMax71:fix/deeply-nested-recursion
Open

Convert deeply nested documents without recursion (#276)#277
HardMax71 wants to merge 1 commit into
matthewwithanm:developfrom
HardMax71:fix/deeply-nested-recursion

Conversation

@HardMax71

Copy link
Copy Markdown

Fixes GH-276. process_tag recursed for every nesting level, so an ordinary acyclic tree hit the default recursion limit at about 330 levels. Mail clients produce that shape easily, Outlook wraps every quoted reply in another div.

process_tag now walks the subtree with an explicit stack. The per-tag work moved into _open_tag (pick the children, build the parent context) and _close_tag (join, collapse newlines, run the convert function), unchanged otherwise. Traversal order is the same, so the output is identical and the existing suite passes untouched. bs4 did the same for tree output in 4.12.1 (bug 1471755).

Subclasses that override process_tag or process_element keep their per-child calls, so per-tag filters found in the wild still fire for nested tags (covered by a test). A cyclic tree (#256) would now spin instead of raising, so a tag already on the current path is skipped, same outcome as #274.

Checked on 3.8 with pytest, flake8, mypy and rst-lint as in CI. A 1000 level document converts in about 0.1 s.

Copilot AI lite review requested due to automatic review settings September 3, 2026 12:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

RecursionError on deeply nested HTML (about 330 levels), separate from the cyclic-tree case in #256

2 participants