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

Guido van Rossum guido at python.org
Fri Jul 30 22:42:37 CEST 2010


On Fri, Jul 30, 2010 at 1:26 PM, Barry Warsaw <barry at python.org> wrote:
> 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.

Well it is a reserved name so those packages that were setting it
should have known that they were using undefined behavior that could
change at any time.

> 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.

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list