RE: [Python-Dev] Fix import errors to have data
by Delaney, Timothy C (Timothy)
Guido van Rossum wrote:
>> 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. Wouldn't it be better to
>> change Python to stop leaving insane module objects in sys.modules
>> to begin with? That's harder, but seems to me it would do a lot
>> more good for a lot more people.
OK - the problem as I see it is that a given module that exists, but
raises ImportError, only raises ImportError *once*, whereas it really
should raise ImportError every time i.e. currently doing the following:
prints when it really should raise ImportError.
Additionally, a module could have messed with sys.modules directly, so
just putting None in for the broken module wouldn't be sufficient (you
could possibly get the broken module via another name).
Perhaps the import machinery could keep a (weak?) mapping from module
*object* to the ImportError it raised. If the module that would be
returned by the import is in the mapping, raise the corresponding
ImportError instead. The appropriate line, etc in the module would thus
be shown each time the module was imported.
I believe this would work properly for reload() as well.