1. python_mirrors
  2. cpython

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.

  • Participants
  • Parent commits d55a06f
  • Branches 3.2

Comments (0)

Files changed (2)

File Lib/test/test_xml_etree.py

View file
     '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"))

File Modules/_elementtree.c

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