[Python-Dev] Fix import errors to have data

Neal Norwitz neal at metaslash.com
Tue Jul 27 18:49:14 CEST 2004


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?

Neal



More information about the Python-Dev mailing list