[Python-Dev] ImportWarning flood (original) (raw)

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Wed Jun 28 14:25:58 CEST 2006


--- "Martin v. L�wis" <martin at v.loewis.de> wrote:

Ralf W. Grosse-Kunstleve wrote: > If there is a consenus, I'd create a new exception ImportErrorNoModule(name) > that is used consistently from all places. This would ensure uniformity of the > message in the future.

A correction proposal should only be given if it is likely correct.

It is not a proposal, just a "note". Maybe a better alternative would be

ImportError: No module name foo Reminder: To resolve import problems consult the section on "Packages" at http://www.python.org/doc/tut/

There can be many reasons why an import could fail: there might be no read permission for the file,

The warning in 2.5b1 doesn't fire in this case:

% ls -l junk.py ---------- 1 rwgk cci 16 Jun 28 05:01 junk.py % python Python 2.5b1 (r25b1:47027, Jun 26 2006, 02:59:25) [GCC 4.1.0 20060304 (Red Hat 4.1.0-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import junk Traceback (most recent call last): File "", line 1, in ImportError: No module named junk

or the PYTHONPATH might be setup incorrectly.

That's impossible to detect.

IOW, a hint about a missing init.py should only be given if a directory with the name of module was found, but lacked an init.py (i.e. in the cases where currently a warning is produced).

I am thinking you'd need to build up a buffer of potential warnings while trying to resolve an import. If the import succeeds the buffer is discarded, if it fails it is added to the exception message, or the warnings are "flushed" right before the ImportError is raised. Does that sound right? How would this interact with threading (it seems you'd need a separate buffer for each thread)?


Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com



More information about the Python-Dev mailing list