changeset 3921:6d0d025e125a

demandimport: fix import x.y.z as a when x.y is already imported.
author Matt Mackall <mpm@selenic.com>
date Sun, 17 Dec 2006 14:56:12 -0600
parents f2c4a2ee59ed
children 693eec9570f3
files mercurial/demandimport.py
diffstat 1 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/demandimport.py	Sat Dec 16 14:51:22 2006 -0600
+++ b/mercurial/demandimport.py	Sun Dec 17 14:56:12 2006 -0600
@@ -45,12 +45,18 @@
             head, globals, locals, after = self._data
             mod = _origimport(head, globals, locals)
             # load submodules
+            def subload(mod, p):
+                h, t = p, None
+                if '.' in p:
+                    h, t = p.split('.', 1)
+                if not hasattr(mod, h):
+                    setattr(mod, h, _demandmod(p, mod.__dict__, mod.__dict__))
+                else:
+                    subload(getattr(mod, h), t)
+
             for x in after:
-                hx = x
-                if '.' in x:
-                    hx = x.split('.')[0]
-                if not hasattr(mod, hx):
-                    setattr(mod, hx, _demandmod(x, mod.__dict__, mod.__dict__))
+                subload(mod, x)
+
             # are we in the locals dictionary still?
             if locals and locals.get(head) == self:
                 locals[head] = mod