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
Adjust warning message and stacklevel
  • Loading branch information
jacobtylerwalls committed Jan 22, 2023
commit 22a1618dddb0b29da22d7d3920da2a727bf24b85
3 changes: 2 additions & 1 deletion Lib/test/test_xml_etree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3963,7 +3963,8 @@ class BoolTest(unittest.TestCase):
def test_warning(self):
e = ET.fromstring('<a style="new"></a>')
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)
Expand Down
3 changes: 2 additions & 1 deletion Lib/xml/etree/ElementTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.", A9A7
DeprecationWarning, stacklevel=2
)
Expand Down
6 changes: 3 additions & 3 deletions Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
0