Why no warnings when re-assigning builtin names?

Chris Angelico rosuav at gmail.com
Wed Aug 17 19:42:26 CEST 2011

On Wed, Aug 17, 2011 at 5:33 PM, Seebs <usenet-nospam at seebs.net> wrote:
> If it's such a bad thing, *why is it allowed*?  Why are you proud of the
> ability to do something that you are never socially-allowed to do?

Going back to my original three examples:

> 1) Deliberate shadowing because you want to change the behavior of the
> name. Extremely rare.
> 2) Shadowing simply by using the name of an unusual builtin (like
> 'file') in a context where you never use it. Very common.
> 3) Unintentional shadowing where you create a variable, but then
> intend to use the builtin. This is the only one that's a problem.

All three are allowed, but it's the first one that's considered
unusual. The second one is simply that Python doesn't have a million
and one reserved words. Yes, you probably don't want to use 'print' as
a variable name, but shadowing it with an exact equivalent would be
fine (eg to automatically date-stamp or log your output, without
changing your code). And as described above, using list/str/id etc is
not uncommon.

I greatly prefer this to the alternative, which is another 133
reserved words (based on Python 3.2 for Windows).


More information about the Python-list mailing list