Message 186767 - Python tracker (original) (raw)

Here's a simple patch to optimize away constant boolean conjunctions/disjunctions. for example:

def foo(): if 1 and 0: print("hi")

now disassembles into: 7 0 LOAD_CONST 0 (None) 3 RETURN_VALUE

while I realize more general techniques for achieving this have been proposed (ie http://bugs.python.org/issue1346238), this is a very simple, self-contained patch.