From acd875faa4a6529e16ef322ed4062929366d01db Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 5 Feb 2022 13:55:22 -0500 Subject: [PATCH 01/13] bpo-38941: Warn when testing element truth values in C version of ElementTree --- Lib/test/test_xml_etree_c.py | 22 ++++++++++++++ Misc/ACKS | 1 + .../2022-02-05-12-01-58.bpo-38941.8IhvyG.rst | 3 ++ Modules/_elementtree.c | 30 ++++++++++++++++++- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2022-02-05-12-01-58.bpo-38941.8IhvyG.rst diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py index bec8208571902e..97b27c043aa846 100644 --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -234,6 +234,27 @@ def test_element_with_children(self): self.check_sizeof(e, self.elementsize + self.extra + struct.calcsize('8P')) + +@unittest.skipUnless(cET, 'requires _elementtree') +@support.cpython_only +class BoolTest(unittest.TestCase): + def test_warning(self): + e = cET.Element('a') + msg = ( + r"The behavior of this method will change in future versions. " + r"Use specific 'len\(elem\)' or 'elem is not None' test instead.") + with self.assertWarnsRegex(FutureWarning, msg): + result = bool(e) + # Emulate prior behavior for now + self.assertIs(result, False) + + # Element with children + cET.SubElement(e, 'b') + with self.assertWarnsRegex(FutureWarning, msg): + new_result = bool(e) + self.assertIs(new_result, True) + + def test_main(): from test import test_xml_etree @@ -243,6 +264,7 @@ def test_main(): TestAliasWorking, TestAcceleratorImported, SizeofTest, + BoolTest, ) # Run the same test suite as the Python module diff --git a/Misc/ACKS b/Misc/ACKS index 6df339c3e145bf..7ff39d28357771 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1876,6 +1876,7 @@ Wojtek Walczak Charles Waldman Richard Walker Larry Wall +Jacob Walls Kevin Walzer Rodrigo Steinmuller Wanderley Dingyuan Wang diff --git a/Misc/NEWS.d/next/Library/2022-02-05-12-01-58.bpo-38941.8IhvyG.rst b/Misc/NEWS.d/next/Library/2022-02-05-12-01-58.bpo-38941.8IhvyG.rst new file mode 100644 index 00000000000000..f87530f9613582 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-02-05-12-01-58.bpo-38941.8IhvyG.rst @@ -0,0 +1,3 @@ +The C implementation of the :mod:`xml.etree.ElementTree` module now emits +:exc:`FutureWarning` when testing the truth value of an +:class:`xml.etree.ElementTree.Element`, just like the Python implementation. diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 9dadeef7129384..7b36f68a3302b3 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1468,6 +1468,20 @@ element_getitem(PyObject* self_, Py_ssize_t index) return self->extra->children[index]; } +static int +element_bool(PyObject* self_) +{ + ElementObject* self = (ElementObject*) self_; + (void)PyErr_WarnEx(PyExc_FutureWarning, + "FutureWarning: The behavior of this method will change in future versions. " + "Use specific 'len(elem)' or 'elem is not None' test instead.", + 2); + if (!self->extra) { + return false; + } + return true; +} + /*[clinic input] _elementtree.Element.insert @@ -2059,6 +2073,20 @@ static PySequenceMethods element_as_sequence = { 0, }; +static PyNumberMethods element_as_number = { + 0, /* nb_add */ + 0, /* nb_subtract */ + 0, /* nb_multiply */ + 0, /* nb_remainder */ + 0, /* nb_divmod */ + 0, /* nb_power */ + 0, /* nb_negative */ + 0, /* nb_positive */ + 0, /* nb_absolute */ + element_bool, /* nb_bool */ + 0, /* nb_invert */ +}; + /******************************* Element iterator ****************************/ /* ElementIterObject represents the iteration state over an XML element in @@ -4223,7 +4251,7 @@ static PyTypeObject Element_Type = { 0, /* tp_setattr */ 0, /* tp_as_async */ (reprfunc)element_repr, /* tp_repr */ - 0, /* tp_as_number */ + &element_as_number, /* tp_as_number */ &element_as_sequence, /* tp_as_sequence */ &element_as_mapping, /* tp_as_mapping */ 0, /* tp_hash */ From 7e0be26a95c5922a5cb8845094af65622655d528 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 5 Feb 2022 16:04:17 -0500 Subject: [PATCH 02/13] Fix bug in implementation --- Lib/test/test_xml_etree_c.py | 2 +- Modules/_elementtree.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py index 97b27c043aa846..e2531704e66462 100644 --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -239,7 +239,7 @@ def test_element_with_children(self): @support.cpython_only class BoolTest(unittest.TestCase): def test_warning(self): - e = cET.Element('a') + e = cET.fromstring('') msg = ( r"The behavior of this method will change in future versions. " r"Use specific 'len\(elem\)' or 'elem is not None' test instead.") diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 7b36f68a3302b3..e2a2d64317052a 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1476,10 +1476,10 @@ element_bool(PyObject* self_) "FutureWarning: The behavior of this method will change in future versions. " "Use specific 'len(elem)' or 'elem is not None' test instead.", 2); - if (!self->extra) { - return false; + if (self->extra ? self->extra->length : 0) { + return true; } - return true; + return false; } /*[clinic input] From 331a577698fe5d4c8e923b748da112c5f2610a0f Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 13 Feb 2022 09:15:33 -0500 Subject: [PATCH 03/13] Move test to Python suite --- Lib/test/test_xml_etree.py | 19 +++++++++++++++++++ Lib/test/test_xml_etree_c.py | 22 ---------------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 285559a872a65f..39293e1aa8fb42 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -3909,6 +3909,24 @@ def test_correct_import_pyET(self): self.assertIsInstance(pyET.Element.__init__, types.FunctionType) self.assertIsInstance(pyET.XMLParser.__init__, types.FunctionType) +# -------------------------------------------------------------------- + +class BoolTest(unittest.TestCase): + def test_warning(self): + e = ET.fromstring('') + msg = ( + r"The behavior of this method will change in future versions. " + r"Use specific 'len\(elem\)' or 'elem is not None' test instead.") + with self.assertWarnsRegex(FutureWarning, msg): + result = bool(e) + # Emulate prior behavior for now + self.assertIs(result, False) + + # Element with children + ET.SubElement(e, 'b') + with self.assertWarnsRegex(FutureWarning, msg): + new_result = bool(e) + self.assertIs(new_result, True) # -------------------------------------------------------------------- @@ -4175,6 +4193,7 @@ def test_main(module=None): XMLPullParserTest, BugsTest, KeywordArgsTest, + BoolTest, C14NTest, ] diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py index e2531704e66462..bec8208571902e 100644 --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -234,27 +234,6 @@ def test_element_with_children(self): self.check_sizeof(e, self.elementsize + self.extra + struct.calcsize('8P')) - -@unittest.skipUnless(cET, 'requires _elementtree') -@support.cpython_only -class BoolTest(unittest.TestCase): - def test_warning(self): - e = cET.fromstring('') - msg = ( - r"The behavior of this method will change in future versions. " - r"Use specific 'len\(elem\)' or 'elem is not None' test instead.") - with self.assertWarnsRegex(FutureWarning, msg): - result = bool(e) - # Emulate prior behavior for now - self.assertIs(result, False) - - # Element with children - cET.SubElement(e, 'b') - with self.assertWarnsRegex(FutureWarning, msg): - new_result = bool(e) - self.assertIs(new_result, True) - - def test_main(): from test import test_xml_etree @@ -264,7 +243,6 @@ def test_main(): TestAliasWorking, TestAcceleratorImported, SizeofTest, - BoolTest, ) # Run the same test suite as the Python module From 87e8ad750a582983ce6d33fa903b5e80474be473 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 13 Feb 2022 09:17:59 -0500 Subject: [PATCH 04/13] Concision --- Modules/_elementtree.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index e2a2d64317052a..9c07fbbff4345d 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -2074,17 +2074,7 @@ static PySequenceMethods element_as_sequence = { }; static PyNumberMethods element_as_number = { - 0, /* nb_add */ - 0, /* nb_subtract */ - 0, /* nb_multiply */ - 0, /* nb_remainder */ - 0, /* nb_divmod */ - 0, /* nb_power */ - 0, /* nb_negative */ - 0, /* nb_positive */ - 0, /* nb_absolute */ - element_bool, /* nb_bool */ - 0, /* nb_invert */ + .nb_bool = element_bool, }; /******************************* Element iterator ****************************/ From 4e0e1170e6675ed4d7713fe68a4899fd3a2d7001 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 14 Jan 2023 08:47:18 -0500 Subject: [PATCH 05/13] FutureWarning -> DeprecationWarning --- Lib/test/test_xml_etree.py | 4 ++-- Lib/xml/etree/ElementTree.py | 2 +- .../next/Library/2022-02-05-12-01-58.bpo-38941.8IhvyG.rst | 7 ++++--- Modules/_elementtree.c | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index ec67146abf6542..6d218110d3227f 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -3965,14 +3965,14 @@ def test_warning(self): msg = ( r"The behavior of this method will change in future versions. " r"Use specific 'len\(elem\)' or 'elem is not None' test instead.") - with self.assertWarnsRegex(FutureWarning, msg): + with self.assertWarnsRegex(DeprecationWarning, msg): result = bool(e) # Emulate prior behavior for now self.assertIs(result, False) # Element with children ET.SubElement(e, 'b') - with self.assertWarnsRegex(FutureWarning, msg): + with self.assertWarnsRegex(DeprecationWarning, msg): new_result = bool(e) self.assertIs(new_result, True) diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index df5d5191126ae1..1e310eac226338 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -202,7 +202,7 @@ def __bool__(self): warnings.warn( "The behavior of this method will change 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 diff --git a/Misc/NEWS.d/next/Library/2022-02-05-12-01-58.bpo-38941.8IhvyG.rst b/Misc/NEWS.d/next/Library/2022-02-05-12-01-58.bpo-38941.8IhvyG.rst index f87530f9613582..25aea2d07fbe72 100644 --- a/Misc/NEWS.d/next/Library/2022-02-05-12-01-58.bpo-38941.8IhvyG.rst +++ b/Misc/NEWS.d/next/Library/2022-02-05-12-01-58.bpo-38941.8IhvyG.rst @@ -1,3 +1,4 @@ -The C implementation of the :mod:`xml.etree.ElementTree` module now emits -:exc:`FutureWarning` when testing the truth value of an -:class:`xml.etree.ElementTree.Element`, just like the Python implementation. +The :mod:`xml.etree.ElementTree` module now emits :exc:`DeprecationWarning` +when testing the truth value of an :class:`xml.etree.ElementTree.Element`. +Before, the Python implementation emitted `FutureWarning`, and the C +implementation emitted nothing. diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 932b430420c06a..6720102d6d3a32 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1426,8 +1426,8 @@ static int element_bool(PyObject* self_) { ElementObject* self = (ElementObject*) self_; - (void)PyErr_WarnEx(PyExc_FutureWarning, - "FutureWarning: The behavior of this method will change in future versions. " + (void)PyErr_WarnEx(PyExc_DeprecationWarning, + "DeprecationWarning: The behavior of this method will change in future versions. " "Use specific 'len(elem)' or 'elem is not None' test instead.", 2); if (self->extra ? self->extra->length : 0) { From 6825e38ec69a95a5275afaf7cefdd14c01958c83 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 14 Jan 2023 08:50:32 -0500 Subject: [PATCH 06/13] add missing `:exc:` --- .../next/Library/2022-02-05-12-01-58.bpo-38941.8IhvyG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-02-05-12-01-58.bpo-38941.8IhvyG.rst b/Misc/NEWS.d/next/Library/2022-02-05-12-01-58.bpo-38941.8IhvyG.rst index 25aea2d07fbe72..5f996042260d09 100644 --- a/Misc/NEWS.d/next/Library/2022-02-05-12-01-58.bpo-38941.8IhvyG.rst +++ b/Misc/NEWS.d/next/Library/2022-02-05-12-01-58.bpo-38941.8IhvyG.rst @@ -1,4 +1,4 @@ The :mod:`xml.etree.ElementTree` module now emits :exc:`DeprecationWarning` when testing the truth value of an :class:`xml.etree.ElementTree.Element`. -Before, the Python implementation emitted `FutureWarning`, and the C +Before, the Python implementation emitted :exc:`FutureWarning`, and the C implementation emitted nothing. From 67b932056452a3f8bb61d54fc90e074493f90de6 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 14 Jan 2023 08:57:24 -0500 Subject: [PATCH 07/13] Return int --- Modules/_elementtree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 6720102d6d3a32..488219c83499bc 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1431,9 +1431,9 @@ element_bool(PyObject* self_) "Use specific 'len(elem)' or 'elem is not None' test instead.", 2); if (self->extra ? self->extra->length : 0) { - return true; + return 1; } - return false; + return 0; } /*[clinic input] From eee712a1f517693f23ed86b86f275ead69d127ca Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 14 Jan 2023 09:14:56 -0500 Subject: [PATCH 08/13] Add note to deprecated in 3.12 --- Doc/whatsnew/3.12.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 2c807caa0ed4af..72d81345ca837c 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -413,6 +413,11 @@ Deprecated is no current event loop set and it decides to create one. (Contributed by Serhiy Storchaka and Guido van Rossum in :gh:`100160`.) +* The :mod:`xml.etree.ElementTree` module now emits :exc:`DeprecationWarning` + when testing the truth value of an :class:`xml.etree.ElementTree.Element`. + Before, the Python implementation emitted :exc:`FutureWarning`, and the C + implementation emitted nothing. + Pending Removal in Python 3.13 ------------------------------ From f91bfd2ee3e358192b077460f10270d58be0516d Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 21 Jan 2023 09:29:45 -0500 Subject: [PATCH 09/13] Return -1 --- Modules/_elementtree.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 488219c83499bc..0c963ec1430cd5 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1426,10 +1426,13 @@ static int element_bool(PyObject* self_) { ElementObject* self = (ElementObject*) self_; - (void)PyErr_WarnEx(PyExc_DeprecationWarning, - "DeprecationWarning: The behavior of this method will change in future versions. " - "Use specific 'len(elem)' or 'elem is not None' test instead.", - 2); + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "DeprecationWarning: The behavior of this method will " + "change in future versions. Use specific 'len(elem)' or " + "'elem is not None' test instead.", + 2) < 0) { + return -1; + }; if (self->extra ? self->extra->length : 0) { return 1; } From 37a9446aa301e4fb3935c9400c66460cb977d342 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 21 Jan 2023 09:47:21 -0500 Subject: [PATCH 10/13] Adjust discussion of this usage in etree docs --- Doc/library/xml.etree.elementtree.rst | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst index 876de29b17ca3c..b3ea4f5381605d 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,11 @@ Element Objects if element is None: print("element not found") + .. versionchanged:: 3.12 + Prior to Python 3.12, this usage was discouraged by documentation, and + in the Python implementation with :exc:`FutureWarning`. Now, both + Python and (default) C implementations emit :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 From 424f0bba0c2ba769f115c741fcb8e6e5edd5493d Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 21 Jan 2023 09:56:29 -0500 Subject: [PATCH 11/13] Add Pending Removal notice --- Doc/whatsnew/3.12.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 72d81345ca837c..9e989cec15bc57 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -481,6 +481,12 @@ Pending Removal in Python 3.14 * ``__package__`` and ``__cached__`` will cease to be set or taken into consideration by the import system (:gh:`97879`). +* Testing the truth value of an :class:`xml.etree.ElementTree.Element`, + discouraged by :mod:`xml.etree.ElementTree` documentation since Python 2.6 + and by :exc:`FutureWarning` in the Python implementation since Python 2.7, + is now deprecated in both Python and (default) C implementations by + :exc:`DeprecationWarning` and will raise an exception in Python 3.14. + Pending Removal in Future Versions ---------------------------------- From 322312625234269943cae4ab734ac57dd1fefbb9 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 22 Jan 2023 12:55:12 -0500 Subject: [PATCH 12/13] Avoid mentioning messy history --- Doc/library/xml.etree.elementtree.rst | 4 +--- Doc/whatsnew/3.12.rst | 7 ++----- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst index b3ea4f5381605d..f9290f528e5555 100644 --- a/Doc/library/xml.etree.elementtree.rst +++ b/Doc/library/xml.etree.elementtree.rst @@ -1058,9 +1058,7 @@ Element Objects print("element not found") .. versionchanged:: 3.12 - Prior to Python 3.12, this usage was discouraged by documentation, and - in the Python implementation with :exc:`FutureWarning`. Now, both - Python and (default) C implementations emit :exc:`DeprecationWarning`. + 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 diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 121f288cdb708b..0dedb2ecd0c8b5 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -480,11 +480,8 @@ Pending Removal in Python 3.14 * ``__package__`` and ``__cached__`` will cease to be set or taken into consideration by the import system (:gh:`97879`). -* Testing the truth value of an :class:`xml.etree.ElementTree.Element`, - discouraged by :mod:`xml.etree.ElementTree` documentation since Python 2.6 - and by :exc:`FutureWarning` in the Python implementation since Python 2.7, - is now deprecated in both Python and (default) C implementations by - :exc:`DeprecationWarning` and will raise an exception in Python 3.14. +* 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 Future Versions From 22a1618dddb0b29da22d7d3920da2a727bf24b85 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 22 Jan 2023 13:18:11 -0500 Subject: [PATCH 13/13] Adjust warning message and stacklevel --- Lib/test/test_xml_etree.py | 3 ++- Lib/xml/etree/ElementTree.py | 3 ++- Modules/_elementtree.c | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 6d218110d3227f..ca5bb562996b52 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -3963,7 +3963,8 @@ class BoolTest(unittest.TestCase): def test_warning(self): e = ET.fromstring('') msg = ( - r"The behavior of this method will change in future versions. " + r"Testing an element's truth value will raise an exception in " + r"future versions. " r"Use specific 'len\(elem\)' or 'elem is not None' test instead.") with self.assertWarnsRegex(DeprecationWarning, msg): result = bool(e) diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index 1e310eac226338..42574eefd81beb 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -200,7 +200,8 @@ def __len__(self): 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.", DeprecationWarning, stacklevel=2 ) diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 85148286df4458..df1ebc3cfc3ba5 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1454,10 +1454,10 @@ element_bool(PyObject* self_) { ElementObject* self = (ElementObject*) self_; if (PyErr_WarnEx(PyExc_DeprecationWarning, - "DeprecationWarning: The behavior of this method will " - "change in future versions. Use specific 'len(elem)' or " + "Testing an element's truth value will raise an exception " + "in future versions. Use specific 'len(elem)' or " "'elem is not None' test instead.", - 2) < 0) { + 1) < 0) { return -1; }; if (self->extra ? self->extra->length : 0) {