Skip to content

bpo-34941: Fix searching Element subclasses.#9766

Merged
serhiy-storchaka merged 1 commit into
python:masterfrom
serhiy-storchaka:etree-find-element-subclasses
Oct 14, 2018
Merged

bpo-34941: Fix searching Element subclasses.#9766
serhiy-storchaka merged 1 commit into
python:masterfrom
serhiy-storchaka:etree-find-element-subclasses

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Oct 9, 2018

Copy link
Copy Markdown
Member

Methods find(), findtext() and findall() of xml.etree.ElementTree.Element
were not able to find chldren which are instances of Element subclasses.

https://bugs.python.org/issue34941

Methods find(), findtext() and findall() of xml.etree.ElementTree.Element
were not able to find chldren which are instances of Element subclasses.
@jackjansen

Copy link
Copy Markdown
Member

Neat find, thanks! One remark: should there be a note in the documentation (TreeBuilder section) that the element instance returned by the element_factory should be an instance of (a subclass of) Element?

@serhiy-storchaka

serhiy-storchaka commented Oct 9, 2018

Copy link
Copy Markdown
Member Author

I am unsure. Some parts of the module requires Element subclasses and raise an error otherwise (e.g. append() ad iter()). Others support duck-typing (like slice assignment and serializing). You have found that some operations work only with exact Elements and silently ignore types. I think we need more changes in master, but I'm unsure what should these changes be: restrict children be instances of Element subclasses or add duck typing support everywhere.

See also bpo-28234.

@scoder

scoder commented Oct 14, 2018

Copy link
Copy Markdown
Contributor

LGTM

@serhiy-storchaka serhiy-storchaka merged commit b11c566 into python:master Oct 14, 2018
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6, 3.7.
🐍🍒⛏🤖

@serhiy-storchaka serhiy-storchaka deleted the etree-find-element-subclasses branch October 14, 2018 07:32
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 14, 2018
Methods find(), findtext() and findall() of xml.etree.ElementTree.Element
were not able to find chldren which are instances of Element subclasses.
(cherry picked from commit b11c566)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-bot

Copy link
Copy Markdown

GH-9867 is a backport of this pull request to the 3.7 branch.

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.6 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker b11c5667f99c4f0018e3394c4d07c519d835671a 3.6

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @serhiy-storchaka, I could not cleanly backport this to 2.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker b11c5667f99c4f0018e3394c4d07c519d835671a 2.7

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

In 2.7 cElementTree.Element is not subclassable.

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Oct 14, 2018
Methods find(), findtext() and findall() of xml.etree.ElementTree.Element
were not able to find chldren which are instances of Element subclasses..
(cherry picked from commit b11c566)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-bot

Copy link
Copy Markdown

GH-9868 is a backport of this pull request to the 3.6 branch.

miss-islington added a commit that referenced this pull request Oct 14, 2018
Methods find(), findtext() and findall() of xml.etree.ElementTree.Element
were not able to find chldren which are instances of Element subclasses.
(cherry picked from commit b11c566)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this pull request Oct 14, 2018
Methods find(), findtext() and findall() of xml.etree.ElementTree.Element
were not able to find chldren which are instances of Element subclasses.
(cherry picked from commit b11c566)
@serhiy-storchaka serhiy-storchaka removed their assignment Oct 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants