[issue8379] if __debug__: has nonobvious behaviour when evaluating .pyo without -O

Brett Cannon report at bugs.python.org
Tue Apr 13 00:00:06 CEST 2010


Brett Cannon <brett at python.org> added the comment:

Your assessment of what is going on, Andy, is correct; the peephole optimizer for bytecode optimizes away the `if __debug__` section of the `if` statement for .pyo files.

But that is actually a reasonable thing for the compiler to do as you are not supposed to run optimized bytecode with the interpreter not running under -O. Running a .pyo file under an interpreter run w/o -O is like compiling for 64-bit but then running on a 32-bit system; you are not following assumptions you told the compiler could be made about the runtime.

So I am closing this as 'wont fix'. Best solution is to simply not run bytecode directly and instead execute the source as bytecode should be treated more as an optimization than some directly executable file format. But if you must execute the bytecode directly, simply make sure you don't mix .pyo/.pyc with an improper setting of -O.

----------
nosy: +brett.cannon
resolution:  -> wont fix
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8379>
_______________________________________


More information about the Python-bugs-list mailing list