Terry Reedy wrote: > Terry Reedy wrote: >> Guido van Rossum wrote: > >>>> The reason seems to be that until the outermost import (in this case >>>> p.b) is completed, while sys.modules has the (incomplete) modules 'p', >>>> 'p.a' and 'p.b', the attributes p.a and p.b aren't added until after >>>> their import is completed. Which it isn't during recursive import. >>>> Apparently 'from <anything> import <something>' looks for the >>>> <something> attribute in the <parent> object. This is because >>>> "from...import" can also be used to import objects other than modules >>>> (e.g. "from M import C"). I'm guessing that setting the attribute is >>>> delayed until the import is totally complete, because upon a failed >>>> import we remove the half-imported module object from sys.modules, but >>>> apparently we didn 't want to be in the business of removing the >>>> attribute from the parent package, so that's only set after the import >>>> is deemed successful. > > I remember a pydev discussion on this point.
A half-baked idea that I just posted to the tracker item: What if the import semantics were adjusted so that, as a last gasp effort before bailing out with an ImportError, the import process checked sys.modules again with the full module name? Would that be enough to eliminate this error? Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia --------------------------------------------------------------- _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com