Python 2.4: Why only assignments to None are forbiden?

John Roth newsgroups at
Sat Nov 13 15:04:28 CET 2004

"Josef Meile" <jmeile at> wrote in message 
news:4195190f at
> Hi,
> Textually from the highlights of python 2.4:
> "Assigning to None - the compiler now treats assigning to None as a 
> SyntaxError."
> I think in general assignments to built-in types, functions, and variables 
> should be also forbiden.

As Ian points out in another response, there's been some
discussion about making a fairly large subset of the builtins
name space immutable, and also to disallow shadowing
of builtins with identical names in module scope.

The main reason for this is performance optimization.
Right now, the len() function, for example, requires
a lookup and two (!) function evaluations. If the
compiler could trust that len() was always the function
in the builtins, then it could compile a direct call to the
__len__() function on the object, at a savings of the
lookup and one function call. There is a considerable savings
projected over the entire name builtin name space.

There's always a tension between protecting people
against common errors and keeping the language
as flexible and dynamic as possible. I'd prefer that
the editors and IDEs take up the slack. For example,
I found that JEdit colorized builtins differently from
ordinary names. This pointed out a few bad habits
I'd fallen into, without taking away the option of
overriding something when I really wanted it.

In any case, it won't happen in 2.4.x. That kind
of change will wait for a full point release: 2.5
or later.

John Roth

More information about the Python-list mailing list