[Python-Dev] Is it intentional that "sys.__debug__ = 1" is illegal in Python 2.7?

Barry Warsaw barry at python.org
Fri Jul 30 22:26:08 CEST 2010


In working on making Python 2.7 available in Debian and Ubuntu, we ran into
two packages that fail to byte compile against Python 2.7, where they are fine
in Python 2.6.  The Debian bug tracker issues are:

    http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=590821
    http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=590822

Specifically, what fails now is assignment to the __debug__ attribute of a
module, e.g. sys -- *not* builtin __debug__.

% python2.6
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> __debug__ = 1
  File "<stdin>", line 1
SyntaxError: can not assign to __debug__
>>> import sys
>>> sys.__debug__ = 1
>>> 
% python2.7
Python 2.7.0+ (release27-maint:83294, Jul 30 2010, 15:49:51) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> __debug__ = 1
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> import sys
>>> sys.__debug__ = 1
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> 

I think it's actually somewhat questionable that this is now illegal.  It
certainly breaks at least two packages.  More disturbing though is that I
cannot find mention of this change in Misc/NEWS or in the tracker, so I don't
actually know if this was intentional or not.

It looks like Benjamin's change in r67171 was the relevant diff.

Thoughts?  Either way I will file a bug.  IOW, if this change should *not*
have been made, I think it should be reverted for Python 2.7.1 and I can patch
our version of Python in the meantime.  If this change is intentional, I'll
file a bug against (or just fix) Misc/NEWS and the What's New.

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20100730/980533f4/attachment-0001.pgp>


More information about the Python-Dev mailing list