You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ElementTree: itertext() and tostring(method="text") lose the text of elements whose tag is a QName #161809
Element.itertext(), and therefore tostring(..., method="text"), skips elements whose tag is not a str, in order to leave out comments and processing instructions. The same check also matches QName tags, so their text disappears, even though the tree serializes to XML with all of its text:
tostring(root, method="text", encoding="unicode") gives 'hello world!QTEXT' with C on 3.12, 'world!' with C on 3.13 and 3.14, and '' with the pure-Python implementation.
Cause. Both implementations skip on "tag is not a str": Python has if not isinstance(tag, str) and tag is not None: return in Element.itertext(), and C has if (elem->tag != Py_None && !PyUnicode_Check(elem->tag)) in elementiter_next(). The C check came with the fix for gh-149571 (GH-149929), which made C skip comments and processing instructions like Python does; QName tags were not considered there. That is why C on 3.13 and 3.14 now drops the text of QName elements. It still yields their children's text and tails, while Python returns nothing for the whole subtree.
Activity
picnixz commentedon Nov 11, 2026
cc @serhiy-storchaka