New submission from Philip Rowlands <pythonb...@dimebar.com>:
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. ---------- components: Library (Lib) messages: 357642 nosy: philiprowlands priority: normal severity: normal status: open title: xml.etree.ElementTree.Element inconsistent warning for bool type: behavior _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38941> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com