Deal with partially setup packages in the redirect hook.

This commit is contained in:
Armin Ronacher 2011-09-21 21:34:47 +02:00
parent ee9b401632
commit 9691b7f0bf
6 changed files with 49 additions and 7 deletions

View file

@ -57,6 +57,17 @@ class _ExtensionImporter(object):
__import__(realname)
except ImportError:
exc_type, exc_value, tb = exc_info()
# since we only establish the entry in sys.modules at the
# very this seems to be redundant, but if recursive imports
# happen we will call into the move import a second time.
# On the second invocation we still don't have an entry for
# fullname in sys.modules, but we will end up with the same
# fake module name and that import will succeed since this
# one already has a temporary entry in the modules dict.
# Since this one "succeeded" temporarily that second
# invocation now will have created a fullname entry in
# sys.modules which we have to kill.
modules.pop(fullname, None)
if self.is_important_traceback(realname, tb):
raise exc_type, exc_value, tb
continue