[Python-checkins] cpython (3.2): Issue #16922: fixed findtext() to return empty Unicode string instead of empty
eli.bendersky
python-checkins at python.org
Sun Jan 13 14:26:59 CET 2013
http://hg.python.org/cpython/rev/849eb27baf1c
changeset: 81484:849eb27baf1c
branch: 3.2
parent: 81474:d55a06f7ccbf
user: Eli Bendersky <eliben at gmail.com>
date: Sun Jan 13 05:22:05 2013 -0800
summary:
Issue #16922: fixed findtext() to return empty Unicode string instead of empty bytes object when there's no text.
Patch by Serhiy Storchaka.
files:
Lib/test/test_xml_etree.py | 2 ++
Modules/_elementtree.c | 2 +-
2 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -352,6 +352,8 @@
'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"))
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -840,7 +840,7 @@
PyObject* text = element_get_text(item);
if (text == Py_None)
- return PyBytes_FromString("");
+ return PyUnicode_FromString("");
Py_XINCREF(text);
return text;
}
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list