Commits

Eli Bendersky committed 849eb27 Draft

Issue #16922: fixed findtext() to return empty Unicode string instead of empty bytes object when there's no text.

Patch by Serhiy Storchaka.

Comments (0)

Files changed (2)

Lib/test/test_xml_etree.py

     'subtext'
     >>> ET.ElementTree(elem).findtext("section/tag")
     'subtext'
+    >>> ET.XML('<root><empty /></root>').findtext('empty')
+    ''
     >>> summarize_list(elem.findall("."))
     ['body']
     >>> summarize_list(elem.findall("tag"))

Modules/_elementtree.c

 
             PyObject* text = element_get_text(item);
             if (text == Py_None)
-                return PyBytes_FromString("");
+                return PyUnicode_FromString("");
             Py_XINCREF(text);
             return text;
         }