MCPcopy Create free account
hub / github.com/ipython/ipython / ensure_fromlist

Function ensure_fromlist

IPython/lib/deepreload.py:221–240  ·  view source on GitHub ↗

Handle 'from module import a, b, c' imports.

(mod, fromlist, buf, recursive)

Source from the content-addressed store, hash-verified

219 return
220
221def ensure_fromlist(mod, fromlist, buf, recursive):
222 """Handle 'from module import a, b, c' imports."""
223 if not hasattr(mod, '__path__'):
224 return
225 for item in fromlist:
226 if not hasattr(item, 'rindex'):
227 raise TypeError("Item in ``from list'' not a string")
228 if item == '*':
229 if recursive:
230 continue # avoid endless recursion
231 try:
232 all = mod.__all__
233 except AttributeError:
234 pass
235 else:
236 ret = ensure_fromlist(mod, all, buf, 1)
237 if not ret:
238 return 0
239 elif not hasattr(mod, item):
240 import_submodule(mod, item, buf + '.' + item)
241
242def deep_import_hook(name, globals=None, locals=None, fromlist=None, level=-1):
243 """Replacement for __import__()"""

Callers 1

deep_import_hookFunction · 0.85

Calls 1

import_submoduleFunction · 0.85

Tested by

no test coverage detected