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

2010-04-14 Thread Brett Cannon
Brett Cannon added the comment: On Wed, Apr 14, 2010 at 18:35, R. David Murray wrote: > > R. David Murray added the comment: > > No, Brett said he thought it was not a bug. If Raymond disagrees, he'll > say so. If I may attempt to channel Brett, I suspect his logic for closing > it "won't fi

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

2010-04-14 Thread R. David Murray
R. David Murray added the comment: No, Brett said he thought it was not a bug. If Raymond disagrees, he'll say so. If I may attempt to channel Brett, I suspect his logic for closing it "won't fix" went more or less like this: "it might be theoretically possible to change this behavior, but

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

2010-04-14 Thread Timothy Fitz
Timothy Fitz added the comment: Does that mean you agree that the behavior is a bug? If we're agreed that the behavior is a bug, then it's just a matter of solving the implementation details. One suggestion is to compile in a __debug__ check at the top of every .pyo file, effectively prependi

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

2010-04-13 Thread Brett Cannon
Brett Cannon added the comment: So technically Python does not know that some bytecode was compiled with optimization flags on; that is simply not carried in the bytecode format. You also cannot rely on file name extensions as the bytecode could have been generated by an interpreter that used

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

2010-04-12 Thread Timothy Fitz
Timothy Fitz added the comment: In this case bytecode isn't an optimization, it's a distribution choice (this bug reared it's ugly head in our closed-source downloadable client). I think that implausible execution paths are still a bug. Running a .pyo without -O should be explicitly an error

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

2010-04-12 Thread Brett Cannon
Brett Cannon 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

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

2010-04-12 Thread Antoine Pitrou
Antoine Pitrou added the comment: It's probably caused by optimizations in the peepholer indeed. -- nosy: +pitrou, rhettinger priority: -> low versions: +Python 2.7, Python 3.1, Python 3.2 ___ Python tracker _

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

2010-04-12 Thread Andy Friesen
New submission from Andy Friesen : In certain circumstances, "if __debug__" seems to be evaluating its "else" clause even when -O is not specified. This can cause very surprising behavior. a.zip contains a single file named a/__init__.pyo. It is the compiled form of the following code: