[Python-Dev] 'shadowing' builtins

Paul Prescod paul@prescod.net
Mon, 17 Jul 2000 13:18:44 -0500

Thomas Wouters wrote:
> ...
> He decided to go to David Beazly's python introduction, and he was suprised
> at how you can do 'None = 4'. And when I explained it's harmless (because
> it's local, not global) he was suprised it didn't generate a warning. And,
> well, why doesn't it generate a warning ? Only with an, uhm, '-w' option or
> so, of course, or perhaps add it to the '-t' option. It would be also a
> compile-time-check. It might require a seperate lookup table (haven't looked
> at it at all, yet) that duplicates the 'builtin' namespace, but I'd think
> it's worth it.

A few thoughts:

 * None, map and other such long-term, ancient built-ins should not be
directly overridable. I don't think we need a warning mode. Just outlaw
it. We can do this with a semantic check in the compiler.

 * Those with a good reason to shadow them would do it by assignment to
the module's dict or __builtins__. The "feature" would still be there if
you need it, but it would be syntactically distinct. Or maybe we need to
disallow it entirely to allow optimizers to attack this important
special case.

 * Python badly needs a warning infrastructure. If I had time, that
would be my first PEP. I'd rather the former tightening up was not
hostage to a warning infrastructure that nobody gets around to
implementing, though. 

 Paul Prescod - Not encumbered by corporate consensus
It's difficult to extract sense from strings, but they're the only
communication coin we can count on. 
	- http://www.cs.yale.edu/~perlis-alan/quotes.html