summaryrefslogtreecommitdiffstats
path: root/Doc/library
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 /Doc/library
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 'Doc/library')
-rw-r--r--Doc/library/xml.etree.elementtree.rst9
1 files changed, 6 insertions, 3 deletions
diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst
index 876de29..f9290f5 100644
--- a/Doc/library/xml.etree.elementtree.rst
+++ b/Doc/library/xml.etree.elementtree.rst
@@ -1045,9 +1045,9 @@ Element Objects
:meth:`~object.__getitem__`, :meth:`~object.__setitem__`,
:meth:`~object.__len__`.
- Caution: Elements with no subelements will test as ``False``. This behavior
- will change in future versions. Use specific ``len(elem)`` or ``elem is
- None`` test instead. ::
+ Caution: Elements with no subelements will test as ``False``. Testing the
+ truth value of an Element is deprecated and will raise an exception in
+ Python 3.14. Use specific ``len(elem)`` or ``elem is None`` test instead.::
element = root.find('foo')
@@ -1057,6 +1057,9 @@ Element Objects
if element is None:
print("element not found")
+ .. versionchanged:: 3.12
+ Testing the truth value of an Element emits :exc:`DeprecationWarning`.
+
Prior to Python 3.8, the serialisation order of the XML attributes of
elements was artificially made predictable by sorting the attributes by
their name. Based on the now guaranteed ordering of dicts, this arbitrary