Why no warnings when re-assigning builtin names?

Ethan Furman ethan at stoneleaf.us
Tue Aug 16 13:48:19 EDT 2011

Seebs wrote:
> On 2011-08-16, Ethan Furman <ethan at stoneleaf.us> wrote:
>> What makes you think it's unintentional?
> Programming experience.
> People *often* do things unintentionally.
>> Seems to me the real issue is somebody using a builtin, such as str or 
>> int, and that they somehow manage to do this without realizing, "wait a 
>> sec', that's one of my variables!"  I don't see that as a problem that 
>> Python needs to solve.
> I think the word "my" prejudices the case.

But fits in well with the OP.

> Imagine stepping into a large project that uses multiple frameworks and
> class libraries and so on.  You know Python but you're new to the project.
> Under which circumstance will you have more problems?
> 1.  There is not a single shadowed built-in in the entire project.
> 2.  There are dozens of shadowed built-ins based on when the original
> programmer felt there wasn't going to be a need for a given built-in
> feature, or possibly just didn't know about it.

My first course of action would be to learn what I'm patching before I 
patch it.  Scope helps in the case of shadowing; lint helps to give 
warnings about that and other things as well.

> Also, how easy or hard do you think it will be to debug those problems?
> What's your first response going to be if, on a screen which doesn't
> contain the word file at all, you try to use the file built-in and you
> get some cryptic error?  Are you going to know to go looking for the
> shadow right away?

I should have a pretty good clue from the traceback, and a couple prints 
or logs around the offending lines should give me the rest.


More information about the Python-list mailing list