mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
Issue #16922: fixed findtext() to return empty Unicode string instead of empty bytes object when there's no text.
Patch by Serhiy Storchaka.
This commit is contained in:
parent
ce1519d250
commit
b09b167419
2 changed files with 3 additions and 1 deletions
|
|
@ -352,6 +352,8 @@ def find():
|
||||||
'subtext'
|
'subtext'
|
||||||
>>> ET.ElementTree(elem).findtext("section/tag")
|
>>> ET.ElementTree(elem).findtext("section/tag")
|
||||||
'subtext'
|
'subtext'
|
||||||
|
>>> ET.XML('<root><empty /></root>').findtext('empty')
|
||||||
|
''
|
||||||
>>> summarize_list(elem.findall("."))
|
>>> summarize_list(elem.findall("."))
|
||||||
['body']
|
['body']
|
||||||
>>> summarize_list(elem.findall("tag"))
|
>>> summarize_list(elem.findall("tag"))
|
||||||
|
|
|
||||||
|
|
@ -840,7 +840,7 @@ element_findtext(ElementObject* self, PyObject* args)
|
||||||
|
|
||||||
PyObject* text = element_get_text(item);
|
PyObject* text = element_get_text(item);
|
||||||
if (text == Py_None)
|
if (text == Py_None)
|
||||||
return PyBytes_FromString("");
|
return PyUnicode_FromString("");
|
||||||
Py_XINCREF(text);
|
Py_XINCREF(text);
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue