[Python-Dev] xmlrpclib.{True, False} (was Re: Assignment to None)

Hrvoje Nikšić hrvoje.niksic at avl.com
Mon Jul 14 10:50:50 CEST 2008


On Mon, 2008-06-16 at 22:27 +0200, M.-A. Lemburg wrote:
> On 2008-06-15 16:47, Georg Brandl wrote:
> > Thomas Lee schrieb:
> >> Georg Brandl wrote:
> >>> Remember that it must still be possible to write (in 2.6)
> >>>
> >>> True = 0
> >>> assert not True
> >>
> >> Ah of course. Looks like I should just avoid optimizations of 
> >> Name("True") and Name("False") all together. That's a shame!
> > 
> > We can of course decide to make assignment to True and False
> > illegal in 2.7 :)
> 
> Raising a run-time exception would be fine, but not a SyntaxError at
> compile time - this would effectively make it impossible to keep
> code compatible to Python 2.1.

Maybe it wouldn't.  Something like:

try:
    True, False
except NameError:
    globals()['True'] = 1
    globals()['False']

should still work for compatibility.  It would break *existing* code
that tries to be compatible with old releases, but that is unavoidable
in making something illegal that was previously legal.  In this case,
the price is justified by being able to optimize access to None, True,
and False without having to resort to dirty tricks such as
"none=None" (previously None=None) in functions.  It should also enable
the compiler to optimize "while True:" the way it optimizes "while 1:".




More information about the Python-Dev mailing list