This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: xml.etree.ElementTree findall() fails when using custom TreeBuilder
Type: behavior Stage: resolved
Components: Library (Lib), XML Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: eli.bendersky, jackjansen, miss-islington, scoder, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2018-10-09 09:32 by jackjansen, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
testetns.py jackjansen, 2018-10-09 09:32
Pull Requests
URL Status Linked Edit
PR 9766 merged serhiy.storchaka, 2018-10-09 11:46
PR 9867 merged miss-islington, 2018-10-14 07:32
PR 9868 merged serhiy.storchaka, 2018-10-14 07:55
Messages (5)
msg327385 - (view) Author: Jack Jansen (jackjansen) * (Python committer) Date: 2018-10-09 09:32
When using a TreeBuilder with a custom factory (returning a subclass of Element with some extra functionality) there is an issue with findall().

XPaths using an indexed predicate no longer work: the findall() result is always empty. The attached test script shows the problem.

I have analysed this as far as finding that the issue is in ElementPath.prepare_predicate.<locals>.select(), the last one. Specifically, the statement
    elems = list(parent.findall(elem.tag))
always returns an empty list (if the Element class is subclassed).

When using Python 2.7 everything works fine. When adding a findall() method to the Element subclass that simply calls Element.findall() everything also works fine. I suspect some issue with the _elementtree C implementation but I don't understand it.
msg327388 - (view) Author: Jack Jansen (jackjansen) * (Python committer) Date: 2018-10-09 09:58
Correction to the last line:
When using Python 2.7 everything works fine. When adding a findall() method to the Element subclass that simply calls ElementPath.findall() everything also works fine. I suspect some issue with the _elementtree C implementation but I don't understand it.
msg327695 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-14 07:32
New changeset b11c5667f99c4f0018e3394c4d07c519d835671a by Serhiy Storchaka in branch 'master':
bpo-34941: Fix searching Element subclasses. (GH-9766)
https://github.com/python/cpython/commit/b11c5667f99c4f0018e3394c4d07c519d835671a
msg327696 - (view) Author: miss-islington (miss-islington) Date: 2018-10-14 07:55
New changeset b1c800303e8458e00428ae66351ad492a503a46f by Miss Islington (bot) in branch '3.7':
bpo-34941: Fix searching Element subclasses. (GH-9766)
https://github.com/python/cpython/commit/b1c800303e8458e00428ae66351ad492a503a46f
msg327698 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-14 08:40
New changeset 7c1c42b3209f1d2546daab6cd77f953eb255df6c by Serhiy Storchaka in branch '3.6':
[3.6] bpo-34941: Fix searching Element subclasses. (GH-9766) (GH-9868)
https://github.com/python/cpython/commit/7c1c42b3209f1d2546daab6cd77f953eb255df6c
History
Date User Action Args
2022-04-11 14:59:06adminsetgithub: 79122
2018-10-14 08:41:19serhiy.storchakasetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: - Python 2.7
2018-10-14 08:40:24serhiy.storchakasetmessages: + msg327698
2018-10-14 07:55:52miss-islingtonsetnosy: + miss-islington
messages: + msg327696
2018-10-14 07:55:28serhiy.storchakasetpull_requests: + pull_request9236
2018-10-14 07:32:34miss-islingtonsetpull_requests: + pull_request9235
2018-10-14 07:32:23serhiy.storchakasetmessages: + msg327695
2018-10-09 11:46:26serhiy.storchakasetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request9153
2018-10-09 10:33:16serhiy.storchakasetassignee: serhiy.storchaka

nosy: + serhiy.storchaka, eli.bendersky, scoder
components: + XML
versions: + Python 2.7, Python 3.6, Python 3.8
2018-10-09 09:58:34jackjansensetmessages: + msg327388
2018-10-09 09:32:15jackjansencreate