[Python-Dev] Python roadmap

Guido van Rossum guido@python.org
Sat, 01 Feb 2003 13:33:41 -0500


> BTW, is there any way in Python to make it issue warnings when 
> built-in names are assigned new values? This could be very
> useful mode for Python beginners who tend to rebind max, min,
> list, etc?

It is sort of against the rules of the language -- the whole point of
scoping is that you should be able to define variables even if they
block a builtin (that you may never have heard of and don't need) from
view.

But it would be a great feature of PyChecker (for all I know, it
already does this).

There's one situation where I actually *do* think this is worth a
warning, or perhaps even an error.  When you import a module and
assign to an attribute of it that didn't exist before and has the name
of a built-in, you may change that module's meaning.  If this wasn't
allowed, an optimizer could know that a particular reference to 'len'
must really reference the built-in len() function, and could generate
in-line code to invoke PyObject_Size() rather than to look up the
built-in len and invoke it.  This would also allow much more efficient
execution of

  for i in range(1000000): ...

if there is no known global named range.

--Guido van Rossum (home page: http://www.python.org/~guido/)