Guido van Rossum <[email protected]> added the comment:
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*).
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue42899>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com