8000 gh-83122: Deprecate testing element truth values in `ElementTree` by jacobtylerwalls · Pull Request #31149 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-83122: Deprecate testing element truth values in ElementTree #31149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
FutureWarning -> DeprecationWarning
  • Loading branch information
jacobtylerwalls committed Jan 14, 2023
commit 4e0e1170e6675ed4d7713fe68a4899fd3a2d7001
4 changes: 2 additions & 2 deletions Lib/test/test_xml_etree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion Lib/xml/etree/ElementTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
0