[Python-Dev] Fix import errors to have data (original) (raw)

Brett C. bac at OCF.Berkeley.EDU
Wed Jul 28 01:58:02 CEST 2004


Neal Norwitz wrote:

On Tue, Jul 27, 2004 at 12:39:22PM -0400, Jim Fulton wrote:

Tim Peters wrote:

[Jim Fulton]

No, it won't. For example, suppose foo imports B. B tries to import C, but fails. B is now broken, but it is still importable. Actually, both foo and B can be imported without errors, even though they are broken. Then you're proposing a way for a highly knowledgable user to anticipate, and partially worm around, that Python leaves behind insane module objects in sys.modules. No. I'm proposing a way for a Python developer to detect the presence or absence of a module. Hm, perhaps it would be better to provide an API (if there isn't one already) to test whether a module is present. Another possibility could be to add a ChainedImportError (or SubImportError?) which would derive from ImportError. The module which imports a broken module would get the normal ImportError. If the module doesn't catch the exception, it would get converted to this new type of ImportError. I don't know how easy this would be to implement, but I think it would solve Jim's problem and perhaps be easier to deal with?

Having exceptions keeping track of previous exceptions might also work. I know that idea was brought up before last year (see http://www.python.org/dev/summary/2003-01-16_2003-01-31.html#idea-for-avoiding-exception-masking for the historically accurate summary of the thread). Idea died when no one could come up with a good way of storing previous exception info.

-Brett



More information about the Python-Dev mailing list