Why no warnings when re-assigning builtin names?

Seebs usenet-nospam at seebs.net
Wed Aug 17 18:33:06 CEST 2011

On 2011-08-17, Chris Angelico <rosuav at gmail.com> wrote:
> def foo(list):
>    """Foo's the list provided and returns True on success or False on
> failure."""
> def bar(list):
>     """Counts the number of bars in the list, assuming it to be made
> of music."""
>     if not foo(list): return

> You call foo() once and bar() twice. How many shadowings have there
> been? How many warnings do you get?

I'd say two, one when def foo... is parsed, one when def bar... is parsed.

> A simple implementation would give five warnings for this case - once
> for each invocation that shadows a builtin. Another simple
> implementation would give two warnings, at the time that the def
> statements are executed; this is preferred, but it's still two
> warnings, and if you have a huge set of functions that do this, that
> can easily be "lines and lines" of warnings. Or should it set a flag
> and say "I've already warned this session about shadowing 'list', so
> suppress all others"? That seems confusing.

I guess I don't object to multiple warnings if I do the same thing multiple
times.  I was just thinking in terms of a single parse-time warning for the
actual point at which something is shadowed, rather than, say, a warning
every time a name is hit during execution of statements and refers to a

Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nospam at seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

More information about the Python-list mailing list