[Python-Dev] Fix import errors to have data

Walter Dörwald walter at livinglogic.de
Wed Jul 28 10:29:00 CEST 2004


Delaney, Timothy C (Timothy) wrote:
> Tim Peters wrote:
> 
> 
>>[Delaney, Timothy C (Timothy)]
>>
>>>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
>>
>>Jim's after something different, while the problem you're thinking
>>about is more general than just ImportError.  When an import of an
>>existing module fails for *any* reason, subsequent attempts to import
>>the same module succeed.  For example,
> 
> Good point. This is the same as not wanting modules in an insane state
> in sys.modules.

This simplest solution for this problem would be to put the module
in sys.modules only after executing the module's code finishes.
Unfortunately this breaks circular imports, because it would lead
to infinite recursion.

This looks like we can't have both: Having a module available only
after importing it works and having circular imports where one
module uses another module that is only half initialized.

Bye,
    Walter Dörwald



More information about the Python-Dev mailing list