Python compiler detect some constant expression used in if / while statement and evaluate them at compilation. However, it does not perform some simple optimisation (evaluating not unary expression or checking if and or or expression are constant because of the first expression). The attached patch allow Python to detect some more constant expression, and to optimise test like the following: if __debug__ and x: pass if not __debug__: pass
I'm working on a different approach: an AST optimizer. It is already able to replace "if __debug__ and x: ...." with "if x: ..." ("pythonenv" option must be enabled). https://bitbucket.org/haypo/astoptimizer/