Message224126
If __debug__ were referenced from the code object's co_consts instead of checking locals, globals and builtins (LOAD_NAME), then optimize=1 would work consistently for a given code object.
Currently in 3.4.1:
>>> dis.dis(compile("if __debug__: x = 1", "", "exec", optimize=0))
1 0 LOAD_CONST 0 (1)
3 STORE_NAME 0 (x)
6 LOAD_CONST 1 (None)
9 RETURN_VALUE
>>> dis.dis(compile("if __debug__: x = 1", "", "exec", optimize=1))
1 0 LOAD_CONST 0 (None)
3 RETURN_VALUE
>>> dis.dis(compile("x = __debug__", "", "exec", optimize=0))
1 0 LOAD_NAME 0 (__debug__)
3 STORE_NAME 1 (x)
6 LOAD_CONST 0 (None)
9 RETURN_VALUE
>>> dis.dis(compile("x = __debug__", "", "exec", optimize=1))
1 0 LOAD_NAME 0 (__debug__)
3 STORE_NAME 1 (x)
6 LOAD_CONST 0 (None)
9 RETURN_VALUE
With the current design, an exec can override builtins.__debug__ in globals or locals:
>>> exec("print(__debug__)", globals(), {"__debug__": "spam"})
spam |
|
Date |
User |
Action |
Args |
2014-07-27 12:56:27 | eryksun | set | recipients:
+ eryksun, arigo, SilentGhost |
2014-07-27 12:56:27 | eryksun | set | messageid: <1406465787.31.0.167467834776.issue22091@psf.upfronthosting.co.za> |
2014-07-27 12:56:27 | eryksun | link | issue22091 messages |
2014-07-27 12:56:27 | eryksun | create | |
|