equal
deleted
inserted
replaced
225 |
225 |
226 def chainmodules(rootmod, modname): |
226 def chainmodules(rootmod, modname): |
227 # recurse down the module chain, and return the leaf module |
227 # recurse down the module chain, and return the leaf module |
228 mod = rootmod |
228 mod = rootmod |
229 for comp in modname.split('.')[1:]: |
229 for comp in modname.split('.')[1:]: |
230 if getattr(mod, comp, nothing) is nothing: |
230 obj = getattr(mod, comp, nothing) |
231 setattr(mod, comp, _demandmod(comp, mod.__dict__, |
231 if obj is nothing: |
232 mod.__dict__, level=1)) |
232 obj = _demandmod(comp, mod.__dict__, mod.__dict__, level=1) |
233 mod = getattr(mod, comp) |
233 setattr(mod, comp, obj) |
|
234 elif mod.__name__ + '.' + comp in sys.modules: |
|
235 # prefer loaded module over attribute (issue5617) |
|
236 obj = sys.modules[mod.__name__ + '.' + comp] |
|
237 mod = obj |
234 return mod |
238 return mod |
235 |
239 |
236 if level >= 0: |
240 if level >= 0: |
237 if name: |
241 if name: |
238 # "from a import b" or "from .a import b" style |
242 # "from a import b" or "from .a import b" style |