This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author philiprowlands
Recipients philiprowlands
Date 2019-11-29.13:21:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1575033665.72.0.950765215131.issue38941@roundup.psfhosted.org>
In-reply-to
Content
Steps to reproduce:

$ python3.7
Python 3.7.2 (default, May 13 2019, 13:52:56)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import xml.etree.ElementTree as ET
>>> bool(ET.fromstring("<a><b><c></c></b></a>").find(".//c"))
False


$ python3.7
Python 3.7.2 (default, May 13 2019, 13:52:56)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.modules['_elementtree'] = None
>>> import xml.etree.ElementTree as ET
>>> bool(ET.fromstring("<a><b><c></c></b></a>").find(".//c"))
__main__:1: FutureWarning: The behavior of this method will change in future versions.  Use specific 'len(elem)' or 'elem is not None' test instead.


This is (almost) the smallest test case, but in real code what I was trying to write was:
```
# check the result code is ok
if response.find("./result[@code='ok']"):
    return True
```

The unintuitive bool() behaviour was surprising, compared to other typical True / False determinations on objects, and I think what the FutureWarning is trying to avoid.

Please implement the same warning for bool(Element) in _elementtree.c as exists in ElementTree.py. bpo29204 was making similar alignments between the versions, but didn't consider this FutureWarning.
History
Date User Action Args
2019-11-29 13:21:05philiprowlandssetrecipients: + philiprowlands
2019-11-29 13:21:05philiprowlandssetmessageid: <1575033665.72.0.950765215131.issue38941@roundup.psfhosted.org>
2019-11-29 13:21:05philiprowlandslinkissue38941 messages
2019-11-29 13:21:05philiprowlandscreate