Re: 3.10 change (?) for __bool__

Jan. 13, 2021
1:51 p.m.
Hi Rob, On 13/01/2021 12:18 pm, Rob Cliffe wrote:
On 12/01/2021 15:53, Mark Shannon wrote:
In master we convert `if x: pass` to `pass` which is equivalent, unless bool(x) has side effects the first time it is called. This is a recent change.
Can you please confirm that this optimisation ONLY applies to bare names, i.e. NOT
if x(): pass if x.y: pass if x+y: pass
The optimization doesn't apply to the expression, but the test. The optimizer (might) transform if x+y: pass to x+y But the expression is still evaluated. Sorry for the confusion, I should have been clearer in my example. It is the call to `bool()` that *might* be eliminated. Cheers, Mark.
Thanks Rob Cliffe
1503
Age (days ago)
1503
Last active (days ago)
0 comments
1 participants
participants (1)
-
Mark Shannon