[Python-Dev] Assigning to __debug__

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Fri, 30 Mar 2001 09:55:59 +0200

After the recent change that assignments to __debug__ are disallowed,
I noticed that IDLE stops working (see SF bug report), since it was
assigning to __debug__. 

Simply commenting-out the assignment (to zero) did no good: Inside the
__debug__ blocks, IDLE would try to perform print statements, which
would write to the re-assigned sys.stdout, which would invoke the code
that had the __debug__, which would give up thanks to infinite
recursion. So essentially, you either have to remove the __debug__
blocks, or rewrite them to writing to save_stdout - in which case all
the ColorDelegator debug message appear in the terminal window.

So anybody porting to Python 2.1 will essentially have to remove all
__debug__ blocks that were previously disabled by assigning 0 to
__debug__. I think this is undesirable.

As I recall, in the original description of __debug__, being able to
assign to it was reported as one of its main features, so that you
still had a run-time option (unless the interpreter was running with
-O, which eliminates the __debug__ blocks).

So in short, I think this change should be reverted.


P.S. What was the motivation for that change, anyway?