[Python-ideas] [Python-Dev] If you shadow a module in the standard library that IDLE depends on, bad things happen

Laura Creighton lac at openend.se
Sun Nov 1 02:53:17 EST 2015


In a message of Sun, 01 Nov 2015 17:06:30 +1100, "Steven D'Aprano" writes:

>I propose the following two changes:
>
>
>(1) Beginning with Python 3.6, the default is that the current directory 
>is put at the end of sys.path rather than the beginning. Instead of:
>
>    >>> print(sys.path)
>    ['', '/this', '/that', '/another']
>
>we will have this instead:
>
>    >>> print(sys.path)
>    ['/this', '/that', '/another', '']
>
>Those who don't shadow installed packages won't notice any 
>difference.
>
>Scripts which deliberately or unintentionally shadow installed packages 
>will break from this change. I don't have a problem with this. You can't 
>fix harmful behaviour without breaking code that depends on that harmful 
>behaviour. 

This is a bad idea, if you mean 'shadows anything in site-packages'.
I write a perfectly good working program, which then silently breaks
because somebody happens to install a site package with a name
conflict with my code.  Can you imagine being in the middle of
writing and debugging such a thing and have everything start
failing because suddenly your program isn't the one being found?
How long is it going to take you to stop looking at your own code,
and your own setup for the problem and begin looking at what
packages got installed by anybody else sharing this machine, and
what they are named?

It is not necessarily going to make the teachers' lives any better.
They will trade the confusion of 'things are acting strangely
around here' for 'I just wrote a program and the stupid langauge
cannot find it'.  

People whose code inadvertantly shadow something are better off with
a warning about the potential problem.

Laura


More information about the Python-ideas mailing list