[Python-Dev] ImportError on no permission

Brett Cannon brett at python.org
Sun May 6 20:51:32 CEST 2007


On 5/6/07, "Martin v. Löwis" <martin at v.loewis.de> wrote:
>
> > Now, why don't we change the semantics as follows: if a file with
> matching name
> > exists (in import.c::find_module), but opening fails, ImportError is
> raised
> > immediately with the concrete error message, and without trying the rest
> of
> > sys.path. That shouldn't cause any working and sane setup to break, or
> did I
> > overlook something obvious here?
>
> I wonder how this would behave if a directory on sys.path was
> unreadable. You might get an ImportError on *any* import, as
> it tries the unreadable directory first, gets a permission error,
> and immediately aborts.
>
> Now, I think it is quite possible that you have inaccessible
> directories on sys.path, e.g. when you inherit PYTHONPATH from
> a parent process.
>
> So I would rather let importing proceed, and add a note to the
> error message that some files could not be read.



How about an ImportWarning instead?  That way people can have either have
import halt immediately, or continue (with or without a message).

-Brett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20070506/124fc4a9/attachment.html 


More information about the Python-Dev mailing list