Skip to content

bpo-34941: Fix searching Element subclasses. #9766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

serhiy-storchaka
Copy link
Member

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

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
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
Copy link
Member Author

serhiy-storchaka commented Oct 9, 2018

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
Copy link
Contributor

scoder commented Oct 14, 2018

LGTM

@serhiy-storchaka serhiy-storchaka merged commit b11c566 into python:master Oct 14, 2018
@miss-islington
Copy link
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 <[email protected]>
@bedevere-bot
Copy link

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

@miss-islington
Copy link
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
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
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 <[email protected]>
@bedevere-bot
Copy link

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 <[email protected]>
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