Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #11475

Re: Why no warnings when re-assigning builtin names?

Subject Re: Why no warnings when re-assigning builtin names?
From Philip Semanchuk <philip@semanchuk.com>
Date 2011-08-15 18:13 -0400
References <BB13E4C4D649234F84A01F6DF64BB87F076AD0CE@ccs-ex01.coldstorage.com>
Newsgroups comp.lang.python
Message-ID <mailman.21.1313446389.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Aug 15, 2011, at 5:52 PM, Gerrat Rickert wrote:

> With surprising regularity, I see program postings (eg. on
> StackOverflow) from inexperienced Python users  accidentally
> re-assigning built-in names.
> 
> 
> 
> For example, they'll innocently call some variable, "list", and assign a
> list of items to it.
> 
> ...and if they're _unlucky_ enough, their program may actually work
> (encouraging them to re-use this name in other programs).

Or they'll assign a class instance to 'object', only to cause weird errors later when they use it as a base class.

I agree that this is a problem. The folks on my project who are new-ish to Python overwrite builtins fairly often. Since there's never been any consequence other than my my vague warnings that something bad might happen as a result, it's difficult for them to develop good habits in this regard. It doesn't help that Eclipse (their editor of choice) doesn't seem to provide a way of coloring builtins differently. (That's what I'm told, anyway. I don't use it.)

> If they try to use an actual keyword, both the interpreter and compiler
> are helpful enough to give them a syntax error, but I think the builtins
> should be "pseudo-reserved", and a user should explicitly have to do
> something *extra* to not receive a warning.

Unfortunately you're suggesting a change to the language which could break existing code. I could see a use for "from __future__ import squawk_if_i_reassign_a_builtin" or something like that, but the current default behavior has to remain as it is.

JMO,
Philip

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Why no warnings when re-assigning builtin names? Philip Semanchuk <philip@semanchuk.com> - 2011-08-15 18:13 -0400
  Re: Why no warnings when re-assigning builtin names? rantingrick <rantingrick@gmail.com> - 2011-08-15 18:12 -0700

csiph-web