mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +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'
|
||||
>>> ET.ElementTree(elem).findtext("section/tag")
|
||||
'subtext'
|
||||
>>> ET.XML('<root><empty /></root>').findtext('empty')
|
||||
''
|
||||
>>> summarize_list(elem.findall("."))
|
||||
['body']
|
||||
>>> summarize_list(elem.findall("tag"))
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue