[issue38941] xml.etree.ElementTree.Element inconsistent warning for bool

Jelle Zijlstra report at bugs.python.org
Tue Mar 22 23:14:02 EDT 2022


Jelle Zijlstra <jelle.zijlstra at gmail.com> added the comment:

I was close to merging the linked PR but there's some renewed concerns about the proposed behavior here: Do we really want to change this behavior and potentially force a lot of people to change their working code?

In addition, the current code emits FutureWarning. I don't really understand what that warning is supposed to be used for (https://docs.python.org/3/library/exceptions.html#FutureWarning), but at least it means we plan to change the behavior later. So we should have a plan for how we'll do that. And whatever we do, the Python and C versions of the code should behave consistently.

Here are two ways forward:

(1) We change both the Python and the C versions of ElementTree to emit a DeprecationWarning on using __bool__ in 3.11. In 3.13, we change the behavior to make __bool__ always return True. (Or perhaps, make it raise an exception.)

(2) We give up on changing this behavior and remove the existing FutureWarning from the Python code. But in that case we should document the gotcha in the boolean behavior of nodes.

I don't have enough experience with ElementTree to recommend either option, but I'm happy to help implement it once we come to a decision.

----------
nosy: +JelleZijlstra
versions: +Python 3.11 -Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38941>
_______________________________________


More information about the Python-bugs-list mailing list