__debug__ http://stackoverflow.com/questions/15305688/conditional-debug-statement-not-executed-though-debug-is-true

Veek M vek.m1234 at gmail.com
Wed Nov 16 00:21:03 EST 2016


Trying to make sense of that article. My understanding of debug was 
simple:
1. __debug__ is always True, unless -O or -OO
2. 'if' is optimized out when True and the expr is inlined.

So what does he mean by:

1. 'If you rebind __debug__, it can cause symptoms'
2. 'During module compilation, the same code that handles literals also 
handles the magic constants ..., None, True, False, and __debug__'
3. 'you'll see that if __debug__: statements are either removed 
entirely, or use LOAD_CONST to load the compile-time debug constant, 
while if bool(__debug__): statements use LOAD_GLOBAL to load the value 
of __debug__.'

4. 'Of course these are guaranteed to be the same… unless you rebind 
__debug__'

Basically every line in that answer is new to me..



More information about the Python-list mailing list