Mark Shannon <m...@hotpy.org> added the comment:
Option 3 with what semantics exactly? https://docs.python.org/3/reference/datamodel.html#object.__bool__ says that __bool__ should return True or False. If we don't allow the optimizer the freedom to assume that __bool__ is self-consistent and has no side effects, then we need to define what happens for stuff like: class FlipFlop: def __init__(self): self.val = random.choice((True, False)) def __bool__(self): self.val = not self.val return self.val Saying that only the second test can be removed is hard to define in a way that we can reliably implement. For example, it makes the simplification of `x = True and y` to `x = y` problematic. We routinely remove any tests of `if True:` or `while True:`, but the removal of `if True:` and the simplification of `x = True and y` to `x = y` is basically the same thing in the CFG. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42899> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com