[Python-Dev] ImportError on no permission (original) (raw)

Georg Brandl g.brandl at gmx.net
Sun May 6 23🔞34 CEST 2007


Martin v. Löwis schrieb:

Now, why don't we change the semantics as follows: if a file with matching name exists (in import.c::findmodule), 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.

That case should be handled differently, yes. My case is that you have a file in the directory with the correct name, but opening it fails (this obviously requires a two-step process, first find the file, then open it).

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.

The warning idea is also fine with me, if it's limited to the above case.

Georg

-- Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out.



More information about the Python-Dev mailing list