public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] portage r12675 - main/trunk/pym/portage
@ 2009-02-22  0:33 Zac Medico (zmedico)
  0 siblings, 0 replies; only message in thread
From: Zac Medico (zmedico) @ 2009-02-22  0:33 UTC (permalink / raw
  To: gentoo-commits

Author: zmedico
Date: 2009-02-22 00:33:41 +0000 (Sun, 22 Feb 2009)
New Revision: 12675

Modified:
   main/trunk/pym/portage/util.py
Log:
Make lazy_import() skip proxy creation for modules that already exist
in sys.modules.


Modified: main/trunk/pym/portage/util.py
===================================================================
--- main/trunk/pym/portage/util.py	2009-02-21 22:07:51 UTC (rev 12674)
+++ main/trunk/pym/portage/util.py	2009-02-22 00:33:41 UTC (rev 12675)
@@ -451,6 +451,8 @@
 	@type args: strings
 	"""
 
+	modules = sys.modules
+
 	for s in args:
 		parts = s.split(':', 1)
 		if len(parts) == 1:
@@ -463,24 +465,27 @@
 			parent_scope = scope
 			for i in xrange(len(components)):
 				alias = components[i]
-				mod = parent_scope.get(alias)
-				if isinstance(mod, types.ModuleType):
-					parent_scope = mod.__dict__
-					continue
 				if i < len(components) - 1:
 					parent_name = ".".join(components[:i+1])
 					__import__(parent_name)
-					mod = sys.modules.get(parent_name)
+					mod = modules.get(parent_name)
 					if not isinstance(mod, types.ModuleType):
 						# raise an exception
 						__import__(name)
 					parent_scope[alias] = mod
 					parent_scope = mod.__dict__
 					continue
-				parent_scope[alias] = _LazyImport(parent_scope, alias, name)
 
+				already_imported = modules.get(name)
+				if already_imported is not None:
+					parent_scope[alias] = already_imported
+				else:
+					parent_scope[alias] = \
+						_LazyImport(parent_scope, alias, name)
+
 		else:
 			name, fromlist = parts
+			already_imported = modules.get(name)
 			fromlist = fromlist.split(',')
 			for s in fromlist:
 				alias = s.split('@', 1)
@@ -489,8 +494,14 @@
 					orig = alias
 				else:
 					orig, alias = alias
-				scope[alias] = _LazyImportFrom(scope, alias,
-					name + '.' + orig)
+				if already_imported is not None:
+					try:
+						scope[alias] = getattr(already_imported, orig)
+					except AttributeError:
+						raise ImportError('cannot import name %s' % orig)
+				else:
+					scope[alias] = _LazyImportFrom(scope, alias,
+						name + '.' + orig)
 
 class _tolerant_shlex(shlex.shlex):
 	def sourcehook(self, newfile):




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-02-22  0:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-22  0:33 [gentoo-commits] portage r12675 - main/trunk/pym/portage Zac Medico (zmedico)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox