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:
Eugene Triguba 2022-08-01 11:52:39 -05:00 committed by GitHub
parent 858c9a58bf
commit a95e60db74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View file

@ -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