◐ Shell
clean mode source ↗

Message 224120 - Python tracker

I can reproduce your example on 3.4, but for the comparison:

>>> exec(compile("if __debug__: print(42)", "exec", "exec", optimize=1))

>>> exec(compile("if __debug__: print(42)", "exec", "exec", optimize=0))
42

So, it's not as straightforward as one might imagine.