Author gvanrossum
Recipients Mark.Shannon, Mohamed_Atef, gregory.p.smith, gvanrossum, pablogsal, serhiy.storchaka, stestagg
Date 2021-01-12.15:47:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1610466459.51.0.135663607558.issue42899@roundup.psfhosted.org>
In-reply-to
Content
Can we translate 'if x: pass' into 'pass'? No, because calling its __bool__ method may have a side effect (as we saw at the start of this thread).

Can we eliminate a lone 'x'? Only if it's a local variable and we're *sure* (because of control flow analysis) that it's got a value. For globals and class variables we must execute the load because there could always be an exception (or the dict could have a trap for lookups).

Can we eliminate e.g. 'x.y'? Never, because it can have a side effect.

In general, eliminating this kind of thing seems silly -- in code that the user intends to be fast such things don't occur, and in test the user probably has a reason to write odd code.


On the other question, I don't see how there's any possible difference in evaluation and side effects between

if a and b: ...

and

if a:
    if b:
        ...

so I have no problem with that (in fact that is what it *means*).
History
Date User Action Args
2021-01-12 15:47:39gvanrossumsetrecipients: + gvanrossum, gregory.p.smith, Mark.Shannon, serhiy.storchaka, Mohamed_Atef, pablogsal, stestagg
2021-01-12 15:47:39gvanrossumsetmessageid: <1610466459.51.0.135663607558.issue42899@roundup.psfhosted.org>
2021-01-12 15:47:39gvanrossumlinkissue42899 messages
2021-01-12 15:47:39gvanrossumcreate