Skip to content

Commit

Permalink
Issue #16922: fixed findtext() to return empty Unicode string instead…
Browse files Browse the repository at this point in the history
… of empty bytes object when there's no text.

Patch by Serhiy Storchaka.
  • Loading branch information
eliben committed Jan 13, 2013
1 parent ce1519d commit b09b167
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Lib/test/test_xml_etree.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ def find():
'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"))
Expand Down
2 changes: 1 addition & 1 deletion Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ element_findtext(ElementObject* self, PyObject* args)

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

0 comments on commit b09b167

Please sign in to comment.