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

Nathaniel Smith njs at pobox.com
Sun Nov 1 12:21:23 EST 2015


On Nov 1, 2015 7:44 AM, "Steven D'Aprano" <steve at pearwood.info> wrote:
>
> On Sun, Nov 01, 2015 at 08:53:17AM +0100, Laura Creighton wrote:
> > In a message of Sun, 01 Nov 2015 17:06:30 +1100, "Steven D'Aprano"
writes:
>
> > >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.
>
> I'm willing to consider that "" should appear in the middle of sys.path:
>
> [standard-library-directories, "", site-package-directories]
>
> but that still allows accidental shadowing of third-party packages. I
> don't think that the problem of accidently shadowing numpy is less
> deserving of a solution than accidently shadowing random. They're both
> problems.

In this case there actually is a common use case [1] that involves issuing
using the "" entry to intentionally shadow third-party packages: if you're
hacking on foo v1.3.dev, and want to test out the code you're writing as
opposed to the installed version of foo v1.2, then switching to the root of
your source checkout before running python or nosetests or whatever
suffices.

(OTOH it is also the true that numpy has had enough users run into problems
due to trying to run python while accidentally in the root of a source
checkout that numpy/__init__.py contains special case code to check for
this case and error out early.)

-n

[1] Commonality here is assessed using the standard experimental procedure,
i.e., "*I* do it so it's common".
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151101/cfd0eb7a/attachment.html>


More information about the Python-ideas mailing list