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 Mark.Shannon
Recipients Mark.Shannon, Mohamed_Atef, ethan.furman, gregory.p.smith, gvanrossum, josh.r, pablogsal, serhiy.storchaka, stestagg
Date 2021-02-02.12:08:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1612267698.72.0.289875105766.issue42899@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-02-02 12:08:18Mark.Shannonsetrecipients: + Mark.Shannon, gvanrossum, gregory.p.smith, ethan.furman, serhiy.storchaka, josh.r, Mohamed_Atef, pablogsal, stestagg
2021-02-02 12:08:18Mark.Shannonsetmessageid: <1612267698.72.0.289875105766.issue42899@roundup.psfhosted.org>
2021-02-02 12:08:18Mark.Shannonlinkissue42899 messages
2021-02-02 12:08:18Mark.Shannoncreate