Assign to True / False in 2.3

Andrew Bennetts andrew-pythonlist at puzzling.org
Wed Jul 2 08:59:25 EDT 2003


On Wed, Jul 02, 2003 at 03:02:59AM -0700, Erik Max Francis wrote:
> Culley Angus wrote:
> 
> > I was a little suprised to find that I could assign a value to 'True',
> > and 'False' without warning though, and was wondering if this is
> > deliberate.
> 
> This is true of pretty much all Python features.  The only special
> dispensation goes to None, which is a warning now (in the 2.3 beta):
> 
> Python 2.3b2 (#1, Jun 29 2003, 20:30:58) 
> [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> None = 0
> <stdin>:1: SyntaxWarning: assignment to None

Incidentally, the reason why a SyntaxWarning isn't raised for True and False
is that there is a lot of existing code for older pythons that do tricks
like:

    True = (1 == 1)
    False = not True

Or something similar, and the Python team didn't want to break code, or
cause spurious warnings for code that might otherwise work perfectly well
with 2.3 and 2.2 or even 1.5.2 (depending on what else it did, of course).

-Andrew.






More information about the Python-list mailing list