gh-68475: Keep comments and processing instructions outside the root element - #156719
Open
serhiy-storchaka wants to merge 2 commits into
Open
gh-68475: Keep comments and processing instructions outside the root element#156719serhiy-storchaka wants to merge 2 commits into
serhiy-storchaka wants to merge 2 commits into
Conversation
… root element ElementTree gets the children attribute, a view of the children of the document, containing the root element and any number of comments and processing instructions around it. Adding a second element is an error. iter() iterates over all of them, but find(), findall() and iterfind() still search from the root element. TreeBuilder collects the comments and processing instructions which occur outside the root element and returns them, together with the root element, from the new document() method. This only happens when insert_comments or insert_pis is set, so nothing changes for existing code. parse() asks the target for the document before close(), which releases it. The C accelerator implements document() too, so that the feature works at full parsing speed.
Documentation build overview
|
Registering the implementation with a cast is a call through a pointer to an incorrect function type: it is warned about by the compiler, reported by UBSan, and traps on WASI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ElementTreenow has achildrenattribute: a view of the children of the document, containing the root element and any number of comments and processing instructions around it. Adding a second element is an error.TreeBuilderno longer discards the comments and processing instructions which occur outside the root element, and returns them, together with the root element, from the newdocument()method. This only happens when insert_comments or insert_pis is true, so nothing changes for existing code.ElementTree.iter()now iterates over all children of the document.find(),findall()anditerfind()still search from the root element.A view which validates its content when modified follows @scoder's suggestion above, rather than the originally proposed
ElementTree.append(), whose name @vadmium and @scoder both objected to. It covers the epilog as well as the prolog.