summaryrefslogtreecommitdiffstats
path: root/Lib/xml/etree
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2023-01-23 01:16:48 (GMT)
committerGitHub <noreply@github.com>2023-01-23 01:16:48 (GMT)
commitd717be04dc7876696cb21ce7901bda0214c4b2e0 (patch)
tree32f9d28061733ce7c115474b76d77ea14fb209c5 /Lib/xml/etree
parent997073c28b2f8d199ff97759775208bc9a99b2b3 (diff)
downloadcpython-d717be04dc7876696cb21ce7901bda0214c4b2e0.zip
cpython-d717be04dc7876696cb21ce7901bda0214c4b2e0.tar.gz
cpython-d717be04dc7876696cb21ce7901bda0214c4b2e0.tar.bz2
gh-83122: Deprecate testing element truth values in `ElementTree` (#31149)
When testing element truth values, emit a DeprecationWarning in all implementations. This had emitted a FutureWarning in the rarely used python-only implementation since ~2.7 and has always been documented as a behavior not to rely on. Matching an element in a tree search but having it test False can be unexpected. Raising the warning enables making the choice to finally raise an exception for this ambiguous behavior in the future.
Diffstat (limited to 'Lib/xml/etree')
-rw-r--r--Lib/xml/etree/ElementTree.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
index df5d519..42574ee 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -200,9 +200,10 @@ class Element:
def __bool__(self):
warnings.warn(
- "The behavior of this method will change in future versions. "
+ "Testing an element's truth value will raise an exception in "
+ "future versions. "
"Use specific 'len(elem)' or 'elem is not None' test instead.",
- FutureWarning, stacklevel=2
+ DeprecationWarning, stacklevel=2
)
return len(self._children) != 0 # emulate old behaviour, for now