[Python-Dev] Fix import errors to have data

Christian Tismer tismer at stackless.com
Tue Aug 3 04:16:16 CEST 2004


Guido van Rossum wrote:

>>>>Circular imports, to be made consistent, would need
>>>>something like a final "commit" after all imports succeeded.
>>>
>>>Silly idea.  Typically, circular imports aren't planned, they just
>>>happen, and (usually) just happen to work.
>>
>>I thought Christian meant this was something that would
>>be done automatically, not something the user would have
>>to do explicitly.
> 
> OK, I misunderstood then.  Apologies to Christian.

I love you for that one.

>>Maybe it could be as simple as saving a snapshot of
>>sys.modules whenever importing of a module is begun,
>>and if execution of its body doesn't complete, restoring
>>the snapshot?
> 
> That sounds like overkill -- any modules that don't participate in the
> cycle but happen to be imported by one of the modules in the cycle
> would also be deleted.

Yes, but that is ok, methinks. Any module that gets imported just
on behalf of another module that *fails* to get imported, was
just imported on behalf of that module, *not* by the user.
And it is the user, finally, who has the say.
He has to accept the extra imports of the successful imports,
but by now means he is responsible of the side effects of
imported code that he didn't write.

If the user had imported that module before, he will still have it.
If he had not, he also will not expect to have it now.
I think it is just fine to remove what he didn't expect.

The user says "I import that module now, and all what it needs".
Nothing more, and nothing less. I know what I'm talking of,
having paid for foreign kids for half of my life :-)

> I still expect that the solution that Tim just checked in (delete any
> module that failed to complete execution) will solve most of the
> problems encountered in real life.  I'm aware of the case you describe
> here:

Yes, but I think you are almost an atom's distance apart off of
the final solution. Grab it!

ciao -- chris

-- 
Christian Tismer             :^)   <mailto:tismer at stackless.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  mobile +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/



More information about the Python-Dev mailing list