mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-91447: Fix findtext to only give an empty string on None (GH-91486)
The API documentation for [findtext](https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.findtext) states that this function gives back an empty string on "no text content." With the previous implementation, this would give back a empty string even on text content values such as 0 or False. This patch attempts to resolve that by only giving back an empty string if the text attribute is set to `None`. Resolves #91447. Automerge-Triggered-By: GH:gvanrossum
This commit is contained in:
parent
858c9a58bf
commit
a95e60db74
3 changed files with 19 additions and 1 deletions
|
@ -416,6 +416,8 @@ def findall(elem, path, namespaces=None):
|
|||
def findtext(elem, path, default=None, namespaces=None):
|
||||
try:
|
||||
elem = next(iterfind(elem, path, namespaces))
|
||||
return elem.text or ""
|
||||
if elem.text is None:
|
||||
return ""
|
||||
return elem.text
|
||||
except StopIteration:
|
||||
return default
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue