Fix lazyimport() to handle partially imported modules by creating
authorZac Medico <zmedico@gentoo.org>
Thu, 12 Aug 2010 10:56:20 +0000 (03:56 -0700)
committerZac Medico <zmedico@gentoo.org>
Thu, 12 Aug 2010 10:56:20 +0000 (03:56 -0700)
proxies, instead of raising ImportError.

pym/portage/proxy/lazyimport.py

index b5d15931bb3ff733e93aa852c4b347b94f9c72c1..d878b7adcecb91ed0dea403983c991e21edfe995 100644 (file)
@@ -199,7 +199,11 @@ def lazyimport(scope, *args):
                                        try:
                                                scope[alias] = getattr(already_imported, attr_name)
                                        except AttributeError:
-                                               raise ImportError('cannot import name %s' % attr_name)
+                                               # Apparently the target module is only partially
+                                               # imported, so create a proxy.
+                                               already_imported = None
+                                               scope[alias] = \
+                                                       _LazyImportFrom(scope, name, attr_name, alias)
                                else:
                                        scope[alias] = \
                                                _LazyImportFrom(scope, name, attr_name, alias)