Author gregory.p.smith
Recipients Mark.Shannon, Mohamed_Atef, ethan.furman, gregory.p.smith, gvanrossum, pablogsal, serhiy.storchaka, stestagg
Date 2021-01-12.17:52:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1610473976.91.0.735748264987.issue42899@roundup.psfhosted.org>
In-reply-to
Content
If the body of a conditional does nothing, it seems fine to optimize the condition out to me.  But I see code from a low level compiled language perspective where that is clearly what would happen.  In reality, who ever meaningfully writes code where the body of a conditional does nothing?

 * Placeholder code with a # TODO perhaps.  [fine to optimize out]
 * Unit tests attempting to test the behavior of __bool__().  [an annoying behavior change]

Are there others?  Are we expecting this odd "not quite a no-op because we're so high level" pattern to ever appear in a performance critical situation?

The workaround for the latter would be to explicitly `if bool(x):` instead of `if x:` when the body is a no-op.  Or not make the body a no-op.  I expect unittest of __bool__() code owners would be fine with that so long as we call it out clearly in What's New docs, it's just that it could be an annoying change for them to make.

Ideally we'd also provide a lib2to3 fixer to detect and fixup code exhibiting that pattern.

The easiest answer is just not to optimize this out if it isn't actually providing us anything deemed important.
History
Date User Action Args
2021-01-12 17:52:56gregory.p.smithsetrecipients: + gregory.p.smith, gvanrossum, ethan.furman, Mark.Shannon, serhiy.storchaka, Mohamed_Atef, pablogsal, stestagg
2021-01-12 17:52:56gregory.p.smithsetmessageid: <1610473976.91.0.735748264987.issue42899@roundup.psfhosted.org>
2021-01-12 17:52:56gregory.p.smithlinkissue42899 messages
2021-01-12 17:52:56gregory.p.smithcreate