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

Function deep_import_hook

IPython/lib/deepreload.py:242–262  ·  view source on GitHub ↗

Replacement for __import__()

(name, globals=None, locals=None, fromlist=None, level=-1)

Source from the content-addressed store, hash-verified

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__()"""
244 parent, buf = get_parent(globals, level)
245
246 head, name, buf = load_next(parent, None if level < 0 else parent, name, buf)
247
248 tail = head
249 while name:
250 tail, name, buf = load_next(tail, tail, name, buf)
251
252 # If tail is None, both get_parent and load_next found
253 # an empty module name: someone called __import__("") or
254 # doctored faulty bytecode
255 if tail is None:
256 raise ValueError('Empty module name')
257
258 if not fromlist:
259 return head
260
261 ensure_fromlist(tail, fromlist, buf, 0)
262 return tail
263
264modules_reloading = {}
265

Callers

nothing calls this directly

Calls 3

get_parentFunction · 0.85
load_nextFunction · 0.85
ensure_fromlistFunction · 0.85

Tested by

no test coverage detected