FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.13] gh-119577: Adjust DeprecationWarning when testing element truth values in ElementTree (GH-119762) by miss-islington · Pull Request #120189 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (2) .rst  (4) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 4 additions & 3 deletions Doc/library/xml.etree.elementtree.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1058,9 +1058,10 @@ Element Objects
:meth:`~object.__getitem__`, :meth:`~object.__setitem__`,
:meth:`~object.__len__`.

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.::
Caution: Elements with no subelements will test as ``False``. In a future
release of Python, all elements will test as ``True`` regardless of whether
subelements exist. Instead, prefer explicit ``len(elem)`` or
``elem is not None`` tests.::

element = root.find('foo')

Expand Down
7 changes: 5 additions & 2 deletions Doc/whatsnew/3.12.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1440,8 +1440,6 @@ and will be removed in Python 3.14.

* :mod:`typing`: :class:`!typing.ByteString`

* :mod:`xml.etree.ElementTree`: Testing the truth value of an :class:`xml.etree.ElementTree.Element`.

* The ``__package__`` and ``__cached__`` attributes on module objects.

* The :attr:`~codeobject.co_lnotab` attribute of code objects.
Expand All @@ -1467,6 +1465,11 @@ although there is currently no date scheduled for their removal.

* :class:`typing.Text` (:gh:`92332`)

* :mod:`xml.etree.ElementTree`: Testing the truth value of an
:class:`xml.etree.ElementTree.Element` is deprecated. In a future release it
will always return True. Prefer explicit ``len(elem)`` or
``elem is not None`` tests instead.

* Currently Python accepts numeric literals immediately followed by keywords,
for example ``0in x``, ``1or x``, ``0if 1else 2``. It allows confusing
and ambiguous expressions like ``[0x1for x in y]`` (which can be
Expand Down
10 changes: 5 additions & 5 deletions Doc/whatsnew/3.13.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1716,11 +1716,6 @@ Pending Removal in Python 3.14
public API.
(Contributed by Gregory P. Smith in :gh:`88168`.)

* :mod:`xml.etree.ElementTree`: Testing the truth value of an
:class:`~xml.etree.ElementTree.Element` is deprecated and will raise an
exception in Python 3.14.


Pending Removal in Python 3.15
------------------------------

Expand Down Expand Up @@ -1925,6 +1920,11 @@ although there is currently no date scheduled for their removal.
* :mod:`wsgiref`: ``SimpleHandler.stdout.write()`` should not do partial
writes.

* :mod:`xml.etree.ElementTree`: Testing the truth value of an
:class:`~xml.etree.ElementTree.Element` is deprecated. In a future release it
it will always return ``True``. Prefer explicit ``len(elem)`` or
``elem is not None`` tests instead.

* :meth:`zipimport.zipimporter.load_module` is deprecated:
use :meth:`~zipimport.zipimporter.exec_module` instead.

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_xml_etree.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4088,7 +4088,7 @@ class BoolTest(unittest.TestCase):
def test_warning(self):
e = ET.fromstring('<a style="new"></a>')
msg = (
r"Testing an element's truth value will raise an exception in "
r"Testing an element's truth value will always return True in "
r"future versions. "
r"Use specific 'len\(elem\)' or 'elem is not None' test instead.")
with self.assertWarnsRegex(DeprecationWarning, msg):
Expand Down
2 changes: 1 addition & 1 deletion Lib/xml/etree/ElementTree.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def __len__(self):

def __bool__(self):
warnings.warn(
"Testing an element's truth value will raise an exception in "
"Testing an element's truth value will always return True in "
"future versions. "
"Use specific 'len(elem)' or 'elem is not None' test instead.",
DeprecationWarning, stacklevel=2
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The :exc:`DeprecationWarning` emitted when testing the truth value of an
:class:`xml.etree.ElementTree.Element` now describes unconditionally
returning ``True`` in a future version rather than raising an exception in
Python 3.14.
2 changes: 1 addition & 1 deletion Modules/_elementtree.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ element_bool(PyObject* self_)
{
ElementObject* self = (ElementObject*) self_;
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"Testing an element's truth value will raise an exception "
"Testing an element's truth value will always return True "
"in future versions. Use specific 'len(elem)' or "
"'elem is not None' test instead.",
1) < 0) {
Expand Down

Back | FazBrowse Home | New Git URL